@@ -56,32 +56,27 @@ def __iter__(self):
5656 temp = line .strip ()
5757 if not temp or not temp [0 ].isdigit ():
5858 continue
59-
6059 try :
6160 timestamp , channel , dummy = temp .split (
6261 None , 2
6362 ) # , frameType, dlc, frameData
6463 except ValueError :
6564 # we parsed an empty comment
6665 continue
67-
6866 timestamp = float (timestamp )
6967 try :
7068 # See ASCWriter
7169 channel = int (channel ) - 1
7270 except ValueError :
7371 pass
74-
7572 if dummy .strip ()[0 :10 ].lower () == "errorframe" :
7673 msg = Message (timestamp = timestamp , is_error_frame = True , channel = channel )
7774 yield msg
78-
7975 elif (
8076 not isinstance (channel , int )
8177 or dummy .strip ()[0 :10 ].lower () == "statistic:"
8278 ):
8379 pass
84-
8580 elif dummy [- 1 :].lower () == "r" :
8681 can_id_str , _ = dummy .split (None , 1 )
8782 can_id_num , is_extended_id = self ._extract_can_id (can_id_str )
@@ -93,7 +88,6 @@ def __iter__(self):
9388 channel = channel ,
9489 )
9590 yield msg
96-
9791 else :
9892 try :
9993 # this only works if dlc > 0 and thus data is availabe
@@ -103,13 +97,11 @@ def __iter__(self):
10397 can_id_str , _ , _ , dlc = dummy .split (None , 3 )
10498 # and we set data to an empty sequence manually
10599 data = ""
106-
107100 dlc = int (dlc )
108101 frame = bytearray ()
109102 data = data .split ()
110103 for byte in data [0 :dlc ]:
111104 frame .append (int (byte , 16 ))
112-
113105 can_id_num , is_extended_id = self ._extract_can_id (can_id_str )
114106
115107 yield Message (
@@ -121,7 +113,6 @@ def __iter__(self):
121113 data = frame ,
122114 channel = channel ,
123115 )
124-
125116 self .stop ()
126117
127118
@@ -135,6 +126,27 @@ class ASCWriter(BaseIOHandler, Listener):
135126 """
136127
137128 FORMAT_MESSAGE = "{channel} {id:<15} Rx {dtype} {data}"
129+ FORMAT_MESSAGE_FD = " " .join (
130+ [
131+ "CANFD" ,
132+ "{channel:>3}" ,
133+ "{dir:<4}" ,
134+ "{id:>8} {symbolic_name:>32}" ,
135+ "{brs}" ,
136+ "{esi}" ,
137+ "{dlc}" ,
138+ "{data_length:>2}" ,
139+ "{data}" ,
140+ "{message_duration:>8}" ,
141+ "{message_length:>4}" ,
142+ "{flags:>8X}" ,
143+ "{crc:>8}" ,
144+ "{bit_timing_conf_arb:>8}" ,
145+ "{bit_timing_conf_data:>8}" ,
146+ "{bit_timing_conf_ext_arb:>8}" ,
147+ "{bit_timing_conf_ext_data:>8}" ,
148+ ]
149+ )
138150 FORMAT_DATE = "%a %b %m %I:%M:%S.{} %p %Y"
139151 FORMAT_EVENT = "{timestamp: 9.6f} {message}\n "
140152
@@ -175,7 +187,6 @@ def log_event(self, message, timestamp=None):
175187 if not message : # if empty or None
176188 logger .debug ("ASCWriter: ignoring empty message" )
177189 return
178-
179190 # this is the case for the very first message:
180191 if not self .header_written :
181192 self .last_timestamp = timestamp or 0.0
@@ -187,15 +198,12 @@ def log_event(self, message, timestamp=None):
187198 self .file .write ("Begin Triggerblock %s\n " % formatted_date )
188199 self .header_written = True
189200 self .log_event ("Start of measurement" ) # caution: this is a recursive call!
190-
191201 # Use last known timestamp if unknown
192202 if timestamp is None :
193203 timestamp = self .last_timestamp
194-
195204 # turn into relative timestamps if necessary
196205 if timestamp >= self .started :
197206 timestamp -= self .started
198-
199207 line = self .FORMAT_EVENT .format (timestamp = timestamp , message = message )
200208 self .file .write (line )
201209
@@ -204,27 +212,49 @@ def on_message_received(self, msg):
204212 if msg .is_error_frame :
205213 self .log_event ("{} ErrorFrame" .format (self .channel ), msg .timestamp )
206214 return
207-
208215 if msg .is_remote_frame :
209216 dtype = "r"
210217 data = []
211218 else :
212219 dtype = "d {}" .format (msg .dlc )
213220 data = ["{:02X}" .format (byte ) for byte in msg .data ]
214-
215221 arb_id = "{:X}" .format (msg .arbitration_id )
216222 if msg .is_extended_id :
217223 arb_id += "x"
218-
219224 channel = channel2int (msg .channel )
220225 if channel is None :
221226 channel = self .channel
222227 else :
223228 # Many interfaces start channel numbering at 0 which is invalid
224229 channel += 1
225-
226- serialized = self .FORMAT_MESSAGE .format (
227- channel = channel , id = arb_id , dtype = dtype , data = " " .join (data )
228- )
229-
230+ if msg .is_fd :
231+ flags = 0
232+ flags |= 1 << 12
233+ if msg .bitrate_switch :
234+ flags |= 1 << 13
235+ if msg .error_state_indicator :
236+ flags |= 1 << 14
237+ serialized = self .FORMAT_MESSAGE_FD .format (
238+ channel = channel ,
239+ id = arb_id ,
240+ dir = "Rx" ,
241+ symbolic_name = "" ,
242+ brs = 1 if msg .bitrate_switch else 0 ,
243+ esi = 1 if msg .error_state_indicator else 0 ,
244+ dlc = msg .dlc ,
245+ data_length = len (data ),
246+ data = " " .join (data ),
247+ message_duration = 0 ,
248+ message_length = 0 ,
249+ flags = flags ,
250+ crc = 0 ,
251+ bit_timing_conf_arb = 0 ,
252+ bit_timing_conf_data = 0 ,
253+ bit_timing_conf_ext_arb = 0 ,
254+ bit_timing_conf_ext_data = 0 ,
255+ )
256+ else :
257+ serialized = self .FORMAT_MESSAGE .format (
258+ channel = channel , id = arb_id , dtype = dtype , data = " " .join (data )
259+ )
230260 self .log_event (serialized , msg .timestamp )
0 commit comments