-
Notifications
You must be signed in to change notification settings - Fork 146
Add log-format argument #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
76bb6e8
f2859d5
5273a4a
695e301
06ec0fa
a536e94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ use crossterm::{ | |
| }; | ||
| use log::error; | ||
| use miette::{IntoDiagnostic, Result}; | ||
| use strum::{Display, EnumIter, EnumString, EnumVariantNames}; | ||
|
|
||
| use crate::{ | ||
| cli::monitor::parser::{InputParser, ResolvingPrinter}, | ||
|
|
@@ -33,6 +34,17 @@ pub mod parser; | |
| mod line_endings; | ||
| mod symbols; | ||
|
|
||
| #[cfg_attr(feature = "cli", derive(clap::ValueEnum))] | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Display, EnumIter, EnumString, EnumVariantNames)] | ||
| #[non_exhaustive] | ||
| #[strum(serialize_all = "lowercase")] | ||
| pub enum LogFormat { | ||
| /// defmt | ||
| Defmt, | ||
| /// serial | ||
| Serial, | ||
SergioGasquez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /// Type that ensures that raw mode is disabled when dropped. | ||
| struct RawModeGuard; | ||
|
|
||
|
|
@@ -58,22 +70,16 @@ pub fn monitor( | |
| pid: u16, | ||
| baud: u32, | ||
| ) -> serialport::Result<()> { | ||
| #[cfg(feature = "defmt")] | ||
| let parser = parser::esp_defmt::EspDefmt::new(elf); | ||
|
|
||
| #[cfg(not(feature = "defmt"))] | ||
| let parser = parser::serial::Serial; | ||
|
|
||
| monitor_with(serial, elf, pid, baud, parser) | ||
| monitor_with(serial, elf, pid, baud, LogFormat::Serial) | ||
| } | ||
|
|
||
| /// Open a serial monitor on the given interface, using the given input parser. | ||
| pub fn monitor_with<L: InputParser>( | ||
| pub fn monitor_with( | ||
| mut serial: Interface, | ||
| elf: Option<&[u8]>, | ||
| pid: u16, | ||
| baud: u32, | ||
| mut parser: L, | ||
| log_format: LogFormat, | ||
| ) -> serialport::Result<()> { | ||
| println!("Commands:"); | ||
| println!(" CTRL+R Reset chip"); | ||
|
|
@@ -102,7 +108,16 @@ pub fn monitor_with<L: InputParser>( | |
| err => err, | ||
| }?; | ||
|
|
||
| parser.feed(&buff[0..read_count], &mut stdout); | ||
| match log_format { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why I didn't notice this but this isn't correct. The defmt parser is stateful, we can't just create a new one every time we have read some bytes. |
||
| LogFormat::Defmt => { | ||
| let mut parser = parser::esp_defmt::EspDefmt::new(elf); | ||
| parser.feed(&buff[0..read_count], &mut stdout); | ||
| } | ||
| LogFormat::Serial => { | ||
| let mut parser = parser::serial::Serial; | ||
| parser.feed(&buff[0..read_count], &mut stdout); | ||
| } | ||
| } | ||
|
|
||
| // Don't forget to flush the writer! | ||
| stdout.flush().ok(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| #[cfg(feature = "defmt")] | ||
| pub mod esp_defmt; | ||
| pub mod serial; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.