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
pub fn name(&self) -> &str
pub fn start_bit(&self) -> u16
pub fn length(&self) -> u16
pub fn byte_order(&self) -> ByteOrder
pub fn is_unsigned(&self) -> bool
pub fn factor(&self) -> f64
pub fn offset(&self) -> f64
pub fn min(&self) -> f64
pub fn max(&self) -> f64
pub fn unit(&self) -> Option<&str>
pub fn receivers(&self) -> &Receivers
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)
Source§impl Signal
impl Signal
Sourcepub fn decode(&self, data: &[u8]) -> Result<f64>
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.
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
Mutably borrows from an owned value. Read more
§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)
🔬This is a nightly-only experimental API. (
clone_to_uninit)