Skip to main content

CalibrationProject

Struct CalibrationProject 

Source
pub struct CalibrationProject { /* private fields */ }
Expand description

A calibration project: an A2L description, optionally bound to a DBC database.

Implementations§

Source§

impl CalibrationProject

Source

pub fn from_a2l(text: &str) -> Result<Self, CalError>

Parse an A2L description and resolve every reference it makes.

§Errors

CalError::A2l for a malformed file, CalError::Unsupported when a characteristic or measurement references a COMPU_METHOD or RECORD_LAYOUT its module does not declare.

Source

pub fn from_a2l_file(path: &Path) -> Result<Self, CalError>

Read and resolve an A2L description from disk.

§Errors

CalError::Io when the file cannot be read, otherwise as from_a2l.

Source

pub fn from_parsed(a2l: A2lProject) -> Result<Self, CalError>

Resolve an already-parsed A2L project.

§Errors

CalError::Unsupported as in from_a2l.

Source

pub fn project_name(&self) -> &str

The A2L PROJECT name.

Source

pub const fn a2l(&self) -> &A2lProject

The underlying parsed description, for callers that need the record layouts and compu methods this layer resolved away.

Source

pub const fn dbc(&self) -> Option<&Dbc>

The attached DBC database, when one has been attached.

Source

pub fn modules(&self) -> impl Iterator<Item = &Module>

Every module, in declaration order.

Source

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

The module named name.

§Errors

CalError::UnknownModule when no such module exists.

Source

pub fn module_names(&self) -> impl Iterator<Item = &str>

Module names, in declaration order.

Source

pub fn characteristic( &self, module: &str, name: &str, ) -> Result<&Characteristic, CalError>

The characteristic name in module module.

§Errors

CalError::UnknownModule or CalError::UnknownCharacteristic.

Source

pub fn measurement( &self, module: &str, name: &str, ) -> Result<&Measurement, CalError>

The measurement name in module module.

§Errors

CalError::UnknownModule or CalError::UnknownCharacteristic.

Source

pub fn declare_elements( &mut self, module: &str, name: &str, elements: usize, ) -> Result<(), CalError>

Declare how many elements a curve/map/value-block deposits.

a2l_parse deliberately does not retain the ASAP2 NUMBER keyword (nor NO_AXIS_PTS, which lives in the AXIS_DESCR blocks it skips), so the element count of a multi-element characteristic is not in the parsed model. Rather than guess — a wrong count reads the wrong number of bytes out of ECU memory — the count is declared here, next to the datatype it multiplies.

§Errors

CalError::UnknownModule or CalError::UnknownCharacteristic.

Source

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

Register the (raw, physical) points of an A2L COMPU_TAB.

Points must be non-empty and strictly ascending by raw value — the order the format specifies, and the order Curve and CompuMethod::apply rely on.

§Errors

CalError::Unsupported when the point list is empty or not strictly ascending.

Source

pub fn table(&self, name: &str) -> Option<&[(f64, f64)]>

The points registered for name.

Source

pub const fn tables(&self) -> &BTreeMap<String, Vec<(f64, f64)>>

Every registered table, by COMPU_TAB name.

Source

pub const fn deposit_byte_order(&self) -> ByteOrder

The byte order used to code multi-byte deposit elements.

XCP slaves advertise their byte order in the CONNECT response; the default is Intel (little-endian), matching xcp_core’s default.

Source

pub fn set_deposit_byte_order(&mut self, order: ByteOrder)

Set the byte order used to code multi-byte deposit elements.

Source

pub fn attach_dbc(&mut self, dbc: Dbc) -> Result<(), CalError>

Bind the project’s characteristics to the signals of dbc.

A characteristic binds to the first signal whose name matches it — exactly first, then ASCII-case-insensitively, because DBC signal names are conventionally upper-case while A2L names are lower-case. Bindings replace any previous attachment. Characteristics with no same-named signal are simply left unbound; require_signal_binding is where that becomes a typed error.

§Errors

CalError::Unsupported when a matched signal’s layout cannot be bit-coded (a width outside 1..=64, or a start bit beyond the DBC range). The database is left unattached.

Source

pub fn attach_dbc_text(&mut self, text: &str) -> Result<(), CalError>

Parse a DBC document and bind it (the common case).

§Errors

CalError::Dbc for a malformed database, otherwise as attach_dbc.

Source

pub fn signal_for_characteristic( &self, module: &str, char_name: &str, ) -> Option<&SignalBinding>

The CAN signal bound to characteristic in module, when one is.

Source

pub fn signal_bindings(&self, module: &str) -> Vec<&SignalBinding>

Every binding in module, ordered by characteristic name.

Source

pub fn signal_for_measurement( &self, module: &str, measurement: &str, ) -> Option<&SignalBinding>

The CAN signal bound to measurement name in module, when one is.

Measurements bind exactly like characteristics do — a bench tool watching engine_speed on the bus wants the same layout it gets for a calibratable.

Source

pub fn measurement_bindings(&self, module: &str) -> Vec<&SignalBinding>

Every measurement binding in module, ordered by measurement name.

Source

pub fn require_measurement_binding( &self, module: &str, measurement: &str, ) -> Result<&SignalBinding, CalError>

The CAN signal bound to measurement name in module.

§Errors

CalError::UnknownModule, CalError::UnknownCharacteristic, or CalError::NoSignalBinding.

Source

pub fn require_signal_binding( &self, module: &str, char_name: &str, ) -> Result<&SignalBinding, CalError>

The CAN signal bound to characteristic in module.

§Errors

CalError::UnknownModule, CalError::UnknownCharacteristic, or CalError::NoSignalBinding when no DBC is attached or no signal matches.

Source

pub fn resolved_conversion( &self, characteristic: &Characteristic, ) -> Result<CompuMethod, CalError>

Resolve a characteristic’s conversion, filling a TABLE method’s points from the registered tables.

§Errors

CalError::Unsupported when a TABLE conversion has no points and no registered COMPU_TAB_REF.

Source

pub fn to_physical( &self, module: &str, name: &str, raw: u64, ) -> Result<f64, CalError>

Raw value → physical value, through the A2L COMPU_METHOD.

raw is the memory bit pattern: for a signed datatype the low element_bits bits are sign-extended, so -1 °C in an SBYTE characteristic is 0xFF.

§Errors

CalError::UnknownModule, CalError::UnknownCharacteristic, or CalError::Unsupported for an unresolvable conversion.

Source

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

Physical value → raw value, inverting the A2L COMPU_METHOD.

The value is limit-checked first, then inverted against the deposit’s raw bounds, then rounded to the nearest integer the datatype holds. The result is the memory bit pattern (two’s complement for signed datatypes).

§Errors

CalError::LimitViolation when the physical value is outside the A2L limits, CalError::OutOfBounds when the deposit cannot represent it, CalError::Unsupported for a non-invertible or unresolvable conversion, plus the lookup errors.

Source

pub fn check_physical_limits( &self, characteristic: &Characteristic, physical: f64, ) -> Result<(), CalError>

Check a physical value against the A2L limits of a characteristic.

§Errors

CalError::LimitViolation carrying the characteristic name, the offending value, and both limits.

Source

pub fn check_limits( &self, module: &str, name: &str, raw: u64, ) -> Result<(), CalError>

Check a raw value against the A2L limits: convert, then check.

§Errors

CalError::LimitViolation carrying the characteristic name, the physical value the raw produced, and both limits.

Source

pub fn locate(&self, name: &str) -> Result<(&str, &Characteristic), CalError>

Locate a characteristic by name across every module, returning the module name too. First declaration wins.

§Errors

CalError::UnknownCharacteristic when no module declares it.

Source

pub fn read_raw( &self, characteristic: &Characteristic, data: &[u8], ) -> Result<Vec<u64>, CalError>

Decode a deposit payload into one raw bit pattern per element.

§Errors

CalError::Unsupported when the datatype is IEEE-754 (a float deposit carries a value, not a bit pattern) or when data is shorter than the declared deposit.

Source

pub fn write_raw( &self, characteristic: &Characteristic, raws: &[u64], ) -> Result<Vec<u8>, CalError>

Encode one raw bit pattern per element into a deposit payload.

The payload is deposit_position + elements · element width bytes long, so the bytes before FNC_VALUES POSITION are present and zero — an ECU that ignores them is unaffected, and one that does not is told exactly what the layout is.

§Errors

CalError::Unsupported when the datatype is IEEE-754, when the element count overflows the deposit size, or when the deposit exceeds one XCP UPLOAD (255 bytes).

Source

pub fn physical_values( &self, characteristic: &Characteristic, raws: &[u64], ) -> Result<Vec<f64>, CalError>

The physical values of one raw value list.

§Errors

CalError::Unsupported for an unresolvable conversion.

Trait Implementations§

Source§

impl Clone for CalibrationProject

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CalibrationProject

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for CalibrationProject

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for CalibrationProject

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.