Refactor put_var processing for gen_sct
This commit is contained in:
@ -1308,160 +1308,176 @@ def put_pid_function(MyDriver, func):
|
|||||||
txt += ['}']
|
txt += ['}']
|
||||||
emit(txt)
|
emit(txt)
|
||||||
|
|
||||||
def put_group(MyDriver, MyGroup):
|
def put_var(MyDriver, MyGroup, MyVar):
|
||||||
readable_or_writeable = False
|
readable_or_writeable = False
|
||||||
|
txt = ['']
|
||||||
|
postfix = []
|
||||||
|
if MyGroup['name']:
|
||||||
|
nodename = MyGroup['path'] + '/' + MyVar['name']
|
||||||
|
else:
|
||||||
|
nodename = MyVar['name']
|
||||||
|
|
||||||
|
# Check driveable attributes are present if required
|
||||||
|
if 'driveable' in MyVar and MyVar['driveable']:
|
||||||
|
for attr in ('lowerlimit', 'upperlimit', 'tolerance'):
|
||||||
|
if attr not in MyVar:
|
||||||
|
msg = 'Driveable: %s does not have required attribute: %s' % (nodename, attr)
|
||||||
|
print 'Warning:', msg
|
||||||
|
txt += [' # Warning: ' + msg]
|
||||||
|
# Check PID attributes are present if required
|
||||||
|
if 'pid_function' in MyVar:
|
||||||
|
for attr in ('pid_pvalue',
|
||||||
|
'pid_ivalue',
|
||||||
|
'pid_dvalue',
|
||||||
|
'pid_imax',
|
||||||
|
'pid_error',
|
||||||
|
'pid_deriv',
|
||||||
|
'pid_integ',
|
||||||
|
):
|
||||||
|
if attr not in MyVar['Property']:
|
||||||
|
msg = 'PID: %s does not have required attribute: %s' % (nodename, attr)
|
||||||
|
print 'Warning:', msg
|
||||||
|
txt += [' # Warning: ' + msg]
|
||||||
|
|
||||||
|
txt += [' hfactory ${scobj_hpath}/%s plain %s %s' % (nodename, MyVar['priv'], MyVar['type'])]
|
||||||
|
if MyVar['readable'] > 0:
|
||||||
|
readable_or_writeable = True
|
||||||
|
fetch_func = MyVar['fetch_function']
|
||||||
|
if fetch_func == 'none':
|
||||||
|
fetch_func = 'getValue'
|
||||||
|
read_func = MyVar['read_function']
|
||||||
|
if 'read_command' in MyVar:
|
||||||
|
read_command = MyVar['read_command']
|
||||||
|
else:
|
||||||
|
read_command = ''
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s read ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, fetch_func, read_func, read_command)]
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, read_func, read_func)]
|
||||||
|
if MyVar['writeable'] > 0 or MyVar['driveable']:
|
||||||
|
readable_or_writeable = True
|
||||||
|
check_func = MyVar['check_function']
|
||||||
|
checkrange_func = MyVar['checkrange_function']
|
||||||
|
write_func = MyVar['write_function']
|
||||||
|
if 'write_command' in MyVar:
|
||||||
|
write_command = MyVar['write_command']
|
||||||
|
else:
|
||||||
|
write_command = ''
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s write ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, write_func, check_func, write_command)]
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, check_func, check_func)]
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s check ${ns}::%s ${scobj_hpath}' % (nodename, checkrange_func)]
|
||||||
|
if MyVar['driveable']:
|
||||||
|
halt_func = MyVar['halt_function']
|
||||||
|
checklimits_func = MyVar['checklimits_function']
|
||||||
|
checkstatus_func = MyVar['checkstatus_function']
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s driving 0' % nodename]
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s checklimits ${ns}::%s ${scobj_hpath}' % (nodename, checklimits_func)]
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s checkstatus ${ns}::%s ${scobj_hpath}' % (nodename, checkstatus_func)]
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s halt ${ns}::%s ${scobj_hpath}' % (nodename, halt_func)]
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s driveable %s' % (nodename, MyVar['driveable'])]
|
||||||
|
if 'control' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s control %s' % (nodename, MyVar['control'])]
|
||||||
|
if 'data' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s data %s' % (nodename, MyVar['data'])]
|
||||||
|
if 'mutable' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s mutable %s' % (nodename, MyVar['mutable'])]
|
||||||
|
if 'nxsave' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s nxsave %s' % (nodename, MyVar['nxsave'])]
|
||||||
|
if 'lowerlimit' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s lowerlimit %s' % (nodename, MyVar['lowerlimit'])]
|
||||||
|
if 'upperlimit' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s upperlimit %s' % (nodename, MyVar['upperlimit'])]
|
||||||
|
if 'tolerance' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s tolerance %s' % (nodename, MyVar['tolerance'])]
|
||||||
|
if 'units' in MyVar:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s units %s' % (nodename, MyVar['units'])]
|
||||||
|
if 'allowed' in MyVar:
|
||||||
|
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:
|
||||||
|
message = 'Error: permlink required in make_ags'
|
||||||
|
PrintPostError(message)
|
||||||
|
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:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s oldval %s' % (nodename, MyVar['value'])]
|
||||||
|
txt += [' hset ${scobj_hpath}/%s %s' % (nodename, MyVar['value'])]
|
||||||
|
else:
|
||||||
|
if MyVar['type'] == 'none':
|
||||||
|
pass
|
||||||
|
elif MyVar['type'] == 'int':
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s oldval 0' % nodename]
|
||||||
|
elif MyVar['type'] == 'float':
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s oldval 0.0' % nodename]
|
||||||
|
else:
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename]
|
||||||
|
for key in sorted(MyVar['Property']):
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (nodename, key, MyVar['Property'][key])]
|
||||||
|
# Generate <dev>_<group...>_<name> at runtime for nxalias
|
||||||
|
if 'nxalias' not in MyVar['Property']:
|
||||||
|
nxalias = '${name}_' + make_path(MyVar)
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)]
|
||||||
|
|
||||||
|
if readable_or_writeable:
|
||||||
|
txt += ['']
|
||||||
|
txt += [' if {[string equal -nocase "${simulation_flag}" "false"]} {']
|
||||||
|
if MyVar['readable'] > 0:
|
||||||
|
poll_period = MyVar['readable']
|
||||||
|
if poll_period < 1:
|
||||||
|
poll_period = 1
|
||||||
|
if poll_period > 3600:
|
||||||
|
poll_period = 3600
|
||||||
|
txt += [' ${sct_controller} poll ${scobj_hpath}/%s %s' % (nodename, poll_period)]
|
||||||
|
if MyVar['writeable'] > 0 or MyVar['driveable']:
|
||||||
|
txt += [' ${sct_controller} write ${scobj_hpath}/%s' % nodename]
|
||||||
|
if MyVar['driveable']:
|
||||||
|
# Generate <dev>_<group...>_<name> at runtime for driveable
|
||||||
|
driveable = '${name}_' + make_path(MyVar)
|
||||||
|
postfix += [' ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (driveable, nodename, MyVar['driveable'])]
|
||||||
|
txt += [' } else {']
|
||||||
|
txt += [' %s::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for %s"' % (MyDriver['namespace'], MyDriver['name'])]
|
||||||
|
txt += [' }']
|
||||||
|
|
||||||
|
return (txt, postfix)
|
||||||
|
|
||||||
|
def put_group(MyDriver, MyGroup):
|
||||||
txt = []
|
txt = []
|
||||||
|
dfr = []
|
||||||
if MyGroup['name']:
|
if MyGroup['name']:
|
||||||
txt += ['']
|
txt += ['']
|
||||||
txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['path']]
|
txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['path']]
|
||||||
if 'GroupProperty' in MyGroup:
|
|
||||||
for key in sorted(MyGroup['GroupProperty']):
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['path'], key, MyGroup['GroupProperty'][key])]
|
|
||||||
groupname = MyGroup['path'] + '/'
|
|
||||||
else:
|
else:
|
||||||
groupname = ''
|
pass
|
||||||
|
|
||||||
for var in sorted(MyGroup['Vars']):
|
for var in sorted(MyGroup['Vars']):
|
||||||
txt += ['']
|
txt += ['']
|
||||||
MyVar = MyGroup['Vars'][var]
|
MyVar = MyGroup['Vars'][var]
|
||||||
nodename = groupname + MyVar['name']
|
infix, postfix = put_var(MyDriver, MyGroup, MyVar)
|
||||||
# Check driveable attributes are present if required
|
txt += infix
|
||||||
if 'driveable' in MyVar and MyVar['driveable']:
|
dfr += postfix
|
||||||
for attr in ('lowerlimit', 'upperlimit', 'tolerance'):
|
|
||||||
if attr not in MyVar:
|
if MyGroup['name']:
|
||||||
msg = 'Driveable: %s does not have required attribute: %s' % (nodename, attr)
|
if 'GroupProperty' in MyGroup:
|
||||||
print 'Warning:', msg
|
for key in sorted(MyGroup['GroupProperty']):
|
||||||
txt += [' # Warning: ' + msg]
|
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['path'], key, MyGroup['GroupProperty'][key])]
|
||||||
# Check PID attributes are present if required
|
else:
|
||||||
if 'pid_function' in MyVar:
|
|
||||||
for attr in ('pid_pvalue',
|
|
||||||
'pid_ivalue',
|
|
||||||
'pid_dvalue',
|
|
||||||
'pid_imax',
|
|
||||||
'pid_error',
|
|
||||||
'pid_deriv',
|
|
||||||
'pid_integ',
|
|
||||||
):
|
|
||||||
if attr not in MyVar['Property']:
|
|
||||||
msg = 'PID: %s does not have required attribute: %s' % (nodename, attr)
|
|
||||||
print 'Warning:', msg
|
|
||||||
txt += [' # Warning: ' + msg]
|
|
||||||
txt += [' hfactory ${scobj_hpath}/%s plain %s %s' % (nodename, MyVar['priv'], MyVar['type'])]
|
|
||||||
if MyVar['readable'] > 0:
|
|
||||||
readable_or_writeable = True
|
|
||||||
fetch_func = MyVar['fetch_function']
|
|
||||||
if fetch_func == 'none':
|
|
||||||
fetch_func = 'getValue'
|
|
||||||
read_func = MyVar['read_function']
|
|
||||||
if 'read_command' in MyVar:
|
|
||||||
read_command = MyVar['read_command']
|
|
||||||
else:
|
|
||||||
read_command = ''
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s read ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, fetch_func, read_func, read_command)]
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, read_func, read_func)]
|
|
||||||
if MyVar['writeable'] > 0 or MyVar['driveable']:
|
|
||||||
readable_or_writeable = True
|
|
||||||
check_func = MyVar['check_function']
|
|
||||||
checkrange_func = MyVar['checkrange_function']
|
|
||||||
write_func = MyVar['write_function']
|
|
||||||
if 'write_command' in MyVar:
|
|
||||||
write_command = MyVar['write_command']
|
|
||||||
else:
|
|
||||||
write_command = ''
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s write ${ns}::%s ${scobj_hpath} %s {%s}' % (nodename, write_func, check_func, write_command)]
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s %s ${ns}::%s ${scobj_hpath}' % (nodename, check_func, check_func)]
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s check ${ns}::%s ${scobj_hpath}' % (nodename, checkrange_func)]
|
|
||||||
if MyVar['driveable']:
|
|
||||||
halt_func = MyVar['halt_function']
|
|
||||||
checklimits_func = MyVar['checklimits_function']
|
|
||||||
checkstatus_func = MyVar['checkstatus_function']
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s driving 0' % nodename]
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s checklimits ${ns}::%s ${scobj_hpath}' % (nodename, checklimits_func)]
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s checkstatus ${ns}::%s ${scobj_hpath}' % (nodename, checkstatus_func)]
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s halt ${ns}::%s ${scobj_hpath}' % (nodename, halt_func)]
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s driveable %s' % (nodename, MyVar['driveable'])]
|
|
||||||
if 'control' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s control %s' % (nodename, MyVar['control'])]
|
|
||||||
if 'data' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s data %s' % (nodename, MyVar['data'])]
|
|
||||||
if 'mutable' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s mutable %s' % (nodename, MyVar['mutable'])]
|
|
||||||
if 'nxsave' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s nxsave %s' % (nodename, MyVar['nxsave'])]
|
|
||||||
if 'lowerlimit' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s lowerlimit %s' % (nodename, MyVar['lowerlimit'])]
|
|
||||||
if 'upperlimit' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s upperlimit %s' % (nodename, MyVar['upperlimit'])]
|
|
||||||
if 'tolerance' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s tolerance %s' % (nodename, MyVar['tolerance'])]
|
|
||||||
if 'units' in MyVar:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s units %s' % (nodename, MyVar['units'])]
|
|
||||||
if 'allowed' in MyVar:
|
|
||||||
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:
|
|
||||||
message = 'Error: permlink required in make_ags'
|
|
||||||
PrintPostError(message)
|
|
||||||
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:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s oldval %s' % (nodename, MyVar['value'])]
|
|
||||||
txt += [' hset ${scobj_hpath}/%s %s' % (nodename, MyVar['value'])]
|
|
||||||
else:
|
|
||||||
if MyVar['type'] == 'none':
|
|
||||||
pass
|
|
||||||
elif MyVar['type'] == 'int':
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s oldval 0' % nodename]
|
|
||||||
elif MyVar['type'] == 'float':
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s oldval 0.0' % nodename]
|
|
||||||
else:
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s oldval UNKNOWN' % nodename]
|
|
||||||
for key in sorted(MyVar['Property']):
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (nodename, key, MyVar['Property'][key])]
|
|
||||||
# Generate <dev>_<group...>_<name> at runtime for nxalias
|
|
||||||
if 'nxalias' not in MyVar['Property']:
|
|
||||||
nxalias = '${name}_' + make_path(MyVar)
|
|
||||||
txt += [' hsetprop ${scobj_hpath}/%s nxalias "%s"' % (nodename, nxalias)]
|
|
||||||
if not MyGroup['name']:
|
|
||||||
if 'GroupProperty' in MyGroup:
|
if 'GroupProperty' in MyGroup:
|
||||||
txt += ['']
|
txt += ['']
|
||||||
for key in sorted(MyGroup['GroupProperty']):
|
for key in sorted(MyGroup['GroupProperty']):
|
||||||
txt += [' hsetprop ${scobj_hpath} %s "%s"' % (key, MyGroup['GroupProperty'][key])]
|
txt += [' hsetprop ${scobj_hpath} %s "%s"' % (key, MyGroup['GroupProperty'][key])]
|
||||||
if readable_or_writeable:
|
|
||||||
txt += ['']
|
|
||||||
txt += [' if {[string equal -nocase "${simulation_flag}" "false"]} {']
|
|
||||||
for var in sorted(MyGroup['Vars']):
|
|
||||||
MyVar = MyGroup['Vars'][var]
|
|
||||||
nodename = groupname + MyVar['name']
|
|
||||||
if MyVar['readable'] > 0:
|
|
||||||
poll_period = MyVar['readable']
|
|
||||||
if poll_period < 1:
|
|
||||||
poll_period = 1
|
|
||||||
if poll_period > 3600:
|
|
||||||
poll_period = 3600
|
|
||||||
txt += [' ${sct_controller} poll ${scobj_hpath}/%s %s' % (nodename, poll_period)]
|
|
||||||
for var in sorted(MyGroup['Vars']):
|
|
||||||
MyVar = MyGroup['Vars'][var]
|
|
||||||
nodename = groupname + MyVar['name']
|
|
||||||
if MyVar['writeable'] > 0 or MyVar['driveable']:
|
|
||||||
txt += [' ${sct_controller} write ${scobj_hpath}/%s' % nodename]
|
|
||||||
if MyVar['driveable']:
|
|
||||||
# Generate <dev>_<group...>_<name> at runtime for driveable
|
|
||||||
driveable = '${name}_' + make_path(MyVar)
|
|
||||||
MyDriver['Deferred'] += ['ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (driveable, nodename, MyVar['driveable'])]
|
|
||||||
txt += [' } else {']
|
|
||||||
txt += [' %s::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for %s"' % (MyDriver['namespace'], MyDriver['name'])]
|
|
||||||
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])
|
||||||
|
|
||||||
|
txt += dfr
|
||||||
|
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
def put_mkDriver(MyDriver):
|
def put_mkDriver(MyDriver):
|
||||||
|
Reference in New Issue
Block a user