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]
+ }
}