Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/scripts/du32_change.py
Views: 1798
#!/usr/bin/env python12"""3Parses a log file and shows how Copter's du32 changes over time45AP_FLAKE8_CLEAN67"""89from __future__ import print_function1011import optparse12import sys13import time1415from pymavlink import mavutil161718class DU32Change(object):19def __init__(self, master):20self.master = master2122def progress(self, text):23'''emit text with possible timestamps etc'''24print("%u: %s" % (time.time(), text))2526def run(self):2728self.progress("Creating connection")29self.conn = mavutil.mavlink_connection(master)3031# this eas was generated from Copter.h's structure for ap_t:32bit_descriptions_list = [33"unused1",34"unused_was_simple_mode bit1",35"unused_was_simple_mode bit2",36"pre_arm_rc_check",37"pre_arm_check",38"auto_armed",39"logging_started",40"land_complete",41"new_radio_frame",42"usb_connected_unused",43"rc_receiver_present_unused",44"compass_mot",45"motor_test",46"initialised",47"land_complete_maybe",48"throttle_zero",49"system_time_set_unused",50"gps_glitching",51"using_interlock",52"land_repo_active",53"motor_interlock_switch",54"in_arming_delay",55"initialised_params",56"unused3",57"unused2",58"armed_with_airmode_switch",59"prec_land_active",60]61bit_descriptions = {}62count = 063for bit in bit_descriptions_list:64bit_descriptions[bit] = count65count += 16667old_m = None6869desired_type = "DU32"70while True:71m = self.conn.recv_match(type=desired_type)72if m is None:73break74if m.Id != 7:75# 7 is LOG_DATA_ID from AP_Logger.h76continue77if old_m is not None and m.Value == old_m.Value:78continue79line = ""80if old_m is None:81for bit in sorted(bit_descriptions.keys()):82bit_set = m.Value & (1 << bit_descriptions[bit])83if bit_set:84print("Original %s: 1" % bit)85else:86print("Original %s: 0" % bit)87else:88for bit in bit_descriptions.keys():89old_bit_set = old_m.Value & (1 << bit_descriptions[bit])90new_bit_set = m.Value & (1 << bit_descriptions[bit])91if new_bit_set and not old_bit_set:92line += " +%s" % bit93elif not new_bit_set and old_bit_set:94line += " -%s" % bit9596timestamp = getattr(m, '_timestamp', 0.0)97formatted_timestamp = "%s.%02u" % (98time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)),99int(timestamp * 100.0) % 100)100101print("%s: %s" % (formatted_timestamp, line))102old_m = m103104105if __name__ == '__main__':106parser = optparse.OptionParser("du32_change.py [options]")107108(opts, args) = parser.parse_args()109110if len(args) < 1:111parser.print_help()112sys.exit(1)113114master = args[0]115116tester = DU32Change(master)117tester.run()118119120