dbcc 
=============
dbcc can translate data base CAN files into Rust code.
The generated code allows interacting with CAN signals in a type safe manner by e.g. matching against signal value enum types.
Furthermore it provides a convenient way to use SocketCAN BCM Sockets, via tokio streams, to filter for a specified message by can identifier.
Features
- Generate message, signal decoder code
- Generate message id constants
- Generate enums for matching against signal values
- Generate tokio streams for CAN messages
- Generate message, signal encoders
Option 1 - Run CLI
Install
cargo install dbcc
Generate code using the CLI.
dbcc --input dbcc --with-tokio -i examples/j1939.dbc > examples/gen/j1939.rs
For warnings during the generation run with:
RUST_LOG=info dbcc --with-tokio -i examples/j1939.dbc > examples/gen/j1939.rs
Option 2 - build.rs
Generate code at build time. Add the following to your build.rs. Adapt the dbc input path and target path according to your needs.
use ;
use can_dbc;
use File;
use *;
use Path;
Include
- Move the generated rust file to your project's
src/folder. - Add the following dependency to your project's
Cargo.toml
byteorder = "1.2"
Use
/// If you are using Rust 2018 no `external crate byteorder;` is necessary
/// Generated module
Including SocketCAN Streams
- Make sure you pass the
--with-tokioflag when invoking dbcc. - Move the generated rust file to your project's
src/folder. - Add the following dependencies to your project's
Cargo.toml
byteorder = "1.3"
futures = "0.3"
tokio = "0.3"
tokio-socketcan-bcm = "1.0"
use Future;
use Stream;
use io;
use Duration;
use tokio;
Naming
Recommendation: Value descriptions aka VAL_ ... should contain only
alphanumeric characters or underscores and should start with an alphabetic character.
E.g. VAL_ 100 "111 Wunderschön Inc" 255 should be VAL_ 100 " Wunderschoen Inc 111" 255
- Enums: Generated names are prefixed with an
Xif the name does not start with an alphabetic character. - Enums: Characters that are not alphanumeric or
_are replaced with anX - Enums: An
XValue(f64)variant is added to each enum since value descriptions often do not cover all possibilities.