def start(self): # Start default writer and reader CspZmqNode.start(self) # Create sockets xpub_out = self._context.socket(zmq.XPUB) xsub_in = self._context.socket(zmq.XSUB) xpub_out.bind('ipc:///tmp/zmqipcin') xsub_in.bind('ipc:///tmp/zmqipcout') s_mon = None if self.monitor: # Crate monitor socket s_mon = self._context.socket(zmq.PUB) s_mon.bind('tcp://*:{}'.format(self.mon_port_hub)) if self.console: self.console_hub() # Start ZMQ proxy (blocking) try: zmq.proxy(xsub_in, xpub_out, s_mon) except KeyboardInterrupt as e: print("Main:", e) finally: # print("Closing due to", e) xsub_in.setsockopt(zmq.LINGER, 0) xsub_in.close() xpub_out.close() if s_mon: s_mon.close() self.stop()
def __init__(self, ip="localhost", in_port="8002", out_port="8001", mon_port="8003", reader=True, writer=False, proto="tcp"): """ CSP ZMQ HUB Is a PUB-SUB proxy that allow to interconnect a set of publisher and subscriber nodes. NODE:PUB:OUT_PORT <----> HUB:XSUB:IN_PORT|::|HUB:XPUB:OUT_PORT <----> NODE:SUB:IN_PORT :param in_port: input port, XSUB socket. (Should match nodes output port, PUB sockets) :param out_port: output port, XPUB socket. (Should match nodes input port, SUB sockets) :param mon_port: monitor port, internal PUB-SUB socket. :param reader: activate monitor :param writer: activate console """ CspZmqNode.__init__(self, None, ip, mon_port, in_port, reader, writer, proto) self.mon_port_hub = mon_port self.out_port_hub = out_port self.in_port_hub = in_port
def __init__(self, this_node, radio_node, predict_ip="127.0.0.1", predict_port="4532", hub_ip="localhost", in_port="8001", out_port="8002", reader=False, writer=True): CspZmqNode.__init__(self, this_node, hub_ip, in_port, out_port, reader, writer) self.predict_ip = predict_ip self.predict_port = predict_port self.radio_node = radio_node self.f_main = 0 self.f_sub = 0 self._predict_th = None
def join(self): CspZmqNode.join(self) self._predict_th.join()
def start(self): CspZmqNode.start(self) self._predict_th = self.predict_reader()