; ============================================================================= ; File : utils/wait_init.ttl ; Version : V2.0.0 ; Date : 2026-08-21 ; Author : ETWen ; ============================================================================= ; Wait until BOTH switch units report more than WT_MIN ports up: ; bcmcmd -n 0 -c ps | grep -w up | wc -l ; bcmcmd -n 1 -c ps | grep -w up | wc -l ; ; Enter : prompt of the previous command is NOT consumed. ; Exit : a command has been sent, prompt NOT consumed (caller does the wait). ; ; Why the "PORTS0=" marker instead of reading the number straight off the ; screen: TTL can only test for a string, so counting requires capturing the ; output. Wrapping the count in an echo gives waitregex a unique anchor, and ; the ECHO of the command itself cannot false-match -- it reads ; "PORTS0=$(bcmcmd ..." and the regex demands a digit right after the "=". ; ; Version History: ; V1.0.0 2026-08-21 Initial Version (waited on "show platform temperature" ; until it stopped reporting "Thermal Not detected") ; V2.0.0 2026-08-21 Wait on the bcmcmd port-up count of BOTH switch units ; instead of the thermal sensors; proceed only when both ; are greater than WT_MIN (216). ; ============================================================================= WT_MIN = 216 ; both units must report MORE than this many ports up WT_INTERVAL = 10 ; seconds between polls timeout = 60 ; per-wait cap; bcmcmd ps is not instant wait prompt_sonic_root :WAIT_PORTS ; --- unit 0 ----------------------------------------------------------------- wt_up0 = 0 sendln "echo PORTS0=$(bcmcmd -n 0 -c ps | grep -w up | wc -l)" waitregex "PORTS0=[ ]*([0-9]+)" if result = 1 then str2int wt_up0 groupmatchstr1 endif wait prompt_sonic_root ; --- unit 1 ----------------------------------------------------------------- wt_up1 = 0 sendln "echo PORTS1=$(bcmcmd -n 1 -c ps | grep -w up | wc -l)" waitregex "PORTS1=[ ]*([0-9]+)" if result = 1 then str2int wt_up1 groupmatchstr1 endif wait prompt_sonic_root ; --- both above the threshold? ---------------------------------------------- ; Nested ifs rather than "and": in TTL "and" is bitwise, so keeping the two ; comparisons separate leaves no room for precedence surprises. if wt_up0 > WT_MIN then if wt_up1 > WT_MIN then goto PORTS_OK endif endif pause WT_INTERVAL goto WAIT_PORTS :PORTS_OK timeout = 0 ; Exit contract: send something without waiting, so the caller's next ; "wait prompt_sonic_root" has a prompt to match. sendln ""