Enum mavio::protocol::MavFrame

source ·
pub enum MavFrame {
    V1(Frame<V1>),
    V2(Frame<V2>),
}
Expand description

Version-agnostic MAVLink frame, that can be matched according to its protocol version.

MavFrame allows to work with MAVLink frames dynamically, but still type-safely, where generic Frame is suboptimal. It has almost the same protocol-agnostic methods as Frame, to access protocol-specific functionality, you have to convert or pattern match MavFrame back into a Frame.

It is not possible to create MavFrame directly. An instance of Frame should be obtained first.

§Examples

Create MavFrame from an instance of Frame and then turn back into a versionless frame:

use mavio::prelude::*;

let frame: Frame<_> = // ... obtain a frame

let mav_frame = MavFrame::new(frame);

match mav_frame {
    MavFrame::V1(_) => { /* `MAVLink 1` specific logic */ }
    MavFrame::V2(_) => { /* `MAVLink 2` specific logic */ }
}

let frame: Frame<Versionless> = mav_frame.into_versionless();

Update existing instance of Frame with a protocol version compatible MavFrame (available only when unsafe feature is enabled):

use mavio::prelude::*;

let mut frame: Frame<_> = // ... obtain a frame

let mav_frame = MavFrame::new(frame.clone());

frame.try_update_from(&mav_frame).unwrap();

Variants§

§

V1(Frame<V1>)

MAVLink 1 frame.

§

V2(Frame<V2>)

MAVLink 2 frame.

Implementations§

source§

impl MavFrame

source

pub fn new<V: MaybeVersioned>(frame: Frame<V>) -> Self

Creates MavFrame from the provided Frame.

source

pub fn version(&self) -> MavLinkVersion

MAVLink version.

See: Frame::version.

source

pub fn payload_length(&self) -> PayloadLength

Payload length.

See: Frame::payload_length.

source

pub fn sequence(&self) -> Sequence

Frame sequence.

See: Frame::sequence.

source

pub fn system_id(&self) -> SystemId

System ID.

See: Frame::system_id.

source

pub fn component_id(&self) -> SystemId

Component ID.

See: Frame::component_id.

source

pub fn message_id(&self) -> MessageId

Message ID.

See: Frame::message_id.

source

pub fn payload(&self) -> &Payload

Payload data.

See: Frame::payload.

source

pub fn checksum(&self) -> Checksum

MAVLink packet checksum.

See: Frame::checksum.

source

pub fn is_signed(&self) -> bool

Returns true if frame is signed.

For MAVLink 1 frames always returns false.

See: Frame::is_signed.

source

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

MAVLink 2 signature.

See: Frame::signature.

source

pub fn remove_signature(&mut self)

Removes MAVLink 2 signature from frame.

Applicable only for MAVLink 2 frames. MAVLink 1 frames will be kept untouched.

See: Frame::remove_signature.

source

pub fn body_length(&self) -> usize

Body length.

See: Frame::body_length.

source

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

Calculates CRC for frame within crc_extra.

See: Frame::calculate_crc.

source

pub fn validate_checksum<D: Dialect>(&self) -> Result<()>

Validates frame in the context of specific dialect.

See: Frame::validate_checksum.

source

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

Validates frame’s checksum using provided crc_extra.

See: Frame::validate_checksum_with_crc_extra.

source

pub fn matches_version<Version: Versioned>(&self, version: Version) -> bool

Checks that frame has MAVLink version equal to the provided one.

See: Frame::matches_version

source

pub fn decode<D: Dialect>(&self) -> Result<D>

Decodes frame into a message of particular MAVLink dialect.

See: Frame::decode.

source

pub fn into_versionless(self) -> Frame<Versionless>

Converts MavFrame into a versionless Frame.

source

pub fn try_into_versioned<V: MaybeVersioned>( self ) -> Result<Frame<V>, VersionError>

Attempts to convert into a versioned form of a Frame.

Returns VersionError if conversion is impossible.

Trait Implementations§

source§

impl Clone for MavFrame

source§

fn clone(&self) -> MavFrame

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 MavFrame

source§

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

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

impl<'de> Deserialize<'de> for MavFrame

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<V: MaybeVersioned> From<Frame<V>> for MavFrame

source§

fn from(value: Frame<V>) -> Self

Converts to this type from the input type.
source§

impl Serialize for MavFrame

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

impl<V: MaybeVersioned> TryFrom<MavFrame> for Frame<V>

§

type Error = VersionError

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

fn try_from(value: MavFrame) -> Result<Self, VersionError>

Performs the conversion.
source§

impl<V: MaybeVersioned> TryUpdateFrom<&MavFrame> for Frame<V>

§

type Error = VersionError

Error, that may be thrown during update.
source§

fn check_try_update_from(&self, value: &&MavFrame) -> Result<(), Self::Error>

Checks, that update is possible. Read more
source§

unsafe fn update_from_unchecked(&mut self, value: &MavFrame)

Performs the update without checking, whether update is possible. Read more
source§

fn try_update_from(&mut self, value: T) -> Result<(), Self::Error>

Performs the update. Read more

Auto Trait Implementations§

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