From 79f647cb1795e62c1b04113834ff13b0193dfa6a Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Thu, 9 Jan 2020 23:40:23 +0100 Subject: [PATCH] common: Implement Logger::list_recordings(). --- src/common/logger.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/common/logger.rs b/src/common/logger.rs index 8ca0ed4..c355bb3 100644 --- a/src/common/logger.rs +++ b/src/common/logger.rs @@ -28,6 +28,7 @@ use systick::elapsed_ms; use buffer::Buffer; use yencode::Yencode; use fmt::*; +use time::Time; pub const MEMORY_SIZE: usize = 2 << 20; const SECTOR_SIZE: usize = 4 << 10; @@ -574,6 +575,38 @@ impl<'a> Logger<'a> { self.write_buffer_offset += num_bytes_written; } + /// + /// Write a listing of the stored recordings to @p tx_buf. + pub fn list_recordings(&mut self, tx_buf: &mut Buffer) { + for index in self.sector_header_iter().rev() { + let sector_header = &self.sector_header[index as usize]; + + if !sector_header.starts_recording() { + continue; + } + + let mut date_time_s = [b' '; 19]; + + if let Some(tm) = Time::from_unix_time(sector_header.start_time) { + tm.fmt_date(&mut date_time_s[0..]); + tm.fmt_time(&mut date_time_s[11..]); + } + + let mut recording_id_s = [b'0'; 9]; + let recording_id_s_len = + fmt_u32_pad(&mut recording_id_s, + sector_header.recording_id as u32, + 8, b' '); + + tx_buf.write(&date_time_s); + tx_buf.write(b" "); + tx_buf.write(&recording_id_s[0..recording_id_s_len]); + tx_buf.write(b"\n"); + + tx_buf.flush(); + } + } + /// /// Check whether or not recording @p recording_id exists. pub fn has_recording(&mut self, recording_id: u16) -> bool { -- 2.30.2