Hi
I am trying to cast a byte buffer (that is contained within a struct) to a different struct variable:
The structs are being used in a comms system to allow the passing of structured packets back and forth between devices. The payload in the iData structure needs to be casted to the PowerData type.Code:typedef struct { uint8_t protocolVersion; uint8_t messageCount; uint8_t payload[9]; } PACK Data_t; typedef struct { uint8_t EE_Header; uint16_t DstShortAddress; uint16_t FV_Version; uint16_t ProtocolVersion; uint8_t EE_Start; uint8_t EE_End; } PACK PowerData_t; Data_t iData; PowerData_t* LPD = (PowerData_t*)iData->payload;
Now the above works fine and dandy, however after I have the local variable LPD with the correct data how do I save this data to a global variable for use after the function doing the converting (above) has finished and the memory for LPD has been re-allocated?
What I am getting at the moment is that the data comes in fine, however by the time I come to use the global data variable the contents has been over written or altered as the pointer to the local variable (LPD) created no longer apply.Code:GlobalPowerData = *LPD; // does work but not as I need:
Any help anyone can give would be greatly appreciated
David