WallClockState

Struct WallClockState 

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

The wall clock, as an offset from a monotonic millisecond timer.

Every method takes the current monotonic reading rather than fetching one, which is what keeps this testable without a clock at all.

Implementations§

Source§

impl WallClockState

Source

pub const UNKNOWN: Self

A device that does not know what time it is, at UTC.

Source

pub const fn now(&self, monotonic_ms: u64) -> Option<u32>

The current time in Unix seconds, or None when unknown.

Source

pub const fn now_ms(&self, monotonic_ms: u64) -> Option<u64>

The current time in Unix milliseconds, or None when unknown.

A clock whose offset would put it before the epoch or past what PROP_TIME can carry reads as unknown rather than as a wrapped value: those are only reachable from an absurd set, and reporting a wrapped time is worse than reporting none.

Source

pub const fn local_now(&self, monotonic_ms: u64) -> Option<u32>

The local wall-clock reading in seconds — the time shifted by the configured zone — or None when the time is unknown.

A reading for presentation, not an instant: it does not name a point in time on its own, and nothing should send it anywhere.

Source

pub const fn is_set(&self) -> bool

Whether the device knows what time it is.

Source

pub const fn source(&self) -> Option<TimeSource>

Where the current reading came from, or None while unset.

Source

pub const fn tz_offset_min(&self) -> i16

Minutes east of UTC.

Source

pub const fn set_tz(&mut self, minutes: i16)

Set the time zone. Independent of the clock: the zone is known from commissioning, and changing it never makes the time known or unknown.

Source

pub const fn clear(&mut self)

Return the device to not knowing what time it is.

The zone survives, because where the device is has not changed.

Source

pub const fn apply( &mut self, epoch: u32, monotonic_ms: u64, source: TimeSource, trust_receiver: bool, ) -> Update

Offer a reading from source, applying the precedence rule.

trust_receiver is PROP_GNSS_TIME_TRUST. The rule:

  • TimeSource::Manual always applies. The operator is the more authoritative source by definition, including while the receiver is distrusted — distrusting the sky is why somebody would set the clock by hand.
  • TimeSource::GnssFix applies whenever the receiver is trusted, overwriting whatever was there. Every fix re-synchronizes the clock, which is what keeps it good over a long deployment.
  • TimeSource::GnssRtc applies only when trusted and the clock is unset. It is a boot-time restore, not a correction: the receiver may have re-synchronized its own RTC from a bad sky while the device was running, so it must not displace a reading that is already in hand.
  • TimeSource::ExternalRtc applies only when the clock is unset, for the same reason, but is not subject to the receiver trust flag — it is not the receiver.

Trait Implementations§

Source§

impl Clone for WallClockState

Source§

fn clone(&self) -> WallClockState

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for WallClockState

Source§

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

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

impl Default for WallClockState

Source§

fn default() -> Self

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

impl PartialEq for WallClockState

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for WallClockState

Source§

impl Eq for WallClockState

Source§

impl StructuralPartialEq for WallClockState

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.