@@ -169,6 +169,12 @@ class Signal(object):
169
169
cycle_time = attr .ib (default = 0 ) # type: int
170
170
initial_value = attr .ib (converter = float_factory , default = float_factory (0.0 )) # type: canmatrix.types.PhysicalValue
171
171
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
+
172
178
min = attr .ib (
173
179
converter = lambda value , float_factory = float_factory : (
174
180
float_factory (value )
@@ -721,6 +727,96 @@ def __eq__(self, other):
721
727
)
722
728
)
723
729
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
+
724
820
725
821
@attr .s (cmp = False )
726
822
class Frame (object ):
@@ -757,13 +853,20 @@ class Frame(object):
757
853
attributes = attr .ib (factory = dict ) # type: typing.MutableMapping[str, typing.Any]
758
854
receivers = attr .ib (factory = list ) # type: typing.MutableSequence[str]
759
855
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 )
760
860
761
861
cycle_time = attr .ib (default = 0 ) # type: int
762
862
763
863
is_j1939 = attr .ib (default = False ) # type: bool
764
864
# ('cycleTime', '_cycleTime', int, None),
765
865
# ('sendType', '_sendType', str, None),
766
866
867
+ pdus = attr .ib (factory = list ) # type: typing.MutableSequence[Pdu]
868
+
869
+
767
870
@property
768
871
def is_multiplexed (self ): # type: () -> bool
769
872
"""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):
879
982
880
983
def __iter__ (self ): # type: () -> typing.Iterator[Signal]
881
984
"""Iterator over all signals."""
985
+
882
986
return iter (self .signals )
883
987
884
988
def add_signal_group (self , Name , Id , signalNames ):
@@ -890,14 +994,18 @@ def add_signal_group(self, Name, Id, signalNames):
890
994
:param list of str signalNames: list of Signal names to add. Non existing names are ignored.
891
995
"""
892
996
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))
894
1001
for signal in signalNames :
895
1002
signal = signal .strip ()
896
1003
if signal .__len__ () == 0 :
897
1004
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 )
901
1009
902
1010
def signal_group_by_name (self , name ):
903
1011
# type: (str) -> typing.Union[SignalGroup, None]
@@ -912,6 +1020,18 @@ def signal_group_by_name(self, name):
912
1020
return signalGroup
913
1021
return None
914
1022
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
+
915
1035
def add_signal (self , signal ):
916
1036
# type: (Signal) -> Signal
917
1037
"""
@@ -923,6 +1043,29 @@ def add_signal(self, signal):
923
1043
self .signals .append (signal )
924
1044
return self .signals [len (self .signals ) - 1 ]
925
1045
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
+
926
1069
def add_transmitter (self , transmitter ):
927
1070
# type: (str) -> None
928
1071
"""Add transmitter ECU Name to Frame.
@@ -988,6 +1131,8 @@ def add_attribute(self, attribute, value):
988
1131
self .attributes [attribute ] = str (value )
989
1132
except UnicodeDecodeError :
990
1133
self .attributes [attribute ] = value
1134
+ if type (self .attributes [attribute ]) == str :
1135
+ self .attributes [attribute ] = self .attributes [attribute ].strip ()
991
1136
992
1137
def del_attribute (self , attribute ):
993
1138
# type: (str) -> typing.Any
0 commit comments