From a7340796319e53352532396e432b17e64009d8b8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Oct 2024 15:52:30 +1100 Subject: [PATCH] added rewrite_log.py example --- examples/rewrite_log.py | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 examples/rewrite_log.py diff --git a/examples/rewrite_log.py b/examples/rewrite_log.py new file mode 100755 index 000000000..2ce9fdcd5 --- /dev/null +++ b/examples/rewrite_log.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +''' +example of rewriting a log with changed values + +this can be useful when wanting to replay a log with different values +''' + +import os +from argparse import ArgumentParser +from progress.bar import Bar +import time +import struct +import sys + +parser = ArgumentParser(description=__doc__) + +parser.add_argument("login") +parser.add_argument("logout") + +args = parser.parse_args() + +from pymavlink import mavutil +from pymavlink import DFReader +import struct + +print("Opening %s" % args.login) +login = mavutil.mavlink_connection(args.login) +output = open(args.logout, mode='wb') + +def write_message(m): + mtype = m.get_type() + buf = bytearray(m.get_msgbuf()) + if mtype == 'RRLT' and m.Idx == 2: + # fix beacon location + buf2 = buf[:3] + struct.pack("