Struct AsyncMavConn

Source
pub struct AsyncMavConn<M: Message> { /* private fields */ }
Expand description

An async adapter for a MAVLink connection

Offers high level functionality to interact with a MAVLink vehicle in an async fashion.

Implementations§

Source§

impl<M: 'static + Message + Clone + Send + Sync> AsyncMavConn<M>

Source

pub fn new( address: &str, mavlink_version: MavlinkVersion, ) -> Result<(Arc<Self>, impl Future<Output = impl Send> + Send), AsyncMavlinkError>

Construct a new MavlinkConnectionHandler

§Arguments
  • address - MAVLink connection &str. Equivalent to the address argument in mavlink::connect
§Examples
use async_mavlink::prelude::*;
use mavlink::{MavlinkVersion, common::MavMessage};
use smol::prelude::*;

smol::block_on(async {
    let (conn, future) = AsyncMavConn::new("udpbcast:127.0.0.2:14551", MavlinkVersion::V1)?;
    smol::spawn(async move { future.await }).detach();
    // ...
})
Source

pub async fn subscribe( &self, message_type: MavMessageType<M>, ) -> Result<Pin<Box<dyn Stream<Item = M>>>, AsyncMavlinkError>

Subscribe to all new MavMessages of the given MavMessageType

This returns a never-ending Stream of MavMessages.

§Arguments
  • message_type - MavMessageType of the desired messages
§Examples
let message_type = MavMessageType::new(&MavMessage::PARAM_VALUE(Default::default()));
let mut stream = conn.subscribe(message_type).await?;
while let Some(MavMessage::PARAM_VALUE(data)) = (stream.next()).await {
    // do something with `data`
}
Source

pub async fn request(&self, message_type: MavMessageType<M>) -> M

Awaits the next MavMessage of the given MavMessageType

§Arguments
  • message_type - MavMessageType of the desired messages
§Examples
let message_type = MavMessageType::new(&MavMessage::PARAM_VALUE(Default::default()));

if let MavMessage::PARAM_VALUE(data) = conn.request(message_type).await {
    // do something with `data`
}
Source

pub async fn send( &self, header: &MavHeader, message: &M, ) -> Result<(), AsyncMavlinkError>

Send a MavMessage to the vehicle

§Arguments
  • message - MavMessage to send
§Examples
let header = MavHeader::default();
let message = MavMessage::PARAM_REQUEST_LIST(PARAM_REQUEST_LIST_DATA {
    target_component: 0,
    target_system: 0,
});

conn.send(&header, &message).await?;
Source

pub async fn send_default(&self, message: &M) -> Result<(), AsyncMavlinkError>

Send a MavMessage to the vehicle

§Arguments
  • message - MavMessage to send
§Examples
let message = MavMessage::PARAM_REQUEST_LIST(PARAM_REQUEST_LIST_DATA {
    target_component: 0,
    target_system: 0,
});

conn.send_default(&message).await?;
Source

pub async fn last_heartbeat(&self) -> Option<Instant>

Returns the Instant from the last received HEARTBEAT

Auto Trait Implementations§

§

impl<M> Freeze for AsyncMavConn<M>

§

impl<M> !RefUnwindSafe for AsyncMavConn<M>

§

impl<M> Send for AsyncMavConn<M>
where M: Send,

§

impl<M> Sync for AsyncMavConn<M>
where M: Send,

§

impl<M> Unpin for AsyncMavConn<M>

§

impl<M> !UnwindSafe for AsyncMavConn<M>

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