-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
256 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use std::{collections::HashMap, rc::Rc}; | ||
|
||
use crate::slint_generatedAppWindow::{raw_can, AppWindow}; | ||
use slint::{Model, SharedString, VecModel, Weak}; | ||
use socketcan::{CanSocket, EmbeddedFrame, Frame, Socket}; | ||
pub struct DebugHandler<'a> { | ||
#[cfg(target_os = "linux")] | ||
pub iface: &'a str, | ||
#[cfg(target_os = "windows")] | ||
pub iface: UsbCanSocket, | ||
pub ui_handle: &'a Weak<AppWindow>, | ||
pub bitrate: String, | ||
pub filter: (u32, u32), | ||
} | ||
|
||
impl<'a> DebugHandler<'a> { | ||
pub fn run(&mut self) { | ||
let can_socket = CanSocket::open(self.iface).unwrap(); | ||
if let Ok(frame) = can_socket.read_frame() { | ||
let frame_id = frame.raw_id() & !0x80000000; | ||
if frame_id >= self.filter.0 && frame_id <= self.filter.1 { | ||
let bitrate = self.bitrate().unwrap(); | ||
let _ = self.ui_handle.upgrade_in_event_loop(move |ui| { | ||
ui.set_bitrate(bitrate as i32); | ||
let raw_data = ui.get_raw_data(); | ||
let mut vec_data = Vec::default(); | ||
for data in raw_data.iter() { | ||
vec_data.push(data); | ||
} | ||
vec_data.push(raw_can { | ||
data: SharedString::from(format!("{:?}", frame.data())), | ||
id: SharedString::from(frame_id.to_string()), | ||
len: frame.len() as i32, | ||
}); | ||
vec_data.reverse(); | ||
let message_vec: Rc<VecModel<raw_can>> = Rc::new(VecModel::from(vec_data)); | ||
ui.set_raw_data(message_vec.into()); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
fn bitrate(&self) -> Option<u32> { | ||
let bitrate_map: HashMap<&str, u32> = [ | ||
("1 Mbit/s", 1_000_000), | ||
("800 kbit/s", 800_000), | ||
("500 kbit/s", 500_000), | ||
("250 kbit/s", 250_000), | ||
("125 kbit/s", 125_000), | ||
("100 kbit/s", 100_000), | ||
("95.238 kbit/s", 95_238), | ||
("83.333 kbit/s", 83_333), | ||
("50 kbit/s", 50_000), | ||
("47.619 kbit/s", 47_619), | ||
("33.333 kbit/s", 33_333), | ||
("20 kbit/s", 20_000), | ||
("10 kbit/s", 10_000), | ||
("5 kbit/s", 5_000), | ||
] | ||
.iter() | ||
.cloned() | ||
.collect(); | ||
|
||
bitrate_map.get(self.bitrate.as_str()).copied() | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
|
||
import { ListView, Button } from "std-widgets.slint"; | ||
|
||
export struct raw_can { | ||
id: string, | ||
len: int, | ||
data: string | ||
} | ||
export component debugPage inherits Rectangle { | ||
in property <string> state; | ||
in property <string> bitrate; | ||
in property <string> bus_load; | ||
in-out property <[raw_can]> raw_data: [ | ||
{id: "181FF1FA", len: 4, data: "00 01 02 03 04 05 06 07"}, | ||
{id: "181FF1FA", len: 4, data: "00 01 02 03 04 05 06 07"}, | ||
{id: "181FF1FA", len: 4, data: "00 01 02 03 04 05 06 07"}, | ||
{id: "181FF1FA", len: 4, data: "00 01 02 03 04 05 06 07"}]; | ||
VerticalLayout { | ||
HorizontalLayout { | ||
Rectangle {} | ||
Rectangle { | ||
max-height: 30px; | ||
Text { | ||
text: "State: " + state; | ||
color: white; | ||
} | ||
} | ||
Rectangle {} | ||
Rectangle { | ||
Text { | ||
text: "Bitrate: " + bitrate; | ||
color: white; | ||
} | ||
} | ||
Rectangle {} | ||
Rectangle { | ||
Text { | ||
text: "Bus Load: " + bus_load + "%"; | ||
color: white; | ||
} | ||
} | ||
Rectangle { | ||
width: 50px; | ||
} | ||
} | ||
Rectangle { | ||
height: 1px; | ||
background: white; | ||
} | ||
HorizontalLayout { | ||
Rectangle { | ||
width: 30px; | ||
Text { | ||
text: "Receive"; | ||
color: white; | ||
rotation-angle: 270deg; | ||
} | ||
border-color: white; | ||
border-width: 1px; | ||
} | ||
VerticalLayout { | ||
ListView { | ||
for raw in raw_data: Rectangle { | ||
HorizontalLayout { | ||
Rectangle { | ||
width: parent.width * 30%; | ||
Text { | ||
text: raw.id; | ||
color: white; | ||
} | ||
} | ||
Rectangle { | ||
width: parent.width * 20%; | ||
Text { | ||
text: raw.len; | ||
color: white; | ||
} | ||
} | ||
Rectangle { | ||
width: parent.width * 50%; | ||
Text { | ||
text: raw.data; | ||
color: white; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
Rectangle { | ||
height: 1px; | ||
border-color: white; | ||
border-width: 1px; | ||
} | ||
HorizontalLayout { | ||
Rectangle { | ||
width: 30px; | ||
Text { | ||
text: "Transmit"; | ||
color: white; | ||
rotation-angle: 270deg; | ||
} | ||
border-color: white; | ||
border-width: 1px; | ||
} | ||
VerticalLayout { | ||
ListView { | ||
for raw in raw_data: Rectangle { | ||
HorizontalLayout { | ||
Rectangle { | ||
width: parent.width * 30%; | ||
Text { | ||
text: raw.id; | ||
color: white; | ||
} | ||
} | ||
Rectangle { | ||
width: parent.width * 20%; | ||
Text { | ||
text: raw.len; | ||
color: white; | ||
} | ||
} | ||
Rectangle { | ||
width: parent.width * 50%; | ||
Text { | ||
text: raw.data; | ||
color: white; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |