]> hydra-www.ietfng.org Git - acmetensortoys-snakecontrol/commitdiff
rpb.expect: rework to support retry main
authorNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sat, 10 Feb 2018 23:52:35 +0000 (18:52 -0500)
committerNathaniel Wesley Filardo <nwfilardo@gmail.com>
Sun, 11 Feb 2018 00:07:53 +0000 (19:07 -0500)
bin/rpb.expect

index 01c0c9a788413f30dc94c4ef860cee0080514168..7384f8eb75c42fbbcd2d42e97451bf0b5bdb97e5 100755 (executable)
@@ -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]
+  }
 }