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§
- parser
- Module containing nom parser combinators
Structs§
- Attr
Default - Attribute
Default - Attribute
Value ForObject - Baudrate
- Baudrate of network in kbit/s
- DBC
- Environment
Variable - Environment
Variable Data - Extended
Multiplex - Mapping between multiplexors and multiplexed signals
- Extended
Multiplex Mapping - Message
- CAN message (frame) details including signal details
- Message
Transmitter - Node
- CAN network nodes, names must be unique
- Signal
- 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
Extended Value Type List - Signal
Groups - Signal groups define a group of signals within a message
- Signal
Type - Signal
Type Ref - Symbol
- ValDescription
- Value
Table - Global value table
- Version
- Version generated by DB editor
Enums§
- Access
Node - Access
Type - Attribute
Definition - Attribute
Value - Attribute
Value Type - Attribute
Valued ForObject Type - Byte
Order - Comment
- Object comments
- EnvType
- Error
- Possible error cases for
can-dbc
- Message
Id - CAN id in header of CAN frame. Must be unique in DBC file.
- Multiplex
Indicator - Signal
Attribute Value - Signal
Extended Value Type - Transmitter
- Value
Description - Encoding for signal raw values.
- Value
Type