Skip to content

Commit 63405e4

Browse files
committed
fix first issue #667 (not second one!)
1 parent 92d8c38 commit 63405e4

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

Diff for: src/canmatrix/formats/arxml.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def fill_caches(self, start_element=None, ar_path=""):
7777

7878
def open(self, filename):
7979
self.tree = lxml.etree.parse(filename)
80-
8180
self.root = self.tree.getroot() # type: _Element
8281

8382
self.ns = "{" + self.tree.xpath('namespace-uri(.)') + "}" # type: str
@@ -1017,15 +1016,21 @@ def decode_compu_method(compu_method, ea, float_factory):
10171016
# keyword definition. 06Jun16
10181017
#####################################################################################################
10191018

1020-
if ll is not None and desc is not None and canmatrix.utils.decode_number(ul.text,
1019+
if len(desc) == 0:
1020+
vt = ea.get_sub_by_name(compu_scale, 'VT')
1021+
if vt is not None:
1022+
desc = vt.text
1023+
1024+
rational = ea.get_child(compu_scale, "COMPU-RATIONAL-COEFFS")
1025+
1026+
if rational is None and ll is not None and desc is not None and canmatrix.utils.decode_number(ul.text,
10211027
float_factory) == canmatrix.utils.decode_number(
10221028
ll.text, float_factory):
10231029
#####################################################################################################
10241030
#####################################################################################################
10251031
values[ll.text] = desc
10261032

10271033
# scale_desc = ea.get_element_desc(compu_scale)
1028-
rational = ea.get_child(compu_scale, "COMPU-RATIONAL-COEFFS")
10291034
if rational is not None:
10301035
numerator_parent = ea.get_child(rational, "COMPU-NUMERATOR")
10311036
numerator = ea.get_children(numerator_parent, "V")

Diff for: src/canmatrix/tests/ARXMLCompuMethod1.arxml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version='1.0' encoding='ASCII'?>
2+
<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">
3+
<AR-PACKAGE>
4+
<COMPU-METHOD>
5+
<SHORT-NAME>New_Frame_NewPDU_NewSignal_Encoding</SHORT-NAME>
6+
<CATEGORY>SCALE_LINEAR_AND_TEXTTABLE</CATEGORY>
7+
8+
<COMPU-INTERNAL-TO-PHYS>
9+
<COMPU-SCALES>
10+
<COMPU-SCALE>
11+
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
12+
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">0</UPPER-LIMIT>
13+
<COMPU-CONST>
14+
<VT>no trailer detected</VT>
15+
</COMPU-CONST>
16+
</COMPU-SCALE>
17+
<COMPU-SCALE>
18+
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">1</LOWER-LIMIT>
19+
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">1</UPPER-LIMIT>
20+
<COMPU-CONST>
21+
<VT>trailer detected</VT>
22+
</COMPU-CONST>
23+
</COMPU-SCALE>
24+
<COMPU-SCALE>
25+
<SHORT-LABEL>TrailerPresence</SHORT-LABEL>
26+
<LOWER-LIMIT INTERVAL-TYPE="CLOSED">0</LOWER-LIMIT>
27+
<UPPER-LIMIT INTERVAL-TYPE="CLOSED">0</UPPER-LIMIT>
28+
<COMPU-RATIONAL-COEFFS>
29+
<COMPU-NUMERATOR>
30+
<V>17</V>
31+
<V>42</V>
32+
</COMPU-NUMERATOR>
33+
<COMPU-DENOMINATOR>
34+
<V>1</V>
35+
</COMPU-DENOMINATOR>
36+
</COMPU-RATIONAL-COEFFS>
37+
</COMPU-SCALE>
38+
</COMPU-SCALES>
39+
</COMPU-INTERNAL-TO-PHYS>
40+
</COMPU-METHOD>
41+
</AR-PACKAGE>
42+
</AUTOSAR>

Diff for: src/canmatrix/tests/test_arxml.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,25 @@ def test_get_signals_from_container_i_pdu():
2727
assert matrix["New_CanCluster"].frames[0].pdus[0].signals[0].attributes["SysSignalName"] == 'PDU_Contained_1_Signal1_905db81da40081cb'
2828

2929

30-
3130
def test_get_signals_from_secured_pdu():
3231
here = Path(__file__).parent
3332
matrix = canmatrix.formats.arxml.load(str(here / "ARXMLSecuredPDUTest.arxml"))
3433
assert matrix["CAN"].frames[0].signals[0].name == 'someTestSignal'
3534
assert matrix["CAN"].frames[0].signals[1].name == 'Signal'
3635

36+
3737
def test_min_max():
3838
here = Path(__file__).parent
3939
matrix = canmatrix.formats.arxml.load(str(here / "ARXML_min_max.arxml"))
40-
assert matrix["New_CanCluster"].frames[0].signals[0].is_signed == False
40+
assert matrix["New_CanCluster"].frames[0].signals[0].is_signed is False
41+
42+
43+
def test_decode_compu_method_1():
44+
here = Path(__file__).parent
45+
ea = canmatrix.formats.arxml.Earxml()
46+
ea.open(str(here / "ARXMLCompuMethod1.arxml"))
47+
compu_method = ea.find("COMPU-METHOD")
48+
values, factor, offset, unit, const = canmatrix.formats.arxml.decode_compu_method(compu_method, ea, float)
49+
assert values == {'0': 'no trailer detected', '1': 'trailer detected'}
50+
assert factor == 42
51+
assert offset == 17

0 commit comments

Comments
 (0)