--- /dev/null
+# 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
--- /dev/null
+# -*- 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
+}
update_push
}
+proc EOE {} { global exitoneof; set exitoneof 1}
+
main
while {[gets stdin l]>=0} {
puts $l
}
}
+
+if {[info exists exitoneof]} { exit 0 }
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] {
catch { after cancel $watchdog; unset watchdog }
puts "failing $m"
tellpic 9801 ;# 16ms
- after 10000 fail_now
+ after 1000 fail_now
fileevent $p readable {}
}
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]} {
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 }
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 }