Signal

Struct Signal 

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

Represents a CAN signal within a message.

A Signal contains:

  • A name
  • Start bit position and length
  • Byte order (big-endian or little-endian)
  • Signed/unsigned flag
  • Factor and offset for physical value conversion
  • Min/max range
  • Optional unit string
  • Receivers (nodes that receive this signal)

§Examples

use dbc_rs::Dbc;

let dbc = Dbc::parse(r#"VERSION "1.0"

BU_: ECM

BO_ 256 Engine : 8 ECM
 SG_ RPM : 0|16@1+ (0.25,0) [0|8000] "rpm" *
"#)?;

let message = dbc.messages().at(0).unwrap();
let signal = message.signals().at(0).unwrap();
println!("Signal: {} (bits: {}-{})", signal.name(), signal.start_bit(), signal.start_bit() + signal.length() - 1);

Implementations§

Source§

impl Signal

Source

pub fn name(&self) -> &str

Source

pub fn start_bit(&self) -> u16

Source

pub fn length(&self) -> u16

Source

pub fn byte_order(&self) -> ByteOrder

Source

pub fn is_unsigned(&self) -> bool

Source

pub fn factor(&self) -> f64

Source

pub fn offset(&self) -> f64

Source

pub fn min(&self) -> f64

Source

pub fn max(&self) -> f64

Source

pub fn unit(&self) -> Option<&str>

Source

pub fn receivers(&self) -> &Receivers

Source

pub fn is_multiplexer_switch(&self) -> bool

Check if this signal is a multiplexer switch (marked with ‘M’)

Source

pub fn multiplexer_switch_value(&self) -> Option<u64>

Get the multiplexer switch value if this is a multiplexed signal (marked with ‘m0’, ‘m1’, etc.) Returns None if this is a normal signal (not multiplexed)

Source§

impl Signal

Source

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

Decode the signal value from CAN message data bytes.

Extracts the raw value from bits based on the signal’s start bit, length, and byte order, then applies factor and offset to return the physical/engineering value.

§Arguments
  • data - The CAN message data bytes (up to 8 bytes for classic CAN, 64 for CAN FD)
§Returns
  • Ok(f64) - The physical value (raw * factor + offset)
  • Err(Error) - If the signal extends beyond the data length
§Examples
use dbc_rs::Dbc;

let dbc = Dbc::parse(r#"VERSION "1.0"

BU_: ECM

BO_ 256 Engine : 8 ECM
 SG_ RPM : 0|16@1+ (0.25,0) [0|8000] "rpm" *
"#)?;

let message = dbc.messages().at(0).unwrap();
let signal = message.signals().at(0).unwrap();

// Decode a CAN message with RPM value of 2000 (raw: 8000)
let data = [0x20, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
let rpm = signal.decode(&data)?;
assert_eq!(rpm, 2000.0);

Decode signal value from CAN payload - optimized for high-throughput decoding.

Source§

impl Signal

Source

pub fn to_dbc_string(&self) -> String

Trait Implementations§

Source§

impl Clone for Signal

Source§

fn clone(&self) -> Signal

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Signal

Source§

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

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

impl Display for Signal

Source§

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

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

impl Hash for Signal

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Signal

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Signal

Auto Trait Implementations§

§

impl Freeze for Signal

§

impl RefUnwindSafe for Signal

§

impl Send for Signal

§

impl Sync for Signal

§

impl Unpin for Signal

§

impl UnwindSafe for Signal

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.