diff --git a/src/main.rs b/src/main.rs index 8a10165..9edee86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ fn main() { let mut device = obd2::Obd2::default(); println!("VIN: {:?}", device.get_vin()); + println!("DTC Info: {:#?}", device.get_dtc_info()); let dtcs = device.get_dtcs(); println!("DTCs: {:?}", dtcs); diff --git a/src/obd2/mod.rs b/src/obd2/mod.rs index abb3803..ceeba88 100644 --- a/src/obd2/mod.rs +++ b/src/obd2/mod.rs @@ -121,6 +121,32 @@ impl Obd2 { Ok(String::from_utf8(result)?) } + pub fn get_dtc_info(&mut self) -> Result> { + let result = self.obd_command(0x01, 0x01)?; + + result + .iter() + .map(|response| { + if response.len() == 4 { + Ok(DtcsInfo { + malfunction_indicator_light: (response[0] & 0x80) == 0x80, + dtc_count: response[0] & 0x7f, + common_test_availability: ((response[1] & 0xf0) >> 1) + | (response[1] & 0x07), + is_compression_engine: (response[1] & 0x08) == 0x08, + specific_test_availability: ((response[3] as u16) << 8) + | (response[2] as u16), + }) + } else { + Err(Error::Other(format!( + "get_dtc_info: expected length 4, got {}", + response.len() + ))) + } + }) + .collect() + } + pub fn get_dtcs(&mut self) -> Result>> { let result = self.obd_mode_command(0x03)?; result @@ -156,6 +182,16 @@ impl Obd2 { } } +#[allow(dead_code)] +#[derive(Debug)] +pub struct DtcsInfo { + malfunction_indicator_light: bool, + dtc_count: u8, + common_test_availability: u8, + is_compression_engine: bool, + specific_test_availability: u16, +} + #[derive(Debug)] pub enum Dtc { Powertrain(u16),