3 Allows connection of the uBlox u-Center software to 4 a uBlox GPS device connected to a PX4 or Pixhawk device, 5 using Mavlink's SERIAL_CONTROL support to route serial 6 traffic to/from the GPS, and exposing the data to u-Center 7 via a local TCP connection. 9 @author: Matthew Lloyd (github@matthewlloyd.net) 11 from __future__
import print_function
13 from pymavlink
import mavutil
14 from argparse
import ArgumentParser
19 parser = ArgumentParser(description=__doc__)
20 parser.add_argument(
"--mavport", required=
True,
21 help=
"Mavlink port name")
22 parser.add_argument(
"--mavbaud", type=int,
23 help=
"Mavlink port baud rate", default=115200)
24 parser.add_argument(
"--devnum", default=2, type=int,
25 help=
"PX4 UART device number (defaults to GPS port)")
26 parser.add_argument(
"--devbaud", default=115200, type=int,
27 help=
"PX4 UART baud rate (defaults to u-Blox GPS baud)")
28 parser.add_argument(
"--tcpport", default=2001, type=int,
29 help=
"local TCP port (defaults to %(default)s)")
30 parser.add_argument(
"--tcpaddr", default=
'127.0.0.1', type=str,
31 help=
"local TCP address (defaults to %(default)s)")
32 parser.add_argument(
"--debug", default=0, type=int,
34 parser.add_argument(
"--buffsize", default=128, type=int,
36 parser.add_argument(
"--login", default=
None, help=
"input log file")
37 parser.add_argument(
"--logout", default=
None, help=
"output log file")
38 args = parser.parse_args()
40 print(
"Connecting to MAVLINK...")
42 args.mavport, args.mavbaud,
43 devnum=args.devnum, devbaud=args.devbaud, debug=args.debug)
45 listen_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
46 listen_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
47 listen_sock.bind((args.tcpaddr, args.tcpport))
50 print(
"Waiting for a TCP connection.")
51 print(
"Use tcp://%s:%d in u-Center." % (args.tcpaddr, args.tcpport))
52 conn_sock, addr = listen_sock.accept()
53 conn_sock.setblocking(0)
54 print(
"TCP connection accepted. Use Ctrl+C to exit.")
59 login = open(args.login,
"w")
61 logout = open(args.logout,
"w")
65 data = conn_sock.recv(args.buffsize)
71 mav_serialport.write(data)
75 data = mav_serialport.read(args.buffsize)
84 if __name__ ==
'__main__':