can_tools
can_tools
is a Rust library for parsing DBC files
used in automotive applications to describe CAN network messages and signals.
It provides a clean and easy-to-use API to read .dbc
files, inspect messages, signals, and nodes,
and access comments and value tables.
✨ Features
- Parses complete
.dbc
files into structured Rust types - Reads:
- Version information
- Bit timing
- Nodes
- Messages
- Signals
- Comments
- Value tables
- Case-insensitive search utilities for messages, signals, and nodes
- Simple API: one call to
parse
produces a ready-to-useDatabase
📦 Installation
Add this to your Cargo.toml
:
[]
= "0.1.7"
🚀 Example
use parse;
📊 Data Model
┌───────────────────────────────────────┐
│ Database │
│───────────────────────────────────────│
│ version: String │
│ bit_timing: String │
│ nodes: Vec<Node> │
│ messages: Vec<Message> │
└───────────────────────┬───────────────┘
│
▼
┌───────────────────────────────────────┐
│ Message │
│───────────────────────────────────────│
│ id: u64 │
│ id_hex: String │
│ name: String │
│ byte_length: usize │
│ sender_nodes: Vec<Node> │
│ signals: Vec<Signal> │
└───────────────────────┬───────────────┘
│
▼
┌───────────────────────────────────────┐
│ Signal │
│───────────────────────────────────────│
│ name: String │
│ bit_start: usize │
│ bit_length: usize │
│ endian: usize │
│ sign: usize │
│ factor: f64 │
│ offset: f64 │
│ min: f64 │
│ max: f64 │
│ unit_of_measurement: String │
│ receiver_nodes: Vec<Node> │
│ value_table: HashMap<i32, String> │
└───────────────────────────────────────┘
Node: represents a CAN ECU (sender or receiver)
📚 Main Types
-
Database
Holds the parsed DBC file structure, including version, bit timing, allNode
s, andMessage
s. -
Message
Represents a CAN message. Contains message ID, name, sender nodes, and its list ofSignal
s. -
Signal
Represents a data field within a CAN message, including bit position, length, scaling factor, unit, receiver nodes, and optional value descriptions. -
Node
Represents a CAN network node (ECU) that can send or receive messages.
📜 License
Licensed under the MIT License.