pub struct Session<A: Adapter> { /* private fields */ }Expand description
The primary entry point for all OBD-II operations.
A Session wraps an Adapter and provides high-level methods for reading PIDs, DTCs, identifying vehicles, and more.
§Example
use obd2_core::adapter::mock::MockAdapter;
use obd2_core::session::Session;
use obd2_core::protocol::pid::Pid;
let adapter = MockAdapter::new();
let mut session = Session::new(adapter);
let profile = session.identify_vehicle().await?;
let rpm = session.read_pid(Pid::ENGINE_RPM).await?;Implementations§
Source§impl<A: Adapter> Session<A>
impl<A: Adapter> Session<A>
Sourcepub fn load_spec(&mut self, path: &Path) -> Result<(), Obd2Error>
pub fn load_spec(&mut self, path: &Path) -> Result<(), Obd2Error>
Load a vehicle spec from a YAML file.
Sourcepub fn load_spec_dir(&mut self, dir: &Path) -> Result<usize, Obd2Error>
pub fn load_spec_dir(&mut self, dir: &Path) -> Result<usize, Obd2Error>
Load all specs from a directory.
Sourcepub fn specs(&self) -> &SpecRegistry
pub fn specs(&self) -> &SpecRegistry
Access the spec registry.
Sourcepub async fn read_pid(&mut self, pid: Pid) -> Result<Reading, Obd2Error>
pub async fn read_pid(&mut self, pid: Pid) -> Result<Reading, Obd2Error>
Read a single standard PID.
Sourcepub async fn read_pids(
&mut self,
pids: &[Pid],
) -> Result<Vec<(Pid, Reading)>, Obd2Error>
pub async fn read_pids( &mut self, pids: &[Pid], ) -> Result<Vec<(Pid, Reading)>, Obd2Error>
Read multiple standard PIDs in sequence.
Sourcepub async fn supported_pids(&mut self) -> Result<HashSet<Pid>, Obd2Error>
pub async fn supported_pids(&mut self) -> Result<HashSet<Pid>, Obd2Error>
Query which standard PIDs this vehicle supports.
Sourcepub async fn read_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>
pub async fn read_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>
Read stored (confirmed) DTCs via broadcast.
Sourcepub async fn read_pending_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>
pub async fn read_pending_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>
Read pending DTCs (Mode 07).
Sourcepub async fn read_permanent_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>
pub async fn read_permanent_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>
Read permanent DTCs (Mode 0A).
Sourcepub async fn clear_dtcs(&mut self) -> Result<(), Obd2Error>
pub async fn clear_dtcs(&mut self) -> Result<(), Obd2Error>
Clear all DTCs and reset monitors (broadcast).
Sourcepub async fn identify_vehicle(&mut self) -> Result<VehicleProfile, Obd2Error>
pub async fn identify_vehicle(&mut self) -> Result<VehicleProfile, Obd2Error>
Identify vehicle: read VIN, decode offline, match spec.
Populates the VehicleProfile with:
- Offline VIN decode (manufacturer, year, vehicle class)
- Matched vehicle spec (if any)
- Supported standard PIDs
Sourcepub async fn read_enhanced(
&mut self,
did: u16,
module: ModuleId,
) -> Result<Reading, Obd2Error>
pub async fn read_enhanced( &mut self, did: u16, module: ModuleId, ) -> Result<Reading, Obd2Error>
Read an enhanced PID from a specific module.
Sourcepub fn module_pids(&self, module: ModuleId) -> Vec<&EnhancedPid>
pub fn module_pids(&self, module: ModuleId) -> Vec<&EnhancedPid>
List enhanced PIDs available for a module (from matched spec).
Sourcepub async fn read_o2_monitoring(
&mut self,
test_id: u8,
) -> Result<Vec<O2TestResult>, Obd2Error>
pub async fn read_o2_monitoring( &mut self, test_id: u8, ) -> Result<Vec<O2TestResult>, Obd2Error>
Read O2 sensor monitoring test results for a specific TID.
Sourcepub async fn read_all_o2_monitoring(
&mut self,
) -> Result<Vec<O2TestResult>, Obd2Error>
pub async fn read_all_o2_monitoring( &mut self, ) -> Result<Vec<O2TestResult>, Obd2Error>
Read all O2 sensor monitoring tests (TIDs 0x01-0x09).
Sourcepub async fn read_j1939_pgn(&mut self, pgn: Pgn) -> Result<Vec<u8>, Obd2Error>
pub async fn read_j1939_pgn(&mut self, pgn: Pgn) -> Result<Vec<u8>, Obd2Error>
Read a J1939 Parameter Group from a heavy-duty vehicle.
Sends a CAN 29-bit request for the specified PGN and returns the raw
response bytes. Use the decoder functions in crate::protocol::j1939
to parse the response.
Requires an ELM327/STN adapter on a J1939-capable vehicle (CAN 29-bit 250 kbps).
§Example
let data = session.read_j1939_pgn(Pgn::EEC1).await.unwrap();
if let Some(eec1) = decode_eec1(&data) {
if let (Some(rpm), Some(torque)) = (eec1.engine_rpm, eec1.actual_torque_pct) {
println!("RPM: {rpm:.0}, Torque: {torque:.0}%");
}
}Sourcepub async fn read_j1939_dtcs(&mut self) -> Result<Vec<J1939Dtc>, Obd2Error>
pub async fn read_j1939_dtcs(&mut self) -> Result<Vec<J1939Dtc>, Obd2Error>
Read and decode J1939 active DTCs (DM1 — PGN 65226).
Returns J1939-format DTCs (SPN + FMI), distinct from OBD-II P-codes.
Sourcepub fn evaluate_threshold(
&self,
pid: Pid,
value: f64,
) -> Option<ThresholdResult>
pub fn evaluate_threshold( &self, pid: Pid, value: f64, ) -> Option<ThresholdResult>
Evaluate a standard PID reading against the matched spec’s thresholds.
Returns None if the value is in normal range, no threshold is defined
for this PID, or no spec is matched.
§Example
if let Some(result) = session.evaluate_threshold(Pid::COOLANT_TEMP, 110.0) {
match result.level {
AlertLevel::Warning => eprintln!("Warning: {}", result.message),
AlertLevel::Critical => eprintln!("CRITICAL: {}", result.message),
AlertLevel::Normal => {}
}
}Sourcepub fn evaluate_enhanced_threshold(
&self,
did: u16,
value: f64,
) -> Option<ThresholdResult>
pub fn evaluate_enhanced_threshold( &self, did: u16, value: f64, ) -> Option<ThresholdResult>
Evaluate an enhanced PID (DID) reading against the matched spec’s thresholds.
Sourcepub fn vehicle(&self) -> Option<&VehicleProfile>
pub fn vehicle(&self) -> Option<&VehicleProfile>
Current vehicle profile (after identify_vehicle()).
Sourcepub fn spec(&self) -> Option<&VehicleSpec>
pub fn spec(&self) -> Option<&VehicleSpec>
Matched spec (shorthand).
Sourcepub fn adapter_info(&self) -> &AdapterInfo
pub fn adapter_info(&self) -> &AdapterInfo
Adapter info.