AsyncModem

Struct AsyncModem 

Source
pub struct AsyncModem<T: Transport + 'static> { /* private fields */ }
Expand description

Async handle to an MMDVM modem running in a spawned tokio task.

The handle is generic over the transport type T so that AsyncModem::shutdown can recover the original transport for reuse (e.g. to send post-MMDVM CAT commands on the same serial port).

Dropping the handle closes the command channel, which causes the spawned loop to exit on its next iteration. For a graceful shutdown that also flushes the pending TX queue AND recovers the inner transport, call AsyncModem::shutdown.

Implementations§

Source§

impl<T: Transport + 'static> AsyncModem<T>

Source

pub fn spawn(transport: T) -> Self

Spawn the modem loop on the current tokio runtime and return a handle for controlling it.

The transport must be an already-connected duplex byte stream (serial port, Bluetooth SPP, test duplex). The shell takes ownership; it is automatically dropped when the loop exits.

§Example
use mmdvm::AsyncModem;
use tokio::io::duplex;

let (client, _modem_side) = duplex(4096);
let mut modem = AsyncModem::spawn(client);
while let Some(event) = modem.next_event().await {
    println!("{event:?}");
}
Source

pub async fn next_event(&mut self) -> Option<Event>

Pull the next event from the modem loop.

Returns None once the task has exited and the event channel has been fully drained.

§Cancellation safety

Cancel-safe — backed by tokio::sync::mpsc::Receiver::recv.

Source

pub async fn send_dstar_header( &mut self, bytes: [u8; 41], ) -> Result<(), ShellError>

Enqueue a D-STAR header for transmission.

The frame is placed in the loop’s TX queue and drained only when the modem reports enough D-STAR FIFO space.

§Errors
Source

pub async fn send_dstar_data( &mut self, bytes: [u8; 12], ) -> Result<(), ShellError>

Enqueue a D-STAR voice data frame for transmission.

§Errors
Source

pub async fn send_dstar_eot(&mut self) -> Result<(), ShellError>

Enqueue a D-STAR end-of-transmission marker.

§Errors
Source

pub async fn set_mode(&mut self, mode: ModemMode) -> Result<(), ShellError>

Set the modem’s operating mode.

§Errors
Source

pub async fn request_version(&mut self) -> Result<(), ShellError>

Trigger a GetVersion request. The response arrives as Event::Version.

§Errors
Source

pub async fn request_status(&mut self) -> Result<(), ShellError>

Trigger an immediate GetStatus request. The response arrives as Event::Status. The loop also polls status every 250 ms on its own, so this is only needed for explicit “check now” flows.

§Errors
Source

pub async fn send_raw( &mut self, command: u8, payload: Vec<u8>, ) -> Result<(), ShellError>

Send a raw frame — escape hatch for protocols we don’t model yet.

§Errors
Source

pub async fn shutdown(self) -> Result<T, ShellError>

Graceful shutdown — flushes the TX queue, exits the loop, and returns the recovered transport.

Consumes the handle. After shutdown returns, the task has fully wound down and ownership of the transport is handed back to the caller so it can be reused (e.g. to switch back to CAT mode on a serial port).

§Errors
  • ShellError::SessionClosed if the loop had already exited before the shutdown command could be delivered, or the task panicked / was aborted before it could hand the transport back.

Trait Implementations§

Source§

impl<T: Debug + Transport + 'static> Debug for AsyncModem<T>

Source§

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

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

impl<T: Transport + 'static> Drop for AsyncModem<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AsyncModem<T>

§

impl<T> RefUnwindSafe for AsyncModem<T>

§

impl<T> Send for AsyncModem<T>

§

impl<T> Sync for AsyncModem<T>

§

impl<T> Unpin for AsyncModem<T>

§

impl<T> UnwindSafe for AsyncModem<T>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more