Skip to content

Commit

Permalink
added rewrite_log.py example
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Oct 9, 2024
1 parent df16b4b commit a734079
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions examples/rewrite_log.py
Original file line number Diff line number Diff line change
@@ -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("<ffiiiIB", m.Range, m.Uncertainty, int(-35.28230025*1e7), int(149.00661081*1e7), 58400, m.TS, m.Idx)
if len(buf2) != len(buf):
print("Buffer length error", m)
sys.exit(1)
buf = buf2
output.write(buf)

bar = Bar('Processing log', max=100)

pct = 0

while True:
m = login.recv_msg()
write_message(m)

new_pct = (login.offset * 100) // login.data_len
if new_pct != pct:
bar.next()
pct = new_pct

0 comments on commit a734079

Please sign in to comment.