Skip to main content

SensorLogger

Struct SensorLogger 

Source
pub struct SensorLogger<L, Clock>
where Clock: Fn() -> u64,
{ /* 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>
where L: LogSink, Clock: Fn() -> u64,

Source

pub fn new(sink: L, clock: Clock) -> Self

Create a new SensorLogger wrapping an existing log.

§Arguments
  • sink: A mounted (or freshly formatted) log
  • clock: Function returning the current timestamp as u64
Source

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.

Source

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 identifier
  • payload: Raw sensor data bytes
Source

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.

Source

pub fn sync(&mut self) -> Result<(), Error>

Flush the page buffer to flash.

Delegates to LogSink::sync.

Source

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.

Source

pub fn sink_mut(&mut self) -> &mut L

Mutable access to the wrapped log, for writes and queries.

Source

pub fn into_inner(self) -> (L, Clock)

Consume the logger and return the wrapped log and clock.

Auto Trait Implementations§

§

impl<L, Clock> Freeze for SensorLogger<L, Clock>
where L: Freeze, Clock: Freeze,

§

impl<L, Clock> RefUnwindSafe for SensorLogger<L, Clock>
where L: RefUnwindSafe, Clock: RefUnwindSafe,

§

impl<L, Clock> Send for SensorLogger<L, Clock>
where L: Send, Clock: Send,

§

impl<L, Clock> Sync for SensorLogger<L, Clock>
where L: Sync, Clock: Sync,

§

impl<L, Clock> Unpin for SensorLogger<L, Clock>
where L: Unpin, Clock: Unpin,

§

impl<L, Clock> UnsafeUnpin for SensorLogger<L, Clock>
where L: UnsafeUnpin, Clock: UnsafeUnpin,

§

impl<L, Clock> UnwindSafe for SensorLogger<L, Clock>
where L: UnwindSafe, Clock: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.