pub struct RobotClock { /* private fields */ }Expand description
A running Robot clock. The clock is a monotonic clock that starts at an arbitrary reference time. It is clone resilient, ie a clone will be the same clock, even when mocked.
Implementations§
Source§impl RobotClock
impl RobotClock
Sourcepub fn new_with_rtc(
read_rtc_ns: impl Fn() -> u64 + Send + Sync + 'static,
sleep_ns: impl Fn(u64) + Send + Sync + 'static,
) -> Self
pub fn new_with_rtc( read_rtc_ns: impl Fn() -> u64 + Send + Sync + 'static, sleep_ns: impl Fn(u64) + Send + Sync + 'static, ) -> Self
Calibrates the architecture counter against an application RTC.
Sourcepub fn from_ref_time(ref_time_ns: u64) -> Self
pub fn from_ref_time(ref_time_ns: u64) -> Self
Builds a monotonic clock starting at the requested reference time.
Sourcepub fn from_ref_time_with_rtc(
read_rtc_ns: fn() -> u64,
sleep_ns: fn(u64),
ref_time_ns: u64,
) -> Self
pub fn from_ref_time_with_rtc( read_rtc_ns: fn() -> u64, sleep_ns: fn(u64), ref_time_ns: u64, ) -> Self
Builds a clock starting at the requested time using an application RTC.
Sourcepub fn from_ref_time_with_origin(ref_time_ns: u64, origin: ClockOrigin) -> Self
pub fn from_ref_time_with_origin(ref_time_ns: u64, origin: ClockOrigin) -> Self
Builds a local monotonic clock at provider-selected reference nanoseconds.
Metadata never transforms the timestamp or implies live synchronization.
Sourcepub fn from_ref_time_with_rtc_and_origin(
read_rtc_ns: fn() -> u64,
sleep_ns: fn(u64),
ref_time_ns: u64,
origin: ClockOrigin,
) -> Self
pub fn from_ref_time_with_rtc_and_origin( read_rtc_ns: fn() -> u64, sleep_ns: fn(u64), ref_time_ns: u64, origin: ClockOrigin, ) -> Self
Builds a clock at a named epoch using application RTC calibration.
The RTC only calibrates elapsed time; origin describes the supplied epoch.
Sourcepub fn mock() -> (Self, RobotClockMock)
pub fn mock() -> (Self, RobotClockMock)
Builds a clock controlled by a mock, shared by all clones.
Sourcepub fn now(&self) -> CuTime
pub fn now(&self) -> CuTime
Reads execution time: local elapsed time, or the selected reference epoch.
Sourcepub fn origin(&self) -> ClockOrigin
pub fn origin(&self) -> ClockOrigin
Describes the source and epoch of execution timestamps without converting them.
Reference metadata is published with the execution mapping and shared by clones. Before initial acquisition, the local origin remains in effect. During resynchronization, the previous epoch remains in effect while the execution clock slews. Providers must preserve the epoch across resync. This accessor performs no counter read, allocation, or reference I/O.
use cu29_clock::{ClockEpoch, ClockSource, RobotClock};
let (clock, _) = RobotClock::mock();
assert_eq!(clock.origin().source, ClockSource::Mock);
assert_eq!(clock.origin().epoch, ClockEpoch::Local);Sourcepub fn recent(&self) -> CuTime
pub fn recent(&self) -> CuTime
Reads the same timeline through the backend’s recent-time operation.
Sourcepub fn raw_now(&self) -> CuInstant
pub fn raw_now(&self) -> CuInstant
Reads undisciplined local counter time in nanoseconds.
Clones share the counter origin and calibration. Independently constructed clocks have their own origins; compare raw readings only within one clock and its clones. Reference capture and elapsed-time measurements use this timeline, which is unaffected by execution-clock synchronization.
use cu29_clock::{CuDuration, RobotClock};
let (clock, control) = RobotClock::mock();
let start = clock.raw_now();
control.increment(CuDuration::from_millis(1));
assert_eq!(clock.raw_now() - start, CuDuration::from_millis(1));Sourcepub fn busy_wait_for(&self, duration: CuDuration)
pub fn busy_wait_for(&self, duration: CuDuration)
Spins for a duration measured on this clock’s undisciplined timeline.
Sourcepub fn busy_wait_until(&self, time: CuInstant)
pub fn busy_wait_until(&self, time: CuInstant)
Spins until a raw deadline from this clock or one of its clones.
Sourcepub fn sync_status(&self) -> Option<SyncStatus>
pub fn sync_status(&self) -> Option<SyncStatus>
Current domain, uncertainty and synchronization health.
Available with or without clock-sync. Returns None when synchronization
is disabled or no discipline has been published. Without the feature this
does not read the counter or require synchronization storage.
use cu29_clock::{RobotClock, sync::SyncStatus};
let (clock, _) = RobotClock::mock();
let quality: Option<SyncStatus> = clock.sync_status();
assert_eq!(quality, None);