23static void PrintTree (
const TreeNode *node,
int indent) {
27 for (
int i = 0; i < indent; ++i)
32 std::cout <<
"[root] " << node->
GetName() <<
"\n";
35 case NodeType::Frame: {
37 std::cout <<
"[frame] " << node->
GetName();
39 if (frame !=
nullptr) {
40 std::cout <<
" id=0x" << std::hex << frame->
canId << std::dec
41 <<
" ext=" << (frame->
isExtended ?
"yes" :
"no")
42 <<
" dlc=" <<
static_cast<unsigned int> (frame->
dlc);
45 std::cout <<
" pgn=" << frame->
pgn;
52 case NodeType::Signal: {
54 std::cout <<
"[signal] " << node->
GetName();
56 if (signal !=
nullptr) {
57 std::cout <<
" start=" << signal->
startBit
58 <<
" len=" << signal->
length
59 <<
" unit=" << signal->
unit;
67 std::cout <<
"[unknown]\n";
72 PrintTree (node->
GetChild (i), indent + 1);
77 std::cout <<
"No frame definition found.\n";
81 std::cout <<
"Decoded frame: " << decoded.
definition->
name <<
"\n";
83 for (std::size_t index = 0U; index < decoded.signals.size(); ++index) {
97int main (
int argc,
char *argv[]) {
99 std::cerr <<
"Usage: dbc_demo <file.dbc>\n";
108 std::unique_ptr<TreeNode> root = treeBuilder.
Build (database);
110 std::cout <<
"=== Parsed tree ===\n";
111 PrintTree (root.get(), 0);
121 rawFrame.
canId = decodeDatabase.frames.empty() ? 0U : decodeDatabase.frames[0].canId;
122 rawFrame.
isExtended = decodeDatabase.frames.empty() ? false : decodeDatabase.frames[0].isExtended;
123 rawFrame.
data.resize (8U, 0U);
128 std::cout <<
"\n=== Decoded frame ===\n";
129 PrintDecodedFrame (decoded);
130 }
catch (
const std::exception &ex) {
131 std::cerr <<
"Error: " << ex.what() <<
"\n";
Converts parsed DBC data into runtime decode database.
DecodeDatabase Build(const DbcDatabase &source) const
Build runtime decode database.
Runtime CAN decoder using prebuilt decode database.
DecodedFrameValue Decode(const DecodeDatabase &database, const RawCanFrame &frame) const
Decode one raw CAN frame.
DbcDatabase ParseFile(const std::string &filePath) const
Parse DBC file.
Builds a simple tree from parsed DBC database.
std::unique_ptr< TreeNode > Build(const DbcDatabase &database) const
Build tree representation of parsed DBC data.
Tree node for later use in model/view or other hierarchy consumers.
const SignalInfo * GetSignal() const
Get signal payload if node is signal.
const TreeNode * GetChild(std::size_t index) const
Get child by index.
const std::string & GetName() const
Get display name.
std::size_t GetChildCount() const
Get child count.
NodeType GetType() const
Get node type.
const FrameInfo * GetFrame() const
Get frame payload if node is frame.
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Parsed DBC content stored in a simple internal form.
Runtime decode database with fast lookup by CAN ID.
const DecodeFrame * definition
One decoded signal value.
const DecodeSignal * definition
Describes one CAN frame from a DBC file.
Raw CAN frame used for runtime or trace decoding.
std::vector< std::uint8_t > data
Describes one signal inside a DBC frame.