#can #dbc #parser #socketcan #j1939

canparse

A CAN signal and definition parser

3 releases

0.1.3 Feb 9, 2019
0.1.2 Jun 9, 2018
0.1.1 May 23, 2018

#8 in #can

Download history 11/week @ 2018-10-27 11/week @ 2018-11-03 9/week @ 2018-11-10 4/week @ 2018-11-17 8/week @ 2018-11-24 5/week @ 2018-12-01 3/week @ 2018-12-08 4/week @ 2018-12-15 8/week @ 2018-12-22 4/week @ 2019-01-05 3/week @ 2019-01-12 2/week @ 2019-01-26 1/week @ 2019-02-02

17 downloads per month

MIT/Apache

50KB
1K SLoC

canparse

crates.io Build Status codecov

A CAN signal and definition parser, written in Rust.

The goal of canparse is to provide a means of converting CAN frames into pre-defined signals, via CANdb definition input (DBC). One common application is the J1939 spec, which defines a set of common parameters for heavy-duty trucks and other vehicles. PgnLibrary is also included as an application of DBC, to give first-class support for the PGN/SPN schema.

Documentation

Usage

Add canparse to your Cargo.toml with:

[dependencies]
canparse = "0.1"

Example

For a predefined DBC file, a simple program which utilizes PgnLibrary can be implemented as folows:

extern crate canparse;

use canparse::pgn::{PgnLibrary, SpnDefinition, ParseMessage};

fn main() {

    // Parse dbc file into PgnLibrary
    let lib = PgnLibrary::from_dbc_file("./j1939.dbc").unwrap();

    // Pull signal definition for engine speed
    let enginespeed_def: &SpnDefinition = lib
        .get_spn("Engine_Speed").unwrap();

    // Parse frame containing engine speed
    let msg: [u8; 8] = [0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88];
    let engine_speed: f32 = enginespeed_def.parse_message(&msg).unwrap();

    println!("Engine speed: {}", engine_speed);
}

Feature flags

  • use-socketcan - Support for socketcan-rs has been included for Linux systems requiring a translation from CANFrame messages, using SpnDefinition values.

Alternatives

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~4.5MB
~76K SLoC