The msg contains a payload, in the form |tag|length|value| size of tag and length is of 2 bytes. size of value is described inside length, and the data type can be uint16, uint32 or uint8.
typedef struct
{
response_uint16_t msg[5];
}payload;
void func(response_uint16_t *msg, int type)
{
int *posPtr = NULL;
void *temp;
int valueLen = msg->length;
posPtr = &msg->tag;
posPtr += sizeof(msg->tag);
posPtr += sizeof(msg->length);
posPtr++; //ideally this should now point to value.
if(type == 1)
{
memcpy((U8*)temp, *posPtr, valueLen);
return(*temp);
}
if(type == 2)
{
memcpy((U16*)temp, *posPtr, valueLen);
return(*temp);
}
}
int main()
{
payload *P;
p = (struct payload*)malloc(sizeof(p));
int res;
/*assumne the msg is filled here and value expected to be filled here is of type U16 */
res =(U16)func(&p->msg[1], 2);
res =(U8)func(&p->msg[2], 1);
.
.
}