Skip to content

Commit

Permalink
Report device mode to user
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed May 20, 2024
1 parent 9852141 commit 7adb7f6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
6 changes: 3 additions & 3 deletions backend/src/diag/device_modes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bitflags::{bitflags, Flags};
use bitflags::{bitflags};
use ecu_diagnostics::{DiagServerResult, DiagError, kwp2000::KwpSessionType, dynamic_diag::DiagSessionMode};

use super::Nag52Diag;
Expand All @@ -12,8 +12,8 @@ bitflags! {
const SLAVE = 1 << 3;
const TEMPORARY_ERROR = 1 << 4;
// Bit 5?
const ERROR1 = 1 << 6;
// Bit 7?
const ERROR = 1 << 6;
const NO_CALIBRATION = 1 << 7;
// Bit 8?
// Bit 9?
// Bit 10?
Expand Down
1 change: 1 addition & 0 deletions backend/src/diag/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl Display for EgsMode {
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
pub enum PCBVersion {
OnePointOne,
OnePointTwo,
Expand Down
10 changes: 5 additions & 5 deletions config_app/src/ui/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ impl crate::window::InterfacePage for ConfigPage {
ui.hyperlink_to("See Mercedes VIN lookup table for your car configuration", include_base64!("aHR0cDovL2RvY3MudWx0aW1hdGUtbmFnNTIubmV0L2VuL2dldHRpbmdzdGFydGVkL2NvbmZpZ3VyYXRpb24vVklOTGlzdA"));

egui::Grid::new("DGS").striped(true).show(ui, |ui| {
let mut x = scn.is_large_nag == 1;
ui.label("Using large 722.6");
ui.checkbox(&mut x, "");
scn.is_large_nag = x as u8;
ui.end_row();
//let mut x = scn.is_large_nag == 1;
//ui.label("Using large 722.6");
//ui.checkbox(&mut x, "");
//scn.is_large_nag = x as u8;
//ui.end_row();

let mut curr_profile = scn.default_profile;
ui.label("Default drive profile");
Expand Down
43 changes: 39 additions & 4 deletions config_app/src/ui/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use backend::diag::device_modes::TcuDeviceMode;
use backend::diag::DataState;
use backend::diag::ident::IdentData;
use backend::diag::Nag52Diag;
Expand Down Expand Up @@ -25,7 +26,8 @@ pub struct MainPage {
diag_server: &'static mut Nag52Diag,
info: Arc<RwLock<DataState<IdentData>>>,
sn: Arc<RwLock<DataState<String>>>,
first_run: bool
first_run: bool,
tcu_mode: Arc<RwLock<DataState<TcuDeviceMode>>>
}

impl MainPage {
Expand All @@ -38,12 +40,12 @@ impl MainPage {
// We can keep it here as a ref to create a box from it when Drop() is called
// so we can drop it safely without a memory leak
let static_ref: &'static mut Nag52Diag = Box::leak(Box::new(nag));

Self {
diag_server: static_ref,
info: Arc::new(RwLock::new(DataState::Unint)),
sn: Arc::new(RwLock::new(DataState::Unint)),
first_run: false,
tcu_mode: Arc::new(RwLock::new(DataState::Unint)),
}
}
}
Expand Down Expand Up @@ -94,6 +96,35 @@ impl InterfacePage for MainPage {
ui.add(egui::Separator::default());
let mut create_page = None;
let ctx = ui.ctx().clone();
if let DataState::LoadOk(mode) = self.tcu_mode.read().clone() {
ui.vertical_centered(|ui| {
ui.heading("TCU Status");
if mode.contains(TcuDeviceMode::NO_CALIBRATION) {
ui.colored_label(Color32::RED,
"Your TCU requires calibrations, and will NOT function. Please go to the EGS compatibility page
to correct this!"
);
} else if mode.contains(TcuDeviceMode::CANLOGGER) {
ui.colored_label(Color32::RED,
"Your TCU is in CAN logging mode, and will NOT function. To disable this,
please go to the Diagnostic routine executor page, and then CAN Logger."
);
} else if mode.contains(TcuDeviceMode::SLAVE) {
ui.colored_label(Color32::RED,
"Your TCU is in slave mode! It will NOT function."
);
} else if mode.contains(TcuDeviceMode::ERROR) {
ui.colored_label(Color32::RED,
"Your TCU has encountered an error. Please consult the LOG window to
see what is wrong."
);
} else {
ui.label("TCU is running normally.");
}
ui.separator();
});
}

ui.vertical_centered(|v| {
v.heading("Tools");
if v.button("Updater").clicked() {
Expand Down Expand Up @@ -206,12 +237,11 @@ impl InterfacePage for MainPage {
}

fn on_load(&mut self, nag: Option<Arc<Nag52Diag>>) {
println!("OnLoad called");
let tcu = self.diag_server.clone();
let setting_lock = self.info.clone();
let sn_lock = self.sn.clone();
let mode_lock = self.tcu_mode.clone();
std::thread::spawn(move|| {
println!("Querying TCU");
let state = match tcu.query_ecu_data() {
Ok(info) => DataState::LoadOk(info),
Err(err) => DataState::LoadErr(err.to_string()),
Expand All @@ -222,6 +252,11 @@ impl InterfacePage for MainPage {
Err(err) => DataState::LoadErr(err.to_string()),
};
*sn_lock.write() = state;
let state: DataState<TcuDeviceMode> = match tcu.read_device_mode() {
Ok(sn) => DataState::LoadOk(sn),
Err(err) => DataState::LoadErr(err.to_string()),
};
*mode_lock.write() = state;
});
}

Expand Down

0 comments on commit 7adb7f6

Please sign in to comment.