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,6 +1,7 @@
"""QML-facing controller for the live/review wafer dashboard."""
from __future__ import annotations
import logging
import time
from typing import Any, Optional
from PySide6.QtCore import QObject, Property, QTimer, Qt, Signal, Slot
@@ -325,10 +326,7 @@ class SessionController(QObject):
result = -result
values.append(result)
# Create a mock timestamp or use elapsed time since start.
# We don't have a time value from the binary stream header right now.
t = seq * 0.05 # approx 20Hz if seq increments 1 per frame
return Frame(seq=seq, time=t, values=values)
return Frame(seq=seq, time=time.monotonic(), values=values)
# Clear out any old data from the prev sessions
self._model.reset()
+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,14 +186,12 @@ 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")
buf = bytearray(initial_bytes)