AMAN.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. import glob
  3. import os
  4. import random
  5. import sys
  6. import time
  7. from aman.com import AircraftReport_pb2
  8. from aman.com.Euroscope import Euroscope
  9. from aman.com.Weather import Weather
  10. from aman.config.AircraftPerformance import AircraftPerformance
  11. from aman.config.Airport import Airport
  12. from aman.config.System import System
  13. from aman.sys.Worker import Worker
  14. class AMAN:
  15. def findConfigPath():
  16. envvar = os.environ.get('AMAN_CONFIG_PATH')
  17. if None == envvar:
  18. print('No AMAN_CONFIG_PATH in environment variables found. Using execution directory.')
  19. path = os.getcwd()
  20. else:
  21. print('AMAN_CONFIG_PATH found.')
  22. path = envvar
  23. print('Config-path: ' + path)
  24. return path
  25. def __init__(self):
  26. # default initialization of members
  27. configPath = AMAN.findConfigPath()
  28. self.SystemConfig = None
  29. self.AircraftPerformance = None
  30. self.Receiver = None
  31. self.Weather = None
  32. self.WebUi = None
  33. self.Workers = []
  34. # read all system relevant configuration files
  35. self.SystemConfig = System(os.path.join(configPath, 'System.ini'))
  36. print('Parsed System.ini')
  37. # read the aircraft performance data
  38. self.AircraftPerformance = AircraftPerformance(os.path.join(configPath, 'PerformanceData.ini'))
  39. if None == self.AircraftPerformance:
  40. sys.stderr.write('No aircraft performance data found!')
  41. sys.exit(-1)
  42. else:
  43. print('Parsed PerformanceData.ini. Extracted ' + str(len(self.AircraftPerformance.Aircrafts)) + ' aircrafts')
  44. # create the communication syb
  45. self.Weather = Weather(self.SystemConfig.Weather)
  46. self.Receiver = Euroscope(configPath, self.SystemConfig.Server, self)
  47. # find the airport configurations and create the workers
  48. airportsPath = os.path.join(os.path.join(configPath, 'airports'), '*.ini')
  49. for file in glob.glob(airportsPath):
  50. icao = os.path.splitext(os.path.basename(file))[0]
  51. print('Parsing planner configuration for ' + icao)
  52. airportConfig = Airport(file, icao)
  53. # initialize the worker thread
  54. worker = Worker(icao, airportConfig, self.Weather, self.AircraftPerformance, self.Receiver)
  55. self.Workers.append(worker)
  56. print('Started worker for ' + icao)
  57. def updateAircraftReport(self, report : AircraftReport_pb2.AircraftReport):
  58. # find the correct worker for the inbound
  59. for worker in self.Workers:
  60. if worker.Icao == report.destination:
  61. worker.acquireLock()
  62. worker.ReportQueue[report.aircraft.callsign] = report
  63. worker.releaseLock()
  64. break