From 07ba3afe47aa391533707db37880770998ddc4cb Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 5 Jan 2006 03:27:50 +0000 Subject: [PATCH] fixes from bessar fettling session --- hostside/eventrun.events | 9 ++++++++ hostside/eventrun.procs | 46 +++++++++++++++++++++++++++++++++++++ hostside/gui-displayer | 4 ++++ hostside/stopgap-controller | 16 +++++++++---- 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 hostside/eventrun.events create mode 100644 hostside/eventrun.procs diff --git a/hostside/eventrun.events b/hostside/eventrun.events new file mode 100644 index 0000000..1080b15 --- /dev/null +++ b/hostside/eventrun.events @@ -0,0 +1,9 @@ +# spong +INIT source /u/ian/things/Bessar/trains/eventrun.procs + +e3 trains_stop +eb trains_start + +b2 tw ask_slow +e6 tw ask_randspeed +ec tw ask_fast diff --git a/hostside/eventrun.procs b/hostside/eventrun.procs new file mode 100644 index 0000000..168a856 --- /dev/null +++ b/hostside/eventrun.procs @@ -0,0 +1,46 @@ +# -*- tcl -*- + +cd /u/ian/things/Bessar/trains +exec xsetroot -solid #00000f + +set trainscmd { + set -x + savelog -c 7 bessar.log +# (set -ex + cd /u/ian/things/trains-bessar/hostside + ./stopgap-controller | ./gui-displayer - +# ) 2>&1 | tee bessar.log +} + +proc trains_start {} { + global trainsf trainscmd + trains_stop + set cmdl [list sh -ec $trainscmd 2>@ stderr] + set trainsf [open |$cmdl w] + fconfigure $trainsf -buffering none -blocking no +} + +proc tw {s} { + global trainsf + if {![info exists trainsf]} return + if {[catch { + puts $trainsf $s + } emsg]} { + puts stderr "tw: $emsg" + trains_stop + } +} + +proc okagain {} { + global okagain + set okagain 1 +} + +proc trains_stop {} { + global trainsf okagain + if {![info exists trainsf]} return + catch { close $trainsf } + unset trainsf + after 3000 okagain + vwait okagain +} diff --git a/hostside/gui-displayer b/hostside/gui-displayer index d4425d6..eadac7d 100755 --- a/hostside/gui-displayer +++ b/hostside/gui-displayer @@ -142,6 +142,8 @@ proc main {} { update_push } +proc EOE {} { global exitoneof; set exitoneof 1} + main while {[gets stdin l]>=0} { @@ -152,3 +154,5 @@ while {[gets stdin l]>=0} { puts $l } } + +if {[info exists exitoneof]} { exit 0 } diff --git a/hostside/stopgap-controller b/hostside/stopgap-controller index 8f89014..0c4f334 100755 --- a/hostside/stopgap-controller +++ b/hostside/stopgap-controller @@ -41,8 +41,9 @@ proc gui {m} { proc gui_init {} { global watchdog polarity segdetect gui "M A2 0" -# gui "M A5 0 J" -# gui "M A6 0 J" + gui "M A5 0 J" + gui "M A6 0 J" + gui "EOE" if {[info exists watchdog]} { gui "P 1" } gui_polarity foreach seg [array names segdetect] { @@ -90,7 +91,7 @@ proc fail {m} { catch { after cancel $watchdog; unset watchdog } puts "failing $m" tellpic 9801 ;# 16ms - after 10000 fail_now + after 1000 fail_now fileevent $p readable {} } @@ -143,6 +144,12 @@ proc pt_ifthenmust {ifpoint ifposwant thenpoint thenpos} { pt_must $thenpoint $thenpos } +proc badwatchdog {} { + global pq + puts "watchdog - oh well" + if {![info exists pq]} { set pq {} } +} + proc pm_charged {} { global pq if {[llength $pq]} { @@ -315,6 +322,7 @@ proc frompic {m} { 01 - 02 { tellnmra $m } 09 { fp $m; pm_hello } 07 { puts "short circuit"; exit 1 } + 0d { fp $m; badwatchdog } 28 { fp $m; pm_charged } 9[0-7] { fp $m; pm_maydetect 0 $v } 9? { fp $m; pm_maydetect 1 $v } @@ -458,7 +466,7 @@ proc ask_fast {} { global speeddirn_fixed; set speeddirn_fixed {speed126 2 126 0} } proc ask_slow {} { - global speeddirn_fixed; set speeddirn_fixed {speed126 2 126 10} + global speeddirn_fixed; set speeddirn_fixed {speed126 2 10 0} } proc ask_randspeed {} { global speeddirn_fixed; catch { unset speeddirn_fixed } -- 2.30.2