ardupilot/Tools/autotest/dump_logs.py

62 lines
1.6 KiB
Python
Raw Normal View History

2013-04-06 02:56:31 -03:00
#!/usr/bin/env python
"""
dump flash logs from SITL
Andrew Tridgell, April 2013
"""
2016-11-08 07:06:05 -04:00
from __future__ import print_function
import optparse
import os
import sys
from pysim import util
2013-04-06 02:56:31 -03:00
############## main program #############
parser = optparse.OptionParser(sys.argv[0])
parser.add_option("--cli", action='store_true', default=False, help='put us in the CLI menu in logs')
opts, args = parser.parse_args()
2013-04-06 02:56:31 -03:00
os.environ['PYTHONUNBUFFERED'] = '1'
2013-04-06 02:56:31 -03:00
def dump_logs(atype):
"""Dump DataFlash logs."""
logfile = '%s.log' % atype
2013-04-06 02:56:31 -03:00
print("Dumping logs for %s to %s" % (atype, logfile))
sitl = util.start_SITL(atype)
2013-04-06 02:56:31 -03:00
log = open(logfile, mode='w')
mavproxy = util.start_MAVProxy_SITL(atype, setup=True, logfile=log)
2013-04-06 02:56:31 -03:00
mavproxy.send('\n\n\n')
print("navigating menus")
mavproxy.expect(']')
mavproxy.send("logs\n")
if opts.cli:
mavproxy.interact()
return
2013-04-06 02:56:31 -03:00
mavproxy.expect("logs enabled:")
lognums = []
i = mavproxy.expect(["No logs", "(\d+) logs"])
if i == 0:
numlogs = 0
else:
numlogs = int(mavproxy.match.group(1))
for i in range(numlogs):
mavproxy.expect("Log (\d+)")
2013-04-06 02:56:31 -03:00
lognums.append(int(mavproxy.match.group(1)))
mavproxy.expect("Log]")
for i in range(numlogs):
print("Dumping log %u (i=%u)" % (lognums[i], i))
mavproxy.send("dump %u\n" % lognums[i])
mavproxy.expect("logs enabled:", timeout=120)
mavproxy.expect("Log]")
util.pexpect_close(mavproxy)
util.pexpect_close(sitl)
2013-04-06 02:56:31 -03:00
log.close()
print("Saved log for %s to %s" % (atype, logfile))
return True
vehicle = os.path.basename(os.getcwd())
dump_logs(vehicle)