Skip to main content

Counter

Struct Counter 

Source
pub struct Counter {
    pub free: Tracked,
    pub pulse: Tracked,
}
Expand description

Both counters a concentrator keeps.

Fields§

§free: Tracked

The one that free runs, which packets are stamped against.

§pulse: Tracked

The one a pulse per second line latches, which disciplines the other.

Implementations§

Source§

impl Counter

Source

pub const fn new() -> Counter

A counter that has read nothing yet.

§Returns

The counter, at zero and having seen no rollover.

Source

pub const fn read(&mut self, bytes: &[u8; 8]) -> (u32, u32)

Takes a reading from the eight bytes the chip answers with.

The pulse counter comes first and the free running one after it, each most significant byte first, and both are scaled from the 32 MHz they count at.

§Arguments
  • bytes - what the burst read answered with.
§Returns

The free running counter and then the pulse one, both in microseconds and both widened past any rollover seen so far.

§Examples
use pamoja_radios::sx1302::timestamp::Counter;

let mut counter = Counter::new();

// The free running counter reads 64 ticks, which is two microseconds.
let (free, pulse) = counter.read(&[0, 0, 0, 32, 0, 0, 0, 64]);
assert_eq!((free, pulse), (2, 1));
Source

pub const fn widened_packet(&self, packet: u32) -> u32

Widens the counter value a packet was stamped with.

A packet reading above the last counter reading was heard before the most recent rollover, not after it, so it belongs to the wrap count before this one.

§Arguments
  • packet - what the packet carried, in microseconds.
§Returns

The value widened past the rollovers seen so far.

§Examples
use pamoja_radios::sx1302::timestamp::Counter;

let mut counter = Counter::new();
counter.read(&[0, 0, 0, 0, 0, 0, 0, 32]);

// A packet heard just before the counter reading sits in the same stretch.
assert_eq!(counter.widened_packet(1), 1);

Trait Implementations§

Source§

impl Clone for Counter

Source§

fn clone(&self) -> Counter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Counter

Source§

impl Debug for Counter

Source§

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

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

impl Default for Counter

Source§

fn default() -> Counter

Returns the “default value” for a type. Read more
Source§

impl Eq for Counter

Source§

impl PartialEq for Counter

Source§

fn eq(&self, other: &Counter) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Counter

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.