Implement driver, group and variable attributes/properties
This commit is contained in:
@ -66,7 +66,8 @@ DriverDump = 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',
|
||||
'DEVICE' : 'DEVICE',
|
||||
'PROTOCOL' : 'PROTOCOL',
|
||||
'DRIVER_PROPERTY' : 'DRIVER_PROPERTY',
|
||||
'CLASS' : 'CLASS',
|
||||
'SIMULATION_GROUP' : 'SIMULATION_GROUP',
|
||||
'CODE' : 'CODE',
|
||||
@ -88,8 +90,10 @@ reserved = {
|
||||
'USECREATENODE' : 'USECREATENODE',
|
||||
# Group keywords
|
||||
'GROUP' : 'GROUP',
|
||||
'GROUP_PROPERTY' : 'GROUP_PROPERTY',
|
||||
# Variable keywords
|
||||
'VAR' : 'VAR',
|
||||
'PROPERTY' : 'PROPERTY',
|
||||
'CONTROL' : 'CONTROL',
|
||||
'DATA' : 'DATA',
|
||||
'NXSAVE' : 'NXSAVE',
|
||||
@ -256,6 +260,7 @@ def p_driver_statement(p):
|
||||
'''driver_statement : driver_assignment
|
||||
| group
|
||||
| code
|
||||
| driver_property
|
||||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
@ -301,12 +306,14 @@ def p_group_statement_list(p):
|
||||
|
||||
def p_group_statement(p):
|
||||
'''group_statement : group_assignment
|
||||
| variable
|
||||
| variable
|
||||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
def p_group_assignment(p):
|
||||
'''group_assignment : var_typ_ass
|
||||
'''group_assignment : group_property
|
||||
| var_typ_ass
|
||||
| property
|
||||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
@ -335,6 +342,7 @@ def p_variable_statement_list(p):
|
||||
def p_variable_statement(p):
|
||||
'''variable_statement : var_typ_ass
|
||||
| var_val_ass
|
||||
| property
|
||||
'''
|
||||
p[0] = p[1]
|
||||
|
||||
@ -385,6 +393,32 @@ def p_var_val_ass(p):
|
||||
'''
|
||||
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):
|
||||
'''
|
||||
number : INTEGER
|
||||
@ -525,18 +559,30 @@ def build_variable(MyDriver, p):
|
||||
if Verbose:
|
||||
print 'Variable:', p
|
||||
MyVar = {}
|
||||
# Copy items for this variable
|
||||
for item in p:
|
||||
if Verbose:
|
||||
print "Variable Item:", item
|
||||
for key in item.keys():
|
||||
MyVar[key] = item[key]
|
||||
if key == 'Property':
|
||||
if not 'Property' in MyVar:
|
||||
MyVar['Property'] = {}
|
||||
MyVar['Property'][item[key][0]] = item[key][1]
|
||||
else:
|
||||
MyVar[key] = item[key]
|
||||
# copy the defaults for missing items
|
||||
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]
|
||||
# if this variable is driveable
|
||||
if 'driveable' in MyVar and MyVar['driveable']:
|
||||
if not 'driveable' in MyDriver:
|
||||
MyDriver['driveable'] = 'true'
|
||||
# defaults for driveable functions
|
||||
# insert defaults for missing driveable functions
|
||||
if 'checklimits_function' not in MyVar:
|
||||
MyVar['checklimits_function'] = 'checklimits'
|
||||
if 'checkstatus_function' not in MyVar:
|
||||
@ -586,10 +632,22 @@ def build_group(MyDriver, p):
|
||||
else:
|
||||
if Verbose:
|
||||
print "Group Item:", item
|
||||
for key in item:
|
||||
MyGroup[key] = item[key]
|
||||
if key in ContextStack[ContextIndex]:
|
||||
ContextStack[ContextIndex][key] = item[key]
|
||||
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:
|
||||
MyGroup[key] = item[key]
|
||||
if key in ContextStack[ContextIndex]:
|
||||
ContextStack[ContextIndex][key] = item[key]
|
||||
pop_context()
|
||||
return MyGroup
|
||||
|
||||
@ -611,8 +669,11 @@ def build_driver(MyDriver, TheTree):
|
||||
elif 'Code' in item:
|
||||
continue
|
||||
else:
|
||||
if Verbose:
|
||||
print "Driver Item:", item
|
||||
if 'DriverProperty' in item:
|
||||
if 'DriverProperty' not in MyDriver:
|
||||
MyDriver['DriverProperty'] = {}
|
||||
MyDriver['DriverProperty'][item['DriverProperty'][0]] = item['DriverProperty'][1]
|
||||
continue
|
||||
for key in item:
|
||||
MyDriver[key] = item[key]
|
||||
if Verbose:
|
||||
@ -1035,6 +1096,9 @@ def put_group(MyDriver, MyGroup):
|
||||
if MyGroup['name']:
|
||||
txt += ['']
|
||||
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'] + '/'
|
||||
else:
|
||||
groupname = ''
|
||||
@ -1110,6 +1174,14 @@ def put_group(MyDriver, MyGroup):
|
||||
txt += [' hsetprop ${scobj_hpath}/%s oldval 0.0' % nodename]
|
||||
else:
|
||||
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:
|
||||
txt += ['']
|
||||
txt += [' if {[SplitReply [%s]]=="false"} {' % MyDriver['simulation_group']]
|
||||
@ -1146,6 +1218,9 @@ def put_mk_sct_driver(MyDriver):
|
||||
txt += ['']
|
||||
txt += [' sicslist setatt ${name} klass %s' % MyDriver['class']]
|
||||
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 += [' set scobj_hpath /sics/${name}']
|
||||
if UsingCreateNode:
|
||||
@ -1277,12 +1352,6 @@ def put_standard_code(MyDriver):
|
||||
elif theFunc['type'] == 'halt_function':
|
||||
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):
|
||||
global NumberOfLinesOut
|
||||
global fdo
|
||||
@ -1293,8 +1362,6 @@ def generate_driver(MyDriver):
|
||||
fdo = open(full_filename, 'w')
|
||||
put_preamble(MyDriver)
|
||||
put_standard_code(MyDriver)
|
||||
if 'driveable' in MyDriver:
|
||||
put_driveable_code(MyDriver)
|
||||
if UsingCreateNode:
|
||||
put_create_node(MyDriver)
|
||||
put_mk_sct_driver(MyDriver)
|
||||
|
Reference in New Issue
Block a user