@@ -187,22 +187,21 @@ def match_type(mtype, patterns):
187
187
currentOffset += len (fields )
188
188
except IndexError :
189
189
quit ()
190
+ except AttributeError :
191
+ print ("Message type '%s' not found" % (type ))
192
+ quit ()
190
193
except TypeError :
191
194
print ("You must specify a list of message types if outputting CSV format via the --types argument." )
192
195
exit ()
193
196
194
197
# The first line output are names for all columns
195
- csv_out = ["" for x in fields ]
196
198
print (args .csv_sep .join (fields ))
197
199
198
- if isbin and args .format == 'csv' : # need to accumulate columns from message
200
+ if ( isbin or islog ) and args .format == 'csv' : # need to accumulate columns from message
199
201
if types is None or len (types ) != 1 :
200
202
print ("Need exactly one type when dumping CSV from bin file" )
201
203
quit ()
202
204
203
- # Track the last timestamp value. Used for compressing data for the CSV output format.
204
- last_timestamp = None
205
-
206
205
# Track types found
207
206
available_types = set ()
208
207
@@ -217,7 +216,11 @@ def match_type(mtype, patterns):
217
216
match_types = []
218
217
match_types .append (k )
219
218
220
- if isbin and args .format == 'csv' :
219
+ if (isbin or islog ) and args .format == 'csv' :
220
+ # Make sure the specified type was found
221
+ if match_types is None :
222
+ print ("Specified type '%s' not found in log file" % (types [0 ]))
223
+ quit ()
221
224
# we need FMT messages for column headings
222
225
match_types .append ("FMT" )
223
226
@@ -226,17 +229,12 @@ def match_type(mtype, patterns):
226
229
while True :
227
230
m = mlog .recv_match (blocking = args .follow , type = match_types )
228
231
if m is None :
229
- # write the final csv line before exiting
230
- if args .format == 'csv' and csv_out :
231
- csv_out [0 ] = "{:.8f}" .format (last_timestamp )
232
- print (args .csv_sep .join (csv_out ))
233
232
break
234
233
m_type = m .get_type ()
235
234
available_types .add (m_type )
236
- if isbin and m_type == "FMT" and args .format == 'csv' :
235
+ if ( isbin or islog ) and m_type == "FMT" and args .format == 'csv' :
237
236
if m .Name == types [0 ]:
238
237
fields += m .Columns .split (',' )
239
- csv_out = ["" for x in fields ]
240
238
print (args .csv_sep .join (fields ))
241
239
242
240
if args .reduce and reduce_msg (m_type , args .reduce ):
@@ -329,27 +327,13 @@ def match_type(mtype, patterns):
329
327
# CSV format outputs columnar data with a user-specified delimiter
330
328
elif args .format == 'csv' :
331
329
data = m .to_dict ()
332
-
333
- # If this message has a duplicate timestamp, copy its data into the existing data list. Also
334
- # do this if it's the first message encountered.
335
- if timestamp == last_timestamp or last_timestamp is None :
336
- if isbin :
337
- newData = [str (data [y ]) if y != "timestamp" else "" for y in fields ]
338
- else :
339
- newData = [str (data [y .split ('.' )[- 1 ]]) if y .split ('.' )[0 ] == m_type and y .split ('.' )[- 1 ] in data else "" for y in fields ]
340
-
341
- for i , val in enumerate (newData ):
342
- if val :
343
- csv_out [i ] = val
344
-
345
- # Otherwise if this is a new timestamp, print out the old output data, and store the current message for later output.
330
+ if isbin or islog :
331
+ csv_out = [str (data [y ]) if y != "timestamp" else "" for y in fields ]
346
332
else :
347
- csv_out [0 ] = "{:.8f}" .format (last_timestamp )
348
- print (args .csv_sep .join (csv_out ))
349
- if isbin :
350
- csv_out = [str (data [y ]) if y != "timestamp" else "" for y in fields ]
351
- else :
352
- csv_out = [str (data [y .split ('.' )[- 1 ]]) if y .split ('.' )[0 ] == m_type and y .split ('.' )[- 1 ] in data else "" for y in fields ]
333
+ csv_out = [str (data [y .split ('.' )[- 1 ]]) if y .split ('.' )[0 ] == m_type and y .split ('.' )[- 1 ] in data else "" for y in fields ]
334
+ csv_out [0 ] = "{:.8f}" .format (timestamp )
335
+ print (args .csv_sep .join (csv_out ))
336
+
353
337
# MAT format outputs data to a .mat file specified through the
354
338
# --mat_file option
355
339
elif args .format == 'mat' :
@@ -393,9 +377,6 @@ def match_type(mtype, patterns):
393
377
s += " seq=%u" % m .get_seq ()
394
378
print (s )
395
379
396
- # Update our last timestamp value.
397
- last_timestamp = timestamp
398
-
399
380
# Export the .mat file
400
381
if args .format == 'mat' :
401
382
scipy .io .savemat (args .mat_file , MAT , do_compression = args .compress )
0 commit comments