Skip to content

Commit 3e115f8

Browse files
authored
Fibex container pdu (#717)
* fibex: support container pdus * fix arxml desc may be none (#711) * remove travis status * fix for #651 * Hope this fixes #650
1 parent 589f5fa commit 3e115f8

File tree

6 files changed

+102
-74
lines changed

6 files changed

+102
-74
lines changed

Diff for: README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
## **Canmatrix** is a python package to read and write several CAN (Controller Area Network) database formats. ##
22
[![PyPI](https://img.shields.io/pypi/v/canmatrix.svg)](https://pypi.org/project/canmatrix/)
33
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/canmatrix.svg)](https://pypi.org/project/canmatrix/)
4-
[![Build Status](https://travis-ci.org/ebroecker/canmatrix.svg?branch=development)](https://travis-ci.org/ebroecker/canmatrix)
54
[![Codecov branch](https://img.shields.io/codecov/c/github/ebroecker/canmatrix/development.svg)](https://codecov.io/gh/ebroecker/canmatrix/)
65
[![GitHub issues](https://img.shields.io/github/issues-raw/ebroecker/canmatrix.svg)](https://github.com/ebroecker/canmatrix/issues)
76

Diff for: docs/contents.rst

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
Canmatrix Documentation
2+
=======================
3+
14

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ def decode_compu_method(compu_method, ea, float_factory):
10311031
# keyword definition. 06Jun16
10321032
#####################################################################################################
10331033

1034-
if len(desc) == 0:
1034+
if desc is None or len(desc) == 0:
10351035
vt = ea.get_sub_by_name(compu_scale, 'VT')
10361036
if vt is not None:
10371037
desc = vt.text
@@ -1248,7 +1248,7 @@ def get_signals(signal_array, frame, ea, multiplex_id, float_factory, bit_offset
12481248

12491249
(is_signed, is_float) = eval_type_of_signal(type_encoding, base_type, ea)
12501250

1251-
unit_element = ea.get_child(isignal, "UNIT")
1251+
unit_element = ea.follow_ref(isignal, "UNIT-REF")
12521252
display_name = ea.get_child(unit_element, "DISPLAY-NAME")
12531253
if display_name is not None:
12541254
signal_unit = display_name.text

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

+97-66
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,78 @@ def selector(self, start_element, selector):
178178
return sorted(result_list, key=lambda element: element.sourceline)
179179

180180

181+
def get_signals_for_pdu(fe, pdu, overall_startbit = 0):
182+
signals = []
183+
ecus = []
184+
for signal_instance in fe.selector(pdu, "//SIGNAL-INSTANCE"):
185+
byte_order_element = fe.selector(signal_instance, "/IS-HIGH-LOW-BYTE-ORDER")
186+
if byte_order_element[0].text == "false":
187+
is_little_endian = True
188+
else:
189+
is_little_endian = False
190+
191+
start_bit = int(fe.selector(signal_instance, "/BIT-POSITION")[0].text, 0) + overall_startbit
192+
signal = fe.selector(signal_instance, ">SIGNAL-REF")[0]
193+
ecu_instance_refs = fe.selector(signal_instance, "<<ECU")
194+
receiver_ecus = []
195+
for ecu_instance_ref in ecu_instance_refs:
196+
if len(fe.selector(ecu_instance_ref, "^INPUT-PORT")) > 0:
197+
ecu_name = fe.sn(fe.get_referencable_parent(ecu_instance_ref))
198+
receiver_ecus.append(ecu_name)
199+
ecus.append(canmatrix.Ecu(name=ecu_name.strip()))
200+
201+
signal_name = fe.sn(signal)
202+
coding = fe.selector(signal, ">CODING-REF")[0]
203+
bit_length = int(fe.selector(coding, "/!BIT-LENGTH")[0].text)
204+
compu_methods = fe.selector(coding, "/!COMPU-METHOD")
205+
sig = canmatrix.Signal(name=signal_name)
206+
207+
for compu_method in compu_methods:
208+
category = fe.selector(compu_method, "/!CATEGORY")
209+
if len(category) > 0 and category[0].text == "LINEAR":
210+
numerator = fe.selector(compu_method, "/!COMPU-NUMERATOR")[0]
211+
denominator = fe.selector(compu_method, "/!COMPU-DENOMINATOR")[0]
212+
teiler = decimal.Decimal(fe.selector(denominator, "/!V")[0].text)
213+
[offset, factor] = [decimal.Decimal(a.text) for a in fe.selector(numerator, "/!V")]
214+
[offset, factor] = [a / teiler for a in [offset, factor]]
215+
sig.offset = offset
216+
sig.factor = factor
217+
try:
218+
sig.min = decimal.Decimal(fe.selector(compu_method, "!PHYS-CONSTRS!LOWER-LIMIT")[0].text)
219+
sig.max = decimal.Decimal(fe.selector(compu_method, "!PHYS-CONSTRS!UPPER-LIMIT")[0].text)
220+
except:
221+
pass
222+
unit = fe.selector(compu_method, ">!UNIT-REF")
223+
if len(unit) > 0:
224+
try:
225+
sig.unit = fe.selector(unit[0], "!DISPLAY-NAME")[0].text
226+
except:
227+
pass
228+
elif len(category) > 0 and category[0].text == "TEXTTABLE":
229+
for compu_scale in fe.selector(compu_method, "/!COMPU-SCALE"):
230+
try:
231+
value_name = fe.selector(compu_scale, "!COMPU-CONST!VT")[0].text
232+
except IndexError:
233+
value_name = fe.get_desc_or_longname(compu_scale)
234+
value_value = fe.selector(compu_scale, "!LOWER-LIMIT")[0].text
235+
sig.add_values(value_value, value_name)
236+
sig.is_little_endian = is_little_endian
237+
if not sig.is_little_endian:
238+
sig.set_startbit(start_bit, bitNumbering=1)
239+
else:
240+
sig.start_bit = start_bit
241+
sig.size = bit_length
242+
sig.receivers = list(set(receiver_ecus))
243+
244+
sig.add_comment(fe.get_desc_or_longname(signal))
245+
signals.append(sig)
246+
return signals, ecus
247+
248+
181249
def load(f, **_options):
182250
fe = Fe(f)
183251
result = {}
252+
sig_group_counter = 0
184253

185254
clusters = fe.selector(fe.root, "//CLUSTER")
186255
names = [fe.sn(a) for a in clusters]
@@ -204,11 +273,35 @@ def load(f, **_options):
204273
extended = arbitration_id_element.attrib.get("EXTENDED-ADDRESSING", 'false') == 'true'
205274
frame_element = fe.selector(ft, ">FRAME-REF")[0]
206275
frame_size = int(fe.selector(frame_element, "/BYTE-LENGTH")[0].text)
207-
pdu = fe.selector(frame_element, ">>PDU-REF")[0]
208276

209-
frame_name = fe.sn(pdu)
210-
# fe.selector(pdu, "<<!PDU-TRIGGERING")
211-
frame = canmatrix.Frame(name=frame_name)
277+
pdu_instances = fe.selector(frame_element, "//PDU-INSTANCE")
278+
279+
if len(pdu_instances) > 1:
280+
frame_name = fe.sn(frame_element)
281+
frame = canmatrix.Frame(name=frame_name)
282+
for pdu_instance in pdu_instances:
283+
pdu = fe.selector(pdu_instance, ">PDU-REF")[0]
284+
pdu_startbit_position = int(fe.selector(pdu_instance, "/BIT-POSITION")[0].text, 0)
285+
signals, ecus = get_signals_for_pdu(fe, pdu, pdu_startbit_position)
286+
for sig in signals:
287+
frame.add_signal(sig)
288+
for ecu in ecus:
289+
db.add_ecu(ecu)
290+
291+
frame.add_signal_group(fe.sn(pdu), sig_group_counter, [sig.name for sig in signals])
292+
sig_group_counter += 1
293+
else:
294+
pdu = fe.selector(pdu_instances[0], ">PDU-REF")[0]
295+
frame_name = fe.sn(pdu)
296+
frame = canmatrix.Frame(name=frame_name)
297+
298+
signals, ecus = get_signals_for_pdu(fe, pdu)
299+
for sig in signals:
300+
frame.add_signal(sig)
301+
for ecu in ecus:
302+
db.add_ecu(ecu)
303+
304+
# fe.selector(pdu, "<<!PDU-TRIGGERING")
212305
frame.size = frame_size
213306
if len(output_ports) > 0:
214307
pdu_triggerings = fe.selector(output_ports[0], ">>PDU-TRIGGERING-REF")
@@ -231,69 +324,7 @@ def load(f, **_options):
231324
if "CAN-FD" in [a.text for a in
232325
fe.selector(ft, "//CAN-FRAME-TX-BEHAVIOR") + fe.selector(ft, "//CAN-FRAME-RX-BEHAVIOR")]:
233326
frame.is_fd = True
234-
for signal_instance in fe.selector(pdu, "//SIGNAL-INSTANCE"):
235-
byte_order_element = fe.selector(signal_instance, "/IS-HIGH-LOW-BYTE-ORDER")
236-
if byte_order_element[0].text == "false":
237-
is_little_endian = True
238-
else:
239-
is_little_endian = False
240-
241-
start_bit = int(fe.selector(signal_instance, "/BIT-POSITION")[0].text, 0)
242-
signal = fe.selector(signal_instance, ">SIGNAL-REF")[0]
243-
ecu_instance_refs = fe.selector(signal_instance, "<<ECU")
244-
receiver_ecus = []
245-
for ecu_instance_ref in ecu_instance_refs:
246-
if len(fe.selector(ecu_instance_ref, "^INPUT-PORT")) > 0:
247-
ecu_name = fe.sn(fe.get_referencable_parent(ecu_instance_ref))
248-
receiver_ecus.append(ecu_name)
249-
db.add_ecu(canmatrix.Ecu(ecu_name))
250-
251-
signal_name = fe.sn(signal)
252-
coding = fe.selector(signal, ">CODING-REF")[0]
253-
bit_length = int(fe.selector(coding, "/!BIT-LENGTH")[0].text)
254-
compu_methods = fe.selector(coding, "/!COMPU-METHOD")
255-
sig = canmatrix.Signal(name=signal_name)
256-
257-
for compu_method in compu_methods:
258-
category = fe.selector(compu_method, "/!CATEGORY")
259-
if len(category) > 0 and category[0].text == "LINEAR":
260-
numerator = fe.selector(compu_method, "/!COMPU-NUMERATOR")[0]
261-
denominator = fe.selector(compu_method, "/!COMPU-DENOMINATOR")[0]
262-
teiler = decimal.Decimal(fe.selector(denominator, "/!V")[0].text)
263-
[offset, factor] = [decimal.Decimal(a.text) for a in fe.selector(numerator, "/!V")]
264-
[offset, factor] = [a / teiler for a in [offset, factor]]
265-
sig.offset = offset
266-
sig.factor = factor
267-
try:
268-
sig.min=decimal.Decimal(fe.selector(compu_method, "!PHYS-CONSTRS!LOWER-LIMIT")[0].text)
269-
sig.max = decimal.Decimal(fe.selector(compu_method, "!PHYS-CONSTRS!UPPER-LIMIT")[0].text)
270-
except:
271-
pass
272-
unit = fe.selector(compu_method, ">!UNIT-REF")
273-
if len(unit) > 0:
274-
try:
275-
sig.unit = fe.selector(unit[0],"!DISPLAY-NAME")[0].text
276-
except:
277-
pass
278-
elif len(category) > 0 and category[0].text == "TEXTTABLE":
279-
for compu_scale in fe.selector(compu_method, "/!COMPU-SCALE"):
280-
try:
281-
value_name = fe.selector(compu_scale, "!COMPU-CONST!VT")[0].text
282-
except IndexError:
283-
value_name = fe.get_desc_or_longname(compu_scale)
284-
value_value = fe.selector(compu_scale, "!LOWER-LIMIT")[0].text
285-
sig.add_values(value_value, value_name)
286-
sig.is_little_endian = is_little_endian
287-
if not sig.is_little_endian:
288-
sig.set_startbit(start_bit, bitNumbering=1)
289-
else:
290-
sig.start_bit = start_bit
291-
sig.size = bit_length
292-
sig.receivers = list(set(receiver_ecus))
293-
294-
sig.add_comment(fe.get_desc_or_longname(signal))
295327

296-
frame.add_signal(sig)
297328
db.add_frame(frame)
298329
return result
299330

Diff for: tox.ini

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ deps=
1212
passenv=
1313
TOXENV
1414
CI
15-
TRAVIS
16-
TRAVIS_*
1715
APPVEYOR
1816
APPVEYOR_*
1917
commands=

Diff for: versioneer.py

-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
* [![Latest Version]
1515
(https://pypip.in/version/versioneer/badge.svg?style=flat)
1616
](https://pypi.python.org/pypi/versioneer/)
17-
* [![Build Status]
18-
(https://travis-ci.org/warner/python-versioneer.png?branch=master)
19-
](https://travis-ci.org/warner/python-versioneer)
2017
2118
This is a tool for managing a recorded version number in distutils-based
2219
python projects. The goal is to remove the tedious and error-prone "update

0 commit comments

Comments
 (0)