diff --git a/src/storage.rs b/src/storage.rs index ce9d07f..8827359 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -155,12 +155,19 @@ impl RmpWrite for StorageRange where S::Error: core::fmt::Debug + } pub struct SimDataRecorder { - storage: StorageRange, + storage: S, last_stamp: Instant } -impl SimDataRecorder where S::Error: core::fmt::Debug + 'static { - pub fn open(storage: S, partitions: PartitionTable<'_>) -> Result>>> { +impl SimDataRecorder { + pub fn new(storage: S) -> Self { + Self { + storage, + last_stamp: Instant::now() + } + } + + pub fn open(storage: S, partitions: PartitionTable<'_>) -> Result>, SimDataError::Error>>>> where S: Storage, ::Error: core::fmt::Debug + 'static { let partition_type = esp_bootloader_esp_idf::partitions::PartitionType::Data( esp_bootloader_esp_idf::partitions::DataPartitionSubType::Undefined, ); @@ -171,17 +178,17 @@ impl SimDataRecorder where S::Error: core::fmt::Debug + ' let start = data_partition.offset() as usize; let end = data_partition.len() as usize + start; - let mut writer = StorageRange::new(storage.clone(), start, end); + let mut writer = StorageRange::new(storage, start, end); warn!("Writing new simulation data at {start:#02x}:{end:#02x}"); StreamIndex { count: 1 }.write_rmp(&mut writer)?; StreamHeader { id: StreamType::Bundle, size: 0 }.write_rmp(&mut writer)?; - Ok(Self { + Ok(SimDataRecorder { storage: writer, last_stamp: Instant::now() }) } - pub fn write_next(&mut self, event: T) -> Result<(), SimDataError>>> { + pub fn write_next(&mut self, event: T) -> Result<(), SimDataError>> where S: RmpWrite { BundleEventHeader { id: T::stream_id() }.write_rmp(&mut self.storage)?; let now = Instant::now(); let event = StreamEvent {