Add 'permlink' code to generated drivers

This commit is contained in:
Douglas Clowes
2014-04-14 14:09:30 +10:00
parent 3869b55380
commit 53d6274e7d

View File

@ -95,6 +95,7 @@ reserved = {
'READABLE' : 'READABLE', 'READABLE' : 'READABLE',
'WRITEABLE' : 'WRITEABLE', 'WRITEABLE' : 'WRITEABLE',
'DRIVEABLE' : 'DRIVEABLE', 'DRIVEABLE' : 'DRIVEABLE',
'PERMLINK' : 'PERMLINK',
'TRUE' : 'TRUE', 'TRUE' : 'TRUE',
'FALSE' : 'FALSE', 'FALSE' : 'FALSE',
# Data Types # Data Types
@ -391,6 +392,7 @@ def p_var_val_ass(p):
| LOWERLIMIT EQUALS value | LOWERLIMIT EQUALS value
| UPPERLIMIT EQUALS value | UPPERLIMIT EQUALS value
| TOLERANCE EQUALS value | TOLERANCE EQUALS value
| PERMLINK EQUALS text_string
| DRIVEABLE EQUALS var_path | DRIVEABLE EQUALS var_path
''' '''
p[0] = { p[1] : p[3] } p[0] = { p[1] : p[3] }
@ -510,6 +512,16 @@ def p_empty(p):
def p_error(t): def p_error(t):
print("Syntax error at '%s'" % t.value), t print("Syntax error at '%s'" % t.value), t
#
# Utility functions
#
def make_path(MyVar):
path = MyVar['path']
if len(path) > 0:
path = path.replace('/', '_')
path += '_' + MyVar['name']
return path
# #
# This section handles building a driver tree from the Abstract Syntax Tree # This section handles building a driver tree from the Abstract Syntax Tree
# generated by the parser. The driver tree has all of the defaults and # generated by the parser. The driver tree has all of the defaults and
@ -623,6 +635,11 @@ def build_variable(MyDriver, p):
# TODO FIXME error message # TODO FIXME error message
print 'Error: Function type mismatch: var = ' + str(MyVar) + ', code = ' + str(MyDriver['Funcs'][MyVar[func]]) + ', func = ' + str(func) print 'Error: Function type mismatch: var = ' + str(MyVar) + ', code = ' + str(MyDriver['Funcs'][MyVar[func]]) + ', func = ' + str(func)
MyDriver['Funcs'][MyVar[func]]['reference_count'] += 1 MyDriver['Funcs'][MyVar[func]]['reference_count'] += 1
if 'permlink' in MyVar:
device_type, node_type = MyVar['permlink'].split('.')
if node_type not in MyDriver['Permlink']:
MyDriver['Permlink'][node_type] = [];
MyDriver['Permlink'][node_type] += [make_path(MyVar)];
if Verbose: if Verbose:
print '==>>MyVar:', MyVar print '==>>MyVar:', MyVar
return MyVar return MyVar
@ -695,6 +712,9 @@ def build_driver(MyDriver, TheTree):
continue continue
for key in item: for key in item:
MyDriver[key] = item[key] MyDriver[key] = item[key]
for item in MyDriver['Permlink']:
if len(MyDriver['Permlink'][item]) > 1:
print 'Error: duplicate permlink entries for "%s"' % item, MyDriver['Permlink'][item]
if Verbose: if Verbose:
print "MyDriver:", MyDriver print "MyDriver:", MyDriver
# #
@ -763,6 +783,13 @@ def put_preamble(MyDriver):
txt += [''] txt += ['']
txt += ['namespace eval %s {' % MyDriver['namespace']] txt += ['namespace eval %s {' % MyDriver['namespace']]
txt += [' set debug_threshold 0'] txt += [' set debug_threshold 0']
if len(MyDriver['Permlink']) > 0:
if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split():
pass
else:
txt += [' if { ![info exists ::scobj::permlink_device_counter]} {']
txt += [' set ::scobj::permlink_device_counter 0']
txt += [' }']
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']]
@ -1148,6 +1175,20 @@ def put_group(MyDriver, MyGroup):
txt += [' hsetprop ${scobj_hpath}/%s units %s' % (nodename, MyVar['units'])] txt += [' hsetprop ${scobj_hpath}/%s units %s' % (nodename, MyVar['units'])]
if 'allowed' in MyVar: if 'allowed' in MyVar:
txt += [' hsetprop ${scobj_hpath}/%s values %s' % (nodename, MyVar['allowed'])] txt += [' hsetprop ${scobj_hpath}/%s values %s' % (nodename, MyVar['allowed'])]
if 'permlink' in MyVar:
device_type, node_type = MyVar['permlink'].split('.')
if device_type.startswith("#"):
if 'make_args' in MyDriver and 'permlink' in MyDriver['make_args'].split():
idx = int(device_type[1:])
device_type = '[string index ${permlink} %d]' % idx
else:
print 'Error: permlink required in make_ags'
if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split():
permlink = device_type + '[format "%02d" ${id}]' + node_type
else:
permlink = device_type + '${permlink_device_number}' + node_type
txt += [' hsetprop ${scobj_hpath}/%s permlink data_set "%s"' % (nodename, permlink)]
txt += [' hsetprop ${scobj_hpath}/%s @description "%s"' % (nodename, permlink)]
if 'value' in MyVar: if 'value' in MyVar:
txt += [' hsetprop ${scobj_hpath}/%s oldval %s' % (nodename, MyVar['value'])] txt += [' hsetprop ${scobj_hpath}/%s oldval %s' % (nodename, MyVar['value'])]
txt += [' hset ${scobj_hpath}/%s %s' % (nodename, MyVar['value'])] txt += [' hset ${scobj_hpath}/%s %s' % (nodename, MyVar['value'])]
@ -1162,14 +1203,9 @@ def put_group(MyDriver, MyGroup):
txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename] txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename]
for key in sorted(MyVar['Property']): for key in sorted(MyVar['Property']):
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (nodename, key, MyVar['Property'][key])] txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (nodename, key, MyVar['Property'][key])]
# Generated at runtime <dev>_<group...>_<name> for nxalias and driveable # Generate <dev>_<group...>_<name> at runtime for nxalias
path = MyVar['path']
if len(path) > 0:
path = path.replace('/', '_') + '_'
path += MyVar['name']
#print "Path: %s" % MyVar['path']
nxalias = '${name}_' + path
if 'nxalias' not in MyVar['Property']: if 'nxalias' not in MyVar['Property']:
nxalias = '${name}_' + make_path(MyVar)
txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)] txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)]
if not MyGroup['name']: if not MyGroup['name']:
if 'GroupProperty' in MyGroup: if 'GroupProperty' in MyGroup:
@ -1193,7 +1229,9 @@ def put_group(MyDriver, MyGroup):
if MyVar['writeable'] > 0 or MyVar['driveable']: if MyVar['writeable'] > 0 or MyVar['driveable']:
txt += [' ${sct_controller} write ${scobj_hpath}/%s' % nodename] txt += [' ${sct_controller} write ${scobj_hpath}/%s' % nodename]
if MyVar['driveable']: if MyVar['driveable']:
txt += [' ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (nxalias, nodename, MyVar['driveable'])] # Generate <dev>_<group...>_<name> at runtime for driveable
driveable = '${name}_' + make_path(MyVar)
txt += [' ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (driveable, nodename, MyVar['driveable'])]
txt += [' }'] txt += [' }']
for grp in sorted(MyGroup['Groups']): for grp in sorted(MyGroup['Groups']):
txt += put_group(MyDriver, MyGroup['Groups'][grp]) txt += put_group(MyDriver, MyGroup['Groups'][grp])
@ -1207,17 +1245,19 @@ def put_mk_sct_driver(MyDriver):
line = 'proc %s::mk_sct_%s { sct_controller name } {' % (MyDriver['namespace'], MyDriver['name']) line = 'proc %s::mk_sct_%s { sct_controller name } {' % (MyDriver['namespace'], MyDriver['name'])
txt += [line] txt += [line]
if 'make_args' in MyDriver: if 'make_args' in MyDriver:
make_args = '' make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()])
for arg in MyDriver['make_args'].split():
if len(make_args) > 0:
make_args += ' '
make_args += '${' + arg + '}'
txt += [' debug_log 1 "mk_sct_%s ${sct_controller} ${name} %s"' % (MyDriver['name'], make_args)] txt += [' debug_log 1 "mk_sct_%s ${sct_controller} ${name} %s"' % (MyDriver['name'], make_args)]
else: else:
txt += [' debug_log 1 "mk_sct_%s for ${name}"' % MyDriver['name']] txt += [' debug_log 1 "mk_sct_%s for ${name}"' % MyDriver['name']]
txt += [' set ns "[namespace current]"'] txt += [' set ns "[namespace current]"']
txt += [' set catch_status [ catch {'] txt += [' set catch_status [ catch {']
txt += [''] txt += ['']
if len(MyDriver['Permlink']) > 0:
if 'make_args' in MyDriver and 'id' in MyDriver['make_args'].split():
pass
else:
txt += [' set permlink_device_number [format "%02d" [incr ::scobj::permlink_device_counter]]']
txt += ['']
txt += [' MakeSICSObj ${name} SCT_OBJECT'] txt += [' MakeSICSObj ${name} SCT_OBJECT']
txt += [''] txt += ['']
txt += [' sicslist setatt ${name} klass %s' % MyDriver['class']] txt += [' sicslist setatt ${name} klass %s' % MyDriver['class']]
@ -1258,11 +1298,7 @@ def put_postamble(MyDriver):
txt += [' set catch_status [ catch {'] txt += [' set catch_status [ catch {']
txt += [' set ns "%s"' % MyDriver['namespace']] txt += [' set ns "%s"' % MyDriver['namespace']]
if 'make_args' in MyDriver: if 'make_args' in MyDriver:
make_args = '' make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()])
for arg in MyDriver['make_args'].split():
if len(make_args) > 0:
make_args += ' '
make_args += '${' + arg + '}'
txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port} %s"' % (MyDriver['name'], make_args)] txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port} %s"' % (MyDriver['name'], make_args)]
else: else:
txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port}"' % MyDriver['name']] txt += [' ${ns}::debug_log 1 "add_%s ${name} ${IP} ${port}"' % MyDriver['name']]
@ -1281,11 +1317,7 @@ def put_postamble(MyDriver):
txt += [' }'] txt += [' }']
txt += [' }'] txt += [' }']
if 'make_args' in MyDriver: if 'make_args' in MyDriver:
make_args = '' make_args = ' '.join(["${%s}"%arg for arg in MyDriver['make_args'].split()])
for arg in MyDriver['make_args'].split():
if len(make_args) > 0:
make_args += ' '
make_args += '${' + arg + '}'
txt += [' ${ns}::debug_log 1 "mk_sct_%s sct_${name} ${name} %s"' % (MyDriver['name'], make_args)] 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 += [' ${ns}::mk_sct_%s sct_${name} ${name} %s' % (MyDriver['name'], make_args)]
else: else:
@ -1405,6 +1437,7 @@ def process_drivers(TheDrivers):
MyDriver['namespace'] = '::scobj::%s' % driver MyDriver['namespace'] = '::scobj::%s' % driver
MyDriver['Groups'] = {} MyDriver['Groups'] = {}
MyDriver['Funcs'] = {} MyDriver['Funcs'] = {}
MyDriver['Permlink'] = {}
build_driver(MyDriver, TheDrivers[driver]) build_driver(MyDriver, TheDrivers[driver])
if Verbose: if Verbose:
print "MyDriver:", MyDriver['name'], '=', MyDriver print "MyDriver:", MyDriver['name'], '=', MyDriver