Skip to content

Commit 988f92d

Browse files
bugadaniSergioGasquez
authored andcommitted
Fix defmt
1 parent d59bd37 commit 988f92d

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Fixed
1717

1818
- Fixed printing panic backtraces when using `esp-println` and `defmt` (#496)
19+
- Fixed defmt parsing when data is read in parts (#503)
1920

2021
### Changed
2122

espflash/src/cli/monitor/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ pub fn monitor_with(
9999
let stdout = stdout();
100100
let mut stdout = ResolvingPrinter::new(elf, stdout.lock());
101101

102+
let mut parser: Box<dyn InputParser> = match log_format {
103+
LogFormat::Defmt => Box::new(parser::esp_defmt::EspDefmt::new(elf)),
104+
LogFormat::Serial => Box::new(parser::serial::Serial),
105+
};
106+
102107
let mut buff = [0; 1024];
103108
loop {
104109
let read_count = match serial.serial_port_mut().read(&mut buff) {
@@ -108,16 +113,7 @@ pub fn monitor_with(
108113
err => err,
109114
}?;
110115

111-
match log_format {
112-
LogFormat::Defmt => {
113-
let mut parser = parser::esp_defmt::EspDefmt::new(elf);
114-
parser.feed(&buff[0..read_count], &mut stdout);
115-
}
116-
LogFormat::Serial => {
117-
let mut parser = parser::serial::Serial;
118-
parser.feed(&buff[0..read_count], &mut stdout);
119-
}
120-
}
116+
parser.feed(&buff[0..read_count], &mut stdout);
121117

122118
// Don't forget to flush the writer!
123119
stdout.flush().ok();

espflash/src/cli/monitor/parser/esp_defmt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ impl EspDefmt {
106106
}
107107
}
108108

109-
fn handle_raw(bytes: &[u8], out: &mut impl Write) {
109+
fn handle_raw(bytes: &[u8], out: &mut dyn Write) {
110110
out.write_all(bytes).unwrap();
111111
}
112112

113-
fn handle_defmt(frame: Frame<'_>, out: &mut impl Write) {
113+
fn handle_defmt(frame: Frame<'_>, out: &mut dyn Write) {
114114
match frame.level() {
115115
Some(level) => {
116116
let color = match level {
@@ -142,7 +142,7 @@ impl EspDefmt {
142142
}
143143

144144
impl InputParser for EspDefmt {
145-
fn feed(&mut self, bytes: &[u8], out: &mut impl Write) {
145+
fn feed(&mut self, bytes: &[u8], out: &mut dyn Write) {
146146
let Some(table) = self.table.as_mut() else {
147147
Self::handle_raw(bytes, out);
148148
return;

espflash/src/cli/monitor/parser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use regex::Regex;
1313
use crate::cli::monitor::{line_endings::normalized, symbols::Symbols};
1414

1515
pub trait InputParser {
16-
fn feed(&mut self, bytes: &[u8], out: &mut impl Write);
16+
fn feed(&mut self, bytes: &[u8], out: &mut dyn Write);
1717
}
1818

1919
// Pattern to much a function address in serial output.

espflash/src/cli/monitor/parser/serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::cli::monitor::parser::InputParser;
55
pub struct Serial;
66

77
impl InputParser for Serial {
8-
fn feed(&mut self, bytes: &[u8], out: &mut impl Write) {
8+
fn feed(&mut self, bytes: &[u8], out: &mut dyn Write) {
99
out.write_all(bytes).unwrap();
1010
}
1111
}

0 commit comments

Comments
 (0)