Skip to main content

Frame

Struct Frame 

Source
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

Source

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 - the CRC_EXTRA seed for msgid.
§Returns

The frame ready to send.

§Errors

Returns MavlinkError::PayloadTooLong if payload is longer than MAX_PAYLOAD.

Source

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.

Source

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.

Source

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 - the CRC_EXTRA seed for msgid.
§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.

Source

pub fn parse_with<F>(bytes: &[u8], crc_extra_for: F) -> Result<Frame>
where F: FnOnce(u32) -> Option<u8>,

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 its CRC_EXTRA, or None if 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.

Source

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 - the CRC_EXTRA for the frame’s message id.
§Returns

The validated frame.

§Errors

As parse_with, except the message id is always resolvable.

Source

pub fn version(&self) -> Version

Returns which wire format the frame uses.

§Returns

Version::V1 or Version::V2.

Source

pub fn sequence(&self) -> u8

Returns the sequence number the sender stamped on the frame.

§Returns

The sequence number.

Source

pub fn system_id(&self) -> u8

Returns the sending system’s id.

§Returns

The system id.

Source

pub fn component_id(&self) -> u8

Returns the sending component’s id.

§Returns

The component id.

Source

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.

Source

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.

Source

pub fn is_signed(&self) -> bool

Reports whether the frame is a signed v2 frame.

§Returns

true if the frame carries a signature.

Source

pub fn payload(&self) -> &[u8]

Returns the payload as it was carried, after any MAVLink 2 truncation.

§Returns

The payload bytes.

Source

pub fn signature(&self) -> Option<&[u8; 13]>

Returns the 13-byte signature block of a signed frame.

§Returns

The signature block, or None if the frame is not signed.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the whole frame, ready for the link.

§Returns

The frame as a byte slice, signature included if present.

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Frame

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Frame

Source§

impl Debug for Frame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Frame

Source§

impl PartialEq for Frame

Source§

fn eq(&self, other: &Frame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Frame

Auto Trait Implementations§

§

impl Freeze for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnsafeUnpin for Frame

§

impl UnwindSafe for Frame

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.