From a924b657e0102bd6f85f27e5eda3b6a580e564e7 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Fri, 13 Feb 2015 10:58:50 +1100 Subject: [PATCH] Generate the TCL from the new Oxford --- .../magneticField/oxford10tlv_sct.tcl | 860 ++++++++++++++++++ 1 file changed, 860 insertions(+) create mode 100644 site_ansto/instrument/config/environment/magneticField/oxford10tlv_sct.tcl diff --git a/site_ansto/instrument/config/environment/magneticField/oxford10tlv_sct.tcl b/site_ansto/instrument/config/environment/magneticField/oxford10tlv_sct.tcl new file mode 100644 index 00000000..e282bd80 --- /dev/null +++ b/site_ansto/instrument/config/environment/magneticField/oxford10tlv_sct.tcl @@ -0,0 +1,860 @@ +# Generated driver for oxford10tlv +# vim: ft=tcl tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent +# + +namespace eval ::scobj::oxford10tlv { + set debug_threshold 5 +} + +proc ::scobj::oxford10tlv::debug_log {tc_root debug_level debug_string} { + set catch_status [ catch { + set debug_threshold [hgetpropval ${tc_root} debug_threshold] + if {${debug_level} >= ${debug_threshold}} { + set now [clock seconds] + set ts [clock format ${now} -format "%Y%m%d"] + set log_file_name "../log/oxford10tlv_[basename ${tc_root}]_${ts}.log" + set fd [open "${log_file_name}" "a"] + set ts [clock format ${now} -format "%T"] + puts ${fd} "${ts} ${debug_string}" + close ${fd} + } + } catch_message ] +} + +proc ::scobj::oxford10tlv::sics_log {debug_level debug_string} { + set catch_status [ catch { + set debug_threshold ${::scobj::oxford10tlv::debug_threshold} + if {${debug_level} >= ${debug_threshold}} { + sicslog "::scobj::oxford10tlv::${debug_string}" + } + } catch_message ] +} + +# check function for hset change +proc ::scobj::oxford10tlv::check_error {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "check_error 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] + } +# check_error hook code starts + if { [hpropexists [sct] driving] } { + if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { + set my_state [hval ${tc_root}/magnet/state] + if {${my_state} != "IDLE"} { + error "Cannot run/drive in state '${my_state}', must be 'IDLE'" + } + } else { + error "Use run/drive and not hset" + } + } +# check_error hook code ends + if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } { + error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]" + } + return OK + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# checklimits function for driveable interface +proc ::scobj::oxford10tlv::checklimits {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "checklimits 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] + } +# checklimits hook code goes here + if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } { + sct driving 0 + error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]" + } + return OK + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# check function for hset change +proc ::scobj::oxford10tlv::checkrange {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 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] + } +# checkrange 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} +} + +# checkstatus function for driveable interface +proc ::scobj::oxford10tlv::checkstatus {tc_root} { + set catch_status [ catch { +# checkstatus hook code goes here + if {[sct driving]} { + set sp "[sct target]" + if {[hpropexists [sct] simulated] && [sct simulated] == "true"} { + set pv "${sp}" + hupdateif ${tc_root}/[sct driveable] ${sp} + } else { + set pv "[hval ${tc_root}/[sct driveable]]" + } + if { abs(${pv} - ${sp}) <= [sct tolerance] } { + if { [hpropexists [sct] settle_time] } { + if { [hpropexists [sct] settle_time_start] } { + if { [sct utime] - [sct settle_time_start] >= [sct settle_time]} { + sct driving 0 + return "idle" + } + return "busy" + } else { + sct utime settle_time_start + return "busy" + } + } + sct driving 0 + return "idle" + } + if { [hpropexists [sct] settle_time_start] } { + hdelprop [sct] settle_time_start + } + return "busy" + } else { + return "idle" + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to request the read of a parameter on a device +proc ::scobj::oxford10tlv::fetch_state {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "fetch_state tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set cmd "${cmd_str}" +# fetch_state hook code starts + set my_state [hval [sct]] + set cmd "@@NOSEND@@" + if {${my_state} == "START"} { + set cmd "setHS ON\r\n@@NOREPLY@@" + sct utime start_time + hupdate [sct] "HTRON" + } elseif {${my_state} == "HTRON"} { + if {[hpropexists [sct] htron_delay]} { + set htron_delay [sct htron_delay] + if {$htron_delay < 10} { + set htron_delay 30 + } elseif {$htron_delay > 60} { + set htron_delay 30 + } + } else { + set htron_delay 30 + } + if {[sct utime] - [sct start_time] > $htron_delay} { + set cmd "setF [hval ${tc_root}/magnet/setpoint]\r\n@@NOREPLY@@" + hupdate [sct] "DRIVE" + } else { + set nextState "idle" + } + } elseif {${my_state} == "DRIVE"} { + if {[hgetpropval ${tc_root}/magnet/setpoint driving] == 0} { + set cmd "setHS OFF\r\n@@NOREPLY@@" + sct utime start_time + hupdate [sct] "HTROFF" + } else { + set nextState "idle" + } + } elseif {${my_state} == "HTROFF"} { + if {[hpropexists [sct] htroff_delay]} { + set htroff_delay [sct htroff_delay] + if {$htroff_delay <= 10} { + set htroff_delay 30 + } elseif {$htroff_delay >= 60} { + set htroff_delay 30 + } + } else { + set htroff_delay 30 + } + if {[sct utime] - [sct start_time] > $htroff_delay} { + hupdate [sct] "IDLE" + } else { + set nextState "idle" + } + } elseif {${my_state} == "IDLE"} { + set nextState "idle" + } +# fetch_state hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + debug_log ${tc_root} 1 "fetch_state sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + 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::oxford10tlv::getValue {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" + if { [hpropexists [sct] geterror] } { + hdelprop [sct] geterror + } + set cmd "${cmd_str}" +# getValue hook code goes here + debug_log ${tc_root} 1 "getValue sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + sct send "${cmd}" + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# halt function for driveable interface +proc ::scobj::oxford10tlv::halt {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]" + ### TODO hset [sct] [hval [sct]] +# halt hook code goes here + sct driving 0 + return "idle" + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to check the write parameter on a device +proc ::scobj::oxford10tlv::noResponse {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]" +# noResponse 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::oxford10tlv::rdValue {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 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]" + } +# rdValue hook code goes here + if { ${data} != [sct oldval] } { + debug_log ${tc_root} 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::oxford10tlv::read_field {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "read_field 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]" + } +# read_field hook code starts + set s1 [string trimright [sct result] "\n"] + set s2 [split $s1 ";"] + if {[llength $s2] > 1} { + if {[string equal -nocase -length 14 "Field_Current=" [lindex $s2 0]]} { + #hupdateif ${tc_root}/magnet/current [string range [lindex $s2 0] 14 end] + set current [string range [lindex $s2 0] 14 end] + hsetprop ${tc_root}/magnet/current result ${current} + set ns [namespace current] + sct with ${tc_root}/magnet/current "${ns}::rdValue ${tc_root}" + } + if {[string equal -nocase -length 12 "Field_Tesla=" [lindex $s2 1]]} { + set data [string range [lindex $s2 1] 12 end] + } + } +# read_field hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + if { ${data} != [sct oldval] } { + debug_log ${tc_root} 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::oxford10tlv::read_heater {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "read_heater 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]" + } +# read_heater hook code goes here + if { ${data} != [sct oldval] } { + debug_log ${tc_root} 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::oxford10tlv::read_rate {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "read_rate 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]" + } +# read_rate hook code goes here + if { ${data} != [sct oldval] } { + debug_log ${tc_root} 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::oxford10tlv::read_state {tc_root} { + set catch_status [ catch { + debug_log ${tc_root} 1 "read_state 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]" + } +# read_state hook code starts + return "idle" +# read_state hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + if { ${data} != [sct oldval] } { + debug_log ${tc_root} 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::oxford10tlv::setValue {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 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}" +# setValue hook code goes here + if { [hpropexists [sct] driving] } { + if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { + sct driving 1 + } + } + debug_log ${tc_root} 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} +} + +# function to write a parameter value on a device +proc ::scobj::oxford10tlv::write_heater {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "write_heater 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}" +# write_heater hook code starts + if {${par} == 0} { + set cmd "setHS OFF\r\n@@NOREPLY@@" + } elseif {${par} == 1} { + set cmd "setHS ON\r\n@@NOREPLY@@" + } else { + error "Invalid parameter '${par}' should be 0 or 1" + } + # Invoke the read function to set the value as if read back + sct result $par + read_heater ${tc_root} +# write_heater hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + if { [hpropexists [sct] driving] } { + if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { + sct driving 1 + } + } + debug_log ${tc_root} 1 "write_heater sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + sct send "${cmd}" + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to write a parameter value on a device +proc ::scobj::oxford10tlv::write_rate {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "write_rate 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}" +# write_rate hook code starts + if {${par} >= 0 && ${par} <= 10} { + set cmd "setR ${par}\r\n@@NOREPLY@@" + } else { + error "Invalid parameter '${par}' should be 0 to 10" + } + # Invoke the read function to set the value as if read back + sct result $par + read_rate ${tc_root} +# write_rate hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + if { [hpropexists [sct] driving] } { + if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { + sct driving 1 + } + } + debug_log ${tc_root} 1 "write_rate sct send ${cmd}" + if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} { + sct send "${cmd}" + } + return ${nextState} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +# function to write a parameter value on a device +proc ::scobj::oxford10tlv::write_setpoint {tc_root nextState cmd_str} { + set catch_status [ catch { + debug_log ${tc_root} 1 "write_setpoint 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}" +# write_setpoint hook code starts + hset ${tc_root}/magnet/state "START" + # Force the driving flag for the state check + sct driving 1 + # Set the value on the field + hupdateif [sct] $par + # It's all over now + set cmd "@@NOSEND@@" + set nextState "idle" +# write_setpoint hook code ends + if { [hpropexists [sct] geterror] } { + debug_log ${tc_root} 9 "[sct] error: [sct geterror]" + error "[sct geterror]" + } + if { [hpropexists [sct] driving] } { + if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { + sct driving 1 + } + } + debug_log ${tc_root} 1 "write_setpoint 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::oxford10tlv::mkDriver { sct_controller name device_class simulation_flag ip_address tcp_port id datype interval } { + ::scobj::oxford10tlv::sics_log 9 "::scobj::oxford10tlv::mkDriver ${sct_controller} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${interval}" + set ns "[namespace current]" + set catch_status [ catch { + + MakeSICSObj ${name} SCT_OBJECT + + sicslist setatt ${name} driver oxford10tlv + sicslist setatt ${name} klass ${device_class} + sicslist setatt ${name} long_name ${name} + + set scobj_hpath /sics/${name} + + hfactory ${scobj_hpath}/magnet plain spy none + + hfactory ${scobj_hpath}/magnet/current plain user float + hsetprop ${scobj_hpath}/magnet/current control true + hsetprop ${scobj_hpath}/magnet/current data true + hsetprop ${scobj_hpath}/magnet/current mutable true + hsetprop ${scobj_hpath}/magnet/current nxsave true + hsetprop ${scobj_hpath}/magnet/current oldval 0.0 + hsetprop ${scobj_hpath}/magnet/current klass "parameter" + hsetprop ${scobj_hpath}/magnet/current sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/magnet/current type "part" + hsetprop ${scobj_hpath}/magnet/current nxalias "${name}_magnet_current" + + hfactory ${scobj_hpath}/magnet/field plain user float + hsetprop ${scobj_hpath}/magnet/field read ${ns}::getValue ${scobj_hpath} read_field {getF} + hsetprop ${scobj_hpath}/magnet/field read_field ${ns}::read_field ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/field control true + hsetprop ${scobj_hpath}/magnet/field data true + hsetprop ${scobj_hpath}/magnet/field mutable true + hsetprop ${scobj_hpath}/magnet/field nxsave true + hsetprop ${scobj_hpath}/magnet/field oldval 0.0 + hsetprop ${scobj_hpath}/magnet/field klass "parameter" + hsetprop ${scobj_hpath}/magnet/field sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/magnet/field type "part" + hsetprop ${scobj_hpath}/magnet/field nxalias "${name}_magnet_field" + + if {[string equal -nocase "${simulation_flag}" "false"]} { + ${sct_controller} poll ${scobj_hpath}/magnet/field 5 + hsetprop ${scobj_hpath}/magnet/field simulated false + } else { + ::scobj::oxford10tlv::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for oxford10tlv" + hsetprop ${scobj_hpath}/magnet/field simulated true + } + + hfactory ${scobj_hpath}/magnet/htr_sw plain user int + hsetprop ${scobj_hpath}/magnet/htr_sw write ${ns}::write_heater ${scobj_hpath} noResponse {} + hsetprop ${scobj_hpath}/magnet/htr_sw noResponse ${ns}::noResponse ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/htr_sw check ${ns}::checkrange ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/htr_sw control true + hsetprop ${scobj_hpath}/magnet/htr_sw data true + hsetprop ${scobj_hpath}/magnet/htr_sw mutable true + hsetprop ${scobj_hpath}/magnet/htr_sw nxsave true + hsetprop ${scobj_hpath}/magnet/htr_sw values 0,1 + hsetprop ${scobj_hpath}/magnet/htr_sw oldval 0 + hsetprop ${scobj_hpath}/magnet/htr_sw klass "parameter" + hsetprop ${scobj_hpath}/magnet/htr_sw sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/magnet/htr_sw type "part" + hsetprop ${scobj_hpath}/magnet/htr_sw nxalias "${name}_magnet_htr_sw" + + if {[string equal -nocase "${simulation_flag}" "false"]} { + ${sct_controller} write ${scobj_hpath}/magnet/htr_sw + hsetprop ${scobj_hpath}/magnet/htr_sw simulated false + } else { + ::scobj::oxford10tlv::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for oxford10tlv" + hsetprop ${scobj_hpath}/magnet/htr_sw simulated true + } + + hfactory ${scobj_hpath}/magnet/rate plain user float + hsetprop ${scobj_hpath}/magnet/rate write ${ns}::write_rate ${scobj_hpath} noResponse {} + hsetprop ${scobj_hpath}/magnet/rate noResponse ${ns}::noResponse ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/rate check ${ns}::checkrange ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/rate control true + hsetprop ${scobj_hpath}/magnet/rate data true + hsetprop ${scobj_hpath}/magnet/rate mutable true + hsetprop ${scobj_hpath}/magnet/rate nxsave true + hsetprop ${scobj_hpath}/magnet/rate oldval 0.0 + hsetprop ${scobj_hpath}/magnet/rate klass "parameter" + hsetprop ${scobj_hpath}/magnet/rate sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/magnet/rate type "part" + hsetprop ${scobj_hpath}/magnet/rate nxalias "${name}_magnet_rate" + + if {[string equal -nocase "${simulation_flag}" "false"]} { + ${sct_controller} write ${scobj_hpath}/magnet/rate + hsetprop ${scobj_hpath}/magnet/rate simulated false + } else { + ::scobj::oxford10tlv::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for oxford10tlv" + hsetprop ${scobj_hpath}/magnet/rate simulated true + } + + hfactory ${scobj_hpath}/magnet/setpoint plain user float + hsetprop ${scobj_hpath}/magnet/setpoint write ${ns}::write_setpoint ${scobj_hpath} noResponse {} + hsetprop ${scobj_hpath}/magnet/setpoint noResponse ${ns}::noResponse ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/setpoint check ${ns}::check_error ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/setpoint driving 0 + hsetprop ${scobj_hpath}/magnet/setpoint checklimits ${ns}::checklimits ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/setpoint checkstatus ${ns}::checkstatus ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/setpoint halt ${ns}::halt ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/setpoint driveable magnet/field + hsetprop ${scobj_hpath}/magnet/setpoint control true + hsetprop ${scobj_hpath}/magnet/setpoint data true + hsetprop ${scobj_hpath}/magnet/setpoint mutable true + hsetprop ${scobj_hpath}/magnet/setpoint nxsave true + hsetprop ${scobj_hpath}/magnet/setpoint lowerlimit -10 + hsetprop ${scobj_hpath}/magnet/setpoint upperlimit 10 + hsetprop ${scobj_hpath}/magnet/setpoint tolerance 0.01 + hsetprop ${scobj_hpath}/magnet/setpoint oldval 0.0 + hsetprop ${scobj_hpath}/magnet/setpoint klass "parameter" + hsetprop ${scobj_hpath}/magnet/setpoint sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/magnet/setpoint settle_time "30" + hsetprop ${scobj_hpath}/magnet/setpoint type "drivable" + hsetprop ${scobj_hpath}/magnet/setpoint nxalias "${name}_magnet_setpoint" + + if {[string equal -nocase "${simulation_flag}" "false"]} { + ${sct_controller} write ${scobj_hpath}/magnet/setpoint + hsetprop ${scobj_hpath}/magnet/setpoint simulated false + } else { + ::scobj::oxford10tlv::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for oxford10tlv" + hsetprop ${scobj_hpath}/magnet/setpoint simulated true + } + + hfactory ${scobj_hpath}/magnet/state plain user text + hsetprop ${scobj_hpath}/magnet/state read ${ns}::fetch_state ${scobj_hpath} read_state {} + hsetprop ${scobj_hpath}/magnet/state read_state ${ns}::read_state ${scobj_hpath} + hsetprop ${scobj_hpath}/magnet/state control true + hsetprop ${scobj_hpath}/magnet/state data false + hsetprop ${scobj_hpath}/magnet/state mutable false + hsetprop ${scobj_hpath}/magnet/state nxsave false + hsetprop ${scobj_hpath}/magnet/state oldval IDLE + hset ${scobj_hpath}/magnet/state IDLE + hsetprop ${scobj_hpath}/magnet/state htroff_delay "10" + hsetprop ${scobj_hpath}/magnet/state htron_delay "10" + hsetprop ${scobj_hpath}/magnet/state sdsinfo "::nexus::scobj::sdsinfo" + hsetprop ${scobj_hpath}/magnet/state type "part" + hsetprop ${scobj_hpath}/magnet/state nxalias "${name}_magnet_state" + + if {[string equal -nocase "${simulation_flag}" "false"]} { + ${sct_controller} poll ${scobj_hpath}/magnet/state 1 + hsetprop ${scobj_hpath}/magnet/state simulated false + } else { + ::scobj::oxford10tlv::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for oxford10tlv" + hsetprop ${scobj_hpath}/magnet/state simulated true + } + hsetprop ${scobj_hpath}/magnet data "true" + hsetprop ${scobj_hpath}/magnet klass "@none" + hsetprop ${scobj_hpath}/magnet type "part" + ansto_makesctdrive ${name}_magnet_setpoint ${scobj_hpath}/magnet/setpoint ${scobj_hpath}/magnet/field ${sct_controller} + hsetprop ${scobj_hpath} driver oxford10tlv + hsetprop ${scobj_hpath} klass ${device_class} + hsetprop ${scobj_hpath} data true + hsetprop ${scobj_hpath} debug_threshold 5 +# mkDriver hook code goes here + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +proc ::scobj::oxford10tlv::add_driver {name device_class simulation_flag ip_address tcp_port id datype interval} { + set catch_status [ catch { + ::scobj::oxford10tlv::sics_log 9 "::scobj::oxford10tlv::add_driver ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${interval}" + if {[string equal -nocase "${simulation_flag}" "false"]} { + if {[string equal -nocase "aqadapter" "${ip_address}"]} { + ::scobj::oxford10tlv::sics_log 9 "makesctcontroller sct_${name} aqadapter ${tcp_port}" + makesctcontroller sct_${name} aqadapter ${tcp_port} + } else { + ::scobj::oxford10tlv::sics_log 9 "makesctcontroller sct_${name} std ${ip_address}:${tcp_port}" + makesctcontroller sct_${name} std ${ip_address}:${tcp_port} + } + } else { + ::scobj::oxford10tlv::sics_log 9 "simulation_flag=${simulation_flag} => Null sctcontroller for oxford10tlv" + ::scobj::oxford10tlv::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL" + makesctcontroller sct_${name} aqadapter NULL + } + ::scobj::oxford10tlv::sics_log 1 "::scobj::oxford10tlv::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${interval}" + ::scobj::oxford10tlv::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${interval} + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +namespace eval ::scobj::oxford10tlv { + namespace export debug_threshold + namespace export debug_log + namespace export sics_log + namespace export mkDriver + namespace export add_driver +} + +proc add_oxford10tlv {name ip_address tcp_port id datype interval} { + set simulation_flag "[string tolower [SplitReply [environment_simulation]]]" + ::scobj::oxford10tlv::add_driver ${name} "environment" ${simulation_flag} ${ip_address} ${tcp_port} ${id} ${datype} ${interval} +} + +clientput "file evaluation of oxford10tlv_sct.tcl" +::scobj::oxford10tlv::sics_log 9 "file evaluation of oxford10tlv_sct.tcl" + +proc ::scobj::oxford10tlv::read_config {} { + set catch_status [ catch { + set ns "::scobj::oxford10tlv" + dict for {k u} $::config_dict { + if { [dict exists $u "implementation"] } { + set simulation_flag "[string tolower [SplitReply [environment_simulation]]]" + set device_class "environment" + if { !([dict exists $u "name"] && [dict exists $u "enabled"]) } { + continue + } + set enabled [string tolower [dict get $u "enabled"]] + if { ! ([string equal -nocase $enabled "true" ] || [string equal -nocase $enabled "always"]) } { + continue + } + if { [dict exists $u "simulation_group"] } { + set simulation_flag [SplitReply [[string tolower [dict get $u "simulation_group"]]]] + } + if { [dict exists $u "device_class"] } { + set device_class "[dict get $u "device_class"]" + } + set name [dict get $u name] + set implementation [dict get $u "implementation"] + if { !([dict exists $::config_dict $implementation]) } { + continue + } + set v [dict get $::config_dict $implementation] + if { !([dict exists $v "driver"]) } { + continue + } + if { [string equal -nocase [dict get $v "driver"] "oxford10tlv"] } { + if { ![string equal -nocase "${simulation_flag}" "false"] } { + set asyncqueue "null" + ${ns}::sics_log 9 "simulation_flag=${simulation_flag} => using null asyncqueue" + ${ns}::sics_log 9 "makesctcontroller sct_${name} aqadapter NULL" + makesctcontroller sct_${name} aqadapter NULL + } elseif { [dict exists $v "asyncqueue"] } { + set asyncqueue [dict get $v "asyncqueue"] + if { [string equal -nocase ${asyncqueue} "sct"] } { + set ip_address [dict get $v ip] + set tcp_port [dict get $v port] + makesctcontroller sct_${name} std ${ip_address}:${tcp_port} + } else { + makesctcontroller sct_${name} aqadapter ${asyncqueue} + } + } else { + if { [dict exists $v "asyncprotocol"] } { + set asyncprotocol [dict get $v "asyncprotocol"] + } else { + set asyncprotocol ${name}_protocol + MakeAsyncProtocol ${asyncprotocol} + if { [dict exists $v "sendterminator"] } { + ${asyncprotocol} sendterminator "[dict get $v "sendterminator"]" + } elseif { [dict exists $v "terminator"] } { + ${asyncprotocol} sendterminator "[dict get $v "terminator"]" + } + if { [dict exists $v "replyterminator"] } { + ${asyncprotocol} replyterminator "[dict get $v "replyterminator"]" + } elseif { [dict exists $v "terminator"] } { + ${asyncprotocol} replyterminator "[dict get $v "terminator"]" + } + } + set asyncqueue ${name}_queue + set ip_address [dict get $v ip] + set tcp_port [dict get $v port] + MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${ip_address} ${tcp_port} + if { [dict exists $v "timeout"] } { + ${asyncqueue} timeout "[dict get $v "timeout"]" + } + makesctcontroller sct_${name} aqadapter ${asyncqueue} + } + set arg_list [list] + set missing_list [list] + foreach arg {id datype interval} { + if {[dict exists $u $arg]} { + lappend arg_list "[dict get $u $arg]" + } elseif {[dict exists $v $arg]} { + lappend arg_list "[dict get $v $arg]" + } else { + ${ns}::sics_log 9 "Missing configuration value $arg" + lappend missing_list $arg + } + } + if { [llength $missing_list] > 0 } { + error "$name is missing configuration values $missing_list" + } + ${ns}::mkDriver sct_${name} ${name} ${device_class} ${simulation_flag} ${ip_address} ${tcp_port} {*}$arg_list + } + } + } + } catch_message ] + handle_exception ${catch_status} ${catch_message} +} + +if { [info exists ::config_dict] } { + ::scobj::oxford10tlv::read_config +} else { + ::scobj::oxford10tlv::sics_log 5 "No config dict" +}