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
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
import struct
|
|
from ubx.messages.msg import UbxMsg
|
|
|
|
class Sig(UbxMsg):
|
|
def __init__(self):
|
|
UbxMsg.__init__(self, 0x01, 0x43)
|
|
|
|
class Group1:
|
|
@classmethod
|
|
def from_bytes(cls, data: bytes):
|
|
obj = Sig.Group1()
|
|
obj.gnss_id = struct.unpack("B", data[0:1])[0]
|
|
obj.sv_id = struct.unpack("B", data[1:2])[0]
|
|
obj.sig_id = struct.unpack("B", data[2:3])[0]
|
|
obj.freq_id = struct.unpack("B", data[3:4])[0]
|
|
obj.pr_res = struct.unpack("<H", data[4:6])[0]
|
|
obj.cno = struct.unpack("B", data[6:7])[0]
|
|
obj.quality_ind = struct.unpack("B", data[7:8])[0]
|
|
obj.corr_source = struct.unpack("B", data[8:9])[0]
|
|
obj.iono_model = struct.unpack("B", data[9:10])[0]
|
|
obj.sig_flags = struct.unpack("<H", data[10:12])[0]
|
|
obj.reserved1 = struct.unpack("BBBB", data[12:16])[0]
|
|
return obj.__dict__
|
|
|
|
@classmethod
|
|
def from_bytes(cls, data: bytes):
|
|
obj = Sig()
|
|
obj.iTOW = struct.unpack("<L", data[0:4])[0]
|
|
obj.version = struct.unpack("B", data[4:5])[0]
|
|
obj.num_signals = struct.unpack("B", data[5:6])[0]
|
|
obj.reserved = struct.unpack("BB", data[6:8])[0]
|
|
obj.signals = []
|
|
offset = 8
|
|
remain = len(data) - offset
|
|
group_size = 16
|
|
n = offset
|
|
while remain >= group_size:
|
|
signal = cls.Group1.from_bytes(data[n:n + group_size])
|
|
n += group_size
|
|
remain -= group_size
|
|
obj.signals.append(signal)
|
|
if remain:
|
|
print(f"Sig.from_bytes: {remain} trailing bytes unparsed (payload size mismatch)")
|
|
return obj.__dict__
|
|
|
|
class Sat(UbxMsg):
|
|
def __init__(self):
|
|
UbxMsg.__init__(self, 0x01, 0x35)
|
|
|
|
class Group1:
|
|
@classmethod
|
|
def from_bytes(cls, data: bytes):
|
|
obj = Sat.Group1()
|
|
obj.gnss_id = struct.unpack("B", data[0:1])[0]
|
|
obj.sv_id = struct.unpack("B", data[1:2])[0]
|
|
obj.cno = struct.unpack("B", data[2:3])[0]
|
|
obj.elev = struct.unpack("B", data[3:4])[0]
|
|
obj.azim = struct.unpack("<h", data[4:6])[0]
|
|
obj.pr_res = struct.unpack("<h", data[6:8])[0]
|
|
obj.flags = struct.unpack("<I", data[8:12])[0]
|
|
return obj.__dict__
|
|
|
|
@classmethod
|
|
def from_bytes(cls, data: bytes):
|
|
obj = Sat()
|
|
obj.iTOW = struct.unpack("<L", data[0:4])[0]
|
|
obj.version = struct.unpack("B", data[4:5])[0]
|
|
obj.num_sv = struct.unpack("B", data[5:6])[0]
|
|
obj.reserved0 = struct.unpack("BB", data[6:8])[0]
|
|
obj.satellites = []
|
|
offset = 8
|
|
remain = len(data) - offset
|
|
group_size = 12
|
|
n = offset
|
|
while remain >= group_size:
|
|
satellite = cls.Group1.from_bytes(data[n:n + group_size])
|
|
n += group_size
|
|
remain -= group_size
|
|
obj.satellites.append(satellite)
|
|
if remain:
|
|
print(f"Sat.from_bytes: {remain} trailing bytes unparsed (payload size mismatch)")
|
|
return obj.__dict__
|