diff --git a/Cargo.toml b/Cargo.toml index ec43f5f..75dc960 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,5 @@ env_logger = "0.10" ftdi = "0.1.3" log = "0.4.8" thiserror = "1.0.15" +serialport="=4.6.1" +anyhow = "1.0.97" diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 1265eb9..8ce16d5 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -220,4 +220,6 @@ func! { /// Get service 1 PID support for $21 to $40 fn get_service_1_pid_support_2(0x01, 0x20) -> u32; + + fn get_fuel_level(0x01, 0x2F) -> u8; } diff --git a/src/device/elm327.rs b/src/device/elm327.rs index 83543a6..5482193 100644 --- a/src/device/elm327.rs +++ b/src/device/elm327.rs @@ -22,12 +22,6 @@ pub struct Elm327 { baud_rate: u32, } -impl Default for Elm327 { - fn default() -> Self { - Elm327::new().unwrap() - } -} - impl Obd2BaseDevice for Elm327 { fn reset(&mut self) -> Result<()> { self.flush_buffers()?; @@ -66,7 +60,7 @@ impl Obd2Reader for Elm327 { impl Elm327 { fn new() -> Result { - let mut ftdi_device = ftdi::find_by_vid_pid(0x0403, 0x6001) + let mut ftdi_device = ftdi::find_by_vid_pid(0x0404, 0x6001) .interface(ftdi::Interface::A) .open()?; diff --git a/src/device/mod.rs b/src/device/mod.rs index 1f0f561..9a8d934 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -3,6 +3,9 @@ mod elm327; pub use elm327::Elm327; +mod elm327_linux; +pub use elm327_linux::Elm327Linux; + type Result = std::result::Result; /// A lower-level API for using an OBD-II device diff --git a/src/error.rs b/src/error.rs index 6feac68..725427f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -17,7 +17,7 @@ pub enum Error { } #[derive(Debug)] -pub struct DeviceError(crate::device::Error); +pub struct DeviceError(pub crate::device::Error); impl From for Error { fn from(e: super::device::Error) -> Self { diff --git a/src/interface.rs b/src/interface.rs index 5d49c0b..d9beb4c 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -6,7 +6,6 @@ use super::{device::Obd2BaseDevice, Error, Obd2Device, Result}; /// /// Wraps an implementer of [Obd2BaseDevice] to allow for higher-level usage of the OBD-II /// interface. -#[derive(Default)] pub struct Obd2 { device: T, } @@ -41,6 +40,14 @@ impl Obd2Device for Obd2 { } impl Obd2 { + pub fn new(dev: T) -> ::anyhow::Result { + let mut device = Obd2 { + device: dev + }; + + Ok(device) + } + fn command(&mut self, command: &[u8]) -> Result>> { let response = self .device diff --git a/src/lib.rs b/src/lib.rs index b0b6261..7fc066a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,7 @@ pub mod commands; pub mod device; -mod error; +pub mod error; pub use error::Error; use error::Result;