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
impl Signal
Sourcepub fn name(&self) -> &str
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");Sourcepub fn start_bit(&self) -> u16
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);Sourcepub fn length(&self) -> u16
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);Sourcepub fn byte_order(&self) -> ByteOrder
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);Sourcepub fn is_unsigned(&self) -> bool
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);Sourcepub fn factor(&self) -> f64
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);Sourcepub fn offset(&self) -> f64
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);Sourcepub fn min(&self) -> f64
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);Sourcepub fn max(&self) -> f64
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);Sourcepub fn unit(&self) -> Option<&str>
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"));Sourcepub fn receivers(&self) -> &Receivers
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"));Sourcepub fn is_multiplexer_switch(&self) -> bool
pub fn is_multiplexer_switch(&self) -> bool
Check if this signal is a multiplexer switch (marked with ‘M’)
Sourcepub fn multiplexer_switch_value(&self) -> Option<u64>
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)
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)