Skip to content

Commit

Permalink
sameold: rename SameEvent → SameReceiverEvent
Browse files Browse the repository at this point in the history
Rename the `SameEvent` to `SameReceiverEvent`. The `SameReceiver`
uses this type to communicate modem status changes, such as the
acquisition and/or loss of carrier. The old name was somewhat
ambiguous with `EventCode`, and the rename helps disambiguate them.

This is an API-BREAKING change.
  • Loading branch information
cbs228 committed Feb 24, 2024
1 parent 1af7ea1 commit 6cc9860
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion crates/sameold/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Events from both layers can be captured using the
[`iter_events()`](https://docs.rs/sameold/latest/sameold/struct.SameReceiver.html#method.iter_events)
method instead of `iter_messages()`. The events iterator can be used to obtain
raw framed
[bursts](https://docs.rs/sameold/latest/sameold/struct.SameEvent.html#method.burst)
[bursts](https://docs.rs/sameold/latest/sameold/struct.SameReceiverEvent.html#method.burst)
without delay or error-correction. Events can also report the detection of SAME
carrier signals before and during message decoding.

Expand Down
6 changes: 3 additions & 3 deletions crates/sameold/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
//! Events from both layers can be captured using the
//! [`iter_events()`](crate::SameReceiver::iter_events) method instead of
//! `iter_messages()`. The events iterator can be used to obtain raw framed
//! [bursts](crate::SameEvent::burst) without delay or error-correction.
//! [bursts](crate::SameReceiverEvent::burst) without delay or error-correction.
//! Events can also report the detection of SAME carrier signals before and
//! during message decoding.
//!
Expand Down Expand Up @@ -238,6 +238,6 @@ pub use message::{
Phenomenon, SignificanceLevel,
};
pub use receiver::{
EqualizerBuilder, LinkState, SameEvent, SameEventType, SameReceiver, SameReceiverBuilder,
TransportState,
EqualizerBuilder, LinkState, SameEventType, SameReceiver, SameReceiverBuilder,
SameReceiverEvent, TransportState,
};
19 changes: 11 additions & 8 deletions crates/sameold/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::convert::From;
use std::iter::{IntoIterator, Iterator};

pub use self::builder::{EqualizerBuilder, SameReceiverBuilder};
pub use self::output::{LinkState, SameEvent, SameEventType, TransportState};
pub use self::output::{LinkState, SameEventType, SameReceiverEvent, TransportState};

use crate::Message;

Expand Down Expand Up @@ -83,7 +83,7 @@ pub struct SameReceiver {
input_sample_counter: u64,
link_state: LinkState,
transport_state: TransportState,
event_queue: std::collections::VecDeque<SameEvent>,
event_queue: std::collections::VecDeque<SameReceiverEvent>,
ted_sample_clock: u32,
samples_until_next_ted: f32,
force_eom_at_sample: Option<u64>,
Expand All @@ -93,7 +93,7 @@ impl SameReceiver {
/// Decode events and messages from a source of audio
///
/// Bind an iterator which will consume the `input` and
/// produce SAME [`SameEvent`] events, which include:
/// produce SAME [`SameReceiverEvent`] events, which include:
///
/// * notifications about acquired and dropped carrier,
/// * attempts to frame messages; and
Expand All @@ -116,7 +116,10 @@ impl SameReceiver {
/// instead if you are only interested in successful
/// decodes.
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub fn iter_events<'rx, I>(&'rx mut self, input: I) -> impl Iterator<Item = SameEvent> + 'rx
pub fn iter_events<'rx, I>(
&'rx mut self,
input: I,
) -> impl Iterator<Item = SameReceiverEvent> + 'rx
where
I: IntoIterator<Item = f32> + 'rx,
{
Expand Down Expand Up @@ -227,7 +230,7 @@ impl SameReceiver {
/// exhausted or an event of interest to the modem occurs. If
/// one does, it is emitted.
#[inline]
fn process<I>(&mut self, audio_iter: &mut I) -> Option<SameEvent>
fn process<I>(&mut self, audio_iter: &mut I) -> Option<SameReceiverEvent>
where
I: Iterator<Item = f32>,
{
Expand All @@ -243,7 +246,7 @@ impl SameReceiver {
if link_state != self.link_state {
// report change
self.link_state = link_state.clone();
self.event_queue.push_back(SameEvent::new(
self.event_queue.push_back(SameReceiverEvent::new(
self.link_state.clone(),
self.input_sample_counter,
));
Expand All @@ -255,7 +258,7 @@ impl SameReceiver {
.filter(|newstate| newstate != &self.transport_state)
{
self.transport_state = transport_state;
self.event_queue.push_back(SameEvent::new(
self.event_queue.push_back(SameReceiverEvent::new(
self.transport_state.clone(),
self.input_sample_counter,
));
Expand Down Expand Up @@ -569,7 +572,7 @@ impl<'rx, 'data, I> Iterator for SameReceiverIter<'rx, I>
where
I: Iterator<Item = f32>,
{
type Item = SameEvent;
type Item = SameReceiverEvent;

fn next(&mut self) -> Option<Self::Item> {
self.receiver.process(&mut self.source).and_then(|evt| {
Expand Down
30 changes: 15 additions & 15 deletions crates/sameold/src/receiver/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ use crate::message::{Message, MessageResult};
/// times for redundancy. These retransmissions are combined
/// together to form a single [`Message`] estimate.
///
/// The [`what()`](SameEvent::what) method returns the event,
/// The [`what()`](SameReceiverEvent::what) method returns the event,
/// which may originate from either layer.
///
/// You can also query for the
/// [`message()`](SameEvent::message) or an individual
/// [`burst()`](SameEvent::burst) estimate, if one is
/// [`message()`](SameReceiverEvent::message) or an individual
/// [`burst()`](SameReceiverEvent::burst) estimate, if one is
/// available now. Not all events have either of these things
/// to report.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct SameEvent {
pub struct SameReceiverEvent {
what: SameEventType,
input_sample_counter: u64,
}

impl SameEvent {
impl SameReceiverEvent {
/// Message or message decoding error, if any
///
/// If the current update includes a message or a reportable
Expand All @@ -44,7 +44,7 @@ impl SameEvent {
/// If the current update includes a successfully-decoded
/// message, returns it. If no message is available, returns
/// `None`. Consider using
/// [`message()`](SameEvent::message()) instead to
/// [`message()`](SameReceiverEvent::message()) instead to
/// report errors.
pub fn message_ok(&self) -> Option<&Message> {
match self.what() {
Expand Down Expand Up @@ -74,7 +74,7 @@ impl SameEvent {
///
/// Clients **MUST NOT** report a single burst as a
/// SAME message. Messages should instead be obtained from
/// from the transport layer's [`message()`](SameEvent::message).
/// from the transport layer's [`message()`](SameReceiverEvent::message).
pub fn burst(&self) -> Option<&[u8]> {
match self.what() {
SameEventType::Link(LinkState::Burst(res)) => Some(res.as_ref()),
Expand All @@ -98,7 +98,7 @@ impl SameEvent {
///
/// If the current update includes a successfully-decoded
/// message, returns it. If no message is available, returns
/// `None`. Consider using [`SameEvent::into_message`] instead.
/// `None`. Consider using [`SameReceiverEvent::into_message`] instead.
pub fn into_message_ok(self) -> Option<Message> {
match self.what {
SameEventType::Transport(TransportState::Message(res)) => res.ok(),
Expand All @@ -123,7 +123,7 @@ impl SameEvent {
}
}

impl SameEvent {
impl SameReceiverEvent {
/// Create from event and time
pub(crate) fn new<E>(what: E, input_sample_counter: u64) -> Self
where
Expand All @@ -136,19 +136,19 @@ impl SameEvent {
}
}

impl From<SameEvent> for Option<MessageResult> {
fn from(rx: SameEvent) -> Self {
impl From<SameReceiverEvent> for Option<MessageResult> {
fn from(rx: SameReceiverEvent) -> Self {
rx.into_message()
}
}

impl From<SameEvent> for Option<Message> {
fn from(rx: SameEvent) -> Self {
impl From<SameReceiverEvent> for Option<Message> {
fn from(rx: SameReceiverEvent) -> Self {
rx.into_message_ok()
}
}

impl std::fmt::Display for SameEvent {
impl std::fmt::Display for SameReceiverEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
Expand All @@ -161,7 +161,7 @@ impl std::fmt::Display for SameEvent {

/// Type of event
///
/// See [`SameEvent`]
/// See [`SameReceiverEvent`]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum SameEventType {
/// Link layer event
Expand Down

0 comments on commit 6cc9860

Please sign in to comment.