Added new reactor status driver.
This commit is contained in:
50
site_ansto/instrument/config/source/reactor_status.sct
Normal file
50
site_ansto/instrument/config/source/reactor_status.sct
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# vim: ts=8 sts=2 sw=2 expandtab autoindent smartindent nocindent
|
||||||
|
# http://neutron.ansto.gov.au/Bragg/proposal/reactor.jsp?type=ALL
|
||||||
|
# Power: 19.198232; CNS Out: 29.26; TG123: 1; CG123: 1; TG4: 3
|
||||||
|
driver reactor_status = {
|
||||||
|
protocol = std;
|
||||||
|
class = NXsource;
|
||||||
|
simulation_group = opal_simulation;
|
||||||
|
|
||||||
|
group = {
|
||||||
|
group_property 'data' = 'true';
|
||||||
|
group_property 'control' = 'true';
|
||||||
|
var status = {
|
||||||
|
type = text;
|
||||||
|
priv = spy;
|
||||||
|
readable = 10;
|
||||||
|
read_command = 'GET /Bragg/proposal/reactor.jsp?type=ALL HTTP/1.0';
|
||||||
|
read_function = rdAll;
|
||||||
|
fetch_function = getState;
|
||||||
|
data = false;
|
||||||
|
control = false;
|
||||||
|
}
|
||||||
|
var power = { type = float; priv = spy; mutable = true; property klass = source;}
|
||||||
|
var cns_out = { type = float; priv = spy; mutable = true; property klass = source;}
|
||||||
|
var tg123 = { type = float; priv = spy; mutable = true; property klass = source;}
|
||||||
|
var cg123 = { type = float; priv = spy; mutable = true; property klass = source;}
|
||||||
|
var tg4 = { type = float; priv = spy; mutable = true; property klass = source;}
|
||||||
|
}
|
||||||
|
|
||||||
|
code read_function rdValue = {
|
||||||
|
}
|
||||||
|
code Write_function setPoint = {
|
||||||
|
}
|
||||||
|
code mkDriver = {
|
||||||
|
}
|
||||||
|
|
||||||
|
code read_function rdAll = {
|
||||||
|
@ set data [lindex [split [string trim ${data}] "\r\n"] end]
|
||||||
|
@ if {${data} != [sct oldval]} {
|
||||||
|
@ foreach {n v} [regexp -all -inline {[A-Z][A-Za-z0-9 ]+|[0-9][0-9.]*} ${data}] {
|
||||||
|
@ switch $n {
|
||||||
|
@ "Power" { hset ${tc_root}/power $v }
|
||||||
|
@ "CNS Out" { hset ${tc_root}/cns_out $v }
|
||||||
|
@ "TG123" { hset ${tc_root}/tg123 $v }
|
||||||
|
@ "CG123" { hset ${tc_root}/cg123 $v }
|
||||||
|
@ "TG4" { hset ${tc_root}/tg4 $v }
|
||||||
|
@ }
|
||||||
|
@ }
|
||||||
|
@ }
|
||||||
|
}
|
||||||
|
}
|
298
site_ansto/instrument/config/source/sct_reactor_status.tcl
Normal file
298
site_ansto/instrument/config/source/sct_reactor_status.tcl
Normal file
@ -0,0 +1,298 @@
|
|||||||
|
# Generated driver for reactor_status
|
||||||
|
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
|
||||||
|
#
|
||||||
|
|
||||||
|
namespace eval ::scobj::reactor_status {
|
||||||
|
set debug_threshold 0
|
||||||
|
}
|
||||||
|
|
||||||
|
proc ::scobj::reactor_status::debug_log {debug_level debug_string} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
if {${debug_level} >= ${::scobj::reactor_status::debug_threshold}} {
|
||||||
|
set fd [open "/tmp/reactor_status.log" "a"]
|
||||||
|
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
|
||||||
|
puts ${fd} "${line}"
|
||||||
|
close ${fd}
|
||||||
|
}
|
||||||
|
} catch_message ]
|
||||||
|
}
|
||||||
|
|
||||||
|
# check function for hset change
|
||||||
|
proc ::scobj::reactor_status::checkrange {tc_root} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
|
||||||
|
set setpoint [sct target]
|
||||||
|
if { [hpropexists [sct] lowerlimit] } {
|
||||||
|
set lolimit [sct lowerlimit]
|
||||||
|
} else {
|
||||||
|
# lowerlimit not set, use target
|
||||||
|
set lolimit [sct target]
|
||||||
|
}
|
||||||
|
if { [hpropexists [sct] upperlimit] } {
|
||||||
|
set hilimit [sct upperlimit]
|
||||||
|
} else {
|
||||||
|
# upperlimit not set, use target
|
||||||
|
set hilimit [sct target]
|
||||||
|
}
|
||||||
|
# hook code goes here
|
||||||
|
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
||||||
|
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
||||||
|
}
|
||||||
|
return OK
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to request the read of a parameter on a device
|
||||||
|
proc ::scobj::reactor_status::getState {tc_root nextState cmd_str} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "getState tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set cmd "${cmd_str}"
|
||||||
|
# hook code goes here
|
||||||
|
debug_log 1 "getState sct send ${cmd}"
|
||||||
|
sct send "${cmd}"
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to request the read of a parameter on a device
|
||||||
|
proc ::scobj::reactor_status::getValue {tc_root nextState cmd_str} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set cmd "${cmd_str}"
|
||||||
|
# hook code goes here
|
||||||
|
debug_log 1 "getValue sct send ${cmd}"
|
||||||
|
sct send "${cmd}"
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to check the write parameter on a device
|
||||||
|
proc ::scobj::reactor_status::noResponse {tc_root} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
|
||||||
|
# hook code goes here
|
||||||
|
return "idle"
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to parse the read of a parameter on a device
|
||||||
|
proc ::scobj::reactor_status::rdAll {tc_root} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "rdAll tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set data [sct result]
|
||||||
|
set nextState "idle"
|
||||||
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
|
# the protocol driver has reported an error
|
||||||
|
sct geterror "${data}"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
# hook code starts
|
||||||
|
set data [lindex [split [string trim ${data}] "\r\n"] end]
|
||||||
|
if {${data} != [sct oldval]} {
|
||||||
|
foreach {n v} [regexp -all -inline {[A-Z][A-Za-z0-9 ]+|[0-9][0-9.]*} ${data}] {
|
||||||
|
switch $n {
|
||||||
|
"Power" { hset ${tc_root}/power $v }
|
||||||
|
"CNS Out" { hset ${tc_root}/cns_out $v }
|
||||||
|
"TG123" { hset ${tc_root}/tg123 $v }
|
||||||
|
"CG123" { hset ${tc_root}/cg123 $v }
|
||||||
|
"TG4" { hset ${tc_root}/tg4 $v }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# hook code ends
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to parse the read of a parameter on a device
|
||||||
|
proc ::scobj::reactor_status::rdValue {tc_root} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set data [sct result]
|
||||||
|
set nextState "idle"
|
||||||
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
|
# the protocol driver has reported an error
|
||||||
|
sct geterror "${data}"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
# hook code goes here
|
||||||
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to write a parameter value on a device
|
||||||
|
proc ::scobj::reactor_status::setValue {tc_root nextState cmd_str} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set par [sct target]
|
||||||
|
set cmd "${cmd_str}${par}"
|
||||||
|
# hook code goes here
|
||||||
|
if { [hpropexists [sct] driving] } {
|
||||||
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
|
sct driving 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug_log 1 "setValue sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
proc ::scobj::reactor_status::mk_sct_reactor_status { sct_controller name } {
|
||||||
|
debug_log 1 "mk_sct_reactor_status for ${name}"
|
||||||
|
set ns "[namespace current]"
|
||||||
|
set catch_status [ catch {
|
||||||
|
|
||||||
|
MakeSICSObj ${name} SCT_OBJECT
|
||||||
|
|
||||||
|
sicslist setatt ${name} klass NXsource
|
||||||
|
sicslist setatt ${name} long_name ${name}
|
||||||
|
|
||||||
|
set scobj_hpath /sics/${name}
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/cg123 plain spy float
|
||||||
|
hsetprop ${scobj_hpath}/cg123 control true
|
||||||
|
hsetprop ${scobj_hpath}/cg123 data true
|
||||||
|
hsetprop ${scobj_hpath}/cg123 mutable true
|
||||||
|
hsetprop ${scobj_hpath}/cg123 nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/cg123 oldval 0.0
|
||||||
|
hsetprop ${scobj_hpath}/cg123 klass "source"
|
||||||
|
hsetprop ${scobj_hpath}/cg123 sdsinfo "::nexus::scobj::sdsinfo"
|
||||||
|
hsetprop ${scobj_hpath}/cg123 type "part"
|
||||||
|
hsetprop ${scobj_hpath}/cg123 nxalias "${name}_cg123"
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/cns_out plain spy float
|
||||||
|
hsetprop ${scobj_hpath}/cns_out control true
|
||||||
|
hsetprop ${scobj_hpath}/cns_out data true
|
||||||
|
hsetprop ${scobj_hpath}/cns_out mutable true
|
||||||
|
hsetprop ${scobj_hpath}/cns_out nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/cns_out oldval 0.0
|
||||||
|
hsetprop ${scobj_hpath}/cns_out klass "source"
|
||||||
|
hsetprop ${scobj_hpath}/cns_out sdsinfo "::nexus::scobj::sdsinfo"
|
||||||
|
hsetprop ${scobj_hpath}/cns_out type "part"
|
||||||
|
hsetprop ${scobj_hpath}/cns_out nxalias "${name}_cns_out"
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/power plain spy float
|
||||||
|
hsetprop ${scobj_hpath}/power control true
|
||||||
|
hsetprop ${scobj_hpath}/power data true
|
||||||
|
hsetprop ${scobj_hpath}/power mutable true
|
||||||
|
hsetprop ${scobj_hpath}/power nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/power oldval 0.0
|
||||||
|
hsetprop ${scobj_hpath}/power klass "source"
|
||||||
|
hsetprop ${scobj_hpath}/power sdsinfo "::nexus::scobj::sdsinfo"
|
||||||
|
hsetprop ${scobj_hpath}/power type "part"
|
||||||
|
hsetprop ${scobj_hpath}/power nxalias "${name}_power"
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/status plain spy text
|
||||||
|
hsetprop ${scobj_hpath}/status read ${ns}::getState ${scobj_hpath} rdAll {GET /Bragg/proposal/reactor.jsp?type=ALL HTTP/1.0}
|
||||||
|
hsetprop ${scobj_hpath}/status rdAll ${ns}::rdAll ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/status control false
|
||||||
|
hsetprop ${scobj_hpath}/status data false
|
||||||
|
hsetprop ${scobj_hpath}/status mutable false
|
||||||
|
hsetprop ${scobj_hpath}/status nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/status oldval UNKNOWN
|
||||||
|
hsetprop ${scobj_hpath}/status sdsinfo "::nexus::scobj::sdsinfo"
|
||||||
|
hsetprop ${scobj_hpath}/status type "part"
|
||||||
|
hsetprop ${scobj_hpath}/status nxalias "${name}_status"
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/tg123 plain spy float
|
||||||
|
hsetprop ${scobj_hpath}/tg123 control true
|
||||||
|
hsetprop ${scobj_hpath}/tg123 data true
|
||||||
|
hsetprop ${scobj_hpath}/tg123 mutable true
|
||||||
|
hsetprop ${scobj_hpath}/tg123 nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/tg123 oldval 0.0
|
||||||
|
hsetprop ${scobj_hpath}/tg123 klass "source"
|
||||||
|
hsetprop ${scobj_hpath}/tg123 sdsinfo "::nexus::scobj::sdsinfo"
|
||||||
|
hsetprop ${scobj_hpath}/tg123 type "part"
|
||||||
|
hsetprop ${scobj_hpath}/tg123 nxalias "${name}_tg123"
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/tg4 plain spy float
|
||||||
|
hsetprop ${scobj_hpath}/tg4 control true
|
||||||
|
hsetprop ${scobj_hpath}/tg4 data true
|
||||||
|
hsetprop ${scobj_hpath}/tg4 mutable true
|
||||||
|
hsetprop ${scobj_hpath}/tg4 nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/tg4 oldval 0.0
|
||||||
|
hsetprop ${scobj_hpath}/tg4 klass "source"
|
||||||
|
hsetprop ${scobj_hpath}/tg4 sdsinfo "::nexus::scobj::sdsinfo"
|
||||||
|
hsetprop ${scobj_hpath}/tg4 type "part"
|
||||||
|
hsetprop ${scobj_hpath}/tg4 nxalias "${name}_tg4"
|
||||||
|
|
||||||
|
hsetprop ${scobj_hpath} control "true"
|
||||||
|
hsetprop ${scobj_hpath} data "true"
|
||||||
|
|
||||||
|
if {[SplitReply [opal_simulation]]=="false"} {
|
||||||
|
${sct_controller} poll ${scobj_hpath}/status 10
|
||||||
|
}
|
||||||
|
hsetprop ${scobj_hpath} klass NXsource
|
||||||
|
# hook code starts
|
||||||
|
# hook code ends
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace eval ::scobj::reactor_status {
|
||||||
|
namespace export debug_log
|
||||||
|
namespace export mk_sct_reactor_status
|
||||||
|
}
|
||||||
|
|
||||||
|
proc add_reactor_status {name IP port} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
set ns "::scobj::reactor_status"
|
||||||
|
${ns}::debug_log 1 "add_reactor_status ${name} ${IP} ${port}"
|
||||||
|
if {[SplitReply [opal_simulation]]=="false"} {
|
||||||
|
if {[string equal -nocase "aqadapter" "${IP}"]} {
|
||||||
|
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
|
||||||
|
makesctcontroller sct_${name} aqadapter ${port}
|
||||||
|
} else {
|
||||||
|
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port}"
|
||||||
|
makesctcontroller sct_${name} std ${IP}:${port}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
${ns}::debug_log 1 "mk_sct_reactor_status sct_${name} ${name}"
|
||||||
|
${ns}::mk_sct_reactor_status sct_${name} ${name}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts stdout "file evaluation of sct_reactor_status.tcl"
|
||||||
|
::scobj::reactor_status::debug_log 1 "file evaluation of sct_reactor_status.tcl"
|
Reference in New Issue
Block a user