def subscriber(e, topic): gmp = GeckoMP() s = Sub(topics=[topic]) addr = zmqTCP('localhost', 9999) print('Subscriber connected to: {}'.format(addr)) s.connect(addr) while e.is_set(): # print(s.recv(flags=zmq.NOBLOCK)) topic, msg = s.recv() # print("recv[{}]: {}".format(topic, msg)) print('sub bye ...')
def publisher(e, topic): gmp = GeckoMP() p = Pub() addr = zmqTCP('localhost', 9998) p.connect(addr) print('Publisher connected to: {}'.format(addr)) cnt = 0 while e.is_set(): msg = {'a': cnt, 'b': bytearray([1, 2, 3])} p.pub(topic, msg) # topic msg cnt += 1 # print('[{}] published msg'.format(cnt)) time.sleep(.05) print('pub bye ...')
def run(self, topic): self.kill_signals() p = Pub() addr = zmqTCP('localhost', 9998) p.connect(addr) print('Publisher connected to: {}'.format(addr)) cnt = 0 raw_img = np.random.rand(640, 480) while not self.kill: msg = {'a': cnt, 'b': raw_img.tobytes(), 'c': time.time()} p.pub(topic, msg) # topic msg cnt += 1 # print('[{}] published msg'.format(cnt)) time.sleep(0.05) print('pub bye ...')
def publisher(e, topic): messages = Messages() p = Pub(pack=messages.serialize) addr = zmqTCP('localhost', 9998) p.connect(addr) name = mp.current_process().name try: cnt = 0 while e.is_set(): msg = IMU(Vector(1,2,3),Vector(1,2,3),Vector(1,2,3)) p.pub(topic, msg) # topic msg cnt += 1 print('>> {} published msg on {}'.format(name, topic)) time.sleep(1) except Exception: pass print("*"*30) print('*** {} pub bye'.format(name)) print("*"*30)
def subscriber(e, topic): mm = Messages() s = Sub(topics=[topic], unpack=mm.deserialize) addr = zmqTCP('localhost', 9999) s.connect(addr) name = mp.current_process().name try: while e.is_set(): t, msg = s.recv() # print(s.recv(flags=zmq.NOBLOCK)) # print("recv[{}]: {}".format(*s.recv())) # print(name, 'recvd message') print('{} recvd[{}] message'.format(name, t, msg)) except Exception as e: print(e) pass print("*" * 30) print('*** {} Sub bye'.format(name)) print("*" * 30)
def subscriber(e, topic): messages = Messages() s = Sub(topics=[topic], unpack=messages.deserialize) filename = 'test.bag' bag = BagWriter(filename, buffer_size=10, pack=messages.serialize) addr = zmqTCP('localhost', 9999) s.connect(addr) name = mp.current_process().name try: while e.is_set(): # print(s.recv(flags=zmq.NOBLOCK)) # print("recv[{}]: {}".format(*s.recv())) t, msg = s.recv() print('<< {} recvd[{}] message'.format(name, t, msg)) bag.push(t, msg) except Exception as e: print(e) bag.close() print("{} is {:.1f} kB".format(filename, os.path.getsize(filename)/1000)) # os.remove(filename) print("*"*30) print('*** {} Sub bye'.format(name)) print("*"*30)