Skip to content

Commit

Permalink
DFReader: is_text_log should return false if binary
Browse files Browse the repository at this point in the history
In mavlogdump, use type of mlog not file ext to determine type to allow .log to be either text or tlog
Update description text in mavlogdump file header
  • Loading branch information
shancock884 committed Jan 9, 2024
1 parent 0a6dbf3 commit 02aa27c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions DFReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,10 @@ def make_format_msgbuf(self, fmt):
def DFReader_is_text_log(filename):
'''return True if a file appears to be a valid text log'''
with open(filename, 'r') as f:
ret = (f.read(8000).find('FMT,') != -1)

try:
ret = (f.read(8000).find('FMT,') != -1)
except UnicodeDecodeError:
ret = False
return ret


Expand Down
13 changes: 7 additions & 6 deletions tools/mavlogdump.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python

'''
example program that dumps a Mavlink log file. The log file is
assumed to be in the format that qgroundcontrol uses, which consists
Dumps out the contents a log file in the requsted format.
The input log file may by a dataflash file in binary (.bin, .px4log)
or text (.log) format, or a telemetry log (.tlog, .log) consisting of
of a series of MAVLink packets, each with a 64 bit timestamp
header. The timestamp is in microseconds since 1970 (unix epoch)
'''
Expand Down Expand Up @@ -99,10 +100,10 @@
if nottypes is not None:
nottypes = nottypes.split(',')

ext = os.path.splitext(filename)[1]
isbin = ext in ['.bin', '.BIN', '.px4log']
islog = ext in ['.log', '.LOG'] # NOTE: "islog" does not mean a tlog
istlog = ext in ['.tlog', '.TLOG']
mlog_type = str(type(mlog))
isbin = "DFReader_binary" in mlog_type
islog = "DFReader_text" in mlog_type # NOTE: "islog" does not mean a tlog
istlog = "mavmmaplog" in mlog_type

# list of msgs to reduce in rate when --reduce is used
reduction_msgs = ['NKF*', 'XKF*', 'IMU*', 'AHR2', 'BAR*', 'ATT', 'BAT*', 'CTUN', 'NTUN', 'GP*', 'IMT*', 'MAG*', 'PL', 'POS', 'POW*', 'RATE', 'RC*', 'RFND', 'UBX*', 'VIBE', 'NKQ*', 'MOT*', 'CTRL', 'FTS*', 'DSF', 'CST*', 'LOS*', 'UWB*']
Expand Down

0 comments on commit 02aa27c

Please sign in to comment.