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
impl Frame
sourcepub fn builder() -> FrameBuilder
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.
sourcepub fn mavlink_version(&self) -> MavLinkVersion
pub fn mavlink_version(&self) -> MavLinkVersion
sourcepub fn incompat_flags(&self) -> Option<u8>
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).
sourcepub fn compat_flags(&self) -> Option<u8>
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).
sourcepub fn payload_length(&self) -> u8
pub fn payload_length(&self) -> u8
Payload length.
Indicates length of the following payload section. This may be affected by payload truncation.
Links
sourcepub fn sequence(&self) -> u8
pub fn sequence(&self) -> u8
Packet sequence number.
Used to detect packet loss. Components increment value for each message sent.
Links
sourcepub fn system_id(&self) -> u8
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.
Links
sourcepub fn component_id(&self) -> u8
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_ALLmay not be used in this field as it is an invalid source address.
Links
sourcepub fn message_id(&self) -> MessageId
pub fn message_id(&self) -> MessageId
sourcepub fn payload(&self) -> &Payload
pub fn payload(&self) -> &Payload
Payload data.
Message data. Content depends on message type (i.e. message_id).
Links
- Payload implementation: [
Payload].
sourcepub fn checksum(&self) -> Checksum
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).
Links
Frame::calculate_crcfor implementation.- MAVLink checksum definition.
- CRC-16/MCRF4XX (PDF).
sourcepub fn signature(&self) -> Option<&Signature>
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.
Links
Frame::is_signed.Frame::link_idandFrame::timestampprovide direct access to signature fields.- MAVLink 2 message signing.
sourcepub fn link_id(&self) -> Option<SignatureLinkId>
pub fn link_id(&self) -> Option<SignatureLinkId>
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.
Links
Self::signaturefrom whichSignaturecan be obtained. The former contains all signature-related fields (if applicable).- MAVLink 2 message signing.
sourcepub fn timestamp(&self) -> Option<MavTimestamp>
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.
Links
Self::signaturefrom whichSignaturecan be obtained. The former contains all signature-related fields (if applicable).MavTimestamptype which has utility function for converting from and into Unix timestamp.- Timestamp handling in MAVLink documentation.
sourcepub fn body_length(&self) -> usize
pub fn body_length(&self) -> usize
sourcepub fn calculate_crc(&self, crc_extra: CrcExtra) -> Checksum
pub fn calculate_crc(&self, crc_extra: CrcExtra) -> Checksum
sourcepub fn validate_checksum(&self, dialect_spec: &dyn DialectSpec) -> Result<()>
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
- Returns
CoreError::Messageif message discovery failed. - Returns
FrameError::InvalidChecksum(wrapped byCoreError) if checksum validation failed.
Links
- [
DialectSpec] for dialect specification. Frame::calculate_crcfor CRC implementation details.
sourcepub fn validate_checksum_with_crc_extra(
&self,
crc_extra: CrcExtra
) -> Result<()>
pub fn validate_checksum_with_crc_extra( &self, crc_extra: CrcExtra ) -> Result<()>
Validates Frame::checksum using provided crc_extra.
Links
Frame::calculate_crcfor CRC implementation details.
sourcepub fn add_signature(
&mut self,
signer: &mut dyn Sign,
conf: SignatureConf
) -> Result<&mut Self>
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.
Links
Signtrait.Signaturestruct which contains frame signature.- MAVLink 2 message signing.
sourcepub fn replace_signature(
&mut self,
signer: &mut dyn Sign,
conf: SignatureConf
) -> Result<&mut Self>
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
- Returns
FrameError::SigningIsNotSupportedwhen caller attempts to signMAVLink 1frame. - Returns
FrameError::SignatureFieldsAreMissingif frame is not already signed.
Links
Signtrait.Signaturestruct which contains frame signature.- MAVLink 2 message signing.
sourcepub fn remove_signature(&mut self) -> &mut Self
pub fn remove_signature(&mut self) -> &mut Self
Removes MAVLink 2 signature from Frame.
Applicable only for MAVLink 2 frames.
sourcepub fn calculate_signature(
&self,
signer: &mut dyn Sign,
secret_key: &SecretKey
) -> Result<SignatureValue>
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.
Links
Signtrait.Signaturestruct which contains frame signature.- MAVLink 2 message signing.