can-dbc

LICENSE VERSION Build Status codecov docs FOSSA Status

A CAN-dbc format parser written with Rust's nom parser combinator library.

1. Example

Read dbc file and generate Rust structs based on the messages/signals defined in the dbc.

```rust 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.readtoend(&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(())

} ```

2. Example

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

Installation

can-dbc is available on crates.io and can be included in your Cargo enabled project like this:

yml [dependencies] can-dbc = "3.0"

Implemented DBC parts

Deviating from standard

Alternatives

License

FOSSA Status