Ejemplo n.º 1
0
def run(device_name='muse',
        mock_data_enabled=True,
        device_id=MOCK_DEVICE_ID,
        cloudbrain_address=RABBITMQ_ADDRESS,
        buffer_size=10,
        device_port='/dev/tty.OpenBCI-DN0094CZ',
        pipe_name=None,
        publisher_type="pika",
        device_mac=None):

    if device_name == 'muse':
        from cloudbrain.connectors.MuseConnector import MuseConnector as Connector
    elif device_name == 'openbci':
        from cloudbrain.connectors.OpenBCIConnector import OpenBCIConnector as Connector
    else:
        raise ValueError("Device type '%s' not supported. "
                         "Supported devices are:%s" % (device_name, _SUPPORTED_DEVICES))

    if mock_data_enabled:
        from cloudbrain.connectors.MockConnector import MockConnector as Connector

    metrics = get_metrics_names(device_name)

    if publisher_type == 'pika':
        publishers = {metric: PikaPublisher(device_name,
                                            device_id,
                                            cloudbrain_address,
                                            metric) for metric in metrics}
    elif publisher_type == 'pipe':
        publishers = {metric: PipePublisher(device_name,
                                            device_id,
                                            metric,
                                            pipe_name) for metric in metrics}
    else:
        raise ValueError("'%s' is not a valid publisher type. "
                         "Valid types are %s." % (publisher_type, "pika, pipe"))

    for publisher in publishers.values():
        publisher.connect()
    if device_name == 'openbci':
        connector = Connector(publishers, buffer_size, device_name, device_port, device_mac)
    else:
        connector = Connector(publishers, buffer_size, device_name, 9090, device_mac)
    connector.connect_device()

    if mock_data_enabled and (publisher_type != 'pipe'):
        print "INFO: Mock data enabled."

    if publisher_type == 'pika':
        print ("SUCCESS: device '%s' connected with ID '%s'\n"
               "Sending data to cloudbrain at address '%s' ...") % (device_name,
                                                                    device_id,
                                                                    cloudbrain_address)
    connector.start()
Ejemplo n.º 2
0
def run(device_name="muse",
        mock_data_enabled=True,
        device_id=MOCK_DEVICE_ID,
        cloudbrain_address=RABBITMQ_ADDRESS,
        buffer_size=10, step_size=10,
        device_port=None,
        pipe_name=None,
        publisher_type="pika",
        device_mac=None):

    if device_name == "muse" and not mock_data_enabled:
        from cloudbrain.connectors.MuseConnector import MuseConnector as Connector
        if not device_port:
            device_port = 9090
    elif device_name in ["openbci","openbci16"] and not mock_data_enabled:
        from lib.connectors.OpenBCIConnector import OpenBCIConnector as Connector
    else:
        raise ValueError("Device type '%s' not supported. "
                         "Supported devices are:%s" % (device_name, _SUPPORTED_DEVICES))


    metrics = get_metrics_names(device_name)

    if publisher_type == "pika":
        publishers = {metric: PikaPublisher(device_name,
                                            device_id,
                                            cloudbrain_address,
                                            metric) for metric in metrics}
    elif publisher_type == "pipe":
        publishers = {metric: PipePublisher(device_name,
                                            device_id,
                                            metric,
                                            pipe_name) for metric in metrics}
    else:
        raise ValueError("'%s' is not a valid publisher type. "
                         "Valid types are %s." % (publisher_type, "pika, pipe"))

    for publisher in publishers.values():
        publisher.connect()
    connector = Connector(publishers, buffer_size, step_size, device_name, device_port, device_mac)
    connector.connect_device()

    if mock_data_enabled and (publisher_type != 'pipe'):
        print "INFO: Mock data enabled."

    if publisher_type == 'pika':
        print ("SUCCESS: device '%s' connected with ID '%s'\n"
               "Sending data to cloudbrain at address '%s' ...") % (device_name,
                                                                    device_id,
                                                                    cloudbrain_address)

    try:
        connector.start()
    except KeyboardInterrupt:
        print "CTRL-C: interrupt received, stopping execution"
    finally:
        # clean up
        connector.disconnect()
        print "Connection closed"
        print "Bye"
Ejemplo n.º 3
0
def run(device_name='muse',
        mock_data_enabled=True,
        device_id=MOCK_DEVICE_ID,
        cloudbrain_address=RABBITMQ_ADDRESS,
        buffer_size=10,
        device_port='/dev/tty.OpenBCI-DN0094CZ'):
    if device_name == 'muse':
        from cloudbrain.connectors.MuseConnector import MuseConnector as Connector
    elif device_name == 'openbci':
        from cloudbrain.connectors.OpenBCIConnector import OpenBCIConnector as Connector
    else:
        raise Exception(
            "Device type '%s' not supported. Supported devices are:%s" %
            (device_name, _SUPPORTED_DEVICES))

    if mock_data_enabled:
        from cloudbrain.connectors.MockConnector import MockConnector as Connector

    metrics = get_metrics_names(device_name)
    publishers = {
        metric: Publisher(device_name, device_id, cloudbrain_address, metric)
        for metric in metrics
    }
    for publisher in publishers.values():
        publisher.connect()
    if device_name == 'openbci':
        connector = Connector(publishers, buffer_size, device_name,
                              device_port)
    else:
        connector = Connector(publishers, buffer_size, device_name)
    connector.connect_device()

    if mock_data_enabled:
        print "INFO: Mock data enabled."
    print(
        "SUCCESS: device '%s' connected with ID '%s'\n"
        "Sending data to cloudbrain at address '%s' ...") % (
            device_name, device_id, cloudbrain_address)
    connector.start()
Ejemplo n.º 4
0
    def run(self):

        if self.module_settings[
                'device_name'] == "muse" and not self.module_settings[
                    'mock_data_enabled']:
            from cloudbrain.connectors.MuseConnector import MuseConnector as Connector
            if not self.module_settings['device_port']:
                device_port = 9090
        elif self.module_settings['device_name'] in [
                "openbci", "openbci16"
        ] and not self.module_settings['mock_data_enabled']:
            from lib.connectors.OpenBCIConnector import OpenBCIConnector as Connector
        else:
            raise ValueError(
                "Device type '%s' not supported. "
                "Supported devices are:%s" %
                (self.module_settings['device_name'], _SUPPORTED_DEVICES))

        metrics = get_metrics_names(self.device_name)

        if self.module_settings['publisher_type'] == "pika":
            publishers = {
                metric:
                PikaPublisher(self.module_settings['device_name'],
                              self.module_settings['device_id'],
                              self.module_settings['cloudbrain_address'],
                              metric)
                for metric in metrics
            }
        elif self.module_settings['publisher_type'] == "pipe":
            publishers = {
                metric:
                PipePublisher(self.module_settings['device_name'],
                              self.module_settings['device_id'], metric,
                              self.module_settings['pipe_name'])
                for metric in metrics
            }
        else:
            raise ValueError(
                "'%s' is not a valid publisher type. "
                "Valid types are %s." %
                (self.module_settings['publisher_type'], "pika, pipe"))

        for publisher in publishers.values():
            publisher.connect()

        connector = Connector(publishers, self.module_settings['buffer_size'],
                              self.module_settings['step_size'],
                              self.module_settings['device_name'],
                              self.module_settings['device_port'],
                              self.module_settings['device_mac'])
        connector.connect_device()

        if self.module_settings['mock_data_enabled'] and (self.publisher_type
                                                          != 'pipe'):
            print "INFO: Mock data enabled."

        if self.publisher_type == 'pika':
            print(
                "SUCCESS: device '%s' connected with ID '%s'\n"
                "Sending data to cloudbrain at address '%s' ...") % (
                    self.module_settings['device_name'],
                    self.module_settings['device_id'],
                    self.module_settings['cloudbrain_address'])

        try:
            connector.start()
        except KeyboardInterrupt:
            print "CTRL-C: interrupt received, stopping execution"
        finally:
            # clean up
            connector.disconnect()
            print "Connection closed"
            print "Bye"