pub struct SensorLoggerAsync<L, Clock>{ /* private fields */ }Expand description
Async version of SensorLogger, wrapping any LogSinkAsync.
All logging methods are async fn and take &mut self. For query access,
use sink_mut() to reach the wrapped log.
§Example
use sensor_db::{SensorDbAsync, SensorLoggerAsync};
let db: SensorDbAsync<_, 256, 32> = SensorDbAsync::new(flash, 0, 32, 2)?;
let mut logger = SensorLoggerAsync::new(db, || get_timestamp_us());
logger.log(&Temperature { celsius: 25.5 }).await?;
logger.sync().await?;Implementations§
Source§impl<L, Clock> SensorLoggerAsync<L, Clock>
impl<L, Clock> SensorLoggerAsync<L, Clock>
Sourcepub fn new(sink: L, clock: Clock) -> Self
pub fn new(sink: L, clock: Clock) -> Self
Create a new SensorLoggerAsync wrapping an existing log.
§Arguments
sink: A mounted (or freshly formatted) async logclock: Function returning the current timestamp asu64
Sourcepub async fn log<T: SensorData>(&mut self, data: &T) -> Result<(), Error>
pub async 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 async fn log_raw(
&mut self,
sensor_id: u16,
payload: &[u8],
) -> Result<(), Error>
pub async 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 async fn log_value<T: IntoBytes + Immutable>(
&mut self,
sensor_id: u16,
data: &T,
) -> Result<(), Error>
pub async 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 async fn sync(&mut self) -> Result<(), Error>
pub async fn sync(&mut self) -> Result<(), Error>
Flush the page buffer to flash.
Delegates to LogSinkAsync::sync.
Sourcepub fn sink_mut(&mut self) -> &mut L
pub fn sink_mut(&mut self) -> &mut L
Mutable access to the wrapped log.
Every async read takes &mut self, so this is the accessor to reach for
— unlike the blocking logger, where sink() covers reads.
Sourcepub fn sink(&self) -> &L
pub fn sink(&self) -> &L
Immutable access to the wrapped log.
Only useful for non-flash methods like stats(), is_mounted(),
and max_payload_size().
Sourcepub fn into_inner(self) -> (L, Clock)
pub fn into_inner(self) -> (L, Clock)
Consume the logger and return the wrapped log and clock.