fix(ttl): add sendlnretry — resend until the device confirms it ran the command
A device that is still booting can silently discard console input the moment its
shell takes over the tty (tty reopen / termios flush). The line sent by `sendln`
vanishes — the device neither echoes nor runs it — so the following `wait` blocks
forever and the rig sits dead.
This is a race, not a delay: `pause` before `sendln` only lowers the odds of hitting
the window, it can never close it. Evidence from a 45-cycle overnight power-cycle run
(For_AI/[COM121]_20260715): 3 cycles hung this way, and the swallowed sends landed at
the same DUT uptime (31.8-34.8s) as the 42 that worked. The `random: crng init done`
line those hangs share is a symptom, not the cause — it only appears because a hung
script stops power-cycling, letting the DUT reach uptime 89.7s it never otherwise sees.
Single-string `wait` aborts the script on timeout (deliberate, see CLAUDE.md), so the
TeraTerm idiom `wait` -> `if result = 0 then goto retry` cannot express a resend here.
Hence a new command rather than a semantics change:
sendlnretry '<text>' '<confirm keyword>' [max attempts]
Sends, then waits for proof the device actually ran it, and resends if that proof does
not arrive. Attempts omitted = retry until it gets through. On success result=1; when
attempts run out result=0 and the script continues so it can handle the failure.
Semantics: clears the receive buffer before each send (a match can only come from this
send); on a hit consumes only up to the first occurrence, leaving the rest for the next
`wait`; deliberately no settle (the keyword appearing is itself proof). Per-attempt
timeout follows timeout/mtimeout when set, else 3s — unlike `wait`, 0 cannot mean
"forever" here since that would mean never retrying.
Not yet run against hardware: compiles clean (cross-built win-x64 on Linux), but the
DUT power-cycle rig is the first real execution.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MKF7C75bhA4ArQhyMpnsxU
This commit is contained in:
@@ -43,6 +43,42 @@
|
||||
|
||||
# 一、ETTerms 獨有指令
|
||||
|
||||
## 送出並確認(sendlnretry)
|
||||
|
||||
| 指令 | 語法 | 說明 |
|
||||
|------|------|------|
|
||||
| `sendlnretry` | `sendlnretry '文字' '確認關鍵字' [最多送出次數]` | 送出 `文字` + `\r\n`,然後等 `確認關鍵字`;沒等到就**重送**。次數省略 = 一直重送到收到為止。命中 `result=1`;用完次數 `result=0` 且**繼續執行**(不中止腳本)。 |
|
||||
|
||||
**為什麼需要它**:裝置在開機、console 剛被 shell 接手的瞬間,可能把收到的輸入直接丟掉
|
||||
(tty 重開 / termios flush)。此時 `sendln` 送出的整行會**無聲無息地消失**——裝置不會回顯、
|
||||
也不會執行,後面的 `wait` 就永遠等不到,腳本整個卡死。這是**機率性**的:
|
||||
在 `sendln` 前面加 `pause` 只是降低撞上那個窗口的機率,**不可能根治**。
|
||||
`sendlnretry` 的作法是送完就確認對方真的有反應,沒反應就再送一次。
|
||||
|
||||
```
|
||||
; 開機後下 tpm2,沒跑到就自動重送(無限重送)
|
||||
wait 'root@(none):/#'
|
||||
sendlnretry 'tpm2' 'TPM 2p0'
|
||||
wait 'PASS'
|
||||
|
||||
; 最多送 3 次,還是不行就自己處置
|
||||
sendlnretry 'tpm2' 'TPM 2p0' 3
|
||||
if result = 0 then
|
||||
dispstr 'tpm2 送了 3 次都沒反應'
|
||||
endif
|
||||
```
|
||||
|
||||
使用要點:
|
||||
|
||||
- **確認關鍵字要挑「命令真的有跑」才會出現的輸出**(例:`TPM 2p0`),
|
||||
**不要挑指令回顯**(例:`tpm2`)——tty 的 echo 由核心產生,不保證命令有被 shell 讀走。
|
||||
- **每次送出前會清空接收緩衝**,確保比對到的是「這次送出」的回應而不是殘留輸出。
|
||||
命中後只消費到**第一次**出現處,後面的輸出留在緩衝裡給接下來的 `wait` 用
|
||||
(所以上例的 `wait 'PASS'` 照常會等到)。
|
||||
- 每次送出後等確認的逾時:`timeout`/`mtimeout` 有設就用設定值,**沒設預設 3 秒**
|
||||
(注意這與 `wait` 不同——`wait` 的 0 是無限等,但無限等在這裡等於永不重送)。
|
||||
- **指令最好是可重複執行的**:若逾時設得太短、而裝置其實只是回應慢,會造成同一個指令送兩次。
|
||||
|
||||
## Group 同步(多分頁協同)
|
||||
|
||||
以下指令**只能在 Run Group 模式**下使用(toolbar 的 `▶ Group1-3`)。
|
||||
@@ -89,7 +125,7 @@ wait 'login:'
|
||||
|
||||
| 項目 | ETTerms 行為 |
|
||||
|------|--------------|
|
||||
| `wait`(**單字串**) | 命中後需裝置**安靜 300ms**(無新資料)才接受,並取「最後一次」出現——排除輸出中途的指令回顯(如 `SVOS> help`)造成腳本搶跑。**逾時會中止腳本**(TeraTerm 是 `result=0` 繼續)。 |
|
||||
| `wait`(**單字串**) | 命中後需裝置**安靜 300ms**(無新資料)才接受,並取「最後一次」出現——排除輸出中途的指令回顯(如 `SVOS> help`)造成腳本搶跑。**逾時會中止腳本**(TeraTerm 是 `result=0` 繼續),因此 TeraTerm 常見的 `wait` → `if result = 0 then goto retry` 重送寫法在單字串 `wait` 上做不到;要「送出後確認、沒回應就重送」請用 [`sendlnretry`](#送出並確認sendlnretry)。 |
|
||||
| `wait`(**多字串**) | TeraTerm 相容:任一命中即繼續,`result` = 第幾個字串(1 起算);逾時 `result=0` **繼續執行**、無 settle。 |
|
||||
| `goto` / 跨區塊跳轉 | `goto` 跳出 `if`/`while` 區塊後,該區塊的迴圈控制即結束(同層繼續直行)。避免 goto 跳「進」區塊中間。 |
|
||||
| `call` | 可以在迴圈 / if 內使用(行內執行,返回後迴圈續跑)。 |
|
||||
|
||||
Reference in New Issue
Block a user