Example #1
0
def EthernetControlPopulation(n_neurons,
                              model,
                              label=None,
                              local_host=None,
                              local_port=None,
                              database_notify_port_num=None,
                              database_ack_port_num=None):
    """ Create a PyNN population that can be included in a network to\
        control an external device which is connected to the host

    :param n_neurons: The number of neurons in the control population
    :param model:\
        Class of a model that creates a vertex of type\
        AbstractEthernetController
    :param label: An optional label for the population
    :param local_host:\
        The optional local host IP address to listen on for commands
    :param local_port: The optional local port to listen on for commands
    :param database_ack_port_num:\
        The optional port to which responses to the database notification\
        protocol are to be sent
    :param database_notify_port_num:\
        The optional port to which notifications from the database\
        notification protocol are to be sent
    :return:\
        A pyNN Population which can be used as the target of a Projection.\
        Note that the Population can also be used as the source of a\
        Projection, but it might not send spikes.
    """
    # pylint: disable=protected-access, too-many-arguments, too-many-locals
    population = Population(n_neurons, model, label=label)
    vertex = population._get_vertex
    if not isinstance(vertex, AbstractEthernetController):
        raise Exception(
            "Vertex must be an instance of AbstractEthernetController")
    translator = vertex.get_message_translator()
    ethernet_control_connection = EthernetControlConnection(
        translator, local_host, local_port)
    devices_with_commands = [
        device for device in vertex.get_external_devices()
        if isinstance(device, AbstractSendMeMulticastCommandsVertex)
    ]
    if devices_with_commands:
        ethernet_command_connection = EthernetCommandConnection(
            translator, devices_with_commands, local_host,
            database_notify_port_num)
        add_database_socket_address(
            ethernet_command_connection.local_ip_address,
            ethernet_command_connection.local_port, database_ack_port_num)
    live_packet_gather = LivePacketGather(
        ethernet_control_connection.local_ip_address,
        ethernet_control_connection.local_port,
        message_type=EIEIOType.KEY_PAYLOAD_32_BIT,
        payload_as_time_stamps=False,
        use_payload_prefix=False)
    spynnaker_external_devices.add_application_vertex(live_packet_gather)
    for partition_id in vertex.get_outgoing_partition_ids():
        spynnaker_external_devices.add_edge(vertex, live_packet_gather,
                                            partition_id)
    return population
Example #2
0
def EthernetSensorPopulation(device,
                             local_host=None,
                             database_notify_port_num=None,
                             database_ack_port_num=None):
    """ Create a pyNN population which can be included in a network to\
        receive spikes from a device connected to the host

    :param device: Class of a model that implements AbstractEthernetController
    :param local_host:\
        The optional local host IP address to listen on for database\
        notification
    :param database_ack_port_num:\
        The optional port to which responses to the database notification\
        protocol are to be sent
    :param database_notify_port_num:\
        The optional port to which notifications from the database\
        notification protocol are to be sent
    :return:\
        A pyNN Population which can be used as the source of a Projection.\
        Note that the Population cannot be used as the target of a Projection.
    """
    if not isinstance(device, AbstractEthernetSensor):
        raise Exception("Model must be an instance of AbstractEthernetSensor")
    injector_params = dict(device.get_injector_parameters())

    population = Population(device.get_n_neurons(),
                            SpikeInjector(notify=False),
                            label=device.get_injector_label(),
                            additional_parameters=injector_params)
    if isinstance(device, AbstractSendMeMulticastCommandsVertex):
        ethernet_command_connection = EthernetCommandConnection(
            device.get_translator(), [device], local_host,
            database_notify_port_num)
        add_database_socket_address(
            ethernet_command_connection.local_ip_address,
            ethernet_command_connection.local_port, database_ack_port_num)
    database_connection = device.get_database_connection()
    if database_connection is not None:
        add_database_socket_address(database_connection.local_ip_address,
                                    database_connection.local_port,
                                    database_ack_port_num)
    return population