From 6f95b7a212eb07b5d7fef06d6e3e9374e4c83f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduard=20Br=C3=B6cker?= Date: Mon, 21 Nov 2022 21:30:11 +0100 Subject: [PATCH] fix first issue #667 (not second one!) (#668) --- src/canmatrix/formats/arxml.py | 11 ++++-- src/canmatrix/tests/ARXMLCompuMethod1.arxml | 42 +++++++++++++++++++++ src/canmatrix/tests/test_arxml.py | 15 +++++++- 3 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/canmatrix/tests/ARXMLCompuMethod1.arxml diff --git a/src/canmatrix/formats/arxml.py b/src/canmatrix/formats/arxml.py index 91c82cb7..a0764fc0 100644 --- a/src/canmatrix/formats/arxml.py +++ b/src/canmatrix/formats/arxml.py @@ -77,7 +77,6 @@ def fill_caches(self, start_element=None, ar_path=""): def open(self, filename): self.tree = lxml.etree.parse(filename) - self.root = self.tree.getroot() # type: _Element self.ns = "{" + self.tree.xpath('namespace-uri(.)') + "}" # type: str @@ -1017,7 +1016,14 @@ def decode_compu_method(compu_method, ea, float_factory): # keyword definition. 06Jun16 ##################################################################################################### - if ll is not None and desc is not None and canmatrix.utils.decode_number(ul.text, + if len(desc) == 0: + vt = ea.get_sub_by_name(compu_scale, 'VT') + if vt is not None: + desc = vt.text + + rational = ea.get_child(compu_scale, "COMPU-RATIONAL-COEFFS") + + if rational is None and ll is not None and desc is not None and canmatrix.utils.decode_number(ul.text, float_factory) == canmatrix.utils.decode_number( ll.text, float_factory): ##################################################################################################### @@ -1025,7 +1031,6 @@ def decode_compu_method(compu_method, ea, float_factory): values[ll.text] = desc # scale_desc = ea.get_element_desc(compu_scale) - rational = ea.get_child(compu_scale, "COMPU-RATIONAL-COEFFS") if rational is not None: numerator_parent = ea.get_child(rational, "COMPU-NUMERATOR") numerator = ea.get_children(numerator_parent, "V") diff --git a/src/canmatrix/tests/ARXMLCompuMethod1.arxml b/src/canmatrix/tests/ARXMLCompuMethod1.arxml new file mode 100644 index 00000000..dab5874e --- /dev/null +++ b/src/canmatrix/tests/ARXMLCompuMethod1.arxml @@ -0,0 +1,42 @@ + + + + + New_Frame_NewPDU_NewSignal_Encoding + SCALE_LINEAR_AND_TEXTTABLE + + + + + 0 + 0 + + no trailer detected + + + + 1 + 1 + + trailer detected + + + + TrailerPresence + 0 + 0 + + + 17 + 42 + + + 1 + + + + + + + + diff --git a/src/canmatrix/tests/test_arxml.py b/src/canmatrix/tests/test_arxml.py index 9ac336e7..b39c027b 100644 --- a/src/canmatrix/tests/test_arxml.py +++ b/src/canmatrix/tests/test_arxml.py @@ -27,14 +27,25 @@ def test_get_signals_from_container_i_pdu(): assert matrix["New_CanCluster"].frames[0].pdus[0].signals[0].attributes["SysSignalName"] == 'PDU_Contained_1_Signal1_905db81da40081cb' - def test_get_signals_from_secured_pdu(): here = Path(__file__).parent matrix = canmatrix.formats.arxml.load(str(here / "ARXMLSecuredPDUTest.arxml")) assert matrix["CAN"].frames[0].signals[0].name == 'someTestSignal' assert matrix["CAN"].frames[0].signals[1].name == 'Signal' + def test_min_max(): here = Path(__file__).parent matrix = canmatrix.formats.arxml.load(str(here / "ARXML_min_max.arxml")) - assert matrix["New_CanCluster"].frames[0].signals[0].is_signed == False + assert matrix["New_CanCluster"].frames[0].signals[0].is_signed is False + + +def test_decode_compu_method_1(): + here = Path(__file__).parent + ea = canmatrix.formats.arxml.Earxml() + ea.open(str(here / "ARXMLCompuMethod1.arxml")) + compu_method = ea.find("COMPU-METHOD") + values, factor, offset, unit, const = canmatrix.formats.arxml.decode_compu_method(compu_method, ea, float) + assert values == {'0': 'no trailer detected', '1': 'trailer detected'} + assert factor == 42 + assert offset == 17