Skip to main content

message_crc_extra

Function message_crc_extra 

Source
pub fn message_crc_extra(name: &str, fields: &[(&str, &str, u8)]) -> u8
Expand description

Derives a message’s CRC_EXTRA from its name and base fields.

MAVLink computes this over the message name, then each base (non-extension) field’s type and name in wire order, with an array field’s length folded in as one byte, and reduces the 16-bit result to a byte. A receiver folds the seed into every frame’s checksum, so a sender and receiver that disagree about a message’s shape reject each other’s frames instead of silently misreading them. Extension fields are excluded, which is what lets a message gain extension fields without breaking compatibility.

§Arguments

  • name - the message name, such as "HEARTBEAT".
  • fields - the base fields in wire order, each as (type, name, array_len), where type is the MAVLink C type such as "uint16_t" and array_len is 0 for a scalar field.

§Returns

The CRC_EXTRA byte.

§Examples

use pamoja_mavlink::message_crc_extra;

// HEARTBEAT, in wire order: the 4-byte field first, then the five bytes.
let crc_extra = message_crc_extra(
    "HEARTBEAT",
    &[
        ("uint32_t", "custom_mode", 0),
        ("uint8_t", "type", 0),
        ("uint8_t", "autopilot", 0),
        ("uint8_t", "base_mode", 0),
        ("uint8_t", "system_status", 0),
        ("uint8_t", "mavlink_version", 0),
    ],
);
assert_eq!(crc_extra, 50);