def generate(params: "PreviewGenerator"): try: # Connect to url and read params._status_pipe.send("Connecting to URL '{}'...".format( params._url)) context = zmq.Context() frame_queue = Msg_Receiver(context, params._url, topics=("frame.eye", )) params._status_pipe.send( "Starting generating previews and saving them in '{}'...". format(params.folder)) streams = {} while not params._command_pipe.poll(): if frame_queue.new_data: topic, payload = frame_queue.recv() id = int(str(topic).split(".")[-1]) if id not in streams: streams[id] = PreviewGenerator.ImageStream( eye_id=id, frame_per_frames=params.frame_per_frames, folder=params.folder, frame_size=(payload["width"], payload["height"]), frame_format=params.frame_format, detector_parameters=params.detector_parameters, ) streams[id].add(payload) del frame_queue except Exception as e: params._status_pipe.send(e)
def __init__(self, g_pool): super(Burnin_Test, self).__init__(g_pool) self.running = False self.end_time = 0 self.button = None self.log_receiver = Msg_Receiver(g_pool.zmq_ctx, g_pool.ipc_sub_url, topics=('logging.info', ))
def _thread_loop(self, context, pipe): # Pyre helper functions def setup_group_member(): group_member = Pyre(self.name) # set headers for header in self.default_headers: group_member.set_header(*header) # join active group group_member.join(self.active_group) # start group_member group_member.start() return group_member def shutdown_group_member(node): node.leave(self.active_group) node.stop() # setup sockets local_in = Msg_Receiver(context, self.g_pool.ipc_sub_url, topics=("remote_notify.", )) local_out = Msg_Dispatcher(context, self.g_pool.ipc_push_url) group_member = setup_group_member() # register sockets for polling poller = zmq.Poller() poller.register(pipe, zmq.POLLIN) poller.register(local_in.socket, zmq.POLLIN) poller.register(group_member.socket(), zmq.POLLIN) logger.info("Pupil Groups started.") # Poll loop while True: # Wait for next readable item readable = dict(poller.poll()) # shout or whisper marked notifications if local_in.socket in readable: topic, notification = local_in.recv() remote_key = "remote_notify" if notification[remote_key] == "all": del notification[remote_key] serialized = serializer.dumps(notification) group_member.shout(self.active_group, serialized) else: peer_uuid_bytes = notification[remote_key] del notification[remote_key] serialized = serializer.dumps(notification) peer_uuid = uuid.UUID(bytes=peer_uuid_bytes) group_member.whisper(peer_uuid, serialized) if group_member.socket() in readable: event = PyreEvent(group_member) if event.msg: for msg in event.msg: try: # try to unpack data notification = serializer.loads(msg, encoding="utf-8") # test if dictionary and if `subject` key is present notification["subject"] # add peer information notification["groups.peer"] = { "uuid_bytes": event.peer_uuid_bytes, "name": event.peer_name, "arrival_timestamp": self.g_pool.get_timestamp(), "type": event.type, } local_out.notify(notification) except Exception: logger.info( "Dropped garbage data by peer {} ({})".format( event.peer_name, event.peer_uuid)) elif event.type == "JOIN" and event.group == self.active_group: local_out.notify({ "subject": "groups.member_joined", "name": event.peer_name, "uuid_bytes": event.peer_uuid_bytes, }) elif (event.type == "LEAVE" and event.group == self.active_group) or event.type == "EXIT": local_out.notify({ "subject": "groups.member_left", "name": event.peer_name, "uuid_bytes": event.peer_uuid_bytes, }) if pipe in readable: command = pipe.recv_string() if command == "$RESTART": # Restart group_member node to change name poller.unregister(group_member.socket()) shutdown_group_member(group_member) group_member = setup_group_member() poller.register(group_member.socket(), zmq.POLLIN) elif command == "$TERM": break del local_in del local_out shutdown_group_member(group_member) self.thread_pipe = None
class Burnin_Test(Plugin): burnin_time = 60 * 60 + 1 # 60x 60sec def __init__(self, g_pool): super(Burnin_Test, self).__init__(g_pool) self.running = False self.end_time = 0 self.button = None self.log_receiver = Msg_Receiver(g_pool.zmq_ctx, g_pool.ipc_sub_url, topics=('logging.info', )) def init_gui(self): self.button = ui.Thumb('running', self, setter=self.toggle, label='B', hotkey='b') self.button.on_color[:] = (1, .0, .0, .8) self.g_pool.quickbar.insert(2, self.button) def deinit_gui(self): if self.button: self.g_pool.quickbar.remove(self.button) self.button = None def toggle(self, _=None): if self.running: self.running = False self.button.status_text = '' else: self.end_time = time() + self.burnin_time self.running = True def recent_events(self, events): while self.log_receiver.new_data: topic, payload = self.log_receiver.recv() if self.running and payload[ 'msg'] == 'Camera stopped providing frames. Reinitialising camera.': fail_reason = 'Camera in process {} disconnected. Burn in test failed.'.format( payload['processName']) say(fail_reason) logger.critical(fail_reason) self.toggle() if self.running: remaining_time = self.end_time - time() self.button.status_text = strftime("%H:%M:%S", gmtime(remaining_time)) if remaining_time < 0: self.toggle() say("Burn in test successful") logger.info("Burn in test successful") def get_init_dict(self): return {} def cleanup(self): """gets called when the plugin get terminated. either volunatily or forced. """ self.deinit_gui() del self.log_receiver
def _thread_loop(self,context,pipe): # Pyre helper functions def setup_group_member(): group_member = Pyre(self.name) # set headers for header in self.default_headers: group_member.set_header(*header) # join active group group_member.join(self.active_group) # start group_member group_member.start() return group_member def shutdown_group_member(node): node.leave(self.active_group) node.stop() # setup sockets local_in = Msg_Receiver(context, self.g_pool.ipc_sub_url, topics=('remote_notify.',)) local_out = Msg_Dispatcher(context, self.g_pool.ipc_push_url) group_member = setup_group_member() # register sockets for polling poller = zmq.Poller() poller.register(pipe,zmq.POLLIN) poller.register(local_in.socket,zmq.POLLIN) poller.register(group_member.socket(),zmq.POLLIN) logger.info('Pupil Groups started.') # Poll loop while True: # Wait for next readable item readable = dict(poller.poll()) # shout or whisper marked notifications if local_in.socket in readable: topic, notification = local_in.recv() remote_key = 'remote_notify' if notification[remote_key] == 'all': del notification[remote_key] serialized = serializer.dumps(notification) group_member.shout(self.active_group,serialized) else: peer_uuid_bytes = notification[remote_key] del notification[remote_key] serialized = serializer.dumps(notification) peer_uuid = uuid.UUID(bytes=peer_uuid_bytes) group_member.whisper(peer_uuid,serialized) if group_member.socket() in readable: event = PyreEvent(group_member) if event.msg: for msg in event.msg: try: # try to unpack data notification = serializer.loads(msg) # test if dictionary and if `subject` key is present notification['subject'] # add peer information notification['groups.peer'] = { 'uuid_bytes': event.peer_uuid_bytes, 'name': event.peer_name, 'arrival_timestamp': self.g_pool.get_timestamp(), 'type': event.type } local_out.notify(notification) except Exception as e: logger.info('Dropped garbage data by peer %s (%s)'%(event.peer_name, event.peer_uuid)) elif event.type == 'JOIN' and event.group == self.active_group: local_out.notify({ 'subject': 'groups.member_joined', 'name': event.peer_name, 'uuid_bytes': event.peer_uuid_bytes }) elif (event.type == 'LEAVE' and \ event.group == self.active_group) or \ event.type == 'EXIT': local_out.notify({ 'subject': 'groups.member_left', 'name': event.peer_name, 'uuid_bytes': event.peer_uuid_bytes }) if pipe in readable: command = pipe.recv() if command == '$RESTART': # Restart group_member node to change name poller.unregister(group_member.socket()) shutdown_group_member(group_member) group_member = setup_group_member() poller.register(group_member.socket(),zmq.POLLIN) elif command == '$TERM': break del local_in del local_out shutdown_group_member(group_member) self.thread_pipe = None
import zmq from zmq_tools import Msg_Receiver ctx = zmq.Context() requester = ctx.socket(zmq.REQ) requester.connect('tcp://localhost:50020') requester.send_string('SUB_PORT') ipc_sub_port = requester.recv_string() monitor = Msg_Receiver(ctx, 'tcp://localhost:%s' % ipc_sub_port, topics=('notify.', )) while True: try: print(monitor.recv()) except KeyboardInterrupt: break
import zmq, msgpack from zmq_tools import Msg_Receiver ctx = zmq.Context() ip = 'localhost' #If you talk to a different machine use its IP. port = 50020 #The port defaults to 50020 but can be set in the GUI of Pupil Capture. # open Pupil Remote socket requester = ctx.socket(zmq.REQ) requester.connect('tcp://%s:%s' % (ip, port)) requester.send_string('SUB_PORT') ipc_sub_port = requester.recv_string() # setup message receiver sub_url = 'tcp://%s:%s' % (ip, ipc_sub_port) receiver = Msg_Receiver(ctx, sub_url, topics=('notify.meta.doc', )) # construct message topic = 'notify.meta.should_doc' payload = msgpack.dumps({'subject': 'meta.should_doc'}) requester.send_string(topic, flags=zmq.SNDMORE) requester.send(payload) requester.recv_string() # wait and print responses while True: # receiver is a Msg_Receiver, that returns a topic/payload tuple on recv() topic, payload = receiver.recv() actor = payload.get('actor') doc = payload.get('doc') print('%s: %s' % (actor, doc))
import io from threading import Thread import subprocess import traceback import sys import helper import csv import matplotlib.pyplot as plt host = "10.3.141.1" port = "50020" ctx = zmq.Context() icp_req_add = "tcp://{}:{}".format(host, port) msg_receiver = Msg_Receiver(ctx, icp_req_add, topics=("hmd_streaming.world", ), block_until_connected=False) def export(listtocsv): with open("lat.csv", "w", newline="") as csvfile: fieldnames = [ "index", "exposure_start", "exposure_end", "client_start", "client_end" ] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerows(listtocsv) def histogram(listfps):
# open Pupil Remote socket requester = ctx.socket(zmq.REQ) requester.connect('tcp://%s:%s' % (ip, port)) requester.send_string('SUB_PORT') ipc_sub_port = requester.recv_string() requester = ctx.socket(zmq.REQ) requester.connect('tcp://%s:%s' % (ip, port)) requester.send_string('PUB_PORT') ipc_pub_port = requester.recv_string() # setup message receiver sub_url = 'tcp://%s:%s' % (ip, ipc_sub_port) pub_url = 'tcp://%s:%s' % (ip, ipc_pub_port) receiver = Msg_Receiver(ctx, sub_url, topics=('gaze.2d.01', )) # topic = 'gaze' # payload = {'topic': topic} # # # create and connect PUB socket to IPC # pub_socket = zmq.Socket(zmq.Context(), zmq.PUB) # pub_socket.connect(pub_url) # # # send payload using custom topic # pub_socket.send_string(topic, flags=zmq.SNDMORE) # pub_socket.send(msgpack.dumps(payload, use_bin_type=True)) # wait and print responses while True: # receiver is a Msg_Receiver, that returns a topic/payload tuple on recv()
import zmq from zmq_tools import Msg_Receiver ctx = zmq.Context() requester = ctx.socket(zmq.REQ) requester.connect('tcp://localhost:50020') requester.send_string('SUB_PORT') ipc_sub_port = requester.recv_string() monitor = Msg_Receiver(ctx,'tcp://localhost:%s'%ipc_sub_port,topics=('notify.',)) while True: try: print(monitor.recv()) except KeyboardInterrupt: break
import zmq from zmq_tools import Msg_Receiver ctx = zmq.Context() requester = ctx.socket(zmq.REQ) requester.connect("tcp://127.0.0.1:50020") requester.send_string("SUB_PORT") ipc_sub_port = requester.recv_string() monitor = Msg_Receiver(ctx, "tcp://127.0.0.1:%s" % ipc_sub_port, topics=("notify.", )) while True: try: print(monitor.recv()) except KeyboardInterrupt: break
import zmq from zmq_tools import Msg_Receiver ctx = zmq.Context() requester = ctx.socket(zmq.REQ) requester.connect('tcp://127.0.0.1:50020') requester.send_string('SUB_PORT') ipc_sub_port = requester.recv_string() monitor = Msg_Receiver(ctx, 'tcp://127.0.0.1:%s' % ipc_sub_port, topics=('notify.', )) while True: try: print(monitor.recv()) except KeyboardInterrupt: break