Start of config app

This commit is contained in:
Ashcon Mohseninia 2022-01-15 10:25:31 +00:00
parent aceca9c11a
commit e11a52a7c5
6 changed files with 144 additions and 0 deletions

2
config_app/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target/
Cargo.lock

13
config_app/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "config_app"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ecu_diagnostics={git="https://github.com/rnd-ash/ecu_diagnostics"}
eframe = { version = "*", default-features = false, features = ["default_fonts", "egui_glow"] }
egui="0.15.0"
image = "0.23.12"
serialport = "4.0.1" # For manual USB connection

5
config_app/src/main.rs Normal file
View File

@ -0,0 +1,5 @@
mod usb_hw;
fn main() {
println!("Hello, world!");
}

View File

@ -0,0 +1,103 @@
//! Abstraction layer for ECU_Diagnostics crate
//! using the USB connection directly to the ESP32 chip
//! The USB endpoint ONLY supports sending fakes ISO-TP messages
use ecu_diagnostics::{HardwareError, hardware::{HardwareInfo, HardwareResult}, channel::{IsoTPChannel, PayloadChannel}};
use serialport::{FlowControl, ClearBuffer, SerialPortBuilder, DataBits, Parity, StopBits};
pub struct Nag52USB {
port: Box<dyn serialport::SerialPort>,
info: HardwareInfo,
}
unsafe impl Sync for Nag52USB{}
unsafe impl Send for Nag52USB{}
impl Nag52USB {
pub fn new(path: String, baud_rate: u32) -> HardwareResult<Self> {
let mut port = match serialport::new(path, baud_rate)
.flow_control(FlowControl::None)
.baud_rate(256000)
.data_bits(DataBits::Eight)
.timeout(std::time::Duration::from_millis(200))
.stop_bits(StopBits::One)
.parity(Parity::None)
.open() {
Ok(mut p) => {
p.clear(ClearBuffer::All).map_err(|e| HardwareError::APIError { code: 99, desc: format!("Clearbuffer error {}", e.description) })?;
},
Err(e) => return Err(HardwareError::APIError { code: 99, desc: e.description })
};
// Create 2 threads
}
}
impl ecu_diagnostics::hardware::Hardware for Nag52USB {
fn create_iso_tp_channel(this: std::sync::Arc<std::sync::Mutex<Self>>) -> ecu_diagnostics::hardware::HardwareResult<Box<dyn ecu_diagnostics::channel::IsoTPChannel>> {
todo!()
}
fn create_can_channel(_this: std::sync::Arc<std::sync::Mutex<Self>>) -> ecu_diagnostics::hardware::HardwareResult<Box<dyn ecu_diagnostics::channel::CanChannel>> {
Err(HardwareError::ChannelNotSupported)
}
fn is_iso_tp_channel_open(&self) -> bool {
todo!()
}
fn is_can_channel_open(&self) -> bool {
false
}
fn read_battery_voltage(&mut self) -> Option<f32> {
None
}
fn read_ignition_voltage(&mut self) -> Option<f32> {
None
}
fn get_info(&self) -> &ecu_diagnostics::hardware::HardwareInfo {
&self.info
}
}
impl PayloadChannel for Nag52USB {
fn open(&mut self) -> ecu_diagnostics::channel::ChannelResult<()> {
todo!()
}
fn close(&mut self) -> ecu_diagnostics::channel::ChannelResult<()> {
todo!()
}
fn set_ids(&mut self, send: u32, recv: u32) -> ecu_diagnostics::channel::ChannelResult<()> {
todo!()
}
fn read_bytes(&mut self, timeout_ms: u32) -> ecu_diagnostics::channel::ChannelResult<Vec<u8>> {
todo!()
}
fn write_bytes(&mut self, addr: u32, buffer: &[u8], timeout_ms: u32) -> ecu_diagnostics::channel::ChannelResult<()> {
todo!()
}
fn clear_rx_buffer(&mut self) -> ecu_diagnostics::channel::ChannelResult<()> {
todo!()
}
fn clear_tx_buffer(&mut self) -> ecu_diagnostics::channel::ChannelResult<()> {
todo!()
}
}
impl IsoTPChannel for Nag52USB {
fn set_iso_tp_cfg(&mut self, cfg: ecu_diagnostics::channel::IsoTPSettings) -> ecu_diagnostics::channel::ChannelResult<()> {
todo!()
}
}

View File

@ -0,0 +1,2 @@
pub mod diag_usb;
pub mod scanner;

View File

@ -0,0 +1,19 @@
use super::diag_usb::Nag52USB;
pub struct Nag52UsbScanner {}
impl ecu_diagnostics::hardware::HardwareScanner<Nag52USB> for Nag52UsbScanner {
fn list_devices(&self) -> Vec<ecu_diagnostics::hardware::HardwareInfo> {
todo!()
}
fn open_device_by_index(&self, idx: usize) -> ecu_diagnostics::hardware::HardwareResult<std::sync::Arc<std::sync::Mutex<Nag52USB>>> {
todo!()
}
fn open_device_by_name(&self, name: &str) -> ecu_diagnostics::hardware::HardwareResult<std::sync::Arc<std::sync::Mutex<Nag52USB>>> {
todo!()
}
}