#!/home/mirror/tcstcl -- set helpTopics(default) {Current commands: getPOS - get the values associated with the hexapod FOO command help - this command - take an optional argument, for more detail abort - exit gracefully exit - exit gracefully } set helpCmds(foo) {foo} # Procedure: Help proc Help { {topic "default"} {x "0"} {y "0"}} { global helpTopics helpCmds if {$topic == ""} return while {[info exists helpCmds($topic)]} { set topic [eval $helpCmds($topic)] } if [info exists helpTopics($topic)] { set msg $helpTopics($topic) } else { set msg "Sorry, but no help is available for this topic" } puts $msg # mkDialog .help "-text {Information on $topic:\n\n$msg} -justify left -aspect 300" "OK {}" } proc getPos {{point "1"}} { global microridge global val timestamp set error {} set val {not valid} exp_send "$microridge(R,$point)" expect { -re " *(\[^,]+),(\[^,]+),(\[^\r]*)\r" { set val $expect_out(buffer) set microridge(R,$point,data) $expect_out(1,string) set microridge(R,$point,units) $expect_out(2,string) set microridge(R,$point,channelId) $expect_out(3,string) # puts $expect_out(1,string) # puts $expect_out(2,string) # puts $expect_out(3,string) # last line - so bail } timeout { set microridge(R,$point,data) "-999.999" set microridge(R,$point,units) "timeout" set microridge(R,$point,channelId) "timeout" } eof {lappend error "unexpected EOF"; puts eof} } if {[llength $error] == 0} { set timestamp [exp_timestamp] set microridge(R,$point,timestamp) $timestamp } else { set timestamp 0 foreach err $error { puts "getPos: $err" } } } proc abort {{rtn "-1"}} { global kprompt # close kermit exp_send \034C expect { $kprompt {#puts "abort: got prompt"} timeout {puts "abort: timeout"} eof {puts "abort: eoft"} } exp_send quit # expect # wait exit $rtn } ######################################################## # Start of program ######################################################## # only want tk for send (now) #wm withdraw . #set time_format "%c %Z" set env(TZ) "UT" set time_format "%Y:%j %X" set timeout 3 set tcl_precision 10 #set tcshostname 128.171.165.3 set tcshostname vtcshost log_user 0 # get in contact #spawn tip microridge #expect { # eof {puts "open failed"} # connected #} set kprompt microRidge-kermit> spawn /home/mirror/kermit -l /dev/ttyS0 -b 9600 -C "set term byte 8, set term cr crlf, set prompt $kprompt" -Y expect { $kprompt {#puts "opened tty, got $kprompt"} timeout {puts "kermitstart: timeout"; abort} eof {puts eof; abort} } exp_send "c\n" expect { options. {#puts "connected"} timeout {puts "kermitconnect:timeout"; abort} eof {puts eof; abort} } # ok, a little race condition - abort assumes we are here, but as soon as # kermit starts we need to exit it. exit -onexit { abort } # now we are talking to the microridge # clear cruft out exp_send " 0} { # should be all at once - entering time critical area getPos 1 getPos 2 getPos 3 getPos 4 getPos 5 set timestamp [exp_timestamp] set position [tcs_position -dec -ha] # end of time (almost) critical area set foo "$microridge(R,1,data) $microridge(R,2,data) $microridge(R,3,data) $microridge(R,4,data) $microridge(R,5,data)" set result {} foreach i $foo { if {$i != "timeout"} { lappend result [expr $i] } else { lappend result $i } } set year [exp_timestamp -format %Y: -seconds $timestamp] set day [expr [exp_timestamp -format %j -seconds $timestamp] - 1] set rest [exp_timestamp -format %X -seconds $timestamp] set timestring "$year$day $rest" puts "$timestring $position $result" incr cnt -1 } #puts "" #puts "for help, use the Help command" #interpreter