Skip to content

Commit adc389b

Browse files
committed
update the arxml format signal output related modules, add new output signal attributes such as PDU_Name, PDU_Type, PDU_Length, PDU_PortType, Signal_Group in the arxml signal output table for both CAN signals and Flexray signals in the arxml signal database.
still draft version need validate, run the load and dump script with Autosar 4.0.3 version arxml test is ok.
1 parent ddcbf10 commit adc389b

File tree

4 files changed

+423
-999
lines changed

4 files changed

+423
-999
lines changed

src/canmatrix/canmatrix.py

+149-4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ class Signal(object):
169169
cycle_time = attr.ib(default=0) # type: int
170170
initial_value = attr.ib(converter=float_factory, default=float_factory(0.0)) # type: canmatrix.types.PhysicalValue
171171

172+
pdu_name = attr.ib(default="") # type: str
173+
pdu_type = attr.ib(default="") # type: str
174+
pdu_length = attr.ib(default="") # type: str
175+
pdu_portType = attr.ib(default="") # type: str
176+
signal_group = attr.ib(default="") # type: str
177+
172178
min = attr.ib(
173179
converter=lambda value, float_factory=float_factory: (
174180
float_factory(value)
@@ -721,6 +727,96 @@ def __eq__(self, other):
721727
)
722728
)
723729

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

725821
@attr.s(cmp=False)
726822
class Frame(object):
@@ -757,13 +853,20 @@ class Frame(object):
757853
attributes = attr.ib(factory=dict) # type: typing.MutableMapping[str, typing.Any]
758854
receivers = attr.ib(factory=list) # type: typing.MutableSequence[str]
759855
signalGroups = attr.ib(factory=list) # type: typing.MutableSequence[SignalGroup]
856+
slot_id = attr.ib(default="")
857+
base_cycle = attr.ib(default="")
858+
repitition_cycle = attr.ib(default="")
859+
is_FlexrayFrame = attr.ib(default=False)
760860

761861
cycle_time = attr.ib(default=0) # type: int
762862

763863
is_j1939 = attr.ib(default=False) # type: bool
764864
# ('cycleTime', '_cycleTime', int, None),
765865
# ('sendType', '_sendType', str, None),
766866

867+
pdus = attr.ib(factory=list) # type: typing.MutableSequence[Pdu]
868+
869+
767870
@property
768871
def is_multiplexed(self): # type: () -> bool
769872
"""Frame is multiplexed if at least one of its signals is a multiplexer."""
@@ -879,6 +982,7 @@ def attribute(self, attribute_name, db=None, default=None):
879982

880983
def __iter__(self): # type: () -> typing.Iterator[Signal]
881984
"""Iterator over all signals."""
985+
882986
return iter(self.signals)
883987

884988
def add_signal_group(self, Name, Id, signalNames):
@@ -890,14 +994,18 @@ def add_signal_group(self, Name, Id, signalNames):
890994
:param list of str signalNames: list of Signal names to add. Non existing names are ignored.
891995
"""
892996
newGroup = SignalGroup(Name, Id)
893-
self.signalGroups.append(newGroup)
997+
logger.debug("in Frame add_signal_group function,signalGroup "+str(newGroup)+" is added.")
998+
999+
#self.signalGroups.append(newGroup)
1000+
#logger.debug("in Frame add_signal_group function,signalGroups last one now is "+str(self.signalGroups))
8941001
for signal in signalNames:
8951002
signal = signal.strip()
8961003
if signal.__len__() == 0:
8971004
continue
898-
signalId = self.signal_by_name(signal)
899-
if signalId is not None:
900-
newGroup.add_signal(signalId)
1005+
#signalId = self.signal_by_name(signal)
1006+
#if signalId is not None:
1007+
newGroup.add_signal(signal)
1008+
self.signalGroups.append(newGroup)
9011009

9021010
def signal_group_by_name(self, name):
9031011
# type: (str) -> typing.Union[SignalGroup, None]
@@ -912,6 +1020,18 @@ def signal_group_by_name(self, name):
9121020
return signalGroup
9131021
return None
9141022

1023+
def add_pdu(self, pdu):
1024+
# type: (Pdu) -> Pdu
1025+
"""
1026+
Add Pdu to Frame.
1027+
1028+
:param Pdu pdu: Pdu to be added.
1029+
:return: the pdu added.
1030+
"""
1031+
self.pdus.append(pdu)
1032+
return self.pdus[len(self.pdus) - 1]
1033+
1034+
9151035
def add_signal(self, signal):
9161036
# type: (Signal) -> Signal
9171037
"""
@@ -923,6 +1043,29 @@ def add_signal(self, signal):
9231043
self.signals.append(signal)
9241044
return self.signals[len(self.signals) - 1]
9251045

1046+
'''used as frame.add_signal_group(group_name, group_id, members) in arxml'''
1047+
def get_signal_group_for_signal(self, signal_to_find):
1048+
logger.debug("01 in frame get_signal_group_for_signal function, start find signalgroup with signal "+str(signal_to_find))
1049+
if self.signalGroups is None:
1050+
logger.debug("02 self.signalGroups is none")
1051+
#logger.debug("03 self.signalGroups[0] is "+ str(self.signalGroups))
1052+
for signal_group in self.signalGroups:
1053+
#logger.debug("04 in frame get_signal_group_for_signal function, current signal list is "+str(signal_group.signals))
1054+
for signal in signal_group.signals:
1055+
#logger.debug("05 in frame get_signal_group_for_signal function, current signal is "+str(signal))
1056+
inputSignalName = str(signal)
1057+
searchingSignalName = str(signal_to_find)
1058+
if inputSignalName == searchingSignalName :
1059+
#logger.debug("06 in frame get_signal_group_for_signal function, found signal group"+ str(signal_group.signals)+"with signal "+str(signal_to_find))
1060+
return signal_group
1061+
if signal is None:
1062+
logger.debug("07 in frame get_signal_group_for_signal function,signal is none in signal group"+ str(self.signalGroups))
1063+
if signal_group is None:
1064+
logger.debug("08 in frame get_signal_group_for_signal function,signal_group is none")
1065+
if signal_group is []:
1066+
logger.debug("09 in frame get_signal_group_for_signal function,signal_group is empty")
1067+
return None
1068+
9261069
def add_transmitter(self, transmitter):
9271070
# type: (str) -> None
9281071
"""Add transmitter ECU Name to Frame.
@@ -988,6 +1131,8 @@ def add_attribute(self, attribute, value):
9881131
self.attributes[attribute] = str(value)
9891132
except UnicodeDecodeError:
9901133
self.attributes[attribute] = value
1134+
if type(self.attributes[attribute]) == str:
1135+
self.attributes[attribute] = self.attributes[attribute].strip()
9911136

9921137
def del_attribute(self, attribute):
9931138
# type: (str) -> typing.Any

0 commit comments

Comments
 (0)