common: Implement Logger::list_recordings().
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 9 Jan 2020 22:40:23 +0000 (23:40 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sat, 11 Jan 2020 09:15:46 +0000 (10:15 +0100)
src/common/logger.rs

index 8ca0ed4da62c36a9130cedb90a3a377b44e74907..c355bb3d47d1d3ab62cbd7dd893fd672925dd959 100644 (file)
@@ -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 {