pub struct SignalBinding {
pub characteristic: String,
pub can_id: u32,
pub start_bit: u16,
pub length: u8,
pub byte_order: ByteOrder,
pub factor: f64,
pub offset: f64,
}Expand description
A resolved binding between a CHARACTERISTIC and a DBC signal.
Fields§
§characteristic: StringThe CHARACTERISTIC this binding describes.
can_id: u32The message’s CAN identifier, widened to u32
(dbc_parse::CanId::raw).
start_bit: u16DBC start bit: the MSB for ByteOrder::Motorola, the LSB for
ByteOrder::Intel. u16 because DBC numbers up to 511 (CAN FD
payloads reach byte 64).
length: u8Signal width in bits (1–64).
byte_order: ByteOrderBit layout order (@0/@1 in the DBC grammar).
factor: f64Physical value = raw * factor + offset.
offset: f64Physical value = raw * factor + offset.
Implementations§
Source§impl SignalBinding
impl SignalBinding
Sourcepub fn from_signal(characteristic: &str, can_id: u32, signal: &Signal) -> Self
pub fn from_signal(characteristic: &str, can_id: u32, signal: &Signal) -> Self
Build a binding from a DBC signal in message can_id.
Sourcepub fn payload_len(&self) -> usize
pub fn payload_len(&self) -> usize
Bytes a payload must have for this layout.
Sourcepub fn extract_raw(&self, data: &[u8]) -> u64
pub fn extract_raw(&self, data: &[u8]) -> u64
The raw bit pattern the signal occupies in data.
Total: positions beyond the buffer read as zero bits (the same
documented semantics dbc_parse uses), so a truncated capture
decodes rather than panicking.
Sourcepub fn encode(&self, data: &mut [u8], physical: f64) -> Result<(), CalError>
pub fn encode(&self, data: &mut [u8], physical: f64) -> Result<(), CalError>
Encode a physical value into data at this signal’s bits — the
exact inverse of decode, modulo the rounding to the
signal’s raw resolution.
§Errors
CalError::Unsupported when factor is zero (nothing can be
inverted), CalError::Dbc when the raw value does not fit the
signal’s width or the buffer is too short.