def main(name): map = generate_map(name) context = Context() pub_socket = context.socket(PUB) pub_socket.bind('tcp://0.0.0.0:20000') map['pub_server'] = pub_socket rep_socket = context.socket(REP) rep_socket.bind('tcp://0.0.0.0:20001') map['rep_server'] = rep_socket manager = MissionManager() rep_socket = map['rep_server'] manager.start_mission(LocMission(map, None)) return while True: req = MissionMessage() req.ParseFromString(rep_socket.recv()) if req.type == 6: req.type = 7 try: if req.missionType == MissionMessage.CONNECTION: manager.start_mission(PlaceMission(map, (0.0, 0.0), req)) elif req.missionType == MissionMessage.LOCALIZATION: manager.start_mission(LocMission(map, req)) else: raise ValueError('unknown mission type') req.status = MissionMessage.ACTIVE except RuntimeError: req.status = MissionMessage.REJECTED rep_socket.send(req.SerializeToString())
from zmq import Context, REQ, SUB, SUBSCRIBE from mission_pb2 import MissionMessage context = Context() socket = context.socket(REQ) socket.connect('tcp://0.0.0.0:20001') req = MissionMessage() req.type = 6 req.missionType = MissionMessage.LOCALIZATION socket.send(req.SerializeToString()) req.ParseFromString(socket.recv()) print req socket = context.socket(SUB) socket.setsockopt(SUBSCRIBE, '') socket.connect('tcp://0.0.0.0:20002') req = MissionMessage() while True: req.ParseFromString(socket.recv()) print req