bacnet-time
The time the portable cores of
rusty-bacnet share: a monotonic
Instant and a Duration, both counted in nanoseconds on a u64.
bacnet-mstp-core, bacnet-bip-core and bacnet-router-core take it, so
firmware that runs several of them feeds them one clock.
#![no_std], no allocator, no dependencies, no features.- The epoch is yours: the cores read no clock, and each call that depends on
time takes
now. Au64of nanoseconds lasts about 584 years. +and-saturate, and every operation has achecked_*form that returnsNoneinstead. Nothing panics.- Unit constructors (
from_micros,from_millis,from_secs) areconstand saturate; unit accessors (as_micros,as_millis,as_secs) round toward zero. - Conversions with
core::time::Duration, so a host maps its monotonic clock onto the timeline exactly:Frominto it, andTryFromback, which refuses a length past about 584 years, or theconstDuration::saturating_from_core, which clamps it. constminandmax, and aDebugwith the unit:Duration(1500ns).- No 64-bit division: on a 32-bit target, where dividing a
u64links a routine of about 1 KB, the accessors,checked_rem, the conversion tocore::time::DurationandDebuguse binary long division.
Example
use ;
// Firmware with a millisecond tick.
let now = from_millis;
let deadline = now + from_millis;
assert_eq!;
// Saturation, and the checked forms.
assert_eq!;
assert_eq!;
assert_eq!;
// A host's monotonic clock, through core::time::Duration.
let elapsed = from_micros;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
License
MIT