I have a C program that receives a 64 byte array of char (which is passed via USB). Depending on the first byte (which indicates the command type) I want to 'impose' a structure over the char array to make the code clearer.
For example, if the command code is 10 I would expect something like:
struct
{
uint8_t commandNumber;
uint16_t xPos;
uint16_t yPos;
int32_t identificationNumber;
} commandTen;
So I would like to cast my char packet[64] 'onto' commandTen and then access the fields using something like:
localVar = commandTenPacket->xPos;
How can this be achieved in C?
Thanks in advance!