@@ -56,32 +56,27 @@ def __iter__(self):
56
56
temp = line .strip ()
57
57
if not temp or not temp [0 ].isdigit ():
58
58
continue
59
-
60
59
try :
61
60
timestamp , channel , dummy = temp .split (
62
61
None , 2
63
62
) # , frameType, dlc, frameData
64
63
except ValueError :
65
64
# we parsed an empty comment
66
65
continue
67
-
68
66
timestamp = float (timestamp )
69
67
try :
70
68
# See ASCWriter
71
69
channel = int (channel ) - 1
72
70
except ValueError :
73
71
pass
74
-
75
72
if dummy .strip ()[0 :10 ].lower () == "errorframe" :
76
73
msg = Message (timestamp = timestamp , is_error_frame = True , channel = channel )
77
74
yield msg
78
-
79
75
elif (
80
76
not isinstance (channel , int )
81
77
or dummy .strip ()[0 :10 ].lower () == "statistic:"
82
78
):
83
79
pass
84
-
85
80
elif dummy [- 1 :].lower () == "r" :
86
81
can_id_str , _ = dummy .split (None , 1 )
87
82
can_id_num , is_extended_id = self ._extract_can_id (can_id_str )
@@ -93,7 +88,6 @@ def __iter__(self):
93
88
channel = channel ,
94
89
)
95
90
yield msg
96
-
97
91
else :
98
92
try :
99
93
# this only works if dlc > 0 and thus data is availabe
@@ -103,13 +97,11 @@ def __iter__(self):
103
97
can_id_str , _ , _ , dlc = dummy .split (None , 3 )
104
98
# and we set data to an empty sequence manually
105
99
data = ""
106
-
107
100
dlc = int (dlc )
108
101
frame = bytearray ()
109
102
data = data .split ()
110
103
for byte in data [0 :dlc ]:
111
104
frame .append (int (byte , 16 ))
112
-
113
105
can_id_num , is_extended_id = self ._extract_can_id (can_id_str )
114
106
115
107
yield Message (
@@ -121,7 +113,6 @@ def __iter__(self):
121
113
data = frame ,
122
114
channel = channel ,
123
115
)
124
-
125
116
self .stop ()
126
117
127
118
@@ -135,6 +126,27 @@ class ASCWriter(BaseIOHandler, Listener):
135
126
"""
136
127
137
128
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
+ )
138
150
FORMAT_DATE = "%a %b %m %I:%M:%S.{} %p %Y"
139
151
FORMAT_EVENT = "{timestamp: 9.6f} {message}\n "
140
152
@@ -175,7 +187,6 @@ def log_event(self, message, timestamp=None):
175
187
if not message : # if empty or None
176
188
logger .debug ("ASCWriter: ignoring empty message" )
177
189
return
178
-
179
190
# this is the case for the very first message:
180
191
if not self .header_written :
181
192
self .last_timestamp = timestamp or 0.0
@@ -187,15 +198,12 @@ def log_event(self, message, timestamp=None):
187
198
self .file .write ("Begin Triggerblock %s\n " % formatted_date )
188
199
self .header_written = True
189
200
self .log_event ("Start of measurement" ) # caution: this is a recursive call!
190
-
191
201
# Use last known timestamp if unknown
192
202
if timestamp is None :
193
203
timestamp = self .last_timestamp
194
-
195
204
# turn into relative timestamps if necessary
196
205
if timestamp >= self .started :
197
206
timestamp -= self .started
198
-
199
207
line = self .FORMAT_EVENT .format (timestamp = timestamp , message = message )
200
208
self .file .write (line )
201
209
@@ -204,27 +212,49 @@ def on_message_received(self, msg):
204
212
if msg .is_error_frame :
205
213
self .log_event ("{} ErrorFrame" .format (self .channel ), msg .timestamp )
206
214
return
207
-
208
215
if msg .is_remote_frame :
209
216
dtype = "r"
210
217
data = []
211
218
else :
212
219
dtype = "d {}" .format (msg .dlc )
213
220
data = ["{:02X}" .format (byte ) for byte in msg .data ]
214
-
215
221
arb_id = "{:X}" .format (msg .arbitration_id )
216
222
if msg .is_extended_id :
217
223
arb_id += "x"
218
-
219
224
channel = channel2int (msg .channel )
220
225
if channel is None :
221
226
channel = self .channel
222
227
else :
223
228
# Many interfaces start channel numbering at 0 which is invalid
224
229
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
+ )
230
260
self .log_event (serialized , msg .timestamp )
0 commit comments