Skip to content

Commit

Permalink
Version 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rnd-ash committed Feb 10, 2021
1 parent d2e0d33 commit c4f7227
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app_rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openvehiclediag"
version = "0.1.0"
version = "0.5.0"
authors = ["ashcon"]
edition = "2018"

Expand Down
16 changes: 14 additions & 2 deletions app_rust/src/commapi/protocols/kwp2000.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions app_rust/src/commapi/protocols/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -157,13 +157,12 @@ pub trait ProtocolServer: Sized {
fn is_in_diag_session(&self) -> bool;
fn get_last_error(&self) -> Option<String>;

fn run_command_isotp(server: &dyn ComServer, send_id: u32, cmd: u8, args: &[u8], receive_require: bool) -> std::result::Result<Vec<u8>, ProtocolError> {
fn run_command_iso_tp(server: &dyn ComServer, send_id: u32, cmd: u8, args: &[u8], receive_require: bool) -> std::result::Result<Vec<u8>, 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)
Expand Down
2 changes: 1 addition & 1 deletion app_rust/src/commapi/protocols/obd2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn read_write_payload_isotp(server: &mut Box<dyn ComServer>, payload: &OBDReques

let cfg = ISO15765Config {
send_id: 0x07DF,
recv_id: 0x7E8,
recv_id: 0x07E8,
block_size: 8, // Sensible decision
sep_time: 20, // Sensible decision
};
Expand Down
10 changes: 5 additions & 5 deletions app_rust/src/windows/diag_session/json_session.rs
Original file line number Diff line number Diff line change
@@ -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}};
Expand Down Expand Up @@ -224,7 +224,7 @@ impl SessionTrait for JsonDiagSession {

fn subscription(&self) -> iced::Subscription<Self::msg> {
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()
}
Expand Down Expand Up @@ -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))
}
}

Expand Down
6 changes: 5 additions & 1 deletion app_rust/src/windows/diag_session/kwp2000_session.rs
Original file line number Diff line number Diff line change
@@ -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}};
Expand Down Expand Up @@ -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)))
Expand Down
8 changes: 4 additions & 4 deletions app_rust/src/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit c4f7227

Please sign in to comment.