pub struct Frame { /* private fields */ }Expand description
An encoded MAVLink frame, held in a fixed buffer so encoding never allocates.
encode_v2 and encode_v1 build a frame to
send; parse reads one received, verifying its checksum so a frame
mangled in transit is rejected rather than misread. Signing a v2 frame is a separate
step in signing, since it needs a key and the timestamp the
sender chooses.
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn encode_v2(
header: Header,
msgid: u32,
payload: &[u8],
crc_extra: u8,
) -> Result<Frame>
pub fn encode_v2( header: Header, msgid: u32, payload: &[u8], crc_extra: u8, ) -> Result<Frame>
Builds a v2 frame for a message, computing and appending the checksum.
Trailing zero bytes of the payload are dropped before transmission as MAVLink 2 requires, except that the first payload byte is always kept.
§Arguments
header- the addressing fields to stamp on the frame.msgid- the 24-bit message id.payload- the serialized message payload, full length.crc_extra- theCRC_EXTRAseed formsgid.
§Returns
The frame ready to send.
§Errors
Returns MavlinkError::PayloadTooLong if payload is longer than
MAX_PAYLOAD.
Sourcepub fn encode_message<M: Message>(header: Header, message: &M) -> Result<Frame>
pub fn encode_message<M: Message>(header: Header, message: &M) -> Result<Frame>
Builds a v2 frame carrying a typed message.
The message knows its own id and CRC_EXTRA and serializes itself, so a caller
hands over the message rather than a payload buffer and two constants that have to
agree with it. The payload is built on the stack, so this allocates nothing.
§Arguments
header- the addressing fields to stamp on the frame.message- the message to carry.
§Returns
The frame ready to send.
§Errors
Returns MavlinkError::PayloadTooLong if the message does not fit a frame.
Sourcepub fn decode_message<M: Message>(&self) -> Result<M>
pub fn decode_message<M: Message>(&self) -> Result<M>
Reads the payload back as a typed message.
§Returns
The decoded message.
§Errors
Returns MavlinkError::PayloadTooLong if the payload is longer than the message
describes.
Sourcepub fn encode_v1(
header: Header,
msgid: u32,
payload: &[u8],
crc_extra: u8,
) -> Result<Frame>
pub fn encode_v1( header: Header, msgid: u32, payload: &[u8], crc_extra: u8, ) -> Result<Frame>
Builds a v1 frame for a message, computing and appending the checksum.
§Arguments
header- the addressing fields to stamp on the frame.msgid- the message id, which must fit a single byte for v1.payload- the serialized message payload.crc_extra- theCRC_EXTRAseed formsgid.
§Returns
The frame ready to send.
§Errors
Returns MavlinkError::PayloadTooLong if payload is longer than MAX_PAYLOAD,
or MavlinkError::UnknownMessage if msgid does not fit a single byte.
Sourcepub fn parse_with<F>(bytes: &[u8], crc_extra_for: F) -> Result<Frame>
pub fn parse_with<F>(bytes: &[u8], crc_extra_for: F) -> Result<Frame>
Parses a received frame, verifying its checksum.
The message id is read from the header and its CRC_EXTRA is resolved through
crc_extra_for, so a frame whose message is unknown is rejected rather than
accepted unchecked. The signature of a signed v2 frame is preserved but not
verified here; pass the parsed frame to a Verifier.
§Arguments
bytes- the raw frame as it came off the link, from the start marker onward.crc_extra_for- resolves a message id to itsCRC_EXTRA, orNoneif unknown.
§Returns
The validated frame.
§Errors
Returns MavlinkError::FrameTooShort if the bytes cannot hold a header,
MavlinkError::BadMagic if the start marker is unrecognized,
MavlinkError::Truncated if the frame is shorter than its length field
promises, MavlinkError::UnknownMessage if the message id has no CRC_EXTRA,
or MavlinkError::CrcMismatch if the checksum does not verify.
Sourcepub fn parse(bytes: &[u8], crc_extra: u8) -> Result<Frame>
pub fn parse(bytes: &[u8], crc_extra: u8) -> Result<Frame>
Parses a received frame whose CRC_EXTRA is already known.
§Arguments
bytes- the raw frame as it came off the link.crc_extra- theCRC_EXTRAfor the frame’s message id.
§Returns
The validated frame.
§Errors
As parse_with, except the message id is always resolvable.
Sourcepub fn component_id(&self) -> u8
pub fn component_id(&self) -> u8
Sourcepub fn message_id(&self) -> u32
pub fn message_id(&self) -> u32
Returns the message id the frame carries.
§Returns
The message id: 0-255 for v1, up to 24 bits for v2.
Sourcepub fn incompat_flags(&self) -> u8
pub fn incompat_flags(&self) -> u8
Returns the incompatibility flags of a v2 frame, or 0 for a v1 frame.
§Returns
The incompatibility flags byte.