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

Returns the signal name.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.name(), "SIGNAL_NAME");
Source

pub fn start_bit(&self) -> u16

Returns the start bit position of the signal in the CAN message payload.

The start bit indicates where the signal begins in the message data. For little-endian signals, this is the LSB position. For big-endian signals, this is the MSB position.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.start_bit(), 16);
Source

pub fn length(&self) -> u16

Returns the length of the signal in bits.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.length(), 16);
Source

pub fn byte_order(&self) -> ByteOrder

Returns the byte order (endianness) of the signal.

Returns either ByteOrder::LittleEndian (Intel format, @1+) or ByteOrder::BigEndian (Motorola format, @0+).

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.byte_order(), ByteOrder::LittleEndian);
Source

pub fn is_unsigned(&self) -> bool

Returns true if the signal is unsigned, false if signed.

In DBC format, + indicates unsigned and - indicates signed.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.is_unsigned(), true);
Source

pub fn factor(&self) -> f64

Returns the scaling factor applied to convert raw signal values to physical values.

The physical value is calculated as: physical_value = raw_value * factor + offset

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.factor(), 0.5);
Source

pub fn offset(&self) -> f64

Returns the offset applied to convert raw signal values to physical values.

The physical value is calculated as: physical_value = raw_value * factor + offset

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.offset(), -40.0);
Source

pub fn min(&self) -> f64

Returns the minimum physical value for this signal.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.min(), -40.0);
Source

pub fn max(&self) -> f64

Returns the maximum physical value for this signal.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.max(), 85.0);
Source

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

Returns the unit of measurement for this signal, if specified.

Returns None if no unit was defined in the DBC file.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.unit(), Some("km/h"));
Source

pub fn receivers(&self) -> &Receivers

Returns the receivers (ECU nodes) that subscribe to this signal.

Returns a reference to a Receivers enum which can be either a list of node names or None.

§Examples
let message = dbc.messages().find("MSG_NAME").unwrap();
let signal = message.signals().find("SIGNAL_NAME").unwrap();
assert_eq!(signal.receivers().len(), 2);
assert!(signal.receivers().contains("ECU2"));
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 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.