harden UBX parsing/dispatch and report peer-side disconnects in GUI

A struct size-mismatch or any other parse error in a listener could
propagate uncaught out of the socket-reading thread and silently kill
it. Catch broadly in the event loop and per-listener in call_listener,
and make the NAV-SAT/NAV-SIG/RXM-RAWX group parsers tolerate a
payload length that isn't an exact multiple of the group size instead
of crashing on a short struct.unpack.

Also wire NetworkBackend's socket-loss detection through to
ReceiverManager (via a queued signal, since the callback fires from
the backend thread) so the GUI reflects a peer-initiated disconnect
instead of leaving the row stuck showing "connected". Verified against
a real ZED-X20P: it drops the TCP session on its own after ~20-28s
regardless of traffic; the GUI now marks the receiver disconnected and
frees its ID for reconnecting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AzmCaNjDb3TAqPpTwunKTY
This commit is contained in:
2026-07-15 22:00:29 +02:00
co-authored by Claude Sonnet 5
parent 3f6f403b7b
commit b3447a28c5
5 changed files with 31 additions and 7 deletions
+6 -1
View File
@@ -10,11 +10,12 @@ from backend.a_backend import ABackend
class NetworkBackend(ABackend):
def __init__(self, servers: list[dict]):
def __init__(self, servers: list[dict], on_disconnect=None):
self.sel = None
self.sock_list = [{'name': s['name'], 'addr': (socket.gethostbyname(s['host']), s['port']), 'xcvr': None, 'queue': Queue()} for s in servers]
self.thread = Thread(target=self.event_loop)
self.loop_enable = True
self.on_disconnect = on_disconnect
def send(self, xcvr: ATransceiver, data: bytes):
sock = self.find_by_name(xcvr.name)
@@ -89,6 +90,10 @@ class NetworkBackend(ABackend):
print(f"Connection {sock['name']} to {sock['addr']} lost: {exc}")
self.sel.unregister(key.fileobj)
key.fileobj.close()
if self.on_disconnect:
self.on_disconnect(sock['name'])
except Exception as exc:
print(f"Connection {sock['name']}: error processing data, ignoring: {exc}")
except KeyboardInterrupt:
print("Caught keyboard interrupt, exiting")