chiark / gitweb /
startup protocol now improved
authorian <ian>
Thu, 5 Jan 2006 00:11:58 +0000 (00:11 +0000)
committerian <ian>
Thu, 5 Jan 2006 00:11:58 +0000 (00:11 +0000)
hostside/stopgap-controller

index 45d700374680481992dc5b66a9c7cf04bd524766..065db6b15b6f101e4a3d8d0613c00d91a423ad18 100755 (executable)
@@ -79,7 +79,7 @@ proc fail_now {} {
     debug "failing now"
     fconfigure $p -blocking yes
     gui "P 0"
-    tellpic 20
+    tellpic 10
     exit 1
 }
 
@@ -88,7 +88,7 @@ proc fail {m} {
     catch { after cancel $watchdog; unset watchdog }
     puts "failing $m"
     tellpic 9801 ;# 16ms
-    after 2000 fail_now
+    after 10000 fail_now
     fileevent $p readable {}
 }
 
@@ -327,7 +327,7 @@ proc onreadp_test {} {
 }
 
 proc onreadp {} {
-    global p m
+    global p m rand
     while 1 {
        set c [read $p 1]
        if {![string length $c]} {
@@ -335,6 +335,10 @@ proc onreadp {} {
            return
        }
        binary scan $c H* x
+       if {![info exists rand]} {
+           fp ...$x
+           return
+       }
        lappend m $x
        if {[regexp {^[0-7]} $x]} {
            if {![regexp {^x} $m]} {
@@ -398,8 +402,16 @@ proc changewhat {} {
     set chwa [after $interval changewhat]
 }
 
+proc onreadcmd {} {
+    if {[gets stdin l] < 0} {
+       if {[eof stdin]} { fileevent stdin readable {} }
+       return
+    }
+    eval $l
+}
+
 proc setup {} {
-    global port p rand testonly
+    global port p testonly
     if {!$testonly} {
        set p [open $port {RDWR NONBLOCK} 0]
     
@@ -413,14 +425,22 @@ proc setup {} {
                -blocking false -buffering none
 
        fileevent $p readable onreadp
+       fconfigure stdin -blocking false
+       fileevent stdin readable onreadcmd
     } else {
        set p stdin
        fconfigure stdin -blocking false
        fileevent stdin readable onreadp_test
     }
 
+    after 250 setup_complete
+}
+
+proc setup_complete {} {
+    global rand
     set rand [open /dev/urandom {RDONLY} 0]
     fconfigure $rand -encoding binary -translation binary
+    tellpic 0a
 }
 
 setup