Skip to content

Commit

Permalink
feat(sdr): log some info about Event-Only sensors in Loggable impl
Browse files Browse the repository at this point in the history
  • Loading branch information
datdenkikniet committed May 12, 2024
1 parent 0dfaec6 commit 3a0e9eb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/storage/sdr/record/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,14 @@ impl Record {
}
}

pub fn event_only(&self) -> Option<&EventOnlySensorRecord> {
if let RecordContents::EventOnlySensor(event) = &self.contents {
Some(event)
} else {
None
}
}

pub fn parse(data: &[u8]) -> Result<Self, ParseError> {
if data.len() < 5 {
return Err(ParseError::NotEnoughData);
Expand Down Expand Up @@ -887,13 +895,16 @@ impl Loggable for Record {
fn as_log(&self) -> Vec<crate::fmt::LogItem> {
let full = self.full_sensor();
let compact = self.compact_sensor();
let event_only = self.event_only();

let mut log = Vec::new();

if full.is_some() {
log.push((0, "SDR Record (Full)").into());
} else if compact.is_some() {
log.push((0, "SDR Record (Compact)").into());
} else if event_only.is_some() {
log.push((0, "SDR Record (Event-only)").into())
} else {
log.push((0, "Cannot log unknown sensor type").into());
return log;
Expand Down Expand Up @@ -933,6 +944,9 @@ impl Loggable for Record {
} else if let Some(compact) = compact {
compact.key_data().log_into(1, &mut log);
log.push((1, "Sensor ID", compact.id_string()).into());
} else if let Some(event_only) = event_only {
event_only.key_data().log_into(1, &mut log);
log.push((1, "Sensor ID", event_only.id_string()).into());
}

log
Expand Down

0 comments on commit 3a0e9eb

Please sign in to comment.