Commit 7437f886 authored by Jose Tiago Macara Coutinho's avatar Jose Tiago Macara Coutinho Committed by blissadm_ID31@bibhelm
Browse files

SPEC config: add fuelcell

parent c6cb0f75
......@@ -1293,6 +1293,81 @@ class Generator(object):
self.__spec_macros.add('kellergauge.mac')
self.__spec_macros.add('gasrig2.mac')
####################
# Fuel cell
####################
def add_fuelcell(self, session_name, name, config_name):
config = self.config.get_config(config_name)
if 'spec' in config:
return self.__add_fuelcell_full(session_name, name)
# don't add the individual channel if the entire fuelcell is to be added
fuelcell_name = config.parent.get_inherited('name')
session_config = self.config.get_config(session_name)
if fuelcell_name not in session_config['config-objects']:
return self.__add_fuelcell_channel(session_name, config)
else:
self._log.info('skipping %r because entire fuelcell %r is going ' \
'to be added', config_name, fuelcell_name)
def __get_fuelcell(self, name):
# 1. for now only support tango serial since it is a modbus tango device
config = self.config.get_config(name)
spec = config.get('spec', None)
tango_type = 'FuelCell'
server = self.__tango_servers.get('{0}/{1}'.format(tango_type, name))
if server is None:
server_host = spec.get(SERVER_HOST_KEY)
fuelcell_dev = '{0}/fuelcell/{1}'.format(self.beamline, name)
dev = TDevice('FuelCell', fuelcell_dev)
dev['properties'] = dict(name=name)
server = TServer(tango_type, name, server_host, [dev])
# cheat a bit: put in tango server info needed by spec...
server.fuelcell = fuelcell_dev
server.counter_ctrl = None
self.__tango_servers[server['server']] = server
self.__spec_setup.append('fcsetup {0}'.format(fuelcell_dev))
return server
def __add_fuelcell_channel(self, session_name, config):
# add the given fuelcell channel to spec setup and add a counter(s)
# (if appropriate)
fuelcell_name = config.parent.get_inherited('name')
fuelcell_config = self.config.get_config(fuelcell_name)
name = self.get_spec_object_name(session_name, config.get('name'))
if fuelcell_config.get_inherited('spec_config') != 'fuelcell':
raise ValueError('fuelcell where channel {0!r} is must have a name'
.format(name))
server = self.__get_fuelcell(fuelcell_name)
self._log.debug('adding fuelcell channel %r to fuelcell %r',
name, fuelcell_name)
counter_ctrl = server.counter_ctrl
if counter_ctrl is None:
counter_ctrl = Device(ltype='PSE_MAC_C', addr='attr_ct', num=0,
conf=server.fuelcell)
self.spec_config.addDevice(counter_ctrl)
server.counter_ctrl = counter_ctrl
unit = counter_ctrl.getCtrlIndex()
counter = Counter(ctrl='MAC_CNT', unit=unit, chan=counter_ctrl.num,
mne=name, name=name)
counter.addPar('CNTPAR:attr_name = {0}'.format(config['channel']))
self.spec_config.addCounter(counter)
counter_ctrl.addChannel(counter.chan)
self.__spec_macros.add('fuelcell.mac')
def __add_fuelcell_full(self, session_name, name):
self._log.debug('adding full fuelcell %r from %s', name, session_name)
server = self.__get_fuelcell(name)
config = self.config.get_config(name)
spec = config.get('spec', None)
if spec:
items = spec.get('items', ())
for item in items:
self.__add_fuelcell_channel(session_name, item)
def add_xia(self, session_name, name, config_name):
device_name = '{0}/xia/{1}'.format(self.beamline, name)
self.__spec_setup.append('xiasetup {0}'.format(device_name))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment