Expand description
DBC file parser — CAN message definitions, signal layout (bit-offset/length/endianness/scaling), value tables, extended multiplexing.
dbc-parse is the estate’s L0 leaf for Vector DBC databases: a
total, zero-dependency parser for the BO_/SG_/CM_/VAL_/BA_/
NS_ grammar, plus correct bit coding for both signal byte orders.
§The Motorola bit-numbering problem
DBC bit numbering runs per byte, LSB-first; the two byte orders differ
in what Signal::start_bit names and the direction of travel:
- Intel (
@1) — little-endian, linear:start_bitis the LSB, bits ascend straight through byte boundaries. - Motorola (
@0) — big-endian, the classic “sawtooth”:start_bitis the MSB; extraction descends within each byte and jumps from bit 0 of one byte to bit 7 of the next (+15in DBC numbering). A39|16@0+signal is a big-endianu16across bytes 4–5; a0|12@0-signal straddles three bytes.
crate::bits documents and implements both; the property tests pin
encode/decode round-trips against known-good examples.
§Example
use dbc_parse::{ByteOrder, Dbc, MultiplexingInfo};
let dbc = Dbc::parse(r#"
BO_ 496 ExampleMessage: 8 PCM1
SG_ Temperature : 0|12@0- (0.01,250) [229.52|270.47] "degK" PCM1,FOO
SG_ Enable : 7|1@0+ (1,0) [0|0] "-" Vector__XXX
"#)?;
let message = &dbc.messages[0];
assert_eq!(message.name, "ExampleMessage");
let temperature = &message.signals[0];
assert_eq!(temperature.byte_order, ByteOrder::Motorola);
assert!(temperature.is_signed);
// The canonical motohawk pattern: 0x01A1 in bytes 0-1 decodes to 242.4 K.
let values = message.unpack(&[0x01, 0xA1, 0x02, 0x1A, 0xF8, 0x80, 0x00, 0x00]);
let (name, value) = (&values[0].0.name, values[0].1);
assert_eq!(name, "Temperature");
assert!((value - 242.4).abs() < 1e-9, "{value}");
assert!(matches!(
message.signals[1].multiplexing_info,
MultiplexingInfo::None
));§Scope
- Parsed and retained:
VERSION,BU_nodes,BO_/SG_(incl.M,m<N>,m<N>M),VAL_,VAL_TABLE_,BA_values,SG_MUL_VAL_. - Parsed and skipped:
NS_,BS_,CM_comments,BA_DEF_/BA_DEF_DEF_schemas, unknown vendor keywords. dbc-parsecarries its own minimalCanId— L0 crates have zero runtime estate dependencies, socan-corecannot be a dependency.
§no_std
no_std + alloc: builds for embedded targets
(thumbv7em-none-eabihf is exercised in CI) with zero runtime
dependencies of any kind.
Modules§
- bits
- Signal bit coding — the two bit-numbering systems of the DBC format.
Structs§
- Attribute
- One
BA_attribute assignment. - Dbc
- A parsed DBC database.
- Extended
Mux - An extended-multiplexing range set (
SG_MUL_VAL_): a signal is present when its selector takes any value in any of the(from, to)inclusive ranges. - Message
- A CAN message declaration (
BO_), with its signals (SG_). - Node
- A node declared in the
BU_section. - Signal
- One signal of a
Message— its layout, scaling, and metadata. - Value
Table - A value table: raw value → label mappings from
VAL_(message-scoped) orVAL_TABLE_(global, named).
Enums§
- Attribute
Object - The object an attribute value attaches to (
BA_). - Attribute
Value - An attribute value as carried by
BA_lines. - Byte
Order - Byte order of a signal’s bit layout.
- CanId
- A CAN identifier: 11-bit (standard) or 29-bit (extended).
- DbcError
- The single crate-level error for parsing and signal coding.
- Multiplexing
Info - Multiplexing role of a signal within its message.
Constants§
- EXTENDED_
ID_ MAX - Largest 29-bit extended identifier.
- STANDARD_
ID_ MAX - Largest 11-bit standard identifier.
Functions§
- parse
- Parses a full DBC document.