Skip to main content

Xtime

Struct Xtime 

Source
pub struct Xtime {
    pub unit: u8,
    pub session: u8,
    pub micros: u64,
}
Expand description

A station clock value taken apart: the radio it was read on, the run of the station it belongs to, and the microseconds that run had counted.

A station reports every uplink with an xtime, and a server hands the same value back with the downlink that answers it, so the station knows which radio and which run the answer is timed against. The reference station writes the microseconds in bits 0 to 47, the run in bits 48 to 55, which it picks at random and never leaves at zero, and the radio in bits 56 to 62 (src/ral.h in lorabasics/basicstation). A value with a run past 31 is larger than a double holds exactly, which is why every reader here takes it as an integer.

§Examples

use pamoja_gateway::station::Xtime;

// A frame heard 3512.348611 seconds into the station's first run, on its only radio.
let heard = Xtime::new(0, 1, 3_512_348_611).expect("in range");
let carried = heard.value();
assert_eq!(Xtime::of(carried), heard);

// A radio past 127, or a run longer than 48 bits of microseconds, has no value.
assert_eq!(Xtime::new(128, 1, 0), None);
assert_eq!(Xtime::new(0, 1, 1 << 48), None);

Fields§

§unit: u8

The radio unit the time was read on, 0 to 127.

§session: u8

The run of the station the time belongs to.

§micros: u64

The microseconds the run had counted, below 2^48.

Implementations§

Source§

impl Xtime

Source

pub const fn new(unit: u8, session: u8, micros: u64) -> Option<Xtime>

Builds a clock value from its parts.

§Arguments
  • unit - the radio unit, 0 to 127.
  • session - the run of the station.
  • micros - the microseconds the run had counted.
§Returns

The value, or None when the unit is past 127 or the microseconds do not fit 48 bits.

Source

pub const fn value(self) -> i64

Returns the value a message carries.

§Returns

The xtime.

Source

pub const fn of(value: i64) -> Xtime

Takes apart a value a message carried.

§Arguments
  • value - the xtime.
§Returns

Its radio unit, run, and microseconds.

Trait Implementations§

Source§

impl Clone for Xtime

Source§

fn clone(&self) -> Xtime

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 Xtime

Source§

impl Debug for Xtime

Source§

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

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

impl Eq for Xtime

Source§

impl PartialEq for Xtime

Source§

fn eq(&self, other: &Xtime) -> 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 Xtime

Auto Trait Implementations§

§

impl Freeze for Xtime

§

impl RefUnwindSafe for Xtime

§

impl Send for Xtime

§

impl Sync for Xtime

§

impl Unpin for Xtime

§

impl UnsafeUnpin for Xtime

§

impl UnwindSafe for Xtime

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> Same for T

Source§

type Output = T

Should always be Self
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.