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::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"
}