Sync from GitHub at 25c8330: hardware-in-the-loop rig, SAM D21 board, guard elimination on RV32/Cortex-M3
0e9783b verified Download scripts/hil/capture.py from Snapkitty/ai-free: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/Snapkitty/ai-free/resolve/main/scripts/hil/capture.py
- Command line
-
hf download hf://Snapkitty/ai-free/scripts/hil/capture.py
-
curl -L -o capture.py https://huggingface.co/Snapkitty/ai-free/resolve/main/scripts/hil/capture.py
1.51 kB
| """Read a serial port until the end-of-run transcript is complete. | |
| python3 capture.py <device> <out.log> <timeout-seconds> <ready-file> | |
| Opens <device> (already set to 115200 8N1 raw by the caller), touches <ready-file> once the | |
| port is open (opening it raises DTR, which the Curiosity Nano's debugger needs before it forwards | |
| any data), and copies everything to <out.log> until the line after `EXIT` (the status) has been | |
| received, or the timeout passes. Only printable ASCII and newlines are kept (carriage returns, | |
| NUL and other glitch bytes as the UART comes up are dropped), so line noise cannot hide the | |
| transcript. Exit status 0 if the transcript ended. | |
| """ | |
| import os, select, sys, time | |
| dev, out, limit, ready = sys.argv[1], sys.argv[2], float(sys.argv[3]), sys.argv[4] | |
| fd = os.open(dev, os.O_RDONLY | os.O_NOCTTY) | |
| open(ready, 'w').close() | |
| buf = b'' | |
| deadline = time.monotonic() + limit | |
| done = False | |
| with open(out, 'wb') as log: | |
| while time.monotonic() < deadline and not done: | |
| r, _, _ = select.select([fd], [], [], 0.2) | |
| if not r: | |
| continue | |
| raw = os.read(fd, 4096) | |
| if not raw: | |
| break | |
| chunk = bytes(b for b in raw if b == 10 or 32 <= b < 127) | |
| buf += chunk | |
| log.write(chunk) | |
| log.flush() | |
| lines = buf.split(b'\n') | |
| for i, line in enumerate(lines[:-1]): | |
| if line.strip() == b'EXIT' and i + 1 < len(lines) - 1: | |
| done = True | |
| break | |
| sys.exit(0 if done else 1) | |