AprsMessenger

Struct AprsMessenger 

Source
pub struct AprsMessenger { /* private fields */ }
Expand description

Manages APRS message send/receive with automatic ack/retry.

Queues outbound messages, assigns sequence IDs, tracks pending acknowledgements, generates retry frames on schedule, and suppresses duplicate deliveries of the same incoming message via a rolling (source, msgno) cache.

Implementations§

Source§

impl AprsMessenger

Source

pub fn new( callsign: Ax25Address, digipeater_path: Vec<Ax25Address>, ) -> AprsMessenger

Create a new messenger with the default config.

Source

pub fn with_config( callsign: Ax25Address, digipeater_path: Vec<Ax25Address>, config: MessengerConfig, ) -> AprsMessenger

Create a new messenger with a caller-supplied MessengerConfig.

Source

pub fn send_message( &mut self, addressee: &str, text: &str, now: Instant, ) -> String

Queue a message for transmission. Returns the assigned message ID.

The message is immediately available from next_frame_to_send. Text longer than MAX_APRS_MESSAGE_TEXT_LEN (67 bytes, APRS 1.0.1 §14) is silently truncated; use Self::send_message_checked if you want a hard error instead.

now is used to initialise the message’s last_sent timestamp to a time in the past so the message is immediately eligible for transmission on the next call to next_frame_to_send.

Source

pub fn next_frame_to_send(&mut self, now: Instant) -> Option<Vec<u8>>

Get the next frame that needs to be sent (initial or retry).

Returns None if no messages need sending right now. Retries happen at MessengerConfig::retry_interval, up to MessengerConfig::max_retries attempts.

now is compared against each pending message’s last_sent to decide whether the retry interval has elapsed.

Source

pub fn send_message_checked( &mut self, addressee: &str, text: &str, now: Instant, ) -> Result<String, AprsError>

Like Self::send_message but returns Err(MessageTooLong) if the text exceeds the APRS 1.0.1 §14 limit of 67 bytes.

§Errors

Returns AprsError::MessageTooLong when the text is too long.

Source

pub fn is_new_incoming( &mut self, source: &str, msg: &AprsMessage, now: Instant, ) -> bool

Check whether an incoming message is a duplicate of one recently seen from the same source station with the same msgno.

Returns true if this is a new message (first time seen within INCOMING_DEDUP_WINDOW), false if it’s a duplicate that should be ignored by the caller. Stateful: records the message in the dedup cache on true. Messages without a message_id are always considered new.

now is used to expire stale dedup entries and to record the arrival time of the current message.

Source

pub fn process_incoming(&mut self, msg: &AprsMessage) -> bool

Process an incoming APRS message.

If the text is an ack or rej control frame (per classify_ack_rej) for a pending message, removes the pending entry and returns true. Returns false for regular messages, including ones that happen to start with the letters ack/rej but aren’t valid control frames.

Source

pub fn build_ack(&self, from: &str, message_id: &str) -> Vec<u8>

Build an ack frame for a received message.

The ack is sent back to from with text ack{message_id}.

Source

pub fn build_rej(&self, from: &str, message_id: &str) -> Vec<u8>

Build a rej (reject) frame for a received message.

The rej is sent back to from with text rej{message_id}.

Source

pub fn cleanup_expired(&mut self, _now: Instant) -> Vec<String>

Remove expired messages (those that have reached MAX_RETRIES attempts) and return their message IDs so callers can notify upstream.

Takes now: Instant for API consistency with the other time-aware methods even though no clock-dependent logic is currently used here — the decision is based on attempt count, not elapsed time.

Source

pub const fn pending_count(&self) -> usize

Number of pending (unacknowledged) messages.

Trait Implementations§

Source§

impl Debug for AprsMessenger

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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