12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- '''
- connect as a client to two tcpip ports on localhost with mavlink packets. pass them both directions, and show packets in human-readable format on-screen.
- this is useful if
- * you have two SITL instances you want to connect to each other and see the comms.
- * you have any tcpip based mavlink happening, and want something better than tcpdump
- hint:
- * you can use netcat/nc to do interesting redorection things with each end if you want to.
- Copyright Sept 2012 David "Buzz" Bussenschutt
- Released under GNU GPL version 3 or later
- '''
- from __future__ import print_function
- import time
- from pymavlink import mavutil
- from argparse import ArgumentParser
- parser = ArgumentParser(description=__doc__)
- parser.add_argument("srcport", type=int)
- parser.add_argument("dstport", type=int)
- args = parser.parse_args()
- msrc = mavutil.mavlink_connection('tcp:localhost:{}'.format(args.srcport), planner_format=False,
- notimestamps=True,
- robust_parsing=True)
- mdst = mavutil.mavlink_connection('tcp:localhost:{}'.format(args.dstport), planner_format=False,
- notimestamps=True,
- robust_parsing=True)
- msrc.logfile_raw = mdst
- mdst.logfile_raw = msrc
- while True:
-
- l = msrc.recv_match();
- if l is not None:
- l_last_timestamp = 0
- if l.get_type() != 'BAD_DATA':
- l_timestamp = getattr(l, '_timestamp', None)
- if not l_timestamp:
- l_timestamp = l_last_timestamp
- l_last_timestamp = l_timestamp
- print("--> %s.%02u: %s\n" % (
- time.strftime("%Y-%m-%d %H:%M:%S",
- time.localtime(l._timestamp)),
- int(l._timestamp*100.0)%100, l))
-
- r = mdst.recv_match();
- if r is not None:
- r_last_timestamp = 0
- if r.get_type() != 'BAD_DATA':
- r_timestamp = getattr(r, '_timestamp', None)
- if not r_timestamp:
- r_timestamp = r_last_timestamp
- r_last_timestamp = r_timestamp
- print("<-- %s.%02u: %s\n" % (
- time.strftime("%Y-%m-%d %H:%M:%S",
- time.localtime(r._timestamp)),
- int(r._timestamp*100.0)%100, r))
|