Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

can

A CAN bus decoder written in C++20. Takes a DBC file and a candump log, decodes every frame, and streams results as CSV.

./tool vehicle.dbc candump.log
142,SteeringAngle,-3.500000
142,SteeringSpeed,0.000000
143,BrakePedalPos,0.000000
...

What it does

CAN frames are just raw bytes on the wire. A DBC file is the schema — it describes which bits in each frame correspond to which signal, how to interpret the byte order, and how to scale the raw integer into a physical value (e.g. rpm, degrees, amps). This tool parses both and produces decoded, human-readable output.

Design

Kept the whole thing as four header files with no external dependencies. The logic splits cleanly:

Bit extraction (bits.hpp) — The two byte orderings in CAN signals (Intel/little-endian and Motorola/big-endian) need different extraction strategies. LE is straightforward: load the frame as a 64-bit LE integer, shift by start_bit, mask by length. BE is trickier — DBC encodes the start_bit as the MSB in Motorola bit-numbering, which doesn't map directly to a physical bit offset, so there's a coordinate conversion step before the same shift/mask applies.

DBC parser (dbc.hpp) — Two regexes cover the entire format: one for BO_ message headers, one for SG_ signal definitions. Standard (11-bit) and extended (29-bit) frame IDs can share the same numeric value and mean different things on the wire, so the map key encodes the extended flag in bit 32 to keep them separate.

Log parser (candump.hpp) — Parses the text format that candump -l produces. Extended frames aren't explicitly flagged in the log, so they're inferred from ID range (> 0x7FF).

Decoder (decode.hpp) — Applies scale and offset to get physical values. Handles multiplexed signals: reads the mux selector first, then skips signals that belong to a different mux group.

Build

make        # build
make test   # run tests
make bench  # benchmark against cantools (Python)

Requires g++ with C++20 support.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages