Fixed most problems with the messaging system.
This commit is contained in:
parent
f023393113
commit
1f1c19232a
1 changed files with 2 additions and 12 deletions
|
@ -102,42 +102,32 @@ class Communication:
|
||||||
|
|
||||||
def encode_message(self, msgtype, msgdata):
|
def encode_message(self, msgtype, msgdata):
|
||||||
if(msgtype == Command.READY):
|
if(msgtype == Command.READY):
|
||||||
print("ENC: Case 1")
|
|
||||||
self.msg_queue.append(("explorer/" + self.uid, Command.SEND + Command.READY))
|
self.msg_queue.append(("explorer/" + self.uid, Command.SEND + Command.READY))
|
||||||
if(msgtype == Command.TARGET):
|
if(msgtype == Command.TARGET):
|
||||||
print("ENC: Case 2")
|
|
||||||
self.msg_queue.append("explorer/" + self.uid, Command.SEND + Command.TARGET + "reached!")
|
self.msg_queue.append("explorer/" + self.uid, Command.SEND + Command.TARGET + "reached!")
|
||||||
if(msgtype == Command.COMPLETE):
|
if(msgtype == Command.COMPLETE):
|
||||||
print("ENC: Case 3")
|
|
||||||
self.msg_queue.append("explorer/" + self.uid, Command.SEND + Command.COMPLETE)
|
self.msg_queue.append("explorer/" + self.uid, Command.SEND + Command.COMPLETE)
|
||||||
if(msgtype == Command.PATH):
|
if(msgtype == Command.PATH):
|
||||||
print("ENC: Case 4")
|
|
||||||
self.msg_queue.append(("planet/" + self.planetname, Command.SEND + Command.PATH + self.pathtostring(msgdata[0], msgdata[1], msgdata[2])))
|
self.msg_queue.append(("planet/" + self.planetname, Command.SEND + Command.PATH + self.pathtostring(msgdata[0], msgdata[1], msgdata[2])))
|
||||||
|
|
||||||
def process_messages(self):
|
def process_messages(self):
|
||||||
for messages in self.msg_queue:
|
for messages in self.msg_queue:
|
||||||
if(type(messages) == tuple):
|
if(type(messages) == tuple):
|
||||||
print("Sending Message:", messages)
|
|
||||||
self.client.publish(messages[0], payload=messages[1], qos=1)
|
self.client.publish(messages[0], payload=messages[1], qos=1)
|
||||||
elif(messages.payload.decode('utf-8').startswith(Command.RECEIVE)):
|
elif(messages.payload.decode('utf-8').startswith(Command.RECEIVE)):
|
||||||
print("Received Message:", messages.payload.decode('utf-8'))
|
|
||||||
self.comexec(messages.payload.decode('utf-8')[4:])
|
self.comexec(messages.payload.decode('utf-8')[4:])
|
||||||
self.msg_queue.pop(0)
|
self.msg_queue.clear()
|
||||||
|
|
||||||
def comexec(self, message):
|
def comexec(self, message):
|
||||||
if not any([message.startswith(instruction) for instruction in Command]): # is planet name and starting position
|
if not any([message.startswith(instruction) for instruction in Command]): # is planet name and starting position
|
||||||
print("EXEC: Case 1")
|
|
||||||
[self.planetname, startnode] = message.rsplit(' ')
|
[self.planetname, startnode] = message.rsplit(' ')
|
||||||
self.subscribetochannel(self.planetname)
|
self.subscribetochannel("planet/" + self.planetname)
|
||||||
self.planet.setcurnode(str2tuple(*startnode.rsplit(',')))
|
self.planet.setcurnode(str2tuple(*startnode.rsplit(',')))
|
||||||
elif message.startswith(Command.PATH):
|
elif message.startswith(Command.PATH):
|
||||||
print("EXEC: Case 2")
|
|
||||||
self.stringtopath(*message[5:].rsplit(' '))
|
self.stringtopath(*message[5:].rsplit(' '))
|
||||||
elif message.startswith(Command.TARGET):
|
elif message.startswith(Command.TARGET):
|
||||||
print("EXEC: Case 3")
|
|
||||||
self.navto = self.planet.shortest_path(self.planet.getcurnode(), str2tuple(*message[7:].rsplit(',')))
|
self.navto = self.planet.shortest_path(self.planet.getcurnode(), str2tuple(*message[7:].rsplit(',')))
|
||||||
elif message.startswith(Command.NOTICE):
|
elif message.startswith(Command.NOTICE):
|
||||||
print("EXEC: Case 4")
|
|
||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
def stringtopath(self, start, target, block, weight):
|
def stringtopath(self, start, target, block, weight):
|
||||||
|
|
Loading…
Reference in a new issue