pub struct Signal { /* private fields */ }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 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);pub fn to_dbc_string(&self) -> String
Trait Implementations§
impl Eq for Signal
impl StructuralPartialEq 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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more