diff --git a/site_ansto/instrument/util/gen_sct.py b/site_ansto/instrument/util/gen_sct.py index ced9a7e5..387b5d13 100755 --- a/site_ansto/instrument/util/gen_sct.py +++ b/site_ansto/instrument/util/gen_sct.py @@ -1302,6 +1302,53 @@ def put_postamble(MyDriver): txt += ['%s::debug_log 1 "file evaluation of sct_%s.tcl"' % (MyDriver['namespace'], MyDriver['name'])] emit(txt) +def put_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]'] + txt += [' set name [dict get $v name]'] + txt += [' MakeAsyncProtocol ${name}_protocol'] + txt += [' MakeAsyncQueue ${name}_queue ${name}_protocol ${IP} ${PORT}'] + if 'make_args' in MyDriver: + txt += [' set arg_list [list]'] + txt += [' foreach arg {' + MyDriver['make_args'] + '} {'] + 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 += [' 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 ${name}_queue $arg_list"' % MyDriver['name']] + txt += [' add_%s ${name} "aqadapter" ${name}_queue {*}$arg_list' % MyDriver['name']] + else: + txt += [' add_%s ${name} "aqadapter" ${name}_queue' % MyDriver['name']] + txt += [' }'] + txt += [' }'] + txt += [' }'] + txt += [' }'] + txt += [' } catch_message ]'] + txt += [' handle_exception ${catch_status} ${catch_message}'] + 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 += ['}'] + emit(txt) + def put_standard_code(MyDriver): # emit all of the functions in Funcs for func in sorted(MyDriver['Funcs']): @@ -1340,6 +1387,7 @@ def generate_driver(MyDriver): put_standard_code(MyDriver) put_mk_sct_driver(MyDriver) put_postamble(MyDriver) + put_config(MyDriver) fdo.close() if CodeDump or Verbose: print "Code Fragments:", MyDriver['Funcs']