Add --force-pack option for ESP32 and platforms with non-standard alignment #1117
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add --force-pack option for ESP32 and platforms with non-standard alignment
This adds support for forcing struct packing on all MAVLink messages,
which is necessary for platforms like ESP32 that have different default
struct alignment than x86/ARM platforms.
Problem:
ESP32 can add unexpected padding between struct fields even when the
MAVLink wire protocol layout is perfectly aligned. The existing needs_pack
mechanism only detects misalignment in the wire format itself, but cannot
predict platform-specific struct layout differences.
For example, ATTITUDE message fields are perfectly aligned in wire format:
So needs_pack = False. But ESP32 compiler may still add padding due to
platform-specific alignment rules, causing:
The wire-protocol alignment test cannot detect this because it only
checks wire format offsets, not platform-specific compiler behavior.
Solution:
--force-pack allows platforms to override the automatic detection and
force MAVPACKED on all message structures, ensuring identical layout
across platforms regardless of compiler alignment preferences.
Changes:
memory handling with packed structures
The mav_array_memcpy change is applied universally (not architecture-specific)
to ensure consistent behavior. The old mav_array_assign_* functions still exist
but are now implemented as macros that call mav_array_memcpy, making this a
backward-compatible improvement that avoids alignment assumptions.
This ensures cross-platform compatibility while maintaining the existing
selective packing behavior for standard platforms.
Fixes struct alignment issues on ESP32 that caused MAVLink message
corruption due to unexpected padding bytes in struct layouts.