Message

Struct Message 

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

Represents a CAN message in a DBC file.

A Message contains:

  • A unique ID (CAN identifier)
  • A name
  • A DLC (Data Length Code) specifying the message size in bytes
  • A sender node (ECU that transmits this message)
  • A collection of signals

§Examples

use dbc_rs::Dbc;

let dbc_content = r#"VERSION "1.0"

BU_: ECM

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

let dbc = Dbc::parse(dbc_content)?;
let message = dbc.messages().at(0).unwrap();
println!("Message: {} (ID: {})", message.name(), message.id());

Implementations§

Source§

impl Message

Source

pub fn decode_into(&self, data: &[u8], out: &mut [f64]) -> usize

Decode all signals into the output buffer (physical values).

This is a zero-allocation decode path for high-speed CAN processing. Signals are decoded in order and written to the output buffer.

§Arguments
  • data - Raw CAN payload bytes
  • out - Output buffer for physical values (must be at least signals().len() long)
§Returns

Number of signals decoded, or 0 if payload is too short.

§Example
let msg = dbc.messages().find_by_id(256).unwrap();
let mut values = [0.0f64; 64];
let count = msg.decode_into(&payload, &mut values);
for i in 0..count {
    let signal = msg.signals().at(i).unwrap();
    println!("{}: {}", signal.name(), values[i]);
}
Source

pub fn decode_raw_into(&self, data: &[u8], out: &mut [i64]) -> usize

Decode all signals into the output buffer (raw integer values).

Returns raw values before factor/offset conversion. Useful for encoding or debugging.

§Arguments
  • data - Raw CAN payload bytes
  • out - Output buffer for raw values (must be at least signals().len() long)
§Returns

Number of signals decoded, or 0 if payload is too short.

Source

pub fn decode_signal(&self, index: usize, data: &[u8]) -> Option<f64>

Decode a single signal by index.

Returns the physical value or None if index is out of bounds or decode fails.

Source

pub fn decode_signal_raw(&self, index: usize, data: &[u8]) -> Option<i64>

Decode a single signal by index (raw value).

Returns the raw integer value or None if index is out of bounds or decode fails.

Source§

impl Message

Source

pub fn id(&self) -> u32

Returns the CAN message ID.

This returns the raw CAN ID as it would appear on the bus (11-bit or 29-bit). For extended (29-bit) IDs, the internal flag bit is stripped. Use is_extended() to check if this is an extended ID.

§Examples
use dbc_rs::Dbc;

let dbc = Dbc::parse(r#"VERSION "1.0"\n\nBU_: ECM\n\nBO_ 256 EngineData : 8 ECM"#)?;
let message = dbc.messages().at(0).unwrap();
assert_eq!(message.id(), 256);
Source

pub fn is_extended(&self) -> bool

Returns true if this message uses an extended (29-bit) CAN ID.

Standard CAN uses 11-bit identifiers (0-2047), while extended CAN uses 29-bit identifiers (0-536870911).

§Examples
use dbc_rs::Dbc;

// Standard 11-bit ID
let dbc = Dbc::parse(r#"VERSION "1.0"\n\nBU_: ECM\n\nBO_ 256 EngineData : 8 ECM"#)?;
let message = dbc.messages().at(0).unwrap();
assert!(!message.is_extended());

// Extended 29-bit ID (with flag bit set: 0x80000000 | 0x18DAF115)
let dbc = Dbc::parse(r#"VERSION "1.0"\n\nBU_: ECM\n\nBO_ 2564485397 OBD2 : 8 ECM"#)?;
let message = dbc.messages().at(0).unwrap();
assert!(message.is_extended());
assert_eq!(message.id(), 0x18DAF115);
Source

pub fn name(&self) -> &str

Returns the message name.

§Examples
use dbc_rs::Dbc;

let dbc = Dbc::parse(r#"VERSION "1.0"\n\nBU_: ECM\n\nBO_ 256 EngineData : 8 ECM"#)?;
let message = dbc.messages().at(0).unwrap();
assert_eq!(message.name(), "EngineData");
Source

pub fn dlc(&self) -> u8

Returns the Data Length Code (DLC) in bytes.

DLC specifies the size of the message payload. For classic CAN, this is 1-8 bytes. For CAN FD, this can be up to 64 bytes.

§Examples
use dbc_rs::Dbc;

let dbc = Dbc::parse(r#"VERSION "1.0"\n\nBU_: ECM\n\nBO_ 256 EngineData : 8 ECM"#)?;
let message = dbc.messages().at(0).unwrap();
assert_eq!(message.dlc(), 8);
Source

pub fn sender(&self) -> &str

Get the sender node name for this message.

The sender is the node that transmits this message on the CAN bus.

§Examples
use dbc_rs::Dbc;

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

BU_: ECM TCM

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

let message = dbc.messages().iter().next().unwrap();
assert_eq!(message.sender(), "ECM");
Source

pub fn signals(&self) -> &Signals

Returns a reference to the signals collection for this message.

The Signals collection provides methods to iterate, search, and access signals by index.

§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" ECM
 SG_ Torque : 16|16@1+ (0.1,0) [0|500] "Nm" ECM
"#)?;

let message = dbc.messages().find("Engine").unwrap();
let signals = message.signals();
assert_eq!(signals.len(), 2);
assert!(signals.find("RPM").is_some());
Source

pub fn min_bytes_required(&self) -> u8

Returns the minimum number of bytes required to decode all signals in this message.

This calculates the actual byte coverage of all signals, which may be less than the declared DLC. Use this when validating frame payloads for decoding - the payload must have at least this many bytes to decode all signals successfully.

§Examples
use dbc_rs::Dbc;

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

BU_: ECM

BO_ 256 Engine : 8 ECM
 SG_ Temp : 0|8@1+ (1,0) [0|255] "" ECM
 SG_ Pressure : 8|8@1+ (1,0) [0|255] "" ECM
"#)?;

let message = dbc.messages().find("Engine").unwrap();
assert_eq!(message.dlc(), 8);              // Declared DLC is 8
assert_eq!(message.min_bytes_required(), 2); // But signals only need 2 bytes
Source

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

Returns the message comment from CM_ BO_ entry, if present.

Source§

impl Message

Source

pub fn to_dbc_string(&self) -> String

Source

pub fn to_string_full(&self) -> String

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

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

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

impl Display for Message

Available on crate feature std only.
Source§

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

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

impl Hash for Message

Source§

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

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

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 Message

Source§

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

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

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 Message

Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.