bwtest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 '''
00004 check bandwidth of link
00005 '''
00006 
00007 import sys, struct, time, os
00008 
00009 from pymavlink import mavutil
00010 
00011 from argparse import ArgumentParser
00012 parser = ArgumentParser(description=__doc__)
00013 
00014 parser.add_argument("--baudrate", type=int,
00015                   help="master port baud rate", default=115200)
00016 parser.add_argument("--device", required=True, help="serial device")
00017 args = parser.parse_args()
00018 
00019 # create a mavlink serial instance
00020 master = mavutil.mavlink_connection(args.device, baud=args.baudrate)
00021 
00022 t1 = time.time()
00023 
00024 counts = {}
00025 
00026 bytes_sent = 0
00027 bytes_recv = 0
00028 
00029 while True:
00030     master.mav.heartbeat_send(1, 1)
00031     master.mav.sys_status_send(1, 2, 3, 4, 5, 6, 7)
00032     master.mav.gps_raw_send(1, 2, 3, 4, 5, 6, 7, 8, 9)
00033     master.mav.attitude_send(1, 2, 3, 4, 5, 6, 7)
00034     master.mav.vfr_hud_send(1, 2, 3, 4, 5, 6)
00035     while master.port.inWaiting() > 0:
00036         m = master.recv_msg()
00037         if m == None: break
00038         if m.get_type() not in counts:
00039             counts[m.get_type()] = 0
00040         counts[m.get_type()] += 1
00041     t2 = time.time()
00042     if t2 - t1 > 1.0:
00043         print("%u sent, %u received, %u errors bwin=%.1f kB/s bwout=%.1f kB/s" % (
00044             master.mav.total_packets_sent,
00045             master.mav.total_packets_received,
00046             master.mav.total_receive_errors,
00047             0.001*(master.mav.total_bytes_received-bytes_recv)/(t2-t1),
00048             0.001*(master.mav.total_bytes_sent-bytes_sent)/(t2-t1)))
00049         bytes_sent = master.mav.total_bytes_sent
00050         bytes_recv = master.mav.total_bytes_received
00051         t1 = t2


mavlink
Author(s): Lorenz Meier
autogenerated on Thu Jun 6 2019 19:01:57