-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtester.py
More file actions
51 lines (43 loc) · 1.72 KB
/
Copy pathtester.py
File metadata and controls
51 lines (43 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from digi.xbee.devices import DigiMeshDevice, RemoteXBeeDevice
from digi.xbee.models.address import XBee64BitAddress
from digi.xbee.exception import XBeeException
from pymavlink import mavutil
import time
PORT = "/dev/cu.usbserial-AQ015EBI" # from your diagnostic
BAUD = 9600 # BD=3 on the radio
REMOTE_ADDR = "0013A20041D365C4" # remote node 64-bit (SH+SL)
# MAVLink over UDP (baud irrelevant here)
master = mavutil.mavlink_connection('udpout:localhost:14550')
def main():
xbee = DigiMeshDevice(PORT, BAUD)
try:
xbee.open()
# Sanity: ensure we’re really on DigiMesh+API
assert xbee.get_protocol().name == "DIGI_MES"
"H"
remote = RemoteXBeeDevice(xbee, XBee64BitAddress.from_hex_string(REMOTE_ADDR))
print("XBee connected. Sending MAVLink heartbeats...")
while True:
hb = master.mav.heartbeat_encode(
mavutil.mavlink.MAV_TYPE_GENERIC,
mavutil.mavlink.MAV_AUTOPILOT_GENERIC,
0, 0, 0, 0
)
payload = hb.pack(master.mav)
try:
xbee.send_data(remote, bytes(payload))
print("Sent MAVLink heartbeat")
except XBeeException as e:
# Print precise TX cause if the radio reports one
status = getattr(e, "status", None)
if status is not None:
print(f"TX Error: {status.name} ({status.value})")
else:
print("TX Error:", repr(e))
time.sleep(1)
finally:
if 'xbee' in locals() and xbee.is_open():
xbee.close()
print("XBee connection closed.")
if __name__ == "__main__":
main()