Use pub socket with a key for the sub in the envelope.

This commit is contained in:
Piv
2020-02-15 20:43:22 +10:30
parent 65f3438631
commit 065dcc437a

View File

@@ -33,12 +33,10 @@ class SlamStreamer:
'''
print('Starting to stream')
self._socket = self._start_socket(self._create_socket(self._zmq_context), self._port)
self._socket = self._start_socket(
self._create_socket(self._zmq_context), self._port)
# Block until user opens zmq.
self._socket.recv()
print('Received message from ZMQ')
print('Started and bound zmq socket.')
# Adapted from BreezySLAM rpslam example.
# Connect to Lidar unit
@@ -75,10 +73,10 @@ class SlamStreamer:
map should be the result of slam.getmap.
location should be a tuple, the result of slam.getpos()
'''
protoScan = SlamScan(map = bytes(mapbytes), \
protoScan = SlamScan(map=bytes(mapbytes),
location=SlamLocation(x=location[0], y=location[1], theta=location[3]))
print('Sending map')
self._socket.send(protoScan.SerializeToString())
self._socket.send_multipart(b'slam_map', protoScan.SerializeToString())
def stop_scanning(self):
self.can_scan = False
@@ -87,7 +85,7 @@ class SlamStreamer:
return zmq.Context.instance()
def _create_socket(self, context):
return context.socket(zmq.PAIR)
return context.socket(zmq.PUB)
def _start_socket(self, socket, port):
socket.bind('tcp://*:' + str(self._port))