Regen sct drivers with async and logging changes

This commit is contained in:
Douglas Clowes
2014-05-16 10:22:58 +10:00
parent 86673f6a8f
commit 81ed966092
7 changed files with 624 additions and 484 deletions

View File

@ -3,13 +3,14 @@
#
namespace eval ::scobj::shutters {
set debug_threshold 0
set debug_threshold 5
}
proc ::scobj::shutters::debug_log {debug_level debug_string} {
proc ::scobj::shutters::debug_log {tc_root debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::shutters::debug_threshold}} {
set fd [open "/tmp/shutters.log" "a"]
set debug_threshold [hgetpropval ${tc_root} debug_threshold]
if {${debug_level} >= ${debug_threshold}} {
set fd [open "/tmp/shutters_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
@ -17,10 +18,19 @@ proc ::scobj::shutters::debug_log {debug_level debug_string} {
} catch_message ]
}
proc ::scobj::shutters::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::shutters::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::shutters::${debug_string}"
}
} catch_message ]
}
# check function for hset change
proc ::scobj::shutters::checkrange {tc_root} {
set catch_status [ catch {
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -34,7 +44,7 @@ proc ::scobj::shutters::checkrange {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checkrange hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -46,13 +56,13 @@ proc ::scobj::shutters::checkrange {tc_root} {
# function to request the read of a parameter on a device
proc ::scobj::shutters::getValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
debug_log 1 "getValue sct send ${cmd}"
# 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}"
}
@ -64,8 +74,8 @@ proc ::scobj::shutters::getValue {tc_root nextState cmd_str} {
# function to check the write parameter on a device
proc ::scobj::shutters::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
# hook code goes here
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}
@ -74,7 +84,7 @@ proc ::scobj::shutters::noResponse {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::shutters::read_switch_pair {tc_root} {
set catch_status [ catch {
debug_log 1 "read_switch_pair tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_switch_pair tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -85,7 +95,7 @@ proc ::scobj::shutters::read_switch_pair {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# read_switch_pair hook code starts
if { [string equal -nocase -length 1 "${data}" "?"] } {
sct geterror "Galil error in: '${data}'"
} else {
@ -107,13 +117,13 @@ proc ::scobj::shutters::read_switch_pair {tc_root} {
sct geterror "Syntax error in: '${data}'=>'${data_list}'"
}
}
# hook code ends
# read_switch_pair hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -126,19 +136,19 @@ proc ::scobj::shutters::read_switch_pair {tc_root} {
# function to write a parameter value on a device
proc ::scobj::shutters::setValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
# setValue 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}"
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -150,13 +160,13 @@ proc ::scobj::shutters::setValue {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::shutters::write_switch {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "write_switch tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "write_switch 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 starts
# write_switch hook code starts
if { [string equal -nocase -length 2 "${par}" "in"] } {
set cmd "SB${cmd_str}"
} elseif { [string equal -nocase -length 2 "${par}" "out"] } {
@ -164,9 +174,9 @@ proc ::scobj::shutters::write_switch {tc_root nextState cmd_str} {
} else {
sct geterror "Value error: '${par}' not in ('in', 'out')"
}
# hook code ends
# write_switch hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -174,7 +184,7 @@ proc ::scobj::shutters::write_switch {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "write_switch sct send ${cmd}"
debug_log ${tc_root} 1 "write_switch sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -183,8 +193,8 @@ proc ::scobj::shutters::write_switch {tc_root nextState cmd_str} {
handle_exception ${catch_status} ${catch_message}
}
proc ::scobj::shutters::mk_sct_shutters { sct_controller name } {
debug_log 1 "mk_sct_shutters for ${name}"
proc ::scobj::shutters::mkDriver { sct_controller name } {
::scobj::shutters::sics_log 9 "::scobj::shutters::mkDriver for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
@ -253,63 +263,71 @@ proc ::scobj::shutters::mk_sct_shutters { sct_controller name } {
${sct_controller} write ${scobj_hpath}/rough_40
}
hsetprop ${scobj_hpath} klass instrument
# hook code starts
# hook code ends
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code starts
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::shutters {
namespace export debug_threshold
namespace export debug_log
namespace export mk_sct_shutters
namespace export sics_log
namespace export mkDriver
}
proc add_shutters {name IP port} {
set catch_status [ catch {
set ns "::scobj::shutters"
${ns}::debug_log 1 "add_shutters ${name} ${IP} ${port}"
::scobj::shutters::sics_log 9 "add_shutters ${name} ${IP} ${port}"
if {[SplitReply [motor_simulation]]=="false"} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
::scobj::shutters::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} dmc2280 ${IP}:${port}"
::scobj::shutters::sics_log 9 "makesctcontroller sct_${name} dmc2280 ${IP}:${port}"
makesctcontroller sct_${name} dmc2280 ${IP}:${port}
}
}
${ns}::debug_log 1 "mk_sct_shutters sct_${name} ${name}"
${ns}::mk_sct_shutters sct_${name} ${name}
::scobj::shutters::sics_log 1 "::scobj::shutters::mkDriver sct_${name} ${name}"
::scobj::shutters::mkDriver sct_${name} ${name}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
puts stdout "file evaluation of sct_shutters.tcl"
::scobj::shutters::debug_log 1 "file evaluation of sct_shutters.tcl"
::scobj::shutters::sics_log 9 "file evaluation of sct_shutters.tcl"
proc ::scobj::shutters::read_config {} {
set catch_status [ catch {
set ns "::scobj::shutters"
${ns}::debug_log 1 "Processing Config"
dict for {k v} $::config_dict {
${ns}::debug_log 1 "Inspecting $k:$v"
if { [dict exists $v "driver"] } {
${ns}::debug_log 1 "Has driver [dict get $v driver]"
if { [dict get $v "driver"] == "shutters" } {
${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"
if { [dict get $v enabled] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
set name [dict get $v name]
MakeAsyncProtocol ${name}_protocol
if { [dict exists $v "terminator"] } {
${name}_protocol sendterminator "[dict get $v "terminator"]"
${name}_protocol replyterminator "[dict get $v "terminator"]"
if { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${name}_queue timeout "[dict get $v "timeout"]"
}
add_shutters ${name} "aqadapter" ${name}_queue
add_shutters ${name} "aqadapter" ${asyncqueue}
}
}
}
@ -317,8 +335,9 @@ proc ::scobj::shutters::read_config {} {
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::shutters::read_config
} else {
::scobj::shutters:debug_log 1 "No config dict"
::scobj::shutters::sics_log 5 "No config dict"
}

View File

@ -3,13 +3,14 @@
#
namespace eval ::scobj::tank {
set debug_threshold 0
set debug_threshold 5
}
proc ::scobj::tank::debug_log {debug_level debug_string} {
proc ::scobj::tank::debug_log {tc_root debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::tank::debug_threshold}} {
set fd [open "/tmp/tank.log" "a"]
set debug_threshold [hgetpropval ${tc_root} debug_threshold]
if {${debug_level} >= ${debug_threshold}} {
set fd [open "/tmp/tank_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
@ -17,10 +18,19 @@ proc ::scobj::tank::debug_log {debug_level debug_string} {
} catch_message ]
}
proc ::scobj::tank::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::tank::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::tank::${debug_string}"
}
} catch_message ]
}
# check function for hset change
proc ::scobj::tank::checkrange {tc_root} {
set catch_status [ catch {
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -34,7 +44,7 @@ proc ::scobj::tank::checkrange {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checkrange hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -46,13 +56,13 @@ proc ::scobj::tank::checkrange {tc_root} {
# function to request the read of a parameter on a device
proc ::scobj::tank::getValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
debug_log 1 "getValue sct send ${cmd}"
# 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}"
}
@ -64,8 +74,8 @@ proc ::scobj::tank::getValue {tc_root nextState cmd_str} {
# function to check the write parameter on a device
proc ::scobj::tank::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
# hook code goes here
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}
@ -74,7 +84,7 @@ proc ::scobj::tank::noResponse {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::tank::read_switch {tc_root} {
set catch_status [ catch {
debug_log 1 "read_switch tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_switch tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -85,7 +95,7 @@ proc ::scobj::tank::read_switch {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# read_switch hook code starts
if { [string equal -nocase -length 1 "${data}" "?"] } {
sct geterror "Galil error in: '${data}'"
} else {
@ -104,13 +114,13 @@ proc ::scobj::tank::read_switch {tc_root} {
sct geterror "Syntax error in: '${data}'=>'${data_list}'"
}
}
# hook code ends
# read_switch hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -123,19 +133,19 @@ proc ::scobj::tank::read_switch {tc_root} {
# function to write a parameter value on a device
proc ::scobj::tank::setValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
# setValue 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}"
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -144,8 +154,8 @@ proc ::scobj::tank::setValue {tc_root nextState cmd_str} {
handle_exception ${catch_status} ${catch_message}
}
proc ::scobj::tank::mk_sct_tank { sct_controller name } {
debug_log 1 "mk_sct_tank for ${name}"
proc ::scobj::tank::mkDriver { sct_controller name } {
::scobj::tank::sics_log 9 "::scobj::tank::mkDriver for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
@ -218,63 +228,71 @@ proc ::scobj::tank::mk_sct_tank { sct_controller name } {
${sct_controller} poll ${scobj_hpath}/switches/reverse 1
}
hsetprop ${scobj_hpath} klass instrument
# hook code starts
# hook code ends
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code starts
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::tank {
namespace export debug_threshold
namespace export debug_log
namespace export mk_sct_tank
namespace export sics_log
namespace export mkDriver
}
proc add_tank {name IP port} {
set catch_status [ catch {
set ns "::scobj::tank"
${ns}::debug_log 1 "add_tank ${name} ${IP} ${port}"
::scobj::tank::sics_log 9 "add_tank ${name} ${IP} ${port}"
if {[SplitReply [motor_simulation]]=="false"} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
::scobj::tank::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} dmc2280 ${IP}:${port}"
::scobj::tank::sics_log 9 "makesctcontroller sct_${name} dmc2280 ${IP}:${port}"
makesctcontroller sct_${name} dmc2280 ${IP}:${port}
}
}
${ns}::debug_log 1 "mk_sct_tank sct_${name} ${name}"
${ns}::mk_sct_tank sct_${name} ${name}
::scobj::tank::sics_log 1 "::scobj::tank::mkDriver sct_${name} ${name}"
::scobj::tank::mkDriver sct_${name} ${name}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
puts stdout "file evaluation of sct_tank.tcl"
::scobj::tank::debug_log 1 "file evaluation of sct_tank.tcl"
::scobj::tank::sics_log 9 "file evaluation of sct_tank.tcl"
proc ::scobj::tank::read_config {} {
set catch_status [ catch {
set ns "::scobj::tank"
${ns}::debug_log 1 "Processing Config"
dict for {k v} $::config_dict {
${ns}::debug_log 1 "Inspecting $k:$v"
if { [dict exists $v "driver"] } {
${ns}::debug_log 1 "Has driver [dict get $v driver]"
if { [dict get $v "driver"] == "tank" } {
${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"
if { [dict get $v enabled] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
set name [dict get $v name]
MakeAsyncProtocol ${name}_protocol
if { [dict exists $v "terminator"] } {
${name}_protocol sendterminator "[dict get $v "terminator"]"
${name}_protocol replyterminator "[dict get $v "terminator"]"
if { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${name}_queue timeout "[dict get $v "timeout"]"
}
add_tank ${name} "aqadapter" ${name}_queue
add_tank ${name} "aqadapter" ${asyncqueue}
}
}
}
@ -282,8 +300,9 @@ proc ::scobj::tank::read_config {} {
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::tank::read_config
} else {
::scobj::tank:debug_log 1 "No config dict"
::scobj::tank::sics_log 5 "No config dict"
}

View File

@ -3,13 +3,14 @@
#
namespace eval ::scobj::hiden_xcs {
set debug_threshold 0
set debug_threshold 5
}
proc ::scobj::hiden_xcs::debug_log {debug_level debug_string} {
proc ::scobj::hiden_xcs::debug_log {tc_root debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::hiden_xcs::debug_threshold}} {
set fd [open "/tmp/hiden_xcs.log" "a"]
set debug_threshold [hgetpropval ${tc_root} debug_threshold]
if {${debug_level} >= ${debug_threshold}} {
set fd [open "/tmp/hiden_xcs_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
@ -17,10 +18,19 @@ proc ::scobj::hiden_xcs::debug_log {debug_level debug_string} {
} catch_message ]
}
proc ::scobj::hiden_xcs::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::hiden_xcs::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::hiden_xcs::${debug_string}"
}
} catch_message ]
}
# checklimits function for driveable interface
proc ::scobj::hiden_xcs::checklimits {tc_root} {
set catch_status [ catch {
debug_log 1 "checklimits tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -34,7 +44,7 @@ proc ::scobj::hiden_xcs::checklimits {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checklimits hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
sct driving 0
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
@ -47,7 +57,7 @@ proc ::scobj::hiden_xcs::checklimits {tc_root} {
# check function for hset change
proc ::scobj::hiden_xcs::checkrange {tc_root} {
set catch_status [ catch {
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -61,7 +71,7 @@ proc ::scobj::hiden_xcs::checkrange {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checkrange hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -73,7 +83,7 @@ proc ::scobj::hiden_xcs::checkrange {tc_root} {
# checkstatus function for driveable interface
proc ::scobj::hiden_xcs::checkstatus {tc_root} {
set catch_status [ catch {
# hook code goes here
# checkstatus hook code goes here
if {[sct driving]} {
set sp "[sct target]"
set pv "[hval ${tc_root}/[sct driveable]]"
@ -107,7 +117,7 @@ proc ::scobj::hiden_xcs::checkstatus {tc_root} {
# check function for hset change
proc ::scobj::hiden_xcs::chkrange_function {tc_root} {
set catch_status [ catch {
debug_log 1 "chkrange_function tc_root=${tc_root} sct=[sct] target=[sct target]"
debug_log ${tc_root} 1 "chkrange_function tc_root=${tc_root} sct=[sct] target=[sct target]"
set setpoint [sct target]
if { [hpropexists [sct] lowerlimit] } {
set lolimit [sct lowerlimit]
@ -121,9 +131,9 @@ proc ::scobj::hiden_xcs::chkrange_function {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code starts
# chkrange_function hook code starts
# hooked
# hook code ends
# chkrange_function hook code ends
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -135,12 +145,12 @@ proc ::scobj::hiden_xcs::chkrange_function {tc_root} {
# function to request the read of a parameter on a device
proc ::scobj::hiden_xcs::fetch_flow {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "fetch_flow tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "fetch_flow tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
set cmd "${cmd_str}"
# hook code starts
# fetch_flow hook code starts
set data 0.0
foreach node [list flow1 flow2] {
set data [expr ${data} + [hval ${tc_root}/${node}]]
@ -152,12 +162,12 @@ proc ::scobj::hiden_xcs::fetch_flow {tc_root nextState cmd_str} {
pid_flow ${tc_root} ${sp} ${data}
}
set cmd "@@NOSEND@@"
# hook code ends
# fetch_flow hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
debug_log 1 "fetch_flow sct send ${cmd}"
debug_log ${tc_root} 1 "fetch_flow sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -169,13 +179,13 @@ proc ::scobj::hiden_xcs::fetch_flow {tc_root nextState cmd_str} {
# function to request the read of a parameter on a device
proc ::scobj::hiden_xcs::getValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
debug_log 1 "getValue sct send ${cmd}"
# 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}"
}
@ -187,9 +197,9 @@ proc ::scobj::hiden_xcs::getValue {tc_root nextState cmd_str} {
# halt function for driveable interface
proc ::scobj::hiden_xcs::halt {tc_root} {
set catch_status [ catch {
debug_log 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
debug_log ${tc_root} 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
### TODO hset [sct] [hval [sct]]
# hook code goes here
# halt hook code goes here
sct driving 0
return "idle"
} catch_message ]
@ -199,8 +209,8 @@ proc ::scobj::hiden_xcs::halt {tc_root} {
# function to check the write parameter on a device
proc ::scobj::hiden_xcs::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
# hook code goes here
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}
@ -209,17 +219,17 @@ proc ::scobj::hiden_xcs::noResponse {tc_root} {
# function to write a parameter value on a device
proc ::scobj::hiden_xcs::no_op {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "no_op tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "no_op 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 starts
# no_op hook code starts
set cmd "@@NOSEND@@"
# hook code ends
# no_op hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -227,7 +237,7 @@ proc ::scobj::hiden_xcs::no_op {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "no_op sct send ${cmd}"
debug_log ${tc_root} 1 "no_op sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -239,7 +249,7 @@ proc ::scobj::hiden_xcs::no_op {tc_root nextState cmd_str} {
# pid function for PID control
proc ::scobj::hiden_xcs::pid_flow {tc_root sp pv} {
set catch_status [ catch {
debug_log 1 "pid_flow tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
debug_log ${tc_root} 1 "pid_flow tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
sct pid_error [expr ${sp} - ${pv}]
set p_value [expr [sct pid_pvalue] * [sct pid_error]]
set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]
@ -253,16 +263,18 @@ proc ::scobj::hiden_xcs::pid_flow {tc_root sp pv} {
}
set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
set pid [expr ${p_value} + ${i_value} + ${d_value}]
# hook code starts
foreach node [list analog/sp1 analog/sp2] {
hsetprop ${tc_root}/${node} bias_flow ${pid}
if { [hpropexists ${tc_root}/${node} target] } {
hset ${tc_root}/${node} [hgetpropval ${tc_root}/${node} target]
} else {
hset ${tc_root}/${node} [hval ${tc_root}/${node}]
# pid_flow hook code starts
foreach node [list ${tc_root}/analog/sp1 ${tc_root}/analog/sp2] {
if { !([hpropexists ${node} bias_flow] && [hgetpropval ${node} bias_flow] == ${pid}) } {
hsetprop ${node} bias_flow ${pid}
if { [hpropexists ${node} target] } {
hset ${node} [hgetpropval ${node} target]
} else {
hset ${node} [hval ${node}]
}
}
}
# hook code ends
# pid_flow hook code ends
sct pid_output ${pid}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
@ -272,7 +284,7 @@ proc ::scobj::hiden_xcs::pid_flow {tc_root sp pv} {
# pid function for PID control
proc ::scobj::hiden_xcs::pid_humidity {tc_root sp pv} {
set catch_status [ catch {
debug_log 1 "pid_humidity tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
debug_log ${tc_root} 1 "pid_humidity tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
sct pid_error [expr ${sp} - ${pv}]
set p_value [expr [sct pid_pvalue] * [sct pid_error]]
set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]
@ -286,19 +298,21 @@ proc ::scobj::hiden_xcs::pid_humidity {tc_root sp pv} {
}
set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
set pid [expr ${p_value} + ${i_value} + ${d_value}]
# hook code starts
# pid_humidity hook code starts
set sign 1
foreach node [list analog/sp1 analog/sp2] {
foreach node [list ${tc_root}/analog/sp1 ${tc_root}/analog/sp2] {
set sign [expr -${sign}]
set signed_pid [expr ${sign} * ${pid}]
hsetprop ${tc_root}/${node} bias_humidity ${signed_pid}
if { [hpropexists ${tc_root}/${node} target] } {
hset ${tc_root}/${node} [hgetpropval ${tc_root}/${node} target]
} else {
hset ${tc_root}/${node} [hval ${tc_root}/${node}]
if { !([hpropexists ${node} bias_humidity] && [hgetpropval ${node} bias_humidity] == ${signed_pid}) } {
hsetprop ${node} bias_humidity ${signed_pid}
if { [hpropexists ${node} target] } {
hset ${node} [hgetpropval ${node} target]
} else {
hset ${node} [hval ${node}]
}
}
}
# hook code ends
# pid_humidity hook code ends
sct pid_output ${pid}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
@ -308,7 +322,7 @@ proc ::scobj::hiden_xcs::pid_humidity {tc_root sp pv} {
# function to parse the read of a parameter on a device
proc ::scobj::hiden_xcs::rdValue {tc_root} {
set catch_status [ catch {
debug_log 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -319,9 +333,9 @@ proc ::scobj::hiden_xcs::rdValue {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code goes here
# rdValue hook code goes here
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -334,7 +348,7 @@ proc ::scobj::hiden_xcs::rdValue {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::hiden_xcs::read_all_data {tc_root} {
set catch_status [ catch {
debug_log 1 "read_all_data tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_all_data tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -345,7 +359,7 @@ proc ::scobj::hiden_xcs::read_all_data {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# read_all_data hook code starts
if { [string equal -nocase -length 2 "${data}" "A "] } {
set data_list [split [string range "${data}" 2 end-3] ',']
if { [llength ${data_list}] == 8 } {
@ -365,13 +379,13 @@ proc ::scobj::hiden_xcs::read_all_data {tc_root} {
set sp [hgetpropval ${sp} target]
pid_humidity ${tc_root} ${sp} ${data}
}
# hook code ends
# read_all_data hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -384,7 +398,7 @@ proc ::scobj::hiden_xcs::read_all_data {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::hiden_xcs::read_digital {tc_root} {
set catch_status [ catch {
debug_log 1 "read_digital tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_digital tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -395,7 +409,7 @@ proc ::scobj::hiden_xcs::read_digital {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# read_digital hook code starts
if { [string equal -nocase -length 5 "${data}" "DOUT ="] } {
set result [scan "${data}" "DOUT = %d OK" val]
if { ${result} == 1 } {
@ -406,13 +420,13 @@ proc ::scobj::hiden_xcs::read_digital {tc_root} {
} else {
sct geterror "Syntax error in: '${data}'"
}
# hook code ends
# read_digital hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -425,7 +439,7 @@ proc ::scobj::hiden_xcs::read_digital {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::hiden_xcs::read_flow {tc_root} {
set catch_status [ catch {
debug_log 1 "read_flow tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_flow tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -436,9 +450,9 @@ proc ::scobj::hiden_xcs::read_flow {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code goes here
# read_flow hook code goes here
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -451,7 +465,7 @@ proc ::scobj::hiden_xcs::read_flow {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::hiden_xcs::read_sixteen {tc_root} {
set catch_status [ catch {
debug_log 1 "read_sixteen tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_sixteen tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -462,7 +476,7 @@ proc ::scobj::hiden_xcs::read_sixteen {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# read_sixteen hook code starts
if { [string equal -nocase -length 5 "${data}" "AIN ="] } {
set result [scan "${data}" "AIN = %d OK" val]
if { ${result} == 1 } {
@ -483,13 +497,13 @@ proc ::scobj::hiden_xcs::read_sixteen {tc_root} {
} else {
sct geterror "Syntax error in: '${data}'"
}
# hook code ends
# read_sixteen hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -502,7 +516,7 @@ proc ::scobj::hiden_xcs::read_sixteen {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::hiden_xcs::read_twelve {tc_root} {
set catch_status [ catch {
debug_log 1 "read_twelve tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_twelve tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -513,7 +527,7 @@ proc ::scobj::hiden_xcs::read_twelve {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# read_twelve hook code starts
if { [string equal -nocase -length 5 "${data}" "AOUT ="] } {
set result [scan "${data}" "AOUT = %d OK" val]
if { ${result} == 1 } {
@ -534,13 +548,13 @@ proc ::scobj::hiden_xcs::read_twelve {tc_root} {
} else {
sct geterror "Syntax error in: '${data}'"
}
# hook code ends
# read_twelve hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -553,19 +567,19 @@ proc ::scobj::hiden_xcs::read_twelve {tc_root} {
# function to write a parameter value on a device
proc ::scobj::hiden_xcs::setValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
# setValue 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}"
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -577,19 +591,19 @@ proc ::scobj::hiden_xcs::setValue {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::hiden_xcs::write_digital {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "write_digital tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "write_digital 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
# write_digital hook code goes here
if { [hpropexists [sct] driving] } {
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
sct driving 1
}
}
debug_log 1 "write_digital sct send ${cmd}"
debug_log ${tc_root} 1 "write_digital sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -601,13 +615,13 @@ proc ::scobj::hiden_xcs::write_digital {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::hiden_xcs::write_flow {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "write_flow tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "write_flow 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 starts
# write_flow hook code starts
if { [hpropexists ${tc_root}/humidity/setpoint target] } {
set humidity_target [hgetpropval ${tc_root}/humidity/setpoint target]
} else {
@ -619,9 +633,9 @@ proc ::scobj::hiden_xcs::write_flow {tc_root nextState cmd_str} {
hset ${tc_root}/analog/sp2 ${flow2_target}
set nextState "idle"
set cmd "@@NOSEND@@"
# hook code ends
# write_flow hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -629,7 +643,7 @@ proc ::scobj::hiden_xcs::write_flow {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "write_flow sct send ${cmd}"
debug_log ${tc_root} 1 "write_flow sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -641,13 +655,13 @@ proc ::scobj::hiden_xcs::write_flow {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::hiden_xcs::write_humidity {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "write_humidity tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "write_humidity 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 starts
# write_humidity hook code starts
if { [hpropexists ${tc_root}/flow/setpoint target] } {
set flow_target [hgetpropval ${tc_root}/flow/setpoint target]
} else {
@ -659,9 +673,9 @@ proc ::scobj::hiden_xcs::write_humidity {tc_root nextState cmd_str} {
hset ${tc_root}/analog/sp2 ${flow2_target}
set nextState "idle"
set cmd "@@NOSEND@@"
# hook code ends
# write_humidity hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -669,7 +683,7 @@ proc ::scobj::hiden_xcs::write_humidity {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "write_humidity sct send ${cmd}"
debug_log ${tc_root} 1 "write_humidity sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -681,13 +695,13 @@ proc ::scobj::hiden_xcs::write_humidity {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::hiden_xcs::write_twelve {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "write_twelve tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "write_twelve 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 starts
# write_twelve hook code starts
if { [hpropexists [sct] base] } {
set base [sct base]
} else {
@ -712,9 +726,9 @@ proc ::scobj::hiden_xcs::write_twelve {tc_root nextState cmd_str} {
}
set par [expr int(${base} + (4095.0 * ${par} / ${span}))]
set cmd "${cmd_str}${par}"
# hook code ends
# write_twelve hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -722,7 +736,7 @@ proc ::scobj::hiden_xcs::write_twelve {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "write_twelve sct send ${cmd}"
debug_log ${tc_root} 1 "write_twelve sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -731,8 +745,8 @@ proc ::scobj::hiden_xcs::write_twelve {tc_root nextState cmd_str} {
handle_exception ${catch_status} ${catch_message}
}
proc ::scobj::hiden_xcs::mk_sct_hiden_xcs { sct_controller name id } {
debug_log 1 "mk_sct_hiden_xcs ${sct_controller} ${name} ${id}"
proc ::scobj::hiden_xcs::mkDriver { sct_controller name id } {
::scobj::hiden_xcs::sics_log 9 "::scobj::hiden_xcs::mkDriver ${sct_controller} ${name} ${id}"
set ns "[namespace current]"
set catch_status [ catch {
@ -1092,74 +1106,80 @@ proc ::scobj::hiden_xcs::mk_sct_hiden_xcs { sct_controller name id } {
ansto_makesctdrive ${name}_humidity_setpoint ${scobj_hpath}/humidity/setpoint ${scobj_hpath}/humidity/sensor ${sct_controller}
}
hsetprop ${scobj_hpath} klass environment
# hook code starts
# hook code ends
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code starts
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::hiden_xcs {
namespace export debug_threshold
namespace export debug_log
namespace export mk_sct_hiden_xcs
namespace export sics_log
namespace export mkDriver
}
proc add_hiden_xcs {name IP port id} {
set catch_status [ catch {
set ns "::scobj::hiden_xcs"
${ns}::debug_log 1 "add_hiden_xcs ${name} ${IP} ${port} ${id}"
::scobj::hiden_xcs::sics_log 9 "add_hiden_xcs ${name} ${IP} ${port} ${id}"
if {[SplitReply [environment_simulation]]=="false"} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
::scobj::hiden_xcs::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port}"
::scobj::hiden_xcs::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}"
makesctcontroller sct_${name} std ${IP}:${port}
}
}
${ns}::debug_log 1 "mk_sct_hiden_xcs sct_${name} ${name} ${id}"
${ns}::mk_sct_hiden_xcs sct_${name} ${name} ${id}
::scobj::hiden_xcs::sics_log 1 "::scobj::hiden_xcs::mkDriver sct_${name} ${name} ${id}"
::scobj::hiden_xcs::mkDriver sct_${name} ${name} ${id}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
puts stdout "file evaluation of sct_hiden_xcs.tcl"
::scobj::hiden_xcs::debug_log 1 "file evaluation of sct_hiden_xcs.tcl"
::scobj::hiden_xcs::sics_log 9 "file evaluation of sct_hiden_xcs.tcl"
proc ::scobj::hiden_xcs::read_config {} {
set catch_status [ catch {
set ns "::scobj::hiden_xcs"
${ns}::debug_log 1 "Processing Config"
dict for {k v} $::config_dict {
${ns}::debug_log 1 "Inspecting $k:$v"
if { [dict exists $v "driver"] } {
${ns}::debug_log 1 "Has driver [dict get $v driver]"
if { [dict get $v "driver"] == "hiden_xcs" } {
${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"
if { [dict get $v enabled] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
set name [dict get $v name]
MakeAsyncProtocol ${name}_protocol
if { [dict exists $v "terminator"] } {
${name}_protocol sendterminator "[dict get $v "terminator"]"
${name}_protocol replyterminator "[dict get $v "terminator"]"
}
MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${name}_queue timeout "[dict get $v "timeout"]"
if { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
set arg_list [list]
foreach arg {id} {
if {[dict exists $v $arg]} {
lappend arg_list "[dict get $v $arg]"
} else {
${ns}::debug_log 1 "Missing configuration value $arg"
${ns}::sics_log 9 "Missing configuration value $arg"
error "Missing configuration value $arg"
}
}
${ns}::debug_log 1 "arg_list = $arg_list"
${ns}::debug_log 1 "add_hiden_xcs ${name} aqadapter ${name}_queue $arg_list"
add_hiden_xcs ${name} "aqadapter" ${name}_queue {*}$arg_list
add_hiden_xcs ${name} "aqadapter" ${asyncqueue} {*}$arg_list
}
}
}
@ -1167,8 +1187,9 @@ proc ::scobj::hiden_xcs::read_config {} {
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::hiden_xcs::read_config
} else {
::scobj::hiden_xcs:debug_log 1 "No config dict"
::scobj::hiden_xcs::sics_log 5 "No config dict"
}

View File

@ -3,13 +3,14 @@
#
namespace eval ::scobj::isotech_ps {
set debug_threshold 0
set debug_threshold 5
}
proc ::scobj::isotech_ps::debug_log {debug_level debug_string} {
proc ::scobj::isotech_ps::debug_log {tc_root debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::isotech_ps::debug_threshold}} {
set fd [open "/tmp/isotech_ps.log" "a"]
set debug_threshold [hgetpropval ${tc_root} debug_threshold]
if {${debug_level} >= ${debug_threshold}} {
set fd [open "/tmp/isotech_ps_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
@ -17,10 +18,19 @@ proc ::scobj::isotech_ps::debug_log {debug_level debug_string} {
} catch_message ]
}
proc ::scobj::isotech_ps::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::isotech_ps::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::isotech_ps::${debug_string}"
}
} catch_message ]
}
# check function for hset change
proc ::scobj::isotech_ps::checkrange {tc_root} {
set catch_status [ catch {
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -34,7 +44,7 @@ proc ::scobj::isotech_ps::checkrange {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checkrange hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -46,13 +56,13 @@ proc ::scobj::isotech_ps::checkrange {tc_root} {
# function to request the read of a parameter on a device
proc ::scobj::isotech_ps::getValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
debug_log 1 "getValue sct send ${cmd}"
# 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}"
}
@ -64,8 +74,8 @@ proc ::scobj::isotech_ps::getValue {tc_root nextState cmd_str} {
# function to check the write parameter on a device
proc ::scobj::isotech_ps::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
# hook code goes here
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}
@ -74,7 +84,7 @@ proc ::scobj::isotech_ps::noResponse {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::isotech_ps::rdValue {tc_root} {
set catch_status [ catch {
debug_log 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -85,15 +95,15 @@ proc ::scobj::isotech_ps::rdValue {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# rdValue hook code starts
set data [string range [sct result] 1 end]
# hook code ends
# rdValue hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -106,7 +116,7 @@ proc ::scobj::isotech_ps::rdValue {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::isotech_ps::read_relay {tc_root} {
set catch_status [ catch {
debug_log 1 "read_relay tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "read_relay tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -117,7 +127,7 @@ proc ::scobj::isotech_ps::read_relay {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# read_relay hook code starts
if { [string equal -nocase -length 2 "F1" "${data}"] } {
set data 1
} elseif { [string equal -nocase -length 2 "F0" "${data}"] } {
@ -125,13 +135,13 @@ proc ::scobj::isotech_ps::read_relay {tc_root} {
} else {
sct geterror "Unexpected response '${data}' not 'F1' nor 'F0'"
}
# hook code ends
# read_relay hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -144,19 +154,19 @@ proc ::scobj::isotech_ps::read_relay {tc_root} {
# function to write a parameter value on a device
proc ::scobj::isotech_ps::setValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
# setValue 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}"
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -168,21 +178,21 @@ proc ::scobj::isotech_ps::setValue {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::isotech_ps::write_relay {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "write_relay tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "write_relay 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 starts
# write_relay hook code starts
if { ${par} == 0 } {
set cmd "KOD"
} else {
set cmd "KOE"
}
# hook code ends
# write_relay hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -190,7 +200,7 @@ proc ::scobj::isotech_ps::write_relay {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "write_relay sct send ${cmd}"
debug_log ${tc_root} 1 "write_relay sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -202,18 +212,18 @@ proc ::scobj::isotech_ps::write_relay {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::isotech_ps::write_voltage {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "write_voltage tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "write_voltage 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 starts
# write_voltage hook code starts
set par "[format "%05.2f" [sct target]]"
set cmd "SV ${par}"
# hook code ends
# write_voltage hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -221,7 +231,7 @@ proc ::scobj::isotech_ps::write_voltage {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "write_voltage sct send ${cmd}"
debug_log ${tc_root} 1 "write_voltage sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -230,8 +240,8 @@ proc ::scobj::isotech_ps::write_voltage {tc_root nextState cmd_str} {
handle_exception ${catch_status} ${catch_message}
}
proc ::scobj::isotech_ps::mk_sct_isotech_ps { sct_controller name } {
debug_log 1 "mk_sct_isotech_ps for ${name}"
proc ::scobj::isotech_ps::mkDriver { sct_controller name } {
::scobj::isotech_ps::sics_log 9 "::scobj::isotech_ps::mkDriver for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
@ -294,62 +304,70 @@ proc ::scobj::isotech_ps::mk_sct_isotech_ps { sct_controller name } {
${sct_controller} write ${scobj_hpath}/volts
}
hsetprop ${scobj_hpath} klass environment
# hook code goes here
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code goes here
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::isotech_ps {
namespace export debug_threshold
namespace export debug_log
namespace export mk_sct_isotech_ps
namespace export sics_log
namespace export mkDriver
}
proc add_isotech_ps {name IP port} {
set catch_status [ catch {
set ns "::scobj::isotech_ps"
${ns}::debug_log 1 "add_isotech_ps ${name} ${IP} ${port}"
::scobj::isotech_ps::sics_log 9 "add_isotech_ps ${name} ${IP} ${port}"
if {[SplitReply [environment_simulation]]=="false"} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
::scobj::isotech_ps::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port} \"\\r\""
::scobj::isotech_ps::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port} \"\\r\""
makesctcontroller sct_${name} std ${IP}:${port} "\r"
}
}
${ns}::debug_log 1 "mk_sct_isotech_ps sct_${name} ${name}"
${ns}::mk_sct_isotech_ps sct_${name} ${name}
::scobj::isotech_ps::sics_log 1 "::scobj::isotech_ps::mkDriver sct_${name} ${name}"
::scobj::isotech_ps::mkDriver sct_${name} ${name}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
puts stdout "file evaluation of sct_isotech_ps.tcl"
::scobj::isotech_ps::debug_log 1 "file evaluation of sct_isotech_ps.tcl"
::scobj::isotech_ps::sics_log 9 "file evaluation of sct_isotech_ps.tcl"
proc ::scobj::isotech_ps::read_config {} {
set catch_status [ catch {
set ns "::scobj::isotech_ps"
${ns}::debug_log 1 "Processing Config"
dict for {k v} $::config_dict {
${ns}::debug_log 1 "Inspecting $k:$v"
if { [dict exists $v "driver"] } {
${ns}::debug_log 1 "Has driver [dict get $v driver]"
if { [dict get $v "driver"] == "isotech_ps" } {
${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"
if { [dict get $v enabled] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
set name [dict get $v name]
MakeAsyncProtocol ${name}_protocol
if { [dict exists $v "terminator"] } {
${name}_protocol sendterminator "[dict get $v "terminator"]"
${name}_protocol replyterminator "[dict get $v "terminator"]"
if { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${name}_queue timeout "[dict get $v "timeout"]"
}
add_isotech_ps ${name} "aqadapter" ${name}_queue
add_isotech_ps ${name} "aqadapter" ${asyncqueue}
}
}
}
@ -357,8 +375,9 @@ proc ::scobj::isotech_ps::read_config {} {
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::isotech_ps::read_config
} else {
::scobj::isotech_ps:debug_log 1 "No config dict"
::scobj::isotech_ps::sics_log 5 "No config dict"
}

View File

@ -3,13 +3,14 @@
#
namespace eval ::scobj::mercury_scpi {
set debug_threshold 0
set debug_threshold 5
}
proc ::scobj::mercury_scpi::debug_log {debug_level debug_string} {
proc ::scobj::mercury_scpi::debug_log {tc_root debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::mercury_scpi::debug_threshold}} {
set fd [open "/tmp/mercury_scpi.log" "a"]
set debug_threshold [hgetpropval ${tc_root} debug_threshold]
if {${debug_level} >= ${debug_threshold}} {
set fd [open "/tmp/mercury_scpi_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
@ -17,10 +18,19 @@ proc ::scobj::mercury_scpi::debug_log {debug_level debug_string} {
} catch_message ]
}
proc ::scobj::mercury_scpi::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::mercury_scpi::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::mercury_scpi::${debug_string}"
}
} catch_message ]
}
# checklimits function for driveable interface
proc ::scobj::mercury_scpi::checklimits {tc_root} {
set catch_status [ catch {
debug_log 1 "checklimits tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -34,7 +44,7 @@ proc ::scobj::mercury_scpi::checklimits {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checklimits hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
sct driving 0
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
@ -47,7 +57,7 @@ proc ::scobj::mercury_scpi::checklimits {tc_root} {
# check function for hset change
proc ::scobj::mercury_scpi::checkrange {tc_root} {
set catch_status [ catch {
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -61,7 +71,7 @@ proc ::scobj::mercury_scpi::checkrange {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checkrange hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -73,7 +83,7 @@ proc ::scobj::mercury_scpi::checkrange {tc_root} {
# checkstatus function for driveable interface
proc ::scobj::mercury_scpi::checkstatus {tc_root} {
set catch_status [ catch {
# hook code goes here
# checkstatus hook code goes here
if {[sct driving]} {
set sp "[sct target]"
set pv "[hval ${tc_root}/[sct driveable]]"
@ -107,13 +117,13 @@ proc ::scobj::mercury_scpi::checkstatus {tc_root} {
# function to request the read of a parameter on a device
proc ::scobj::mercury_scpi::getValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
debug_log 1 "getValue sct send ${cmd}"
# 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}"
}
@ -125,9 +135,9 @@ proc ::scobj::mercury_scpi::getValue {tc_root nextState cmd_str} {
# halt function for driveable interface
proc ::scobj::mercury_scpi::halt {tc_root} {
set catch_status [ catch {
debug_log 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
debug_log ${tc_root} 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
### TODO hset [sct] [hval [sct]]
# hook code goes here
# halt hook code goes here
sct driving 0
return "idle"
} catch_message ]
@ -137,8 +147,8 @@ proc ::scobj::mercury_scpi::halt {tc_root} {
# function to check the write parameter on a device
proc ::scobj::mercury_scpi::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
# hook code goes here
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}
@ -147,7 +157,7 @@ proc ::scobj::mercury_scpi::noResponse {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::mercury_scpi::rdText {tc_root} {
set catch_status [ catch {
debug_log 1 "rdText tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "rdText tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -158,15 +168,15 @@ proc ::scobj::mercury_scpi::rdText {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# rdText hook code starts
scan [lindex [split "$data" ":"] end] "%s" data
# hook code ends
# rdText hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -179,7 +189,7 @@ proc ::scobj::mercury_scpi::rdText {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::mercury_scpi::rdValue {tc_root} {
set catch_status [ catch {
debug_log 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -190,15 +200,15 @@ proc ::scobj::mercury_scpi::rdValue {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# rdValue hook code starts
scan [lindex [split "$data" ":"] end] "%g" data
# hook code ends
# rdValue hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -211,19 +221,19 @@ proc ::scobj::mercury_scpi::rdValue {tc_root} {
# function to write a parameter value on a device
proc ::scobj::mercury_scpi::setPoint {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setPoint tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "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}"
# hook code goes here
# setPoint hook code goes here
if { [hpropexists [sct] driving] } {
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
sct driving 1
}
}
debug_log 1 "setPoint sct send ${cmd}"
debug_log ${tc_root} 1 "setPoint sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -235,19 +245,19 @@ proc ::scobj::mercury_scpi::setPoint {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::mercury_scpi::setValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
# setValue 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}"
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -259,20 +269,21 @@ proc ::scobj::mercury_scpi::setValue {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::mercury_scpi::setValve {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValve tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "setValve 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 starts
# setValve hook code starts
if { [hpropexists [sct] pid_bias] } {
set par [expr ${par} + [hgetpropval [sct] pid_bias]]
set cmd "${cmd_str}${par}"
}
# hook code ends
sct update [sct target]
# setValve hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -280,7 +291,7 @@ proc ::scobj::mercury_scpi::setValve {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "setValve sct send ${cmd}"
debug_log ${tc_root} 1 "setValve sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -289,8 +300,8 @@ proc ::scobj::mercury_scpi::setValve {tc_root nextState cmd_str} {
handle_exception ${catch_status} ${catch_message}
}
proc ::scobj::mercury_scpi::mk_sct_mercury_scpi { sct_controller name id permlink tol valve_tol } {
debug_log 1 "mk_sct_mercury_scpi ${sct_controller} ${name} ${id} ${permlink} ${tol} ${valve_tol}"
proc ::scobj::mercury_scpi::mkDriver { sct_controller name id permlink tol valve_tol } {
::scobj::mercury_scpi::sics_log 9 "::scobj::mercury_scpi::mkDriver ${sct_controller} ${name} ${id} ${permlink} ${tol} ${valve_tol}"
set ns "[namespace current]"
set catch_status [ catch {
@ -682,73 +693,79 @@ proc ::scobj::mercury_scpi::mk_sct_mercury_scpi { sct_controller name id permlin
ansto_makesctdrive ${name}_Valve_setpoint ${scobj_hpath}/Valve/setpoint ${scobj_hpath}/Valve/sensor ${sct_controller}
}
hsetprop ${scobj_hpath} klass environment
# hook code goes here
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code goes here
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::mercury_scpi {
namespace export debug_threshold
namespace export debug_log
namespace export mk_sct_mercury_scpi
namespace export sics_log
namespace export mkDriver
}
proc add_mercury_scpi {name IP port {id 99} {permlink LT} {tol 1} {valve_tol 2}} {
set catch_status [ catch {
set ns "::scobj::mercury_scpi"
${ns}::debug_log 1 "add_mercury_scpi ${name} ${IP} ${port} ${id} ${permlink} ${tol} ${valve_tol}"
::scobj::mercury_scpi::sics_log 9 "add_mercury_scpi ${name} ${IP} ${port} ${id} ${permlink} ${tol} ${valve_tol}"
if {[SplitReply [environment_simulation]]=="false"} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
::scobj::mercury_scpi::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port}"
::scobj::mercury_scpi::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}"
makesctcontroller sct_${name} std ${IP}:${port}
}
}
${ns}::debug_log 1 "mk_sct_mercury_scpi sct_${name} ${name} ${id} ${permlink} ${tol} ${valve_tol}"
${ns}::mk_sct_mercury_scpi sct_${name} ${name} ${id} ${permlink} ${tol} ${valve_tol}
::scobj::mercury_scpi::sics_log 1 "::scobj::mercury_scpi::mkDriver sct_${name} ${name} ${id} ${permlink} ${tol} ${valve_tol}"
::scobj::mercury_scpi::mkDriver sct_${name} ${name} ${id} ${permlink} ${tol} ${valve_tol}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
puts stdout "file evaluation of sct_mercury_scpi.tcl"
::scobj::mercury_scpi::debug_log 1 "file evaluation of sct_mercury_scpi.tcl"
::scobj::mercury_scpi::sics_log 9 "file evaluation of sct_mercury_scpi.tcl"
proc ::scobj::mercury_scpi::read_config {} {
set catch_status [ catch {
set ns "::scobj::mercury_scpi"
${ns}::debug_log 1 "Processing Config"
dict for {k v} $::config_dict {
${ns}::debug_log 1 "Inspecting $k:$v"
if { [dict exists $v "driver"] } {
${ns}::debug_log 1 "Has driver [dict get $v driver]"
if { [dict get $v "driver"] == "mercury_scpi" } {
${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"
if { [dict get $v enabled] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
set name [dict get $v name]
MakeAsyncProtocol ${name}_protocol
if { [dict exists $v "terminator"] } {
${name}_protocol sendterminator "[dict get $v "terminator"]"
${name}_protocol replyterminator "[dict get $v "terminator"]"
}
MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${name}_queue timeout "[dict get $v "timeout"]"
if { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
set arg_list [list]
foreach arg {id permlink tol valve_tol} {
if {[dict exists $v $arg]} {
lappend arg_list "[dict get $v $arg]"
} else {
${ns}::debug_log 1 "Missing configuration value $arg"
${ns}::sics_log 9 "Missing configuration value $arg"
error "Missing configuration value $arg"
}
}
${ns}::debug_log 1 "arg_list = $arg_list"
${ns}::debug_log 1 "add_mercury_scpi ${name} aqadapter ${name}_queue $arg_list"
add_mercury_scpi ${name} "aqadapter" ${name}_queue {*}$arg_list
add_mercury_scpi ${name} "aqadapter" ${asyncqueue} {*}$arg_list
}
}
}
@ -756,8 +773,9 @@ proc ::scobj::mercury_scpi::read_config {} {
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::mercury_scpi::read_config
} else {
::scobj::mercury_scpi:debug_log 1 "No config dict"
::scobj::mercury_scpi::sics_log 5 "No config dict"
}

View File

@ -3,16 +3,17 @@
#
namespace eval ::scobj::pfeiffer_hg {
set debug_threshold 0
set debug_threshold 5
if { ![info exists ::scobj::permlink_device_counter]} {
set ::scobj::permlink_device_counter 0
}
}
proc ::scobj::pfeiffer_hg::debug_log {debug_level debug_string} {
proc ::scobj::pfeiffer_hg::debug_log {tc_root debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::pfeiffer_hg::debug_threshold}} {
set fd [open "/tmp/pfeiffer_hg.log" "a"]
set debug_threshold [hgetpropval ${tc_root} debug_threshold]
if {${debug_level} >= ${debug_threshold}} {
set fd [open "/tmp/pfeiffer_hg_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
@ -20,10 +21,19 @@ proc ::scobj::pfeiffer_hg::debug_log {debug_level debug_string} {
} catch_message ]
}
proc ::scobj::pfeiffer_hg::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::pfeiffer_hg::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::pfeiffer_hg::${debug_string}"
}
} catch_message ]
}
# function to parse the read of a parameter on a device
proc ::scobj::pfeiffer_hg::ack_enq {tc_root} {
set catch_status [ catch {
debug_log 1 "ack_enq tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "ack_enq tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -34,19 +44,19 @@ proc ::scobj::pfeiffer_hg::ack_enq {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# ack_enq hook code starts
if {[string equal -nocase -length 1 ${data} "\x06"]} {
debug_log 1 "ack_enq received ACK, send ENQ"
debug_log ${tc_root} 1 "ack_enq received ACK, send ENQ"
sct send "\x05"
}
return "readPR1"
# hook code ends
# ack_enq hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -59,7 +69,7 @@ proc ::scobj::pfeiffer_hg::ack_enq {tc_root} {
# checklimits function for driveable interface
proc ::scobj::pfeiffer_hg::checklimits {tc_root} {
set catch_status [ catch {
debug_log 1 "checklimits tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -73,7 +83,7 @@ proc ::scobj::pfeiffer_hg::checklimits {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checklimits hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
sct driving 0
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
@ -86,7 +96,7 @@ proc ::scobj::pfeiffer_hg::checklimits {tc_root} {
# check function for hset change
proc ::scobj::pfeiffer_hg::checkrange {tc_root} {
set catch_status [ catch {
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
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]
@ -100,7 +110,7 @@ proc ::scobj::pfeiffer_hg::checkrange {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checkrange hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -112,7 +122,7 @@ proc ::scobj::pfeiffer_hg::checkrange {tc_root} {
# checkstatus function for driveable interface
proc ::scobj::pfeiffer_hg::checkstatus {tc_root} {
set catch_status [ catch {
# hook code goes here
# checkstatus hook code goes here
if {[sct driving]} {
set sp "[sct target]"
set pv "[hval ${tc_root}/[sct driveable]]"
@ -146,13 +156,13 @@ proc ::scobj::pfeiffer_hg::checkstatus {tc_root} {
# function to request the read of a parameter on a device
proc ::scobj::pfeiffer_hg::getValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
debug_log 1 "getValue sct send ${cmd}"
# 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}"
}
@ -164,9 +174,9 @@ proc ::scobj::pfeiffer_hg::getValue {tc_root nextState cmd_str} {
# halt function for driveable interface
proc ::scobj::pfeiffer_hg::halt {tc_root} {
set catch_status [ catch {
debug_log 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
debug_log ${tc_root} 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
### TODO hset [sct] [hval [sct]]
# hook code goes here
# halt hook code goes here
sct driving 0
return "idle"
} catch_message ]
@ -176,8 +186,8 @@ proc ::scobj::pfeiffer_hg::halt {tc_root} {
# function to check the write parameter on a device
proc ::scobj::pfeiffer_hg::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
# hook code goes here
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}
@ -186,7 +196,7 @@ proc ::scobj::pfeiffer_hg::noResponse {tc_root} {
# pid function for PID control
proc ::scobj::pfeiffer_hg::pid_pressure {tc_root sp pv} {
set catch_status [ catch {
debug_log 1 "pid_pressure tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
debug_log ${tc_root} 1 "pid_pressure tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
sct pid_error [expr ${sp} - ${pv}]
set p_value [expr [sct pid_pvalue] * [sct pid_error]]
set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]
@ -200,16 +210,19 @@ proc ::scobj::pfeiffer_hg::pid_pressure {tc_root sp pv} {
}
set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
set pid [expr ${p_value} + ${i_value} + ${d_value}]
# hook code starts
# pid_pressure hook code starts
if { [hpropexists [sct] pid_control] } {
hsetprop [hgetpropval [sct] pid_control] pid_bias ${pid}
if { [hpropexists [hgetpropval [sct] pid_control] target] } {
hset [hgetpropval [sct] pid_control] [hgetpropval [hgetpropval [sct] pid_control] target]
set co [hgetpropval [sct] pid_control]
if { !([hpropexists ${co} pid_bias] && [hgetpropval ${co} pid_bias] == ${pid}) } {
hsetprop ${co} pid_bias ${pid}
if { [hpropexists ${co} target] } {
hset ${co} [hgetpropval ${co} target]
} else {
hset [hgetpropval [sct] pid_control] [hval [hgetpropval [sct] pid_control]]
hset ${co} [hval ${co}]
}
}
}
# hook code ends
# pid_pressure hook code ends
sct pid_output ${pid}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
@ -219,7 +232,7 @@ proc ::scobj::pfeiffer_hg::pid_pressure {tc_root sp pv} {
# function to parse the read of a parameter on a device
proc ::scobj::pfeiffer_hg::rdValue {tc_root} {
set catch_status [ catch {
debug_log 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -230,9 +243,9 @@ proc ::scobj::pfeiffer_hg::rdValue {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code goes here
# rdValue hook code goes here
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -245,7 +258,7 @@ proc ::scobj::pfeiffer_hg::rdValue {tc_root} {
# function to parse the read of a parameter on a device
proc ::scobj::pfeiffer_hg::readPR1 {tc_root} {
set catch_status [ catch {
debug_log 1 "readPR1 tc_root=${tc_root} sct=[sct] result=[sct result]"
debug_log ${tc_root} 1 "readPR1 tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -256,7 +269,7 @@ proc ::scobj::pfeiffer_hg::readPR1 {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# readPR1 hook code starts
set val [string range $data 3 12]
set status [string range $data 0 0]
set data ${val}
@ -266,13 +279,13 @@ proc ::scobj::pfeiffer_hg::readPR1 {tc_root} {
set pv $val
pid_pressure ${tc_root} ${sp} ${pv}
}
# hook code ends
# readPR1 hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -285,13 +298,13 @@ proc ::scobj::pfeiffer_hg::readPR1 {tc_root} {
# function to request the read of a parameter on a device
proc ::scobj::pfeiffer_hg::sendPR1 {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "sendPR1 tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "sendPR1 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 "sendPR1 sct send ${cmd}"
# sendPR1 hook code goes here
debug_log ${tc_root} 1 "sendPR1 sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -303,17 +316,20 @@ proc ::scobj::pfeiffer_hg::sendPR1 {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::pfeiffer_hg::setPoint {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setPoint tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "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}"
# hook code starts
# setPoint hook code starts
sct pid_control /sample/tc9/Valve/Setpoint
# hook code ends
sct update [sct target]
set cmd "@@NOSEND@@"
set nextState "idle"
# setPoint hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { [hpropexists [sct] driving] } {
@ -321,7 +337,7 @@ proc ::scobj::pfeiffer_hg::setPoint {tc_root nextState cmd_str} {
sct driving 1
}
}
debug_log 1 "setPoint sct send ${cmd}"
debug_log ${tc_root} 1 "setPoint sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -333,19 +349,19 @@ proc ::scobj::pfeiffer_hg::setPoint {tc_root nextState cmd_str} {
# function to write a parameter value on a device
proc ::scobj::pfeiffer_hg::setValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
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}"
# hook code goes here
# setValue 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}"
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -354,8 +370,8 @@ proc ::scobj::pfeiffer_hg::setValue {tc_root nextState cmd_str} {
handle_exception ${catch_status} ${catch_message}
}
proc ::scobj::pfeiffer_hg::mk_sct_pfeiffer_hg { sct_controller name } {
debug_log 1 "mk_sct_pfeiffer_hg for ${name}"
proc ::scobj::pfeiffer_hg::mkDriver { sct_controller name } {
::scobj::pfeiffer_hg::sics_log 9 "::scobj::pfeiffer_hg::mkDriver for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
@ -433,65 +449,73 @@ proc ::scobj::pfeiffer_hg::mk_sct_pfeiffer_hg { sct_controller name } {
ansto_makesctdrive ${name}_pressure_setpoint ${scobj_hpath}/pressure/setpoint ${scobj_hpath}/pressure/sensor ${sct_controller}
}
hsetprop ${scobj_hpath} klass environment
# hook code starts
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code starts
hsetprop ${scobj_hpath}/pressure/sensor read ${ns}::sendPR1 ${scobj_hpath} ack_enq {PR1}
hsetprop ${scobj_hpath}/pressure/sensor ack_enq ${ns}::ack_enq ${scobj_hpath}
# hook code ends
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::pfeiffer_hg {
namespace export debug_threshold
namespace export debug_log
namespace export mk_sct_pfeiffer_hg
namespace export sics_log
namespace export mkDriver
}
proc add_pfeiffer_hg {name IP port} {
set catch_status [ catch {
set ns "::scobj::pfeiffer_hg"
${ns}::debug_log 1 "add_pfeiffer_hg ${name} ${IP} ${port}"
::scobj::pfeiffer_hg::sics_log 9 "add_pfeiffer_hg ${name} ${IP} ${port}"
if {[SplitReply [environment_simulation]]=="false"} {
if {[string equal -nocase "aqadapter" "${IP}"]} {
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
::scobj::pfeiffer_hg::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port}"
::scobj::pfeiffer_hg::sics_log 9 "makesctcontroller sct_${name} std ${IP}:${port}"
makesctcontroller sct_${name} std ${IP}:${port}
}
}
${ns}::debug_log 1 "mk_sct_pfeiffer_hg sct_${name} ${name}"
${ns}::mk_sct_pfeiffer_hg sct_${name} ${name}
::scobj::pfeiffer_hg::sics_log 1 "::scobj::pfeiffer_hg::mkDriver sct_${name} ${name}"
::scobj::pfeiffer_hg::mkDriver sct_${name} ${name}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
puts stdout "file evaluation of sct_pfeiffer_hg.tcl"
::scobj::pfeiffer_hg::debug_log 1 "file evaluation of sct_pfeiffer_hg.tcl"
::scobj::pfeiffer_hg::sics_log 9 "file evaluation of sct_pfeiffer_hg.tcl"
proc ::scobj::pfeiffer_hg::read_config {} {
set catch_status [ catch {
set ns "::scobj::pfeiffer_hg"
${ns}::debug_log 1 "Processing Config"
dict for {k v} $::config_dict {
${ns}::debug_log 1 "Inspecting $k:$v"
if { [dict exists $v "driver"] } {
${ns}::debug_log 1 "Has driver [dict get $v driver]"
if { [dict get $v "driver"] == "pfeiffer_hg" } {
${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"
if { [dict get $v enabled] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
set name [dict get $v name]
MakeAsyncProtocol ${name}_protocol
if { [dict exists $v "terminator"] } {
${name}_protocol sendterminator "[dict get $v "terminator"]"
${name}_protocol replyterminator "[dict get $v "terminator"]"
if { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${name}_queue timeout "[dict get $v "timeout"]"
}
add_pfeiffer_hg ${name} "aqadapter" ${name}_queue
add_pfeiffer_hg ${name} "aqadapter" ${asyncqueue}
}
}
}
@ -499,8 +523,9 @@ proc ::scobj::pfeiffer_hg::read_config {} {
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::pfeiffer_hg::read_config
} else {
::scobj::pfeiffer_hg:debug_log 1 "No config dict"
::scobj::pfeiffer_hg::sics_log 5 "No config dict"
}

View File

@ -3,13 +3,14 @@
#
namespace eval ::scobj::reactor_status {
set debug_threshold 0
set debug_threshold 5
}
proc ::scobj::reactor_status::debug_log {debug_level debug_string} {
proc ::scobj::reactor_status::debug_log {tc_root 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 debug_threshold [hgetpropval ${tc_root} debug_threshold]
if {${debug_level} >= ${debug_threshold}} {
set fd [open "/tmp/reactor_status_[basename ${tc_root}].log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}"
close ${fd}
@ -17,10 +18,19 @@ proc ::scobj::reactor_status::debug_log {debug_level debug_string} {
} catch_message ]
}
proc ::scobj::reactor_status::sics_log {debug_level debug_string} {
set catch_status [ catch {
set debug_threshold ${::scobj::reactor_status::debug_threshold}
if {${debug_level} >= ${debug_threshold}} {
sicslog "::scobj::reactor_status::${debug_string}"
}
} 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]"
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]
@ -34,7 +44,7 @@ proc ::scobj::reactor_status::checkrange {tc_root} {
# upperlimit not set, use target
set hilimit [sct target]
}
# hook code goes here
# checkrange hook code goes here
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
}
@ -46,13 +56,13 @@ proc ::scobj::reactor_status::checkrange {tc_root} {
# 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}"
debug_log ${tc_root} 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}"
# getState hook code goes here
debug_log ${tc_root} 1 "getState sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -64,13 +74,13 @@ proc ::scobj::reactor_status::getState {tc_root nextState cmd_str} {
# 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}"
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}"
# hook code goes here
debug_log 1 "getValue sct send ${cmd}"
# 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}"
}
@ -82,8 +92,8 @@ proc ::scobj::reactor_status::getValue {tc_root nextState cmd_str} {
# 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
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}
@ -92,7 +102,7 @@ proc ::scobj::reactor_status::noResponse {tc_root} {
# 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]"
debug_log ${tc_root} 1 "rdAll tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -103,7 +113,7 @@ proc ::scobj::reactor_status::rdAll {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code starts
# rdAll 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}] {
@ -116,13 +126,13 @@ proc ::scobj::reactor_status::rdAll {tc_root} {
}
}
}
# hook code ends
# rdAll hook code ends
if { [hpropexists [sct] geterror] } {
debug_log 1 "[sct] error: [sct geterror]"
debug_log ${tc_root} 9 "[sct] error: [sct geterror]"
error "[sct geterror]"
}
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -135,7 +145,7 @@ proc ::scobj::reactor_status::rdAll {tc_root} {
# 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]"
debug_log ${tc_root} 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror
}
@ -146,9 +156,9 @@ proc ::scobj::reactor_status::rdValue {tc_root} {
sct geterror "${data}"
error "[sct geterror]"
}
# hook code goes here
# rdValue hook code goes here
if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[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
@ -161,19 +171,19 @@ proc ::scobj::reactor_status::rdValue {tc_root} {
# function to write a parameter value on a device
proc ::scobj::reactor_status::setPoint {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setPoint tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
debug_log ${tc_root} 1 "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}"
# hook code goes here
# setPoint hook code goes here
if { [hpropexists [sct] driving] } {
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
sct driving 1
}
}
debug_log 1 "setPoint sct send ${cmd}"
debug_log ${tc_root} 1 "setPoint sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -185,19 +195,19 @@ proc ::scobj::reactor_status::setPoint {tc_root nextState cmd_str} {
# 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}"
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}"
# hook code goes here
# setValue 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}"
debug_log ${tc_root} 1 "setValue sct send ${cmd}"
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
sct send "${cmd}"
}
@ -206,8 +216,8 @@ proc ::scobj::reactor_status::setValue {tc_root nextState cmd_str} {
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}"
proc ::scobj::reactor_status::mkDriver { sct_controller name } {
::scobj::reactor_status::sics_log 9 "::scobj::reactor_status::mkDriver for ${name}"
set ns "[namespace current]"
set catch_status [ catch {
@ -292,63 +302,71 @@ proc ::scobj::reactor_status::mk_sct_reactor_status { sct_controller name } {
${sct_controller} poll ${scobj_hpath}/status 30
}
hsetprop ${scobj_hpath} klass NXsource
# hook code starts
# hook code ends
hsetprop ${scobj_hpath} debug_threshold 5
# mkDriver hook code starts
# mkDriver hook code ends
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
namespace eval ::scobj::reactor_status {
namespace export debug_threshold
namespace export debug_log
namespace export mk_sct_reactor_status
namespace export sics_log
namespace export mkDriver
}
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}"
::scobj::reactor_status::sics_log 9 "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}"
::scobj::reactor_status::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"
makesctcontroller sct_${name} aqadapter ${port}
} else {
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port}"
::scobj::reactor_status::sics_log 9 "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}
::scobj::reactor_status::sics_log 1 "::scobj::reactor_status::mkDriver sct_${name} ${name}"
::scobj::reactor_status::mkDriver 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"
::scobj::reactor_status::sics_log 9 "file evaluation of sct_reactor_status.tcl"
proc ::scobj::reactor_status::read_config {} {
set catch_status [ catch {
set ns "::scobj::reactor_status"
${ns}::debug_log 1 "Processing Config"
dict for {k v} $::config_dict {
${ns}::debug_log 1 "Inspecting $k:$v"
if { [dict exists $v "driver"] } {
${ns}::debug_log 1 "Has driver [dict get $v driver]"
if { [dict get $v "driver"] == "reactor_status" } {
${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"
if { [dict get $v enabled] } {
set IP [dict get $v ip]
set PORT [dict get $v port]
set name [dict get $v name]
MakeAsyncProtocol ${name}_protocol
if { [dict exists $v "terminator"] } {
${name}_protocol sendterminator "[dict get $v "terminator"]"
${name}_protocol replyterminator "[dict get $v "terminator"]"
if { [dict exists $v "asyncqueue"] } {
set asyncqueue [dict get $v "asyncqueue"]
} else {
if { [dict exists $v "asyncprotocol"] } {
set asyncprotocol [dict get $v "asyncprotocol"]
} else {
set asyncprotocol ${name}_protocol
MakeAsyncProtocol ${asyncprotocol}
if { [dict exists $v "terminator"] } {
${asyncprotocol} sendterminator "[dict get $v "terminator"]"
${asyncprotocol} replyterminator "[dict get $v "terminator"]"
}
}
set asyncqueue ${name}_queue
set IP [dict get $v ip]
set PORT [dict get $v port]
MakeAsyncQueue ${asyncqueue} ${asyncprotocol} ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${asyncqueue} timeout "[dict get $v "timeout"]"
}
}
MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}
if { [dict exists $v "timeout"] } {
${name}_queue timeout "[dict get $v "timeout"]"
}
add_reactor_status ${name} "aqadapter" ${name}_queue
add_reactor_status ${name} "aqadapter" ${asyncqueue}
}
}
}
@ -356,8 +374,9 @@ proc ::scobj::reactor_status::read_config {} {
} catch_message ]
handle_exception ${catch_status} ${catch_message}
}
if { [info exists ::config_dict] } {
::scobj::reactor_status::read_config
} else {
::scobj::reactor_status:debug_log 1 "No config dict"
::scobj::reactor_status::sics_log 5 "No config dict"
}