Regen sct drivers with async and logging changes
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user