Implement driver, group and variable attributes/properties

This commit is contained in:
Douglas Clowes
2014-02-07 11:50:53 +11:00
parent 115965fbae
commit 7f99daaf05

View File

@ -66,7 +66,8 @@ DriverDump = False
CodeDump = False CodeDump = False
# #
# Tokenizer # Tokenizer: This recognizes the tokens which can be keywords, identifiers,
# numbers or strings plus the punctuation.
# #
# #
@ -79,6 +80,7 @@ reserved = {
'VENDOR' : 'VENDOR', 'VENDOR' : 'VENDOR',
'DEVICE' : 'DEVICE', 'DEVICE' : 'DEVICE',
'PROTOCOL' : 'PROTOCOL', 'PROTOCOL' : 'PROTOCOL',
'DRIVER_PROPERTY' : 'DRIVER_PROPERTY',
'CLASS' : 'CLASS', 'CLASS' : 'CLASS',
'SIMULATION_GROUP' : 'SIMULATION_GROUP', 'SIMULATION_GROUP' : 'SIMULATION_GROUP',
'CODE' : 'CODE', 'CODE' : 'CODE',
@ -88,8 +90,10 @@ reserved = {
'USECREATENODE' : 'USECREATENODE', 'USECREATENODE' : 'USECREATENODE',
# Group keywords # Group keywords
'GROUP' : 'GROUP', 'GROUP' : 'GROUP',
'GROUP_PROPERTY' : 'GROUP_PROPERTY',
# Variable keywords # Variable keywords
'VAR' : 'VAR', 'VAR' : 'VAR',
'PROPERTY' : 'PROPERTY',
'CONTROL' : 'CONTROL', 'CONTROL' : 'CONTROL',
'DATA' : 'DATA', 'DATA' : 'DATA',
'NXSAVE' : 'NXSAVE', 'NXSAVE' : 'NXSAVE',
@ -256,6 +260,7 @@ def p_driver_statement(p):
'''driver_statement : driver_assignment '''driver_statement : driver_assignment
| group | group
| code | code
| driver_property
''' '''
p[0] = p[1] p[0] = p[1]
@ -306,7 +311,9 @@ def p_group_statement(p):
p[0] = p[1] p[0] = p[1]
def p_group_assignment(p): def p_group_assignment(p):
'''group_assignment : var_typ_ass '''group_assignment : group_property
| var_typ_ass
| property
''' '''
p[0] = p[1] p[0] = p[1]
@ -335,6 +342,7 @@ def p_variable_statement_list(p):
def p_variable_statement(p): def p_variable_statement(p):
'''variable_statement : var_typ_ass '''variable_statement : var_typ_ass
| var_val_ass | var_val_ass
| property
''' '''
p[0] = p[1] p[0] = p[1]
@ -385,6 +393,32 @@ def p_var_val_ass(p):
''' '''
p[0] = { p[1] : p[3] } p[0] = { p[1] : p[3] }
def p_driver_property(p):
'''
driver_property : DRIVER_PROPERTY id_or_str EQUALS value
'''
p[0] = { 'DriverProperty' : ( p[2], p[4] ) }
def p_group_property(p):
'''
group_property : GROUP_PROPERTY id_or_str EQUALS value
'''
p[0] = { 'GroupProperty' : ( p[2], p[4] ) }
def p_property(p):
'''
property : PROPERTY id_or_str EQUALS value
'''
p[0] = { 'Property' : ( p[2], p[4] ) }
def p_value(p):
'''
value : number
| id_or_str
| true_false
'''
p[0] = p[1]
def p_number(p): def p_number(p):
''' '''
number : INTEGER number : INTEGER
@ -525,18 +559,30 @@ def build_variable(MyDriver, p):
if Verbose: if Verbose:
print 'Variable:', p print 'Variable:', p
MyVar = {} MyVar = {}
# Copy items for this variable
for item in p: for item in p:
if Verbose: if Verbose:
print "Variable Item:", item print "Variable Item:", item
for key in item.keys(): for key in item.keys():
if key == 'Property':
if not 'Property' in MyVar:
MyVar['Property'] = {}
MyVar['Property'][item[key][0]] = item[key][1]
else:
MyVar[key] = item[key] MyVar[key] = item[key]
# copy the defaults for missing items
for key in ContextStack[ContextIndex]: for key in ContextStack[ContextIndex]:
if not key in MyVar: if key == 'Property':
if 'Property' not in MyVar:
MyVar['Property'] = {}
for key2 in ContextStack[ContextIndex][key]:
if key2 not in MyVar['Property']:
MyVar['Property'][key2] = ContextStack[ContextIndex][key][key2]
elif not key in MyVar:
MyVar[key] = ContextStack[ContextIndex][key] MyVar[key] = ContextStack[ContextIndex][key]
# if this variable is driveable
if 'driveable' in MyVar and MyVar['driveable']: if 'driveable' in MyVar and MyVar['driveable']:
if not 'driveable' in MyDriver: # insert defaults for missing driveable functions
MyDriver['driveable'] = 'true'
# defaults for driveable functions
if 'checklimits_function' not in MyVar: if 'checklimits_function' not in MyVar:
MyVar['checklimits_function'] = 'checklimits' MyVar['checklimits_function'] = 'checklimits'
if 'checkstatus_function' not in MyVar: if 'checkstatus_function' not in MyVar:
@ -586,6 +632,18 @@ def build_group(MyDriver, p):
else: else:
if Verbose: if Verbose:
print "Group Item:", item print "Group Item:", item
if 'GroupProperty' in item:
if 'GroupProperty' not in MyGroup:
MyGroup['GroupProperty'] = {}
MyGroup['GroupProperty'][item['GroupProperty'][0]] = item['GroupProperty'][1]
elif 'Property' in item:
if 'Property' not in MyGroup:
MyGroup['Property'] = {}
MyGroup['Property'][item['Property'][0]] = item['Property'][1]
if 'Property' not in ContextStack[ContextIndex]:
ContextStack[ContextIndex]['Property'] = {}
ContextStack[ContextIndex]['Property'][item['Property'][0]] = item['Property'][1]
else:
for key in item: for key in item:
MyGroup[key] = item[key] MyGroup[key] = item[key]
if key in ContextStack[ContextIndex]: if key in ContextStack[ContextIndex]:
@ -611,8 +669,11 @@ def build_driver(MyDriver, TheTree):
elif 'Code' in item: elif 'Code' in item:
continue continue
else: else:
if Verbose: if 'DriverProperty' in item:
print "Driver Item:", item if 'DriverProperty' not in MyDriver:
MyDriver['DriverProperty'] = {}
MyDriver['DriverProperty'][item['DriverProperty'][0]] = item['DriverProperty'][1]
continue
for key in item: for key in item:
MyDriver[key] = item[key] MyDriver[key] = item[key]
if Verbose: if Verbose:
@ -1035,6 +1096,9 @@ def put_group(MyDriver, MyGroup):
if MyGroup['name']: if MyGroup['name']:
txt += [''] txt += ['']
txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['name']] txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['name']]
if 'GroupProperty' in MyGroup:
for key in sorted(MyGroup['GroupProperty']):
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['name'], key, MyGroup['GroupProperty'][key])]
groupname = MyGroup['name'] + '/' groupname = MyGroup['name'] + '/'
else: else:
groupname = '' groupname = ''
@ -1110,6 +1174,14 @@ def put_group(MyDriver, MyGroup):
txt += [' hsetprop ${scobj_hpath}/%s oldval 0.0' % nodename] txt += [' hsetprop ${scobj_hpath}/%s oldval 0.0' % nodename]
else: else:
txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename] txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename]
if 'Property' in MyVar:
for key in sorted(MyVar['Property']):
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (nodename, key, MyVar['Property'][key])]
if not MyGroup['name']:
if 'GroupProperty' in MyGroup:
txt += ['']
for key in sorted(MyGroup['GroupProperty']):
txt += [' hsetprop ${scobj_hpath} %s "%s"' % (key, MyGroup['GroupProperty'][key])]
if readable_or_writeable: if readable_or_writeable:
txt += [''] txt += ['']
txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']] txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']]
@ -1146,6 +1218,9 @@ def put_mk_sct_driver(MyDriver):
txt += [''] txt += ['']
txt += [' sicslist setatt ${name} klass %s' % MyDriver['class']] txt += [' sicslist setatt ${name} klass %s' % MyDriver['class']]
txt += [' sicslist setatt ${name} long_name ${name}'] txt += [' sicslist setatt ${name} long_name ${name}']
if 'DriverProperty' in MyDriver:
for key in MyDriver['DriverProperty']:
txt += [' sicslist setatt ${name} %s "%s"' % (key, MyDriver['DriverProperty'][key])]
txt += [''] txt += ['']
txt += [' set scobj_hpath /sics/${name}'] txt += [' set scobj_hpath /sics/${name}']
if UsingCreateNode: if UsingCreateNode:
@ -1277,12 +1352,6 @@ def put_standard_code(MyDriver):
elif theFunc['type'] == 'halt_function': elif theFunc['type'] == 'halt_function':
put_halt_function(MyDriver, func); put_halt_function(MyDriver, func);
def put_driveable_code(MyDriver):
#put_checklimits_function(MyDriver, 'checklimits')
#put_checkstatus_function(MyDriver, 'checkhstatus')
#put_halt_function(MyDriver, 'halt')
pass
def generate_driver(MyDriver): def generate_driver(MyDriver):
global NumberOfLinesOut global NumberOfLinesOut
global fdo global fdo
@ -1293,8 +1362,6 @@ def generate_driver(MyDriver):
fdo = open(full_filename, 'w') fdo = open(full_filename, 'w')
put_preamble(MyDriver) put_preamble(MyDriver)
put_standard_code(MyDriver) put_standard_code(MyDriver)
if 'driveable' in MyDriver:
put_driveable_code(MyDriver)
if UsingCreateNode: if UsingCreateNode:
put_create_node(MyDriver) put_create_node(MyDriver)
put_mk_sct_driver(MyDriver) put_mk_sct_driver(MyDriver)