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
impl AprsMessenger
Sourcepub fn new(
callsign: Ax25Address,
digipeater_path: Vec<Ax25Address>,
) -> AprsMessenger
pub fn new( callsign: Ax25Address, digipeater_path: Vec<Ax25Address>, ) -> AprsMessenger
Create a new messenger with the default config.
Sourcepub fn with_config(
callsign: Ax25Address,
digipeater_path: Vec<Ax25Address>,
config: MessengerConfig,
) -> AprsMessenger
pub fn with_config( callsign: Ax25Address, digipeater_path: Vec<Ax25Address>, config: MessengerConfig, ) -> AprsMessenger
Create a new messenger with a caller-supplied MessengerConfig.
Sourcepub fn send_message(
&mut self,
addressee: &str,
text: &str,
now: Instant,
) -> String
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.
Sourcepub fn next_frame_to_send(&mut self, now: Instant) -> Option<Vec<u8>>
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.
Sourcepub fn send_message_checked(
&mut self,
addressee: &str,
text: &str,
now: Instant,
) -> Result<String, AprsError>
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.
Sourcepub fn is_new_incoming(
&mut self,
source: &str,
msg: &AprsMessage,
now: Instant,
) -> bool
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.
Sourcepub fn process_incoming(&mut self, msg: &AprsMessage) -> bool
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.
Sourcepub fn build_ack(&self, from: &str, message_id: &str) -> Vec<u8> ⓘ
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}.
Sourcepub fn build_rej(&self, from: &str, message_id: &str) -> Vec<u8> ⓘ
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}.
Sourcepub fn cleanup_expired(&mut self, _now: Instant) -> Vec<String>
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.
Sourcepub const fn pending_count(&self) -> usize
pub const fn pending_count(&self) -> usize
Number of pending (unacknowledged) messages.