Commit b286f303 by almagosi

Final commit maybe

parent 854ddac4
import mensajeInterfaz as msg
import time
msgInterfaz = msg.MensajeInterfaz()
mapa = msgInterfaz.getMapa()
print(f"Mapa recibido {mapa}")
print("Comprobando solicitud")
while(not msgInterfaz.pedidoSolicitado):
time.sleep(1)
print("Comprobando solicitud")
posicion = msgInterfaz.getPosicion()
print(f"Posicion Recibida {posicion}")
print(f'Posicion x = {posicion[0]} : y = {posicion[1]}')
pedido = ((4,5),(7,9))
msgInterfaz.sendPedido(pedido)
print("Pedido enviado")
time.sleep(60)
\ No newline at end of file
import conexion as cn
import time
mapa = "0202000105030705000200041109060110031000000200080101100110000106010701"
while(True):
cn.send_mqtt_message("map",mapa)
print("Enviado")
time.sleep(30)
\ No newline at end of file
#from typing import Any
import conexion as cn
import time
import json
class MensajeInterfaz:
def __init__(self) -> None:
def on_message_default(client,userdata,message):
print(f'Recive Topic:{message.topic} Mensage:{str(message.payload.decode("utf-8"))}')
mensaje = str(message.payload.decode("utf-8"))
if(mensaje.split(self.sepMsg)[0] == self.prefMsg['pedido']):
self.pedidoSolicitado = True
if(mensaje.split(self.sepMsg)[0] == self.prefMsg['posicion']):
mensaje = str(message.payload.decode("utf-8"))
sspos = mensaje.split(self.sepMsg)[1].split(",")
ssx = int(sspos[0].split("(")[1])
ssy = int(sspos[1].split(")")[0])
self.posicion = (ssx,ssy)
def on_message_mapa(client,userdata,message):
print(f'Recive Topic:{message.topic} Mensage:{str(message.payload.decode("utf-8"))}')
self.mapa = str(message.payload.decode("utf-8"))
while(not self.sinc):
time.sleep(2)
self.__enviarMapa()
self.conex.desubscribir(message.topic)
def on_message_sinc(client,userdata,message):
print(f'Recive Topic:{message.topic} Mensage:{str(message.payload.decode("utf-8"))}')
self.sinc = True
#def on_message(client, userdata, message):
# print(f'Recive Topic:{message.topic} Mensage:{str(message.payload.decode("utf-8"))}')
# filtrarMensage(message.topic,str(message.payload.decode("utf-8")))
with open(file="conexionConfig.json",mode='r') as f:
data = json.load(f)
#self.topicSubs = ["A3-467/GrupoL/Robot"]
self.topicSubs = data['topicSubsInterfaz']
print(f'Topics a subscribir {self.topicSubs}')
#self.topicSend = ["A3-467/GrupoL/Interfaz"]
self.topicSend = data['topicSendInterfaz']
print(f'Topics a enviar {self.topicSend}')
#self.prefMsg = {"mapa":'map',
# "pedido":'ped',
# "posicion":'pos'}
self.prefMsg = data['prefijoMensajes']
self.sepMsg = data['separadorMensaje']
defs = [on_message_default,on_message_mapa,on_message_sinc]
self.conex = cn.Conexion(self.topicSubs,on_msg=defs)
self.mapa = ""
self.posicion : list
self.pedidoSolicitado = False
self.sinc = False
self.__sincronizacion()
def __sincronizacion(self):
while(not self.sinc):
self.conex.publicar(self.topicSend[-1],self.prefMsg['sinc'])
time.sleep(2)
print("SINCRONIZADO")
self.conex.desubscribir(self.topicSubs[-1])
self.conex.publicar(self.topicSend[-1],self.prefMsg['sinc'])
def __enviarMapa(self):
self.conex.publicar(self.topicSend[0],str(self.prefMsg['mapa'] + self.sepMsg + self.mapa))
def getMapa(self):
while(len(self.mapa) == 0):
time.sleep(1)
return self.mapa
def sendPedido(self,pedido):
msg = ""
for pos in pedido:
for num in pos:
msg = msg + str(num)
self.conex.publicar(self.topicSend[0],self.prefMsg['pedido'] + self.sepMsg + msg)
self.pedidoSolicitado = False
def getPosicion(self):
while(self.posicion is None):
print("No hay posicion")
time.sleep(1)
return self.posicion
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment