Skip to main content

CalibrationSession

Struct CalibrationSession 

Source
pub struct CalibrationSession<'a> { /* private fields */ }
Expand description

A calibration session against one ECU, over one transport.

Implementations§

Source§

impl<'a> CalibrationSession<'a>

Source

pub fn connect( project: &'a CalibrationProject, transport: Box<dyn XcpTransport + 'a>, mode: ResourceMode, ) -> Result<Self, CalError>

Open a session on project over transport.

mode is the slave’s resource bitmask. When it is non-empty the session requires ResourceMode::CAL_PAGE and refuses to connect otherwise — a slave that advertises no CAL/PAG resource cannot be calibrated, and finding that out at connect time is much cheaper than finding it out at the first write. Pass the empty mask ([ResourceMode::CONNECT_NORMAL]) to skip the check, which is what a caller does when the transport is not completing a real CONNECT handshake.

§Errors

CalError::Xcp — xcp_core::XcpError::AccessDenied — when the resource mask excludes CAL/PAG.

Source

pub const fn project(&self) -> &'a CalibrationProject

The project this session calibrates.

Source

pub fn transport(&self) -> &dyn XcpTransport

The transport, borrowed.

Source

pub fn transport_mut(&mut self) -> &mut (dyn XcpTransport + 'a)

The transport, mutably borrowed.

Source

pub const fn resources(&self) -> ResourceMode

The negotiated resource mask.

Source

pub const fn cal_page(&self) -> u32

The active calibration page.

Source

pub fn set_cal_page(&mut self, page: u32) -> Result<(), CalError>

Switch the slave’s active calibration page.

§Errors

CalError::Transport when the transport rejected the switch; the session’s page is left unchanged in that case, so a failed switch cannot silently redirect a later write to the wrong page.

Source

pub fn upload_frames(&self, addr: u32, len: u8) -> Vec<u8> ⓘ

The SET_MTA + UPLOAD frames for a read of len bytes at addr, in the project’s deposit byte order.

Source

pub fn download_frames(&self, addr: u32, data: &[u8]) -> Vec<u8> ⓘ

The SET_MTA + DOWNLOAD frames for a write of data at addr, in the project’s deposit byte order.

Source

pub fn set_cal_page_frame(&self, page: u32) -> Vec<u8> ⓘ

The SET_CAL_PAGE frame for page (switch on the ECU, all segments).

Source

pub fn read_characteristic( &mut self, module: &str, name: &str, ) -> Result<f64, CalError>

Read a characteristic and return the physical value of its first element.

§Errors

CalError::Transport on a bus failure, CalError::Unsupported for an unresolvable conversion or a deposit the UPLOAD cannot carry, plus the lookup errors.

Source

pub fn read_characteristic_elements( &mut self, module: &str, name: &str, ) -> Result<Vec<f64>, CalError>

Read every element of a characteristic and return their physical values — the curve or map as one read.

§Errors

As read_characteristic.

Source

pub fn read_characteristic_raw( &mut self, module: &str, name: &str, ) -> Result<Vec<u64>, CalError>

Read every element of a characteristic and return its raw bit patterns.

§Errors

CalError::Transport, CalError::Unsupported (including a deposit larger than one 255-byte UPLOAD), plus the lookup errors.

Source

pub fn write_characteristic( &mut self, module: &str, name: &str, physical: f64, ) -> Result<(), CalError>

Write a physical value to a characteristic’s first element, and read it back to confirm the ECU latched it.

The value is limit-checked and inverted through the COMPU_METHOD before anything reaches the bus, so a rejected write costs no traffic.

§Errors

CalError::LimitViolation for an out-of-limit value, CalError::OutOfBounds when the deposit cannot represent it, CalError::Transport on a bus failure or a read-back mismatch, plus the lookup errors.

Source

pub fn write_characteristic_element( &mut self, module: &str, name: &str, index: usize, physical: f64, ) -> Result<(), CalError>

Write a physical value to one element of a characteristic and read it back to confirm.

§Errors

As write_characteristic.

Source

pub fn write_characteristic_raw( &mut self, module: &str, name: &str, index: usize, raw: u64, ) -> Result<(), CalError>

Write a raw bit pattern to one element, without limit checking or read-back — the path a snapshot restore takes, where the value was already validated when it was captured.

A multi-element deposit is read, one element replaced, and written back whole: a calibration engineer adjusting curve point 3 must not lose points 1, 2, and 4.

§Errors

CalError::OutOfBounds when index is past the end of the deposit, CalError::Transport on a bus failure, plus the lookup errors.

Source

pub fn read_measurement( &mut self, module: &str, name: &str, ) -> Result<f64, CalError>

Read a measurement and return its physical value.

§Errors

CalError::Transport on a bus failure, CalError::Unsupported for an unresolvable conversion, plus the lookup errors.

Source

pub fn snapshot(&mut self, names: &[&str]) -> Result<Snapshot, CalError>

Capture the named characteristics, searching every module for each name (first declaration wins).

The snapshot records the page it was taken on, so restore puts the ECU back where it found it.

§Errors

As read_characteristic_raw, and CalError::UnknownCharacteristic for a name no module declares.

Source

pub fn snapshot_module(&mut self, module: &str) -> Result<Snapshot, CalError>

Capture every characteristic of one module.

§Errors

As snapshot.

Source

pub fn restore(&mut self, snapshot: &Snapshot) -> Result<(), CalError>

Restore a captured calibration set: switch to the snapshot’s page, then write every captured raw value back verbatim.

Raws are written, not physical values, so a restore is bit-exact and cannot drift through a second round of inversion.

§Errors

CalError::Transport, CalError::UnknownModule / CalError::UnknownCharacteristic when the project no longer declares a captured parameter, plus the write errors.

Source

pub fn diff(&self, other: &Snapshot) -> Vec<CalibrationDelta>

Diff this session’s baseline snapshot against other, one entry per element.

&self cannot read the bus, so the “before” side is the baseline installed by set_baseline (or capture_baseline). With no baseline set, every parameter is reported as new. Use diff_snapshots to diff two snapshots you already hold.

within_limits is evaluated against the project’s current A2L limits, so a baseline captured before a limit was tightened is reported against the limit that now applies.

Source

pub fn set_baseline(&mut self, snapshot: Snapshot)

Install the baseline every diff measures against.

Source

pub fn baseline(&self) -> Option<&Snapshot>

The installed baseline, when one is set.

Source

pub fn capture_baseline(&mut self) -> Result<(), CalError>

Capture a baseline over every characteristic of every module and install it.

§Errors

CalError::Transport, CalError::UnknownModule / CalError::UnknownCharacteristic, CalError::Unsupported — as snapshot.

Trait Implementations§

Source§

impl Debug for CalibrationSession<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for CalibrationSession<'a>

§

impl<'a> !Send for CalibrationSession<'a>

§

impl<'a> !Sync for CalibrationSession<'a>

§

impl<'a> !UnwindSafe for CalibrationSession<'a>

§

impl<'a> Freeze for CalibrationSession<'a>

§

impl<'a> Unpin for CalibrationSession<'a>

§

impl<'a> UnsafeUnpin for CalibrationSession<'a>

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, 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.