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§
Implementations§
source§impl MavFrame
impl MavFrame
sourcepub fn new<V: MaybeVersioned>(frame: Frame<V>) -> Self
pub fn new<V: MaybeVersioned>(frame: Frame<V>) -> Self
sourcepub fn version(&self) -> MavLinkVersion
pub fn version(&self) -> MavLinkVersion
MAVLink
version.
See: Frame::version
.
sourcepub fn payload_length(&self) -> PayloadLength
pub fn payload_length(&self) -> PayloadLength
Payload length.
See: Frame::payload_length
.
sourcepub fn sequence(&self) -> Sequence
pub fn sequence(&self) -> Sequence
Frame sequence.
See: Frame::sequence
.
sourcepub fn system_id(&self) -> SystemId
pub fn system_id(&self) -> SystemId
System ID
.
See: Frame::system_id
.
sourcepub fn component_id(&self) -> SystemId
pub fn component_id(&self) -> SystemId
Component ID
.
See: Frame::component_id
.
sourcepub fn message_id(&self) -> MessageId
pub fn message_id(&self) -> MessageId
Message ID
.
See: Frame::message_id
.
sourcepub fn payload(&self) -> &Payload
pub fn payload(&self) -> &Payload
Payload data.
See: Frame::payload
.
sourcepub fn checksum(&self) -> Checksum
pub fn checksum(&self) -> Checksum
MAVLink packet checksum.
See: Frame::checksum
.
sourcepub fn signature(&self) -> Option<&Signature>
pub fn signature(&self) -> Option<&Signature>
MAVLink 2
signature.
See: Frame::signature
.
sourcepub fn remove_signature(&mut self)
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
.
sourcepub fn body_length(&self) -> usize
pub fn body_length(&self) -> usize
Body length.
See: Frame::body_length
.
sourcepub fn calculate_crc(&self, crc_extra: CrcExtra) -> Checksum
pub fn calculate_crc(&self, crc_extra: CrcExtra) -> Checksum
Calculates CRC for frame within crc_extra
.
See: Frame::calculate_crc
.
sourcepub fn validate_checksum<D: Dialect>(&self) -> Result<()>
pub fn validate_checksum<D: Dialect>(&self) -> Result<()>
Validates frame in the context of specific dialect.
See: Frame::validate_checksum
.
sourcepub fn validate_checksum_with_crc_extra(
&self,
crc_extra: CrcExtra
) -> Result<(), ChecksumError>
pub fn validate_checksum_with_crc_extra( &self, crc_extra: CrcExtra ) -> Result<(), ChecksumError>
Validates frame’s checksum using provided crc_extra
.
sourcepub fn matches_version<Version: Versioned>(&self, version: Version) -> bool
pub fn matches_version<Version: Versioned>(&self, version: Version) -> bool
Checks that frame has MAVLink version equal to the provided one.
sourcepub fn decode<D: Dialect>(&self) -> Result<D>
pub fn decode<D: Dialect>(&self) -> Result<D>
Decodes frame into a message of particular MAVLink dialect.
See: Frame::decode
.
sourcepub fn into_versionless(self) -> Frame<Versionless>
pub fn into_versionless(self) -> Frame<Versionless>
sourcepub fn try_into_versioned<V: MaybeVersioned>(
self
) -> Result<Frame<V>, VersionError>
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<'de> Deserialize<'de> for MavFrame
impl<'de> Deserialize<'de> for MavFrame
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<V: MaybeVersioned> TryFrom<MavFrame> for Frame<V>
impl<V: MaybeVersioned> TryFrom<MavFrame> for Frame<V>
§type Error = VersionError
type Error = VersionError
source§impl<V: MaybeVersioned> TryUpdateFrom<&MavFrame> for Frame<V>
impl<V: MaybeVersioned> TryUpdateFrom<&MavFrame> for Frame<V>
§type Error = VersionError
type Error = VersionError
source§fn check_try_update_from(&self, value: &&MavFrame) -> Result<(), Self::Error>
fn check_try_update_from(&self, value: &&MavFrame) -> Result<(), Self::Error>
⚠
Checks, that update is possible. Read moresource§unsafe fn update_from_unchecked(&mut self, value: &MavFrame)
unsafe fn update_from_unchecked(&mut self, value: &MavFrame)
⚠
Performs the update without checking, whether update is possible. Read more