AMAN.py 3.1 KB

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