#dbc #can #automotive #ecu

can-dbc

A parser for the DBC format. The DBC format is used to exchange CAN network data.

12 stable releases

✓ Uses Rust 2018 edition

3.0.1 May 17, 2020
3.0.0 Nov 25, 2019
2.2.1 Nov 14, 2019
2.2.0 Jun 3, 2019
1.0.0 Dec 9, 2018

#64 in Parser implementations

Download history 25/week @ 2020-03-14 34/week @ 2020-03-21 134/week @ 2020-03-28 175/week @ 2020-04-04 223/week @ 2020-04-11 32/week @ 2020-04-18 17/week @ 2020-04-25 14/week @ 2020-05-02 2/week @ 2020-05-09 24/week @ 2020-05-16 32/week @ 2020-05-23 43/week @ 2020-05-30 8/week @ 2020-06-06 19/week @ 2020-06-13 8/week @ 2020-06-20 19/week @ 2020-06-27

261 downloads per month
Used in dbcc

MIT license

77KB
2K SLoC

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.

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(())
}

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:

[dependencies]
can-dbc = "3.0"

Implemented DBC parts

  • 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

Deviating from standard

  • multispace between parsers instead of single space allowing e.g. (two spaces) SIG_GROUP 13.
  • VAL_ suffix may be ; or ;

Alternatives

License

FOSSA Status

Dependencies

~1–1.5MB
~32K SLoC