Documentation and organization improvements
This commit is contained in:
parent
2a43bf94bd
commit
1b4ccd0dde
5 changed files with 131 additions and 49 deletions
|
|
@ -2,14 +2,30 @@ use core::fmt;
|
|||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// A higher-level API for using an OBD-II device
|
||||
pub trait Obd2Device {
|
||||
/// Send an OBD command with mode and PID, and get a list of responses (one for each ECU that
|
||||
/// responds)
|
||||
/// Send an OBD-II command with mode and PID and get responses
|
||||
///
|
||||
/// 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 two bytes of the
|
||||
/// response---representing the mode and PID the vehicle received---are validated and removed.
|
||||
fn obd_command(&mut self, mode: u8, pid: u8) -> Result<Vec<Vec<u8>>>;
|
||||
|
||||
/// Like [obd_command](Self::obd_command), but for commands that do not require a PID
|
||||
/// Send an OBD-II command with only mode and get responses
|
||||
///
|
||||
/// 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.
|
||||
fn obd_mode_command(&mut self, mode: u8) -> Result<Vec<Vec<u8>>>;
|
||||
|
||||
/// Send command and get list of OBD-II responses as an array
|
||||
///
|
||||
/// Like [obd_command](Self::obd_command), but each ECU's response (after removing the first
|
||||
/// two bytes) is converted to an array of the specified length. If any response is the wrong
|
||||
/// length, and error is returned.
|
||||
///
|
||||
/// This function can be used when the response length is known, so that it is easier to index
|
||||
/// into the response without causing a panic and without dealing with Options.
|
||||
fn obd_command_len<const RESPONSE_LENGTH: usize>(
|
||||
&mut self,
|
||||
mode: u8,
|
||||
|
|
@ -25,6 +41,12 @@ pub trait Obd2Device {
|
|||
.collect()
|
||||
}
|
||||
|
||||
/// Send command and get array of OBD-II responses with each as an array
|
||||
///
|
||||
/// Like [obd_command_len](Self::obd_command_len), but also convert the list of ECU responses
|
||||
/// to an array. This can be used when the number of ECUs that should respond is known in
|
||||
/// advance. Most commonly, this will be when the count of ECUs is one, for values where only a
|
||||
/// single ECU should respond like the speed of the vehicle.
|
||||
fn obd_command_cnt_len<const RESPONSE_COUNT: usize, const RESPONSE_LENGTH: usize>(
|
||||
&mut self,
|
||||
mode: u8,
|
||||
|
|
@ -37,8 +59,10 @@ pub trait Obd2Device {
|
|||
.map_err(|_| Error::IncorrectResponseLength("count", RESPONSE_COUNT, count))
|
||||
}
|
||||
|
||||
/// Retreive the VIN (vehicle identification number), this should match the one printed on the
|
||||
/// vehicle
|
||||
/// Retreive the VIN (vehicle identification number)
|
||||
///
|
||||
/// This should match the number printed on the vehicle, and is a good command for checking
|
||||
/// that the OBD-II interface is working correctly.
|
||||
fn get_vin(&mut self) -> Result<String> {
|
||||
let mut result = self.obd_command(0x09, 0x02)?.pop().unwrap();
|
||||
result.remove(0); // do not know what this byte is
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue