Skip to content

Commit

Permalink
Iss484 (#502)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
ebroecker authored Sep 22, 2020
1 parent 18e4c9d commit 5d66cba
Show file tree
Hide file tree
Showing 10 changed files with 699 additions and 511 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ matrix:
env: TOXENV=dist
- python: 2.7
- python: pypy
- python: 3.4
- python: 3.5
- python: pypy3.5
- python: 3.6
- python: 3.7
dist: xenial
sudo: true
- python: 3.8
- python: 2.7
env: TOXENV=old_tests
- python: 3.7
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ environment:
- TOXENV: dist
- TOXENV: py27
- TOXENV: pypy
- TOXENV: py34
- TOXENV: py35
- TOXENV: py36
- TOXENV: py37
- TOXENV: py38
- TOXENV: pypy3

matrix:
Expand Down
14 changes: 14 additions & 0 deletions examples/fr_dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python3
import canmatrix.formats
import sys
cluster = canmatrix.formats.loadp(sys.argv[1], decode_flexray = True)

for cm in cluster:
for frame in cluster[cm]:
frame_info = "{}-{}-{}".format(frame.slot_id, frame.base_cycle, frame.repitition_cycle)
for pdu in frame.pdus:
for signal in pdu.signals:
sig_group = pdu.get_signal_group_for_signal(signal)
sig_group = "None" if sig_group is None else sig_group.name
print("{}: {}, {}, {}, {}, {}".format(frame_info, frame.size, pdu.pdu_type, pdu.name, sig_group, signal.name))

2 changes: 2 additions & 0 deletions requirements.test.py3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ xlwt==1.3.0
xlrd==1.1.0
lxml==4.3.1
click==7.0
xlsxwriter==1.2.8
pyaml==20.4.0
99 changes: 98 additions & 1 deletion src/canmatrix/canmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ def calculate_raw_range(self):
if self.is_float
else int
)
rawRange = 2 ** (self.size - (1 if self.is_signed else 0))
size_to_calc = self.size if self.size <= 128 else 128
if size_to_calc != self.size:
logger.info("max calculation for {} not possible using 128 as base for max value".format(self.size))
rawRange = 2 ** (size_to_calc - (1 if self.is_signed else 0))

return (
factory(-rawRange if self.is_signed else 0),
factory(rawRange - 1),
Expand Down Expand Up @@ -732,6 +736,83 @@ def to_compound_integer(self):
else:
return self.id

def __eq__(self, other):
return (
self.id == other.id
and (
self.extended is None
or other.extended is None
or self.extended == other.extended
)
)

@attr.s(cmp=False)
class Pdu(object):
"""
Represents a PDU.
PDUs are hierarchical groups of signals which are needed to represent Flexray busses
Whereas a PDU is the same than a frame on CAN bus, at flexray a frame may consist of
multiple PDUs (a bit like multiple signal layout for multiplexed can frames).
This class is only used for flexray busses.
"""

name = attr.ib(default="") # type: str
size = attr.ib(default=0) # type: int
triggering_name = attr.ib(default="") # type: str
pdu_type = attr.ib(default="") # type: str
port_type = attr.ib(default="") # type: str
signals = attr.ib(factory=list) # type: typing.MutableSequence[Signal]
signalGroups = attr.ib(factory=list) # type: typing.MutableSequence[SignalGroup]

def add_signal(self, signal):
# type: (Signal) -> Signal
"""
Add Signal to Pdu.
:param Signal signal: Signal to be added.
:return: the signal added.
"""
self.signals.append(signal)
return self.signals[len(self.signals) - 1]
def add_signal_group(self, Name, Id, signalNames):
# type: (str, int, typing.Sequence[str]) -> None
"""Add new SignalGroup to the Frame. Add given signals to the group.
:param str Name: Group name
:param int Id: Group id
:param list of str signalNames: list of Signal names to add. Non existing names are ignored.
"""
newGroup = SignalGroup(Name, Id)
self.signalGroups.append(newGroup)
for signal in signalNames:
signal = signal.strip()
if signal.__len__() == 0:
continue
signalId = self.signal_by_name(signal)
if signalId is not None:
newGroup.add_signal(signalId)

def get_signal_group_for_signal(self, signal_to_find):
for signal_group in self.signalGroups:
for signal in signal_group:
if signal == signal_to_find:
return signal_group
return None

def signal_by_name(self, name):
# type: (str) -> typing.Union[Signal, None]
"""
Get signal by name.
:param str name: signal name to be found.
:return: signal with given name or None if not found
"""
for signal in self.signals:
if signal.name == name:
return signal
return None


@attr.s(cmp=False)
class Frame(object):
Expand Down Expand Up @@ -775,6 +856,9 @@ class Frame(object):
# ('cycleTime', '_cycleTime', int, None),
# ('sendType', '_sendType', str, None),

pdus = attr.ib(factory=list) # type: typing.MutableSequence[Pdu]


@property
def is_multiplexed(self): # type: () -> bool
"""Frame is multiplexed if at least one of its signals is a multiplexer."""
Expand Down Expand Up @@ -890,6 +974,7 @@ def attribute(self, attribute_name, db=None, default=None):

def __iter__(self): # type: () -> typing.Iterator[Signal]
"""Iterator over all signals."""

return iter(self.signals)

def add_signal_group(self, Name, Id, signalNames):
Expand Down Expand Up @@ -923,6 +1008,18 @@ def signal_group_by_name(self, name):
return signalGroup
return None

def add_pdu(self, pdu):
# type: (Pdu) -> Pdu
"""
Add Pdu to Frame.
:param Pdu pdu: Pdu to be added.
:return: the pdu added.
"""
self.pdus.append(pdu)
return self.pdus[len(self.pdus) - 1]


def add_signal(self, signal):
# type: (Signal) -> Signal
"""
Expand Down
5 changes: 4 additions & 1 deletion src/canmatrix/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ def get_formats():
@click.option('--merge', help="merge additional can databases.\nSyntax: --merge filename[:ecu=SOMEECU][:frame=FRAME1][:frame=FRAME2],filename2")
# arxml switches
@click.option('--arxmlIgnoreClusterInfo/--no-arxmlIgnoreClusterInfo', 'arxmlIgnoreClusterInfo', default=False, help="Ignore any can cluster info from arxml; Import all frames in one matrix\ndefault False")
@click.option('--arxmlUseXpath(--no-arxmlUseXpath', 'arxmlUseXpath', default=False, help="Use experimental Xpath-Implementation for resolving AR-Paths; \ndefault False")
@click.option('--arxmlUseXpath/--no-arxmlUseXpath', 'arxmlUseXpath', default=False, help="Use experimental Xpath-Implementation for resolving AR-Paths; \ndefault False")
@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")
@click.option('--arxmlFlexray/--no-arxmlFlexray', 'decode_flexray', default = False, help="EXPERIMENTAL: import basic flexray data from ARXML")
@click.option('--arxmlEthernet/--no-arxmlFlexray', 'decode_ethernet', default = False, help="EXPERIMENTAL: import basic ethernet data from ARXML")

# dbc switches
@click.option('--dbcImportEncoding', 'dbcImportEncoding', default="iso-8859-1", help="Import charset of dbc (relevant for units), maybe utf-8\ndefault iso-8859-1")
@click.option('--dbcImportCommentEncoding', 'dbcImportCommentEncoding', default="iso-8859-1", help="Import charset of Comments in dbc\ndefault iso-8859-1")
Expand Down
Loading

0 comments on commit 5d66cba

Please sign in to comment.