pub struct CalibrationProject { /* private fields */ }Expand description
A calibration project: an A2L description, optionally bound to a DBC database.
Implementations§
Source§impl CalibrationProject
impl CalibrationProject
Sourcepub fn from_a2l(text: &str) -> Result<Self, CalError>
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.
Sourcepub fn from_a2l_file(path: &Path) -> Result<Self, CalError>
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.
Sourcepub fn from_parsed(a2l: A2lProject) -> Result<Self, CalError>
pub fn from_parsed(a2l: A2lProject) -> Result<Self, CalError>
Sourcepub fn project_name(&self) -> &str
pub fn project_name(&self) -> &str
The A2L PROJECT name.
Sourcepub const fn a2l(&self) -> &A2lProject
pub const fn a2l(&self) -> &A2lProject
The underlying parsed description, for callers that need the record layouts and compu methods this layer resolved away.
Sourcepub fn module_names(&self) -> impl Iterator<Item = &str>
pub fn module_names(&self) -> impl Iterator<Item = &str>
Module names, in declaration order.
Sourcepub fn characteristic(
&self,
module: &str,
name: &str,
) -> Result<&Characteristic, CalError>
pub fn characteristic( &self, module: &str, name: &str, ) -> Result<&Characteristic, CalError>
The characteristic name in module module.
§Errors
Sourcepub fn measurement(
&self,
module: &str,
name: &str,
) -> Result<&Measurement, CalError>
pub fn measurement( &self, module: &str, name: &str, ) -> Result<&Measurement, CalError>
The measurement name in module module.
§Errors
Sourcepub fn declare_elements(
&mut self,
module: &str,
name: &str,
elements: usize,
) -> Result<(), CalError>
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
Sourcepub fn register_table(
&mut self,
name: &str,
points: Vec<(f64, f64)>,
) -> Result<(), CalError>
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.
Sourcepub const fn tables(&self) -> &BTreeMap<String, Vec<(f64, f64)>>
pub const fn tables(&self) -> &BTreeMap<String, Vec<(f64, f64)>>
Every registered table, by COMPU_TAB name.
Sourcepub const fn deposit_byte_order(&self) -> ByteOrder
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.
Sourcepub fn set_deposit_byte_order(&mut self, order: ByteOrder)
pub fn set_deposit_byte_order(&mut self, order: ByteOrder)
Set the byte order used to code multi-byte deposit elements.
Sourcepub fn attach_dbc(&mut self, dbc: Dbc) -> Result<(), CalError>
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.
Sourcepub fn attach_dbc_text(&mut self, text: &str) -> Result<(), CalError>
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.
Sourcepub fn signal_for_characteristic(
&self,
module: &str,
char_name: &str,
) -> Option<&SignalBinding>
pub fn signal_for_characteristic( &self, module: &str, char_name: &str, ) -> Option<&SignalBinding>
The CAN signal bound to characteristic in module, when one is.
Sourcepub fn signal_bindings(&self, module: &str) -> Vec<&SignalBinding>
pub fn signal_bindings(&self, module: &str) -> Vec<&SignalBinding>
Every binding in module, ordered by characteristic name.
Sourcepub fn signal_for_measurement(
&self,
module: &str,
measurement: &str,
) -> Option<&SignalBinding>
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.
Sourcepub fn measurement_bindings(&self, module: &str) -> Vec<&SignalBinding>
pub fn measurement_bindings(&self, module: &str) -> Vec<&SignalBinding>
Every measurement binding in module, ordered by measurement name.
Sourcepub fn require_measurement_binding(
&self,
module: &str,
measurement: &str,
) -> Result<&SignalBinding, CalError>
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.
Sourcepub fn require_signal_binding(
&self,
module: &str,
char_name: &str,
) -> Result<&SignalBinding, CalError>
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.
Sourcepub fn resolved_conversion(
&self,
characteristic: &Characteristic,
) -> Result<CompuMethod, CalError>
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.
Sourcepub fn to_physical(
&self,
module: &str,
name: &str,
raw: u64,
) -> Result<f64, CalError>
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.
Sourcepub fn to_raw(
&self,
module: &str,
name: &str,
physical: f64,
) -> Result<u64, CalError>
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.
Sourcepub fn check_physical_limits(
&self,
characteristic: &Characteristic,
physical: f64,
) -> Result<(), CalError>
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.
Sourcepub fn check_limits(
&self,
module: &str,
name: &str,
raw: u64,
) -> Result<(), CalError>
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.
Sourcepub fn locate(&self, name: &str) -> Result<(&str, &Characteristic), CalError>
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.
Sourcepub fn read_raw(
&self,
characteristic: &Characteristic,
data: &[u8],
) -> Result<Vec<u64>, CalError>
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.
Sourcepub fn write_raw(
&self,
characteristic: &Characteristic,
raws: &[u64],
) -> Result<Vec<u8>, CalError>
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).
Sourcepub fn physical_values(
&self,
characteristic: &Characteristic,
raws: &[u64],
) -> Result<Vec<f64>, CalError>
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.