Refactor put_var processing for gen_sct
This commit is contained in:
@ -1308,22 +1308,15 @@ 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 = []
|
txt = ['']
|
||||||
|
postfix = []
|
||||||
if MyGroup['name']:
|
if MyGroup['name']:
|
||||||
txt += ['']
|
nodename = MyGroup['path'] + '/' + MyVar['name']
|
||||||
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 = ''
|
nodename = MyVar['name']
|
||||||
for var in sorted(MyGroup['Vars']):
|
|
||||||
txt += ['']
|
|
||||||
MyVar = MyGroup['Vars'][var]
|
|
||||||
nodename = groupname + MyVar['name']
|
|
||||||
# Check driveable attributes are present if required
|
# Check driveable attributes are present if required
|
||||||
if 'driveable' in MyVar and MyVar['driveable']:
|
if 'driveable' in MyVar and MyVar['driveable']:
|
||||||
for attr in ('lowerlimit', 'upperlimit', 'tolerance'):
|
for attr in ('lowerlimit', 'upperlimit', 'tolerance'):
|
||||||
@ -1345,6 +1338,7 @@ def put_group(MyDriver, MyGroup):
|
|||||||
msg = 'PID: %s does not have required attribute: %s' % (nodename, attr)
|
msg = 'PID: %s does not have required attribute: %s' % (nodename, attr)
|
||||||
print 'Warning:', msg
|
print 'Warning:', msg
|
||||||
txt += [' # Warning: ' + msg]
|
txt += [' # Warning: ' + msg]
|
||||||
|
|
||||||
txt += [' hfactory ${scobj_hpath}/%s plain %s %s' % (nodename, MyVar['priv'], MyVar['type'])]
|
txt += [' hfactory ${scobj_hpath}/%s plain %s %s' % (nodename, MyVar['priv'], MyVar['type'])]
|
||||||
if MyVar['readable'] > 0:
|
if MyVar['readable'] > 0:
|
||||||
readable_or_writeable = True
|
readable_or_writeable = True
|
||||||
@ -1430,17 +1424,10 @@ def put_group(MyDriver, MyGroup):
|
|||||||
if 'nxalias' not in MyVar['Property']:
|
if 'nxalias' not in MyVar['Property']:
|
||||||
nxalias = '${name}_' + make_path(MyVar)
|
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 '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 {[string equal -nocase "${simulation_flag}" "false"]} {']
|
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:
|
if MyVar['readable'] > 0:
|
||||||
poll_period = MyVar['readable']
|
poll_period = MyVar['readable']
|
||||||
if poll_period < 1:
|
if poll_period < 1:
|
||||||
@ -1448,20 +1435,49 @@ def put_group(MyDriver, MyGroup):
|
|||||||
if poll_period > 3600:
|
if poll_period > 3600:
|
||||||
poll_period = 3600
|
poll_period = 3600
|
||||||
txt += [' ${sct_controller} poll ${scobj_hpath}/%s %s' % (nodename, poll_period)]
|
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']:
|
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']:
|
||||||
# Generate <dev>_<group...>_<name> at runtime for driveable
|
# Generate <dev>_<group...>_<name> at runtime for driveable
|
||||||
driveable = '${name}_' + make_path(MyVar)
|
driveable = '${name}_' + make_path(MyVar)
|
||||||
MyDriver['Deferred'] += ['ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (driveable, nodename, MyVar['driveable'])]
|
postfix += [' ansto_makesctdrive %s ${scobj_hpath}/%s ${scobj_hpath}/%s ${sct_controller}' % (driveable, nodename, MyVar['driveable'])]
|
||||||
txt += [' } else {']
|
txt += [' } else {']
|
||||||
txt += [' %s::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for %s"' % (MyDriver['namespace'], MyDriver['name'])]
|
txt += [' %s::sics_log 9 "simulation_flag=${simulation_flag} => No poll/write for %s"' % (MyDriver['namespace'], MyDriver['name'])]
|
||||||
txt += [' }']
|
txt += [' }']
|
||||||
|
|
||||||
|
return (txt, postfix)
|
||||||
|
|
||||||
|
def put_group(MyDriver, MyGroup):
|
||||||
|
txt = []
|
||||||
|
dfr = []
|
||||||
|
if MyGroup['name']:
|
||||||
|
txt += ['']
|
||||||
|
txt += [' hfactory ${scobj_hpath}/%s plain spy none' % MyGroup['path']]
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
for var in sorted(MyGroup['Vars']):
|
||||||
|
txt += ['']
|
||||||
|
MyVar = MyGroup['Vars'][var]
|
||||||
|
infix, postfix = put_var(MyDriver, MyGroup, MyVar)
|
||||||
|
txt += infix
|
||||||
|
dfr += postfix
|
||||||
|
|
||||||
|
if MyGroup['name']:
|
||||||
|
if 'GroupProperty' in MyGroup:
|
||||||
|
for key in sorted(MyGroup['GroupProperty']):
|
||||||
|
txt += [' hsetprop ${scobj_hpath}/%s %s "%s"' % (MyGroup['path'], key, MyGroup['GroupProperty'][key])]
|
||||||
|
else:
|
||||||
|
if 'GroupProperty' in MyGroup:
|
||||||
|
txt += ['']
|
||||||
|
for key in sorted(MyGroup['GroupProperty']):
|
||||||
|
txt += [' hsetprop ${scobj_hpath} %s "%s"' % (key, MyGroup['GroupProperty'][key])]
|
||||||
|
|
||||||
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