From 2d35d935b4588968e9e8434663fe56d751f7ab30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Onur=20=C3=96zkan?= Date: Tue, 21 Jul 2026 12:51:43 +0300 Subject: [PATCH] scripts: rename read-mavlink -> test-mavlink with writings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onur Özkan --- scripts/read-mavlink.py | 14 -------------- scripts/test-mavlink.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 14 deletions(-) delete mode 100755 scripts/read-mavlink.py create mode 100755 scripts/test-mavlink.py 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)