def get_instance(self, capability, *args, **kwargs):
        '''
        Search in the discovered plugins for a capability and return an instance to it

        Args:
            capability (str or int): Capability name or id to search

        Returns:
            any: Capability instance

        Raises:
            ValueError: If unable to find capability
        '''
        if capability in self._plugins:  # search by name (interface)
            operator = self._plugins[capability][PLUGIN_CLASS](capability,
                                                               self._kymera,
                                                               *args, **kwargs)
        else:  # search by cap_id
            for cap in self._plugins:
                if self._plugins[cap][PLUGIN_CAP_ID] == capability:
                    operator = self._plugins[cap][PLUGIN_CLASS](cap,
                                                                self._kymera,
                                                                *args,
                                                                **kwargs)
                    break
            else:  # not in registered caps, use generic
                operator = CapabilityGeneric(capability, self._kymera, *args,
                                             **kwargs)

        register_instance('operator', operator)
        register_instance('operator_' + str(operator.cap_id), operator)
        return operator
Beispiel #2
0
    def create(self):
        '''
        Start service and create stream

        TODO: If stream_type of a SCO Processing Service instance is easily available,
        raise a RuntimeError if we are trying to start two instances with the same
        stream_type and hci_handle.
        '''
        if self.__config.stream is not None:
            stream = get_instance('stream_sco')
            if stream.get_type() == self.get_type():
                raise RuntimeError('trying to start two sco streams of same type')
            self.__data.sco_service = stream.get_sco_service()
        else:
            if self.__config.service_tag is not None:
                service_tag = self.__config.service_tag
            else:
                service_tag = get_instance_num('sco_processing_service') + 100

            self.__data.sco_service = HydraScoProcessingService(service_tag=service_tag,
                                                                **self._sco_kwargs)
            register_instance('sco_processing_service', self.__data.sco_service)
            self.__data.sco_service.start()
            self.__data.sco_service.config()

        return super(StreamHydraSco, self).create()
Beispiel #3
0
    def get_instance(self, interface, stream_type, *args, **kwargs):
        '''
        Search in the discovered plugins for an stream interface and return an instance of it

        Args:
            interface (str): Stream interface
            stream_type (str): Stream type name

        Returns:
            any: Stream instance

        Raises:
            ValueError: If unable to find stream interface
        '''
        if interface in self._plugins:
            stream = self._plugins[interface][PLUGIN_CLASS](stream_type, *args,
                                                            **kwargs)
            register_instance('stream_' + interface, stream)
            return stream
        raise ValueError('unable to find stream interface:%s' % (interface))
Beispiel #4
0
    def create(self):
        if self.__config.service_tag is not None:
            service_tag = self.__config.service_tag
        else:
            service_tag = get_instance_num('hydra_service') + 1

        md_buffer_size = self.__config.metadata_buffer_size * self.__config.metadata_enable
        md_length = METADATA_HEADER_LENGTH[
            self.__config.metadata_format] - METADATA_BASE_LENGTH

        if self._stream_type == STREAM_TYPE_SOURCE:
            callback = None
            if (self.__config.backing == BACKING_FILE
                    and self.__config.sample_rate == 0
                    and not self.__data.source_packetiser):
                callback = self._space_available
            self.__helper.audio_hydra = HydraAudioSink(
                self.__helper.hydra_prot,
                device_type=self.__config.device_type,
                service_tag=service_tag,
                data_buffer_size=self.__config.data_buffer_size,
                metadata_buffer_size=md_buffer_size,
                metadata_header_length=md_length,
                space_handler=callback)
            self.__helper.audio_hydra.start()
        else:
            self.__helper.audio_hydra = HydraAudioSource(
                self.__helper.hydra_prot,
                device_type=self.__config.device_type,
                service_tag=service_tag,
                data_buffer_size=self.__config.data_buffer_size,
                metadata_buffer_size=md_buffer_size,
                metadata_header_length=md_length,
                space_handler=self._space_available)
            self.__helper.audio_hydra.start()
        register_instance('hydra_service', self.__helper.audio_hydra)

        if self.__config.metadata_enable:
            self.__data.stream2.create()

        return super(StreamHydraAudioData, self).create()
Beispiel #5
0
    def get_instance(self, interface, endpoint_type, *args, **kwargs):
        '''
        Search in the discovered plugins for an endpoint interface and return an instance of it

        Args:
            interface (str): Endpoint interface
            endpoint_type (str): Endpoint type name

        Returns:
            any: Endpoint instance

        Raises:
            ValueError: If unable to find endpoint interface
        '''
        if interface in self._plugins:  # search by name (interface)
            endpoint = self._plugins[interface][PLUGIN_CLASS](self._kymera,
                                                              endpoint_type,
                                                              *args, **kwargs)
            register_instance('endpoint', endpoint)
            register_instance('endpoint_' + interface, endpoint)
            return endpoint
        raise ValueError('unable to find endpoint interface:%s' % (interface))
Beispiel #6
0
    def initialise(self):
        '''
        Initialise kalsim shell environment

        This includes launching the selected combination of kalcmd, kalsim and kalaccess
        components and starting several middleware components as uut, stream, kymera, endpoint
        and capability handlers
        '''
        print('Initialising')

        if self._param.debug:
            set_config_param('KALCMD_LOCK_TIMEOUT', KALCMD_LOCK_TIMEOUT_DEBUG)
            set_config_param('UUT_MESSAGE_RECEIVE_TIMEOUT', UUT_MESSAGE_RECEIVE_TIMEOUT_DEBUG)
        if DEBUG_SESSION:
            set_config_param('UUT_MESSAGE_RECEIVE_TIMEOUT', UUT_MESSAGE_RECEIVE_TIMEOUT_DEBUG)

        self._instr.kalsim = None
        if self._config.kalsim:
            self._instr.kalsim = Kalsim(**self._config.kalsim)

        self._instr.kalaccess = None
        if self._config.kalaccess:
            from kats.instrument.kalaccess.kalaccess import Kalaccess
            self._instr.kalaccess = Kalaccess(**self._config.kalaccess)

        self._instr.kalcmd = Kalcmd(**self._config.kalcmd)
        register_instance('kalcmd', self._instr.kalcmd)

        if self._param.debug and self._param.kalaccess_skip:
            print(
                'Initialisation will not be completed until an external kalaccess session is connected and run issued')

        # kalcmd is smart enough to spawn kalsim and kalaccess in its connect method
        self._instr.kalcmd.connect(self._instr.kalsim, self._instr.kalaccess)

        print('Kalcmd connected to a %s' % (self._instr.kalcmd.get_kalimba_name()))

        self._instr.acat = None
        if self._config.acat:
            from kats.instrument.acat.acat import Acat
            self._instr.acat = Acat(**self._config.acat)
            self._instr.acat.connect()

        cap = load_capability_file(self._param.capability_description)
        register_instance('capability_description', cap)

        # load all the middleware that will be available in the repl
        platforms = ['common', 'kalsim', self._param.platform]
        self.helper.uut = uut_get_instance(platforms, self._instr.kalcmd)
        register_instance('uut', self.helper.uut)

        self.helper.kalcmd_stream = KalcmdStream(self._instr.kalcmd)
        register_instance('kalcmd_stream', self.helper.kalcmd_stream)
        self.helper.stream = StreamFactory(platforms, self._instr.kalcmd)
        register_instance('stream', self.helper.stream)

        self.helper.kymera = kymera_get_instance(platforms, self.helper.uut)
        self.helper.endpoint = EndpointFactory(platforms, self.helper.kymera, ENDPOINT_PATH)
        self.helper.capability = CapabilityFactory(platforms, self.helper.kymera)
        self.helper.graph = Graph(self.helper.stream,
                                  self.helper.endpoint,
                                  self.helper.capability,
                                  None,
                                  self.helper.kymera,
                                  None)

        if self._param.platform in [PLATFORM_CRESCENDO, PLATFORM_STRE, PLATFORM_STREPLUS,
                                    PLATFORM_MORA]:
            self.helper.accmd = self.helper.kymera._accmd  # pylint: disable = protected-access
            register_instance('accmd', self.helper.accmd)

            from kats.kalsim.hydra_service.protocol import HydraProtocol
            self.helper.hydra_protocol = HydraProtocol(self.helper.uut)
            register_instance('hydra_protocol', self.helper.hydra_protocol)

            from kats.kalsim.hydra_service.download_service import HydraCapabilityDownloadService
            self.helper.hydra_cap_download = HydraCapabilityDownloadService(
                self.helper.stream, self.helper.accmd, self.helper.hydra_protocol,
                service_tag=1000)
            register_instance('hydra_cap_download', self.helper.hydra_cap_download)

            if self._param.license_manager_use:
                from kats.kalsim.component.license_manager import LicenseManager
                config = {
                    'filename': self._param.license_manager_filename,
                }
                self.helper.license_manager = LicenseManager(self.helper.hydra_protocol, **config)
                register_instance('license_manager', self.helper.license_manager)

            if not self._param.hydra_ftp_server_skip:
                from kats.kalsim.component.hydra_ftp_server import HydraFtpServer
                config = {
                    'directory': self._param.hydra_ftp_server_directory,
                    'prefix': self._param.hydra_ftp_server_prefix,
                }
                self.helper.hydra_ftp_server = HydraFtpServer(self.helper.hydra_protocol, **config)
                register_instance('hydra_ftp_server', self.helper.hydra_ftp_server)

            if self._param.pstore_use:
                from kats.kalsim.component.pstore import PStore
                config = {
                    'filename': self._param.pstore_filename,
                }
                self.helper.ps_store = PStore(**config)
                register_instance('pstore', self.helper.ps_store)

        self._namespace = {
            'uut': self.helper.uut,
            'kymera': self.helper.kymera,
            'endpoint': self.helper.endpoint,
            'capability': self.helper.capability,
            'stream': self.helper.stream,
            'graph': self.helper.graph,
            'kalcmd': self._instr.kalcmd,
            'reset': self.reset,
            'khelp': self.help
        }
        if self._instr.kalaccess:
            self._namespace['kal'] = self._instr.kalaccess.get_kal_access()
        if self._instr.acat:
            self._namespace['acat'] = self._instr.acat.get_session()
        if vars(self.helper).get('hydra_protocol', None):
            self._namespace['hydra_protocol'] = vars(self.helper)['hydra_protocol']
        if vars(self.helper).get('hydra_cap_download', None):
            self._namespace['hydra_cap_download'] = vars(self.helper)['hydra_cap_download']