api modifications
This commit is contained in:
parent
db4b4d990d
commit
0994648ed1
|
@ -11,3 +11,5 @@ env_logger = "0.10"
|
||||||
ftdi = "0.1.3"
|
ftdi = "0.1.3"
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
thiserror = "1.0.15"
|
thiserror = "1.0.15"
|
||||||
|
serialport="=4.6.1"
|
||||||
|
anyhow = "1.0.97"
|
||||||
|
|
|
@ -220,4 +220,6 @@ func! {
|
||||||
|
|
||||||
/// Get service 1 PID support for $21 to $40
|
/// Get service 1 PID support for $21 to $40
|
||||||
fn get_service_1_pid_support_2(0x01, 0x20) -> u32;
|
fn get_service_1_pid_support_2(0x01, 0x20) -> u32;
|
||||||
|
|
||||||
|
fn get_fuel_level(0x01, 0x2F) -> u8;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,6 @@ pub struct Elm327 {
|
||||||
baud_rate: u32,
|
baud_rate: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Elm327 {
|
|
||||||
fn default() -> Self {
|
|
||||||
Elm327::new().unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Obd2BaseDevice for Elm327 {
|
impl Obd2BaseDevice for Elm327 {
|
||||||
fn reset(&mut self) -> Result<()> {
|
fn reset(&mut self) -> Result<()> {
|
||||||
self.flush_buffers()?;
|
self.flush_buffers()?;
|
||||||
|
@ -66,7 +60,7 @@ impl Obd2Reader for Elm327 {
|
||||||
|
|
||||||
impl Elm327 {
|
impl Elm327 {
|
||||||
fn new() -> Result<Self> {
|
fn new() -> Result<Self> {
|
||||||
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)
|
.interface(ftdi::Interface::A)
|
||||||
.open()?;
|
.open()?;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
mod elm327;
|
mod elm327;
|
||||||
pub use elm327::Elm327;
|
pub use elm327::Elm327;
|
||||||
|
|
||||||
|
mod elm327_linux;
|
||||||
|
pub use elm327_linux::Elm327Linux;
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
/// A lower-level API for using an OBD-II device
|
/// A lower-level API for using an OBD-II device
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DeviceError(crate::device::Error);
|
pub struct DeviceError(pub crate::device::Error);
|
||||||
|
|
||||||
impl From<super::device::Error> for Error {
|
impl From<super::device::Error> for Error {
|
||||||
fn from(e: super::device::Error) -> Self {
|
fn from(e: super::device::Error) -> Self {
|
||||||
|
|
|
@ -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
|
/// Wraps an implementer of [Obd2BaseDevice] to allow for higher-level usage of the OBD-II
|
||||||
/// interface.
|
/// interface.
|
||||||
#[derive(Default)]
|
|
||||||
pub struct Obd2<T: Obd2BaseDevice> {
|
pub struct Obd2<T: Obd2BaseDevice> {
|
||||||
device: T,
|
device: T,
|
||||||
}
|
}
|
||||||
|
@ -41,6 +40,14 @@ impl<T: Obd2BaseDevice> Obd2Device for Obd2<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Obd2BaseDevice> Obd2<T> {
|
impl<T: Obd2BaseDevice> Obd2<T> {
|
||||||
|
pub fn new(dev: T) -> ::anyhow::Result<Self> {
|
||||||
|
let mut device = Obd2 {
|
||||||
|
device: dev
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(device)
|
||||||
|
}
|
||||||
|
|
||||||
fn command(&mut self, command: &[u8]) -> Result<Vec<Vec<u8>>> {
|
fn command(&mut self, command: &[u8]) -> Result<Vec<Vec<u8>>> {
|
||||||
let response = self
|
let response = self
|
||||||
.device
|
.device
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub mod commands;
|
||||||
|
|
||||||
pub mod device;
|
pub mod device;
|
||||||
|
|
||||||
mod error;
|
pub mod error;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
use error::Result;
|
use error::Result;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue