refactor: standardize timing with monotonic clocks, remove redundant stream parsing

This commit is contained in:
jack
2026-06-15 11:37:51 -07:00
parent a70764e08c
commit b34b920759
2 changed files with 3 additions and 19 deletions
+1 -15
View File
@@ -32,18 +32,6 @@ class StreamReader:
self._thread = threading.Thread(target=self._run, daemon = True)
self._thread.start()
def _read_exact(self, count: int) -> bytes | None:
"""Read exactly `count` bytes. Returns None if timed out/stopped."""
buf = bytearray()
while len(buf) < count and not self._stop.is_set():
b = self._transport.read(1)
if not b:
continue
buf.extend(b)
if self._stop.is_set():
return None
return bytes(buf)
def _run(self) -> None:
try:
# Check the first few bytes to determine if the wafer is streaming binary, ASCII hex dump, or text lines.
@@ -198,13 +186,11 @@ class StreamReader:
values.append(0.0)
try:
frame = Frame(seq=seq, time=seq * 0.1, values=values)
frame = Frame(seq=seq, time=time.monotonic(), values=values)
self._on_frame(frame)
seq += 1
except Exception as exc:
log.error("Error emitting ASCII frame: %s", exc)
time.sleep(0.05)
def _run_text_lines(self, initial_bytes: bytes) -> None:
log.info("StreamReader: starting line-by-line ASCII text parsing")