ceremcem / modbus_lib

Lightweight and easy to merge Modbus RTU Slave library for microcontrollers
MIT License
15 stars 7 forks source link

Endian dependens #3

Open Jonas-Meyer97 opened 2 years ago

Jonas-Meyer97 commented 2 years ago

I implemented the modbus library into my project and noticed while debugging that the union CRC_t, MbDataField is endian dependent. It would really help if the dependence on endianness would be documented in comments and Readme/Usage guide. Also is there any plan to implement some sort of configuration with macros like

#ifndef LITTLE_ENDIAN
    #define LITTLE_ENDIAN 1234
#endif

#ifndef BIG_ENDIAN
    #define BIG_ENDIAN 4321
#endif

#ifndef BYTE_ORDER
    #define BYTE_ORDER LITTLE_ENDIAN
#endif

#if BYTE_ORDER == LITTLE_ENDIAN
    struct {
        uint8_t low;
        uint8_t high;
    } bytes;
#else
    struct {
        uint8_t high;
        uint8_t low;
    } bytes;
#endif
ceremcem commented 2 years ago

I read a little bit history about that and it seems like this Little/Big endian dictation is not clarified. Adding an endianness configuration would be nice. However, I've no test setup ATM to implement/test this option. I will add such an option as soon as possible, but I can't promise any time frame.