From: Nathaniel Wesley Filardo Date: Sat, 10 Feb 2018 23:52:35 +0000 (-0500) Subject: rpb.expect: rework to support retry X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;p=acmetensortoys-snakecontrol rpb.expect: rework to support retry --- diff --git a/bin/rpb.expect b/bin/rpb.expect index 01c0c9a..7384f8e 100755 --- a/bin/rpb.expect +++ b/bin/rpb.expect @@ -2,31 +2,54 @@ proc help {} { global argv0 - global actionnames - send_user "usage: $argv0 outlet {on|off|boot}\n" + send_user "usage: $argv0 outlet {on|off}\n" exit 1 } -proc waitprompt {} { - expect { - "RPB+> " { } - timeout { - send_user " ===> TIMEOUT <===\n" - exit 1 +proc spser {} { + global spawn_id + set pid [spawn /home/pi/sc/bin/serial.wrap [ exec readlink -f /dev/serial/by-path/platform-20980000.usb-usb-0:1.3.3:1.0-port0 ]] + + set timeout 30 + for { set i 0 } { $i < 10 } { incr i } { + send "\n" + expect { + "RPB+> " { break } + timeout { send_user " ===> timeout (attempt ${i}) <===\n" } } - } + } + if { $i == 10 } { + send_user " ===> TIMEOUT WHILE CONNECTING <===\n" + exit 1 + } + + return $pid } -spawn /home/pi/sc/bin/serial.wrap [ exec readlink -f /dev/serial/by-path/platform-20980000.usb-usb-0:1.2:1.0-port0 ] -set timeout 70 -send "\n" -waitprompt +set PID [spser] if {$argc == 2} { set outlet [lindex $argv 0] set cmd [string toupper [lindex $argv 1]] - send "/$outlet $cmd\n" - set timeout 30 - waitprompt + for { set i 0 } { $i < 10 } { incr i } { + send "/$outlet $cmd\n" + set timeout 10 + expect { + -re " ${outlet}\[^\n\]*${cmd}\[^\n\]*\r\n" { + expect { + "RPB+> " { break } + timeout { send_user " ===> TIMEOUT WHILE FINISHING <===\n" ; exit 1 } + } + } + "RPB+> " { send_user "===> prompt (status mismatch? attempt ${i}) <===\n" } + timeout { send_user " ===> timeout (attempt ${i}) <===\n" } + } + + close + exec kill $PID + wait + + set PID [spser] + } }