pub struct SensorLogger<L, Clock>{ /* private fields */ }Expand description
A convenience wrapper around a LogSink that automatically timestamps entries.
The Clock parameter is any Fn() -> u64 that returns the current timestamp
(typically microseconds since epoch). This avoids threading a timestamp through
every call site.
For query and read access, use sink() or
sink_mut() to reach the wrapped log — the logger
deliberately exposes no reads of its own, so nothing here has to be
duplicated when the log underneath changes.
Implementations§
Source§impl<L, Clock> SensorLogger<L, Clock>
impl<L, Clock> SensorLogger<L, Clock>
Sourcepub fn new(sink: L, clock: Clock) -> Self
pub fn new(sink: L, clock: Clock) -> Self
Create a new SensorLogger wrapping an existing log.
§Arguments
sink: A mounted (or freshly formatted) logclock: Function returning the current timestamp asu64
Sourcepub fn log<T: SensorData>(&mut self, data: &T) -> Result<(), Error>
pub fn log<T: SensorData>(&mut self, data: &T) -> Result<(), Error>
Log a typed sensor reading with an auto-generated timestamp.
The sensor ID is derived from T::SENSOR_ID.
Sourcepub fn log_raw(&mut self, sensor_id: u16, payload: &[u8]) -> Result<(), Error>
pub fn log_raw(&mut self, sensor_id: u16, payload: &[u8]) -> Result<(), Error>
Log a raw payload with an auto-generated timestamp.
§Arguments
sensor_id: Sensor identifierpayload: Raw sensor data bytes
Sourcepub fn log_value<T: IntoBytes + Immutable>(
&mut self,
sensor_id: u16,
data: &T,
) -> Result<(), Error>
pub fn log_value<T: IntoBytes + Immutable>( &mut self, sensor_id: u16, data: &T, ) -> Result<(), Error>
Log a typed value with an explicit sensor ID and auto-generated timestamp.
This is the Layer 1 equivalent — you provide the sensor ID, the clock provides the timestamp.
Sourcepub fn sync(&mut self) -> Result<(), Error>
pub fn sync(&mut self) -> Result<(), Error>
Flush the page buffer to flash.
Delegates to LogSink::sync.
Sourcepub fn sink(&self) -> &L
pub fn sink(&self) -> &L
Immutable access to the wrapped log.
Enough for the accessors that touch no flash —
stats, is_mounted, spool_stats and the
rest. Reads and writes both go through
sink_mut(), because reading flash is a &mut
operation.
Sourcepub fn sink_mut(&mut self) -> &mut L
pub fn sink_mut(&mut self) -> &mut L
Mutable access to the wrapped log, for writes and queries.
Sourcepub fn into_inner(self) -> (L, Clock)
pub fn into_inner(self) -> (L, Clock)
Consume the logger and return the wrapped log and clock.