AMAN.py 2.9 KB

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