DBC Guide
CanMessenger::DBC parses DBC text and maps signal values to raw CAN bytes.
Load a DBC File
dbc = CanMessenger::DBC.load('example.dbc')
You can also parse inline content:
dbc = CanMessenger::DBC.new(File.read('example.dbc'))
Supported DBC Elements
Current parser support is intentionally narrow and focused:
BO_message definitions.SG_signal definitions in the commonstart|length@endian+/- (factor,offset)pattern.- Ignores standard metadata directives such as
VERSION,NS_,BS_,BU_,CM_,VAL_,BA_,BA_DEF_,BA_DEF_DEF_,SIG_VALTYPE_, andBO_TX_BU_.
Malformed BO_/SG_ lines and unknown non-empty directives, including unsupported BA_* variants, now raise ArgumentError with line context.
If your DBC uses advanced constructs (for example multiplexing or uncommon syntax variants), validate with tests before relying on runtime behavior.
Encode by Message Name
frame = dbc.encode_can('Example', Speed: 42)
# => { id: 256, data: [42, ...] }
Validation performed during encoding includes:
- Unknown message name rejection.
- Signed/unsigned range checks.
- Signal bit-bound checks against message DLC.
Decode by CAN ID
decoded = dbc.decode_can(frame[:id], frame[:data])
# => { name: 'Example', signals: { Speed: 42.0 } }
Returns nil if no message with matching CAN ID is found.
Big-endian and Little-endian Signals
@1is treated as little-endian.@0is treated as big-endian (Motorola/sawtooth indexing).
Current releases include corrected multi-byte big-endian bit mapping and stricter unsigned overflow checks.