Skip to main content

SignalBinding

Struct SignalBinding 

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

The CHARACTERISTIC this binding describes.

§can_id: u32

The message’s CAN identifier, widened to u32 (dbc_parse::CanId::raw).

§start_bit: u16

DBC 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: u8

Signal width in bits (1–64).

§byte_order: ByteOrder

Bit layout order (@0/@1 in the DBC grammar).

§factor: f64

Physical value = raw * factor + offset.

§offset: f64

Physical value = raw * factor + offset.

Implementations§

Source§

impl SignalBinding

Source

pub fn from_signal(characteristic: &str, can_id: u32, signal: &Signal) -> Self

Build a binding from a DBC signal in message can_id.

Source

pub fn payload_len(&self) -> usize

Bytes a payload must have for this layout.

Source

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.

Source

pub fn decode(&self, data: &[u8]) -> f64

Decode the signal’s physical value from a payload.

Source

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.

Source

pub fn decode_all(bindings: &[Self], data: &[u8]) -> Vec<(u32, String, f64)>

Decode every binding of bindings from one payload, as (can_id, name, physical) triples in the order given.

Trait Implementations§

Source§

impl Clone for SignalBinding

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 SignalBinding

Source§

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

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

impl Display for SignalBinding

Source§

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

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

impl PartialEq for SignalBinding

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 SignalBinding

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.