Skip to main content

Connection

Struct Connection 

Source
pub struct Connection<L> { /* private fields */ }
Expand description

A MAVLink endpoint over a ByteLink: sends and receives whole messages, and signs and verifies them when configured to.

A connection owns its sending identity and sequence counter, a streaming Parser for the bytes it reads, and optional signing. Attach a Signer to sign every outgoing frame and a Verifier to check every signed incoming one.

Implementations§

Source§

impl<L: ByteLink> Connection<L>

Source

pub fn new(link: L, system_id: u8, component_id: u8) -> Self

Creates a connection that sends as the given system and component.

§Arguments
  • link - the byte stream to carry frames over.
  • system_id - this endpoint’s system id.
  • component_id - this endpoint’s component id.
§Returns

The connection, with signing off.

Source

pub fn with_signer(self, signer: Signer) -> Self

Signs every outgoing frame with signer.

§Arguments
  • signer - the signer to stamp outgoing frames with.
§Returns

The connection, for chaining.

Source

pub fn with_verifier(self, verifier: Verifier) -> Self

Verifies signed incoming frames with verifier, and rejects unsigned ones.

§Arguments
  • verifier - the verifier to check incoming signed frames with.
§Returns

The connection, for chaining.

Source

pub async fn send<M: Message>(&mut self, message: &M) -> Result<()>

Sends a typed message, signing it if a signer is attached.

§Arguments
  • message - the message to send.
§Returns

Ok(()) once the frame has been written to the link.

§Errors

Returns MavlinkError::PayloadTooLong if the message does not fit a frame, or a link error from the underlying ByteLink.

Source

pub async fn recv(&mut self) -> Result<Frame>

Receives the next whole frame from the link, verifying its signature if required.

§Returns

The next valid frame.

§Errors

Returns MavlinkError::Closed if the link ends before a frame arrives, MavlinkError::Unsigned if a signature is required but the frame is unsigned, MavlinkError::BadSignature or MavlinkError::ReplayedTimestamp if a signed frame does not verify, or a link error from the underlying ByteLink.

Returns a shared reference to the underlying link.

§Returns

The link.

Auto Trait Implementations§

§

impl<L> Freeze for Connection<L>
where L: Freeze,

§

impl<L> RefUnwindSafe for Connection<L>
where L: RefUnwindSafe,

§

impl<L> Send for Connection<L>
where L: Send,

§

impl<L> Sync for Connection<L>
where L: Sync,

§

impl<L> Unpin for Connection<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for Connection<L>
where L: UnsafeUnpin,

§

impl<L> UnwindSafe for Connection<L>
where L: UnwindSafe,

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

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.