Skip to content

Commit

Permalink
mavproxy_link: Windows support for bytes-available
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Sep 13, 2024
1 parent b103fba commit c3baa38
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions MAVProxy/modules/mavproxy_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,28 @@ def cmd_hl(self, args):
else:
print("usage: hl <on|off>")

def bytes_available_for_reading(self, sock):
if self.mpstate.system == 'Windows':
print("Windows")
try:
import ctypes
import ctypes.wintypes
bytes_available = ctypes.wintypes.DWORD()
FIONREAD = 0x4004667F
ctypes.windll.ws2_32.ioctlsocket(sock.fileno(), FIONREAD, ctypes.byref(bytes_available))
return bytes_available.value
except (AttributeError, ImportError):
pass
return None

bytes_available = ""
try:
import fcntl
return struct.unpack('I', fcntl.ioctl(sock, 0x541B, struct.pack('I', 0)))[0]
except (AttributeError, ImportError):
pass
return None

def show_link(self):
'''show link information'''
for master in self.mpstate.mav_master:
Expand All @@ -309,14 +331,11 @@ def show_link(self):
pass

# add an entry for bytes-available-to-read:
bytes_available = ""
try:
import fcntl
sock = master.port
bytes_available = struct.unpack('I', fcntl.ioctl(sock, 0x541B, struct.pack('I', 0)))[0]
bytes_available = self.bytes_available_for_reading(master.port)
if bytes_available is not None:
bytes_available = f" avail={bytes_available}"
except (AttributeError, ImportError):
pass
else:
bytes_available = ""

print("link %s %s (%u packets, %u bytes, %.2fs delay, %u lost, %.1f%% loss, rate:%uB/s%s%s)" % (
self.link_label(master),
Expand Down

0 comments on commit c3baa38

Please sign in to comment.