Now on the next frame, we need to retrieve the value of the request field so we can use it in decoding the response. Use the PersistentField method to retrieve inter-frame data.
FIELD request_code (Fixed 0) RETRIEVE (PersistentField request) SUPPRESS_DETAIL
Here's the full decoder, using our request and request_code fields. Assume the first byte in the frame is the address. If the data is a request, the second byte is the request code, followed by any additional data that may be required. If the data is a response, the bytes after the first contain the data requested. There's a 2 byte CRC on the end of each frame.
DECODE
TABLE request_codes
{ 0 "Send" "Send File" 0 send_file}
{ 1 "Rcv" "Receive File" 0 receive_file}
{ 2 "Ack" "Acknowledge Receipt of File" 0 ack}
{ DEFAULT "Unknown"}
ENDTABLE
FIELD address (Fixed 1) (Hex) "Address"
GROUP frame_is_request IF (FieldIs EqualTo 0x00 address)
{
FIELD request (Fixed 1) RETRIEVE (StorePersistentField request) (Table request_codes) "Request"
BRANCH (FromTable request_codes request)
}
GROUP frame_is_response IF (FieldIs NotEqualTo 0x00 address)
{
FIELD retrieved_request_code (Fixed 0) RETRIEVE (PersistentField request) (Table request_ codes) "Request Responding To"
BRANCH (FromTable request_codes retrieved_request_code)
}
FIELD crc16 (Fixed 2) (Hex) "CRC" VERIFY (Check_CrcCRC16 0 0xffff)
END_MAIN_PATH
GROUP send_file
{
GROUP send_request IF (FieldIs EqualTo 0x00 address) "Send File Request"
{
[FIELDs here]
}
GROUP send_response IF (FieldIs NotEqualTo 0x00 address) "Send File Response"
{
[FIELDs here]
}
}
If you need to do something more complex with your inter-frame data, such as matching values from more than one field before deciding what to return, you will need to write a custom data object. These objects and how to write them are described in Decoder Data Objects.