Skip to content

Commit

Permalink
MAVExplorer: Add logmessage download/help commands
Browse files Browse the repository at this point in the history
Use DFMetaData.download to download XML files to .pymavlink/LogMessages
Use DFMetaData.print_help to print logmessage help
Apply suggestions, and perform flake8 check on new code

Co-authored-by: Peter Barker <[email protected]>
  • Loading branch information
shancock884 and peterbarker committed Apr 2, 2024
1 parent 0f1e9e6 commit ee73e97
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions MAVProxy/tools/MAVExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import MAVProxy.modules.lib.mp_util as mp_util
from pymavlink import mavutil
from pymavlink import mavwp
from pymavlink import DFReader
from MAVProxy.modules.lib.mp_settings import MPSettings, MPSetting
from MAVProxy.modules.lib import wxsettings
from MAVProxy.modules.lib.graphdefinition import GraphDefinition
Expand Down Expand Up @@ -128,6 +129,7 @@ def __init__(self):
"dump" : ['(MESSAGETYPE)', '--verbose (MESSAGETYPE)'],
"map" : ['(VARIABLE) (VARIABLE) (VARIABLE) (VARIABLE) (VARIABLE)'],
"param" : ['download', 'check', 'help (PARAMETER)'],
"logmessage": ['download', 'help (MESSAGETYPE)'],
}
self.aliases = {}
self.graphs = []
Expand Down Expand Up @@ -332,6 +334,9 @@ def load_graphs():
mestate.graphs = []
gfiles = ['mavgraphs.xml']
for dirname, dirnames, filenames in os.walk(mp_util.dot_mavproxy()):
# Skip XML files in the LogMessages subfolder
if os.path.basename(dirname) == "LogMessages":
continue
for filename in filenames:
if filename.lower().endswith('.xml'):
gfiles.append(os.path.join(dirname, filename))
Expand Down Expand Up @@ -1176,6 +1181,44 @@ def cmd_paramchange(args):
vmap[pname] = pvalue
mestate.mlog.rewind()


def cmd_logmessage(args):
'''show log message information'''
mlog = mestate.mlog
usage = "Usage: logmessage <help|download>"
# Print usage and return, if we have no arguments
if len(args) <= 0:
print(usage)
return
# help: print help for the requested log message
if args[0] == 'help':
if len(args) < 2:
print(usage)
return
if hasattr(mlog, 'metadata'):
mlog.metadata.print_help(args[1])
elif isinstance(mlog, mavutil.mavlogfile):
print("logmessage help is not supported for telemetry log files")
else:
print("Incompatible pymavlink; upgrade pymavlink?")
return
# download: download XML files for log messages
if args[0] == 'download':
if not hasattr(DFReader, 'DFMetaData'):
print("Incompatible pymavlink; upgrade pymavlink?")
return
try:
child = multiproc.Process(target=DFReader.DFMetaData.download)
child.start()
except Exception as e:
print(e)
if hasattr(mlog, 'metadata'):
mlog.metadata.reset()
return
# Print usage if we've dropped through the ifs
print(usage)


def cmd_mission(args):
'''show mission'''
if (len(args) == 1):
Expand Down Expand Up @@ -1463,6 +1506,7 @@ def main_loop():
'dump' : (cmd_dump, 'dump messages from log'),
'file' : (cmd_file, 'show files'),
'mission' : (cmd_mission, 'show mission'),
'logmessage' : (cmd_logmessage, 'show log message information'),
}

def progress_bar(pct):
Expand Down

0 comments on commit ee73e97

Please sign in to comment.