mavlink/mavlink-devguide

MAVLink 2 Variable Length arrays doc incorrect?

hamishwillee opened this issue · 0 comments

MAVLink 2 > Variable length arrays says something that appears to be incorrect.

MAVLink 2 truncates any zero (empty) elements at the end of the largest array in a message. Other arrays in the message will not be truncated.

As far as I can see in the code this does not happen and is contradictory to our other docs. What actually happens is that whatever zero elements are at the end of the message will be stripped. That could be part or all of one or multiple fields (smallest sized objects based on reordering). It might not be part of an array.

Looking at the code and field reordering docs what happens is that

  • all elements are ordered for sending by size of the object type from largest to smallest and within the object size, elements retain their declaration order.
  • The message is packed by the sending code with all empty fields and values "zero filled".
  • The sending code strips all zeros off the end of the message, gets the new payload length, and puts that into the message (which after some more playing around gets sent)
  • When the message is received the payload is recovered. If the length of the received payload is less than the expected max for the message, the message buffer is zero filled at the end. This reconstructs the full expected message buffer.

There does not appear to be any code to handle sorting or stripping of empty array info.

Can anyone confirm. If I am incorrect, how does the array truncation work (can you show me the mavgen code?)

Further, this probably implies that large arrays that are more likely to be empty should be the last field in a message.