Skip to content

Commit

Permalink
Merge pull request #26 from rnd-ash/comm_api_rework
Browse files Browse the repository at this point in the history
Version 1.0.5
  • Loading branch information
rnd-ash authored May 15, 2021
2 parents 98ca22d + c5ecc57 commit 62f7ff1
Show file tree
Hide file tree
Showing 46 changed files with 2,656 additions and 1,179 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The idea is to make diagnosing and exploring your cars diagnostics functions pos
This is for my University FYP for my degree at the University of Reading

### Latest release
[Version 1.0.0 (21/04/21)](https://github.com/rnd-ash/OpenVehicleDiag/releases/tag/v1.0.0)
[Version 1.0.5 (15/05/21)](https://github.com/rnd-ash/OpenVehicleDiag/releases/tag/v1.0.0)

## Youtube video playlist
Videos showing OpenVehicleDiag in use and its development progress can be found [here](https://youtube.com/playlist?list=PLxrw-4Vt7xtty50LmMoLXN2iKiUknbMng)
Expand Down
5 changes: 4 additions & 1 deletion app_rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[package]
name = "openvehiclediag"
version = "1.0.0"
version = "1.0.5"
description = "pen Vehicle Diagnostics (OVD) is a Rust-based open source vehicle ECU diagnostic platform."
edition = "2018"

[package.metadata.bundle]
version = "0.6.0"
authors = ["ashcon"]
Expand Down Expand Up @@ -33,6 +34,8 @@ hex-serde = "0.1.0"
chrono = "0.4.19"
hex = "0.4.2"
image = "0.23.12"
dialog = "0.3.0"
backtrace = "0.3.59"

[target.'cfg(windows)'.dependencies]
winreg = "0.8"
Expand Down
2 changes: 0 additions & 2 deletions app_rust/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Open vehicle diagnostics app



## Features (Current)
* CAN Tracer
* OBD Toolbox
Expand Down
2 changes: 1 addition & 1 deletion app_rust/src/cli_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub mod draw_routine {
block_size: 8,
sep_time: 20,
use_ext_isotp: false,
use_ext_can: false
use_ext_can: false,
},
None,
)
Expand Down
58 changes: 11 additions & 47 deletions app_rust/src/commapi/comm_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ pub struct ISO15765Config {
unsafe impl Send for ISO15765Config {}
unsafe impl Sync for ISO15765Config {}

#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum FilterType {
Pass,
Block,
Pass { id: u32, mask: u32 },
Block { id: u32, mask: u32 },
IsoTP { id: u32, mask: u32, fc: u32 },
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -224,8 +225,11 @@ pub trait ComServer: Send + Sync + Debug {
/// ## Returns
/// The number of CAN Frames successfully written to the vehicle, if Timeout is 0, this
/// number will always be equal to the number of frames that were provided.
fn send_can_packets(&mut self, data: &[CanFrame], timeout_ms: u32)
-> Result<usize, ComServerError>;
fn send_can_packets(
&mut self,
data: &[CanFrame],
timeout_ms: u32,
) -> Result<usize, ComServerError>;

/// Returns a boolean indicating if there is at least 1 channel communicating with the car
fn is_connected(&self) -> bool;
Expand Down Expand Up @@ -326,27 +330,14 @@ pub trait ComServer: Send + Sync + Debug {
///
/// ## Returns
/// The filter ID provided by the adapter. Use this when destroying the filter
fn add_can_filter(&mut self, filter: FilterType, id: u32, mask: u32)
-> Result<u32, ComServerError>;
fn add_can_filter(&mut self, f: FilterType) -> Result<u32, ComServerError>;

/// Tells the adapter to remove an active filter on an open CAN channel
/// # Params
/// * filter_idx - Filter ID to remove, this should be the value given by [`add_can_filter`](fn@add_can_filter)
fn rem_can_filter(&mut self, filter_idx: u32) -> Result<(), ComServerError>;

fn add_iso15765_filter(&mut self, id: u32, mask: u32, fc_id: u32) -> Result<u32, ComServerError>;

fn configure_iso15765(&mut self, cfg: &ISO15765Config) -> Result<u32, ComServerError> {
self.add_iso15765_filter(cfg.recv_id, 0xFFFF, cfg.send_id)
.and_then(|idx| {
self.set_iso15765_params(cfg.sep_time, cfg.block_size)
.map(|_| idx)
.map_err(|e| match self.rem_iso15765_filter(idx) {
Ok(_) => e,
Err(e1) => e1,
})
})
}
fn add_iso15765_filter(&mut self, f: FilterType) -> Result<u32, ComServerError>;

/// Tells the adapter to remove an active filter on an open ISO15765 channel
/// # Params
Expand All @@ -369,33 +360,6 @@ pub trait ComServer: Send + Sync + Debug {
block_size: u32,
) -> Result<(), ComServerError>;

/// Sends an ISOTP payload and attempts to read the ECUs response
/// IMPORTANT - This function assumes the ISO15765 interface is ALREADY open
fn send_receive_iso15765(
&self,
p: ISO15765Data,
max_timeout_ms: u128,
max_resp: usize,
) -> Result<Vec<ISO15765Data>, ComServerError> {
self.clear_iso15765_rx_buffer()?; // Clear the receive buffer
self.send_iso15765_data(&[p], 0)?; // Send data
let mut timeout = max_timeout_ms;
let mut payloads: Vec<ISO15765Data> = Vec::new();
let start = Instant::now();
while start.elapsed().as_millis() < timeout {
if let Ok(d) = self.read_iso15765_packets(0, 10) {
for msg in d {
payloads.push(msg);
if max_resp != 0 && payloads.len() >= max_resp {
timeout = 0; // Return now!
}
}
}
std::thread::sleep(std::time::Duration::from_millis(1));
}
Ok(payloads)
}

/// Tells the adapter to clear any data in its Rx buffer
/// that is from CAN protocol
fn clear_can_rx_buffer(&self) -> Result<(), ComServerError>;
Expand Down
Loading

0 comments on commit 62f7ff1

Please sign in to comment.