ardupilot/Tools/scripts/powr_change.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
2.8 KiB
Python
Raw Normal View History

Tools: add powr_change.py Simpler to work out what's gone wrong in a log this way: pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$ ./powr_change.py /tmp/00000109.BIN 1644894818: Creating connection 2022-02-14 00:30:25.91: +MAV_POWER_STATUS_BRICK_VALID +MAV_POWER_STATUS_SERVO_VALID 2022-02-14 00:33:15.46: +MAV_POWER_STATUS_CHANGED 2022-02-14 00:33:34.96: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:33:35.06: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.86: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.96: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.46: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.56: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.45: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.55: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.85: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.95: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.25: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.35: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.75: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.85: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:51.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:38:01.89: -MAV_POWER_STATUS_CHANGED pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$
2022-02-14 23:15:22 -04:00
#!/usr/bin/env python
"""
Parses a log file and shows how the power flags changed over time
AP_FLAKE8_CLEAN
"""
from __future__ import print_function
import optparse
import sys
import time
from pymavlink import mavutil
class POWRChange(object):
def __init__(self, master):
self.master = master
def progress(self, text):
'''emit text with possible timestamps etc'''
print("%u: %s" % (time.time(), text))
def bit_description(self, bit_number):
if 1 << bit_number not in mavutil.mavlink.enums["MAV_POWER_STATUS"]:
return "UNKNOWN_BIT[%u]" % bit_number
name = mavutil.mavlink.enums["MAV_POWER_STATUS"][1 << bit_number].name
# return name with common prefix removed:
return name[len("MAV_POWER_STATUS_"):]
Tools: add powr_change.py Simpler to work out what's gone wrong in a log this way: pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$ ./powr_change.py /tmp/00000109.BIN 1644894818: Creating connection 2022-02-14 00:30:25.91: +MAV_POWER_STATUS_BRICK_VALID +MAV_POWER_STATUS_SERVO_VALID 2022-02-14 00:33:15.46: +MAV_POWER_STATUS_CHANGED 2022-02-14 00:33:34.96: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:33:35.06: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.86: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.96: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.46: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.56: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.45: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.55: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.85: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.95: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.25: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.35: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.75: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.85: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:51.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:38:01.89: -MAV_POWER_STATUS_CHANGED pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$
2022-02-14 23:15:22 -04:00
def run(self):
self.progress("Creating connection")
self.conn = mavutil.mavlink_connection(master)
desired_type = "POWR"
current = None
while True:
m = self.conn.recv_match(type=desired_type)
if m is None:
break
if current is None:
current_flags = 0
current_accflags = 0
have_accflags = hasattr(m, "AccFlags")
Tools: add powr_change.py Simpler to work out what's gone wrong in a log this way: pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$ ./powr_change.py /tmp/00000109.BIN 1644894818: Creating connection 2022-02-14 00:30:25.91: +MAV_POWER_STATUS_BRICK_VALID +MAV_POWER_STATUS_SERVO_VALID 2022-02-14 00:33:15.46: +MAV_POWER_STATUS_CHANGED 2022-02-14 00:33:34.96: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:33:35.06: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.86: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.96: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.46: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.56: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.45: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.55: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.85: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.95: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.25: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.35: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.75: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.85: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:51.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:38:01.89: -MAV_POWER_STATUS_CHANGED pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$
2022-02-14 23:15:22 -04:00
else:
current_flags = current.Flags
if have_accflags:
current_accflags = current.AccFlags
Tools: add powr_change.py Simpler to work out what's gone wrong in a log this way: pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$ ./powr_change.py /tmp/00000109.BIN 1644894818: Creating connection 2022-02-14 00:30:25.91: +MAV_POWER_STATUS_BRICK_VALID +MAV_POWER_STATUS_SERVO_VALID 2022-02-14 00:33:15.46: +MAV_POWER_STATUS_CHANGED 2022-02-14 00:33:34.96: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:33:35.06: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.86: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.96: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.46: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.56: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.45: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.55: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.85: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.95: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.25: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.35: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.75: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.85: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:51.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:38:01.89: -MAV_POWER_STATUS_CHANGED pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$
2022-02-14 23:15:22 -04:00
flags = m.Flags
line = ""
for bit in range(0, 32): # range?
mask = 1 << bit
old_bit_set = current_flags & mask
new_bit_set = flags & mask
if new_bit_set and not old_bit_set:
line += " +%s" % self.bit_description(bit)
elif not new_bit_set and old_bit_set:
line += " -%s" % self.bit_description(bit)
if have_accflags:
accflags = m.AccFlags
old_acc_bit_set = current_accflags & mask
new_acc_bit_set = accflags & mask
if new_acc_bit_set and not old_acc_bit_set:
line += " ACCFLAGS+%s" % self.bit_description(bit)
if len(line) == 0:
continue
Tools: add powr_change.py Simpler to work out what's gone wrong in a log this way: pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$ ./powr_change.py /tmp/00000109.BIN 1644894818: Creating connection 2022-02-14 00:30:25.91: +MAV_POWER_STATUS_BRICK_VALID +MAV_POWER_STATUS_SERVO_VALID 2022-02-14 00:33:15.46: +MAV_POWER_STATUS_CHANGED 2022-02-14 00:33:34.96: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:33:35.06: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.86: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:16.96: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.46: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:38.56: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:40.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.45: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:41.55: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.85: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:45.95: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:47.15: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.25: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:48.35: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.75: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:49.85: -MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:34:51.05: +MAV_POWER_STATUS_PERIPH_OVERCURRENT 2022-02-14 00:38:01.89: -MAV_POWER_STATUS_CHANGED pbarker@bluebottle:~/rc/ardupilot/Tools/scripts(master)$
2022-02-14 23:15:22 -04:00
current = m
timestamp = getattr(m, '_timestamp', 0.0)
formatted_timestamp = "%s.%02u" % (
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)),
int(timestamp * 100.0) % 100)
print("%s: %s" % (formatted_timestamp, line))
current = m
if __name__ == '__main__':
parser = optparse.OptionParser("powr_change.py [options]")
(opts, args) = parser.parse_args()
if len(args) < 1:
parser.print_help()
sys.exit(1)
master = args[0]
tester = POWRChange(master)
tester.run()