From: ian Date: Thu, 5 Jan 2006 00:11:58 +0000 (+0000) Subject: startup protocol now improved X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=22d44657e2c54fd2f2a3467ba37118a076377454;p=trains.git startup protocol now improved --- diff --git a/hostside/stopgap-controller b/hostside/stopgap-controller index 45d7003..065db6b 100755 --- a/hostside/stopgap-controller +++ b/hostside/stopgap-controller @@ -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