Wrap generated driver code in 'catch' and handle_exception blocks

This commit is contained in:
Douglas Clowes
2014-03-18 12:42:56 +11:00
parent 7269776484
commit 94e2e06f22
3 changed files with 408 additions and 333 deletions

View File

@ -7,16 +7,19 @@ namespace eval ::scobj::shutters {
} }
proc ::scobj::shutters::debug_log {debug_level debug_string} { proc ::scobj::shutters::debug_log {debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::shutters::debug_threshold}} { if {${debug_level} >= ${::scobj::shutters::debug_threshold}} {
set fd [open "/tmp/shutters.log" "a"] set fd [open "/tmp/shutters.log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}" set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}" puts ${fd} "${line}"
close ${fd} close ${fd}
} }
} catch_message ]
} }
# check function for hset change # check function for hset change
proc ::scobj::shutters::checkrange {tc_root} { 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 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
set setpoint [sct target] set setpoint [sct target]
if { [hpropexists [sct] lowerlimit] } { if { [hpropexists [sct] lowerlimit] } {
@ -35,10 +38,13 @@ proc ::scobj::shutters::checkrange {tc_root} {
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::shutters::getValue {tc_root nextState cmd_str} { 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 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror hdelprop [sct] geterror
@ -47,16 +53,22 @@ proc ::scobj::shutters::getValue {tc_root nextState cmd_str} {
debug_log 1 "getValue sct send ${cmd}" debug_log 1 "getValue sct send ${cmd}"
sct send "${cmd}" sct send "${cmd}"
return ${nextState} return ${nextState}
} 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::shutters::noResponse {tc_root} { proc ::scobj::shutters::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]" debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
return "idle" return "idle"
} 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::shutters::read_switch_pair {tc_root} { 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 1 "read_switch_pair tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror hdelprop [sct] geterror
@ -66,7 +78,7 @@ proc ::scobj::shutters::read_switch_pair {tc_root} {
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} { if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
# the protocol driver has reported an error # the protocol driver has reported an error
sct geterror "${data}" sct geterror "${data}"
return -code error "[sct geterror]" error "[sct geterror]"
} }
# hook code starts # hook code starts
if { [string equal -nocase -length 1 "${data}" "?"] } { if { [string equal -nocase -length 1 "${data}" "?"] } {
@ -93,7 +105,7 @@ proc ::scobj::shutters::read_switch_pair {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] } { if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]" debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
@ -102,10 +114,13 @@ proc ::scobj::shutters::read_switch_pair {tc_root} {
sct utime readtime sct utime readtime
} }
return ${nextState} 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::shutters::setValue {tc_root nextState cmd_str} { 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 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror hdelprop [sct] geterror
@ -122,10 +137,13 @@ proc ::scobj::shutters::setValue {tc_root nextState cmd_str} {
sct send "${cmd}" sct send "${cmd}"
} }
return ${nextState} 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::shutters::write_switch {tc_root nextState cmd_str} { 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 1 "write_switch tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror hdelprop [sct] geterror
@ -143,7 +161,7 @@ proc ::scobj::shutters::write_switch {tc_root nextState cmd_str} {
# 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] driving] } {
if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } { if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {
@ -155,6 +173,8 @@ proc ::scobj::shutters::write_switch {tc_root nextState cmd_str} {
sct send "${cmd}" sct send "${cmd}"
} }
return ${nextState} return ${nextState}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
} }
proc ::scobj::shutters::mk_sct_shutters { sct_controller name } { proc ::scobj::shutters::mk_sct_shutters { sct_controller name } {
@ -230,7 +250,7 @@ proc ::scobj::shutters::mk_sct_shutters { sct_controller name } {
# 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_shutters" handle_exception ${catch_status} ${catch_message}
} }
namespace eval ::scobj::shutters { namespace eval ::scobj::shutters {
@ -239,6 +259,7 @@ namespace eval ::scobj::shutters {
} }
proc add_shutters {name IP port} { proc add_shutters {name IP port} {
set catch_status [ catch {
set ns "::scobj::shutters" set ns "::scobj::shutters"
${ns}::debug_log 1 "add_shutters ${name} ${IP} ${port}" ${ns}::debug_log 1 "add_shutters ${name} ${IP} ${port}"
if {[SplitReply [motor_simulation]]=="false"} { if {[SplitReply [motor_simulation]]=="false"} {
@ -253,6 +274,8 @@ proc add_shutters {name IP port} {
${ns}::debug_log 1 "mk_sct_shutters sct_${name} ${name}" ${ns}::debug_log 1 "mk_sct_shutters sct_${name} ${name}"
${ns}::mk_sct_shutters sct_${name} ${name} ${ns}::mk_sct_shutters sct_${name} ${name}
close ${fd} close ${fd}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
} }
puts stdout "file evaluation of sct_shutters.tcl" puts stdout "file evaluation of sct_shutters.tcl"

View File

@ -7,16 +7,19 @@ namespace eval ::scobj::tank {
} }
proc ::scobj::tank::debug_log {debug_level debug_string} { proc ::scobj::tank::debug_log {debug_level debug_string} {
set catch_status [ catch {
if {${debug_level} >= ${::scobj::tank::debug_threshold}} { if {${debug_level} >= ${::scobj::tank::debug_threshold}} {
set fd [open "/tmp/tank.log" "a"] set fd [open "/tmp/tank.log" "a"]
set line "[clock format [clock seconds] -format "%T"] ${debug_string}" set line "[clock format [clock seconds] -format "%T"] ${debug_string}"
puts ${fd} "${line}" puts ${fd} "${line}"
close ${fd} close ${fd}
} }
} catch_message ]
} }
# check function for hset change # check function for hset change
proc ::scobj::tank::checkrange {tc_root} { proc ::scobj::tank::checkrange {tc_root} {
set catch_status [ catch {
debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]" debug_log 1 "checkrange tc_root=${tc_root} sct=[sct] target=[sct target]"
set setpoint [sct target] set setpoint [sct target]
if { [hpropexists [sct] lowerlimit] } { if { [hpropexists [sct] lowerlimit] } {
@ -35,10 +38,13 @@ proc ::scobj::tank::checkrange {tc_root} {
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::tank::getValue {tc_root nextState cmd_str} { proc ::scobj::tank::getValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" debug_log 1 "getValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror hdelprop [sct] geterror
@ -47,16 +53,22 @@ proc ::scobj::tank::getValue {tc_root nextState cmd_str} {
debug_log 1 "getValue sct send ${cmd}" debug_log 1 "getValue sct send ${cmd}"
sct send "${cmd}" sct send "${cmd}"
return ${nextState} return ${nextState}
} 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::tank::noResponse {tc_root} { proc ::scobj::tank::noResponse {tc_root} {
set catch_status [ catch {
debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]" debug_log 1 "noResponse tc_root=${tc_root} sct=[sct] resp=[sct result]"
return "idle" return "idle"
} 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::tank::read_switch {tc_root} { proc ::scobj::tank::read_switch {tc_root} {
set catch_status [ catch {
debug_log 1 "read_switch tc_root=${tc_root} sct=[sct] result=[sct result]" debug_log 1 "read_switch tc_root=${tc_root} sct=[sct] result=[sct result]"
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror hdelprop [sct] geterror
@ -66,7 +78,7 @@ proc ::scobj::tank::read_switch {tc_root} {
if {[string equal -nocase -length 7 ${data} "ASCERR:"]} { if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {
# the protocol driver has reported an error # the protocol driver has reported an error
sct geterror "${data}" sct geterror "${data}"
return -code error "[sct geterror]" error "[sct geterror]"
} }
# hook code starts # hook code starts
if { [string equal -nocase -length 1 "${data}" "?"] } { if { [string equal -nocase -length 1 "${data}" "?"] } {
@ -90,7 +102,7 @@ proc ::scobj::tank::read_switch {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] } { if { ${data} != [sct oldval] } {
debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]" debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"
@ -99,10 +111,13 @@ proc ::scobj::tank::read_switch {tc_root} {
sct utime readtime sct utime readtime
} }
return ${nextState} 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::tank::setValue {tc_root nextState cmd_str} { proc ::scobj::tank::setValue {tc_root nextState cmd_str} {
set catch_status [ catch {
debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}" debug_log 1 "setValue tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"
if { [hpropexists [sct] geterror] } { if { [hpropexists [sct] geterror] } {
hdelprop [sct] geterror hdelprop [sct] geterror
@ -119,6 +134,8 @@ proc ::scobj::tank::setValue {tc_root nextState cmd_str} {
sct send "${cmd}" sct send "${cmd}"
} }
return ${nextState} return ${nextState}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
} }
proc ::scobj::tank::mk_sct_tank { sct_controller name } { proc ::scobj::tank::mk_sct_tank { sct_controller name } {
@ -186,7 +203,7 @@ proc ::scobj::tank::mk_sct_tank { sct_controller name } {
# 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_tank" handle_exception ${catch_status} ${catch_message}
} }
namespace eval ::scobj::tank { namespace eval ::scobj::tank {
@ -195,6 +212,7 @@ namespace eval ::scobj::tank {
} }
proc add_tank {name IP port} { proc add_tank {name IP port} {
set catch_status [ catch {
set ns "::scobj::tank" set ns "::scobj::tank"
${ns}::debug_log 1 "add_tank ${name} ${IP} ${port}" ${ns}::debug_log 1 "add_tank ${name} ${IP} ${port}"
if {[SplitReply [motor_simulation]]=="false"} { if {[SplitReply [motor_simulation]]=="false"} {
@ -209,6 +227,8 @@ proc add_tank {name IP port} {
${ns}::debug_log 1 "mk_sct_tank sct_${name} ${name}" ${ns}::debug_log 1 "mk_sct_tank sct_${name} ${name}"
${ns}::mk_sct_tank sct_${name} ${name} ${ns}::mk_sct_tank sct_${name} ${name}
close ${fd} close ${fd}
} catch_message ]
handle_exception ${catch_status} ${catch_message}
} }
puts stdout "file evaluation of sct_tank.tcl" puts stdout "file evaluation of sct_tank.tcl"

View File

@ -745,12 +745,14 @@ def put_preamble(MyDriver):
txt += ['}'] txt += ['}']
txt += [''] txt += ['']
txt += ['proc %s::debug_log {debug_level debug_string} {' % MyDriver['namespace']] txt += ['proc %s::debug_log {debug_level debug_string} {' % MyDriver['namespace']]
txt += [' set catch_status [ catch {']
txt += [' if {${debug_level} >= ${%s::debug_threshold}} {' % MyDriver['namespace']] txt += [' if {${debug_level} >= ${%s::debug_threshold}} {' % MyDriver['namespace']]
txt += [' set fd [open "/tmp/%s.log" "a"]' % MyDriver['name']] txt += [' set fd [open "/tmp/%s.log" "a"]' % MyDriver['name']]
txt += [' set line "[clock format [clock seconds] -format "%T"] ${debug_string}"'] txt += [' set line "[clock format [clock seconds] -format "%T"] ${debug_string}"']
txt += [' puts ${fd} "${line}"'] txt += [' puts ${fd} "${line}"']
txt += [' close ${fd}'] txt += [' close ${fd}']
txt += [' }'] txt += [' }']
txt += [' } catch_message ]']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -758,6 +760,7 @@ def put_write_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# function to write a parameter value on a device'] txt += ['# function to write a parameter value on a device']
txt += ['proc %s::%s {tc_root nextState cmd_str} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root nextState cmd_str} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func]
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' hdelprop [sct] geterror'] txt += [' hdelprop [sct] geterror']
@ -770,7 +773,7 @@ def put_write_function(MyDriver, func):
txt += ['# hook code ends'] txt += ['# hook code ends']
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' debug_log 1 "[sct] error: [sct geterror]"'] txt += [' debug_log 1 "[sct] error: [sct geterror]"']
txt += [' return -code error "[sct geterror]"'] txt += [' error "[sct geterror]"']
txt += [' }'] txt += [' }']
txt += [' if { [hpropexists [sct] driving] } {'] txt += [' if { [hpropexists [sct] driving] } {']
txt += [' if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {'] txt += [' if { [hpropexists [sct] writestatus] && [sct writestatus] == "start" } {']
@ -782,6 +785,8 @@ def put_write_function(MyDriver, func):
txt += [' sct send "${cmd}"'] txt += [' sct send "${cmd}"']
txt += [' }'] txt += [' }']
txt += [' return ${nextState}'] txt += [' return ${nextState}']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -789,12 +794,15 @@ def put_check_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# function to check the write parameter on a device'] txt += ['# function to check the write parameter on a device']
txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] resp=[sct result]"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] resp=[sct result]"' % func]
if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0: if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs'][func]['text'] txt += MyDriver['Funcs'][func]['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
txt += [' return "idle"'] txt += [' return "idle"']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -802,6 +810,7 @@ def put_fetch_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# function to request the read of a parameter on a device'] txt += ['# function to request the read of a parameter on a device']
txt += ['proc %s::%s {tc_root nextState cmd_str} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root nextState cmd_str} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func]
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' hdelprop [sct] geterror'] txt += [' hdelprop [sct] geterror']
@ -813,11 +822,13 @@ def put_fetch_function(MyDriver, func):
txt += ['# hook code ends'] txt += ['# hook code ends']
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' debug_log 1 "[sct] error: [sct geterror]"'] txt += [' debug_log 1 "[sct] error: [sct geterror]"']
txt += [' return -code error "[sct geterror]"'] txt += [' error "[sct geterror]"']
txt += [' }'] txt += [' }']
txt += [' debug_log 1 "%s sct send ${cmd}"' % func] txt += [' debug_log 1 "%s sct send ${cmd}"' % func]
txt += [' sct send "${cmd}"'] txt += [' sct send "${cmd}"']
txt += [' return ${nextState}'] txt += [' return ${nextState}']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -825,6 +836,7 @@ def put_read_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# function to parse the read of a parameter on a device'] txt += ['# function to parse the read of a parameter on a device']
txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] result=[sct result]"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] result=[sct result]"' % func]
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' hdelprop [sct] geterror'] txt += [' hdelprop [sct] geterror']
@ -834,7 +846,7 @@ def put_read_function(MyDriver, func):
txt += [' if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {'] txt += [' if {[string equal -nocase -length 7 ${data} "ASCERR:"]} {']
txt += [' # the protocol driver has reported an error'] txt += [' # the protocol driver has reported an error']
txt += [' sct geterror "${data}"'] txt += [' sct geterror "${data}"']
txt += [' return -code error "[sct geterror]"'] txt += [' error "[sct geterror]"']
txt += [' }'] txt += [' }']
if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0: if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
@ -842,7 +854,7 @@ def put_read_function(MyDriver, func):
txt += ['# hook code ends'] txt += ['# hook code ends']
txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' if { [hpropexists [sct] geterror] } {']
txt += [' debug_log 1 "[sct] error: [sct geterror]"'] txt += [' debug_log 1 "[sct] error: [sct geterror]"']
txt += [' return -code error "[sct geterror]"'] txt += [' error "[sct geterror]"']
txt += [' }'] txt += [' }']
txt += [' if { ${data} != [sct oldval] } {'] txt += [' if { ${data} != [sct oldval] } {']
txt += [' debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"'] txt += [' debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"']
@ -851,6 +863,8 @@ def put_read_function(MyDriver, func):
txt += [' sct utime readtime'] txt += [' sct utime readtime']
txt += [' }'] txt += [' }']
txt += [' return ${nextState}'] txt += [' return ${nextState}']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -858,6 +872,7 @@ def put_checkrange_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# check function for hset change'] txt += ['# check function for hset change']
txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] target=[sct target]"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] target=[sct target]"' % func]
txt += [' set setpoint [sct target]'] txt += [' set setpoint [sct target]']
txt += [' if { [hpropexists [sct] lowerlimit] } {'] txt += [' if { [hpropexists [sct] lowerlimit] } {']
@ -880,6 +895,8 @@ def put_checkrange_function(MyDriver, func):
txt += [' error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"'] txt += [' error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"']
txt += [' }'] txt += [' }']
txt += [' return OK'] txt += [' return OK']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -887,6 +904,7 @@ def put_checklimits_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# checklimits function for driveable interface'] txt += ['# checklimits function for driveable interface']
txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] target=[sct target]"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] target=[sct target]"' % func]
txt += [' set setpoint [sct target]'] txt += [' set setpoint [sct target]']
txt += [' if { [hpropexists [sct] lowerlimit] } {'] txt += [' if { [hpropexists [sct] lowerlimit] } {']
@ -910,6 +928,8 @@ def put_checklimits_function(MyDriver, func):
txt += [' error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"'] txt += [' error "setpoint ${setpoint} violates limits (${lolimit}..${hilimit}) on [sct]"']
txt += [' }'] txt += [' }']
txt += [' return OK'] txt += [' return OK']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -917,6 +937,7 @@ def put_checkstatus_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# checkstatus function for driveable interface'] txt += ['# checkstatus function for driveable interface']
txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0: if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
txt += ['# hook code starts'] txt += ['# hook code starts']
txt += MyDriver['Funcs'][func]['text'] txt += MyDriver['Funcs'][func]['text']
@ -932,6 +953,8 @@ def put_checkstatus_function(MyDriver, func):
txt += [' } else {'] txt += [' } else {']
txt += [' return "idle"'] txt += [' return "idle"']
txt += [' }'] txt += [' }']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -939,6 +962,7 @@ def put_halt_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# halt function for driveable interface'] txt += ['# halt function for driveable interface']
txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] driving=[sct driving]"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] driving=[sct driving]"' % func]
txt += [' ### TODO hset [sct] [hval [sct]]'] txt += [' ### TODO hset [sct] [hval [sct]]']
if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0: if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0:
@ -947,6 +971,8 @@ def put_halt_function(MyDriver, func):
txt += ['# hook code ends'] txt += ['# hook code ends']
txt += [' sct driving 0'] txt += [' sct driving 0']
txt += [' return "idle"'] txt += [' return "idle"']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -954,6 +980,7 @@ def put_pid_function(MyDriver, func):
txt = [''] txt = ['']
txt += ['# pid function for PID control'] txt += ['# pid function for PID control']
txt += ['proc %s::%s {tc_root sp pv} {' % (MyDriver['namespace'], func)] txt += ['proc %s::%s {tc_root sp pv} {' % (MyDriver['namespace'], func)]
txt += [' set catch_status [ catch {']
txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"' % func] txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"' % func]
txt += [' sct pid_error [expr ${sp} - ${pv}]'] txt += [' sct pid_error [expr ${sp} - ${pv}]']
txt += [' set p_value [expr [sct pid_pvalue] * [sct pid_error]]'] txt += [' set p_value [expr [sct pid_pvalue] * [sct pid_error]]']
@ -973,6 +1000,8 @@ def put_pid_function(MyDriver, func):
txt += MyDriver['Funcs'][func]['text'] txt += MyDriver['Funcs'][func]['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
txt += [' sct pid_output ${pid}'] txt += [' sct pid_output ${pid}']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += [' return ${pid}'] txt += [' return ${pid}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -1134,7 +1163,7 @@ def put_mk_sct_driver(MyDriver):
txt += MyDriver['Funcs']['mkDriver']['text'] txt += MyDriver['Funcs']['mkDriver']['text']
txt += ['# hook code ends'] txt += ['# hook code ends']
txt += [' } catch_message ]'] txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message} "in ${ns}::mk_sct_%s"' % MyDriver['name']] txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
emit(txt) emit(txt)
@ -1150,6 +1179,7 @@ def put_postamble(MyDriver):
else: else:
line = 'proc add_%s {name IP port} {' % MyDriver['name'] line = 'proc add_%s {name IP port} {' % MyDriver['name']
txt += [line] txt += [line]
txt += [' set catch_status [ catch {']
txt += [' set ns "%s"' % MyDriver['namespace']] txt += [' set ns "%s"' % MyDriver['namespace']]
txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port}"' % MyDriver['name']] txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port}"' % MyDriver['name']]
txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']] txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']]
@ -1181,6 +1211,8 @@ def put_postamble(MyDriver):
#txt += [' ${ns}::debug_log 1 "makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler"'] #txt += [' ${ns}::debug_log 1 "makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler"']
# txt += [' makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler'] # txt += [' makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler']
txt += [' close ${fd}'] txt += [' close ${fd}']
txt += [' } catch_message ]']
txt += [' handle_exception ${catch_status} ${catch_message}']
txt += ['}'] txt += ['}']
txt += [''] txt += ['']
txt += ['puts stdout "file evaluation of sct_%s.tcl"' % MyDriver['name']] txt += ['puts stdout "file evaluation of sct_%s.tcl"' % MyDriver['name']]