pub struct FrameBuilder<V: MaybeVersioned, L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, M: IsMsgId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> { /* private fields */ }
Expand description

Builder for Frame.

Frame builder is useful, when you want to build a frame manually. In most cases we suggest to use Endpoint::next_frame of a previously configured endpoint.

§Examples

Create a new frame from a heartbeat message using parameters of existing endpoint:

use mavio::dialects::minimal::messages::Heartbeat;
use mavio::prelude::*;

let endpoint = Endpoint::new::<V2>(MavLinkId::new(17, 42));

let frame = Frame::builder()
    .endpoint(&endpoint)
    .message(&Heartbeat::default()).unwrap()
    .build();

Create a new frame manually:

use mavio::dialects::minimal::messages::Heartbeat;
use mavio::protocol::{IntoPayload};
use mavio::prelude::*;

let message = Heartbeat::default();
let payload = message.encode(MavLinkVersion::V2).unwrap();

let frame = Frame::builder()
    .version(V2)
    .sequence(11)
    .system_id(17)
    .component_id(42)
    .message_id(Heartbeat::spec().id())
    .payload(payload.bytes())
    .crc_extra(Heartbeat::spec().crc_extra())
    .build();

Implementations§

source§

impl FrameBuilder<Versionless, Unset, Unset, Unset, Unset, Unset, Unset, Unset, Unset>

source

pub fn new() -> Self

Default constructor.

source§

impl<V: MaybeVersioned, L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, M: IsMsgId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>

source

pub fn sequence( self, sequence: Sequence ) -> FrameBuilder<V, L, Sequenced, S, C, M, P, E, Unset>

Set packet sequence number.

Drops previously set FrameBuilder::signature.

See: Frame::sequence.

source

pub fn system_id( self, system_id: SystemId ) -> FrameBuilder<V, L, Seq, HasSysId, C, M, P, E, Unset>

Set system ID.

Drops previously set FrameBuilder::signature.

See: Frame::system_id.

source

pub fn component_id( self, component_id: ComponentId ) -> FrameBuilder<V, L, Seq, S, HasCompId, M, P, E, Sig>

Set component ID.

See: Frame::component_id.

source§

impl<V: MaybeVersioned, L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> FrameBuilder<V, L, Seq, S, C, Unset, P, E, Sig>

source

pub fn message_id( self, message_id: MessageId ) -> FrameBuilder<V, L, Seq, S, C, HasMsgId, P, Unset, Unset>

Set message ID.

This method drops previously set FrameBuilder::crc_extra and FrameBuilder::signature and can be called only once.

See: Frame::message_id.

§Examples
use mavio::prelude::*;

let frame = Frame::builder()
    .message_id(0)
    /* other frame parameters */

This won’t compile:

use mavio::prelude::*;

let frame = Frame::builder()
    .message_id(0)
    .message_id(1)  // won't compile
    /* other frame parameters */
source§

impl<V: Versioned, L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> FrameBuilder<V, L, Seq, S, C, HasMsgId, P, E, Sig>

source

pub fn payload( self, bytes: &[u8] ) -> FrameBuilder<V, HasPayloadLen, Seq, S, C, HasMsgId, HasPayload, E, Unset>

Set payload bytes.

The size of the provided slice is not checked. Larger slices will be truncated and missing trailing bytes will be replaced with zeros.

This method drops previously set FrameBuilder::signature and available only once FrameBuilder::message_id and FrameBuilder::version are defined.

See: Frame::payload.

§Examples
use mavio::prelude::*;

let frame = Frame::builder()
    .message_id(0)
    .version(V2)
    .payload(&[0; 10]);
source§

impl<V: MaybeVersioned, L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, M: IsMsgId, P: IsPayload, Sig: IsSigned> FrameBuilder<V, L, Seq, S, C, M, P, Unset, Sig>

source

pub fn crc_extra( self, crc_extra: CrcExtra ) -> FrameBuilder<V, L, Seq, S, C, M, P, HasCrcExtra, Sig>

Set CRC_EXTRA.

source§

impl<L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, M: IsMsgId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> FrameBuilder<Versionless, L, Seq, S, C, M, P, E, Sig>

source

pub fn version<Version: Versioned>( self, version: Version ) -> FrameBuilder<Version, L, Seq, S, C, M, P, E, Sig>

Set MAVLink protocol version.

This method can be called only once. When MAVLink protocol version is set, it can’t be changed:

use mavio::protocol::{FrameBuilder, V1, V2};

FrameBuilder::new()
    .version(V1)
    .version(V2); // can't set MAVLink version twice!
source§

impl<L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, M: IsMsgId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> FrameBuilder<V2, L, Seq, S, C, M, P, E, Sig>

source

pub fn incompat_flags( self, incompat_flags: IncompatFlags ) -> FrameBuilder<V2, L, Seq, S, C, M, P, E, Sig>

Sets incompatibility flags for MAVLink 2 header.

Drops or sets MAVLINK_IFLAG_SIGNED incompatibility flag based on the presence of FrameBuilder::signature.

This method becomes available only once FrameBuilder::version is set to V2. So, the following is okay:

FrameBuilder::new()
    .version(V2)
    .incompat_flags(IncompatFlags::MAVLINK_IFLAG_SIGNED);

While this won’t compile:

FrameBuilder::new()
    .system_id(10)
    .incompat_flags(IncompatFlags::MAVLINK_IFLAG_SIGNED);  // Won't compile
source

pub fn compat_flags( self, compat_flags: CompatFlags ) -> FrameBuilder<V2, L, Seq, S, C, M, P, E, Sig>

Set compatibility flags for MAVLink 2 header.

This method becomes available only once FrameBuilder::version is set to V2. So, the following is okay:

FrameBuilder::new()
    .version(V2)
    .compat_flags(CompatFlags::BIT_1);

While this won’t compile:

FrameBuilder::new()
    .system_id(10)
    .compat_flags(CompatFlags::BIT_1);  // Won't compile
source

pub fn signature( self, signature: Signature ) -> Behold<FrameBuilder<V2, L, Seq, S, C, M, P, E, HasSignature>>

Set packet signature for MAVLink 2 header.

Setting signature manually is dangerous and may lead to creation of invalid frame. Use Frame::add_signature whenever possible. Still, we provide this method to use on your own discretion. The result is wrapped with Behold and marked as #[must_use] to give caller a hint.

This method becomes available only once FrameBuilder::version is set to V2. So, the following is okay:

FrameBuilder::new()
    .version(V2)
    .signature(Signature{
         // ...  
    }).discard();

While this won’t compile:

FrameBuilder::new()
    .system_id(10)
    .signature(Signature{
         // ...  
    }); // Won't compile
source§

impl<L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, M: IsMsgId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> FrameBuilder<Versionless, L, Seq, S, C, M, P, E, Sig>

source

pub fn endpoint<V: Versioned>( self, endpoint: &Endpoint<V> ) -> FrameBuilder<V, L, Sequenced, HasSysId, HasCompId, M, P, E, Sig>

Updates frame builder with parameters of a MAVlink Endpoint.

Defines the following fields:

§Examples
use mavio::prelude::*;
use mavio::protocol::{Endpoint, MavLinkId, FrameBuilder};

let device = Endpoint::new::<V2>(MavLinkId::new(1, 1));

FrameBuilder::new().endpoint(&device);
source§

impl<V: Versioned, L: IsPayloadLen, Seq: IsSequenced, S: IsSysId, C: IsCompId, M: IsMsgId, P: IsPayload, E: IsCrcExtra, Sig: IsSigned> FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>

source

pub fn message( self, message: &dyn Message ) -> Result<FrameBuilder<V, HasPayloadLen, Seq, S, C, HasMsgId, HasPayload, HasCrcExtra, Sig>>

Set MAVLink message.

Imports and encodes MAVLink message. Uses crc_extra from Message to create a checksum.

Uses message to define:

§Errors

Returns SpecError if message is misconfigured or does not support previously specified FrameBuilder::version.

source§

impl FrameBuilder<V1, HasPayloadLen, Sequenced, HasSysId, HasCompId, HasMsgId, HasPayload, HasCrcExtra, Unset>

source

pub fn upgrade( self ) -> FrameBuilder<V2, HasPayloadLen, Sequenced, HasSysId, HasCompId, HasMsgId, HasPayload, HasCrcExtra, Unset>

Upgrades from MAVlink 1 to MAVLink 2 protocol version.

Can be used in tandem with Frame::to_builder as a way to upgrade frames.

source§

impl<V: Versioned, Sig: IsSigned> FrameBuilder<V, HasPayloadLen, Sequenced, HasSysId, HasCompId, HasMsgId, HasPayload, HasCrcExtra, Sig>

source

pub fn build(self) -> Frame<V>

Build Frame for a specific MAVLink protocol version.

If you want a frame with opaque version, use Frame::into_versionless from the obtained frame.

Trait Implementations§

source§

impl<V: Clone + MaybeVersioned, L: Clone + IsPayloadLen, Seq: Clone + IsSequenced, S: Clone + IsSysId, C: Clone + IsCompId, M: Clone + IsMsgId, P: Clone + IsPayload, E: Clone + IsCrcExtra, Sig: Clone + IsSigned> Clone for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>

source§

fn clone(&self) -> FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>

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<V: Debug + MaybeVersioned, L: Debug + IsPayloadLen, Seq: Debug + IsSequenced, S: Debug + IsSysId, C: Debug + IsCompId, M: Debug + IsMsgId, P: Debug + IsPayload, E: Debug + IsCrcExtra, Sig: Debug + IsSigned> Debug for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>

source§

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

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

impl Default for FrameBuilder<Versionless, Unset, Unset, Unset, Unset, Unset, Unset, Unset, Unset>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, V, L, Seq, S, C, M, P, E, Sig> Deserialize<'de> for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>
where V: Deserialize<'de> + MaybeVersioned, L: Deserialize<'de> + IsPayloadLen, Seq: Deserialize<'de> + IsSequenced, S: Deserialize<'de> + IsSysId, C: Deserialize<'de> + IsCompId, M: Deserialize<'de> + IsMsgId, P: Deserialize<'de> + IsPayload, E: Deserialize<'de> + IsCrcExtra, Sig: Deserialize<'de> + IsSigned,

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, L, Seq, S, C, M, P, E, Sig> Serialize for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>
where V: Serialize + MaybeVersioned, L: Serialize + IsPayloadLen, Seq: Serialize + IsSequenced, S: Serialize + IsSysId, C: Serialize + IsCompId, M: Serialize + IsMsgId, P: Serialize + IsPayload, E: Serialize + IsCrcExtra, Sig: Serialize + IsSigned,

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<V, L, Seq, S, C, M, P, E, Sig> Freeze for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>
where C: Freeze, E: Freeze, L: Freeze, M: Freeze, P: Freeze, S: Freeze, Seq: Freeze, Sig: Freeze,

§

impl<V, L, Seq, S, C, M, P, E, Sig> RefUnwindSafe for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>

§

impl<V, L, Seq, S, C, M, P, E, Sig> Send for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>
where C: Send, E: Send, L: Send, M: Send, P: Send, S: Send, Seq: Send, Sig: Send,

§

impl<V, L, Seq, S, C, M, P, E, Sig> Sync for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>
where C: Sync, E: Sync, L: Sync, M: Sync, P: Sync, S: Sync, Seq: Sync, Sig: Sync,

§

impl<V, L, Seq, S, C, M, P, E, Sig> Unpin for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>
where C: Unpin, E: Unpin, L: Unpin, M: Unpin, P: Unpin, S: Unpin, Seq: Unpin, Sig: Unpin, V: Unpin,

§

impl<V, L, Seq, S, C, M, P, E, Sig> UnwindSafe for FrameBuilder<V, L, Seq, S, C, M, P, E, Sig>

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