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.""" """QML-facing controller for the live/review wafer dashboard."""
from __future__ import annotations from __future__ import annotations
import logging import logging
import time
from typing import Any, Optional from typing import Any, Optional
from PySide6.QtCore import QObject, Property, QTimer, Qt, Signal, Slot from PySide6.QtCore import QObject, Property, QTimer, Qt, Signal, Slot
@@ -325,10 +326,7 @@ class SessionController(QObject):
result = -result result = -result
values.append(result) values.append(result)
# Create a mock timestamp or use elapsed time since start. return Frame(seq=seq, time=time.monotonic(), values=values)
# 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)
# Clear out any old data from the prev sessions # Clear out any old data from the prev sessions
self._model.reset() self._model.reset()
+1 -15
View File
@@ -32,18 +32,6 @@ class StreamReader:
self._thread = threading.Thread(target=self._run, daemon = True) self._thread = threading.Thread(target=self._run, daemon = True)
self._thread.start() 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: def _run(self) -> None:
try: try:
# Check the first few bytes to determine if the wafer is streaming binary, ASCII hex dump, or text lines. # 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) values.append(0.0)
try: try:
frame = Frame(seq=seq, time=seq * 0.1, values=values) frame = Frame(seq=seq, time=time.monotonic(), values=values)
self._on_frame(frame) self._on_frame(frame)
seq += 1 seq += 1
except Exception as exc: except Exception as exc:
log.error("Error emitting ASCII frame: %s", exc) log.error("Error emitting ASCII frame: %s", exc)
time.sleep(0.05)
def _run_text_lines(self, initial_bytes: bytes) -> None: def _run_text_lines(self, initial_bytes: bytes) -> None:
log.info("StreamReader: starting line-by-line ASCII text parsing") log.info("StreamReader: starting line-by-line ASCII text parsing")