From c4f7227493ddd43dcd40cadf6c6cfddb961077b1 Mon Sep 17 00:00:00 2001 From: Ashcon Mohseninia Date: Wed, 10 Feb 2021 22:11:34 +0000 Subject: [PATCH] Version 0.5.0 --- app_rust/Cargo.toml | 2 +- app_rust/src/commapi/protocols/kwp2000.rs | 16 ++++++++++++++-- app_rust/src/commapi/protocols/mod.rs | 7 +++---- app_rust/src/commapi/protocols/obd2.rs | 2 +- .../src/windows/diag_session/json_session.rs | 10 +++++----- .../src/windows/diag_session/kwp2000_session.rs | 6 +++++- app_rust/src/windows/window.rs | 8 ++++---- 7 files changed, 33 insertions(+), 18 deletions(-) diff --git a/app_rust/Cargo.toml b/app_rust/Cargo.toml index f43cc9f..fe4af48 100644 --- a/app_rust/Cargo.toml +++ b/app_rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "openvehiclediag" -version = "0.1.0" +version = "0.5.0" authors = ["ashcon"] edition = "2018" diff --git a/app_rust/src/commapi/protocols/kwp2000.rs b/app_rust/src/commapi/protocols/kwp2000.rs index cc3a386..51376d4 100644 --- a/app_rust/src/commapi/protocols/kwp2000.rs +++ b/app_rust/src/commapi/protocols/kwp2000.rs @@ -199,6 +199,18 @@ pub enum DiagSession { ExtendedDiag = 0x92, } +impl ToString for DiagSession { + fn to_string(&self) -> String { + match &self { + DiagSession::Normal => "Normal", + DiagSession::ECUFlash => "Flash", + DiagSession::StandBy => "Standby", + DiagSession::ECUPassive => "Passive", + DiagSession::ExtendedDiag => "Extended diagnostics" + }.into() + } +} + impl DiagSession { pub (crate) fn send_tester_present(&self) -> bool { self != &DiagSession::Normal @@ -418,14 +430,14 @@ impl ProtocolServer for KWP2000ECU { let mut timer = Instant::now(); while should_run_t.load(Relaxed) { if let Ok(data) = channel_tx_receiver.try_recv() { - let res = Self::run_command_isotp(comm_server.as_ref(), s_id, data.0, &data.1, data.2); + let res = Self::run_command_iso_tp(comm_server.as_ref(), s_id, data.0, &data.1, data.2); if channel_rx_sender.send(res).is_err() { *last_error_t.write().unwrap() = Some(ProtocolError::CustomError("Sender channel died".into())); break } } if timer.elapsed().as_millis() >= 2000 && session_type_t.read().unwrap().send_tester_present() { - if let Ok(res) = Self::run_command_isotp(comm_server.as_ref(), s_id, Service::TesterPresent.into(), &[0x01], true) { + if let Ok(res) = Self::run_command_iso_tp(comm_server.as_ref(), s_id, Service::TesterPresent.into(), &[0x01], true) { println!("Tester present resp: {:02X?}", res); } timer = Instant::now(); diff --git a/app_rust/src/commapi/protocols/mod.rs b/app_rust/src/commapi/protocols/mod.rs index 4d7ace8..5871d2e 100644 --- a/app_rust/src/commapi/protocols/mod.rs +++ b/app_rust/src/commapi/protocols/mod.rs @@ -142,7 +142,7 @@ impl DiagServer { impl Drop for DiagServer { fn drop(&mut self) { - println!("Drop for diagserver called!"); + println!("Drop for Diag Server called!"); self.kill_diag_server() } } @@ -157,13 +157,12 @@ pub trait ProtocolServer: Sized { fn is_in_diag_session(&self) -> bool; fn get_last_error(&self) -> Option; - fn run_command_isotp(server: &dyn ComServer, send_id: u32, cmd: u8, args: &[u8], receive_require: bool) -> std::result::Result, ProtocolError> { + fn run_command_iso_tp(server: &dyn ComServer, send_id: u32, cmd: u8, args: &[u8], receive_require: bool) -> std::result::Result, ProtocolError> { let mut data = ISO15765Data { id: send_id, - data: vec![], + data: vec![cmd], pad_frame: false, }; - data.data.push(cmd); data.data.extend_from_slice(args); if !receive_require { server.send_iso15765_data(&[data], 0).map(|_| vec![]).map_err(ProtocolError::CommError) diff --git a/app_rust/src/commapi/protocols/obd2.rs b/app_rust/src/commapi/protocols/obd2.rs index cd6b441..1c64349 100644 --- a/app_rust/src/commapi/protocols/obd2.rs +++ b/app_rust/src/commapi/protocols/obd2.rs @@ -15,7 +15,7 @@ fn read_write_payload_isotp(server: &mut Box, payload: &OBDReques let cfg = ISO15765Config { send_id: 0x07DF, - recv_id: 0x7E8, + recv_id: 0x07E8, block_size: 8, // Sensible decision sep_time: 20, // Sensible decision }; diff --git a/app_rust/src/windows/diag_session/json_session.rs b/app_rust/src/windows/diag_session/json_session.rs index a0d9d78..a57e21a 100644 --- a/app_rust/src/windows/diag_session/json_session.rs +++ b/app_rust/src/windows/diag_session/json_session.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, cmp::min, collections::HashMap, sync::Arc, time::Instant}; +use std::{borrow::Borrow, cell::RefCell, cmp::min, collections::HashMap, sync::Arc, time::Instant}; use commapi::protocols; use common::schema::{OvdECU, diag::service::{ParamDecodeError, Service}, variant::{ECUVariantDefinition, ECUVariantPattern}}; @@ -224,7 +224,7 @@ impl SessionTrait for JsonDiagSession { fn subscription(&self) -> iced::Subscription { if self.looping_service.is_some() { - return time::every(std::time::Duration::from_millis(333)).map(JsonDiagSessionMsg::LoopRead); + return time::every(std::time::Duration::from_millis(500)).map(JsonDiagSessionMsg::LoopRead); } Subscription::none() } @@ -403,12 +403,12 @@ impl ServiceSelector { content_view = content_view.push(button_coloured(&mut self.execb, format!("{}{}", text, curr_service.inner.borrow().name).as_str(), ButtonType::Danger).on_press(SelectorMsg::ExecService)) } if self.can_execute == self.view_selection[0] { - // Show the loop button - content_view = content_view.push(button_coloured(&mut self.l_btn, "Begin loop", ButtonType::Warning).on_press(SelectorMsg::BeginLoopService)) + // Show the graph button + content_view = content_view.push(button_coloured(&mut self.l_btn, "Begin graphing", ButtonType::Info).on_press(SelectorMsg::BeginLoopService)) } } else { // Stop the loop - content_view = content_view.push(button_coloured(&mut self.l_btn, "Stop loop", ButtonType::Warning).on_press(SelectorMsg::StopLoopService)) + content_view = content_view.push(button_coloured(&mut self.l_btn, "Stop graphing", ButtonType::Info).on_press(SelectorMsg::StopLoopService)) } } diff --git a/app_rust/src/windows/diag_session/kwp2000_session.rs b/app_rust/src/windows/diag_session/kwp2000_session.rs index c359908..6c40863 100644 --- a/app_rust/src/windows/diag_session/kwp2000_session.rs +++ b/app_rust/src/windows/diag_session/kwp2000_session.rs @@ -1,6 +1,6 @@ use std::{borrow::BorrowMut, cell::RefCell, sync::{Arc, atomic::AtomicBool}, thread::JoinHandle, time::Instant}; -use iced::{Column, Container, Length, Row, Subscription, time}; +use iced::{Column, Container, Length, Row, Space, Subscription, time}; use log_view::{LogType, LogView}; use crate::{commapi::{comm_api::{ComServer, ISO15765Config}, protocols::{ProtocolServer, kwp2000::KWP2000ECU}}, themes::{ButtonType, TextType, TitleSize, button_outlined, text, title_text}, windows::{diag_manual::DiagManualMessage, window}}; @@ -72,6 +72,10 @@ impl SessionTrait for KWP2000DiagSession { if !in_session { ui = ui.push(button_outlined(&mut self.back_btn, "Back", ButtonType::Secondary).on_press(KWP2000DiagSessionMsg::Back)) } + ui = ui.push(Space::with_height(Length::Fill)); + if let Some(se) = &self.diag_server { + ui = ui.push(Row::new().push(text(format!("Current session type: {}", se.get_session_type().to_string()).as_str(), TextType::Normal))); + } Row::new().spacing(8).padding(8) .push(ui.width(Length::FillPortion(1))) diff --git a/app_rust/src/windows/window.rs b/app_rust/src/windows/window.rs index 0aae063..09f5a8a 100644 --- a/app_rust/src/windows/window.rs +++ b/app_rust/src/windows/window.rs @@ -9,7 +9,7 @@ use crate::windows::diag_home::{DiagHomeMessage}; use crate::windows::obd::{OBDMessage, OBDHome}; use crate::themes::{toggle_theme, button_coloured, ButtonType, container, text, TextType}; -use super::diag_home::{self, DiagHome}; +use super::diag_home::{DiagHome}; // This can be modified by diagnostic sessions in order to disable going @@ -289,9 +289,9 @@ impl MainWindow { impl Drop for MainWindow { fn drop(&mut self) { if let Some(mut s) = self.server.take() { - s.close_iso15765_interface(); - s.close_can_interface(); - s.close_device(); + s.close_iso15765_interface().expect("Error closing ISO15765"); + s.close_can_interface().expect("Error closing can Interface"); + s.close_device().expect("Error closing device"); } } }