Struct mavio::protocol::Frame

source ·
pub struct Frame { /* private fields */ }
Expand description

MAVLink frame.

Since MAVLink frames has a complex internal structure depending on [MavLinkVersion], encoded [MessageImpl] and presence of Signature, there are no constructor for this struct. Frame can be either received as they were sent by remote or built from FrameBuilder.

Use Frame::builder to create a new unsigned message and Frame::add_signature/Frame::replace_signature to manage signature of exising frame.

Implementations§

source§

impl Frame

source

pub fn builder() -> FrameBuilder

Instantiates a builder for Frame.

An instance of FrameBuilder returned by this function is initialized with default values. Once desired frame parameters are set, use FrameBuilder::build or FrameBuilder::build_for to obtain a valid instance of Frame.

source

pub fn header(&self) -> &Header

Generic MAVLink header.

MAVLink protocol version defined by Header.

source

pub fn incompat_flags(&self) -> Option<u8>

Incompatibility flags for MAVLink 2 header.

Flags that must be understood for MAVLink compatibility (implementation discards packet if it does not understand flag).

See: MAVLink 2 incompatibility flags.

source

pub fn compat_flags(&self) -> Option<u8>

Compatibility flags for MAVLink 2 header.

Flags that can be ignored if not understood (implementation can still handle packet even if it does not understand flag).

See: MAVLink 2 compatibility flags.

source

pub fn payload_length(&self) -> u8

Payload length.

Indicates length of the following payload section. This may be affected by payload truncation.

source

pub fn sequence(&self) -> u8

Packet sequence number.

Used to detect packet loss. Components increment value for each message sent.

source

pub fn system_id(&self) -> u8

System ID.

ID of system (vehicle) sending the message. Used to differentiate systems on network.

Note that the broadcast address 0 may not be used in this field as it is an invalid source address.

source

pub fn component_id(&self) -> u8

Component ID.

ID of component sending the message. Used to differentiate components in a system (e.g. autopilot and a camera). Use appropriate values in MAV_COMPONENT.

Note that the broadcast address MAV_COMP_ID_ALL may not be used in this field as it is an invalid source address.

source

pub fn message_id(&self) -> MessageId

Message ID.

ID of MAVLink message. Defines how payload will be encoded and decoded.

source

pub fn payload(&self) -> &Payload

Payload data.

Message data. Content depends on message type (i.e. message_id).

  • Payload implementation: [Payload].
source

pub fn checksum(&self) -> Checksum

MAVLink packet checksum.

CRC-16/MCRF4XX checksum for message (excluding magic byte).

Includes CRC_EXTRA byte.

Checksum is encoded with little endian (low byte, high byte).

source

pub fn signature(&self) -> Option<&Signature>

MAVLink 2 signature.

Returns signature that ensures the link is tamper-proof.

Available only for signed MAVLink 2 frame. For MAVLink 1 always return None.

MAVLink 2 signature link_id, a 8-bit identifier of a MAVLink channel.

Peers may have different semantics or rules for different links. For example, some links may have higher priority over another during routing. Or even different secret keys for authorization.

Available only for signed MAVLink 2 frame. For MAVLink 1 always return None.

source

pub fn timestamp(&self) -> Option<MavTimestamp>

MAVLink 2 signature MavTimestamp, a 48-bit value that specifies the moment when message was sent.

The unit of measurement is the number of millisecond * 10 since MAVLink epoch (1st January 2015 GMT).

According to MAVLink protocol, the sender must guarantee that the next timestamp is greater than the previous one.

Available only for signed MAVLink 2 frame. For MAVLink 1 always return None.

source

pub fn is_signed(&self) -> bool

Whether a Frame is signed.

Returns true if Frame contains Signature. Correctness of signature is not validated.

For MAVLink 1 always returns false.

source

pub fn body_length(&self) -> usize

Body length.

Returns the length of the entire Frame body. The frame body consist of [Payload::bytes], Checksum, and optional Signature (for MAVLink 2 protocol).

source

pub fn calculate_crc(&self, crc_extra: CrcExtra) -> Checksum

Calculates CRC for Frame within crc_extra.

Provided crc_extra depends on a dialect and contains a digest of message XML definition.

source

pub fn validate_checksum(&self, dialect_spec: &dyn DialectSpec) -> Result<()>

Validates frame in the context of specific dialect.

Receives dialect specification in dialect_spec, ensures that message with such ID exists in this dialect, and compares checksums using EXTRA_CRC.

Errors
source

pub fn validate_checksum_with_crc_extra( &self, crc_extra: CrcExtra ) -> Result<()>

Validates Frame::checksum using provided crc_extra.

source

pub fn add_signature( &mut self, signer: &mut dyn Sign, conf: SignatureConf ) -> Result<&mut Self>

Adds signature to MAVLink 2 frame.

Signs MAVLink 2 frame with provided instance of signer that implements Sign trait and signature configuration specified as SignatureConf.

Errors

Returns FrameError::SigningIsNotSupported when caller attempts to sign MAVLink 1 frame.

source

pub fn replace_signature( &mut self, signer: &mut dyn Sign, conf: SignatureConf ) -> Result<&mut Self>

Replaces existing signature for MAVLink 2 frame.

Re-signs MAVLink 2 frame with provided instance of signer that implements Sign. An instance of Frame should already have a (possibly invalid) signature.

Errors
source

pub fn remove_signature(&mut self) -> &mut Self

Removes MAVLink 2 signature from Frame.

Applicable only for MAVLink 2 frames.

source

pub fn calculate_signature( &self, signer: &mut dyn Sign, secret_key: &SecretKey ) -> Result<SignatureValue>

Calculates MAVLink 2 signature.

Calculates MAVLink 2 frame signature with provided instance of signer that implements Sign trait and signature configuration specified as SignatureConf.

Errors

Returns FrameError::SigningIsNotSupported when caller attempts to sign MAVLink 1 frame.

Trait Implementations§

source§

impl Clone for Frame

source§

fn clone(&self) -> Frame

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Frame

source§

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

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

impl<'de> Deserialize<'de> for Frame

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for Frame

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin 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> 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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,