From bf84f65e5a13235f8c2e2c1695a0c1644e52ba06 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 23 Apr 2014 16:26:43 +1000 Subject: [PATCH] Changes to generated driver logging --- site_ansto/instrument/util/gen_sct.py | 106 ++++++++++++++------------ 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index 7b1d9b24..8adca4be 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -822,7 +822,7 @@ def put_preamble(MyDriver): txt += ['#'] txt += [''] txt += ['namespace eval %s {' % MyDriver['namespace']] - txt += [' set debug_threshold 0'] + txt += [' set debug_threshold 5'] if len(MyDriver['Permlink']) > 0: if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split(): pass @@ -832,16 +832,26 @@ def put_preamble(MyDriver): txt += [' }'] txt += ['}'] txt += [''] - txt += ['proc %s::debug_log {debug_level debug_string} {' % MyDriver['namespace']] + txt += ['proc %s::debug_log {tc_root debug_level debug_string} {' % MyDriver['namespace']] txt += [' set catch_status [ catch {'] - txt += [' if {${debug_level} >= ${%s::debug_threshold}} {' % MyDriver['namespace']] - txt += [' set fd [open "/tmp/%s.log" "a"]' % MyDriver['name']] + txt += [' set debug_threshold [hgetpropval ${tc_root} debug_threshold]'] + txt += [' if {${debug_level} >= ${debug_threshold}} {'] + txt += [' set fd [open "/tmp/%s_[basename ${tc_root}].log" "a"]' % MyDriver['name']] txt += [' set line "[clock format [clock seconds] -format "%T"] ${debug_string}"'] txt += [' puts ${fd} "${line}"'] txt += [' close ${fd}'] txt += [' }'] txt += [' } catch_message ]'] txt += ['}'] + txt += [''] + txt += ['proc %s::sics_log {debug_level debug_string} {' % MyDriver['namespace']] + txt += [' set catch_status [ catch {'] + txt += [' set debug_threshold ${%s::debug_threshold}' % MyDriver['namespace']] + txt += [' if {${debug_level} >= ${debug_threshold}} {'] + txt += [' sicslog "%s::${debug_string}"' % MyDriver['namespace']] + txt += [' }'] + txt += [' } catch_message ]'] + txt += ['}'] emit(txt) def put_write_function(MyDriver, func): @@ -849,7 +859,7 @@ def put_write_function(MyDriver, func): txt += ['# function to write a parameter value on a device'] 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 ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func] txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' hdelprop [sct] geterror'] txt += [' }'] @@ -860,7 +870,7 @@ def put_write_function(MyDriver, func): txt += MyDriver['Funcs'][func]['text'] txt += ['# %s hook code ends' % func] txt += [' if { [hpropexists [sct] geterror] } {'] - txt += [' debug_log 1 "[sct] error: [sct geterror]"'] + txt += [' debug_log ${tc_root} 9 "[sct] error: [sct geterror]"'] txt += [' error "[sct geterror]"'] txt += [' }'] else: @@ -870,7 +880,7 @@ def put_write_function(MyDriver, func): txt += [' sct driving 1'] txt += [' }'] txt += [' }'] - txt += [' debug_log 1 "%s sct send ${cmd}"' % func] + txt += [' debug_log ${tc_root} 1 "%s sct send ${cmd}"' % func] txt += [' if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {'] txt += [' sct send "${cmd}"'] txt += [' }'] @@ -885,7 +895,7 @@ def put_check_function(MyDriver, func): txt += ['# function to check the write parameter on a device'] 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 ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] resp=[sct result]"' % func] if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0: txt += ['# %s hook code starts' % func] txt += MyDriver['Funcs'][func]['text'] @@ -903,7 +913,7 @@ def put_fetch_function(MyDriver, func): 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 += [' set catch_status [ catch {'] - txt += [' debug_log 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func] + txt += [' debug_log ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] cmd=${cmd_str}"' % func] txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' hdelprop [sct] geterror'] txt += [' }'] @@ -913,12 +923,12 @@ def put_fetch_function(MyDriver, func): txt += MyDriver['Funcs'][func]['text'] txt += ['# %s hook code ends' % func] txt += [' if { [hpropexists [sct] geterror] } {'] - txt += [' debug_log 1 "[sct] error: [sct geterror]"'] + txt += [' debug_log ${tc_root} 9 "[sct] error: [sct geterror]"'] txt += [' error "[sct geterror]"'] txt += [' }'] else: txt += ['# %s hook code goes here' % func] - txt += [' debug_log 1 "%s sct send ${cmd}"' % func] + txt += [' debug_log ${tc_root} 1 "%s sct send ${cmd}"' % func] txt += [' if {![string equal -nocase -length 10 ${cmd} "@@NOSEND@@"]} {'] txt += [' sct send "${cmd}"'] txt += [' }'] @@ -933,7 +943,7 @@ def put_read_function(MyDriver, func): txt += ['# function to parse the read of a parameter on a device'] 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 ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] result=[sct result]"' % func] txt += [' if { [hpropexists [sct] geterror] } {'] txt += [' hdelprop [sct] geterror'] txt += [' }'] @@ -949,13 +959,13 @@ def put_read_function(MyDriver, func): txt += MyDriver['Funcs'][func]['text'] txt += ['# %s hook code ends' % func] txt += [' if { [hpropexists [sct] geterror] } {'] - txt += [' debug_log 1 "[sct] error: [sct geterror]"'] + txt += [' debug_log ${tc_root} 9 "[sct] error: [sct geterror]"'] txt += [' error "[sct geterror]"'] txt += [' }'] else: txt += ['# %s hook code goes here' % func] txt += [' if { ${data} != [sct oldval] } {'] - txt += [' debug_log 1 "[sct] changed to new:${data}, from old:[sct oldval]"'] + txt += [' debug_log ${tc_root} 1 "[sct] changed to new:${data}, from old:[sct oldval]"'] txt += [' sct oldval ${data}'] txt += [' sct update ${data}'] txt += [' sct utime readtime'] @@ -971,7 +981,7 @@ def put_checkrange_function(MyDriver, func): txt += ['# check function for hset change'] 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 ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] target=[sct target]"' % func] txt += [' set setpoint [sct target]'] txt += [' if { [hpropexists [sct] lowerlimit] } {'] txt += [' set lolimit [sct lowerlimit]'] @@ -1005,7 +1015,7 @@ def put_checklimits_function(MyDriver, func): txt += ['# checklimits function for driveable interface'] 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 ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] target=[sct target]"' % func] txt += [' set setpoint [sct target]'] txt += [' if { [hpropexists [sct] lowerlimit] } {'] txt += [' set lolimit [sct lowerlimit]'] @@ -1082,7 +1092,7 @@ def put_halt_function(MyDriver, func): txt += ['# halt function for driveable interface'] 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 ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] driving=[sct driving]"' % func] txt += [' ### TODO hset [sct] [hval [sct]]'] if func in MyDriver['Funcs'] and len(MyDriver['Funcs'][func]['text']) > 0: txt += ['# %s hook code starts' % func] @@ -1102,7 +1112,7 @@ def put_pid_function(MyDriver, func): txt += ['# pid function for PID control'] 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 ${tc_root} 1 "%s tc_root=${tc_root} sct=[sct] pv=${pv} sp=${sp}"' % func] txt += [' sct pid_error [expr ${sp} - ${pv}]'] txt += [' set p_value [expr [sct pid_pvalue] * [sct pid_error]]'] txt += [' set d_value [expr [sct pid_dvalue] * (${pv} - [sct oldval])]'] @@ -1277,18 +1287,18 @@ def put_group(MyDriver, MyGroup): txt += put_group(MyDriver, MyGroup['Groups'][grp]) return txt -def put_mk_sct_driver(MyDriver): +def put_mkDriver(MyDriver): txt = [''] if 'make_args' in MyDriver: - line = 'proc %s::mk_sct_%s { sct_controller name %s } {' % (MyDriver['namespace'], MyDriver['name'], MyDriver['make_args']) + line = 'proc %s::mkDriver { sct_controller name %s } {' % (MyDriver['namespace'], MyDriver['make_args']) else: - line = 'proc %s::mk_sct_%s { sct_controller name } {' % (MyDriver['namespace'], MyDriver['name']) + line = 'proc %s::mkDriver { sct_controller name } {' % (MyDriver['namespace']) txt += [line] if 'make_args' in MyDriver: make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()]) - txt += [' debug_log 1 "mk_sct_%s ${sct_controller} ${name} %s"' % (MyDriver['name'], make_args)] + txt += [' %s::sics_log 9 "%s::mkDriver ${sct_controller} ${name} %s"' % (MyDriver['namespace'], MyDriver['namespace'], make_args)] else: - txt += [' debug_log 1 "mk_sct_%s for ${name}"' % MyDriver['name']] + txt += [' %s::sics_log 9 "%s::mkDriver for ${name}"' % (MyDriver['namespace'], MyDriver['namespace'])] txt += [' set ns "[namespace current]"'] txt += [' set catch_status [ catch {'] txt += [''] @@ -1312,6 +1322,7 @@ def put_mk_sct_driver(MyDriver): txt += put_group(MyDriver, MyDriver['Groups'][group]) txt += [' hsetprop ${scobj_hpath} klass %s' % MyDriver['class']] + txt += [' hsetprop ${scobj_hpath} debug_threshold 5'] func = 'mkDriver' if func in MyDriver['Funcs']: txt += ['# %s hook code starts' % func] @@ -1327,8 +1338,10 @@ def put_mk_sct_driver(MyDriver): def put_postamble(MyDriver): txt = [''] txt += ['namespace eval %s {' % MyDriver['namespace']] + txt += [' namespace export debug_threshold'] txt += [' namespace export debug_log'] - txt += [' namespace export mk_sct_%s' % MyDriver['name']] + txt += [' namespace export sics_log'] + txt += [' namespace export mkDriver'] txt += ['}'] txt += [''] if 'add_args' in MyDriver: @@ -1337,56 +1350,51 @@ def put_postamble(MyDriver): line = 'proc add_%s {name IP port} {' % MyDriver['name'] txt += [line] txt += [' set catch_status [ catch {'] - txt += [' set ns "%s"' % MyDriver['namespace']] if 'make_args' in MyDriver: make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()]) - txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port} %s"' % (MyDriver['name'], make_args)] + txt += [' %s::sics_log 9 "add_%s ${name} ${IP} ${port} %s"' % (MyDriver['namespace'], MyDriver['name'], make_args)] else: - txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port}"' % MyDriver['name']] + txt += [' %s::sics_log 9 "add_%s ${name} ${IP} ${port}"' % (MyDriver['namespace'], MyDriver['name'])] txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']] txt += [' if {[string equal -nocase "aqadapter" "${IP}"]} {'] - txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} aqadapter ${port}"'] + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} aqadapter ${port}"' % MyDriver['namespace']] txt += [' makesctcontroller sct_${name} aqadapter ${port}'] txt += [' } else {'] if 'protocol_args' in MyDriver: protocol_args = MyDriver['protocol_args'].replace('\\', '\\\\').replace('"', '\\"') - txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} %s ${IP}:${port} %s"' % (MyDriver['protocol'], protocol_args)] + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${IP}:${port} %s"' % (MyDriver['namespace'], MyDriver['protocol'], protocol_args)] txt += [' makesctcontroller sct_${name} %s ${IP}:${port} %s' % (MyDriver['protocol'], MyDriver['protocol_args'])] else: - txt += [' ${ns}::debug_log 1 "makesctcontroller sct_${name} %s ${IP}:${port}"' % MyDriver['protocol']] + txt += [' %s::sics_log 9 "makesctcontroller sct_${name} %s ${IP}:${port}"' % (MyDriver['namespace'], MyDriver['protocol'])] txt += [' makesctcontroller sct_${name} %s ${IP}:${port}' % MyDriver['protocol']] txt += [' }'] txt += [' }'] if 'make_args' in MyDriver: make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()]) - txt += [' ${ns}::debug_log 1 "mk_sct_%s sct_${name} ${name} %s"' % (MyDriver['name'], make_args)] - txt += [' ${ns}::mk_sct_%s sct_${name} ${name} %s' % (MyDriver['name'], make_args)] + txt += [' %s::sics_log 1 "%s::mkDriver sct_${name} ${name} %s"' % (MyDriver['namespace'], MyDriver['namespace'], make_args)] + txt += [' %s::mkDriver sct_${name} ${name} %s' % (MyDriver['namespace'], make_args)] else: - txt += [' ${ns}::debug_log 1 "mk_sct_%s sct_${name} ${name}"' % MyDriver['name']] - txt += [' ${ns}::mk_sct_%s sct_${name} ${name}' % MyDriver['name']] + txt += [' %s::sics_log 1 "%s::mkDriver sct_${name} ${name}"' % (MyDriver['namespace'], MyDriver['namespace'])] + txt += [' %s::mkDriver sct_${name} ${name}' % (MyDriver['namespace'])] # TODO -#txt += [' ${ns}::debug_log 1 "makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler"'] +#txt += [' %s::sics_log "makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler"' % (MyDriver['namespace'])] # txt += [' makesctemon ${name} /sics/${name}/emon/monmode /sics/${name}/emon/isintol /sics/${name}/emon/errhandler'] txt += [' } catch_message ]'] txt += [' handle_exception ${catch_status} ${catch_message}'] txt += ['}'] txt += [''] txt += ['puts stdout "file evaluation of sct_%s.tcl"' % MyDriver['name']] - txt += ['%s::debug_log 1 "file evaluation of sct_%s.tcl"' % (MyDriver['namespace'], MyDriver['name'])] + txt += ['%s::sics_log 9 "file evaluation of sct_%s.tcl"' % (MyDriver['namespace'], MyDriver['name'])] emit(txt) -def put_config(MyDriver): +def put_read_config(MyDriver): txt = [''] txt += ['proc %s::read_config {} {' % MyDriver['namespace']] txt += [' set catch_status [ catch {'] txt += [' set ns "%s"' % MyDriver['namespace']] - txt += [' ${ns}::debug_log 1 "Processing Config"'] txt += [' dict for {k v} $::config_dict {'] - txt += [' ${ns}::debug_log 1 "Inspecting $k:$v"'] txt += [' if { [dict exists $v "driver"] } {'] - txt += [' ${ns}::debug_log 1 "Has driver [dict get $v driver]"'] txt += [' if { [dict get $v "driver"] == "%s" } {' % MyDriver['name']] - txt += [' ${ns}::debug_log 1 "Correct driver, enabled = [dict get $v enabled]"'] txt += [' if { [dict get $v enabled] } {'] txt += [' set IP [dict get $v ip]'] txt += [' set PORT [dict get $v port]'] @@ -1416,12 +1424,10 @@ def put_config(MyDriver): txt += [' if {[dict exists $v $arg]} {'] txt += [' lappend arg_list "[dict get $v $arg]"'] txt += [' } else {'] - txt += [' ${ns}::debug_log 1 "Missing configuration value $arg"'] + txt += [' ${ns}::sics_log 9 "Missing configuration value $arg"'] txt += [' error "Missing configuration value $arg"'] txt += [' }'] txt += [' }'] - txt += [' ${ns}::debug_log 1 "arg_list = $arg_list"'] - txt += [' ${ns}::debug_log 1 "add_%s ${name} aqadapter ${asyncqueue} $arg_list"' % MyDriver['name']] txt += [' add_%s ${name} "aqadapter" ${asyncqueue} {*}$arg_list' % MyDriver['name']] else: txt += [' add_%s ${name} "aqadapter" ${asyncqueue}' % MyDriver['name']] @@ -1432,10 +1438,14 @@ def put_config(MyDriver): txt += [' } catch_message ]'] txt += [' handle_exception ${catch_status} ${catch_message}'] txt += ['}'] + emit(txt) + +def put_check_config(MyDriver): + txt = [''] txt += ['if { [info exists ::config_dict] } {'] txt += [' %s::read_config' % MyDriver['namespace']] txt += ['} else {'] - txt += [' %s:debug_log 1 "No config dict"' % MyDriver['namespace']] + txt += [' %s::sics_log 5 "No config dict"' % MyDriver['namespace']] txt += ['}'] emit(txt) @@ -1475,9 +1485,10 @@ def generate_driver(MyDriver): fdo = open(full_filename, 'w') put_preamble(MyDriver) put_standard_code(MyDriver) - put_mk_sct_driver(MyDriver) + put_mkDriver(MyDriver) put_postamble(MyDriver) - put_config(MyDriver) + put_read_config(MyDriver) + put_check_config(MyDriver) fdo.close() if CodeDump or Verbose: print "Code Fragments:", MyDriver['Funcs'] @@ -1519,6 +1530,7 @@ def process_source(source_files): # # Build the parser # + #yaccer = yacc.yacc(tabmodule="gen_sct",outputdir="/tmp",write_tables=0,debug=0) yaccer = yacc.yacc() for source_file in source_files: