change to request-response communication for an easier update of euroscope
This commit is contained in:
@@ -14,24 +14,31 @@ from aman.com import Communication_pb2
|
||||
from aman.config.Server import Server
|
||||
from threading import Thread, _active
|
||||
|
||||
class ReceiverThread(Thread):
|
||||
def __init__(self, socket, aman):
|
||||
class ComThread(Thread):
|
||||
def __init__(self, com, aman):
|
||||
Thread.__init__(self)
|
||||
self.Socket = socket
|
||||
self.Com = com
|
||||
self.AMAN = aman
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
try:
|
||||
msg = self.Socket.recv(zmq.NOBLOCK)
|
||||
msg = self.Com.Socket.recv(zmq.NOBLOCK)
|
||||
|
||||
# parse the received message
|
||||
report = Communication_pb2.AircraftUpdate()
|
||||
report.ParseFromString(msg)
|
||||
|
||||
# try to associate the received aircrafts to airports
|
||||
icao = []
|
||||
for inbound in report.reports:
|
||||
self.AMAN.updateAircraftReport(inbound)
|
||||
icao = inbound.destination
|
||||
|
||||
# get the sequence of the airport
|
||||
airport = self.AMAN.findAirport(icao)
|
||||
if None != airport:
|
||||
self.Com.sendSequence('', airport.inboundSequence(), airport.WeatherModel)
|
||||
|
||||
except zmq.ZMQError as error:
|
||||
if zmq.EAGAIN == error.errno:
|
||||
@@ -44,9 +51,8 @@ class ReceiverThread(Thread):
|
||||
class Euroscope:
|
||||
def __init__(self, configPath : str, config : Server, aman):
|
||||
self.Context = None
|
||||
self.ReceiverSocket = None
|
||||
self.ReceiverThread = None
|
||||
self.NotificationSocket = None
|
||||
self.Socket = None
|
||||
self.Thread = None
|
||||
self.Context = zmq.Context()
|
||||
|
||||
# find the key directories
|
||||
@@ -70,27 +76,19 @@ class Euroscope:
|
||||
keyPair = zmq.auth.load_certificate(keyPairPath[0])
|
||||
|
||||
# initialize the receiver
|
||||
self.ReceiverSocket = zmq.Socket(self.Context, zmq.SUB)
|
||||
self.ReceiverSocket.setsockopt(zmq.CURVE_PUBLICKEY, keyPair[0])
|
||||
self.ReceiverSocket.setsockopt(zmq.CURVE_SECRETKEY, keyPair[1])
|
||||
self.ReceiverSocket.setsockopt(zmq.CURVE_SERVER, True)
|
||||
self.ReceiverSocket.bind('tcp://' + config.Address + ':' + str(config.PortReceiver))
|
||||
self.ReceiverSocket.setsockopt(zmq.SUBSCRIBE, b'')
|
||||
self.ReceiverThread = ReceiverThread(self.ReceiverSocket, aman)
|
||||
self.ReceiverThread.setDaemon(True)
|
||||
self.ReceiverThread.start()
|
||||
self.Socket = zmq.Socket(self.Context, zmq.REP)
|
||||
self.Socket.setsockopt(zmq.CURVE_PUBLICKEY, keyPair[0])
|
||||
self.Socket.setsockopt(zmq.CURVE_SECRETKEY, keyPair[1])
|
||||
self.Socket.setsockopt(zmq.CURVE_SERVER, True)
|
||||
self.Socket.bind('tcp://' + config.Address + ':' + str(config.PortReceiver))
|
||||
#self.Socket.setsockopt(zmq.SUBSCRIBE, b'')
|
||||
self.Thread = ComThread(self, aman)
|
||||
self.Thread.setDaemon(True)
|
||||
self.Thread.start()
|
||||
print('Listening to tcp://' + config.Address + ':' + str(config.PortReceiver))
|
||||
|
||||
# initialize the notification
|
||||
self.NotificationSocket = zmq.Socket(self.Context, zmq.PUB)
|
||||
self.NotificationSocket.setsockopt(zmq.CURVE_PUBLICKEY, keyPair[0])
|
||||
self.NotificationSocket.setsockopt(zmq.CURVE_SECRETKEY, keyPair[1])
|
||||
self.NotificationSocket.setsockopt(zmq.CURVE_SERVER, True)
|
||||
self.NotificationSocket.bind('tcp://' + config.Address + ':' + str(config.PortNotification))
|
||||
print('Publishing to tcp://' + config.Address + ':' + str(config.PortNotification))
|
||||
|
||||
def sendSequence(self, airport : str, inbounds, weather):
|
||||
if None == self.NotificationSocket:
|
||||
if None == self.Socket:
|
||||
return
|
||||
|
||||
sequence = Communication_pb2.AircraftSequence()
|
||||
@@ -133,4 +131,4 @@ class Euroscope:
|
||||
wp.pta = pta[0:delimiter]
|
||||
|
||||
message = sequence.SerializeToString()
|
||||
self.NotificationSocket.send(message)
|
||||
self.Socket.send(message)
|
||||
|
||||
Viittaa uudesa ongelmassa
Block a user