示例#1
0
    def __init__(self, name, endpoint, drop_warn_cutoff, callback):
        """
        Initialise a Node for the Adapter. The node should subscribe to
        a ZMQ socket and pass any frames received at that socket to the main
        adapter.
        """
        logging.debug("Live View Proxy Node Initialising: %s", endpoint)
        self.name = name
        self.endpoint = endpoint
        self.callback = callback
        self.dropped_frame_count = 0
        self.received_frame_count = 0
        self.last_frame = 0
        self.current_acq = 0
        self.drop_warn_cutoff = drop_warn_cutoff
        self.drop_unwarn_cutoff = drop_warn_cutoff * 0.75
        self.has_warned = False
        # subscribe to the given socket address.
        self.channel = IpcTornadoChannel(IpcTornadoChannel.CHANNEL_TYPE_SUB,
                                         endpoint=endpoint)
        self.channel.subscribe()
        self.channel.connect()
        # callback is called whenever data 'arrives' at the socket. This is driven by the IOLoop
        self.channel.register_callback(self.local_callback)

        self.param_tree = ParameterTree({
            'endpoint': (lambda: self.endpoint, None),
            'dropped_frames': (lambda: self.dropped_frame_count, None),
            'received_frames': (lambda: self.received_frame_count, None),
            'last_frame': (lambda: self.last_frame, None),
            'current_acquisition': (lambda: self.current_acq, None),
        })

        logging.debug("Proxy Connected to Socket: %s", endpoint)
示例#2
0
    def __init__(self, parent, endpoint):
        """
        Initialise IPC channel as a subscriber, and register the callback.

        :param parent: the class that created this object, a LiveViewer, given so that this object
        can reference the method in the parent
        :param endpoint: the URI address of the socket to subscribe to
        """
        self.parent = parent
        self.endpoint = endpoint
        self.frame_count = 0
        self.channel = IpcTornadoChannel(IpcTornadoChannel.CHANNEL_TYPE_SUB, endpoint=endpoint)
        self.channel.subscribe()
        self.channel.connect()
        # register the get_image method to be called when the ZMQ socket receives a message
        self.channel.register_callback(self.callback)
    def __init__(self, ip_address, port):
        self.logger = logging.getLogger(self.__class__.__name__)

        self._ip_address = ip_address
        self._port = port

        self.ctrl_endpoint = self.ENDPOINT_TEMPLATE.format(IP=ip_address,
                                                           PORT=port)
        self.logger.debug("Connecting to client at %s", self.ctrl_endpoint)
        self.ctrl_channel = IpcTornadoChannel(
            IpcTornadoChannel.CHANNEL_TYPE_DEALER)
        self.ctrl_channel.connect(self.ctrl_endpoint)
        self.ctrl_channel.register_callback(self._callback)
        self._parameters = {}
        self.message_id = 0

        self._lock = RLock()
示例#4
0
    def __init__(self, **kwargs):
        """
        Initialise the Adapter, using the provided configuration.
        Create the node classes for the subscriptions to multiple ZMQ sockets.
        Also create the publish socket to push frames onto.
        """
        logging.debug("Live View Proxy Adapter init called")
        super(LiveViewProxyAdapter, self).__init__(**kwargs)

        self.dest_endpoint = self.options.get(DEST_ENDPOINT_CONFIG_NAME,
                                              DEFAULT_DEST_ENDPOINT).strip()

        self.drop_warn_percent = float(
            self.options.get(DROP_WARN_CONFIG_NAME, DEFAULT_DROP_WARN_PERCENT))

        try:
            logging.debug("Connecting publish socket to endpoint: %s",
                          self.dest_endpoint)
            self.publish_channel = IpcTornadoChannel(
                IpcTornadoChannel.CHANNEL_TYPE_PUB, self.dest_endpoint)
            self.publish_channel.bind()
        except ZMQError as channel_err:
            # ZMQError raised here if the socket addr is already in use.
            logging.error("Connection Failed. Error given: %s",
                          channel_err.message)
        self.max_queue = self.options.get(QUEUE_LENGTH_CONFIG_NAME,
                                          DEFAULT_QUEUE_LENGTH)

        if SOURCE_ENDPOINTS_CONFIG_NAME in self.options:
            self.source_endpoints = []
            for target_str in self.options[SOURCE_ENDPOINTS_CONFIG_NAME].split(
                    ','):
                try:
                    # config provides the nodes as "node_name=socket_URI" pairs. Split those strings
                    (target, url) = target_str.split("=")
                    self.source_endpoints.append(
                        LiveViewProxyNode(target.strip(), url.strip(),
                                          self.drop_warn_percent,
                                          self.add_to_queue))
                except (ValueError, ZMQError):
                    logging.debug("Error parsing target list: %s", target_str)
        else:
            self.source_endpoints = [
                LiveViewProxyNode("node_1", DEFAULT_SOURCE_ENDPOINT,
                                  self.drop_warn_percent, self.add_to_queue)
            ]

        tree = {
            "target_endpoint": (lambda: self.dest_endpoint, None),
            'last_sent_frame': (lambda: self.last_sent_frame, None),
            'dropped_frames': (lambda: self.dropped_frame_count, None),
            'reset': (None, self.set_reset),
            "nodes": {}
        }
        for sub in self.source_endpoints:
            tree["nodes"][sub.name] = sub.param_tree

        self.param_tree = ParameterTree(tree)

        self.queue = PriorityQueue(self.max_queue)

        self.last_sent_frame = (0, 0)
        self.dropped_frame_count = 0

        self.get_frame_from_queue()