sort the received aircraft reports into the corresponding worker thread

This commit is contained in:
Sven Czarnian
2021-09-03 23:35:17 +02:00
parent 1561335e1b
commit 9de9b813ba
3 changed files with 28 additions and 8 deletions

View File

@@ -11,12 +11,13 @@ import zmq
import zmq.auth
from aman.com import AircraftReport_pb2
from aman.config import Server
from aman.config.Server import Server
class ReceiverThread(threading.Thread):
def __init__(self, socket):
def __init__(self, socket, aman):
threading.Thread.__init__(self)
self.socket = socket
self.aman = aman
def run(self):
while True:
@@ -26,6 +27,10 @@ class ReceiverThread(threading.Thread):
# parse the received message
report = AircraftReport_pb2.AircraftReport()
report.ParseFromString(msg)
# try to associate the received aircraft to an airport
self.aman.updateAircraftReport(report)
except zmq.ZMQError as error:
if zmq.EAGAIN == error.errno:
time.sleep(0.5)
@@ -50,7 +55,7 @@ class ReceiverThread(threading.Thread):
class Euroscope:
# @brief Initializes the ZMQ socket
# @param[in] config The server configuration
def __init__(self, configPath : str, config : Server.Server):
def __init__(self, configPath : str, config : Server, aman):
self.context = zmq.Context()
# find the key directories
@@ -80,7 +85,7 @@ class Euroscope:
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)
self.receiverThread = ReceiverThread(self.receiverSocket, aman)
self.receiverThread.start()
print('Listening at tcp://' + config.Address + ':' + str(config.PortReceiver))