Skip to content
This repository has been archived by the owner on Jan 14, 2023. It is now read-only.

Commit

Permalink
Revert stupid hardcoded format for channels and add config
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Sep 11, 2020
1 parent f6080a9 commit cd8504d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 40 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-embed"
version = "0.9.0"
version = "0.9.1"
authors = ["Noah Hüsser <[email protected]>"]
edition = "2018"
description = "A utility to develop software for embedded ARM and RISC-V cores."
Expand Down
2 changes: 1 addition & 1 deletion src/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 15 additions & 26 deletions src/rttui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand All @@ -71,6 +71,7 @@ impl App {
pull_channel(&mut down_channels, number),
None,
config.rtt.show_timestamps,
DataFormat::String,
));
}

Expand All @@ -80,6 +81,7 @@ impl App {
Some(channel),
None,
config.rtt.show_timestamps,
DataFormat::String,
));
}
}
Expand Down Expand Up @@ -120,7 +122,6 @@ impl App {
Ok(Self {
tabs,
current_tab: 0,

terminal,
events,
history_path,
Expand Down Expand Up @@ -157,9 +158,8 @@ impl App {
let mut height = 0;
let mut messages_wrapped: Vec<String> = 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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -322,20 +321,18 @@ 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);
let final_path = path.join(name);

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(_) => {}
Expand All @@ -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!(
Expand Down Expand Up @@ -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();
}
}

Expand Down
21 changes: 17 additions & 4 deletions src/rttui/channel.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
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<usize>,
pub down: Option<usize>,
pub name: Option<String>,
pub format: DataFormat,
}

#[derive(Debug)]
pub struct ChannelState {
up_channel: Option<UpChannel>,
down_channel: Option<DownChannel>,
name: String,
format: DataFormat,
messages: Vec<String>,
data: Vec<u8>,
last_line_done: bool,
Expand All @@ -31,6 +38,7 @@ impl ChannelState {
down_channel: Option<DownChannel>,
name: Option<String>,
show_timestamps: bool,
format: DataFormat,
) -> Self {
let name = name
.or_else(|| up_channel.as_ref().and_then(|up| up.name().map(Into::into)))
Expand All @@ -45,6 +53,7 @@ impl ChannelState {
up_channel,
down_channel,
name,
format,
messages: Vec::new(),
last_line_done: true,
input: String::new(),
Expand Down Expand Up @@ -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;
}
Expand All @@ -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()) {
Expand All @@ -118,7 +131,7 @@ impl ChannelState {
return;
}

match fmt {
match self.format {
DataFormat::String => {
let now = Local::now();

Expand Down
6 changes: 0 additions & 6 deletions src/rttui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
pub mod app;
pub mod channel;
pub mod event;

#[derive(Debug)]
pub enum DataFormat {
String,
BinaryLE,
}

0 comments on commit cd8504d

Please sign in to comment.