Fix lint issues and add comments
Lint issues: - spelling problems - iter instead of into_iter
This commit is contained in:
parent
db4b4d990d
commit
1171380877
|
@ -42,7 +42,7 @@ impl From<u16> for Dtc {
|
|||
1 => Dtc::Chassis(n),
|
||||
2 => Dtc::Body(n),
|
||||
3 => Dtc::Network(n),
|
||||
_ => unreachable!(),
|
||||
_ => unreachable!(), // can't happen, only two bits
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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::<Vec<char>>())
|
||||
.collect::<String>()
|
||||
.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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@ impl From<super::device::Error> for Error {
|
|||
|
||||
impl From<std::num::ParseIntError> 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<std::string::FromUtf8Error> for Error {
|
||||
fn from(e: std::string::FromUtf8Error) -> Self {
|
||||
Error::Other(format!("invalid string recieved: {:?}", e))
|
||||
Error::Other(format!("invalid string received: {:?}", e))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,11 @@ impl<T: Obd2BaseDevice> Obd2Device for Obd2<T> {
|
|||
|
||||
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<T: Obd2BaseDevice> Obd2<T> {
|
|||
.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())
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
//! ```
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
#![warn(missing_docs)]
|
||||
#![warn(missing_docs, clippy::panic)]
|
||||
|
||||
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
|
||||
/// 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<Vec<Vec<u8>>>;
|
||||
|
||||
/// Send command and get list of OBD-II responses as an array
|
||||
|
|
Loading…
Reference in a new issue