forked frommarcelbuesing/can-dbc
- Notifications
You must be signed in to change notification settings - Fork0
auxoncorp/can-dbc
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A CAN-dbc format parser written with Rust'snom 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::*;fnmain() -> io::Result<()>{letmut f =File::open("./examples/sample.dbc")?;letmut buffer =Vec::new(); f.read_to_end(&mut buffer)?;let dbc = can_dbc::DBC::from_slice(&buffer).expect("Failed to parse dbc file");letmut scope =Scope::new();for messagein dbc.messages(){for signalin message.signals(){letmut scope =Scope::new();let message_struct = scope.new_struct(message.message_name());for signalin 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 atdbc-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"
- version
- new_symbols
- bit_timing(deprecated but mandatory)
- nodes
- value_tables
- messages
- message_transmitters
- environment_variables
- environment_variables_data
- signal_types
- comments
- attribute_definitions
- sigtype_attr_list(format missing documentation)
- attribute_defaults
- attribute_values
- value_descriptions
- category_definitions(deprecated)
- categories(deprecated)
- filter(deprecated)
- signal_type_refs
- signal_groups
- signal_extended_value_type_list
- multispace between parsers instead of single space allowing e.g. (two spaces)
SIG_GROUP 13
. VAL_
suffix may be;
or;
Test dbcs files were copied from thecantools project.
This project usescargo-deny for checking the licenses of dependencies. To run the check locally run the following:
cargo install cargo-denycargo deny check