From f7b8f26e481f65989476b9ef5b075db485e9d108 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Sun, 14 Nov 2021 10:02:21 +0100 Subject: [PATCH] add the function to request the configuration --- aman/com/WebUI.py | 55 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/aman/com/WebUI.py b/aman/com/WebUI.py index 012ee6b..ea437b0 100644 --- a/aman/com/WebUI.py +++ b/aman/com/WebUI.py @@ -9,6 +9,8 @@ from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry from requests.structures import CaseInsensitiveDict +from aman.config.AirportSequencing import AirportSequencing +from aman.config.RunwaySequencing import RunwaySequencing from aman.config.Server import Server class InboundEncoder(JSONEncoder): @@ -43,8 +45,57 @@ class WebUI: session.mount('https://', adapter) return session - def requestConfiguration(self, airport): - return + def requestConfiguration(self, airport, navData): + if airport not in navData.Runways: + return None + + # prepare the HTTP header and session + headers = CaseInsensitiveDict() + headers['Accept'] = 'application/json' + headers['Content-Type'] = 'application/json' + session = WebUI.createSession() + + url = self.Config.WebUiUrl + self.Config.WebUiConfigurationReceiver + data = json.dumps({ 'airport': airport }, ensure_ascii=True) + + try: + response = session.get(url, headers=headers, data=data, timeout=2) + if 200 != response.status_code: + return None + except requests.exceptions.ConnectTimeout: + return None + + config = json.loads(response.json()) + + # WebUI sent the wrong airport + if config['airport'] != airport or 0 == len(config['activeRunways']): + return None + + airportConfig = AirportSequencing(airport) + airportConfig.UseMustShallMay = config['useMustShallMay'] + + # build the sequencing information per runway + for activeRunway in config['activeRunways']: + gngRunway = None + for runway in navData.Runways[airport]: + if runway.Name == activeRunway['runway']: + gngRunway = runway + break + + # could not find the runway + if None == gngRunway: + return None + + runway = RunwaySequencing(gngRunway) + runway.Spacing = int(activeRunway['spacing']) + airportConfig.activateRunway(runway) + + # resolve the dependencies + for dependency in config['dependentRunways']: + if 2 == len(dependency): + airportConfig.addDependency(dependency[0], dependency[1]) + + return airportConfig def sendSequence(self, airport, inbounds): # prepare the HTTP header and session