diff --git a/scripts/read-mavlink.py b/scripts/read-mavlink.py deleted file mode 100755 index 674d1d0..0000000 --- a/scripts/read-mavlink.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python3 - -# NixOS: nix-shell -p 'python313.withPackages (ps: [ ps.pymavlink ps.pyserial ])' --run './scripts/read-mavlink.py /dev/ttyUSB0' - -import sys - -from pymavlink import mavutil - -if len(sys.argv) != 2: - sys.exit(f"usage: {sys.argv[0]} ") - -connection = mavutil.mavlink_connection(sys.argv[1], baud=115200) -while message := connection.recv_match(blocking=True): - print(message) diff --git a/scripts/test-mavlink.py b/scripts/test-mavlink.py new file mode 100755 index 0000000..92d2749 --- /dev/null +++ b/scripts/test-mavlink.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +import sys +import time + +from pymavlink import mavutil + +if len(sys.argv) != 2: + sys.exit(f"usage: {sys.argv[0]} ") + +connection = mavutil.mavlink_connection(sys.argv[1], baud=115200) +next_timesync = 0.0 +next_ping = 0.0 +ping_sequence = 0 + +while True: + now = time.monotonic() + if now >= next_timesync: + connection.mav.timesync_send(0, time.monotonic_ns() // 1_000) + next_timesync = now + 0.2 + + if now >= next_ping: + connection.mav.ping_send( + int(time.time_ns() // 1_000), + ping_sequence, + 0, + 0, + ) + ping_sequence = (ping_sequence + 1) & 0xFFFFFFFF + next_ping = now + 0.1 + + while message := connection.recv_match(blocking=False): + print(message) + + time.sleep(0.01)