Skip to content

define sizes and explicit values for all enums #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2021

Conversation

runger1101001
Copy link
Member

This commit adds defined sizes (uint8_t or int8_t in one case) and explicit values to all our enums.

This is due to the work on I2CCommander, and the need to do serialisation/deserialisation of these values in binary format.

While in theory the C++ compiler would probably have generated stable values, making them explicit guarantees this, and is also a form of documentation (e.g. makes it easy to see which enum constant has byte value 0x04 when looking at a Wireshark capture).

in addition there is a subtlety that enums are usually ints e.g. (sizeof(enumtype)==4 on 32 bit MCUs) but if you don't specify it isn't guaranteed. So when serialising, you could wind up with different sizes for the enum types on different architectures (or maybe due to compiler settings). Also that makes them subject to endianness problems (ugh :-( ).
Luckily all our enums have <256 elements, so I have defined their size to 8bit integers which gets rid of all these problems.

@runger1101001
Copy link
Member Author

Tested compile under ArduinoIDE for Arduino UNO and Tiny M4.
Tested compile & run under STM32F4.

@runger1101001 runger1101001 added the enhancement New feature or request label Nov 27, 2021
@runger1101001 runger1101001 merged commit 6c880c7 into simplefoc:dev Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant