Expand description
A CAN database (dbc) format parser written with Rust’s nom parser combinator library. CAN databases are used to exchange details about a CAN network. E.g. what messages are being send over the CAN bus and what data do they contain.
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(())
}
Modules
Module containing nom parser combinators
Structs
Baudrate of network in kbit/s
CAN message (frame) details including signal details
CAN id in header of CAN frame.
Must be unique in DBC file.
CAN network nodes, names must be unique
One or multiple signals are the payload of a CAN frame.
To determine the actual value of a signal the following fn applies:
let fnvalue = |can_signal_value| -> can_signal_value * factor + offset;
Signal groups define a group of signals within a message
Global value table
Version generated by DB editor
Enums
Object comments
Possible error cases for
can-dbc
Encoding for signal raw values.