Compare commits
	
		
			1 commit
		
	
	
		
			1769d2a84b
			...
			642d2255ef
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 642d2255ef | 
					 12 changed files with 98 additions and 125 deletions
				
			
		| 
						 | 
					@ -8,11 +8,7 @@ edition = "2021"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[dependencies]
 | 
					[dependencies]
 | 
				
			||||||
env_logger = "0.10"
 | 
					env_logger = "0.10"
 | 
				
			||||||
 | 
					ftdi = "0.1.3"
 | 
				
			||||||
log = "0.4.8"
 | 
					log = "0.4.8"
 | 
				
			||||||
thiserror = "1.0.15"
 | 
					thiserror = "1.0.15"
 | 
				
			||||||
ftdi = { version = "0.1.3", optional = true }
 | 
					serialport="=4.6.1"
 | 
				
			||||||
serialport= { version = "=4.6.1", optional = true }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
[features]
 | 
					 | 
				
			||||||
ftdi_comm = [ "dep:ftdi" ]
 | 
					 | 
				
			||||||
serialport_comm = [ "dep:serialport" ]
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -220,4 +220,7 @@ 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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Get the fuel level (out of 255)
 | 
				
			||||||
 | 
					    fn get_fuel_level(0x01, 0x2F) -> u8;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -42,7 +42,7 @@ impl From<u16> for Dtc {
 | 
				
			||||||
            1 => Dtc::Chassis(n),
 | 
					            1 => Dtc::Chassis(n),
 | 
				
			||||||
            2 => Dtc::Body(n),
 | 
					            2 => Dtc::Body(n),
 | 
				
			||||||
            3 => Dtc::Network(n),
 | 
					            3 => Dtc::Network(n),
 | 
				
			||||||
            _ => unreachable!(), // can't happen, only two bits
 | 
					            _ => unreachable!(),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ impl<T: SerialComm> Obd2BaseDevice for Elm327<T> {
 | 
				
			||||||
    fn send_cmd(&mut self, data: &[u8]) -> Result<()> {
 | 
					    fn send_cmd(&mut self, data: &[u8]) -> Result<()> {
 | 
				
			||||||
        trace!("send_cmd: sending {:?}", std::str::from_utf8(data));
 | 
					        trace!("send_cmd: sending {:?}", std::str::from_utf8(data));
 | 
				
			||||||
        self.send_serial_str(
 | 
					        self.send_serial_str(
 | 
				
			||||||
            data.iter()
 | 
					            data.into_iter()
 | 
				
			||||||
                .flat_map(|v| format!("{:02X}", v).chars().collect::<Vec<char>>())
 | 
					                .flat_map(|v| format!("{:02X}", v).chars().collect::<Vec<char>>())
 | 
				
			||||||
                .collect::<String>()
 | 
					                .collect::<String>()
 | 
				
			||||||
                .as_str(),
 | 
					                .as_str(),
 | 
				
			||||||
| 
						 | 
					@ -115,18 +115,13 @@ impl<T: SerialComm> Elm327<T> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fn reset_protocol(&mut self) -> Result<()> {
 | 
					    fn reset_protocol(&mut self) -> Result<()> {
 | 
				
			||||||
        info!("Performing protocol reset");
 | 
					        info!("Performing protocol reset");
 | 
				
			||||||
 | 
					 | 
				
			||||||
        // set to use automatic protocol selection
 | 
					 | 
				
			||||||
        let elm_response = self.serial_cmd("ATSP0")?;
 | 
					        let elm_response = self.serial_cmd("ATSP0")?;
 | 
				
			||||||
        debug!("reset_protocol: got response {:?}", elm_response);
 | 
					        debug!("reset_protocol: got response {:?}", elm_response);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // perform the search for ECUs
 | 
					 | 
				
			||||||
        let obd_response = self.cmd(&[0x01, 0x00])?;
 | 
					        let obd_response = self.cmd(&[0x01, 0x00])?;
 | 
				
			||||||
        debug!("reset_protocol: got OBD response {:?}", obd_response);
 | 
					        debug!("reset_protocol: got OBD response {:?}", obd_response);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // get rid of extra data hanging around in the buffer
 | 
					 | 
				
			||||||
        self.flush_buffers()?;
 | 
					        self.flush_buffers()?;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,42 +0,0 @@
 | 
				
			||||||
use super::serial_comm::{SerialComm, DEFAULT_BAUD_RATE};
 | 
					 | 
				
			||||||
use super::Result;
 | 
					 | 
				
			||||||
use std::io::{Read, Write};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/// Communicate with a USB to Serial FTDI device
 | 
					 | 
				
			||||||
/// with the FTDI library
 | 
					 | 
				
			||||||
pub struct FTDIDevice {
 | 
					 | 
				
			||||||
    device: ftdi::Device,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl FTDIDevice {
 | 
					 | 
				
			||||||
    /// Creates a new instance of an FTDIDevice
 | 
					 | 
				
			||||||
    pub fn new() -> Result<Self> {
 | 
					 | 
				
			||||||
        let mut device = ftdi::find_by_vid_pid(0x0404, 0x6001)
 | 
					 | 
				
			||||||
            .interface(ftdi::Interface::A)
 | 
					 | 
				
			||||||
            .open()?;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        device.set_baud_rate(DEFAULT_BAUD_RATE)?;
 | 
					 | 
				
			||||||
        device.configure(ftdi::Bits::Eight, ftdi::StopBits::One, ftdi::Parity::None)?;
 | 
					 | 
				
			||||||
        device.usb_reset()?;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Ok(Self { device })
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl SerialComm for FTDIDevice {
 | 
					 | 
				
			||||||
    fn write_all(&mut self, data: &[u8]) -> Result<()> {
 | 
					 | 
				
			||||||
        Ok(self.device.write_all(data)?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fn read(&mut self, data: &mut [u8]) -> Result<usize> {
 | 
					 | 
				
			||||||
        Ok(self.device.read(data)?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()> {
 | 
					 | 
				
			||||||
        Ok(self.device.set_baud_rate(baud_rate)?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fn purge_buffers(&mut self) -> Result<()> {
 | 
					 | 
				
			||||||
        Ok(self.device.usb_purge_buffers()?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -4,16 +4,7 @@ mod elm327;
 | 
				
			||||||
pub use elm327::Elm327;
 | 
					pub use elm327::Elm327;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mod serial_comm;
 | 
					mod serial_comm;
 | 
				
			||||||
 | 
					pub use serial_comm::{FTDIDevice, SerialPort};
 | 
				
			||||||
#[cfg(feature = "ftdi_comm")]
 | 
					 | 
				
			||||||
mod ftdi_comm;
 | 
					 | 
				
			||||||
#[cfg(feature = "ftdi_comm")]
 | 
					 | 
				
			||||||
pub use ftdi_comm::FTDIDevice;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#[cfg(feature = "serialport_comm")]
 | 
					 | 
				
			||||||
mod serialport_comm;
 | 
					 | 
				
			||||||
#[cfg(feature = "serialport_comm")]
 | 
					 | 
				
			||||||
pub use serialport_comm::SerialPort;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Result<T> = std::result::Result<T, Error>;
 | 
					type Result<T> = std::result::Result<T, Error>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,12 +54,10 @@ pub trait Obd2Reader {
 | 
				
			||||||
#[derive(thiserror::Error, Debug)]
 | 
					#[derive(thiserror::Error, Debug)]
 | 
				
			||||||
pub enum Error {
 | 
					pub enum Error {
 | 
				
			||||||
    /// An error with the underlying [FTDI device](ftdi::Device)
 | 
					    /// An error with the underlying [FTDI device](ftdi::Device)
 | 
				
			||||||
    #[cfg(feature = "ftdi_comm")]
 | 
					 | 
				
			||||||
    #[error("FTDI error: `{0:?}`")]
 | 
					    #[error("FTDI error: `{0:?}`")]
 | 
				
			||||||
    Ftdi(ftdi::Error),
 | 
					    Ftdi(ftdi::Error),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// An error with the underlying [serialport device](serialport::SerialPort)
 | 
					    /// An error with the underlying [serialport device](serialport::SerialPort)
 | 
				
			||||||
    #[cfg(feature = "serialport_comm")]
 | 
					 | 
				
			||||||
    #[error("Serialport error: `{0:?}`")]
 | 
					    #[error("Serialport error: `{0:?}`")]
 | 
				
			||||||
    Serialport(serialport::Error),
 | 
					    Serialport(serialport::Error),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -81,14 +70,12 @@ pub enum Error {
 | 
				
			||||||
    Communication(String),
 | 
					    Communication(String),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(feature = "ftdi_comm")]
 | 
					 | 
				
			||||||
impl From<ftdi::Error> for Error {
 | 
					impl From<ftdi::Error> for Error {
 | 
				
			||||||
    fn from(e: ftdi::Error) -> Self {
 | 
					    fn from(e: ftdi::Error) -> Self {
 | 
				
			||||||
        Error::Ftdi(e)
 | 
					        Error::Ftdi(e)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(feature = "serialport_comm")]
 | 
					 | 
				
			||||||
impl From<serialport::Error> for Error {
 | 
					impl From<serialport::Error> for Error {
 | 
				
			||||||
    fn from(e: serialport::Error) -> Self {
 | 
					    fn from(e: serialport::Error) -> Self {
 | 
				
			||||||
        Error::Serialport(e)
 | 
					        Error::Serialport(e)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,8 @@
 | 
				
			||||||
use super::Result;
 | 
					use super::Result;
 | 
				
			||||||
 | 
					use std::io::{Read, Write};
 | 
				
			||||||
 | 
					use std::time::Duration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub const DEFAULT_BAUD_RATE: u32 = 38_400;
 | 
					const DEFAULT_BAUD_RATE: u32 = 38_400;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// An API to communicate with a serial device
 | 
					/// An API to communicate with a serial device
 | 
				
			||||||
pub trait SerialComm {
 | 
					pub trait SerialComm {
 | 
				
			||||||
| 
						 | 
					@ -9,3 +11,84 @@ pub trait SerialComm {
 | 
				
			||||||
    fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()>;
 | 
					    fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()>;
 | 
				
			||||||
    fn purge_buffers(&mut self) -> Result<()>;
 | 
					    fn purge_buffers(&mut self) -> Result<()>;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Communicate with a serial device using the
 | 
				
			||||||
 | 
					/// serialport library
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// /dev/tty* or similar on unix-like systems
 | 
				
			||||||
 | 
					/// COM devices on Windows systems
 | 
				
			||||||
 | 
					pub struct SerialPort {
 | 
				
			||||||
 | 
					    device: Box<dyn serialport::SerialPort>,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl SerialPort {
 | 
				
			||||||
 | 
					    /// Creates a new instance of a SerialPort
 | 
				
			||||||
 | 
					    pub fn new(path: &str) -> Result<Self> {
 | 
				
			||||||
 | 
					        let device = serialport::new(path, DEFAULT_BAUD_RATE)
 | 
				
			||||||
 | 
					            .timeout(Duration::from_millis(10))
 | 
				
			||||||
 | 
					            .parity(serialport::Parity::None)
 | 
				
			||||||
 | 
					            .data_bits(serialport::DataBits::Eight)
 | 
				
			||||||
 | 
					            .stop_bits(serialport::StopBits::One)
 | 
				
			||||||
 | 
					            .path(path)
 | 
				
			||||||
 | 
					            .open()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Ok(Self { device })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl SerialComm for SerialPort {
 | 
				
			||||||
 | 
					    fn write_all(&mut self, data: &[u8]) -> Result<()> {
 | 
				
			||||||
 | 
					        Ok(self.device.write_all(data)?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn read(&mut self, data: &mut [u8]) -> Result<usize> {
 | 
				
			||||||
 | 
					        Ok(self.device.read(data)?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()> {
 | 
				
			||||||
 | 
					        Ok(self.device.set_baud_rate(baud_rate)?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn purge_buffers(&mut self) -> Result<()> {
 | 
				
			||||||
 | 
					        Ok(self.device.clear(serialport::ClearBuffer::All)?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Communicate with a USB to Serial FTDI device
 | 
				
			||||||
 | 
					/// with the FTDI library
 | 
				
			||||||
 | 
					pub struct FTDIDevice {
 | 
				
			||||||
 | 
					    device: ftdi::Device,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl FTDIDevice {
 | 
				
			||||||
 | 
					    /// Creates a new instance of an FTDIDevice
 | 
				
			||||||
 | 
					    pub fn new() -> Result<Self> {
 | 
				
			||||||
 | 
					        let mut device = ftdi::find_by_vid_pid(0x0404, 0x6001)
 | 
				
			||||||
 | 
					            .interface(ftdi::Interface::A)
 | 
				
			||||||
 | 
					            .open()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        device.set_baud_rate(DEFAULT_BAUD_RATE)?;
 | 
				
			||||||
 | 
					        device.configure(ftdi::Bits::Eight, ftdi::StopBits::One, ftdi::Parity::None)?;
 | 
				
			||||||
 | 
					        device.usb_reset()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Ok(Self { device })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl SerialComm for FTDIDevice {
 | 
				
			||||||
 | 
					    fn write_all(&mut self, data: &[u8]) -> Result<()> {
 | 
				
			||||||
 | 
					        Ok(self.device.write_all(data)?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn read(&mut self, data: &mut [u8]) -> Result<usize> {
 | 
				
			||||||
 | 
					        Ok(self.device.read(data)?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()> {
 | 
				
			||||||
 | 
					        Ok(self.device.set_baud_rate(baud_rate)?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn purge_buffers(&mut self) -> Result<()> {
 | 
				
			||||||
 | 
					        Ok(self.device.usb_purge_buffers()?)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,46 +0,0 @@
 | 
				
			||||||
use super::serial_comm::{SerialComm, DEFAULT_BAUD_RATE};
 | 
					 | 
				
			||||||
use super::Result;
 | 
					 | 
				
			||||||
use std::io::{Read, Write};
 | 
					 | 
				
			||||||
use std::time::Duration;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/// Communicate with a serial device using the
 | 
					 | 
				
			||||||
/// serialport library
 | 
					 | 
				
			||||||
///
 | 
					 | 
				
			||||||
/// /dev/tty* or similar on unix-like systems
 | 
					 | 
				
			||||||
/// COM devices on Windows systems
 | 
					 | 
				
			||||||
pub struct SerialPort {
 | 
					 | 
				
			||||||
    device: Box<dyn serialport::SerialPort>,
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl SerialPort {
 | 
					 | 
				
			||||||
    /// Creates a new instance of a SerialPort
 | 
					 | 
				
			||||||
    pub fn new(path: &str) -> Result<Self> {
 | 
					 | 
				
			||||||
        let device = serialport::new(path, DEFAULT_BAUD_RATE)
 | 
					 | 
				
			||||||
            .timeout(Duration::from_millis(10))
 | 
					 | 
				
			||||||
            .parity(serialport::Parity::None)
 | 
					 | 
				
			||||||
            .data_bits(serialport::DataBits::Eight)
 | 
					 | 
				
			||||||
            .stop_bits(serialport::StopBits::One)
 | 
					 | 
				
			||||||
            .path(path)
 | 
					 | 
				
			||||||
            .open()?;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        Ok(Self { device })
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl SerialComm for SerialPort {
 | 
					 | 
				
			||||||
    fn write_all(&mut self, data: &[u8]) -> Result<()> {
 | 
					 | 
				
			||||||
        Ok(self.device.write_all(data)?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fn read(&mut self, data: &mut [u8]) -> Result<usize> {
 | 
					 | 
				
			||||||
        Ok(self.device.read(data)?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fn set_baud_rate(&mut self, baud_rate: u32) -> Result<()> {
 | 
					 | 
				
			||||||
        Ok(self.device.set_baud_rate(baud_rate)?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    fn purge_buffers(&mut self) -> Result<()> {
 | 
					 | 
				
			||||||
        Ok(self.device.clear(serialport::ClearBuffer::All)?)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -21,7 +21,7 @@ pub enum Error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// An error with the ELM327 device
 | 
					/// An error with the ELM327 device
 | 
				
			||||||
#[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 {
 | 
				
			||||||
| 
						 | 
					@ -31,12 +31,12 @@ impl From<super::device::Error> for Error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl From<std::num::ParseIntError> for Error {
 | 
					impl From<std::num::ParseIntError> for Error {
 | 
				
			||||||
    fn from(e: std::num::ParseIntError) -> Self {
 | 
					    fn from(e: std::num::ParseIntError) -> Self {
 | 
				
			||||||
        Error::Other(format!("invalid data recieved: {:?}", e))
 | 
					        Error::Other(format!("invalid data received: {:?}", e))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl From<std::string::FromUtf8Error> for Error {
 | 
					impl From<std::string::FromUtf8Error> for Error {
 | 
				
			||||||
    fn from(e: std::string::FromUtf8Error) -> Self {
 | 
					    fn from(e: std::string::FromUtf8Error) -> Self {
 | 
				
			||||||
        Error::Other(format!("invalid string recieved: {:?}", e))
 | 
					        Error::Other(format!("invalid string received: {:?}", e))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,11 +16,9 @@ impl<T: Obd2BaseDevice> Obd2Device for Obd2<T> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for response in result.iter() {
 | 
					        for response in result.iter() {
 | 
				
			||||||
            if response.first() != Some(&(0x40 | mode)) {
 | 
					            if response.first() != Some(&(0x40 | mode)) {
 | 
				
			||||||
                // mismatch of mode in response
 | 
					 | 
				
			||||||
                todo!()
 | 
					                todo!()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if response.get(1) != Some(&pid) {
 | 
					            if response.get(1) != Some(&pid) {
 | 
				
			||||||
                // mismatch of PID in response
 | 
					 | 
				
			||||||
                todo!()
 | 
					                todo!()
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -122,8 +120,7 @@ impl<T: Obd2BaseDevice> Obd2<T> {
 | 
				
			||||||
            .filter_map(|l| l.split_once(':'))
 | 
					            .filter_map(|l| l.split_once(':'))
 | 
				
			||||||
            .flat_map(|(idx, data)| {
 | 
					            .flat_map(|(idx, data)| {
 | 
				
			||||||
                if u8::from_str_radix(idx, 16) != Ok(n_idx) {
 | 
					                if u8::from_str_radix(idx, 16) != Ok(n_idx) {
 | 
				
			||||||
                    // got an invalid hex code or values were not already in the correct order
 | 
					                    todo!()
 | 
				
			||||||
                    todo!("Line index: {}, should be {:X}", idx, n_idx)
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                n_idx = (n_idx + 1) % 0x10;
 | 
					                n_idx = (n_idx + 1) % 0x10;
 | 
				
			||||||
                data.split_whitespace().map(|s| s.to_owned())
 | 
					                data.split_whitespace().map(|s| s.to_owned())
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,7 +22,7 @@
 | 
				
			||||||
//! ```
 | 
					//! ```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#![forbid(unsafe_code)]
 | 
					#![forbid(unsafe_code)]
 | 
				
			||||||
#![warn(missing_docs, clippy::panic)]
 | 
					#![warn(missing_docs)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub mod commands;
 | 
					pub mod commands;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ pub trait Obd2Device {
 | 
				
			||||||
    ///
 | 
					    ///
 | 
				
			||||||
    /// The responses are a list with one element for each ECU that responds. The data is decoded
 | 
					    /// The responses are a list with one element for each ECU that responds. The data is decoded
 | 
				
			||||||
    /// into the ODB-II bytes from the vehicle and the first byte of the response---representing
 | 
					    /// into the ODB-II bytes from the vehicle and the first byte of the response---representing
 | 
				
			||||||
    /// the mode the vehicle received---is validated and removed.
 | 
					    /// the mode the vehicle recieved---is validated and removed.
 | 
				
			||||||
    fn obd_mode_command(&mut self, mode: u8) -> Result<Vec<Vec<u8>>>;
 | 
					    fn obd_mode_command(&mut self, mode: u8) -> Result<Vec<Vec<u8>>>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// Send command and get list of OBD-II responses as an array
 | 
					    /// Send command and get list of OBD-II responses as an array
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue