|
@@ -186,6 +186,20 @@ grpc:
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _drain_fd(fd: int) -> None:
|
|
|
|
|
+ """Drop bytes already sitting on the PTY master before hthd opens the slave."""
|
|
|
|
|
+ while True:
|
|
|
|
|
+ ready, _, _ = select.select([fd], [], [], 0)
|
|
|
|
|
+ if not ready:
|
|
|
|
|
+ return
|
|
|
|
|
+ try:
|
|
|
|
|
+ chunk = os.read(fd, 4096)
|
|
|
|
|
+ except OSError:
|
|
|
|
|
+ return
|
|
|
|
|
+ if not chunk:
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _set_raw_clocal(fd: int) -> None:
|
|
def _set_raw_clocal(fd: int) -> None:
|
|
|
"""Binary 8N1-like PTY: no ICANON (or SET_ALL never leaves the line buffer)."""
|
|
"""Binary 8N1-like PTY: no ICANON (or SET_ALL never leaves the line buffer)."""
|
|
|
attrs = termios.tcgetattr(fd)
|
|
attrs = termios.tcgetattr(fd)
|
|
@@ -271,8 +285,10 @@ class UartTap:
|
|
|
self._started.set()
|
|
self._started.set()
|
|
|
|
|
|
|
|
def holding(self) -> bool:
|
|
def holding(self) -> bool:
|
|
|
|
|
+ # Rewrite MOTOR_STATUS before hthd starts so leftover 0x47 cannot
|
|
|
|
|
+ # sit in the PTY buffer and look like an immediate startup_complete.
|
|
|
if not self._started.is_set():
|
|
if not self._started.is_set():
|
|
|
- return False
|
|
|
|
|
|
|
+ return True
|
|
|
elapsed = time.monotonic() - self._start
|
|
elapsed = time.monotonic() - self._start
|
|
|
if elapsed >= self.max_hold_s:
|
|
if elapsed >= self.max_hold_s:
|
|
|
return False
|
|
return False
|
|
@@ -678,6 +694,7 @@ def main() -> int:
|
|
|
# baud) and at least one MOTOR_STATUS rewrite, so production UART
|
|
# baud) and at least one MOTOR_STATUS rewrite, so production UART
|
|
|
# proves no GET_TEMPERATURE during delayed startup.
|
|
# proves no GET_TEMPERATURE during delayed startup.
|
|
|
tap.mark_hthd_start()
|
|
tap.mark_hthd_start()
|
|
|
|
|
+ _drain_fd(master)
|
|
|
hthd = subprocess.Popen([str(hthd_bin), "--config", str(cfg)], cwd=str(HOST), env={**os.environ})
|
|
hthd = subprocess.Popen([str(hthd_bin), "--config", str(cfg)], cwd=str(HOST), env={**os.environ})
|
|
|
for _ in range(200):
|
|
for _ in range(200):
|
|
|
if Path(obs).exists() and Path(ctl).exists():
|
|
if Path(obs).exists() and Path(ctl).exists():
|