From c0ae0dc87f8356f5fdabf94e8b548dcd1c00ed39 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 9 Sep 2024 15:05:43 +1000 Subject: [PATCH] mavproxy_link.py: add bytes-available-to-read counter in link stats output --- MAVProxy/modules/mavproxy_link.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/MAVProxy/modules/mavproxy_link.py b/MAVProxy/modules/mavproxy_link.py index ad199efaba..5d2e60a278 100644 --- a/MAVProxy/modules/mavproxy_link.py +++ b/MAVProxy/modules/mavproxy_link.py @@ -306,7 +306,18 @@ def show_link(self): except AttributeError: # some mav objects may not have a "signing" attribute pass - print("link %s %s (%u packets, %u bytes, %.2fs delay, %u lost, %.1f%% loss, rate:%uB/s%s)" % ( + + # 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 = f" avail={bytes_available}" + except (AttributeError, ImportError): + pass + + print("link %s %s (%u packets, %u bytes, %.2fs delay, %u lost, %.1f%% loss, rate:%uB/s%s%s)" % ( self.link_label(master), status, self.status.counters['MasterIn'][master.linknum], @@ -316,6 +327,7 @@ def show_link(self): master.packet_loss(), self.status.bytecounters['MasterIn'][master.linknum].rate(), sign_string, + bytes_available )) def reset_link_stats(self):