Skip to content

Commit 5d66cba

Browse files
authored
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
1 parent 18e4c9d commit 5d66cba

File tree

10 files changed

+699
-511
lines changed

10 files changed

+699
-511
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ matrix:
88
env: TOXENV=dist
99
- python: 2.7
1010
- python: pypy
11-
- python: 3.4
1211
- python: 3.5
1312
- python: pypy3.5
1413
- python: 3.6
1514
- python: 3.7
1615
dist: xenial
1716
sudo: true
17+
- python: 3.8
1818
- python: 2.7
1919
env: TOXENV=old_tests
2020
- python: 3.7

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ environment:
77
- TOXENV: dist
88
- TOXENV: py27
99
- TOXENV: pypy
10-
- TOXENV: py34
1110
- TOXENV: py35
1211
- TOXENV: py36
1312
- TOXENV: py37
13+
- TOXENV: py38
1414
- TOXENV: pypy3
1515

1616
matrix:

examples/fr_dump.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
import canmatrix.formats
3+
import sys
4+
cluster = canmatrix.formats.loadp(sys.argv[1], decode_flexray = True)
5+
6+
for cm in cluster:
7+
for frame in cluster[cm]:
8+
frame_info = "{}-{}-{}".format(frame.slot_id, frame.base_cycle, frame.repitition_cycle)
9+
for pdu in frame.pdus:
10+
for signal in pdu.signals:
11+
sig_group = pdu.get_signal_group_for_signal(signal)
12+
sig_group = "None" if sig_group is None else sig_group.name
13+
print("{}: {}, {}, {}, {}, {}".format(frame_info, frame.size, pdu.pdu_type, pdu.name, sig_group, signal.name))
14+

requirements.test.py3.txt

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ xlwt==1.3.0
1919
xlrd==1.1.0
2020
lxml==4.3.1
2121
click==7.0
22+
xlsxwriter==1.2.8
23+
pyaml==20.4.0

src/canmatrix/canmatrix.py

+98-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ def calculate_raw_range(self):
347347
if self.is_float
348348
else int
349349
)
350-
rawRange = 2 ** (self.size - (1 if self.is_signed else 0))
350+
size_to_calc = self.size if self.size <= 128 else 128
351+
if size_to_calc != self.size:
352+
logger.info("max calculation for {} not possible using 128 as base for max value".format(self.size))
353+
rawRange = 2 ** (size_to_calc - (1 if self.is_signed else 0))
354+
351355
return (
352356
factory(-rawRange if self.is_signed else 0),
353357
factory(rawRange - 1),
@@ -732,6 +736,83 @@ def to_compound_integer(self):
732736
else:
733737
return self.id
734738

739+
def __eq__(self, other):
740+
return (
741+
self.id == other.id
742+
and (
743+
self.extended is None
744+
or other.extended is None
745+
or self.extended == other.extended
746+
)
747+
)
748+
749+
@attr.s(cmp=False)
750+
class Pdu(object):
751+
"""
752+
Represents a PDU.
753+
754+
PDUs are hierarchical groups of signals which are needed to represent Flexray busses
755+
Whereas a PDU is the same than a frame on CAN bus, at flexray a frame may consist of
756+
multiple PDUs (a bit like multiple signal layout for multiplexed can frames).
757+
This class is only used for flexray busses.
758+
"""
759+
760+
name = attr.ib(default="") # type: str
761+
size = attr.ib(default=0) # type: int
762+
triggering_name = attr.ib(default="") # type: str
763+
pdu_type = attr.ib(default="") # type: str
764+
port_type = attr.ib(default="") # type: str
765+
signals = attr.ib(factory=list) # type: typing.MutableSequence[Signal]
766+
signalGroups = attr.ib(factory=list) # type: typing.MutableSequence[SignalGroup]
767+
768+
def add_signal(self, signal):
769+
# type: (Signal) -> Signal
770+
"""
771+
Add Signal to Pdu.
772+
773+
:param Signal signal: Signal to be added.
774+
:return: the signal added.
775+
"""
776+
self.signals.append(signal)
777+
return self.signals[len(self.signals) - 1]
778+
def add_signal_group(self, Name, Id, signalNames):
779+
# type: (str, int, typing.Sequence[str]) -> None
780+
"""Add new SignalGroup to the Frame. Add given signals to the group.
781+
782+
:param str Name: Group name
783+
:param int Id: Group id
784+
:param list of str signalNames: list of Signal names to add. Non existing names are ignored.
785+
"""
786+
newGroup = SignalGroup(Name, Id)
787+
self.signalGroups.append(newGroup)
788+
for signal in signalNames:
789+
signal = signal.strip()
790+
if signal.__len__() == 0:
791+
continue
792+
signalId = self.signal_by_name(signal)
793+
if signalId is not None:
794+
newGroup.add_signal(signalId)
795+
796+
def get_signal_group_for_signal(self, signal_to_find):
797+
for signal_group in self.signalGroups:
798+
for signal in signal_group:
799+
if signal == signal_to_find:
800+
return signal_group
801+
return None
802+
803+
def signal_by_name(self, name):
804+
# type: (str) -> typing.Union[Signal, None]
805+
"""
806+
Get signal by name.
807+
808+
:param str name: signal name to be found.
809+
:return: signal with given name or None if not found
810+
"""
811+
for signal in self.signals:
812+
if signal.name == name:
813+
return signal
814+
return None
815+
735816

736817
@attr.s(cmp=False)
737818
class Frame(object):
@@ -775,6 +856,9 @@ class Frame(object):
775856
# ('cycleTime', '_cycleTime', int, None),
776857
# ('sendType', '_sendType', str, None),
777858

859+
pdus = attr.ib(factory=list) # type: typing.MutableSequence[Pdu]
860+
861+
778862
@property
779863
def is_multiplexed(self): # type: () -> bool
780864
"""Frame is multiplexed if at least one of its signals is a multiplexer."""
@@ -890,6 +974,7 @@ def attribute(self, attribute_name, db=None, default=None):
890974

891975
def __iter__(self): # type: () -> typing.Iterator[Signal]
892976
"""Iterator over all signals."""
977+
893978
return iter(self.signals)
894979

895980
def add_signal_group(self, Name, Id, signalNames):
@@ -923,6 +1008,18 @@ def signal_group_by_name(self, name):
9231008
return signalGroup
9241009
return None
9251010

1011+
def add_pdu(self, pdu):
1012+
# type: (Pdu) -> Pdu
1013+
"""
1014+
Add Pdu to Frame.
1015+
1016+
:param Pdu pdu: Pdu to be added.
1017+
:return: the pdu added.
1018+
"""
1019+
self.pdus.append(pdu)
1020+
return self.pdus[len(self.pdus) - 1]
1021+
1022+
9261023
def add_signal(self, signal):
9271024
# type: (Signal) -> Signal
9281025
"""

src/canmatrix/cli/convert.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ def get_formats():
7777
@click.option('--merge', help="merge additional can databases.\nSyntax: --merge filename[:ecu=SOMEECU][:frame=FRAME1][:frame=FRAME2],filename2")
7878
# arxml switches
7979
@click.option('--arxmlIgnoreClusterInfo/--no-arxmlIgnoreClusterInfo', 'arxmlIgnoreClusterInfo', default=False, help="Ignore any can cluster info from arxml; Import all frames in one matrix\ndefault False")
80-
@click.option('--arxmlUseXpath(--no-arxmlUseXpath', 'arxmlUseXpath', default=False, help="Use experimental Xpath-Implementation for resolving AR-Paths; \ndefault False")
80+
@click.option('--arxmlUseXpath/--no-arxmlUseXpath', 'arxmlUseXpath', default=False, help="Use experimental Xpath-Implementation for resolving AR-Paths; \ndefault False")
8181
@click.option('--arxmlExportVersion', 'arVersion', default="3.2.3", help="Set output AUTOSAR version\ncurrently only 3.2.3 and 4.1.0 are supported\ndefault 3.2.3")
82+
@click.option('--arxmlFlexray/--no-arxmlFlexray', 'decode_flexray', default = False, help="EXPERIMENTAL: import basic flexray data from ARXML")
83+
@click.option('--arxmlEthernet/--no-arxmlFlexray', 'decode_ethernet', default = False, help="EXPERIMENTAL: import basic ethernet data from ARXML")
84+
8285
# dbc switches
8386
@click.option('--dbcImportEncoding', 'dbcImportEncoding', default="iso-8859-1", help="Import charset of dbc (relevant for units), maybe utf-8\ndefault iso-8859-1")
8487
@click.option('--dbcImportCommentEncoding', 'dbcImportCommentEncoding', default="iso-8859-1", help="Import charset of Comments in dbc\ndefault iso-8859-1")

0 commit comments

Comments
 (0)