Add more getter functions to the commands module
This commit is contained in:
parent
97f17af790
commit
8d521ff46d
|
@ -22,6 +22,11 @@ fn main() {
|
|||
|
||||
let state = time::Instant::now();
|
||||
while state.elapsed() < time::Duration::from_secs(5) {
|
||||
println!("");
|
||||
println!(
|
||||
"Coolant Temperature: {:?}",
|
||||
device.get_engine_coolant_temperature()
|
||||
);
|
||||
println!("RPM: {:?}", device.get_rpm());
|
||||
println!("Speed: {:?}", device.get_speed());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{commands::Obd2DataRetrieval, Error, Obd2Device, Result};
|
||||
use crate::{Error, Obd2Device, Result};
|
||||
|
||||
use super::{Dtc, DtcsInfo};
|
||||
use super::{Dtc, DtcsInfo, Obd2DataRetrieval};
|
||||
|
||||
impl<T: Obd2Device> Obd2DataRetrieval for T {
|
||||
fn get_vin(&mut self) -> Result<String> {
|
||||
|
@ -72,6 +72,22 @@ impl<T: Obd2Device> Obd2DataRetrieval for T {
|
|||
.collect::<Result<Vec<Vec<Dtc>>>>()
|
||||
}
|
||||
|
||||
fn get_engine_load(&mut self) -> Result<u8> {
|
||||
Ok(self.obd_command_cnt_len::<1, 1>(0x01, 0x0C)?[0][0])
|
||||
}
|
||||
|
||||
fn get_engine_coolant_temperature(&mut self) -> Result<i16> {
|
||||
Ok((self.obd_command_cnt_len::<1, 1>(0x01, 0x0C)?[0][0] as i16) - 40)
|
||||
}
|
||||
|
||||
fn get_fuel_pressure(&mut self) -> Result<i16> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_engine_manifold_pressure(&mut self) -> Result<f32> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn get_rpm(&mut self) -> Result<f32> {
|
||||
let result = self.obd_command_cnt_len::<1, 2>(0x01, 0x0C)?[0];
|
||||
Ok(f32::from(u16::from_be_bytes(result)) / 4.0)
|
||||
|
|
|
@ -16,8 +16,8 @@ pub trait Obd2DataRetrieval: private::Sealed {
|
|||
|
||||
/// 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.
|
||||
/// Service 0x09, PID 0x01. 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>;
|
||||
|
||||
/// Get DTC (diagnostic trouble code) metadata for each ECU
|
||||
|
@ -26,8 +26,21 @@ pub trait Obd2DataRetrieval: private::Sealed {
|
|||
/// Get DTCs for each ECU
|
||||
fn get_dtcs(&mut self) -> Result<Vec<Vec<Dtc>>>;
|
||||
|
||||
/// Get the calculated engine
|
||||
// fn get_engine_load(&mut self) -> Result<u8>;
|
||||
/// Get the calculated engine load (out of 255)
|
||||
fn get_engine_load(&mut self) -> Result<u8>;
|
||||
|
||||
/// Get the temperature of the engine's coolant in ºC
|
||||
fn get_engine_coolant_temperature(&mut self) -> Result<i16>;
|
||||
|
||||
/// Get the fuel pressure in kPa
|
||||
///
|
||||
/// This measurement is gauge pressure (measured relative to the atmosphere)
|
||||
fn get_fuel_pressure(&mut self) -> Result<i16>;
|
||||
|
||||
/// Get the intake manifold pressure in kPa
|
||||
///
|
||||
/// This measurement is absolute pressure.
|
||||
fn get_engine_manifold_pressure(&mut self) -> Result<f32>;
|
||||
|
||||
/// Get the RPM in increments of 0.25
|
||||
fn get_rpm(&mut self) -> Result<f32>;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
//! Crate for communicating with OBD-II (on-board diagnostics) interfaces on cars
|
||||
//!
|
||||
//! The high-level data retrieval functions can be found in [commands::Obd2DataRetrieval].
|
||||
//!
|
||||
//! # Usage
|
||||
//! ```
|
||||
//! use obd2::{commands::Obd2DataRetrieval, device::Elm327, Obd2};
|
||||
|
|
Loading…
Reference in a new issue