I have a structure I need to send across LORA so I am trying to create a CRC of the unioned char array but I am having a strange time understanding the layout of the structure.
This is the structure in question
And this is the union
sizeof() tells me the structure is 36 bytes but my awful math says 28 bytes
By putting known values into the array and looking at the char union byte by byte, I think I have this...
Acknowledging that it doesn't solve everything - pulsetime and mv don't seem to start where I expect (The ? in the table represent what look like dead bytes that aren't used - is this an artifact of those values needing to start on a certain byte boundary? Would I make a couple of bytes saving by stacking the byte and boolean values together in the structure?
This is doing my head in!
Cheers - N
This is the structure in question
Code:
struct timepacket { // 36 bytes according to sizeof()
byte startorfinish; // 1
int carnum; // 4
time_t pulsetime; // 4
uint32_t pulsems; // 4
byte sats; // 1
int millivolts; // 4
boolean sent; // 1
int crc; // 4
byte terminator; // 1
};
And this is the union
Code:
union outputLora {
timepacket timepacketdata;
byte LoraLine[timepacketsize];
};
sizeof() tells me the structure is 36 bytes but my awful math says 28 bytes
By putting known values into the array and looking at the char union byte by byte, I think I have this...
Code:
timepacket structure
1 2 3
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
startfin X
carnum X X X X
pulsetime ? ? ? X X X X
pulsems X X X X
sats X
mv ? ? ? X X X X
sent X
crc X X X X
term X
Acknowledging that it doesn't solve everything - pulsetime and mv don't seem to start where I expect (The ? in the table represent what look like dead bytes that aren't used - is this an artifact of those values needing to start on a certain byte boundary? Would I make a couple of bytes saving by stacking the byte and boolean values together in the structure?
This is doing my head in!
Cheers - N