Exemplo n.º 1
0
    def _read_cbf_output_link(self):
        """Get the CBF output link map from the CSP subarray device.

        This provides the map of FSP to channels needed to construct
        the receive address map.

        :return: Channel link map string as read from CSP.

        """
        LOG.debug('Reading cbfOutputLink attribute ...')
        attribute_fqdn = self._config.get('cspCbfOutlinkAddress', None)
        if attribute_fqdn is None:
            msg = "'cspCbfOutlinkAddress' not found in PB configuration"
            self._set_obs_state(ObsState.FAULT, verbose=False)
            self._raise_command_error(msg)
        LOG.debug('Reading cbfOutLink from: %s', attribute_fqdn)
        attribute_proxy = AttributeProxy(attribute_fqdn)
        attribute_proxy.ping()
        LOG.debug('Waiting for cbfOutputLink to provide config for scanId: %s',
                  self._scanId)
        cbf_out_link_dict = {}
        start_time = time.time()
        # FIXME(BMo) Horrible hack to poll the CSP device until the scanID \
        # matches - use events instead!!
        cbf_out_link = ''
        while cbf_out_link_dict.get('scanId') != self._scanId:
            cbf_out_link = attribute_proxy.read().value
            cbf_out_link_dict = json.loads(cbf_out_link)
            time.sleep(1.0)
            elapsed = time.time() - start_time
            LOG.debug('Waiting for cbfOutputLink attribute (elapsed: %2.4f s) '
                      ': %s', elapsed, cbf_out_link)
            if elapsed >= 20.0:
                self._set_obs_state(ObsState.FAULT, verbose=False)
                self._raise_command_error(
                    'Timeout reached while reading cbf output link!')
                break
        # event_id = attribute_proxy.subscribe_event(
        #     tango.EventType.CHANGE_EVENT,
        #     self._cbf_output_link_callback
        # )
        # self._events_telstate[event_id] = attribute_proxy
        # print(attribute_proxy.is_event_queue_empty())
        # events = attribute_proxy.get_events()
        LOG.debug('Channel link map (str): "%s"', cbf_out_link)
        return cbf_out_link
Exemplo n.º 2
0
    def _get_channel_link_map(self, scan_id, timeout=30.0):
        """Get channel link map from the CSP Tango device attribute.

        :param scan_id: Scan ID to match
        :param timeout: Timeout in seconds
        :returns: Validated channel link map as dict

        """
        LOG.debug('Reading channel link map from %s',
                  self._cbf_outlink_address)
        attribute_proxy = AttributeProxy(self._cbf_outlink_address)
        attribute_proxy.ping()

        LOG.debug(
            'Waiting for CSP attribute to provide channel link map for '
            'scan ID %s', scan_id)
        # This is a horrendous hack to poll the CSP device until the scan
        # ID matches. It needs to refactored to use events.
        start_time = time.time()
        while True:
            channel_link_map_str = attribute_proxy.read().value
            channel_link_map = self._validate_json_config(
                channel_link_map_str, 'channel_link_map.json')
            if channel_link_map is None:
                self._set_obs_state(ObsState.FAULT)
                self._raise_command_error('Channel link map validation '
                                          'failed')
                break
            if channel_link_map.get('scanID') == scan_id:
                break
            elapsed = time.time() - start_time
            LOG.debug(
                'Waiting for scan ID on CSP attribute '
                '(elapsed: %2.4f s)', elapsed)
            if elapsed > timeout:
                self._set_obs_state(ObsState.FAULT)
                self._raise_command_error('Timeout reached while waiting for '
                                          'scan ID on CSP attribute')
                channel_link_map = None
                break
            time.sleep(1.0)

        return channel_link_map