#[cfg(feature = "serde")]
use super::SerializeUbxPacketFields;
#[cfg(feature = "serde")]
use crate::serde::ser::SerializeMap;
#[allow(unused_imports, reason = "It is only unused in some feature sets")]
use crate::FieldIter;
use crate::{error::ParserError, UbxPacketMeta};
use ublox_derive::ubx_packet_recv;
#[ubx_packet_recv]
#[ubx(class = 0x27, id = 0x10, max_payload_len = 136)] struct SecSiglog {
version: u8,
num_events: u8,
reserved0: [u8; 6],
#[ubx(map_type = SecSiglogEventIter, may_fail,
from = SecSiglogEventIter::new,
is_valid = SecSiglogEventIter::is_valid)]
events: [u8; 0],
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
pub struct SecSiglogEvent {
pub time_elapsed_s: u32,
pub detection_type: u8,
pub event_type: u8,
}
#[derive(Debug, Clone)]
pub struct SecSiglogEventIter<'a> {
data: &'a [u8],
offset: usize,
}
impl<'a> SecSiglogEventIter<'a> {
fn new(data: &'a [u8]) -> Self {
Self { data, offset: 0 }
}
#[allow(
dead_code,
reason = "Used by ubx_packet_recv macro for validation, but may appear unused in some feature configurations"
)]
fn is_valid(payload: &[u8]) -> bool {
payload.len().is_multiple_of(8)
}
}
impl core::iter::Iterator for SecSiglogEventIter<'_> {
type Item = SecSiglogEvent;
fn next(&mut self) -> Option<Self::Item> {
let chunk = self.data.get(self.offset..self.offset + 8)?;
let event = SecSiglogEvent {
time_elapsed_s: u32::from_le_bytes(chunk[0..4].try_into().ok()?),
detection_type: chunk[4],
event_type: chunk[5],
};
self.offset += 8;
Some(event)
}
}