Skip to content

Commit

Permalink
Merge pull request #3 from rincewound/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
rincewound authored Dec 18, 2024
2 parents fa8f7b9 + 5b90533 commit 69a7227
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 25 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ version = "0.1.0"
edition = "2021"

[dependencies]
chrono = "0.4.39"
crossterm = "0.28.1"
ratatui = "0.29.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.133"
serial2 = "0.2.28"
snafu = "0.8.5"

[profile.release]
opt-level = 'z' # Optimize for size
lto = true
lto = true
14 changes: 9 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ for developers. klemme is a mode based application, i.e. at any given time it ca

* Supports common baud rates & port settings
* Wide range of display modes that can be applied retro actively
* Uses less than 2 MB RAM in most circumstances

## Modes

```mermaid
flowchart
Normal --> Settings
Settings --> Normal
Normal --> Interactive
Normal --> Analyzer
Settings --> Normal
Settings --> Interactive
Interactive --> Normal
Interactive --> Analyzer
Analyzer --> Normal
Analyzer --> Interactive
Settings --> Interactive
Normal --> Analyzer
```

## Keys
Expand All @@ -34,6 +33,7 @@ Normal --> Analyzer

* esc - Change to normal mode
* F2 - Change display mode
* F9 - Toggle timing display mode
* F10 - Clear history

### Normal Mode
Expand Down Expand Up @@ -100,3 +100,7 @@ Examples:
* Input: AB CF Output Bytes: 0xAB, 0xCF
* Input: BCEF Output Bytes: 0xBC 0xEF
* Input: B C DF Output Bytes: 0xBC 0xDF

## Settings

klemme will attempt to store a .klemme file in the folder it is executed in.
64 changes: 58 additions & 6 deletions src/analyzer_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,39 @@ use ratatui::{
};

use crate::{
mode::ApplicationMode,
portthread::{RxTx, SerialStateMessage},
serialtypes::control_char_to_string,
DisplayMode,
mode::ApplicationMode, portthread::{RxTx, SerialStateMessage}, serialtypes::control_char_to_string, DisplayMode
};


const TIME_INFORMATION_MODES: [TimeInformationMode; 2] = [
TimeInformationMode::None,
// TimeInformationMode::Delta,
TimeInformationMode::Absolute,
// TimeInformationMode::AbsoluteWithDelta,
];

#[derive(Debug, Default, PartialEq, Clone, Copy)]
pub enum TimeInformationMode
{
None,
// Delta,
#[default]
Absolute,
// AbsoluteWithDelta,
}

impl Display for TimeInformationMode {

fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TimeInformationMode::None => write!(f, "None"),
// TimeInformationMode::Delta => write!(f, "Delta"),
TimeInformationMode::Absolute => write!(f, "Absolute"),
// TimeInformationMode::AbsoluteWithDelta => write!(f, "Absolute with Delta"),
}
}
}

#[derive(Debug, Default, PartialEq)]
pub enum Endianness {
Big,
Expand All @@ -40,6 +67,7 @@ pub struct AnalyzerMode {
analyzer_cursor_pos: usize,
analyzer_endianness: Endianness,
active_display_mode: DisplayMode,
active_time_display_mode: TimeInformationMode,
}

impl AnalyzerMode {
Expand All @@ -52,6 +80,7 @@ impl AnalyzerMode {
analyzer_cursor_pos: 0,
analyzer_endianness: Endianness::Little,
active_display_mode: DisplayMode::Hex,
active_time_display_mode: TimeInformationMode::None,
}
}

Expand All @@ -70,8 +99,6 @@ impl ApplicationMode for AnalyzerMode {
KeyCode::Down => self.scroll_analyzer_cursor_down(),
KeyCode::PageUp => self.scroll_up(),
KeyCode::PageDown => self.scroll_down(),

//KeyCode::F(2) => self.settingsmode.rotate_display_mode(),
KeyCode::Char('e') => self.rotate_analyzer_endianness(),
_ => {}
}
Expand Down Expand Up @@ -145,6 +172,16 @@ impl AnalyzerMode {
}
}

pub fn rotate_time_display_mode(&mut self) {
let mut selectd_index = TIME_INFORMATION_MODES
.iter()
.position(|x| *x == self.active_time_display_mode)
.unwrap_or(0);
selectd_index += 1;
selectd_index %= TIME_INFORMATION_MODES.len();
self.active_time_display_mode = TIME_INFORMATION_MODES[selectd_index];
}

pub fn update_data(
&mut self,
data_source: &Receiver<SerialStateMessage>,
Expand All @@ -156,6 +193,7 @@ impl AnalyzerMode {

pub fn clear_history(&mut self) {
self.display_history.clear();
self.display_history.shrink_to_fit();
}

fn popup_area(area: Rect, percent_x: u16, percent_y: u16) -> Rect {
Expand Down Expand Up @@ -221,8 +259,19 @@ impl AnalyzerMode {
}
}

fn select_time_format_string(&self) -> String {
match self.active_time_display_mode {
TimeInformationMode::Absolute => "%H:%M:%S%.3f ".to_string(),
// TimeInformationMode::Delta => "%H:%M:%S%.3f ".to_string(),
TimeInformationMode::None => "".to_string(),
// TimeInformationMode::AbsoluteWithDelta => format!("%H:%M:%S%.3f[+{} ms] ", delta_to_prev),
}
.to_string()
}

fn build_list_items(&self, analyzer_data: &mut Vec<u8>, max_num_rows: usize) -> Vec<Line<'_>> {
let mut line_index = 0;

let items: Vec<Line> = self
.display_history
.iter()
Expand Down Expand Up @@ -264,7 +313,10 @@ impl AnalyzerMode {
*analyzer_data = x.data.to_vec();
}

let time_string = x.timestamp.format(&self.select_time_format_string()).to_string();

let ln = Line::from(vec![
time_string.fg(ratatui::style::Color::Gray),
x.rx_tx.to_string().fg(if x.rx_tx == RxTx::Tx {
ratatui::style::Color::Green
} else {
Expand Down
1 change: 1 addition & 0 deletions src/interactive_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const CRLF_SETTINGS: [CRLFSetting; 4] = [
CRLFSetting::CRLF,
];


impl Display for CRLFSetting {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use ratatui::{
layout::{Constraint, Layout, Rect},
DefaultTerminal, Frame,
};
use serde::{Deserialize, Serialize};

use std::sync::mpsc;
use std::sync::mpsc::{Receiver, Sender};
Expand All @@ -31,7 +32,7 @@ const DISPLAY_MODES: [DisplayMode; 5] = [
DisplayMode::MixedDec,
];

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum DisplayMode {
Decimal,
Hex,
Expand Down Expand Up @@ -182,6 +183,10 @@ impl App {
self.settingsmode.rotate_display_mode();
}

if key_event.code == KeyCode::F(9) {
self.analyzermode.rotate_time_display_mode();
}

if key_event.code == KeyCode::F(10) {
self.analyzermode.clear_history();
}
Expand Down
Loading

0 comments on commit 69a7227

Please sign in to comment.