2013-04-06 02:56:31 -03:00
|
|
|
#!/usr/bin/env python
|
2016-07-31 07:22:06 -03:00
|
|
|
"""
|
|
|
|
dump flash logs from SITL
|
|
|
|
Andrew Tridgell, April 2013
|
|
|
|
"""
|
2013-04-06 02:56:31 -03:00
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from pysim import util
|
2013-04-06 02:56:31 -03:00
|
|
|
|
|
|
|
|
2013-04-17 08:36:13 -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'
|
|
|
|
|
2016-07-31 07:22:06 -03:00
|
|
|
|
2013-04-06 02:56:31 -03:00
|
|
|
def dump_logs(atype):
|
2016-07-31 07:22:06 -03:00
|
|
|
"""Dump DataFlash logs."""
|
2013-04-18 21:24:35 -03:00
|
|
|
logfile = '%s.log' % atype
|
2013-04-06 02:56:31 -03:00
|
|
|
print("Dumping logs for %s to %s" % (atype, logfile))
|
2016-07-31 07:22:06 -03:00
|
|
|
sitl = util.start_SITL(atype)
|
2013-04-06 02:56:31 -03:00
|
|
|
log = open(logfile, mode='w')
|
2016-07-31 07:22:06 -03:00
|
|
|
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")
|
2013-04-17 08:36:13 -03:00
|
|
|
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):
|
2013-04-17 08:36:13 -03:00
|
|
|
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)
|
2016-07-31 07:22:06 -03:00
|
|
|
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
|
|
|
|
|
2013-04-18 21:24:35 -03:00
|
|
|
vehicle = os.path.basename(os.getcwd())
|
|
|
|
dump_logs(vehicle)
|