Rust dbc parser

Related tags

Automotive can-dbc
Overview

can-dbc

LICENSE VERSION Actions 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

Comments
  • I tried to generate using following dbc file:

    I tried to generate using following dbc file:

    I tried to generate using following dbc file: toyota_corolla_2017_pt_generated.dbc.zip But got error:

    Error: Could not parse dbc file: NomError(
        Error(
            Code(
                CompleteByteSlice(
                    [
                        67,
                        77,
                        95,
                        32,
                        34,
                        65,
                        85,
                        84,
                        79,
                        71,
                        69,
                        78,
                        69,
                        82,
                        65,
                        84,
                        69,
                        68,
    ...
    

    Originally posted by @andresv in https://github.com/technocreatives/dbc-codegen/issues/7#issuecomment-792576173

    opened by marcelbuesing 8
  • Be more lenient about trailing spaces

    Be more lenient about trailing spaces

    Hi, I've recently used canmatrix to generate a dbc file (from kcd) and can-dbc had some issues parsing it. Figuring out what went wrong took me about an hour, but the fix was rather trivial -- it was just a bunch of trailing spaces.

    opened by killercup 6
  • Allow zero time occurence of BU name

    Allow zero time occurence of BU name

    By the dbc file format specification node name could be repeated from zero to multiple times. This commit fix node name parsing allowing zero time name occurences.

    opened by euttsov 3
  • Add support for dbcs with extended multiplex messages

    Add support for dbcs with extended multiplex messages

    Parsing a DBC file with extendend multiplexing (multiple and possibly nested multiplexors per message) results currently in a partly parsed file. Extended Multiplexing is described here: https://cdn.vector.com/cms/content/know-how/_application-notes/AN-ION-1-0521_Extended_Signal_Multiplexing.pdf

    I added support, but the message_multiplexor_switch function makes no sense for multiplexed messages. Any suggestions how to handle that?

    opened by pbert519 2
  • VAL_TABLE_ cannot be parsed

    VAL_TABLE_ cannot be parsed

    Hi there, I am trying to parse a VAL_TABLE_. I have added it to the SAMPLE_DBC in lib.rs, right after the VAL_ line, and it looks like this:

    VAL_TABLE_ Signal_4 1 \"Val1\" 2 \"Val2\";
    

    This results in an Incomplete error. Am I doing something wrong? I've tried several variants of VAL_TABLE_ lines, and nothing seems to work.

    opened by theryangeary 2
  • Question: serialize to CAN payload

    Question: serialize to CAN payload

    I can see that this library can be used to parse messages from dbc file. However is it also possible to serialize those messages so they can be sent out using socketcan?

    opened by andresv 1
  • Add license scan report and status

    Add license scan report and status

    Your FOSSA integration was successful! Attached in this PR is a badge and license report to track scan status in your README.

    Below are docs for integrating FOSSA license checks into your CI:

    opened by fossabot 1
  • Vector vs HashMap; Attribute Values

    Vector vs HashMap; Attribute Values

    Hi, just curious as to your reasoning for choosing vectors over hash-maps for the organization of the members of the DBC struct.

    I was also curious if you planned on associating attribute_values that pertain directly to signals/messages in the signals/messages themselves rather than a completely seperate vector in the DBC struct. I've found myself wanting to have those available with the messages themselves rather than looking up the message THEN looking up the attribute_values.

    Just curious as to your thoughts.

    Thanks for the work done on this, it has greatly assisted me to do some rapid development with CAN.

    opened by vergil-SI 2
Releases(5.0.0)
Owner
Marcel
don't forget to play. PGP https://keybase.io/marcelbuesing
Marcel
Linux SocketCAN access in Rust

Rust SocketCAN support Maintenance status: This crate is in the process of entering renewed joint maintainership with @fpagliughi. Please stay patient

Marc Brinkmann 61 Dec 30, 2022
Yet Another Parser library for Rust. A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing strings and slices.

Yap: Yet another (rust) parsing library A lightweight, dependency free, parser combinator inspired set of utility methods to help with parsing input.

James Wilson 117 Dec 14, 2022
Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Website for Microformats Rust parser (using 'microformats-parser'/'mf2')

Microformats 5 Jul 19, 2022
Djotters is a Djot parser and translater written via parser combinators, in rust.

?? Djotters Turning your Djot (markdown) into lovely HTML! Djotters is here to let you draft up a document and watch it render in real time. If you wa

Anthony Alaribe 4 Mar 26, 2024
A language parser tool to build recursive descent top down parser.

lang-pt A language parser tool to generate recursive descent top down parser. Overview Parsers written for the languages like Javascript are often cus

Creative Forest 7 Jan 4, 2023
Rust DLT (Diagnostic Log and Trace) packet parser

dlt_parse A zero allocation rust library for basic parsing & writing DLT (Diagnostic Log and Trace) packets. Currently only the parsing and writing of

Julian Schmid 23 Dec 16, 2022
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

null 10.4k Jan 10, 2023
Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

null 743 Jan 1, 2023
JSON parser which picks up values directly without performing tokenization in Rust

Pikkr JSON parser which picks up values directly without performing tokenization in Rust Abstract Pikkr is a JSON parser which picks up values directl

Pikkr 615 Dec 29, 2022
A XML parser written in Rust

RustyXML Documentation RustyXML is a namespace aware XML parser written in Rust. Right now it provides a basic SAX-like API, and an ElementBuilder bas

null 97 Dec 27, 2022
A CSV parser for Rust, with Serde support.

csv A fast and flexible CSV reader and writer for Rust, with support for Serde. Dual-licensed under MIT or the UNLICENSE. Documentation https://docs.r

Andrew Gallant 1.3k Jan 5, 2023
A native Rust port of Google's robots.txt parser and matcher C++ library.

robotstxt A native Rust port of Google's robots.txt parser and matcher C++ library. Native Rust port, no third-part crate dependency Zero unsafe code

Folyd 72 Dec 11, 2022
Rust parser combinator framework

nom, eating data byte by byte nom is a parser combinators library written in Rust. Its goal is to provide tools to build safe parsers without compromi

Geoffroy Couprie 7.6k Jan 7, 2023
Parsing Expression Grammar (PEG) parser generator for Rust

Parsing Expression Grammars in Rust Documentation | Release Notes rust-peg is a simple yet flexible parser generator that makes it easy to write robus

Kevin Mehall 1.2k Dec 30, 2022
A fast monadic-style parser combinator designed to work on stable Rust.

Chomp Chomp is a fast monadic-style parser combinator library designed to work on stable Rust. It was written as the culmination of the experiments de

Martin Wernstål 228 Oct 31, 2022
A parser combinator library for Rust

combine An implementation of parser combinators for Rust, inspired by the Haskell library Parsec. As in Parsec the parsers are LL(1) by default but th

Markus Westerlind 1.1k Dec 28, 2022
LR(1) parser generator for Rust

LALRPOP LALRPOP is a Rust parser generator framework with usability as its primary goal. You should be able to write compact, DRY, readable grammars.

null 2.4k Jan 7, 2023
A typed parser generator embedded in Rust code for Parsing Expression Grammars

Oak Compiled on the nightly channel of Rust. Use rustup for managing compiler channels. You can download and set up the exact same version of the comp

Pierre Talbot 138 Nov 25, 2022
Rust query string parser with nesting support

What is Queryst? This is a fork of the original, with serde and serde_json updated to 0.9 A query string parsing library for Rust inspired by https://

Stanislav Panferov 67 Nov 16, 2022
Soon to be AsciiDoc parser implemented in rust!

pagliascii "But ASCII Doc, I am Pagliascii" Soon to be AsciiDoc parser implemented in rust! This project is the current implementation of the requeste

Lukas Wirth 49 Dec 11, 2022