Skip to content

Commit

Permalink
fix first issue #667 (not second one!) (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebroecker authored Nov 21, 2022
1 parent 6f0042f commit 6f95b7a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/canmatrix/formats/arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1017,15 +1016,21 @@ 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):
#####################################################################################################
#####################################################################################################
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")
Expand Down
42 changes: 42 additions & 0 deletions src/canmatrix/tests/ARXMLCompuMethod1.arxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version='1.0' encoding='ASCII'?>
<AUTOSAR xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://autosar.org/3.2.3" xsi:schemaLocation="http://autosar.org/3.2.3 AUTOSAR_323.xsd">
<AR-PACKAGE>
<COMPU-METHOD>
<SHORT-NAME>New_Frame_NewPDU_NewSignal_Encoding</SHORT-NAME>
<CATEGORY>SCALE_LINEAR_AND_TEXTTABLE</CATEGORY>

<COMPU-INTERNAL-TO-PHYS>
<COMPU-SCALES>
<COMPU-SCALE>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">0</UPPER-LIMIT>
<COMPU-CONST>
<VT>no trailer detected</VT>
</COMPU-CONST>
</COMPU-SCALE>
<COMPU-SCALE>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">1</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">1</UPPER-LIMIT>
<COMPU-CONST>
<VT>trailer detected</VT>
</COMPU-CONST>
</COMPU-SCALE>
<COMPU-SCALE>
<SHORT-LABEL>TrailerPresence</SHORT-LABEL>
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">0</UPPER-LIMIT>
<COMPU-RATIONAL-COEFFS>
<COMPU-NUMERATOR>
<V>17</V>
<V>42</V>
</COMPU-NUMERATOR>
<COMPU-DENOMINATOR>
<V>1</V>
</COMPU-DENOMINATOR>
</COMPU-RATIONAL-COEFFS>
</COMPU-SCALE>
</COMPU-SCALES>
</COMPU-INTERNAL-TO-PHYS>
</COMPU-METHOD>
</AR-PACKAGE>
</AUTOSAR>
15 changes: 13 additions & 2 deletions src/canmatrix/tests/test_arxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6f95b7a

Please sign in to comment.