commit 7c036dc0a73394d44b0e7d741d046f86ccfadbb2
parent c7b64d2dcb5ffd1537a3f5cd9deb662128b7b7ec
Author: Sylvia Ivory <git@sivory.net>
Date: Sun, 15 Mar 2026 23:29:58 -0700
Implement journal entry parsing
Diffstat:
2 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/tools/src/sylveos/journal.rs b/tools/src/sylveos/journal.rs
@@ -92,12 +92,13 @@ pub struct JournalEntry {
#[derive(Debug, Clone, Copy)]
pub enum LogLevel {
- Critical,
- Error,
- Warning,
- Info,
- Trace,
- Debug,
+ Critical = 0,
+ Error = 1,
+ Warning = 2,
+ Info = 3,
+ Trace = 4,
+ Debug = 5,
+ Invalid = 6,
}
impl LogLevel {
@@ -109,6 +110,19 @@ impl LogLevel {
LogLevel::Info => "info ",
LogLevel::Trace => "trace ",
LogLevel::Debug => "debug ",
+ LogLevel::Invalid => "invalid ",
+ }
+ }
+
+ pub fn from_byte(byte: u8) -> Self {
+ match byte {
+ 0 => Self::Critical,
+ 1 => Self::Error,
+ 2 => Self::Warning,
+ 3 => Self::Info,
+ 4 => Self::Debug,
+ 5 => Self::Debug,
+ _ => Self::Invalid,
}
}
}
diff --git a/tools/src/sylveos/mod.rs b/tools/src/sylveos/mod.rs
@@ -10,6 +10,7 @@ use std::{
time::Duration,
};
+use chrono::Local;
pub use console::ConsoleWidget;
use crossterm::event::{Event, EventStream, KeyCode};
pub use journal::JournalWidget;
@@ -224,5 +225,23 @@ async fn parse_message(port: &mut ReadHalf<SerialStream>) -> Result<Message> {
return Ok(Message::Disconnect);
}
+ if byte == 1 {
+ // Journal entry (or SOH if you adopt ascii)
+ // next byte is level
+ // next int is length of message
+ // next bytes is message
+ let time = Local::now();
+ let level = journal::LogLevel::from_byte(port.read_u8().await?);
+ let length = port.read_u32_le().await?;
+
+ let mut buffer: Vec<u8> = Vec::with_capacity(length as usize);
+ buffer.resize(length as usize, 0);
+ port.read_exact(buffer.as_mut_slice()).await?;
+
+ let msg = String::from_utf8_lossy(buffer.as_slice()).to_string();
+
+ return Ok(Message::Journal(JournalEntry { time, level, msg }));
+ }
+
Ok(Message::Console(byte))
}