diff --git a/src/commands/types.rs b/src/commands/types.rs index 5c10d8b..75f1f21 100644 --- a/src/commands/types.rs +++ b/src/commands/types.rs @@ -42,7 +42,7 @@ impl From for Dtc { 1 => Dtc::Chassis(n), 2 => Dtc::Body(n), 3 => Dtc::Network(n), - _ => unreachable!(), + _ => unreachable!(), // can't happen, only two bits } } } diff --git a/src/device/elm327.rs b/src/device/elm327.rs index 83543a6..59e3c17 100644 --- a/src/device/elm327.rs +++ b/src/device/elm327.rs @@ -23,6 +23,10 @@ pub struct Elm327 { } impl Default for Elm327 { + /// Create a Elm327 device + /// + /// # Panics + /// If the device cannot be initialized. Use [Self::new] for a panic-free API. fn default() -> Self { Elm327::new().unwrap() } @@ -40,7 +44,7 @@ impl Obd2BaseDevice for Elm327 { fn send_cmd(&mut self, data: &[u8]) -> Result<()> { trace!("send_cmd: sending {:?}", std::str::from_utf8(data)); self.send_serial_str( - data.into_iter() + data.iter() .flat_map(|v| format!("{:02X}", v).chars().collect::>()) .collect::() .as_str(), @@ -134,15 +138,22 @@ impl Elm327 { fn reset_protocol(&mut self) -> Result<()> { info!("Performing protocol reset"); + + // set to use automatic protocol selection debug!( "reset_protocol: got response {:?}", self.serial_cmd("ATSP0")? ); + + // perform the search debug!( "reset_protocol: got OBD response {:?}", self.cmd(&[0x01, 0x00])? ); + + // get rid of extra data hanging around in the buffer self.flush_buffers()?; + Ok(()) } diff --git a/src/error.rs b/src/error.rs index 6feac68..f209597 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,12 +27,12 @@ impl From for Error { impl From for Error { fn from(e: std::num::ParseIntError) -> Self { - Error::Other(format!("invalid data recieved: {:?}", e)) + Error::Other(format!("invalid data received: {:?}", e)) } } impl From for Error { fn from(e: std::string::FromUtf8Error) -> Self { - Error::Other(format!("invalid string recieved: {:?}", e)) + Error::Other(format!("invalid string received: {:?}", e)) } } diff --git a/src/interface.rs b/src/interface.rs index 5d49c0b..88328eb 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -17,9 +17,11 @@ impl Obd2Device for Obd2 { for response in result.iter() { if response.first() != Some(&(0x40 | mode)) { + // mismatch of mode in response todo!() } if response.get(1) != Some(&pid) { + // mismatch of PID in response todo!() } } @@ -109,7 +111,8 @@ impl Obd2 { .filter_map(|l| l.split_once(':')) .flat_map(|(idx, data)| { if u8::from_str_radix(idx, 16) != Ok(n_idx) { - todo!() + // got an invalid hex code or values were not already in the correct order + todo!("Line index: {}, should be {:X}", idx, n_idx) } n_idx = (n_idx + 1) % 0x10; data.split_whitespace().map(|s| s.to_owned()) diff --git a/src/lib.rs b/src/lib.rs index b0b6261..65a7a17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ //! ``` #![forbid(unsafe_code)] -#![warn(missing_docs)] +#![warn(missing_docs, clippy::panic)] pub mod commands; diff --git a/src/obd2_device.rs b/src/obd2_device.rs index 219855e..b7268fd 100644 --- a/src/obd2_device.rs +++ b/src/obd2_device.rs @@ -13,7 +13,7 @@ pub trait Obd2Device { /// /// 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 - /// the mode the vehicle recieved---is validated and removed. + /// the mode the vehicle received---is validated and removed. fn obd_mode_command(&mut self, mode: u8) -> Result>>; /// Send command and get list of OBD-II responses as an array