From cd8504dec9cda4030f4cfc6cb1bb5ee2f6c501f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20H=C3=BCsser?= Date: Fri, 11 Sep 2020 23:45:51 +0200 Subject: [PATCH] Revert stupid hardcoded format for channels and add config --- CHANGELOG.md | 15 ++++++++++++++- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config/default.toml | 2 +- src/rttui/app.rs | 41 +++++++++++++++-------------------------- src/rttui/channel.rs | 21 +++++++++++++++++---- src/rttui/mod.rs | 6 ------ 7 files changed, 49 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4e58e8..bd9ef63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +## [0.9.1] + +### Added + +- Added a config flag to config what format to use on a channel. + +### Changed + +### Fixed + +- Fixed a bug where all channels except 0 would be interpreted as binary. + ## [0.9.0] ### Added @@ -121,7 +133,8 @@ An example is this config: ## [0.6.0] - Initial release -[Unreleased]: https://github.com/probe-rs/probe-rs/compare/v0.9.0...master +[Unreleased]: https://github.com/probe-rs/probe-rs/compare/v0.9.1...master +[0.9.1]: https://github.com/probe-rs/probe-rs/releases/tag/v0.9.1..v0.9.0 [0.9.0]: https://github.com/probe-rs/probe-rs/releases/tag/v0.9.0..v0.8.0 [0.8.0]: https://github.com/probe-rs/probe-rs/releases/tag/v0.8.0..v0.7.0 [0.7.0]: https://github.com/probe-rs/probe-rs/releases/tag/v0.7.0..v0.6.1 diff --git a/Cargo.lock b/Cargo.lock index f5708eb..6ff7a21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -218,7 +218,7 @@ checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" [[package]] name = "cargo-embed" -version = "0.9.0" +version = "0.9.1" dependencies = [ "anyhow", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 1922d5f..dfcf781 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-embed" -version = "0.9.0" +version = "0.9.1" authors = ["Noah Hüsser "] edition = "2018" description = "A utility to develop software for embedded ARM and RISC-V cores." diff --git a/src/config/default.toml b/src/config/default.toml index 6297d8d..88189f6 100644 --- a/src/config/default.toml +++ b/src/config/default.toml @@ -44,7 +44,7 @@ log_level = "WARN" enabled = false # A list of channel associations to be displayed. If left empty, all channels are displayed. channels = [ - # { up = 0, down = 0, name = "name" } + # { up = 0, down = 0, name = "name", format = "String" } ] # The duration in ms for which the logger should retry to attach to RTT. timeout = 3000 diff --git a/src/rttui/app.rs b/src/rttui/app.rs index 888a2d5..184b44e 100644 --- a/src/rttui/app.rs +++ b/src/rttui/app.rs @@ -17,9 +17,8 @@ use tui::{ Terminal, }; -use super::channel::ChannelState; +use super::channel::{ChannelState, DataFormat}; use super::event::{Event, Events}; -use super::DataFormat; use event::{DisableMouseCapture, KeyModifiers}; @@ -61,6 +60,7 @@ impl App { .and_then(|down| pull_channel(&mut down_channels, down)), channel.name.clone(), config.rtt.show_timestamps, + channel.format, )) } } else { @@ -71,6 +71,7 @@ impl App { pull_channel(&mut down_channels, number), None, config.rtt.show_timestamps, + DataFormat::String, )); } @@ -80,6 +81,7 @@ impl App { Some(channel), None, config.rtt.show_timestamps, + DataFormat::String, )); } } @@ -120,7 +122,6 @@ impl App { Ok(Self { tabs, current_tab: 0, - terminal, events, history_path, @@ -157,9 +158,8 @@ impl App { let mut height = 0; let mut messages_wrapped: Vec = Vec::new(); - match current_tab { - //String todo deal with enums instead - 0 => { + match tabs[current_tab].format() { + DataFormat::String => { self.terminal .draw(|f| { let constraints = if has_down_channel { @@ -231,8 +231,7 @@ impl App { .set_scroll_offset(message_num - height.min(message_num)); } } - //binary - _ => { + DataFormat::BinaryLE => { self.terminal .draw(|f| { let constraints = if has_down_channel { @@ -322,10 +321,9 @@ impl App { if let Some(path) = &self.history_path { for (i, tab) in self.tabs.iter().enumerate() { - // todo dont hardcode DataFormat, take from config - let extension = match i { - 0 => "txt", - _ => "dat", + let extension = match tab.format() { + DataFormat::String => "txt", + DataFormat::BinaryLE => "dat", }; let name = format!("{}_channel{}.{}", self.logname, i, extension); @@ -333,9 +331,8 @@ impl App { match std::fs::File::create(final_path.clone()) { Ok(mut file) => { - match i { - //string, take from config and store and match the enum - 0 => { + match tab.format() { + DataFormat::String => { for line in tab.messages() { match writeln!(file, "{}", line) { Ok(_) => {} @@ -349,10 +346,7 @@ impl App { } } } - //binary - //todo formatting into like f32s and then back to u8? - //to presuambly maintian endianness? - _ => match file.write(&tab.data()) { + DataFormat::BinaryLE => match file.write(&tab.data()) { Ok(_) => {} Err(e) => { eprintln!( @@ -419,13 +413,8 @@ impl App { /// Polls the RTT target for new data on all channels. pub fn poll_rtt(&mut self) { - for (i, channel) in self.tabs.iter_mut().enumerate() { - //for now, just assume 0 is string everything else is binaryle - let fmt = match i { - 0 => DataFormat::String, - _ => DataFormat::BinaryLE, - }; - channel.poll_rtt(fmt); + for channel in self.tabs.iter_mut() { + channel.poll_rtt(); } } diff --git a/src/rttui/channel.rs b/src/rttui/channel.rs index d8b5274..a0e207b 100644 --- a/src/rttui/channel.rs +++ b/src/rttui/channel.rs @@ -1,14 +1,20 @@ use std::fmt; -use super::DataFormat; use chrono::Local; use probe_rs_rtt::{DownChannel, UpChannel}; -#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)] +#[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)] +pub enum DataFormat { + String, + BinaryLE, +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct ChannelConfig { pub up: Option, pub down: Option, pub name: Option, + pub format: DataFormat, } #[derive(Debug)] @@ -16,6 +22,7 @@ pub struct ChannelState { up_channel: Option, down_channel: Option, name: String, + format: DataFormat, messages: Vec, data: Vec, last_line_done: bool, @@ -31,6 +38,7 @@ impl ChannelState { down_channel: Option, name: Option, show_timestamps: bool, + format: DataFormat, ) -> Self { let name = name .or_else(|| up_channel.as_ref().and_then(|up| up.name().map(Into::into))) @@ -45,6 +53,7 @@ impl ChannelState { up_channel, down_channel, name, + format, messages: Vec::new(), last_line_done: true, input: String::new(), @@ -89,6 +98,10 @@ impl ChannelState { &self.name } + pub fn format(&self) -> DataFormat { + self.format + } + pub fn set_scroll_offset(&mut self, value: usize) { self.scroll_offset = value; } @@ -100,7 +113,7 @@ impl ChannelState { /// Polls the RTT target for new data on the specified channel. /// /// Processes all the new data and adds it to the linebuffer of the respective channel. - pub fn poll_rtt(&mut self, fmt: DataFormat) { + pub fn poll_rtt(&mut self) { // TODO: Proper error handling. let count = if let Some(channel) = self.up_channel.as_mut() { match channel.read(self.rtt_buffer.0.as_mut()) { @@ -118,7 +131,7 @@ impl ChannelState { return; } - match fmt { + match self.format { DataFormat::String => { let now = Local::now(); diff --git a/src/rttui/mod.rs b/src/rttui/mod.rs index b83f849..4dff106 100644 --- a/src/rttui/mod.rs +++ b/src/rttui/mod.rs @@ -1,9 +1,3 @@ pub mod app; pub mod channel; pub mod event; - -#[derive(Debug)] -pub enum DataFormat { - String, - BinaryLE, -}