I realise you can pack the struct on a 32 bit platform to give compatibility with a struct from an 8 bit platform, but it there a way to make a struct on a 8 bit platform emulate the padded nature of a struct from a 32 bit platform?
If you are moving data between platforms, the internal representation of the data types is a consideration along with "endianness" (or what ever it is called), byte alignment and other encoding like ASCII flavours.
Can you give an example of the struct and say from which to which platform you are moving it
This was the test struct I was using
struct TestStruct{
byte switch_status = 88;
byte command_message = 2;
byte average_current = 3;
float peak_current = 4;
byte average_voltage = 5;
byte peak_voltage = 6;
byte phase = 7;
byte trip_current_amps = 30;
byte adc_peak = 8;
} testData;
On 32 bit platform a pad byte gets added before the float.
Originally I was doing a transfer from an MEGA328 to a SAMD21 using this library GitHub - PowerBroker2/SerialTransfer: Arduino library to transfer dynamic, packetized data fast and reliably via Serial, I2C, or SPI and stumbled on the alignment/padding issue and the attribute((packed)) fix at the receiving end.
Then I started wondering how you would go about interfacing an 8 bit micro with a 32 bit system which didn't use packed data and couldn't be modified.
I could manually add a dummy byte on the 8 bit version but I was hoping that there would be some automated tool or "attribute" that would do this transparently.
Then I started wondering how you would go about interfacing an 8 bit micro with a 32 bit system which didn't use packed data and couldn't be modified.
There is no obligation in the C++ specification to arrange the data in a particular order especially if you did not use the GCC (non standard) attribute options such as packed or aligned.
you would need to understand how the compiler represented the data in memory on the sender side to be able to decode on the receiver side.
==> so using packed and aligned will make your life easier (won't deal with endianness)
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.