Skip to content

Integer wrapping around rather than negative value #25

@JulianWgs

Description

@JulianWgs

A minimal dbc-file:

VERSION "A version string"

BA_ "SingleFrame" BO_ 2364539904 0;

BO_ 643 Message: 8 Vector__XXX
 SG_ Signal : 32|16@1- (1,0) [0|0] "" Vector__XXX

Rust code:

extern crate canparse;
// use std::env;

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

fn main() {
    let dbc_filename = "test.dbc";
    let msg_name = "Signal";

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

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

    // Parse frame containing engine speed
    let msg: [u8; 8] = [0x00, 0x01, 0x00, 0x00, 0xcb, 0xff, 0x02, 0x00];
    let engine_speed = enginespeed_def.parse_message(&msg).unwrap();

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

Output:

Engine speed: 65483

But the correct value should be 65483 - 2**16=-53, which cantools correctly decodes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions