Git Product home page Git Product logo

a2lfile's Introduction

a2lfile

Github Actions codecov license

a2lfile is a library that allows you to read, modify and write a2l files.

Features

  • full support for files using A2L version 1.7.1
  • it is fast
  • the layout and format of the input file is preserved. The intention is that after reading, modifying and then writing a file the resulting diff should be minimal
  • easy access to application-specific data inside of IF_DATA blocks is provided through a macro that generates code based on an A2ML specification

What is an a2l file

A2l files are commonly used during the development and testing of automotive ECUs. The consumer of the a2l file typically performs online calibration over a protocol such as XCP and/or offline tuning by generating flashable parameter sets.

If you have never seen an a2l file then you are unlikely to need this library.

Tools

The program a2ltool is based on this library.

Documentation

Add this to your Cargo.toml:

[dependencies]
a2lfile = "2.0"

A simple program based on the a2lfile library might look like this:

use a2lfile::*;

fn main() {
    let input_filename = &std::ffi::OsString::from("example.a2l");
    let mut logmsgs = Vec::<A2LError>::new();
    let mut a2l_file = a2lfile::load(
        input_filename,
        None,
        &mut logmsgs,
        false
    ).expect("could not load the file");
    for log_msg in logmsgs {
        println!("warning while loading the file: {}", log_msg);
    }

    // perform a consistency check
    let mut logmsgs = Vec::<String>::new();
    a2l_file.check(&mut logmsgs);
    for log_msg in logmsgs {
        println!("warning during consistency check: {}", log_msg);
    }

    for measurement in &a2l_file.project.module[0].measurement {
        // do something with the MEASUREMENT objects in the file
        println!("MEASUREMENT: {:#?}", measurement);
    }

    // create a new CHARACTERISTIC object
    let new_characteristic = Characteristic::new(
        "my_name".to_string(),
        "my extended description".to_string(),
        CharacteristicType::Value,
        0x12345678,
        "something.RECORD_LAYOUT".to_string(),
        0.0,
        "NO_COMPU_METHOD".to_string(),
        0.0,
        100.0
    );
    a2l_file.project.module[0].characteristic.push(new_characteristic);


    // update the sorting to find a suitable insertion point for the new characteristic - by default it will be placed at the end
    a2l_file.sort_new_items();

    // write the modified file
    a2l_file.write(
        &std::ffi::OsString::from("example_output.txt"),
        Some("modified by the demo program")
    ).expect("failed to write output");
}

License

Licensed under either of

a2lfile's People

Contributors

danielt avatar jl-rbpt avatar stephan-cr avatar tardyp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

a2lfile's Issues

Please add a CHAGELOG and use SemVer

At first thanks for your great crate and our effort.

It would be nice if you could add CHANGELOG to your repo. So it is really easy for all users of your crate to see the the differences of the versions. If I could suggest a changelog format, I would use https://keepachangelog.com/en/1.0.0/

It would be nice too, if you could use / switch semantic versioning https://semver.org/
Rust uses SemVer as default for specifing dependencies https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html

RECORD_LAYOUT fields are not sorted correctly

RECORD_LAYOUT fields should be sorted by the position (index) in an ascending order. Some tools give warning about this.

Current behavior:

/begin RECORD_LAYOUT
      MAP_XU16_YU16_ZU16
      AXIS_PTS_X 3 UWORD INDEX_INCR DIRECT
      AXIS_PTS_Y 4 UWORD INDEX_INCR DIRECT
      FNC_VALUES 5 UWORD ROW_DIR DIRECT
      NO_AXIS_PTS_X 1 UBYTE
      NO_AXIS_PTS_Y 2 UBYTE
/end RECORD_LAYOUT

Expected behavior:

/begin RECORD_LAYOUT
      MAP_XU16_YU16_ZU16
      NO_AXIS_PTS_X 1 UBYTE
      NO_AXIS_PTS_Y 2 UBYTE
      AXIS_PTS_X 3 UWORD INDEX_INCR DIRECT
      AXIS_PTS_Y 4 UWORD INDEX_INCR DIRECT
      FNC_VALUES 5 UWORD ROW_DIR DIRECT
/end RECORD_LAYOUT

DISPLAY_IDENTIFIER that starts with a number causes a tokenization exception

I have encountered an a2l which contains DISPLAY_IDENTIFIER names that start with a number. This causes an "TokenizerError { tokenizer_error: MissingWhitespace" error to be thrown when the a2lfile loads the a2l.

The screenshot below contains an example:

Screenshot from 2023-11-09 17-20-34

I do not know if a DISPLAY_IDENTIFIER name that starts with a number is valid in the a2l format. If it isn't, than this issue could be ignored or a feature could be added to the parser to detect this illegal name type. Then, a more appropriate error could be raised.

a2l merge group or function issue

Hi,
this is a very useful and fast tool for the a2l merge.
but when merge group and funtion the REF_MEASURMENT varaibels will be added the .MERGE.
this is wrong process for group and function merge operation. but for the measurements and characteristics.

Extract Record Layout field from Characteristics variables

Is it possible to extract the Record_Layout field from a Characteristic variable using a2lFile's parser ?

Ex:
Assuming I have the following Characteristic variable called CoF_swtFlt0_C, is it possible to extract the record layout's value SCALAR_UBYTE ?

image

merge_mod_par issue

Hi,
when i use a2ltool to merge a2l files, but the mod_par part has issues because currently the SYSTEM_CONSTANT is not considered. only consider the MEMORY_LAYOUT and MEMORY_SEGMENT elements. but the SYSTEM_CONSTANT elements are alao need to merge.

namemap public API

Hi,
First of all, thanks for this crate, it makes a2l a bit less hateable.

First thing I do to use the crate is to index most things by name as everything is referencing each other by name.

then I realized a2lfile includes a namemap, which already does that thing for me.
then I realize its private for the checker utility.

I wanted to just submit a PR making it pub, but then the interface with the log_msg might not be the best.

Can we think of a proper api?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.