Crates.io | can-dbc |
lib.rs | can-dbc |
version | 6.0.0 |
source | src |
created_at | 2018-12-09 20:37:26.637289 |
updated_at | 2024-02-08 22:13:01.950378 |
description | A parser for the DBC format. The DBC format is used to exchange CAN network data. |
homepage | https://github.com/marcelbuesing/can-dbc |
repository | https://github.com/marcelbuesing/can-dbc.git |
max_upload_size | |
id | 100994 |
size | 321,717 |
A CAN-dbc format parser written with Rust's nom parser combinator library.
Read dbc file and generate Rust structs based on the messages/signals defined in the dbc.
use can_dbc::DBC;
use codegen::Scope;
use std::fs::File;
use std::io;
use std::io::prelude::*;
fn main() -> io::Result<()> {
let mut f = File::open("./examples/sample.dbc")?;
let mut buffer = Vec::new();
f.read_to_end(&mut buffer)?;
let dbc = can_dbc::DBC::from_slice(&buffer).expect("Failed to parse dbc file");
let mut scope = Scope::new();
for message in dbc.messages() {
for signal in message.signals() {
let mut scope = Scope::new();
let message_struct = scope.new_struct(message.message_name());
for signal in message.signals() {
message_struct.field(signal.name().to_lowercase().as_str(), "f64");
}
}
}
println!("{}", scope.to_string());
Ok(())
}
For a proper implementation for reading or writing CAN frames according to the DBC, I recommend you take a look at dbc-codegen.
The file parser simply parses a dbc input file and prints the parsed content.
cargo test && ./target/debug/examples/file_parser -i examples/sample.dbc
can-dbc is available on crates.io and can be included in your Cargo enabled project like this:
[dependencies]
can-dbc = "3.0"
SIG_GROUP 13
.VAL_
suffix may be ;
or ;
Test dbcs files were copied from the cantools project.
This project uses cargo-deny for checking the licenses of dependencies. To run the check locally run the following:
cargo install cargo-deny
cargo deny check