Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: LIN bus *.LDF to *.DBC format #531

Open
MatinF opened this issue Dec 2, 2020 · 28 comments
Open

Feature request: LIN bus *.LDF to *.DBC format #531

MatinF opened this issue Dec 2, 2020 · 28 comments
Assignees

Comments

@MatinF
Copy link

MatinF commented Dec 2, 2020

Hi Eduard,

Would it be possible to support loading a LIN bus *.LDF file into canmatrix - with the use case of e.g. creating a DBC file from the loaded LDF file?

This would e.g. allow tools like asammdf that rely on canmatrix to let users load *.LDF files directly to decode LIN bus data - or to alternatively use canmatrix to first create a DBC file from their LDF files.

We would be able to provide sample LIN bus data in the MDF4 format as well as LDF files for this purpose via e-mail. Further, we would be happy to work with you to test and evaluate the code.

Let me know if this is something you'd be open to.

There may be some option to leverage source code from e.g. this module:
https://github.com/uCAN-LIN/LinUSBConverter

@danielhrisca
Copy link
Contributor

It would be great to load the LDF files as canmatrix.Matrix objects as well

@reymor
Copy link

reymor commented Jan 17, 2021

@MatinF @ebroecker

Hello,

I'm open to contribute to this new feature. Let me know how I could help you.

@ebroecker ebroecker self-assigned this Jan 17, 2021
@ebroecker
Copy link
Owner

using ldfparser (https://github.com/c4deszes/ldfparser) looks very promising to me.

Gonna hack something thus we have a base to discuss.

@ebroecker
Copy link
Owner

@MatinF
Copy link
Author

MatinF commented Jan 23, 2021

Awesome Eduard. Daniel if you get the chance to test adding this to asammdf I can do some tests

@MatinF
Copy link
Author

MatinF commented Feb 9, 2021

Hi Eduard, would you be able to include this functionality in an upcoming release? Then it may be possible to include it in e.g. asammdf and our Python API.

@ebroecker
Copy link
Owner

Does it fullfill your needs?
Did you test?

If it works for your needs certainly I'll add it to a future release

@danielhrisca
Copy link
Contributor

I'm getting this error when I try to load a LDF file:

File "D:\02__PythonWorkspace\_venv\lib\site-packages\canmatrix\formats\__init__.py", line 96, in load
    dbs[key] = module_instance.load(file_object, **options)  # type: ignore
  File "D:\02__PythonWorkspace\_venv\lib\site-packages\canmatrix\formats\ldf.py", line 7, in load
    ldf = ldfparser.parseLDF(path=f.name)  # using f.name is not nice, but works
AttributeError: '_io.BytesIO' object has no attribute 'name'

@danielhrisca
Copy link
Contributor

I've managed to load the LDF file only by using canmatrix.formats.loadp instead of canmatrix.formats.loads

Here are the first missing items:

  • conversion rules are not loaded
  • I don't think that there is an explicit signed/unsigned declaration in the ldf so this would have to be deduced from the conversion definition (there it has the min and max raw range)

@MatinF
Copy link
Author

MatinF commented Feb 10, 2021

It should also be noted perhaps that some LIN messages contain signals that have differing decoding rules depending on the physical value. For example the below message:

  Enc_BatteryCurrent {
    physical_value, 1, 66, 10, -1230, "Ampere" ;
    physical_value, 67, 4765, 0.1, -576.6, "Ampere" ;
    physical_value, 4766, 12765, 0.01, -147.66, "Ampere" ;
    physical_value, 12766, 52765, 0.001, -32.766, "Ampere" ;
    physical_value, 52766, 60765, 0.01, -507.66, "Ampere" ;
    physical_value, 60766, 65465, 0.1, -5976.6, "Ampere" ;
    physical_value, 65466, 65532, 10, -654090, "Ampere" ;
    logical_value, 0, "IBatt_lowerlimit" ;
    logical_value, 65533, "IBatt_upperlimit" ;
    logical_value, 65534, "BatteryCurrent_Error" ;
    logical_value, 65535, "LIN_INIT" ;
  }

In such cases, the decoding rule logic cannot be fully handled within the DBC framework. My recommendation for now would be to simply ignore such messages if possible.

@ebroecker
Copy link
Owner

Thanks for the feedback, gonna work on it

ebroecker added a commit that referenced this issue Feb 10, 2021
add support for LIN-Converters
@MatinF
Copy link
Author

MatinF commented Feb 12, 2021

In regards to comparing LDF vs DBC, you might also find the below article section useful Eduard:
https://www.csselectronics.com/screen/page/lin-bus-protocol-intro-basics/language/en#lin-description-file

Martin

@ebroecker
Copy link
Owner

did someone have a chance to check acdd5d3 ?

@MatinF
Copy link
Author

MatinF commented Feb 21, 2021

@danielhrisca not sure if this is the version you included in the asammdf dev version I tested

@danielhrisca
Copy link
Contributor

danielhrisca commented Mar 7, 2021

@ebroecker the new commit throws this exception in calc_max

File "D:\02__PythonWorkspace\_venv\lib\site-packages\canmatrix\canmatrix.py", line 395, in calc_max
    return self.offset + (self.float_factory(rawMax) * self.factor)
TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'

I think all LDF signals should be parsed as unsigned. @MatinF please confirm if this is true.

Another problem is that there should have a way to store all the conversions/decoding rules. @ebroecker do you think this could be feasible?

ebroecker added a commit that referenced this issue Jan 11, 2022
* include LICENSE in source distribution (#365)

* arxml: rx/tx typo fix 

fix for #366

* annotate and fix codestyle dbc (#369)

* Always use Signal.is_little_endian as bool #326 (#371)

* Add coding, remove #!python where inappropriate (#370)

* annotation cleanup ticket #323 (#372)

* Update cli doc (inspired by #361) (#373)

* fix: xls is using the wrong number for arbitration id (#377)

* add outputformat for Scapy (#378)

* add output format for scapy
* fix special char handling in scapy exporter
* add unit test
simplify get_fmt

* Dump factor, offset, min, max as float. Load as numeric (#380)

* Dump factor, offset, min, max as float. Load as numeric

* fixed tests

* fixed tests

* added --jsonNativeTypes as cli option

* review remarks

* ARXML: merge container PDU and Secured PDU support  (#384)

* #381 support for containers
* #381 create signalgroups for containers
* #382 support secured pdus) (#383)
* add unittests for #363 and #382

* Iss381 - fix for #381 - wrong default ArbitrationId handling (#386)

* fix for #381 wrong default ArbitrationId handling

* support for Scapy input file (#387)

* add output format for scapy

* optional ignoring failures durig character encoding #375 (#388)

* fix for #238 (j1939 Frame setters might raise TypeError) (#389)

move j1939 (pgn, prio, source) handling direct to arbitration-id class
(fixes #238)

* Iss385 // Arxml Container support and ARXML refactoring (#390)

ARXML updates:
* fix for #385 
* json fix multiplex reading issue (#136)
* ARXML refactoring, DLC for canFD support canmatrix.Frame.fit_dlc now
fits to next correct dlc value, DBC export reniced for candb++ (#385)
* add test for fit_dlc
* arxml refactoring and better type handling #368
* improvement for #242

* DBC: fix #242. J1939 and FD Frames in dbc

candb seems to be queasy about the order of the VFrameFormat attribute
definition. This Patch seems to generate a dbc, which can contain can_fd
AND J1939-frames.

* XLSX fixes  (#392)

XLSX: fixes #240 (signal init value in excel template)
XLSX: fixes #367 (2.)

* fix for #288 (#393)

* switch from optparse to click (#236) (#394)

* [WIP] add Basic cli tests (#395)

* add tests for global, manipulation and filter swithces of cli.convert
* add basic cli test for cli.compare

* fix some bugs, which were found by these tests

* Annotation cleanup #323 (#396)

* Remove cm prefix (#236) (#399)

Thanks

* add muxing support to scapy output; merge PR #398 also (#400)

* [try to] Unify imports (#402)

* unify imports (#236)

* [WIP] dump/export wireshark lua can subdissector (#404)

* add basic wireshark dissector creator
creastes lua script for dissecting can messages

* add cannelloni dissector for wireshark

* add some doc for scapy and wireshark usage

* [WIP] cycle_time as generic signal and frame attribute  (#405)

* implement cycle_time as generic signal and frame attribute / remove
Gen[Msg/Sig]cycle from attributes  #146
* use effective frame cycle time for export
use gcd of singnal-cycletimes for calculating effective cycle time

This removes one (of many) dbc specific parts from canmatrix and other formats

* Iss407: [dbc] Signal Comments with space bevore semicolon broken import (#409)

* fix for issue #407 [dbc] Signal Comments with space bevore semicolon broken import

* make initial value to a native attribute of Signal class (#408)

* make initial value to a native attribute of Signal class

* [dbf] exended ids corrected

* optionally allow multiple singals with same name in frame #411 (#412)

* Fix setup.py for console_scripts (#417)

* [WIP] [dbc] Iss413: fix comment reading with whitespaces in front of ; (#416)

* optionally allow multiple singals with same name in frame #411
* fixes #413 (space before semicolon mulit line comment)
* fix for iss #414, keeps defines in dbc: this keeps defines from dbc in matrix object, even if
native attribute exists.

* convert: selective rx/tx ecu extraction issue #421 (#422)

* [WIP] [ARXML] can_fd info (potentional fix for #410) (#418)

* potentional fix for #410
* [ARXML] can-fd recogintion
* add baudrate attributes

* [WIP] Auto deploy (#420)

* add auto deploy for tags on master

* add submodules doc

* update doc to make start_bit more clear in documentation #424

* [dbc] fix dbc issues (#431)

* fix dbc export for empty matrix
* copy_frame handles default values now (fix #430)

* fix copy_frame

* fix for issue #436 (#439)

* [convert] add delete_obsolete_ecus (fix for #434) (#438)

* [copy] Iss430 better attribute handling  (#437)

* handling missing default values for defines
* add ecu attribute handling #430

* fix for #441 (#442)

* fix for #441 jsonAll export option working again

* make old test less loud

* Fix some bugs in FIBEX export (#445)

* Fix FIBEX convertion, Handle duplicate signal name

* Repair more click convert parameters (#451)

* Repair command line param names for csv, json, xls(x)

* update tests

* use last supported colorama for pypy3.4

* Fixing issue where we see dictionary attributes change during iteration (#455)

* Arxml limits number formats (#457)

* add number decoding in arxml for different basis
* fix #454

* fix for #460

* fix #460

* Update cli.rst

add arxmlExportVersion documentation  (#461)

* Check for EOF when parsing enums in a .sym file. Fixes #465 (#468)

* Check for EOF when parsing enums in a .sym file. Fixes #465

* Fix test to check for different exception in the python2.7 case

* Log the exception as well when importing a format failed (#467)

* Process the .sym file "Title" field. fixes #469 And Fix Enum dictionary comma splitting  (#470)

* Implement processing of the Title property of .sym files.
* Fix CanMatrix.attribute to return default as documented
* Set the default for the "Title" attribute properly
* Reimplement the quote_aware_comma_split function to handle spaces
between fields
* Change the sym parser to use quote_aware_comma_split to split enum value
tables. Fixes #462.
Add test cases to show that enums are read in correctly from .sym files

* fix for #471 (#473)

* Fix J1939 PGN getter/setter to use full 18bits. Fixes #474 (#475)

* Fix J1939 PGN getter/setter to use full 18bits. Fixes #474

Remove the criteria that PF must be >= 240 for PS field to be set as
this seems to be incorrect. (It may be that for some specific case the
PS need to not be used, but it isn't documented here and in general the
PGN should be all 18 bits)
Modifed Tests:

test_canmatrix_get_frame_by_pgn()
seemed to be using made up data and didn't accound for the DP and EDP
fields in expected PGN

test_canid_repr()
Modified the expected repr value to include the PS field in the PGN.

test_canid_parse_values()
Modified expected PGN to include the PS field, Moved the list of
test_data into parametrized cases on a new test.

New Tests:

test_frame_j1939_id_from_components()
Tests constructing a full 29-bit CAN ID from the Priority, Source, and
PGN

test_frame_decode_j1939_id()
Tests extracting Priority Source and PGN from an Arbiration ID

* Add the global desistantion Address 0xFF to the BAM arbitration IDs

* Improve the fix, to more explicitly handle the difference between
PDU-Format 1 and PDU-Format 2, (where the PF >= 240 comes in).
The PGN setter now will now set the arbitration ID to contain the
destination address, but when the PGN getter is used it will strip the
destination field off. I think that it is unlikely for the PGN setter
to be used with PDU-F1 PGN containing a destination. But in the case
that it is I think it makes more sense to not throw the destination
address field away.

* Add enumberations as a field to the json file to store the value tables (#476)

Add a test to check that if a json file is read containing enums and
then saved and re-read it get the same enum table

* Adding changes to allow ArbitrationId classes to be sorted (#466)

* Adding comparators to ArbitrationId
* Changing default Arbitration ID extended to False
* Review based changes
Co-authored-by: Syed Raza <[email protected]>

* Parse sym types (#479)

* Allow parsing of the main .sym signal types : string, raw, char.
Add a type_label attribute so that symbol files can be saved back to
.sym format without loss of information.
Add an is_ascii attribute for symbols
Add a check to see if Signal names need Quoting when saving to a .sym
file (if they start with a number or contain a space etc.)

Add a test which reads in a .sym file containing all signal types and
checks that they are all correctly imported and exported.

* Allow parsing of the main .sym signal types : string, raw, char.
Add a type_label attribute so that symbol files can be saved back to
.sym format without loss of information.
Add an is_ascii attribute for symbols
Add a check to see if Signal names need Quoting when saving to a .sym
file (if they start with a number or contain a space etc.)

Add a test which reads in a .sym file containing all signal types and
checks that they are all correctly imported and exported.

* Add fix for "isidentifier" fucntion on python 2.7

* Fix logic to match variable name. (Functionality unchanged)

Co-authored-by: Eduard Bröcker <[email protected]>

* Fix sym.dump to export the value_table into the {ENUMS} field of the (#481)

.sym file.
Refactor to remove the use of global variables "enum_dict" and "enums"

Add a test which checks that enums in the original .sym file and enums
which appear as values on a signal are exported to the .sym file.

* Accept types which are in the value table as enum sgnals (#482)

* Fix additional case in sym enum export (#486)

* Accept types which are in the value table as enum sgnals

* Fix previous change to also generate enums from the signal values field
when signal is in a multiplexed frame.

* [DBF] support j1939 read (#501)

Co-authored-by: Broecker <[email protected]>

* possible fix for #490 (#503)

* add tests for issue #424 (#500)

add tests for Motorola forward MSB and Motorola forward LSB start_bit

* Iss484 (#502)

* [arxml] add some basic support for flexray and ethernet data

* extract most of relevant flexray info (#432)

not yet integraded - only extracted by now

* prove of concept for flexray dump (#432)

* starting rework ARXML

* add xlsxwriter to test deps

* add pyyaml to test-reqs

* Update requirements.test.py3.txt

* fix so that tests work again

* remove py3.4 add py3.8

* disable py34 test - enable py38 test

* disable py34

* remove py3.4

* remove py8 warnings

* fix dbc for py8

* fix for #484

buggy ARXMLs with no System-Signals referenced

* fix ci

* fix ci (#504)

* fix ci

* Iss492 (#505)

* integrate fix from #492

* Arxml read baudrate (#452)

* Read Baudrate from arxml

* Enable reading hex values with prefix 0x

* Adaption to pass test with string speed values

* Update to read in hex values define with 0x and integers e.g. 0

* Removal of commented line

* Explicit conversion to string for logger output

Co-authored-by: ForestRupicolous <>
Co-authored-by: Eduard Bröcker <[email protected]>

* Iss496 (#506)

* #496 fix ignore encoding switch

* Iss499 (#507)

* fixes #499

decode_number now supports floating point value

* [WIP] [arxml] add some basic support for flexray and ethernet data (#426)

* [arxml] add some basic support for flexray and ethernet data
* extract most of relevant flexray info (#432)
* starting rework ARXML
* fix dbc for py8
* support for container-pdus with "none" type
* fix for container id byteorder
* fix for secured-ipdus in container
* fix for byteorder big endian header_ids of container-i-pdus
* once again header_id
* Header_id again
* fix for missing compu method
* make SOME/IP at least work a bixt #283
* interprete OPAQUE as intel
* dbc allow '"' in Values
* fix container-pdu without header but with offset
* arxml: fix for container-ipdus, containing same pdu multiple times
* fix enum support for py2.7

* Iss509 (#510)  dbf fix for exporting empty matrix

* dbf fix for exporting empty matrix

* Iss496 (#511)

* #496 fix ignore encoding switch
* clean encoding error implementation

* Master (#514)

* remegerge release (#512)

* Fix sym mux decode, by always treating mux field as unsigned (#517)

* Add a test to show that sym file mux values arent working

* Add a fix to always treat MUX values as unsigned signals

* Log as warning instead of exception (#519)

Logging as exception prints a stack backtrace. Since the modules are optional
and listed as extra instead of a required dependency, this should probably be
a warning instead of an error/exception.

Co-authored-by: Lennart Moltrecht <[email protected]>

* src/canmatrix.py: fix nested mux with no values (#527)

If a complexly multiplexed signal has a sub-multiplexer with no values, a TypeError is thrown.

* add is_fd flag for json output (#532)

Co-authored-by: Dennis Röck <[email protected]>

* Iss526 (#536)

* fix ci

* fix ci

* fixes #526

* fix for #526escaped quotes

* #526 use raw strings for test

* Bump lxml from 4.5.2 to 4.6.2 (#539)

Bumps [lxml](https://github.com/lxml/lxml) from 4.5.2 to 4.6.2.
- [Release notes](https://github.com/lxml/lxml/releases)
- [Changelog](https://github.com/lxml/lxml/blob/master/CHANGES.txt)
- [Commits](lxml/lxml@lxml-4.5.2...lxml-4.6.2)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Iss535 (#537)

* fix ci
* possible fix for issue #535

* Iss522 (#530)


* arxml: add reciever information from signals to frames  (issue #522)

* Fix ci (#542)

* fix dbc testcase
* remove xlsx read from tests (#541)

* basic ldf import

* update requirements for ldfparser

* first implementation for odx import#544

* start diag frame at byte 1

* odx service muxer

* odx zwischenstand

* issue #531 Lin Converters

add support for LIN-Converters

* odx zwischnstand

* Revert "odx zwischnstand"

This reverts commit f4476de.

* Update xls.py (#549)

Thanks!

* add direct decode function for python can frames (#548)

* better mux export hanling in sym

* Correctly the result if compare two frame with different ID (#552)

When comparing two dbc, the the frame has different ID it should be marked as "changed" frame.

* Overall code improvements (#555)

* fix: use six.moves instead of future.moves to fix annoying import of top level modules

* fix: missing future import + clean up dependencies

* fix: __package__ does not exist in Python 2.7

* fix: string decoding issue in Python 2.7

* update tox.ini

* fix: install all extras in tox.init

* update travis and appveyor config

* remove unused requirements files

* update tox.ini

* remove unwanted line in test.sh

* fix: Python version 3.9 not available in AppVeyor yet

* fix: only keep minimum requirements for test

* improvement dbc to dbf (#556)

temporary hot fix for canconvert dbc to dbf

* fix issue #547 (#560)

DeprecationWarning: The usage of `cmp` is deprecated and will be removed
on or after 2021-06-01.  Please use `eq` and `order` instead.
    @attr.s(cmp=False)

Signed-off-by: An Nguyen <[email protected]>

* fix issue #559 (#561)

Signed-off-by: An Nguyen <[email protected]>

* fix initial value setting (#566)

Thanks
Co-authored-by: JAZI Nadhmi <[email protected]>

* Set initial_value to physical value (#567)

Currently the initial_value is incorrectly set to the signal raw value.

* arxml fix (#564)

Co-authored-by: Eduard Bröcker <[email protected]>

* arxml.py: (#569)

optimize find/findall
    fix ECU transmitter/receivers for clusters
    rework signals receiers settings

Co-authored-by: JAZI Nadhmi <[email protected]>

* [arxml]: Use ISignal Name for canmatrix.Signal (#570)

Add attributes to  Signal for other names

Co-authored-by: JAZI Nadhmi <[email protected]>

* ARXML Replace ArTree with more simple cache

add option to rename Signal from Signal-Attribute

* add/update doc

* Arxml refactoring (#571)

* ARXML Replace ArTree with more simple cache
* add option to rename Signal from Signal-Attribute
* add/update doc

* rework arxml parsing and use Pdu for PDU contained frames (#576)

Add a converter from PDU contained to multiplexed frame
Add option to handle it in the CLI
Update decoder function

Co-authored-by: JAZI Nadhmi <[email protected]>

* fix convert pdu container (#577)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Remove prints from the code and add the message to the exception (#578)

* remove duplicated pdus (#583)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Improve multiplexer JSON output (#585)

Co-authored-by: Edward Pierzchalski <[email protected]>

* Fix typo (#586)

* bugfix: to get the signals for a pdu you have to use follow_all_ref instead of follow_ref (#591)

Co-authored-by: Markus Konrad <[email protected]>

* improve logging output to be able to identify problems faster/better (#592)

Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>

* fix for issue #596 (#597)

cope with signals without receiver

Co-authored-by: Eduard Bröcker <[email protected]>

* fix for #403

* arxml init value may not decoded

just ignore #550

* fixes #572

* arxml helpers

* Added option calcSignalMax & recalcSignalMax to calculate max value during converting dbc

* Fixed a wrong keypress mistake

* Removed float conversion before checking if the signal max is zero

* fix PDU container decoding (#605)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Kankan patch1 (#604)

* Added option calcSignalMax & recalcSignalMax to calculate max value during converting dbc

* Fixed a wrong keypress mistake

* Removed float conversion before checking if the signal max is zero

* fix tox and continuous integration (#609)

* Fixing Issue#610 :: Custom Signal Attributes are removed due to wrong indent

* Kankan patch :: Custom Signal Attributes are removed  (#611)


* Fix #610 :: Custom Signal Attributes are removed due to wrong indent

* #612 Bugfix formats.xls and formats.xlsx missing method parameters (#613)

* Update guess_value method in utils.py (#615)

add a conversion of 0b and 0x string values into int string representation in the guess_value method

initial motivation was to get valid input values for the decimal.Decimal() class
since it crashed in the arxml.py file line 1234:

1232            if initvalue is not None and initvalue.text is not None:
1233                initvalue.text = canmatrix.utils.guess_value(initvalue.text)
1234               new_signal.initial_value = float_factory(initvalue.text)

* Added deleteFloatingSignals , checkFloatingFrames, checkSignalRange, checkSignalUnit, checkSignalReceiver & checkFloatingSignals

* Added J1939 to Extended dbc and vice versa

* feat: add support for Python 3.10 (#619)

* feat: add support for Python 3.10
* chore: fix appveyor configuration
* chore: remove useless commands in appveyor configuration
* chore: Python 3.9 and 3.10 only available for Visual Studio 2019 and up in appveyor

* arxml: read data related to E2E-protection (#594)

* read informations about E2E-Profiles (of I-Signalgroup) into the canmatrix-object
* also read informations about E2E-Profiles (of I-Signalgroup) into the canmatrix-object if a Container-PDU is processed

Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>

Co-authored-by: Daniel Hrisca <[email protected]>
Co-authored-by: Funth0mas <[email protected]>
Co-authored-by: Thomas Fritzsche <[email protected]>
Co-authored-by: chrisoro <[email protected]>
Co-authored-by: Bröcker <[email protected]>
Co-authored-by: Kyle Altendorf <[email protected]>
Co-authored-by: akaanich-technica <[email protected]>
Co-authored-by: Syed <[email protected]>
Co-authored-by: Seneda <[email protected]>
Co-authored-by: Ulf Rüegg <[email protected]>
Co-authored-by: Broecker <[email protected]>
Co-authored-by: Martin Korinek <[email protected]>
Co-authored-by: Leo <[email protected]>
Co-authored-by: Lennart Moltrecht <[email protected]>
Co-authored-by: Ryan Rowe <[email protected]>
Co-authored-by: Dennis <[email protected]>
Co-authored-by: Dennis Röck <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cesare12 <[email protected]>
Co-authored-by: Moris Yun <[email protected]>
Co-authored-by: Darkin <[email protected]>
Co-authored-by: jazi007 <[email protected]>
Co-authored-by: pierreluctg <[email protected]>
Co-authored-by: L X <[email protected]>
Co-authored-by: JAZI Nadhmi <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Ajinkya Pasalkar <[email protected]>
Co-authored-by: tainnok <[email protected]>
Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>
Co-authored-by: Kankan Sarkar <[email protected]>
Co-authored-by: Arcola-Kankan <[email protected]>
Co-authored-by: AlexDLSy <[email protected]>
Co-authored-by: tobiasandorfer <[email protected]>
ebroecker added a commit that referenced this issue Jan 11, 2022
* include LICENSE in source distribution (#365)

* arxml: rx/tx typo fix 

fix for #366

* annotate and fix codestyle dbc (#369)

* Always use Signal.is_little_endian as bool #326 (#371)

* Add coding, remove #!python where inappropriate (#370)

* annotation cleanup ticket #323 (#372)

* Update cli doc (inspired by #361) (#373)

* fix: xls is using the wrong number for arbitration id (#377)

* add outputformat for Scapy (#378)

* add output format for scapy
* fix special char handling in scapy exporter
* add unit test
simplify get_fmt

* Dump factor, offset, min, max as float. Load as numeric (#380)

* Dump factor, offset, min, max as float. Load as numeric

* fixed tests

* fixed tests

* added --jsonNativeTypes as cli option

* review remarks

* ARXML: merge container PDU and Secured PDU support  (#384)

* #381 support for containers
* #381 create signalgroups for containers
* #382 support secured pdus) (#383)
* add unittests for #363 and #382

* Iss381 - fix for #381 - wrong default ArbitrationId handling (#386)

* fix for #381 wrong default ArbitrationId handling

* support for Scapy input file (#387)

* add output format for scapy

* optional ignoring failures durig character encoding #375 (#388)

* fix for #238 (j1939 Frame setters might raise TypeError) (#389)

move j1939 (pgn, prio, source) handling direct to arbitration-id class
(fixes #238)

* Iss385 // Arxml Container support and ARXML refactoring (#390)

ARXML updates:
* fix for #385 
* json fix multiplex reading issue (#136)
* ARXML refactoring, DLC for canFD support canmatrix.Frame.fit_dlc now
fits to next correct dlc value, DBC export reniced for candb++ (#385)
* add test for fit_dlc
* arxml refactoring and better type handling #368
* improvement for #242

* DBC: fix #242. J1939 and FD Frames in dbc

candb seems to be queasy about the order of the VFrameFormat attribute
definition. This Patch seems to generate a dbc, which can contain can_fd
AND J1939-frames.

* XLSX fixes  (#392)

XLSX: fixes #240 (signal init value in excel template)
XLSX: fixes #367 (2.)

* fix for #288 (#393)

* switch from optparse to click (#236) (#394)

* [WIP] add Basic cli tests (#395)

* add tests for global, manipulation and filter swithces of cli.convert
* add basic cli test for cli.compare

* fix some bugs, which were found by these tests

* Annotation cleanup #323 (#396)

* Remove cm prefix (#236) (#399)

Thanks

* add muxing support to scapy output; merge PR #398 also (#400)

* [try to] Unify imports (#402)

* unify imports (#236)

* [WIP] dump/export wireshark lua can subdissector (#404)

* add basic wireshark dissector creator
creastes lua script for dissecting can messages

* add cannelloni dissector for wireshark

* add some doc for scapy and wireshark usage

* [WIP] cycle_time as generic signal and frame attribute  (#405)

* implement cycle_time as generic signal and frame attribute / remove
Gen[Msg/Sig]cycle from attributes  #146
* use effective frame cycle time for export
use gcd of singnal-cycletimes for calculating effective cycle time

This removes one (of many) dbc specific parts from canmatrix and other formats

* Iss407: [dbc] Signal Comments with space bevore semicolon broken import (#409)

* fix for issue #407 [dbc] Signal Comments with space bevore semicolon broken import

* make initial value to a native attribute of Signal class (#408)

* make initial value to a native attribute of Signal class

* [dbf] exended ids corrected

* optionally allow multiple singals with same name in frame #411 (#412)

* Fix setup.py for console_scripts (#417)

* [WIP] [dbc] Iss413: fix comment reading with whitespaces in front of ; (#416)

* optionally allow multiple singals with same name in frame #411
* fixes #413 (space before semicolon mulit line comment)
* fix for iss #414, keeps defines in dbc: this keeps defines from dbc in matrix object, even if
native attribute exists.

* convert: selective rx/tx ecu extraction issue #421 (#422)

* [WIP] [ARXML] can_fd info (potentional fix for #410) (#418)

* potentional fix for #410
* [ARXML] can-fd recogintion
* add baudrate attributes

* [WIP] Auto deploy (#420)

* add auto deploy for tags on master

* add submodules doc

* update doc to make start_bit more clear in documentation #424

* [dbc] fix dbc issues (#431)

* fix dbc export for empty matrix
* copy_frame handles default values now (fix #430)

* fix copy_frame

* fix for issue #436 (#439)

* [convert] add delete_obsolete_ecus (fix for #434) (#438)

* [copy] Iss430 better attribute handling  (#437)

* handling missing default values for defines
* add ecu attribute handling #430

* fix for #441 (#442)

* fix for #441 jsonAll export option working again

* make old test less loud

* Fix some bugs in FIBEX export (#445)

* Fix FIBEX convertion, Handle duplicate signal name

* Repair more click convert parameters (#451)

* Repair command line param names for csv, json, xls(x)

* update tests

* use last supported colorama for pypy3.4

* Fixing issue where we see dictionary attributes change during iteration (#455)

* Arxml limits number formats (#457)

* add number decoding in arxml for different basis
* fix #454

* fix for #460

* fix #460

* Update cli.rst

add arxmlExportVersion documentation  (#461)

* Check for EOF when parsing enums in a .sym file. Fixes #465 (#468)

* Check for EOF when parsing enums in a .sym file. Fixes #465

* Fix test to check for different exception in the python2.7 case

* Log the exception as well when importing a format failed (#467)

* Process the .sym file "Title" field. fixes #469 And Fix Enum dictionary comma splitting  (#470)

* Implement processing of the Title property of .sym files.
* Fix CanMatrix.attribute to return default as documented
* Set the default for the "Title" attribute properly
* Reimplement the quote_aware_comma_split function to handle spaces
between fields
* Change the sym parser to use quote_aware_comma_split to split enum value
tables. Fixes #462.
Add test cases to show that enums are read in correctly from .sym files

* fix for #471 (#473)

* Fix J1939 PGN getter/setter to use full 18bits. Fixes #474 (#475)

* Fix J1939 PGN getter/setter to use full 18bits. Fixes #474

Remove the criteria that PF must be >= 240 for PS field to be set as
this seems to be incorrect. (It may be that for some specific case the
PS need to not be used, but it isn't documented here and in general the
PGN should be all 18 bits)
Modifed Tests:

test_canmatrix_get_frame_by_pgn()
seemed to be using made up data and didn't accound for the DP and EDP
fields in expected PGN

test_canid_repr()
Modified the expected repr value to include the PS field in the PGN.

test_canid_parse_values()
Modified expected PGN to include the PS field, Moved the list of
test_data into parametrized cases on a new test.

New Tests:

test_frame_j1939_id_from_components()
Tests constructing a full 29-bit CAN ID from the Priority, Source, and
PGN

test_frame_decode_j1939_id()
Tests extracting Priority Source and PGN from an Arbiration ID

* Add the global desistantion Address 0xFF to the BAM arbitration IDs

* Improve the fix, to more explicitly handle the difference between
PDU-Format 1 and PDU-Format 2, (where the PF >= 240 comes in).
The PGN setter now will now set the arbitration ID to contain the
destination address, but when the PGN getter is used it will strip the
destination field off. I think that it is unlikely for the PGN setter
to be used with PDU-F1 PGN containing a destination. But in the case
that it is I think it makes more sense to not throw the destination
address field away.

* Add enumberations as a field to the json file to store the value tables (#476)

Add a test to check that if a json file is read containing enums and
then saved and re-read it get the same enum table

* Adding changes to allow ArbitrationId classes to be sorted (#466)

* Adding comparators to ArbitrationId
* Changing default Arbitration ID extended to False
* Review based changes
Co-authored-by: Syed Raza <[email protected]>

* Parse sym types (#479)

* Allow parsing of the main .sym signal types : string, raw, char.
Add a type_label attribute so that symbol files can be saved back to
.sym format without loss of information.
Add an is_ascii attribute for symbols
Add a check to see if Signal names need Quoting when saving to a .sym
file (if they start with a number or contain a space etc.)

Add a test which reads in a .sym file containing all signal types and
checks that they are all correctly imported and exported.

* Allow parsing of the main .sym signal types : string, raw, char.
Add a type_label attribute so that symbol files can be saved back to
.sym format without loss of information.
Add an is_ascii attribute for symbols
Add a check to see if Signal names need Quoting when saving to a .sym
file (if they start with a number or contain a space etc.)

Add a test which reads in a .sym file containing all signal types and
checks that they are all correctly imported and exported.

* Add fix for "isidentifier" fucntion on python 2.7

* Fix logic to match variable name. (Functionality unchanged)

Co-authored-by: Eduard Bröcker <[email protected]>

* Fix sym.dump to export the value_table into the {ENUMS} field of the (#481)

.sym file.
Refactor to remove the use of global variables "enum_dict" and "enums"

Add a test which checks that enums in the original .sym file and enums
which appear as values on a signal are exported to the .sym file.

* Accept types which are in the value table as enum sgnals (#482)

* Fix additional case in sym enum export (#486)

* Accept types which are in the value table as enum sgnals

* Fix previous change to also generate enums from the signal values field
when signal is in a multiplexed frame.

* [DBF] support j1939 read (#501)

Co-authored-by: Broecker <[email protected]>

* possible fix for #490 (#503)

* add tests for issue #424 (#500)

add tests for Motorola forward MSB and Motorola forward LSB start_bit

* Iss484 (#502)

* [arxml] add some basic support for flexray and ethernet data

* extract most of relevant flexray info (#432)

not yet integraded - only extracted by now

* prove of concept for flexray dump (#432)

* starting rework ARXML

* add xlsxwriter to test deps

* add pyyaml to test-reqs

* Update requirements.test.py3.txt

* fix so that tests work again

* remove py3.4 add py3.8

* disable py34 test - enable py38 test

* disable py34

* remove py3.4

* remove py8 warnings

* fix dbc for py8

* fix for #484

buggy ARXMLs with no System-Signals referenced

* fix ci

* fix ci (#504)

* fix ci

* Iss492 (#505)

* integrate fix from #492

* Arxml read baudrate (#452)

* Read Baudrate from arxml

* Enable reading hex values with prefix 0x

* Adaption to pass test with string speed values

* Update to read in hex values define with 0x and integers e.g. 0

* Removal of commented line

* Explicit conversion to string for logger output

Co-authored-by: ForestRupicolous <>
Co-authored-by: Eduard Bröcker <[email protected]>

* Iss496 (#506)

* #496 fix ignore encoding switch

* Iss499 (#507)

* fixes #499

decode_number now supports floating point value

* [WIP] [arxml] add some basic support for flexray and ethernet data (#426)

* [arxml] add some basic support for flexray and ethernet data
* extract most of relevant flexray info (#432)
* starting rework ARXML
* fix dbc for py8
* support for container-pdus with "none" type
* fix for container id byteorder
* fix for secured-ipdus in container
* fix for byteorder big endian header_ids of container-i-pdus
* once again header_id
* Header_id again
* fix for missing compu method
* make SOME/IP at least work a bixt #283
* interprete OPAQUE as intel
* dbc allow '"' in Values
* fix container-pdu without header but with offset
* arxml: fix for container-ipdus, containing same pdu multiple times
* fix enum support for py2.7

* Iss509 (#510)  dbf fix for exporting empty matrix

* dbf fix for exporting empty matrix

* Iss496 (#511)

* #496 fix ignore encoding switch
* clean encoding error implementation

* Master (#514)

* remegerge release (#512)

* Fix sym mux decode, by always treating mux field as unsigned (#517)

* Add a test to show that sym file mux values arent working

* Add a fix to always treat MUX values as unsigned signals

* Log as warning instead of exception (#519)

Logging as exception prints a stack backtrace. Since the modules are optional
and listed as extra instead of a required dependency, this should probably be
a warning instead of an error/exception.

Co-authored-by: Lennart Moltrecht <[email protected]>

* src/canmatrix.py: fix nested mux with no values (#527)

If a complexly multiplexed signal has a sub-multiplexer with no values, a TypeError is thrown.

* add is_fd flag for json output (#532)

Co-authored-by: Dennis Röck <[email protected]>

* Iss526 (#536)

* fix ci

* fix ci

* fixes #526

* fix for #526escaped quotes

* #526 use raw strings for test

* Bump lxml from 4.5.2 to 4.6.2 (#539)

Bumps [lxml](https://github.com/lxml/lxml) from 4.5.2 to 4.6.2.
- [Release notes](https://github.com/lxml/lxml/releases)
- [Changelog](https://github.com/lxml/lxml/blob/master/CHANGES.txt)
- [Commits](lxml/lxml@lxml-4.5.2...lxml-4.6.2)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Iss535 (#537)

* fix ci
* possible fix for issue #535

* Iss522 (#530)


* arxml: add reciever information from signals to frames  (issue #522)

* Fix ci (#542)

* fix dbc testcase
* remove xlsx read from tests (#541)

* basic ldf import

* update requirements for ldfparser

* first implementation for odx import#544

* start diag frame at byte 1

* odx service muxer

* odx zwischenstand

* issue #531 Lin Converters

add support for LIN-Converters

* odx zwischnstand

* Revert "odx zwischnstand"

This reverts commit f4476de.

* Update xls.py (#549)

Thanks!

* add direct decode function for python can frames (#548)

* better mux export hanling in sym

* Correctly the result if compare two frame with different ID (#552)

When comparing two dbc, the the frame has different ID it should be marked as "changed" frame.

* Overall code improvements (#555)

* fix: use six.moves instead of future.moves to fix annoying import of top level modules

* fix: missing future import + clean up dependencies

* fix: __package__ does not exist in Python 2.7

* fix: string decoding issue in Python 2.7

* update tox.ini

* fix: install all extras in tox.init

* update travis and appveyor config

* remove unused requirements files

* update tox.ini

* remove unwanted line in test.sh

* fix: Python version 3.9 not available in AppVeyor yet

* fix: only keep minimum requirements for test

* improvement dbc to dbf (#556)

temporary hot fix for canconvert dbc to dbf

* fix issue #547 (#560)

DeprecationWarning: The usage of `cmp` is deprecated and will be removed
on or after 2021-06-01.  Please use `eq` and `order` instead.
    @attr.s(cmp=False)

Signed-off-by: An Nguyen <[email protected]>

* fix issue #559 (#561)

Signed-off-by: An Nguyen <[email protected]>

* fix initial value setting (#566)

Thanks
Co-authored-by: JAZI Nadhmi <[email protected]>

* Set initial_value to physical value (#567)

Currently the initial_value is incorrectly set to the signal raw value.

* arxml fix (#564)

Co-authored-by: Eduard Bröcker <[email protected]>

* arxml.py: (#569)

optimize find/findall
    fix ECU transmitter/receivers for clusters
    rework signals receiers settings

Co-authored-by: JAZI Nadhmi <[email protected]>

* [arxml]: Use ISignal Name for canmatrix.Signal (#570)

Add attributes to  Signal for other names

Co-authored-by: JAZI Nadhmi <[email protected]>

* ARXML Replace ArTree with more simple cache

add option to rename Signal from Signal-Attribute

* add/update doc

* Arxml refactoring (#571)

* ARXML Replace ArTree with more simple cache
* add option to rename Signal from Signal-Attribute
* add/update doc

* rework arxml parsing and use Pdu for PDU contained frames (#576)

Add a converter from PDU contained to multiplexed frame
Add option to handle it in the CLI
Update decoder function

Co-authored-by: JAZI Nadhmi <[email protected]>

* fix convert pdu container (#577)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Remove prints from the code and add the message to the exception (#578)

* remove duplicated pdus (#583)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Improve multiplexer JSON output (#585)

Co-authored-by: Edward Pierzchalski <[email protected]>

* Fix typo (#586)

* bugfix: to get the signals for a pdu you have to use follow_all_ref instead of follow_ref (#591)

Co-authored-by: Markus Konrad <[email protected]>

* improve logging output to be able to identify problems faster/better (#592)

Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>

* fix for issue #596 (#597)

cope with signals without receiver

Co-authored-by: Eduard Bröcker <[email protected]>

* fix for #403

* arxml init value may not decoded

just ignore #550

* fixes #572

* arxml helpers

* Added option calcSignalMax & recalcSignalMax to calculate max value during converting dbc

* Fixed a wrong keypress mistake

* Removed float conversion before checking if the signal max is zero

* fix PDU container decoding (#605)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Kankan patch1 (#604)

* Added option calcSignalMax & recalcSignalMax to calculate max value during converting dbc

* Fixed a wrong keypress mistake

* Removed float conversion before checking if the signal max is zero

* fix tox and continuous integration (#609)

* Fixing Issue#610 :: Custom Signal Attributes are removed due to wrong indent

* Kankan patch :: Custom Signal Attributes are removed  (#611)


* Fix #610 :: Custom Signal Attributes are removed due to wrong indent

* #612 Bugfix formats.xls and formats.xlsx missing method parameters (#613)

* Update guess_value method in utils.py (#615)

add a conversion of 0b and 0x string values into int string representation in the guess_value method

initial motivation was to get valid input values for the decimal.Decimal() class
since it crashed in the arxml.py file line 1234:

1232            if initvalue is not None and initvalue.text is not None:
1233                initvalue.text = canmatrix.utils.guess_value(initvalue.text)
1234               new_signal.initial_value = float_factory(initvalue.text)

* Added deleteFloatingSignals , checkFloatingFrames, checkSignalRange, checkSignalUnit, checkSignalReceiver & checkFloatingSignals

* Added J1939 to Extended dbc and vice versa

* feat: add support for Python 3.10 (#619)

* feat: add support for Python 3.10
* chore: fix appveyor configuration
* chore: remove useless commands in appveyor configuration
* chore: Python 3.9 and 3.10 only available for Visual Studio 2019 and up in appveyor

* arxml: read data related to E2E-protection (#594)

* read informations about E2E-Profiles (of I-Signalgroup) into the canmatrix-object
* also read informations about E2E-Profiles (of I-Signalgroup) into the canmatrix-object if a Container-PDU is processed

Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>

Co-authored-by: Daniel Hrisca <[email protected]>
Co-authored-by: Funth0mas <[email protected]>
Co-authored-by: Thomas Fritzsche <[email protected]>
Co-authored-by: chrisoro <[email protected]>
Co-authored-by: Bröcker <[email protected]>
Co-authored-by: Kyle Altendorf <[email protected]>
Co-authored-by: akaanich-technica <[email protected]>
Co-authored-by: Syed <[email protected]>
Co-authored-by: Seneda <[email protected]>
Co-authored-by: Ulf Rüegg <[email protected]>
Co-authored-by: Broecker <[email protected]>
Co-authored-by: Martin Korinek <[email protected]>
Co-authored-by: Leo <[email protected]>
Co-authored-by: Lennart Moltrecht <[email protected]>
Co-authored-by: Ryan Rowe <[email protected]>
Co-authored-by: Dennis <[email protected]>
Co-authored-by: Dennis Röck <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cesare12 <[email protected]>
Co-authored-by: Moris Yun <[email protected]>
Co-authored-by: Darkin <[email protected]>
Co-authored-by: jazi007 <[email protected]>
Co-authored-by: pierreluctg <[email protected]>
Co-authored-by: L X <[email protected]>
Co-authored-by: JAZI Nadhmi <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Ajinkya Pasalkar <[email protected]>
Co-authored-by: tainnok <[email protected]>
Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>
Co-authored-by: Kankan Sarkar <[email protected]>
Co-authored-by: Arcola-Kankan <[email protected]>
Co-authored-by: AlexDLSy <[email protected]>
Co-authored-by: tobiasandorfer <[email protected]>

Co-authored-by: Daniel Hrisca <[email protected]>
Co-authored-by: Funth0mas <[email protected]>
Co-authored-by: Thomas Fritzsche <[email protected]>
Co-authored-by: chrisoro <[email protected]>
Co-authored-by: Bröcker <[email protected]>
Co-authored-by: Kyle Altendorf <[email protected]>
Co-authored-by: akaanich-technica <[email protected]>
Co-authored-by: Syed <[email protected]>
Co-authored-by: Seneda <[email protected]>
Co-authored-by: Ulf Rüegg <[email protected]>
Co-authored-by: Broecker <[email protected]>
Co-authored-by: Martin Korinek <[email protected]>
Co-authored-by: Leo <[email protected]>
Co-authored-by: Lennart Moltrecht <[email protected]>
Co-authored-by: Ryan Rowe <[email protected]>
Co-authored-by: Dennis <[email protected]>
Co-authored-by: Dennis Röck <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cesare12 <[email protected]>
Co-authored-by: Moris Yun <[email protected]>
Co-authored-by: Darkin <[email protected]>
Co-authored-by: jazi007 <[email protected]>
Co-authored-by: pierreluctg <[email protected]>
Co-authored-by: L X <[email protected]>
Co-authored-by: JAZI Nadhmi <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Ajinkya Pasalkar <[email protected]>
Co-authored-by: tainnok <[email protected]>
Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>
Co-authored-by: Kankan Sarkar <[email protected]>
Co-authored-by: Arcola-Kankan <[email protected]>
Co-authored-by: AlexDLSy <[email protected]>
Co-authored-by: tobiasandorfer <[email protected]>
ebroecker added a commit that referenced this issue Mar 23, 2022
* merge for release 0.9.4 (#621)

* include LICENSE in source distribution (#365)

* arxml: rx/tx typo fix 

fix for #366

* annotate and fix codestyle dbc (#369)

* Always use Signal.is_little_endian as bool #326 (#371)

* Add coding, remove #!python where inappropriate (#370)

* annotation cleanup ticket #323 (#372)

* Update cli doc (inspired by #361) (#373)

* fix: xls is using the wrong number for arbitration id (#377)

* add outputformat for Scapy (#378)

* add output format for scapy
* fix special char handling in scapy exporter
* add unit test
simplify get_fmt

* Dump factor, offset, min, max as float. Load as numeric (#380)

* Dump factor, offset, min, max as float. Load as numeric

* fixed tests

* fixed tests

* added --jsonNativeTypes as cli option

* review remarks

* ARXML: merge container PDU and Secured PDU support  (#384)

* #381 support for containers
* #381 create signalgroups for containers
* #382 support secured pdus) (#383)
* add unittests for #363 and #382

* Iss381 - fix for #381 - wrong default ArbitrationId handling (#386)

* fix for #381 wrong default ArbitrationId handling

* support for Scapy input file (#387)

* add output format for scapy

* optional ignoring failures durig character encoding #375 (#388)

* fix for #238 (j1939 Frame setters might raise TypeError) (#389)

move j1939 (pgn, prio, source) handling direct to arbitration-id class
(fixes #238)

* Iss385 // Arxml Container support and ARXML refactoring (#390)

ARXML updates:
* fix for #385 
* json fix multiplex reading issue (#136)
* ARXML refactoring, DLC for canFD support canmatrix.Frame.fit_dlc now
fits to next correct dlc value, DBC export reniced for candb++ (#385)
* add test for fit_dlc
* arxml refactoring and better type handling #368
* improvement for #242

* DBC: fix #242. J1939 and FD Frames in dbc

candb seems to be queasy about the order of the VFrameFormat attribute
definition. This Patch seems to generate a dbc, which can contain can_fd
AND J1939-frames.

* XLSX fixes  (#392)

XLSX: fixes #240 (signal init value in excel template)
XLSX: fixes #367 (2.)

* fix for #288 (#393)

* switch from optparse to click (#236) (#394)

* [WIP] add Basic cli tests (#395)

* add tests for global, manipulation and filter swithces of cli.convert
* add basic cli test for cli.compare

* fix some bugs, which were found by these tests

* Annotation cleanup #323 (#396)

* Remove cm prefix (#236) (#399)

Thanks

* add muxing support to scapy output; merge PR #398 also (#400)

* [try to] Unify imports (#402)

* unify imports (#236)

* [WIP] dump/export wireshark lua can subdissector (#404)

* add basic wireshark dissector creator
creastes lua script for dissecting can messages

* add cannelloni dissector for wireshark

* add some doc for scapy and wireshark usage

* [WIP] cycle_time as generic signal and frame attribute  (#405)

* implement cycle_time as generic signal and frame attribute / remove
Gen[Msg/Sig]cycle from attributes  #146
* use effective frame cycle time for export
use gcd of singnal-cycletimes for calculating effective cycle time

This removes one (of many) dbc specific parts from canmatrix and other formats

* Iss407: [dbc] Signal Comments with space bevore semicolon broken import (#409)

* fix for issue #407 [dbc] Signal Comments with space bevore semicolon broken import

* make initial value to a native attribute of Signal class (#408)

* make initial value to a native attribute of Signal class

* [dbf] exended ids corrected

* optionally allow multiple singals with same name in frame #411 (#412)

* Fix setup.py for console_scripts (#417)

* [WIP] [dbc] Iss413: fix comment reading with whitespaces in front of ; (#416)

* optionally allow multiple singals with same name in frame #411
* fixes #413 (space before semicolon mulit line comment)
* fix for iss #414, keeps defines in dbc: this keeps defines from dbc in matrix object, even if
native attribute exists.

* convert: selective rx/tx ecu extraction issue #421 (#422)

* [WIP] [ARXML] can_fd info (potentional fix for #410) (#418)

* potentional fix for #410
* [ARXML] can-fd recogintion
* add baudrate attributes

* [WIP] Auto deploy (#420)

* add auto deploy for tags on master

* add submodules doc

* update doc to make start_bit more clear in documentation #424

* [dbc] fix dbc issues (#431)

* fix dbc export for empty matrix
* copy_frame handles default values now (fix #430)

* fix copy_frame

* fix for issue #436 (#439)

* [convert] add delete_obsolete_ecus (fix for #434) (#438)

* [copy] Iss430 better attribute handling  (#437)

* handling missing default values for defines
* add ecu attribute handling #430

* fix for #441 (#442)

* fix for #441 jsonAll export option working again

* make old test less loud

* Fix some bugs in FIBEX export (#445)

* Fix FIBEX convertion, Handle duplicate signal name

* Repair more click convert parameters (#451)

* Repair command line param names for csv, json, xls(x)

* update tests

* use last supported colorama for pypy3.4

* Fixing issue where we see dictionary attributes change during iteration (#455)

* Arxml limits number formats (#457)

* add number decoding in arxml for different basis
* fix #454

* fix for #460

* fix #460

* Update cli.rst

add arxmlExportVersion documentation  (#461)

* Check for EOF when parsing enums in a .sym file. Fixes #465 (#468)

* Check for EOF when parsing enums in a .sym file. Fixes #465

* Fix test to check for different exception in the python2.7 case

* Log the exception as well when importing a format failed (#467)

* Process the .sym file "Title" field. fixes #469 And Fix Enum dictionary comma splitting  (#470)

* Implement processing of the Title property of .sym files.
* Fix CanMatrix.attribute to return default as documented
* Set the default for the "Title" attribute properly
* Reimplement the quote_aware_comma_split function to handle spaces
between fields
* Change the sym parser to use quote_aware_comma_split to split enum value
tables. Fixes #462.
Add test cases to show that enums are read in correctly from .sym files

* fix for #471 (#473)

* Fix J1939 PGN getter/setter to use full 18bits. Fixes #474 (#475)

* Fix J1939 PGN getter/setter to use full 18bits. Fixes #474

Remove the criteria that PF must be >= 240 for PS field to be set as
this seems to be incorrect. (It may be that for some specific case the
PS need to not be used, but it isn't documented here and in general the
PGN should be all 18 bits)
Modifed Tests:

test_canmatrix_get_frame_by_pgn()
seemed to be using made up data and didn't accound for the DP and EDP
fields in expected PGN

test_canid_repr()
Modified the expected repr value to include the PS field in the PGN.

test_canid_parse_values()
Modified expected PGN to include the PS field, Moved the list of
test_data into parametrized cases on a new test.

New Tests:

test_frame_j1939_id_from_components()
Tests constructing a full 29-bit CAN ID from the Priority, Source, and
PGN

test_frame_decode_j1939_id()
Tests extracting Priority Source and PGN from an Arbiration ID

* Add the global desistantion Address 0xFF to the BAM arbitration IDs

* Improve the fix, to more explicitly handle the difference between
PDU-Format 1 and PDU-Format 2, (where the PF >= 240 comes in).
The PGN setter now will now set the arbitration ID to contain the
destination address, but when the PGN getter is used it will strip the
destination field off. I think that it is unlikely for the PGN setter
to be used with PDU-F1 PGN containing a destination. But in the case
that it is I think it makes more sense to not throw the destination
address field away.

* Add enumberations as a field to the json file to store the value tables (#476)

Add a test to check that if a json file is read containing enums and
then saved and re-read it get the same enum table

* Adding changes to allow ArbitrationId classes to be sorted (#466)

* Adding comparators to ArbitrationId
* Changing default Arbitration ID extended to False
* Review based changes
Co-authored-by: Syed Raza <[email protected]>

* Parse sym types (#479)

* Allow parsing of the main .sym signal types : string, raw, char.
Add a type_label attribute so that symbol files can be saved back to
.sym format without loss of information.
Add an is_ascii attribute for symbols
Add a check to see if Signal names need Quoting when saving to a .sym
file (if they start with a number or contain a space etc.)

Add a test which reads in a .sym file containing all signal types and
checks that they are all correctly imported and exported.

* Allow parsing of the main .sym signal types : string, raw, char.
Add a type_label attribute so that symbol files can be saved back to
.sym format without loss of information.
Add an is_ascii attribute for symbols
Add a check to see if Signal names need Quoting when saving to a .sym
file (if they start with a number or contain a space etc.)

Add a test which reads in a .sym file containing all signal types and
checks that they are all correctly imported and exported.

* Add fix for "isidentifier" fucntion on python 2.7

* Fix logic to match variable name. (Functionality unchanged)

Co-authored-by: Eduard Bröcker <[email protected]>

* Fix sym.dump to export the value_table into the {ENUMS} field of the (#481)

.sym file.
Refactor to remove the use of global variables "enum_dict" and "enums"

Add a test which checks that enums in the original .sym file and enums
which appear as values on a signal are exported to the .sym file.

* Accept types which are in the value table as enum sgnals (#482)

* Fix additional case in sym enum export (#486)

* Accept types which are in the value table as enum sgnals

* Fix previous change to also generate enums from the signal values field
when signal is in a multiplexed frame.

* [DBF] support j1939 read (#501)

Co-authored-by: Broecker <[email protected]>

* possible fix for #490 (#503)

* add tests for issue #424 (#500)

add tests for Motorola forward MSB and Motorola forward LSB start_bit

* Iss484 (#502)

* [arxml] add some basic support for flexray and ethernet data

* extract most of relevant flexray info (#432)

not yet integraded - only extracted by now

* prove of concept for flexray dump (#432)

* starting rework ARXML

* add xlsxwriter to test deps

* add pyyaml to test-reqs

* Update requirements.test.py3.txt

* fix so that tests work again

* remove py3.4 add py3.8

* disable py34 test - enable py38 test

* disable py34

* remove py3.4

* remove py8 warnings

* fix dbc for py8

* fix for #484

buggy ARXMLs with no System-Signals referenced

* fix ci

* fix ci (#504)

* fix ci

* Iss492 (#505)

* integrate fix from #492

* Arxml read baudrate (#452)

* Read Baudrate from arxml

* Enable reading hex values with prefix 0x

* Adaption to pass test with string speed values

* Update to read in hex values define with 0x and integers e.g. 0

* Removal of commented line

* Explicit conversion to string for logger output

Co-authored-by: ForestRupicolous <>
Co-authored-by: Eduard Bröcker <[email protected]>

* Iss496 (#506)

* #496 fix ignore encoding switch

* Iss499 (#507)

* fixes #499

decode_number now supports floating point value

* [WIP] [arxml] add some basic support for flexray and ethernet data (#426)

* [arxml] add some basic support for flexray and ethernet data
* extract most of relevant flexray info (#432)
* starting rework ARXML
* fix dbc for py8
* support for container-pdus with "none" type
* fix for container id byteorder
* fix for secured-ipdus in container
* fix for byteorder big endian header_ids of container-i-pdus
* once again header_id
* Header_id again
* fix for missing compu method
* make SOME/IP at least work a bixt #283
* interprete OPAQUE as intel
* dbc allow '"' in Values
* fix container-pdu without header but with offset
* arxml: fix for container-ipdus, containing same pdu multiple times
* fix enum support for py2.7

* Iss509 (#510)  dbf fix for exporting empty matrix

* dbf fix for exporting empty matrix

* Iss496 (#511)

* #496 fix ignore encoding switch
* clean encoding error implementation

* Master (#514)

* remegerge release (#512)

* Fix sym mux decode, by always treating mux field as unsigned (#517)

* Add a test to show that sym file mux values arent working

* Add a fix to always treat MUX values as unsigned signals

* Log as warning instead of exception (#519)

Logging as exception prints a stack backtrace. Since the modules are optional
and listed as extra instead of a required dependency, this should probably be
a warning instead of an error/exception.

Co-authored-by: Lennart Moltrecht <[email protected]>

* src/canmatrix.py: fix nested mux with no values (#527)

If a complexly multiplexed signal has a sub-multiplexer with no values, a TypeError is thrown.

* add is_fd flag for json output (#532)

Co-authored-by: Dennis Röck <[email protected]>

* Iss526 (#536)

* fix ci

* fix ci

* fixes #526

* fix for #526escaped quotes

* #526 use raw strings for test

* Bump lxml from 4.5.2 to 4.6.2 (#539)

Bumps [lxml](https://github.com/lxml/lxml) from 4.5.2 to 4.6.2.
- [Release notes](https://github.com/lxml/lxml/releases)
- [Changelog](https://github.com/lxml/lxml/blob/master/CHANGES.txt)
- [Commits](lxml/lxml@lxml-4.5.2...lxml-4.6.2)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Iss535 (#537)

* fix ci
* possible fix for issue #535

* Iss522 (#530)


* arxml: add reciever information from signals to frames  (issue #522)

* Fix ci (#542)

* fix dbc testcase
* remove xlsx read from tests (#541)

* basic ldf import

* update requirements for ldfparser

* first implementation for odx import#544

* start diag frame at byte 1

* odx service muxer

* odx zwischenstand

* issue #531 Lin Converters

add support for LIN-Converters

* odx zwischnstand

* Revert "odx zwischnstand"

This reverts commit f4476de.

* Update xls.py (#549)

Thanks!

* add direct decode function for python can frames (#548)

* better mux export hanling in sym

* Correctly the result if compare two frame with different ID (#552)

When comparing two dbc, the the frame has different ID it should be marked as "changed" frame.

* Overall code improvements (#555)

* fix: use six.moves instead of future.moves to fix annoying import of top level modules

* fix: missing future import + clean up dependencies

* fix: __package__ does not exist in Python 2.7

* fix: string decoding issue in Python 2.7

* update tox.ini

* fix: install all extras in tox.init

* update travis and appveyor config

* remove unused requirements files

* update tox.ini

* remove unwanted line in test.sh

* fix: Python version 3.9 not available in AppVeyor yet

* fix: only keep minimum requirements for test

* improvement dbc to dbf (#556)

temporary hot fix for canconvert dbc to dbf

* fix issue #547 (#560)

DeprecationWarning: The usage of `cmp` is deprecated and will be removed
on or after 2021-06-01.  Please use `eq` and `order` instead.
    @attr.s(cmp=False)

Signed-off-by: An Nguyen <[email protected]>

* fix issue #559 (#561)

Signed-off-by: An Nguyen <[email protected]>

* fix initial value setting (#566)

Thanks
Co-authored-by: JAZI Nadhmi <[email protected]>

* Set initial_value to physical value (#567)

Currently the initial_value is incorrectly set to the signal raw value.

* arxml fix (#564)

Co-authored-by: Eduard Bröcker <[email protected]>

* arxml.py: (#569)

optimize find/findall
    fix ECU transmitter/receivers for clusters
    rework signals receiers settings

Co-authored-by: JAZI Nadhmi <[email protected]>

* [arxml]: Use ISignal Name for canmatrix.Signal (#570)

Add attributes to  Signal for other names

Co-authored-by: JAZI Nadhmi <[email protected]>

* ARXML Replace ArTree with more simple cache

add option to rename Signal from Signal-Attribute

* add/update doc

* Arxml refactoring (#571)

* ARXML Replace ArTree with more simple cache
* add option to rename Signal from Signal-Attribute
* add/update doc

* rework arxml parsing and use Pdu for PDU contained frames (#576)

Add a converter from PDU contained to multiplexed frame
Add option to handle it in the CLI
Update decoder function

Co-authored-by: JAZI Nadhmi <[email protected]>

* fix convert pdu container (#577)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Remove prints from the code and add the message to the exception (#578)

* remove duplicated pdus (#583)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Improve multiplexer JSON output (#585)

Co-authored-by: Edward Pierzchalski <[email protected]>

* Fix typo (#586)

* bugfix: to get the signals for a pdu you have to use follow_all_ref instead of follow_ref (#591)

Co-authored-by: Markus Konrad <[email protected]>

* improve logging output to be able to identify problems faster/better (#592)

Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>

* fix for issue #596 (#597)

cope with signals without receiver

Co-authored-by: Eduard Bröcker <[email protected]>

* fix for #403

* arxml init value may not decoded

just ignore #550

* fixes #572

* arxml helpers

* Added option calcSignalMax & recalcSignalMax to calculate max value during converting dbc

* Fixed a wrong keypress mistake

* Removed float conversion before checking if the signal max is zero

* fix PDU container decoding (#605)

Co-authored-by: JAZI Nadhmi <[email protected]>

* Kankan patch1 (#604)

* Added option calcSignalMax & recalcSignalMax to calculate max value during converting dbc

* Fixed a wrong keypress mistake

* Removed float conversion before checking if the signal max is zero

* fix tox and continuous integration (#609)

* Fixing Issue#610 :: Custom Signal Attributes are removed due to wrong indent

* Kankan patch :: Custom Signal Attributes are removed  (#611)


* Fix #610 :: Custom Signal Attributes are removed due to wrong indent

* #612 Bugfix formats.xls and formats.xlsx missing method parameters (#613)

* Update guess_value method in utils.py (#615)

add a conversion of 0b and 0x string values into int string representation in the guess_value method

initial motivation was to get valid input values for the decimal.Decimal() class
since it crashed in the arxml.py file line 1234:

1232            if initvalue is not None and initvalue.text is not None:
1233                initvalue.text = canmatrix.utils.guess_value(initvalue.text)
1234               new_signal.initial_value = float_factory(initvalue.text)

* Added deleteFloatingSignals , checkFloatingFrames, checkSignalRange, checkSignalUnit, checkSignalReceiver & checkFloatingSignals

* Added J1939 to Extended dbc and vice versa

* feat: add support for Python 3.10 (#619)

* feat: add support for Python 3.10
* chore: fix appveyor configuration
* chore: remove useless commands in appveyor configuration
* chore: Python 3.9 and 3.10 only available for Visual Studio 2019 and up in appveyor

* arxml: read data related to E2E-protection (#594)

* read informations about E2E-Profiles (of I-Signalgroup) into the canmatrix-object
* also read informations about E2E-Profiles (of I-Signalgroup) into the canmatrix-object if a Container-PDU is processed

Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>

Co-authored-by: Daniel Hrisca <[email protected]>
Co-authored-by: Funth0mas <[email protected]>
Co-authored-by: Thomas Fritzsche <[email protected]>
Co-authored-by: chrisoro <[email protected]>
Co-authored-by: Bröcker <[email protected]>
Co-authored-by: Kyle Altendorf <[email protected]>
Co-authored-by: akaanich-technica <[email protected]>
Co-authored-by: Syed <[email protected]>
Co-authored-by: Seneda <[email protected]>
Co-authored-by: Ulf Rüegg <[email protected]>
Co-authored-by: Broecker <[email protected]>
Co-authored-by: Martin Korinek <[email protected]>
Co-authored-by: Leo <[email protected]>
Co-authored-by: Lennart Moltrecht <[email protected]>
Co-authored-by: Ryan Rowe <[email protected]>
Co-authored-by: Dennis <[email protected]>
Co-authored-by: Dennis Röck <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cesare12 <[email protected]>
Co-authored-by: Moris Yun <[email protected]>
Co-authored-by: Darkin <[email protected]>
Co-authored-by: jazi007 <[email protected]>
Co-authored-by: pierreluctg <[email protected]>
Co-authored-by: L X <[email protected]>
Co-authored-by: JAZI Nadhmi <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Ajinkya Pasalkar <[email protected]>
Co-authored-by: tainnok <[email protected]>
Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>
Co-authored-by: Kankan Sarkar <[email protected]>
Co-authored-by: Arcola-Kankan <[email protected]>
Co-authored-by: AlexDLSy <[email protected]>
Co-authored-by: tobiasandorfer <[email protected]>

* add testcase for Issue #625

* bugfix for #625

* fix is vs. ==

* attributes are more often strings now

Co-authored-by: Daniel Hrisca <[email protected]>
Co-authored-by: Funth0mas <[email protected]>
Co-authored-by: Thomas Fritzsche <[email protected]>
Co-authored-by: chrisoro <[email protected]>
Co-authored-by: Bröcker <[email protected]>
Co-authored-by: Kyle Altendorf <[email protected]>
Co-authored-by: akaanich-technica <[email protected]>
Co-authored-by: Syed <[email protected]>
Co-authored-by: Seneda <[email protected]>
Co-authored-by: Ulf Rüegg <[email protected]>
Co-authored-by: Broecker <[email protected]>
Co-authored-by: Martin Korinek <[email protected]>
Co-authored-by: Leo <[email protected]>
Co-authored-by: Lennart Moltrecht <[email protected]>
Co-authored-by: Ryan Rowe <[email protected]>
Co-authored-by: Dennis <[email protected]>
Co-authored-by: Dennis Röck <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Cesare12 <[email protected]>
Co-authored-by: Moris Yun <[email protected]>
Co-authored-by: Darkin <[email protected]>
Co-authored-by: jazi007 <[email protected]>
Co-authored-by: pierreluctg <[email protected]>
Co-authored-by: L X <[email protected]>
Co-authored-by: JAZI Nadhmi <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Edward Pierzchalski <[email protected]>
Co-authored-by: Ajinkya Pasalkar <[email protected]>
Co-authored-by: tainnok <[email protected]>
Co-authored-by: Markus Konrad <[email protected]>
Co-authored-by: Eduard Bröcker <[email protected]>
Co-authored-by: Kankan Sarkar <[email protected]>
Co-authored-by: Arcola-Kankan <[email protected]>
Co-authored-by: AlexDLSy <[email protected]>
Co-authored-by: tobiasandorfer <[email protected]>
@ebroecker
Copy link
Owner

I'll close this issue, please open new issues for problems with current implementation

@MatinF
Copy link
Author

MatinF commented Dec 10, 2024

Hi Edward,

I would like to test this out to e.g. see if I can load attached LDF file and export it to DBC. I tried using below script, but I get this error. I tested with the latest release build of canmatrix:

C:\Users\marti\Downloads\LIN_LDF_EXAMPLE>python testy.py LIN_LDF_EXAMPLE.ldf test.dbc
ldf is not supported
xls is not supported
xlsx is not supported
Loading LDF file: LIN_LDF_EXAMPLE.ldf
Error during conversion: Failed to parse the LDF file.

Here is the script:

import canmatrix.formats
import sys

def convert_ldf_to_dbc(ldf_file: str, dbc_file: str):
    """
    Converts an LDF (LIN Description File) to a DBC (CAN Database File).
    
    Parameters:
        ldf_file (str): Path to the input LDF file.
        dbc_file (str): Path to the output DBC file.
    """
    try:
        # Load the LDF file
        print(f"Loading LDF file: {ldf_file}")
        matrix = canmatrix.formats.loadp(ldf_file)
        
        # Check if the loading was successful
        if matrix is None:
            raise ValueError("Failed to parse the LDF file.")
        
        print(f"Successfully loaded LDF file: {ldf_file}")
        
        # Export the matrix to a DBC file
        print(f"Exporting to DBC file: {dbc_file}")
        canmatrix.formats.dump(matrix, dbc_file)
        
        print(f"Successfully exported to DBC file: {dbc_file}")
    except Exception as e:
        print(f"Error during conversion: {e}")

if __name__ == "__main__":
    # Example usage: python convert_ldf_to_dbc.py input.ldf output.dbc
    if len(sys.argv) != 3:
        print("Usage: python convert_ldf_to_dbc.py <input_ldf_file> <output_dbc_file>")
        sys.exit(1)
    
    input_ldf = sys.argv[1]
    output_dbc = sys.argv[2]
    convert_ldf_to_dbc(input_ldf, output_dbc)

The file I am trying to load is attached. Any idea what the issue may be?

LIN_LDF_EXAMPLE.zip

@reymor
Copy link

reymor commented Dec 10, 2024

Hello @MatinF

I think that you need to install ldfparser package

@MatinF
Copy link
Author

MatinF commented Dec 10, 2024

Thanks - I tried installing ldfparser, but now I get this error:

C:\Users\marti\Downloads\LIN_LDF_EXAMPLE>python testy.py IBS_200X_P_24V.ldf test2.dbc
xls is not supported
xlsx is not supported
Loading LDF file: IBS_200X_P_24V.ldf
Successfully loaded LDF file: IBS_200X_P_24V.ldf
Exporting to DBC file: test2.dbc
Error during conversion: dump() missing 1 required positional argument: 'export_type'
```

@MatinF
Copy link
Author

MatinF commented Dec 10, 2024

I tried updating the dump() function to take a 3rd input, "dbc", which results in below:

C:\Users\marti\Downloads\LIN_LDF_EXAMPLE>python testy.py IBS_200X_P_24V.ldf test2.dbc
xls is not supported
xlsx is not supported
Loading LDF file: IBS_200X_P_24V.ldf
Successfully loaded LDF file: IBS_200X_P_24V.ldf
Exporting to DBC file: test2.dbc
Successfully exported to DBC file: test2.dbc

However, the file is not exported to the expected location that I provide. It seems to load correctly if I print the matrix object, so I guess the problem is related to my use of canmatrix.formats.dump.

@MatinF
Copy link
Author

MatinF commented Dec 10, 2024

Sorry, now I got it working after using dumpp instead of dump. I.e. the below script works as intended:

import canmatrix.formats
import sys

def convert_ldf_to_dbc(ldf_file: str, dbc_file: str):
    """
    Converts an LDF (LIN Description File) to a DBC (CAN Database File).
    
    Parameters:
        ldf_file (str): Path to the input LDF file.
        dbc_file (str): Path to the output DBC file.
    """
    try:
        # Load the LDF file
        print(f"Loading LDF file: {ldf_file}")
        matrix = canmatrix.formats.loadp(ldf_file)
        
        print("matrix",matrix)
        # Check if the loading was successful
        if matrix is None:
            raise ValueError("Failed to parse the LDF file.")
        
        print(f"Successfully loaded LDF file: {ldf_file}")
        
        # Export the matrix to a DBC file
        print(f"Exporting to DBC file: {dbc_file}")
        dbc = canmatrix.formats.dumpp(matrix, dbc_file, "dbc")
        
        print(f"Successfully exported to DBC file: {dbc_file}")
    except Exception as e:
        print(f"Error during conversion: {e}")

if __name__ == "__main__":
    # Example usage: python convert_ldf_to_dbc.py input.ldf output.dbc
    if len(sys.argv) != 3:
        print("Usage: python convert_ldf_to_dbc.py <input_ldf_file> <output_dbc_file>")
        sys.exit(1)
    
    input_ldf = sys.argv[1]
    output_dbc = sys.argv[2]
    convert_ldf_to_dbc(input_ldf, output_dbc)

One observation in this regard:

Some LIN signals like BatteryCurrent in the example file have multiple physical value ranges as per below in the MDF:

  Enc_BatteryCurrent {
    physical_value, 1, 66, 10, -1230, "Ampere" ;
    physical_value, 67, 4765, 0.1, -576.6, "Ampere" ;
    physical_value, 4766, 12765, 0.01, -147.66, "Ampere" ;
    physical_value, 12766, 52765, 0.001, -32.766, "Ampere" ;
    physical_value, 52766, 60765, 0.01, -507.66, "Ampere" ; 
    physical_value, 60766, 65465, 0.1, -5976.6, "Ampere" ;
    physical_value, 65466, 65532, 10, -654090, "Ampere" ;
    logical_value, 0, "IBatt_lowerlimit" ;
    logical_value, 65533, "IBatt_upperlimit" ;
    logical_value, 65534, "BatteryCurrent_Error" ;
    logical_value, 65535, "LIN_INIT" ;
  }

In the DBC file context, this could be handled via extended multiplexing as showcased below:

image

Would this be possible to introduce in the parsing of LDF files so that multiple physical value ranges get translated automatically into extended multiplexing ranges?

Currently it looks like the logic is to include the 'last' physical entry. This can be a starting point for the purpose of speeding up the creation of a DBC file - but it would make it non-usable for loading LDF files in e.g. the asammdf GUI for decoding LIN bus log files (as many LIN signals have multiple physical value ranges).

@reymor
Copy link

reymor commented Dec 10, 2024

I think that it is because there is no 1to1 conversion between dbc and ldf.

I understand that multiple entries for physical value is not something possible in dbc file format. However,

Would this be possible to introduce in the parsing of LDF files so that multiple physical value ranges get translated automatically into extended multiplexing ranges?

I think that it is possible

So, here let me understand what you mean:

  Enc_BatteryCurrent {
    physical_value, 1, 66, 10, -1230, "Ampere" ;
    physical_value, 67, 4765, 0.1, -576.6, "Ampere" ;
    physical_value, 4766, 12765, 0.01, -147.66, "Ampere" ;
    physical_value, 12766, 52765, 0.001, -32.766, "Ampere" ;
    physical_value, 52766, 60765, 0.01, -507.66, "Ampere" ;
    physical_value, 60766, 65465, 0.1, -5976.6, "Ampere" ;
    physical_value, 65466, 65532, 10, -654090, "Ampere" ;
    logical_value, 0, "IBatt_lowerlimit" ;
    logical_value, 65533, "IBatt_upperlimit" ;
    logical_value, 65534, "BatteryCurrent_Error" ;
    logical_value, 65535, "LIN_INIT" ;
  }

How do you use the extended multiplexing here?

@MatinF
Copy link
Author

MatinF commented Dec 11, 2024

I believe a 1:1 mapping can be achieved for most LIN signals, with the primary challenge being the cases where a single LIN signal has multiple physical value representations (as in the example I provided). My suggestion in this case would be to consider if this could be handled via extended multiplexing. I illustrate how this would work for the specific example of BatteryCurrent via the picture I shared from Kvaser's DBC editor. Here I use the 16 bits reflecting the BatteryCurrent range and I essentially use that as a multiplexor to modify the interpretation of the same 16 bit range for the purpose of calculating a BatteryCurrent1, BatteryCurrent2, ... signal. Essentially adding a suffix index for each unique physical_value entry of the signal.

The resulting DBC works as intended in the sense that it will correctly DBC decode the data using the scaling/offset specified for the range defined in the multiplexing.

Let me know if it makes more sense? I am not sure if it becomes too complex to create this form of conversion in canmatrix, though. Maybe a starting point could be that canmatrix is able to load the LDF and correctly map the various physical_value ranges correctly for the internal database object somehow - I am not sure if that is done currently. The hope would be to allow tools like the asammdf GUI to then properly load LDF files and use it for decoding MF4 files that contain LIN bus data out-the-box. If this could be achieved, it would to us be more relevant than e.g. being able to export a DBC equivalent format.

@MatinF
Copy link
Author

MatinF commented Dec 11, 2024

Looking at the internal format of the canmatrix database, I guess the fundamental issue is that - similar to DBC files - the internal format only expects a single scale/offset value per signal (although it is able to also incorporate the 'value table' provided by the logical values in the LDF). For example, the aforementioned BatteryCurrent signal seems to look as below in the internal format:

Frame(
    name="IBS_DataAcquisition",
    arbitration_id=ArbitrationId(
        id=33,
        extended=False
    ),
    size=8,
    transmitters=["IBS"],
    is_complex_multiplexed=False,
    is_fd=False,
    comment="",
    signals=[
        Signal(
            name="BatteryCurrent",
            start_bit=0,
            size=16,
            is_little_endian=True,
            is_signed=False,
            offset=-654090.0,
            factor=10.0,
            unit="Ampere",
            receivers=["SG"],
            comment=None,
            multiplex=None,
            mux_value=None,
            is_float=False,
            is_ascii=False,
            type_label="",
            enumeration=None,
            comments={},
            attributes={},
            values={
                0: "IBatt_lowerlimit",
                65533: "IBatt_upperlimit",
                65534: "BatteryCurrent_Error",
                65535: "LIN_INIT"
            },
            mux_val_grp=[],
            muxer_for_signal=None,
            calc_min_for_none=True,
            calc_max_for_none=True,
            cycle_time=0,
            initial_value=65535,
            min=65466,
            max=65532
        ),
        ...
    ]
)

As evident, the factor/offset corresponds to the last physical_value entry in the signal description of the LDF:

offset=-654090.0,
factor=10.0,

I guess that in order to properly resolve this, a rather fundamental structural change would be required in the canmatrix internal database format to handle multiple possible physical value entries per signal. One option might be to indeed leverage extended multiplexing as described above, as this seems to be supported by canmatrix from what I can tell. This would have the benefit that it would allow a direct export to DBC files as well. But it has the downside that a single signal, BatteryCurrent would have to be mapped to multiple signals, e.g. BatteryCurrent1, BatteryCurrent2, ... to reflect the full range of physical values described in the LDF.

Edit: For context, this is how the encoding section for the BatteryCurrent signal looks from the ldfparser library if I load the LDF and export the contents to JSON:

{
      "name": "Enc_BatteryCurrent",
      "values": [
        {
          "type": "physical",
          "min": 1,
          "max": 66,
          "scale": 10.0,
          "offset": -1230.0,
          "unit": "Ampere"
        },
        {
          "type": "physical",
          "min": 67,
          "max": 4765,
          "scale": 0.1,
          "offset": -576.6,
          "unit": "Ampere"
        },
        {
          "type": "physical",
          "min": 4766,
          "max": 12765,
          "scale": 0.01,
          "offset": -147.66,
          "unit": "Ampere"
        },
        {
          "type": "physical",
          "min": 12766,
          "max": 52765,
          "scale": 0.001,
          "offset": -32.766,
          "unit": "Ampere"
        },
        {
          "type": "physical",
          "min": 52766,
          "max": 60765,
          "scale": 0.01,
          "offset": -507.66,
          "unit": "Ampere"
        },
        {
          "type": "physical",
          "min": 60766,
          "max": 65465,
          "scale": 0.1,
          "offset": -5976.6,
          "unit": "Ampere"
        },
        {
          "type": "physical",
          "min": 65466,
          "max": 65532,
          "scale": 10.0,
          "offset": -654090.0,
          "unit": "Ampere"
        },
        {
          "type": "logical",
          "value": 0,
          "text": "IBatt_lowerlimit"
        },
        {
          "type": "logical",
          "value": 65533,
          "text": "IBatt_upperlimit"
        },
        {
          "type": "logical",
          "value": 65534,
          "text": "BatteryCurrent_Error"
        },
        {
          "type": "logical",
          "value": 65535,
          "text": "LIN_INIT"
        }
      ]
    },

@ebroecker would be interested in your view on this and the feasibility of introducing this aspect of the LDF format into the canmatrix database format.

@ebroecker ebroecker reopened this Dec 14, 2024
@ebroecker
Copy link
Owner

For now we have only valuetables (1:1 Value to Label mapping) and scaling with factor and offset.
Anyway in LDF but also in ARXML it is possible to have different scales for different ranges.

I think it could be the right thing to do to implement something that supports these more flexible raw to physical mappings.

@ebroecker
Copy link
Owner

I added a simple change ,

#823

feel free to discuss

@MatinF
Copy link
Author

MatinF commented Dec 18, 2024

Awesome Eduard, appreciate it! I think this would be a really useful addition to enable the decoding of LIN data in various tools with LDF files.

@danielhrisca If you get the chance to try and incorporate this in a dev build, I'd be happy to do some testing on our sample data to verify if this works as intended.

@MatinF
Copy link
Author

MatinF commented Jan 14, 2025

@ebroecker Will it be possible to merge this change into the master branch and release this as an update to the canmatrix repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants