2828
2929class ASCReader (BaseIOHandler ):
3030 """
31- Iterator of CAN messages from a ASC logging file.
31+ Iterator of CAN messages from a ASC logging file. Meta data (comments,
32+ bus statistics, J1939 Transport Protocol messages) is ignored.
3233
3334 TODO: turn relative timestamps back to absolute form
3435 """
@@ -58,9 +59,13 @@ def __iter__(self):
5859 temp = line .strip ()
5960 if not temp or not temp [0 ].isdigit ():
6061 continue
61-
62+ is_fd = False
6263 try :
6364 timestamp , channel , dummy = temp .split (None , 2 ) # , frameType, dlc, frameData
65+ if channel == "CANFD" :
66+ timestamp , _ , channel , _ , dummy = temp .split (None , 4 )
67+ is_fd = True
68+
6469 except ValueError :
6570 # we parsed an empty comment
6671 continue
@@ -77,7 +82,10 @@ def __iter__(self):
7782 channel = channel )
7883 yield msg
7984
80- elif not isinstance (channel , int ) or dummy .strip ()[0 :10 ].lower () == 'statistic:' :
85+ elif (not isinstance (channel , int )
86+ or dummy .strip ()[0 :10 ].lower () == 'statistic:'
87+ or dummy .split (None , 1 )[0 ] == "J1939TP"
88+ ):
8189 pass
8290
8391 elif dummy [- 1 :].lower () == 'r' :
@@ -91,16 +99,32 @@ def __iter__(self):
9199 yield msg
92100
93101 else :
102+ brs = None
103+ esi = None
104+ data_length = 0
94105 try :
95- # this only works if dlc > 0 and thus data is availabe
96- can_id_str , _ , _ , dlc , data = dummy .split (None , 4 )
106+ # this only works if dlc > 0 and thus data is available
107+ if not is_fd :
108+ can_id_str , _ , _ , dlc , data = dummy .split (None , 4 )
109+ else :
110+ can_id_str , frame_name , brs , esi , dlc , data_length , data = dummy .split (
111+ None , 6
112+ )
113+ if frame_name .isdigit ():
114+ # Empty frame_name
115+ can_id_str , brs , esi , dlc , data_length , data = dummy .split (
116+ None , 5
117+ )
97118 except ValueError :
98119 # but if not, we only want to get the stuff up to the dlc
99120 can_id_str , _ , _ , dlc = dummy .split (None , 3 )
100121 # and we set data to an empty sequence manually
101122 data = ''
102-
103- dlc = int (dlc )
123+ dlc = int (dlc , 16 )
124+ if is_fd :
125+ # For fd frames, dlc and data length might not be equal and
126+ # data_length is the actual size of the data
127+ dlc = int (data_length )
104128 frame = bytearray ()
105129 data = data .split ()
106130 for byte in data [0 :dlc ]:
@@ -115,7 +139,10 @@ def __iter__(self):
115139 is_remote_frame = False ,
116140 dlc = dlc ,
117141 data = frame ,
118- channel = channel
142+ is_fd = is_fd ,
143+ channel = channel ,
144+ bitrate_switch = is_fd and brs == "1" ,
145+ error_state_indicator = is_fd and esi == "1" ,
119146 )
120147
121148 self .stop ()
0 commit comments