Last active
March 30, 2023 13:33
-
-
Save okalachev/ad44863ba0942372d38f82aaee135f80 to your computer and use it in GitHub Desktop.
MAVLink monitor tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
"""MAVLink Monitor | |
Monitor MAVLink packages from a serial port, UDP, or TCP link. | |
Usage: | |
mavlink_monitor.py [--dialect=<dialect>] [-b] <url> | |
mavlink_monitor.py (-h | --help) | |
Options: | |
--dialect=<dialect> MAVLink dialect [default: common] | |
-b Send HEARTBEAT | |
<url> Connection link URL in Pymavlink format | |
-h --help Show this screen | |
Examples: | |
./mavlink_monitor.py -b /dev/ttyACM0 | |
./mavlink_monitor.py udpin:localhost:14540 | |
""" | |
from docopt import docopt | |
arguments = docopt(__doc__) | |
from pymavlink import mavutil | |
mavutil.set_dialect(arguments['--dialect']) | |
fd = mavutil.mavlink_connection(arguments['<url>'], source_system=255, source_component=0) | |
if arguments['-b']: | |
fd.mav.heartbeat_send(mavutil.mavlink.MAV_TYPE_GCS, mavutil.mavlink.MAV_AUTOPILOT_INVALID, 0, 0, 0) | |
try: | |
while True: | |
msg = fd.recv_match(blocking=True) | |
if not msg: | |
continue | |
print(msg) | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment