can_tools
Rust utilities for reading, creating, editing and writing CAN DBC files, with optional AUTOSAR .arxml import support.
Features
- Parse DBC files into an in-memory
CanDatabase(tolerant to comments, extra spaces, and Windows-1252 encoded files). - Convert AUTOSAR
.arxmlclusters intoCanDatabaseinstances. - Serialize databases back to DBC text with attributes, comments, value tables, multiplexing, and sender/receiver relations.
- Build a fresh database with sensible defaults for attributes such as bus type, baud rate, and version metadata.
- SlotMap-backed storage with stable keys for nodes, messages, and signals, plus helper lookups and sort utilities.
Quick start
Add to your Cargo.toml:
= "2.1.2"
Parse a DBC, tweak it, and write it back:
use ;
Create a brand new database:
use ;
Import AUTOSAR .arxml:
use parse;
Iterate messages, nodes, and signals:
use ;
Modules at a glance
parse:from_dbc_fileandfrom_arxml_fileentry points for ingestion.save:save_to_fileand helpers to serialize aCanDatabase.create: builds aCanDatabasepre-populated with canonical attributes.types: core data structures (CanDatabase,CanMessage,CanSignal,CanNode, attributes, errors).core: internal decoders/encoders for DBC sections (attributes, comments, signals, value tables, etc.).
Error handling
All public operations return strongly-typed errors (e.g. DbcParseError, DbcSaveError, DatabaseError). Many parsing helpers are resilient: malformed lines are skipped where safe, while structural issues (wrong extensions, I/O errors) bubble up as errors.
Notes
- DBC files are decoded as Windows-1252 with common German characters transliterated to ASCII.
- Names and lookups are case-insensitive; message IDs are tracked in both decimal and hex.
- Multiplexing is supported (both multiplexer and multiplexed signals), as are value tables and relational attributes (
BU_SG_REL_,BU_BO_REL_).
License
MIT