DSP Binary message template¶
When creating a non string based message scheme it is common to use structs with a common header. Note that seq_no, majrev, minrev may not always be useful.
For example:
typedef struct
{
uint8_t sig1; // 2 byte identification
uint8_t sig2; //
uint8_t id; // message ID
uint8_t seq_no; // sequence number
uint8_t majrev; // message revision
uint8_t minrev; // message revision
uint16_t length; // following bytes of data
} header_type;
typedef struct
{
header_type header; // length 4
int32_t value; // generic message type to pass integer
} tsIntValMsgType;
typedef struct
{
header_type header; // length 8
uint32_t num_data;
uint32_t * data_ptr; // Pointer to shared memory. copied to ARM using tcDspApp::ReadMemory() call.
} tsData;
And have a union that combines all your message types for inital parsing.
union dsp_messages
{
header_type header;
tsIntValMsgType int_val_msg;
tsData data_response;
unsigned char data[MAX_MSG_LENGTH + sizeof(header_type)];
};
Then in your inbound message handler you can do something like.
if (buffer != NULL && length != 0)
{
const dsp_messages *pmsg = (const dsp_messages*) buffer;
// Check the message signature
if (pmsg->header.sig1 != cnSig1 || pmsg->header.sig2 < cnSig2)
{
// PRINT ERROR MESSAGE
goto inbounddone;
}
// Other data handling/verification
// Switch on header.id and cast pmsg to the correct struct. And call a function that handles that particular message type.
}
Go to top