Skip to main content

Session

Struct Session 

Source
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>

Source

pub fn new(adapter: A) -> Self

Create a new Session with default embedded specs.

Source

pub fn load_spec(&mut self, path: &Path) -> Result<(), Obd2Error>

Load a vehicle spec from a YAML file.

Source

pub fn load_spec_dir(&mut self, dir: &Path) -> Result<usize, Obd2Error>

Load all specs from a directory.

Source

pub fn specs(&self) -> &SpecRegistry

Access the spec registry.

Source

pub async fn read_pid(&mut self, pid: Pid) -> Result<Reading, Obd2Error>

Read a single standard PID.

Source

pub async fn read_pids( &mut self, pids: &[Pid], ) -> Result<Vec<(Pid, Reading)>, Obd2Error>

Read multiple standard PIDs in sequence.

Source

pub async fn supported_pids(&mut self) -> Result<HashSet<Pid>, Obd2Error>

Query which standard PIDs this vehicle supports.

Source

pub async fn read_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>

Read stored (confirmed) DTCs via broadcast.

Source

pub async fn read_pending_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>

Read pending DTCs (Mode 07).

Source

pub async fn read_permanent_dtcs(&mut self) -> Result<Vec<Dtc>, Obd2Error>

Read permanent DTCs (Mode 0A).

Source

pub async fn clear_dtcs(&mut self) -> Result<(), Obd2Error>

Clear all DTCs and reset monitors (broadcast).

Source

pub async fn read_vin(&mut self) -> Result<String, Obd2Error>

Read VIN (17 characters).

Source

pub async fn identify_vehicle(&mut self) -> Result<VehicleProfile, Obd2Error>

Identify vehicle: read VIN, decode offline, match spec.

Source

pub async fn read_enhanced( &mut self, did: u16, module: ModuleId, ) -> Result<Reading, Obd2Error>

Read an enhanced PID from a specific module.

Source

pub fn module_pids(&self, module: ModuleId) -> Vec<&EnhancedPid>

List enhanced PIDs available for a module (from matched spec).

Source

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.

Source

pub async fn read_all_o2_monitoring( &mut self, ) -> Result<Vec<O2TestResult>, Obd2Error>

Read all O2 sensor monitoring tests (TIDs 0x01-0x09).

Source

pub fn vehicle(&self) -> Option<&VehicleProfile>

Current vehicle profile (after identify_vehicle()).

Source

pub fn spec(&self) -> Option<&VehicleSpec>

Matched spec (shorthand).

Source

pub fn adapter_info(&self) -> &AdapterInfo

Adapter info.

Source

pub async fn battery_voltage(&mut self) -> Result<Option<f64>, Obd2Error>

Battery voltage.

Source

pub async fn raw_request( &mut self, service: u8, data: &[u8], target: Target, ) -> Result<Vec<u8>, Obd2Error>

Raw service request (escape hatch).

Trait Implementations§

Source§

impl<A: Adapter> Debug for Session<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> Freeze for Session<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for Session<A>
where A: RefUnwindSafe,

§

impl<A> Send for Session<A>

§

impl<A> Sync for Session<A>
where A: Sync,

§

impl<A> Unpin for Session<A>
where A: Unpin,

§

impl<A> UnsafeUnpin for Session<A>
where A: UnsafeUnpin,

§

impl<A> UnwindSafe for Session<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more