fix(sfm): RADIO RING detection ignores bytes inside frames
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
This commit is contained in:
1 parent
82b91835fb
commit
52ada0215c
2 files changed
+106
-7
No files matched your search
+26
-7
@@ -29,12 +29,21 @@ class RingDetected(Exception):
|
||||
|
||||
|
||||
class RingWatchTransport(BaseTransport):
|
||||
"""Passes bytes through; raises RingDetected the moment RADIO RING appears,
|
||||
including when it is split across two reads."""
|
||||
"""Passes bytes through; raises RingDetected the moment RADIO RING appears
|
||||
OUTSIDE a frame, including when it is split across two reads.
|
||||
|
||||
Inside a frame the bytes are data: the 0x2C call-home config block's dial
|
||||
string is literally "RADIO RING". A frame runs from STX to an unescaped
|
||||
ETX; inside it DLE escapes the next byte.
|
||||
"""
|
||||
|
||||
_STX, _ETX, _DLE = 0x02, 0x03, 0x10
|
||||
|
||||
def __init__(self, inner: BaseTransport) -> None:
|
||||
self._inner = inner
|
||||
self._tail = b""
|
||||
self._in_frame = False
|
||||
self._escaped = False
|
||||
|
||||
def connect(self) -> None:
|
||||
self._inner.connect()
|
||||
@@ -51,12 +60,22 @@ class RingWatchTransport(BaseTransport):
|
||||
|
||||
def read(self, n: int) -> bytes:
|
||||
data = self._inner.read(n)
|
||||
if data:
|
||||
window = self._tail + data
|
||||
if RING in window:
|
||||
for b in data:
|
||||
if self._in_frame:
|
||||
if self._escaped:
|
||||
self._escaped = False
|
||||
elif b == self._DLE:
|
||||
self._escaped = True
|
||||
elif b == self._ETX:
|
||||
self._in_frame = False
|
||||
elif b == self._STX:
|
||||
self._in_frame = True
|
||||
self._tail = b""
|
||||
raise RingDetected("RADIO RING")
|
||||
self._tail = window[-(len(RING) - 1):]
|
||||
else:
|
||||
self._tail = (self._tail + bytes([b]))[-len(RING):]
|
||||
if self._tail == RING:
|
||||
self._tail = b""
|
||||
raise RingDetected("RADIO RING")
|
||||
return data
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user