From 0a3805fa5ae02350a99c56c9ed3557354544419a Mon Sep 17 00:00:00 2001 From: Ferdi Franceschini Date: Fri, 14 Feb 2014 15:04:05 +1100 Subject: [PATCH] Load instrument specific rules if defined in the anticollider.tcl --- .../anticollider/anticollider_common.tcl | 91 +++++++++++++------ 1 file changed, 64 insertions(+), 27 deletions(-) diff --git a/site_ansto/instrument/config/anticollider/anticollider_common.tcl b/site_ansto/instrument/config/anticollider/anticollider_common.tcl index 121005b0..81e08ad0 100644 --- a/site_ansto/instrument/config/anticollider/anticollider_common.tcl +++ b/site_ansto/instrument/config/anticollider/anticollider_common.tcl @@ -1,8 +1,6 @@ # Author: Ferdi Franceschini (ffr@ansto.gov.au) # TODO Handle sequencing when simultaneously moving multiple axes -# TODO Handle functional dependencies (just write your own tcl script) -# or get the generic acscript to call a user proc AntiCollisionInstall namespace eval anticollider { @@ -11,11 +9,41 @@ namespace eval anticollider { array unset ::anticollider::veto_region array set ::anticollider::veto_region "" +# Don't show 'acscript' call on error. This is done by the anticollider +# module. +proc handle_acscript_exception {status message args} { + switch $status { + 0 { + # TCL_OK, This is raised when you just drop out of the + # bottom of a 'catch' command. + return -code ok + } + 1 { + # TCL_ERROR + return -code error "$message: $args" + } + 2 { + # TCL_RETURN + return -code return "$message" + } + 3 { + # TCL_BREAK + return -code break + } + 4 { + # TCL_CONTINUE + return -code continue + } + default { + # Propogate user defined return codes with message + return -code $status "$message" + } + } +} ## # @brief Load an anticollider script proc ::anticollider::loadscript {args} { - variable prog - set prog "" + variable veto_rules set fh [open $::cfPath(anticollider)/[lindex $args 0] RDONLY ] while {[gets $fh line] >= 0} { @@ -23,7 +51,7 @@ proc ::anticollider::loadscript {args} { if [regexp {^\s*$|^ *#} $line] { continue } - lappend prog $line + lappend veto_rules $line } } @@ -31,7 +59,7 @@ proc ::anticollider::loadscript {args} { # @brief Compile compile an anticollider declaration into a veto region table # for the anticollider script. # -# @param vprog, an anticollider declaration as a list of quote enclosed lines. +# @param veto_rules, an anticollider declaration as a list of quote enclosed lines. # @return Generates the ::anticollider::veto_region lookup table. # # Example\n @@ -42,14 +70,16 @@ proc ::anticollider::loadscript {args} { # for sphi forbid { {0 5} {10 15} } when schi in { {5 10} {15 20} }\n # forbid {-inf 5} when mtth in {0 10} for sphi\n # forbid {0 10} for samx whenall { samrot in {0 5} samy in {0 15} }\n -proc ::anticollider::genveto {vprog} { +proc ::anticollider::genveto {veto_rules} { variable veto_region array unset veto_region set lnum 1 - foreach line $vprog { + foreach line $veto_rules { array unset vp array set vp $line + clientput "::anticollider::veto_rule: $line" + if [info exists vp(whenall)] { foreach {mot in range} $vp(whenall) { # if {[llength [join $range]] != 2} { @@ -147,7 +177,6 @@ proc ::anticollider::veto_region_acscript {args} { } } } - anticollision add 0 $regmot $target } } message ] handle_exception $catch_status $message @@ -159,30 +188,38 @@ proc ::anticollider::init {} { variable evp variable veto_region - if [ catch { - ::anticollider::genveto $::anticollider::prog + set catch_status [ catch { + if { ![info exists ::anticollider::veto_rules] } { + return + } + clientput Load anticollider rules: + if { [info procs ::anticollider::load_acrules] == "::anticollider::load_acrules" } { + ::anticollider::load_acrules + } + ::anticollider::genveto $::anticollider::veto_rules foreach motor [array names veto_region] { anticollision register $motor } - } message ] { - clientput [info level 0] ERROR: $message - if {$::errorCode=="NONE"} {return $message} - return -code error $message - } -} - -proc ::anticollider::acscript {args} { - set catch_status [ catch { - if {[::anticollider::enable $args] == "false"} { - foreach {regmot target} $args { - anticollision add 0 $regmot $target - } - return - } - ::anticollider::veto_region_acscript {*}$args } message ] handle_exception $catch_status $message } +lappend ::anticollider::scripts ::anticollider::veto_region_acscript +proc ::anticollider::acscript {args} { + set catch_status [ catch { + if {[::anticollider::enable $args] == "false"} { + return + } else { + foreach {regmot target} $args { + anticollision add 0 $regmot $target + } + } + foreach script $::anticollider::scripts { + $script {*}$args + } + } message ] + handle_acscript_exception $catch_status $message +} + publish ::anticollider::acscript user anticollision script ::anticollider::acscript