def process(filename): '''process one logfile''' print("Processing %s" % filename) mlog = mavutil.mavlink_connection(filename, notimestamps=opts.notimestamps, robust_parsing=opts.robust) output = None count = 1 dirname = os.path.dirname(filename) while True: m = mlog.recv_match(condition=opts.condition) if m is None: break if mlog.flightmode.upper() == opts.mode.upper(): if output is None: path = os.path.join(dirname, "%s%u.tlog" % (opts.mode, count)) count += 1 print("Creating %s" % path) output = mavutil.mavlogfile(path, write=True) else: if output is not None: output.close() output = None if output and m.get_type() != 'BAD_DATA': timestamp = getattr(m, '_timestamp', None) output.write(struct.pack('>Q', timestamp * 1.0e6)) output.write(m.get_msgbuf())
def process(filename): '''process one logfile''' print("Processing %s" % filename) mlog = mavutil.mavlink_connection(filename, notimestamps=opts.notimestamps, robust_parsing=opts.robust) output = None count = 1 dirname = os.path.dirname(filename) while True: m = mlog.recv_match(condition=opts.condition) if m is None: break if mlog.flightmode.upper() == opts.mode.upper(): if output is None: path = os.path.join(dirname, "%s%u.tlog" % (opts.mode, count)) count += 1 print("Creating %s" % path) output = mavutil.mavlogfile(path, write=True) else: if output is not None: output.close() output = None if output and m.get_type() != 'BAD_DATA': timestamp = getattr(m, '_timestamp', None) output.write(struct.pack('>Q', timestamp*1.0e6)) output.write(m.get_msgbuf())
def run(self): _log.info("Запускаюсь. Использую url:") # mav1 = mavutil.mavlink_connection("udpin:0.0.0.0:22466") mav2 = mavutil.mavlink_connection("udpin:0.0.0.0:22467") mav_read_file = mavutil.mavlogfile(read_file, robust_parsing= False, notimestamps= True) while True: # msg1 = mav1.recv_match(blocking=False) # msg2 = mav2.recv_match(blocking=False) msg_read_file = mav_read_file.recv_match(blocking=False) # if msg1: # self.process_message(msg1) # if self.uplink_msgs: # print(self.uplink_msgs) # mav1.write(self.uplink_msgs) # self.uplink_msgs = [] # if msg2: # self.process_message(msg2) # if self.uplink_msgs: # mav2.write(self.uplink_msgs) # self.uplink_msgs = [] if msg_read_file: self.process_message(msg_read_file)
def read_log_file(path_to_log_file, timestamps): mav_read_file = mavutil.mavlogfile(path_to_log_file, robust_parsing=True, notimestamps=(not timestamps)) while True: msg_read = mav_read_file.recv_match(blocking=False) if msg_read == None: break print(msg_read)
def main(argv): parser = argparse.ArgumentParser("tm parser to csvs", add_help=True) parser.add_argument("-i,--input", nargs="?", dest="input", required=True) parser.add_argument("-o,--output_dir", nargs="?", dest="output_dir", help="If output is None, input filename is name for output directory", default=None) parser.add_argument("--notimestamps", dest="notimestamps", default=False, action='store_true') args = parser.parse_args(argv) base_path = args.output_dir f = args.input notimestamps = args.notimestamps if not base_path: fname = os.path.split(f)[1] base_path = os.path.splitext(fname)[0] if not os.path.isdir(base_path): os.makedirs(base_path, exist_ok=True) con = mavutil.mavlogfile(f, notimestamps=notimestamps) processors = {} bad_data_bytes = 0 while True: msg = con.recv_msg() if not msg: break msg_id = msg.get_msgId() if msg_id < 0: bad_data_bytes += 1 continue msg_hdr = msg.get_header() msg_key = "%s-%s-%s" % (msg_id, msg_hdr.srcSystem, msg_hdr.srcComponent) if msg_key not in processors: processor = MsgProcessor(base_path, notimestamps=notimestamps) processors.update({msg_key: processor}) processor = processors[msg_key] processor.accept(msg) print("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-") print("Stats in total:") for msg_key, processor in processors.items(): print("%s-%s: %d messages" % (processor.msg_class.name, msg_key, processor.message_count)) print("bad data %s bytes in total" % bad_data_bytes)
def play_file(url, filepath, **mavlogfile_kwargs): source_mav = mavutil.mavlogfile(filepath, **mavlogfile_kwargs) target_con = mavutil.mavlink_connection(url) target_mav = target_con.mav _log.info("Играю файл %s", filepath) _log.info("Отпарвляю пакеты на url %s", url) zero_time = time.time() while True: msg = source_mav.recv_msg() if not msg: break play_time = get_msg_time(msg, zero_time) sleep_amount = play_time - time.time() _log.debug(msg) _log.debug("sleep amount: %s", sleep_amount) if sleep_amount > 0: time.sleep(sleep_amount) target_mav.send(msg)
def set_logfile(self, filename): '''provide a mavlink logfile for data''' self.mlog = mavutil.mavlogfile(filename)
from pymavlink import mavutil if len(args) < 1: print("Usage: mavlogdump.py [options] <LOGFILE>") sys.exit(1) filename = args[0] mlog = mavutil.mavlink_connection(filename, planner_format=opts.planner, notimestamps=opts.notimestamps, robust_parsing=opts.robust, dialect=opts.dialect) output = None if opts.output: output = mavutil.mavlogfile(opts.output, write=True) types = opts.types if types is not None: types = types.split(',') while True: m = mlog.recv_match(condition=opts.condition, blocking=opts.follow) if m is None: break if types is not None and m.get_type() not in types: continue last_timestamp = 0 if output and m.get_type() != 'BAD_DATA': timestamp = getattr(m, '_timestamp', None)
def set_logfile(self, filename): '''provide a mavlink logfile for data''' self.mlog = mavutil.mavlogfile(filename)
import multiprocessing import writerpool import pymavlink.dialects.v10.lapwing as mavlink import pymavlink.mavutil as mavutil parser = argparse.ArgumentParser() parser.add_argument('-f', '--infile', type=str, required=True, help='Input file') args = parser.parse_args() f = mavutil.mavlogfile(args.infile, robust_parsing=True, notimestamps=True) writerpool = writerpool.WriterPool() total_bytes = 0 msgcnt = 0 bytescnt = 0 maverrorcnt = 0 indexerrorcnt = 0 while (True): try: m2 = f.recv_msg() if (None != m2): msgcnt += 1 bytescnt += len(m2._msgbuf)
def start(self): self.connection = mavutil.mavlogfile(self.log_path, notimestamps=True) self.time_shift = None self.time_start = None
from pymavlink import mavutil if len(args) < 1: print("Usage: mavlogdump.py [options] <LOGFILE>") sys.exit(1) filename = args[0] mlog = mavutil.mavlink_connection(filename, planner_format=opts.planner, notimestamps=opts.notimestamps, robust_parsing=opts.robust, dialect=opts.dialect) output = None if opts.output: output = mavutil.mavlogfile(opts.output, write=True) types = opts.types if types is not None: types = types.split(',') while True: m = mlog.recv_match(condition=opts.condition, blocking=opts.follow) if m is None: break if types is not None and m.get_type() not in types: continue last_timestamp = 0 if output and m.get_type() != 'BAD_DATA': timestamp = getattr(m, '_timestamp', None)
import argparse import struct import binascii import multiprocessing import writerpool import pymavlink.dialects.v10.lapwing as mavlink import pymavlink.mavutil as mavutil parser = argparse.ArgumentParser() parser.add_argument('-f', '--infile', type=str, required=True, help='Input file') args = parser.parse_args() f = mavutil.mavlogfile(args.infile, robust_parsing=True, notimestamps=True) writerpool = writerpool.WriterPool() total_bytes = 0 msgcnt = 0 bytescnt = 0 maverrorcnt = 0 indexerrorcnt = 0 while (True): try: m2 = f.recv_msg() if (None != m2): msgcnt += 1 bytescnt += len(m2._msgbuf)
def set_logfile(self, filename): """provide a mavlink logfile for data""" self.mlog = mavutil.mavlogfile(filename)