Skip to content

Commit

Permalink
fix: read_v2_msg_async_inner, write_versioned_msg_async_signed
Browse files Browse the repository at this point in the history
doc: update for async
fix: remove unused serial code from async connection
  • Loading branch information
pv42 committed Sep 7, 2024
1 parent 2350411 commit 41e2ec1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
20 changes: 4 additions & 16 deletions mavlink-core/src/async_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ mod file;
#[cfg(feature = "signing")]
use crate::SigningConfig;

/// A MAVLink connection
/// An async MAVLink connection
#[async_trait::async_trait]
pub trait AsyncMavConnection<M: Message + Sync> {
/// Receive a mavlink message.
///
/// Blocks until a valid frame is received, ignoring invalid messages.
/// Wait until a valid frame is received, ignoring invalid messages.
async fn recv(&self) -> Result<(MavHeader, M), crate::error::MessageReadError>;

/// Send a mavlink message
Expand Down Expand Up @@ -61,7 +61,7 @@ pub trait AsyncMavConnection<M: Message + Sync> {
fn setup_signing(&mut self, signing_data: Option<SigningConfig>);
}

/// Connect to a MAVLink node by address string.
/// Connect asynchronously to a MAVLink node by address string.
///
/// The address must be in one of the following formats:
///
Expand All @@ -70,12 +70,11 @@ pub trait AsyncMavConnection<M: Message + Sync> {
/// * `udpin:<addr>:<port>` to create a UDP server, listening for incoming packets
/// * `udpout:<addr>:<port>` to create a UDP client
/// * `udpbcast:<addr>:<port>` to create a UDP broadcast
/// * NOT `serial:<port>:<baudrate>` to create a serial connection
/// * `file:<path>` to extract file data
///
/// Serial is currently not supported for async connections, use [`crate::connect`] instead.
/// The type of the connection is determined at runtime based on the address type, so the
/// connection is returned as a trait object.
// TODO only reason this has to be send is udp serve
pub async fn connect_async<M: Message + Sync + Send>(
address: &str,
) -> io::Result<Box<dyn AsyncMavConnection<M> + Sync + Send>> {
Expand All @@ -102,24 +101,13 @@ pub async fn connect_async<M: Message + Sync + Send>(
{
protocol_err
}
} else if cfg!(feature = "direct-serial") && address.starts_with("serial:") {
#[cfg(feature = "direct-serial")]
{
todo!()
//Ok(Box::new(direct_serial::open(&address["serial:".len()..])?))
}
#[cfg(not(feature = "direct-serial"))]
{
protocol_err
}
} else if address.starts_with("file") {
Ok(Box::new(file::open(&address["file:".len()..]).await?))
} else {
protocol_err
}
}

// TODO remove this ?
/// Returns the socket address for the given address.
pub(crate) fn get_socket_addr<T: std::net::ToSocketAddrs>(
address: T,
Expand Down
4 changes: 2 additions & 2 deletions mavlink-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ async fn read_v2_msg_async_inner<M: Message, R: tokio::io::AsyncReadExt + Unpin>
read: &mut AsyncPeekReader<R>,
signing_data: Option<&SigningData>,
) -> Result<(MavHeader, M), error::MessageReadError> {
let message = read_v2_raw_message_async_signed::<M, _>(read, signing_data).await?;
let message = read_v2_raw_message_async_inner::<M, _>(read, signing_data).await?;

Ok((
MavHeader {
Expand Down Expand Up @@ -1212,7 +1212,7 @@ pub async fn write_versioned_msg_async<M: Message, W: tokio::io::AsyncWriteExt +
}

/// Async write a message with signing support using the given mavlink version
#[cfg(feature = "tokio-1")]
#[cfg(all(feature = "tokio-1", feature = "signing"))]
pub async fn write_versioned_msg_async_signed<M: Message, W: tokio::io::AsyncWriteExt + Unpin>(
w: &mut W,
version: MavlinkVersion,
Expand Down

0 comments on commit 41e2ec1

Please sign in to comment.