From 471c60b9ecc18a3ec0fa78ea5281617cdabaa28e Mon Sep 17 00:00:00 2001 From: Simon Hancock Date: Mon, 8 Jan 2024 17:32:12 +0100 Subject: [PATCH] Mavdumplog: Handle TLog files saved with .log extension DFReader: is_text_log should return false if binary Mavlogdump: use class type not file ext to determine input format, to allow .log to be either text or tlog Update description text in mavlogdump file header --- DFReader.py | 6 ++++-- tools/mavlogdump.py | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DFReader.py b/DFReader.py index 8b0212cb4..8d5ab3c9d 100644 --- a/DFReader.py +++ b/DFReader.py @@ -1208,8 +1208,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 diff --git a/tools/mavlogdump.py b/tools/mavlogdump.py index 09909897c..46da13946 100755 --- a/tools/mavlogdump.py +++ b/tools/mavlogdump.py @@ -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) ''' @@ -69,6 +70,7 @@ import inspect from pymavlink import mavutil +from pymavlink import DFReader if args.profile: @@ -99,10 +101,9 @@ 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'] +isbin = isinstance(mlog,DFReader.DFReader_binary) +islog = isinstance(mlog,DFReader.DFReader_text) # NOTE: "islog" does not mean a tlog +istlog = isinstance(mlog,mavutil.mavmmaplog) # 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*']