Hello
I have a function that takes a strut and turns it into a uint8_t array. This code is running on an embedded device and works well. I have recently copied this code to a linux development environment to try to get it to work there as well.
Everything works as it should, however the 16bit variables in my struct are produced backwards:
Code:
typedef struct {
uint8_t deviceType;
uint8_t RSSI;
uint16_t batteryVoltage;
uint16_t errors;
} AppAuxSLANPacket_t;
So when I want to convert my struct into a byte array (buffer) I do this:
Code:
{
transcribePacket((uint8_t*)&AuxSLANPacket, 6);
}...
void transcribePacket(uint8_t message[], uint8_t length) {
int x, y = 0;
for (x = 0; x < length; x++) {
buffer[x] = message[x];
} // for
} // transcribe
This works fine on the embedded device and I get a byte array with all of the data of the structs in it. If I do the same in the linux dev environment the 16bit variables are written to the byte array backwards:
embedded device example byte array: (correct)
0x10 | 0x20 | 0x01 | 0xFF | 0xDA | 0x33
Linux dev environment example for same data:
0x10 | 0x20 | 0xFF | 0x01 | 0x33 | 0xDA
Here the 16 bit values have been entered into the byte array, but put in backwards.
It is exactly the same code doing this on each platform which leads me to think there is a compiler options somewhere I need to change.
Has anyone got any ideas?
may thanks indeed
David