Skip to content

Commit

Permalink
Iss 625 (#631)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
1 parent 57897b0 commit 116f7e7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
21 changes: 18 additions & 3 deletions src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ def add_attribute(self, attribute, value): # type (attribute: str, value: typin
:param str attribute: Attribute name
:param any value: Attribute value
"""
self.attributes[attribute] = value
try:
self.attributes[attribute] = str(value)
except UnicodeDecodeError:
self.attributes[attribute] = value
if type(self.attributes[attribute]) == str:
self.attributes[attribute] = self.attributes[attribute].strip()

def del_attribute(self, attribute):
if attribute in self.attributes:
Expand Down Expand Up @@ -282,7 +287,12 @@ def add_attribute(self, attribute, value):
:param str attribute: attribute name
:param value: attribute value
"""
self.attributes[attribute] = value
try:
self.attributes[attribute] = str(value)
except UnicodeDecodeError:
self.attributes[attribute] = value
if type(self.attributes[attribute]) == str:
self.attributes[attribute] = self.attributes[attribute].strip()

def del_attribute(self, attribute):
"""
Expand Down Expand Up @@ -1715,7 +1725,12 @@ def add_attribute(self, attribute, value): # type: (str, typing.Any) -> None
:param str attribute: attribute name
:param value: attribute value
"""
self.attributes[attribute] = value
try:
self.attributes[attribute] = str(value)
except UnicodeDecodeError:
self.attributes[attribute] = value
if type(self.attributes[attribute]) == str:
self.attributes[attribute] = self.attributes[attribute].strip()

def add_signal_defines(self, type, definition):
"""
Expand Down
6 changes: 3 additions & 3 deletions src/canmatrix/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ def convert(infile, out_file_name, **options): # type: (str, str, **str) -> Non
if options.get('checkSignalRange') is not None and options['checkSignalRange']:
for frame in db.frames:
for signal in frame.signals:
if (signal.phys2raw(signal.max) - signal.phys2raw(signal.min)) is 0:
if (signal.phys2raw(signal.max) - signal.phys2raw(signal.min)) == 0:
logger.warning("Invalid Min , Max value of %s", (frame.name+"::"+signal.name))

# Check for Signals without unit and Value table , the idea is to improve signal readability
if options.get('checkSignalUnit') is not None and options['checkSignalUnit']:
for frame in db.frames:
for signal in frame:
if signal.unit is "" and len(signal.values) == 0:
if signal.unit == "" and len(signal.values) == 0:
logger.warning("Please add value table for the signal %s or add appropriate Unit", (frame.name+"::"+signal.name))

# Convert dbc from J1939 to Extended format
Expand All @@ -317,7 +317,7 @@ def convert(infile, out_file_name, **options): # type: (str, str, **str) -> Non
if options.get('convertToJ1939') is not None and options['convertToJ1939']:
for frame in db.frames:
frame.is_j1939=True
db.add_attribute("ProtocolType","J1939")
db.add_attribute("ProtocolType", "J1939")

logger.info(name)
logger.info("%d Frames found" % (db.frames.__len__()))
Expand Down
2 changes: 1 addition & 1 deletion src/canmatrix/formats/dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def create_attribute_string(attribute, attribute_class, name, value, is_string):
# type: (str, str, str, typing.Any, bool) -> str
if is_string:
value = '"' + value + '"'
elif not value:
elif value is None:
value = '""'

attribute_string = 'BA_ "' + attribute + '" ' + attribute_class + ' ' + name + ' ' + str(value) + ';\n'
Expand Down
6 changes: 3 additions & 3 deletions src/canmatrix/tests/test_canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_decode_signal():
def test_ecu_find_attribute():
ecu = canmatrix.canmatrix.Ecu(name="Gateway")
ecu.add_attribute("attr1", 255)
assert ecu.attribute("attr1") == 255
assert ecu.attribute("attr1") == '255'


def test_ecu_no_attribute():
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_signal_find_mandatory_attribute(some_signal):

def test_signal_find_optional_attribute(some_signal):
some_signal.add_attribute("attr1", 255)
assert some_signal.attribute("attr1") == 255
assert some_signal.attribute("attr1") == '255'


def test_signal_no_attribute(some_signal):
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_signal_delete_wrong_attribute_doesnt_raise(some_signal):
def test_signal_spn(some_signal):
assert some_signal.spn is None
some_signal.add_attribute("SPN", 10)
assert some_signal.spn == 10
assert some_signal.spn == '10'


def test_signal_set_startbit():
Expand Down
2 changes: 1 addition & 1 deletion src/canmatrix/tests/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_copy_ecu_with_attributes():
assert len(matrix1.frames) == 1
assert len(matrix1.ecus) == 1
assert matrix1.ecu_by_name("ECU") is not None
assert matrix1.ecu_by_name("ECU").attribute("Node Address") == 42
assert matrix1.ecu_by_name("ECU").attribute("Node Address") == '42'
assert matrix1.ecu_by_name("ECU").attribute("some_ecu_define", matrix1) == "default_value"

def test_copy_frame_default_attributes():
Expand Down
28 changes: 28 additions & 0 deletions src/canmatrix/tests/test_dbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,31 @@ def test_without_ecu():

matrix = canmatrix.formats.dbc.load(dbc, dbcImportEncoding="utf8")
matrix.frames[0].signals[0].name == "A_B_C_D_E"


def test_int_attribute_zero():
db = canmatrix.CanMatrix()
frame = canmatrix.Frame("some Frame")
frame.add_signal(canmatrix.Signal("signal_name", size=1, start_bit=1))
db.add_frame(frame)
db.add_ecu_defines("ecu_define", "INT 0 10")
db.add_ecu_defines("ecu_define2", "INT 0 10")
db.add_ecu_defines("ecu_define3", "INT 0 10")

db.add_frame_defines("test", "INT 0 10")
db.add_frame_defines("test2", "INT 0 10")
frame.add_attribute("test", 7)
frame.add_attribute("test2", 0)

ecu = canmatrix.Ecu('TestEcu')
ecu.add_attribute('ecu_define', 1)
ecu.add_attribute('ecu_define2', 0)

db.add_ecu(ecu)

outdbc = io.BytesIO()
canmatrix.formats.dump(db, outdbc, "dbc")
assert 'BO_ 0 7' in outdbc.getvalue().decode('utf8')
assert 'BO_ 0 0' in outdbc.getvalue().decode('utf8')
assert 'TestEcu 1' in outdbc.getvalue().decode('utf8')
assert 'TestEcu 0' in outdbc.getvalue().decode('utf8')

0 comments on commit 116f7e7

Please sign in to comment.