Wrap generated driver code in 'catch' and handle_exception blocks
This commit is contained in:
@ -7,106 +7,121 @@ namespace eval ::scobj::hiden_xcs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc ::scobj::hiden_xcs::debug_log {debug_level debug_string} {
|
proc ::scobj::hiden_xcs::debug_log {debug_level debug_string} {
|
||||||
if {${debug_level} >= ${::scobj::hiden_xcs::debug_threshold}} {
|
set catch_status [ catch {
|
||||||
set fd [open "/tmp/hiden_xcs.log" "a"]
|
if {${debug_level} >= ${::scobj::hiden_xcs::debug_threshold}} {
|
||||||
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
|
set fd [open "/tmp/hiden_xcs.log" "a"]
|
||||||
puts ${fd} "${line}"
|
set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
|
||||||
close ${fd}
|
puts ${fd} "${line}"
|
||||||
}
|
close ${fd}
|
||||||
|
}
|
||||||
|
} catch_message ]
|
||||||
}
|
}
|
||||||
|
|
||||||
# checklimits function for driveable interface
|
# checklimits function for driveable interface
|
||||||
proc ::scobj::hiden_xcs::checklimits {tc_root} {
|
proc ::scobj::hiden_xcs::checklimits {tc_root} {
|
||||||
debug_log 1 "checklimits tc_root=${tc_root} sct=[sct] target=[sct target]"
|
set catch_status [ catch {
|
||||||
set setpoint [sct target]
|
debug_log 1 "checklimits tc_root=${tc_root} sct=[sct] target=[sct target]"
|
||||||
if { [hpropexists [sct] lowerlimit] } {
|
set setpoint [sct target]
|
||||||
set lolimit [sct lowerlimit]
|
if { [hpropexists [sct] lowerlimit] } {
|
||||||
} else {
|
set lolimit [sct lowerlimit]
|
||||||
# lowerlimit not set, use target
|
} else {
|
||||||
set lolimit [sct target]
|
# lowerlimit not set, use target
|
||||||
}
|
set lolimit [sct target]
|
||||||
if { [hpropexists [sct] upperlimit] } {
|
}
|
||||||
set hilimit [sct upperlimit]
|
if { [hpropexists [sct] upperlimit] } {
|
||||||
} else {
|
set hilimit [sct upperlimit]
|
||||||
# upperlimit not set, use target
|
} else {
|
||||||
set hilimit [sct target]
|
# upperlimit not set, use target
|
||||||
}
|
set hilimit [sct target]
|
||||||
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
}
|
||||||
sct driving 0
|
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
||||||
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
sct driving 0
|
||||||
}
|
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
||||||
return OK
|
}
|
||||||
|
return OK
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# check function for hset change
|
# check function for hset change
|
||||||
proc ::scobj::hiden_xcs::checkrange {tc_root} {
|
proc ::scobj::hiden_xcs::checkrange {tc_root} {
|
||||||
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
|
set catch_status [ catch {
|
||||||
set setpoint [sct target]
|
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
|
||||||
if { [hpropexists [sct] lowerlimit] } {
|
set setpoint [sct target]
|
||||||
set lolimit [sct lowerlimit]
|
if { [hpropexists [sct] lowerlimit] } {
|
||||||
} else {
|
set lolimit [sct lowerlimit]
|
||||||
# lowerlimit not set, use target
|
} else {
|
||||||
set lolimit [sct target]
|
# lowerlimit not set, use target
|
||||||
}
|
set lolimit [sct target]
|
||||||
if { [hpropexists [sct] upperlimit] } {
|
}
|
||||||
set hilimit [sct upperlimit]
|
if { [hpropexists [sct] upperlimit] } {
|
||||||
} else {
|
set hilimit [sct upperlimit]
|
||||||
# upperlimit not set, use target
|
} else {
|
||||||
set hilimit [sct target]
|
# upperlimit not set, use target
|
||||||
}
|
set hilimit [sct target]
|
||||||
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
}
|
||||||
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
||||||
}
|
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
||||||
return OK
|
}
|
||||||
|
return OK
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# checkstatus function for driveable interface
|
# checkstatus function for driveable interface
|
||||||
proc ::scobj::hiden_xcs::checkstatus {tc_root} {
|
proc ::scobj::hiden_xcs::checkstatus {tc_root} {
|
||||||
if {[sct driving]} {
|
set catch_status [ catch {
|
||||||
set sp "[sct target]"
|
if {[sct driving]} {
|
||||||
set pv "[hval ${tc_root}/[sct driveable]]"
|
set sp "[sct target]"
|
||||||
if { ${pv} > ${sp} - [sct tolerance] && ${pv} < ${sp} + [sct tolerance] } {
|
set pv "[hval ${tc_root}/[sct driveable]]"
|
||||||
sct driving 0
|
if { ${pv} > ${sp} - [sct tolerance] && ${pv} < ${sp} + [sct tolerance] } {
|
||||||
|
sct driving 0
|
||||||
|
return "idle"
|
||||||
|
}
|
||||||
|
return "busy"
|
||||||
|
} else {
|
||||||
return "idle"
|
return "idle"
|
||||||
}
|
}
|
||||||
return "busy"
|
} catch_message ]
|
||||||
} else {
|
handle_exception ${catch_status} ${catch_message}
|
||||||
return "idle"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# check function for hset change
|
# check function for hset change
|
||||||
proc ::scobj::hiden_xcs::chkrange_function {tc_root} {
|
proc ::scobj::hiden_xcs::chkrange_function {tc_root} {
|
||||||
debug_log 1 "chkrange_function tc_root=${tc_root} sct=[sct] target=[sct target]"
|
set catch_status [ catch {
|
||||||
set setpoint [sct target]
|
debug_log 1 "chkrange_function tc_root=${tc_root} sct=[sct] target=[sct target]"
|
||||||
if { [hpropexists [sct] lowerlimit] } {
|
set setpoint [sct target]
|
||||||
set lolimit [sct lowerlimit]
|
if { [hpropexists [sct] lowerlimit] } {
|
||||||
} else {
|
set lolimit [sct lowerlimit]
|
||||||
# lowerlimit not set, use target
|
} else {
|
||||||
set lolimit [sct target]
|
# lowerlimit not set, use target
|
||||||
}
|
set lolimit [sct target]
|
||||||
if { [hpropexists [sct] upperlimit] } {
|
}
|
||||||
set hilimit [sct upperlimit]
|
if { [hpropexists [sct] upperlimit] } {
|
||||||
} else {
|
set hilimit [sct upperlimit]
|
||||||
# upperlimit not set, use target
|
} else {
|
||||||
set hilimit [sct target]
|
# upperlimit not set, use target
|
||||||
}
|
set hilimit [sct target]
|
||||||
|
}
|
||||||
# hook code starts
|
# hook code starts
|
||||||
# hooked
|
# hooked
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
||||||
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
||||||
}
|
}
|
||||||
return OK
|
return OK
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to request the read of a parameter on a device
|
# function to request the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::fetch_flow {tc_root nextState cmd_str} {
|
proc ::scobj::hiden_xcs::fetch_flow {tc_root nextState cmd_str} {
|
||||||
debug_log 1 "fetch_flow tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "fetch_flow tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set cmd "${cmd_str}"
|
}
|
||||||
|
set cmd "${cmd_str}"
|
||||||
# hook code starts
|
# hook code starts
|
||||||
set data 0.0
|
set data 0.0
|
||||||
set targets 0.0
|
set targets 0.0
|
||||||
@ -132,116 +147,137 @@ proc ::scobj::hiden_xcs::fetch_flow {tc_root nextState cmd_str} {
|
|||||||
}
|
}
|
||||||
return ${nextState}
|
return ${nextState}
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
}
|
||||||
debug_log 1 "fetch_flow sct send ${cmd}"
|
debug_log 1 "fetch_flow sct send ${cmd}"
|
||||||
sct send "${cmd}"
|
sct send "${cmd}"
|
||||||
return ${nextState}
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to request the read of a parameter on a device
|
# function to request the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::getValue {tc_root nextState cmd_str} {
|
proc ::scobj::hiden_xcs::getValue {tc_root nextState cmd_str} {
|
||||||
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set cmd "${cmd_str}"
|
}
|
||||||
debug_log 1 "getValue sct send ${cmd}"
|
set cmd "${cmd_str}"
|
||||||
sct send "${cmd}"
|
debug_log 1 "getValue sct send ${cmd}"
|
||||||
return ${nextState}
|
sct send "${cmd}"
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# halt function for driveable interface
|
# halt function for driveable interface
|
||||||
proc ::scobj::hiden_xcs::halt {tc_root} {
|
proc ::scobj::hiden_xcs::halt {tc_root} {
|
||||||
debug_log 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
|
set catch_status [ catch {
|
||||||
### TODO hset [sct] [hval [sct]]
|
debug_log 1 "halt tc_root=${tc_root} sct=[sct] driving=[sct driving]"
|
||||||
sct driving 0
|
### TODO hset [sct] [hval [sct]]
|
||||||
return "idle"
|
sct driving 0
|
||||||
|
return "idle"
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to check the write parameter on a device
|
# function to check the write parameter on a device
|
||||||
proc ::scobj::hiden_xcs::noResponse {tc_root} {
|
proc ::scobj::hiden_xcs::noResponse {tc_root} {
|
||||||
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
|
set catch_status [ catch {
|
||||||
return "idle"
|
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
|
||||||
|
return "idle"
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# pid function for PID control
|
# pid function for PID control
|
||||||
proc ::scobj::hiden_xcs::pid_flow {tc_root sp pv} {
|
proc ::scobj::hiden_xcs::pid_flow {tc_root sp pv} {
|
||||||
debug_log 1 "pid_flow tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
|
set catch_status [ catch {
|
||||||
sct pid_error [expr ${sp} - ${pv}]
|
debug_log 1 "pid_flow tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
|
||||||
set p_value [expr [sct pid_pvalue] * [sct pid_error]]
|
sct pid_error [expr ${sp} - ${pv}]
|
||||||
set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]
|
set p_value [expr [sct pid_pvalue] * [sct pid_error]]
|
||||||
sct pid_deriv [sct pid_error]
|
set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]
|
||||||
sct pid_integ [expr [sct pid_integ] + [sct pid_error]]
|
sct pid_deriv [sct pid_error]
|
||||||
if { [sct pid_integ] > [sct pid_imax] } {
|
sct pid_integ [expr [sct pid_integ] + [sct pid_error]]
|
||||||
sct pid_integ [sct pid_imax]
|
if { [sct pid_integ] > [sct pid_imax] } {
|
||||||
}
|
sct pid_integ [sct pid_imax]
|
||||||
if { [sct pid_integ] < -[sct pid_imax] } {
|
}
|
||||||
sct pid_integ -[sct pid_imax]
|
if { [sct pid_integ] < -[sct pid_imax] } {
|
||||||
}
|
sct pid_integ -[sct pid_imax]
|
||||||
set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
|
}
|
||||||
set pid [expr ${p_value} + ${i_value} + ${d_value}]
|
set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
|
||||||
sct pid_output ${pid}
|
set pid [expr ${p_value} + ${i_value} + ${d_value}]
|
||||||
|
sct pid_output ${pid}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
return ${pid}
|
return ${pid}
|
||||||
}
|
}
|
||||||
|
|
||||||
# pid function for PID control
|
# pid function for PID control
|
||||||
proc ::scobj::hiden_xcs::pid_humidity {tc_root sp pv} {
|
proc ::scobj::hiden_xcs::pid_humidity {tc_root sp pv} {
|
||||||
debug_log 1 "pid_humidity tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
|
set catch_status [ catch {
|
||||||
sct pid_error [expr ${sp} - ${pv}]
|
debug_log 1 "pid_humidity tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"
|
||||||
set p_value [expr [sct pid_pvalue] * [sct pid_error]]
|
sct pid_error [expr ${sp} - ${pv}]
|
||||||
set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]
|
set p_value [expr [sct pid_pvalue] * [sct pid_error]]
|
||||||
sct pid_deriv [sct pid_error]
|
set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]
|
||||||
sct pid_integ [expr [sct pid_integ] + [sct pid_error]]
|
sct pid_deriv [sct pid_error]
|
||||||
if { [sct pid_integ] > [sct pid_imax] } {
|
sct pid_integ [expr [sct pid_integ] + [sct pid_error]]
|
||||||
sct pid_integ [sct pid_imax]
|
if { [sct pid_integ] > [sct pid_imax] } {
|
||||||
}
|
sct pid_integ [sct pid_imax]
|
||||||
if { [sct pid_integ] < -[sct pid_imax] } {
|
}
|
||||||
sct pid_integ -[sct pid_imax]
|
if { [sct pid_integ] < -[sct pid_imax] } {
|
||||||
}
|
sct pid_integ -[sct pid_imax]
|
||||||
set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
|
}
|
||||||
set pid [expr ${p_value} + ${i_value} + ${d_value}]
|
set i_value [expr [sct pid_ivalue] * [sct pid_integ]]
|
||||||
sct pid_output ${pid}
|
set pid [expr ${p_value} + ${i_value} + ${d_value}]
|
||||||
|
sct pid_output ${pid}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
return ${pid}
|
return ${pid}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to parse the read of a parameter on a device
|
# function to parse the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::rdValue {tc_root} {
|
proc ::scobj::hiden_xcs::rdValue {tc_root} {
|
||||||
debug_log 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "rdValue tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set data [sct result]
|
|
||||||
set nextState "idle"
|
|
||||||
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
|
||||||
# the protocol driver has reported an error
|
|
||||||
sct geterror "${data}"
|
|
||||||
return -code error "[sct geterror]"
|
|
||||||
}
|
|
||||||
if { ${data} != [sct oldval] } {
|
|
||||||
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
|
||||||
sct oldval ${data}
|
|
||||||
sct update ${data}
|
|
||||||
sct utime readtime
|
|
||||||
}
|
}
|
||||||
return ${nextState}
|
set data [sct result]
|
||||||
|
set nextState "idle"
|
||||||
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
|
# the protocol driver has reported an error
|
||||||
|
sct geterror "${data}"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to parse the read of a parameter on a device
|
# function to parse the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::read_all_data {tc_root} {
|
proc ::scobj::hiden_xcs::read_all_data {tc_root} {
|
||||||
debug_log 1 "read_all_data tc_root=${tc_root} sct=[sct] result=[sct result]"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "read_all_data tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set data [sct result]
|
}
|
||||||
set nextState "idle"
|
set data [sct result]
|
||||||
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
set nextState "idle"
|
||||||
# the protocol driver has reported an error
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
sct geterror "${data}"
|
# the protocol driver has reported an error
|
||||||
return -code error "[sct geterror]"
|
sct geterror "${data}"
|
||||||
}
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
# hook code starts
|
# hook code starts
|
||||||
if { [string equal -nocase -length 2 "${data}" "A "] } {
|
if { [string equal -nocase -length 2 "${data}" "A "] } {
|
||||||
set data_list [split [string range "${data}" 2 end-3] ',']
|
set data_list [split [string range "${data}" 2 end-3] ',']
|
||||||
@ -271,32 +307,35 @@ proc ::scobj::hiden_xcs::read_all_data {tc_root} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
|
||||||
if { ${data} != [sct oldval] } {
|
|
||||||
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
|
||||||
sct oldval ${data}
|
|
||||||
sct update ${data}
|
|
||||||
sct utime readtime
|
|
||||||
}
|
}
|
||||||
return ${nextState}
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to parse the read of a parameter on a device
|
# function to parse the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::read_digital {tc_root} {
|
proc ::scobj::hiden_xcs::read_digital {tc_root} {
|
||||||
debug_log 1 "read_digital tc_root=${tc_root} sct=[sct] result=[sct result]"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "read_digital tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set data [sct result]
|
}
|
||||||
set nextState "idle"
|
set data [sct result]
|
||||||
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
set nextState "idle"
|
||||||
# the protocol driver has reported an error
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
sct geterror "${data}"
|
# the protocol driver has reported an error
|
||||||
return -code error "[sct geterror]"
|
sct geterror "${data}"
|
||||||
}
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
# hook code starts
|
# hook code starts
|
||||||
if { [string equal -nocase -length 5 "${data}" "DOUT ="] } {
|
if { [string equal -nocase -length 5 "${data}" "DOUT ="] } {
|
||||||
set result [scan "${data}" "DOUT = %d OK" val]
|
set result [scan "${data}" "DOUT = %d OK" val]
|
||||||
@ -309,54 +348,60 @@ proc ::scobj::hiden_xcs::read_digital {tc_root} {
|
|||||||
sct geterror "Syntax error in: '${data}'"
|
sct geterror "Syntax error in: '${data}'"
|
||||||
}
|
}
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
|
||||||
if { ${data} != [sct oldval] } {
|
|
||||||
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
|
||||||
sct oldval ${data}
|
|
||||||
sct update ${data}
|
|
||||||
sct utime readtime
|
|
||||||
}
|
}
|
||||||
return ${nextState}
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to parse the read of a parameter on a device
|
# function to parse the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::read_flow {tc_root} {
|
proc ::scobj::hiden_xcs::read_flow {tc_root} {
|
||||||
debug_log 1 "read_flow tc_root=${tc_root} sct=[sct] result=[sct result]"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "read_flow tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set data [sct result]
|
|
||||||
set nextState "idle"
|
|
||||||
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
|
||||||
# the protocol driver has reported an error
|
|
||||||
sct geterror "${data}"
|
|
||||||
return -code error "[sct geterror]"
|
|
||||||
}
|
|
||||||
if { ${data} != [sct oldval] } {
|
|
||||||
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
|
||||||
sct oldval ${data}
|
|
||||||
sct update ${data}
|
|
||||||
sct utime readtime
|
|
||||||
}
|
}
|
||||||
return ${nextState}
|
set data [sct result]
|
||||||
|
set nextState "idle"
|
||||||
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
|
# the protocol driver has reported an error
|
||||||
|
sct geterror "${data}"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to parse the read of a parameter on a device
|
# function to parse the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::read_sixteen {tc_root} {
|
proc ::scobj::hiden_xcs::read_sixteen {tc_root} {
|
||||||
debug_log 1 "read_sixteen tc_root=${tc_root} sct=[sct] result=[sct result]"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "read_sixteen tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set data [sct result]
|
}
|
||||||
set nextState "idle"
|
set data [sct result]
|
||||||
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
set nextState "idle"
|
||||||
# the protocol driver has reported an error
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
sct geterror "${data}"
|
# the protocol driver has reported an error
|
||||||
return -code error "[sct geterror]"
|
sct geterror "${data}"
|
||||||
}
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
# hook code starts
|
# hook code starts
|
||||||
if { [string equal -nocase -length 5 "${data}" "AIN ="] } {
|
if { [string equal -nocase -length 5 "${data}" "AIN ="] } {
|
||||||
set result [scan "${data}" "AIN = %d OK" val]
|
set result [scan "${data}" "AIN = %d OK" val]
|
||||||
@ -379,32 +424,35 @@ proc ::scobj::hiden_xcs::read_sixteen {tc_root} {
|
|||||||
sct geterror "Syntax error in: '${data}'"
|
sct geterror "Syntax error in: '${data}'"
|
||||||
}
|
}
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
|
||||||
if { ${data} != [sct oldval] } {
|
|
||||||
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
|
||||||
sct oldval ${data}
|
|
||||||
sct update ${data}
|
|
||||||
sct utime readtime
|
|
||||||
}
|
}
|
||||||
return ${nextState}
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to parse the read of a parameter on a device
|
# function to parse the read of a parameter on a device
|
||||||
proc ::scobj::hiden_xcs::read_twelve {tc_root} {
|
proc ::scobj::hiden_xcs::read_twelve {tc_root} {
|
||||||
debug_log 1 "read_twelve tc_root=${tc_root} sct=[sct] result=[sct result]"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "read_twelve tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set data [sct result]
|
}
|
||||||
set nextState "idle"
|
set data [sct result]
|
||||||
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
set nextState "idle"
|
||||||
# the protocol driver has reported an error
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
sct geterror "${data}"
|
# the protocol driver has reported an error
|
||||||
return -code error "[sct geterror]"
|
sct geterror "${data}"
|
||||||
}
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
# hook code starts
|
# hook code starts
|
||||||
if { [string equal -nocase -length 5 "${data}" "AOUT ="] } {
|
if { [string equal -nocase -length 5 "${data}" "AOUT ="] } {
|
||||||
set result [scan "${data}" "AOUT = %d OK" val]
|
set result [scan "${data}" "AOUT = %d OK" val]
|
||||||
@ -427,67 +475,76 @@ proc ::scobj::hiden_xcs::read_twelve {tc_root} {
|
|||||||
sct geterror "Syntax error in: '${data}'"
|
sct geterror "Syntax error in: '${data}'"
|
||||||
}
|
}
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
|
||||||
if { ${data} != [sct oldval] } {
|
|
||||||
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
|
||||||
sct oldval ${data}
|
|
||||||
sct update ${data}
|
|
||||||
sct utime readtime
|
|
||||||
}
|
}
|
||||||
return ${nextState}
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to write a parameter value on a device
|
# function to write a parameter value on a device
|
||||||
proc ::scobj::hiden_xcs::setValue {tc_root nextState cmd_str} {
|
proc ::scobj::hiden_xcs::setValue {tc_root nextState cmd_str} {
|
||||||
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set par [sct target]
|
|
||||||
set cmd "${cmd_str}${par}"
|
|
||||||
if { [hpropexists [sct] driving] } {
|
|
||||||
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
|
||||||
sct driving 1
|
|
||||||
}
|
}
|
||||||
}
|
set par [sct target]
|
||||||
debug_log 1 "setValue sct send ${cmd}"
|
set cmd "${cmd_str}${par}"
|
||||||
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
if { [hpropexists [sct] driving] } {
|
||||||
sct send "${cmd}"
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
}
|
sct driving 1
|
||||||
return ${nextState}
|
}
|
||||||
|
}
|
||||||
|
debug_log 1 "setValue sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to write a parameter value on a device
|
# function to write a parameter value on a device
|
||||||
proc ::scobj::hiden_xcs::write_digital {tc_root nextState cmd_str} {
|
proc ::scobj::hiden_xcs::write_digital {tc_root nextState cmd_str} {
|
||||||
debug_log 1 "write_digital tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "write_digital tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set par [sct target]
|
|
||||||
set cmd "${cmd_str}${par}"
|
|
||||||
if { [hpropexists [sct] driving] } {
|
|
||||||
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
|
||||||
sct driving 1
|
|
||||||
}
|
}
|
||||||
}
|
set par [sct target]
|
||||||
debug_log 1 "write_digital sct send ${cmd}"
|
set cmd "${cmd_str}${par}"
|
||||||
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
if { [hpropexists [sct] driving] } {
|
||||||
sct send "${cmd}"
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
}
|
sct driving 1
|
||||||
return ${nextState}
|
}
|
||||||
|
}
|
||||||
|
debug_log 1 "write_digital sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to write a parameter value on a device
|
# function to write a parameter value on a device
|
||||||
proc ::scobj::hiden_xcs::write_flow {tc_root nextState cmd_str} {
|
proc ::scobj::hiden_xcs::write_flow {tc_root nextState cmd_str} {
|
||||||
debug_log 1 "write_flow tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "write_flow tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set par [sct target]
|
}
|
||||||
set cmd "${cmd_str}${par}"
|
set par [sct target]
|
||||||
|
set cmd "${cmd_str}${par}"
|
||||||
# hook code starts
|
# hook code starts
|
||||||
if { [hpropexists ${tc_root}/humidity target] } {
|
if { [hpropexists ${tc_root}/humidity target] } {
|
||||||
set humidity_target [hgetpropval ${tc_root}/humidity target]
|
set humidity_target [hgetpropval ${tc_root}/humidity target]
|
||||||
@ -500,30 +557,33 @@ proc ::scobj::hiden_xcs::write_flow {tc_root nextState cmd_str} {
|
|||||||
hset ${tc_root}/analog/sp2 ${flow2_target}
|
hset ${tc_root}/analog/sp2 ${flow2_target}
|
||||||
set cmd "@@NOSEND@@"
|
set cmd "@@NOSEND@@"
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
|
||||||
if { [hpropexists [sct] driving] } {
|
|
||||||
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
|
||||||
sct driving 1
|
|
||||||
}
|
}
|
||||||
}
|
if { [hpropexists [sct] driving] } {
|
||||||
debug_log 1 "write_flow sct send ${cmd}"
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
sct driving 1
|
||||||
sct send "${cmd}"
|
}
|
||||||
}
|
}
|
||||||
return ${nextState}
|
debug_log 1 "write_flow sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to write a parameter value on a device
|
# function to write a parameter value on a device
|
||||||
proc ::scobj::hiden_xcs::write_humidity {tc_root nextState cmd_str} {
|
proc ::scobj::hiden_xcs::write_humidity {tc_root nextState cmd_str} {
|
||||||
debug_log 1 "write_humidity tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "write_humidity tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set par [sct target]
|
}
|
||||||
set cmd "${cmd_str}${par}"
|
set par [sct target]
|
||||||
|
set cmd "${cmd_str}${par}"
|
||||||
# hook code starts
|
# hook code starts
|
||||||
if { [hpropexists ${tc_root}/flow target] } {
|
if { [hpropexists ${tc_root}/flow target] } {
|
||||||
set flow_target [hgetpropval ${tc_root}/flow target]
|
set flow_target [hgetpropval ${tc_root}/flow target]
|
||||||
@ -536,30 +596,33 @@ proc ::scobj::hiden_xcs::write_humidity {tc_root nextState cmd_str} {
|
|||||||
hset ${tc_root}/analog/sp2 ${flow2_target}
|
hset ${tc_root}/analog/sp2 ${flow2_target}
|
||||||
set cmd "@@NOSEND@@"
|
set cmd "@@NOSEND@@"
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
|
||||||
if { [hpropexists [sct] driving] } {
|
|
||||||
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
|
||||||
sct driving 1
|
|
||||||
}
|
}
|
||||||
}
|
if { [hpropexists [sct] driving] } {
|
||||||
debug_log 1 "write_humidity sct send ${cmd}"
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
sct driving 1
|
||||||
sct send "${cmd}"
|
}
|
||||||
}
|
}
|
||||||
return ${nextState}
|
debug_log 1 "write_humidity sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
# function to write a parameter value on a device
|
# function to write a parameter value on a device
|
||||||
proc ::scobj::hiden_xcs::write_twelve {tc_root nextState cmd_str} {
|
proc ::scobj::hiden_xcs::write_twelve {tc_root nextState cmd_str} {
|
||||||
debug_log 1 "write_twelve tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
set catch_status [ catch {
|
||||||
if { [hpropexists [sct] geterror] } {
|
debug_log 1 "write_twelve tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
|
||||||
hdelprop [sct] geterror
|
if { [hpropexists [sct] geterror] } {
|
||||||
}
|
hdelprop [sct] geterror
|
||||||
set par [sct target]
|
}
|
||||||
set cmd "${cmd_str}${par}"
|
set par [sct target]
|
||||||
|
set cmd "${cmd_str}${par}"
|
||||||
# hook code starts
|
# hook code starts
|
||||||
if { [hpropexists [sct] base] } {
|
if { [hpropexists [sct] base] } {
|
||||||
set base [sct base]
|
set base [sct base]
|
||||||
@ -586,20 +649,22 @@ proc ::scobj::hiden_xcs::write_twelve {tc_root nextState cmd_str} {
|
|||||||
set par [expr int(${base} + (4095.0 * ${par} / ${span}))]
|
set par [expr int(${base} + (4095.0 * ${par} / ${span}))]
|
||||||
set cmd "${cmd_str}${par}"
|
set cmd "${cmd_str}${par}"
|
||||||
# hook code ends
|
# hook code ends
|
||||||
if { [hpropexists [sct] geterror] } {
|
if { [hpropexists [sct] geterror] } {
|
||||||
debug_log 1 "[sct] error: [sct geterror]"
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
return -code error "[sct geterror]"
|
error "[sct geterror]"
|
||||||
}
|
|
||||||
if { [hpropexists [sct] driving] } {
|
|
||||||
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
|
||||||
sct driving 1
|
|
||||||
}
|
}
|
||||||
}
|
if { [hpropexists [sct] driving] } {
|
||||||
debug_log 1 "write_twelve sct send ${cmd}"
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
sct driving 1
|
||||||
sct send "${cmd}"
|
}
|
||||||
}
|
}
|
||||||
return ${nextState}
|
debug_log 1 "write_twelve sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc ::scobj::hiden_xcs::mk_sct_hiden_xcs { sct_controller name tol } {
|
proc ::scobj::hiden_xcs::mk_sct_hiden_xcs { sct_controller name tol } {
|
||||||
@ -884,7 +949,7 @@ proc ::scobj::hiden_xcs::mk_sct_hiden_xcs { sct_controller name tol } {
|
|||||||
# hook code starts
|
# hook code starts
|
||||||
# hook code ends
|
# hook code ends
|
||||||
} catch_message ]
|
} catch_message ]
|
||||||
handle_exception ${catch_status} ${catch_message} "in ${ns}::mk_sct_hiden_xcs"
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace eval ::scobj::hiden_xcs {
|
namespace eval ::scobj::hiden_xcs {
|
||||||
@ -893,20 +958,23 @@ namespace eval ::scobj::hiden_xcs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proc add_hiden_xcs {name IP port terminator {tol 0.5}} {
|
proc add_hiden_xcs {name IP port terminator {tol 0.5}} {
|
||||||
set ns "::scobj::hiden_xcs"
|
set catch_status [ catch {
|
||||||
${ns}::debug_log 1 "add_hiden_xcs ${name} ${IP} ${port}"
|
set ns "::scobj::hiden_xcs"
|
||||||
if {[SplitReply [environment_simulation]]=="false"} {
|
${ns}::debug_log 1 "add_hiden_xcs ${name} ${IP} ${port}"
|
||||||
if {[string equal -nocase "aqadapter" "${IP}"]} {
|
if {[SplitReply [environment_simulation]]=="false"} {
|
||||||
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
|
if {[string equal -nocase "aqadapter" "${IP}"]} {
|
||||||
makesctcontroller sct_${name} aqadapter ${port}
|
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
|
||||||
} else {
|
makesctcontroller sct_${name} aqadapter ${port}
|
||||||
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port} ${terminator}"
|
} else {
|
||||||
makesctcontroller sct_${name} std ${IP}:${port} ${terminator}
|
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port} ${terminator}"
|
||||||
|
makesctcontroller sct_${name} std ${IP}:${port} ${terminator}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
${ns}::debug_log 1 "mk_sct_hiden_xcs sct_${name} ${name} ${tol}"
|
||||||
${ns}::debug_log 1 "mk_sct_hiden_xcs sct_${name} ${name} ${tol}"
|
${ns}::mk_sct_hiden_xcs sct_${name} ${name} ${tol}
|
||||||
${ns}::mk_sct_hiden_xcs sct_${name} ${name} ${tol}
|
close ${fd}
|
||||||
close ${fd}
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
}
|
}
|
||||||
|
|
||||||
puts stdout "file evaluation of sct_hiden_xcs.tcl"
|
puts stdout "file evaluation of sct_hiden_xcs.tcl"
|
||||||
|
312
site_ansto/instrument/config/environment/sct_isotech_ps.tcl
Normal file
312
site_ansto/instrument/config/environment/sct_isotech_ps.tcl
Normal file
@ -0,0 +1,312 @@
|
|||||||
|
# Generated driver for isotech_ps
|
||||||
|
# vim: tabstop=8 softtabstop=2 shiftwidth=2 nocindent smartindent
|
||||||
|
#
|
||||||
|
|
||||||
|
namespace eval ::scobj::isotech_ps {
|
||||||
|
set debug_threshold 0
|
||||||
|
}
|
||||||
|
|
||||||
|
proc ::scobj::isotech_ps::debug_log {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 line "[clock format [clock seconds] -format "%T"] ${debug_string}"
|
||||||
|
puts ${fd} "${line}"
|
||||||
|
close ${fd}
|
||||||
|
}
|
||||||
|
} 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]"
|
||||||
|
set setpoint [sct target]
|
||||||
|
if { [hpropexists [sct] lowerlimit] } {
|
||||||
|
set lolimit [sct lowerlimit]
|
||||||
|
} else {
|
||||||
|
# lowerlimit not set, use target
|
||||||
|
set lolimit [sct target]
|
||||||
|
}
|
||||||
|
if { [hpropexists [sct] upperlimit] } {
|
||||||
|
set hilimit [sct upperlimit]
|
||||||
|
} else {
|
||||||
|
# upperlimit not set, use target
|
||||||
|
set hilimit [sct target]
|
||||||
|
}
|
||||||
|
if { ${setpoint} < ${lolimit} || ${setpoint} > ${hilimit} } {
|
||||||
|
error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"
|
||||||
|
}
|
||||||
|
return OK
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to request the read of a parameter on a device
|
||||||
|
proc ::scobj::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}"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set cmd "${cmd_str}"
|
||||||
|
debug_log 1 "getValue sct send ${cmd}"
|
||||||
|
sct send "${cmd}"
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to check the write parameter on a device
|
||||||
|
proc ::scobj::isotech_ps::noResponse {tc_root} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
|
||||||
|
return "idle"
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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]"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set data [sct result]
|
||||||
|
set nextState "idle"
|
||||||
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
|
# the protocol driver has reported an error
|
||||||
|
sct geterror "${data}"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
# hook code starts
|
||||||
|
set data [string range [sct result] 1 end]
|
||||||
|
# hook code ends
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to parse the read of a parameter on a device
|
||||||
|
proc ::scobj::isotech_ps::read_relay {tc_root} {
|
||||||
|
set catch_status [ catch {
|
||||||
|
debug_log 1 "read_relay tc_root=${tc_root} sct=[sct] result=[sct result]"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set data [sct result]
|
||||||
|
set nextState "idle"
|
||||||
|
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
|
||||||
|
# the protocol driver has reported an error
|
||||||
|
sct geterror "${data}"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
# hook code starts
|
||||||
|
if { [string equal -nocase -length 2 "F1" "${data}"] } {
|
||||||
|
set data 1
|
||||||
|
} elseif { [string equal -nocase -length 2 "F0" "${data}"] } {
|
||||||
|
set data 0
|
||||||
|
} else {
|
||||||
|
sct geterror "Unexpected response '${data}' not 'F1' nor 'F0'"
|
||||||
|
}
|
||||||
|
# hook code ends
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
if { ${data} != [sct oldval] } {
|
||||||
|
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
|
||||||
|
sct oldval ${data}
|
||||||
|
sct update ${data}
|
||||||
|
sct utime readtime
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to 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}"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set par [sct target]
|
||||||
|
set cmd "${cmd_str}${par}"
|
||||||
|
if { [hpropexists [sct] driving] } {
|
||||||
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
|
sct driving 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug_log 1 "setValue sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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}"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set par [sct target]
|
||||||
|
set cmd "${cmd_str}${par}"
|
||||||
|
# hook code starts
|
||||||
|
if { ${par} == 0 } {
|
||||||
|
set cmd "KOD"
|
||||||
|
} else {
|
||||||
|
set cmd "KOE"
|
||||||
|
}
|
||||||
|
# hook code ends
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
if { [hpropexists [sct] driving] } {
|
||||||
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
|
sct driving 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug_log 1 "write_relay sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
# function to write a parameter value on a device
|
||||||
|
proc ::scobj::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}"
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
hdelprop [sct] geterror
|
||||||
|
}
|
||||||
|
set par [sct target]
|
||||||
|
set cmd "${cmd_str}${par}"
|
||||||
|
# hook code starts
|
||||||
|
set par "[format "%05.2f" [sct target]]"
|
||||||
|
set cmd "SV ${par}"
|
||||||
|
# hook code ends
|
||||||
|
if { [hpropexists [sct] geterror] } {
|
||||||
|
debug_log 1 "[sct] error: [sct geterror]"
|
||||||
|
error "[sct geterror]"
|
||||||
|
}
|
||||||
|
if { [hpropexists [sct] driving] } {
|
||||||
|
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
|
||||||
|
sct driving 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug_log 1 "write_voltage sct send ${cmd}"
|
||||||
|
if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {
|
||||||
|
sct send "${cmd}"
|
||||||
|
}
|
||||||
|
return ${nextState}
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
proc ::scobj::isotech_ps::mk_sct_isotech_ps { sct_controller name } {
|
||||||
|
debug_log 1 "mk_sct_isotech_ps for ${name}"
|
||||||
|
set ns "[namespace current]"
|
||||||
|
set catch_status [ catch {
|
||||||
|
|
||||||
|
MakeSICSObj ${name} SCT_OBJECT
|
||||||
|
|
||||||
|
sicslist setatt ${name} klass environment
|
||||||
|
sicslist setatt ${name} long_name ${name}
|
||||||
|
|
||||||
|
set scobj_hpath /sics/${name}
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/amps plain user float
|
||||||
|
hsetprop ${scobj_hpath}/amps read ${ns}::getValue ${scobj_hpath} rdValue {A}
|
||||||
|
hsetprop ${scobj_hpath}/amps rdValue ${ns}::rdValue ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/amps control true
|
||||||
|
hsetprop ${scobj_hpath}/amps data true
|
||||||
|
hsetprop ${scobj_hpath}/amps mutable true
|
||||||
|
hsetprop ${scobj_hpath}/amps nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/amps units A
|
||||||
|
hsetprop ${scobj_hpath}/amps oldval 0.0
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/relay plain user int
|
||||||
|
hsetprop ${scobj_hpath}/relay read ${ns}::getValue ${scobj_hpath} read_relay {F}
|
||||||
|
hsetprop ${scobj_hpath}/relay read_relay ${ns}::read_relay ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/relay write ${ns}::write_relay ${scobj_hpath} noResponse {KO}
|
||||||
|
hsetprop ${scobj_hpath}/relay noResponse ${ns}::noResponse ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/relay check ${ns}::checkrange ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/relay control true
|
||||||
|
hsetprop ${scobj_hpath}/relay data true
|
||||||
|
hsetprop ${scobj_hpath}/relay mutable true
|
||||||
|
hsetprop ${scobj_hpath}/relay nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/relay oldval 0
|
||||||
|
|
||||||
|
hfactory ${scobj_hpath}/volts plain user float
|
||||||
|
hsetprop ${scobj_hpath}/volts read ${ns}::getValue ${scobj_hpath} rdValue {V}
|
||||||
|
hsetprop ${scobj_hpath}/volts rdValue ${ns}::rdValue ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/volts write ${ns}::write_voltage ${scobj_hpath} noResponse {SV}
|
||||||
|
hsetprop ${scobj_hpath}/volts noResponse ${ns}::noResponse ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/volts check ${ns}::checkrange ${scobj_hpath}
|
||||||
|
hsetprop ${scobj_hpath}/volts control true
|
||||||
|
hsetprop ${scobj_hpath}/volts data true
|
||||||
|
hsetprop ${scobj_hpath}/volts mutable true
|
||||||
|
hsetprop ${scobj_hpath}/volts nxsave true
|
||||||
|
hsetprop ${scobj_hpath}/volts units V
|
||||||
|
hsetprop ${scobj_hpath}/volts oldval 0.0
|
||||||
|
|
||||||
|
if {[SplitReply [environment_simulation]]=="false"} {
|
||||||
|
${sct_controller} poll ${scobj_hpath}/amps 5
|
||||||
|
${sct_controller} poll ${scobj_hpath}/relay 5
|
||||||
|
${sct_controller} poll ${scobj_hpath}/volts 5
|
||||||
|
${sct_controller} write ${scobj_hpath}/relay
|
||||||
|
${sct_controller} write ${scobj_hpath}/volts
|
||||||
|
}
|
||||||
|
hsetprop ${scobj_hpath} klass environment
|
||||||
|
} catch_message ]
|
||||||
|
handle_exception ${catch_status} ${catch_message}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace eval ::scobj::isotech_ps {
|
||||||
|
namespace export debug_log
|
||||||
|
namespace export mk_sct_isotech_ps
|
||||||
|
}
|
||||||
|
|
||||||
|
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}"
|
||||||
|
if {[SplitReply [environment_simulation]]=="false"} {
|
||||||
|
if {[string equal -nocase "aqadapter" "${IP}"]} {
|
||||||
|
${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"
|
||||||
|
makesctcontroller sct_${name} aqadapter ${port}
|
||||||
|
} else {
|
||||||
|
${ns}::debug_log 1 "makesctcontroller sct_${name} std ${IP}:${port} \"\\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}
|
||||||
|
close ${fd}
|
||||||
|
} 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"
|
Reference in New Issue
Block a user