36 lines
812 B
Python
Executable File
36 lines
812 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import time
|
|
|
|
from pymavlink import mavutil
|
|
|
|
if len(sys.argv) != 2:
|
|
sys.exit(f"usage: {sys.argv[0]} <serial-device>")
|
|
|
|
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)
|