Hi Guillaume,
the fields are ordered for size to prevent alignment issues and the checksum is calculated over these reordered fields to make sure the reordering is correct.
That is a bit unintuitive and we need better documentation. From your strings I can see that you are not ordering the fields, as 16 bit values would have to be before the 8 bit ones. Check the python generator for the sorting and let me know if you need more information - the documentation is really not in shape yet on that topic.
-Lorenz
On Sep 3, 2012, at 3:45 PM, ghelle wrote:
Hello,
i am coding a MAVLink generator for Java and i have a problem to compute the extra crc and build the MAVLINK_MESSAGE_CRCS byte array...
In pyton code i found that :
def message_checksum(msg):
'''calculate a 8-bit checksum of the key fields of a message, so we
can detect incompatible XML changes'''
crc = mavutil.x25crc(
msg.name + ' ')
for f in msg.ordered_fields:
crc.accumulate(f.type + ' ')
crc.accumulate(
f.name + ' ')
if f.array_length:
crc.accumulate(chr(f.array_length))
return (crc.crc&0xFF) ^ (crc.crc>>8)
So during the parsing i build a String and accumulate it.
By example i have :
"FENCE_FETCH_POINT uint8_t target_system uint8_t target_component uint8_t idx " => 90
"SET_MAG_OFFSETS uint8_t target_system uint8_t target_component int16_t mag_ofs_x int16_t mag_ofs_y int16_t mag_ofs_z " ==> 149
but it is not the good values like found in MAVLINK_MESSAGE_CRCS in C header file...
Where am i wrong?
Do i use the good strings and names?
Thanks for your help!
Best Regards
Guillaume Helle