Refactor put_var processing for gen_sct
This commit is contained in:
@ -1308,22 +1308,15 @@ def put_pid_function(MyDriver, func):
|
||||
txt += ['}']
|
||||
emit(txt)
|
||||
|
||||
def put_group(MyDriver, MyGroup):
|
||||
def put_var(MyDriver, MyGroup, MyVar):
|
||||
readable_or_writeable = False
|
||||
txt = []
|
||||
txt = ['']
|
||||
postfix = []
|
||||
if MyGroup['name']:
|
||||
txt += ['']
|
||||
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'] + '/'
|
||||
nodename = MyGroup['path'] + '/' + MyVar['name']
|
||||
else:
|
||||
groupname = ''
|
||||
for var in sorted(MyGroup['Vars']):
|
||||
txt += ['']
|
||||
MyVar = MyGroup['Vars'][var]
|
||||
nodename = groupname + MyVar['name']
|
||||
nodename = MyVar['name']
|
||||
|
||||
# Check driveable attributes are present if required
|
||||
if 'driveable' in MyVar and MyVar['driveable']:
|
||||
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)
|
||||
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
|
||||
@ -1430,17 +1424,10 @@ def put_group(MyDriver, MyGroup):
|
||||
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:
|
||||
txt += ['']
|
||||
for key in sorted(MyGroup['GroupProperty']):
|
||||
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:
|
||||
@ -1448,20 +1435,49 @@ def put_group(MyDriver, MyGroup):
|
||||
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'])]
|
||||
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 = []
|
||||
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']):
|
||||
txt += put_group(MyDriver, MyGroup['Groups'][grp])
|
||||
|
||||
txt += dfr
|
||||
|
||||
return txt
|
||||
|
||||
def put_mkDriver(MyDriver):
|
||||
|
Reference in New Issue
Block a user