AMAN.py 2.9 KB

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