feat(scripting): add sprintf2 command and fix prompt-wait race (v0.1.2)

- Add TeraTerm-compatible sprintf2 (C printf formatting into a string var)

- Fix SVOS power-cycle script racing ahead by gating prompt waits behind output-completion markers

- Bump version to 0.1.2; docs and README updates
This commit is contained in:
2026-06-04 14:13:43 +08:00
parent a8dc3d4a7a
commit 7b8f04e1dd
14 changed files with 1454 additions and 37 deletions
+45
View File
@@ -0,0 +1,45 @@
prompt_productOS = "6000#"
ip = "192.168.1.21" ; PDU IP
device = 1 ; PDU 裝置編號(iPoMan II/III 以 1 為預設)
port_1 = 1 ; 要測試的插座埠
port_2 = 2 ; 要測試的插座埠
act_off = 0
act_on = 1
; ── 連線 ──
idx = 1
while idx
pduconnect device ip
if result == 0 then
messagebox 'PDU connect failed — 檢查 IP / 網路 / community'
endif
; ── 單埠 OFF → ON 電源循環 ──
pause 3
pductrl device port_1 act_off
pductrl device port_2 act_off
pause 3
pductrl device port_1 act_on
pause 1
pductrl device port_2 act_on
pause 3
wait "6000 login:"
sendln "admin"
wait "Password:"
sendln ""
waitall prompt
sendlngroup A "show version"
sendlngroup B "show int b"
waitall prompt
sendlngroup A "show version"
sendlngroup B "show int b"
waitall prompt
sendlngroup A "show int b"
sendlngroup B "show version"
endwhile
+22
View File
@@ -0,0 +1,22 @@
; test-pdu.ttl — PDU 控制指令測試(iPoMan II/III via SNMP)
; 不需 active session 的回應;pduconnect / pductrl 走 SNMP 直連 PDU。
; 執行前請改下方 ip / device / port 為實際值。執行中可按 Stop 中止。
ip = "192.168.1.21" ; PDU IP
device = 1 ; PDU 裝置編號(iPoMan II/III 以 1 為預設)
port = 1 ; 要測試的插座埠
act_off = 0
act_on = 1
; ── 連線 ──
pduconnect device ip
if result == 0 then
messagebox 'PDU connect failed — 檢查 IP / 網路 / community'
endif
; ── 單埠 OFF → ON 電源循環 ──
pductrl device port act_off
pause 3
pductrl device port act_on
pause 3
+47
View File
@@ -0,0 +1,47 @@
prompt_SVOS = "SVOS> "
ip = "192.168.1.21" ; PDU IP
device = 1 ; PDU 裝置編號(iPoMan II/III 以 1 為預設)
port = 1 ; 要測試的插座埠
act_off = 0
act_on = 1
; ── 連線 ──
pduconnect device ip
if result == 0 then
messagebox 'PDU connect failed — 檢查 IP / 網路 / community'
endif
cnt_total = 0
while 1
; ── 單埠 OFF → ON 電源循環 ──
flushrecv ; 清掉上一輪殘留輸出,等待 boot 訊息更乾淨
pause 3
pductrl device port act_off
pause 5
pductrl device port act_on
pause 3
wait "Select profile(primary):"
sendln "0"
wait "ServiceOS login:"
sendln "admin"
wait prompt_SVOS ; 登入後第一個就緒提示(此處無指令輸出,安全)
sendln "version"
wait "SHA:" ; 先等 version 輸出跑完(最後一行),避免比對到回顯的 "SVOS> version"
wait prompt_SVOS
sendln "help"
wait "more info" ; 先等 help 輸出跑完,再等就緒提示
wait prompt_SVOS
sendln "help"
wait "more info"
wait prompt_SVOS
cnt_total = cnt_total + 1
sprintf2 total_print "====== Total Power Cycle :%d ======" cnt_total
sendln total_print
wait prompt_SVOS
endwhile
@@ -0,0 +1,44 @@
prompt_ProductOS = "6000# "
ip = "192.168.1.21" ; PDU IP
device = 1 ; PDU 裝置編號(iPoMan II/III 以 1 為預設)
port = 1 ; 要測試的插座埠
act_off = 0
act_on = 1
; ── 連線 ──
pduconnect device ip
if result == 0 then
messagebox 'PDU connect failed — 檢查 IP / 網路 / community'
endif
cnt_total = 0
while 1
; ── 單埠 OFF → ON 電源循環 ──
flushrecv ; 清掉上一輪殘留輸出,等待 boot 訊息更乾淨
pause 3
pductrl device port act_off
pause 5
pductrl device port act_on
pause 3
wait "6000 login:"
sendln "admin"
wait "Password: "
sendln ""
wait prompt_ProductOS
sendln "show version"
wait prompt_ProductOS
sendln "show int b"
wait prompt_ProductOS
sendln "show int b"
wait prompt_ProductOS
cnt_total = cnt_total + 1
sprintf2 total_print "====== Total Power Cycle :%d ======" cnt_total
sendln total_print
wait prompt_ProductOS
endwhile
+25
View File
@@ -0,0 +1,25 @@
; sprintf2 範例 / 自我測試
; 在任一已連線 session 執行;結果以 messagebox 顯示
sprintf2 ver 'Tera Term 4.%d' 51
messagebox ver
sprintf2 win 'Windows %d (+%s)' 2000 'SP4'
messagebox win
sprintf2 test '%s=%d %s=0x%x' 'dec' 10 'hex' 33
messagebox test
; 寬度 / 補零 / 精度
sprintf2 pad '[%05d] [%-8s] [%+.2f]' -42 'hi' '3.14159'
messagebox pad
; 累加自身(格式字串保持字面值,引數才展開變數)
sprintf2 acc '%s' 'start'
sprintf2 acc '%s-A' acc
sprintf2 acc '%s-B' acc
messagebox acc
; result 狀態:0=成功
sprintf2 ok '%d' 1
messagebox result