[8] | 1 | # Module related to the high-level tracking of the flight
|
---|
| 2 |
|
---|
| 3 | #---------------------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | import const
|
---|
| 6 |
|
---|
| 7 | import threading
|
---|
| 8 |
|
---|
| 9 | #---------------------------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | class Flight(object):
|
---|
| 12 | """The object with the global flight state.
|
---|
| 13 |
|
---|
| 14 | It is also the hub for the other main objects participating in the handling of
|
---|
| 15 | the flight."""
|
---|
| 16 | def __init__(self, logger):
|
---|
| 17 | """Construct the flight."""
|
---|
| 18 | self._stage = None
|
---|
| 19 | self.logger = logger
|
---|
| 20 | self.cruiseAltitude = None
|
---|
[9] | 21 | self.flareTimeFromFS = False
|
---|
[8] | 22 | self.aircraftType = None
|
---|
| 23 | self.aircraft = None
|
---|
| 24 | self.simulator = None
|
---|
| 25 |
|
---|
| 26 | self._endCondition = threading.Condition()
|
---|
| 27 |
|
---|
[9] | 28 | self._flareStart = None
|
---|
| 29 | self._flareStartFS = None
|
---|
| 30 |
|
---|
[8] | 31 | @property
|
---|
| 32 | def stage(self):
|
---|
| 33 | """Get the flight stage."""
|
---|
| 34 | return self._stage
|
---|
| 35 |
|
---|
| 36 | def setStage(self, timestamp, stage):
|
---|
[9] | 37 | """Set the flight stage.
|
---|
| 38 |
|
---|
| 39 | Returns if the stage has really changed."""
|
---|
[8] | 40 | if stage!=self._stage:
|
---|
| 41 | self._stage = stage
|
---|
| 42 | self.logger.stage(timestamp, stage)
|
---|
| 43 | if stage==const.STAGE_END:
|
---|
| 44 | with self._endCondition:
|
---|
| 45 | self._endCondition.notify()
|
---|
[9] | 46 | return True
|
---|
| 47 | else:
|
---|
| 48 | return False
|
---|
| 49 |
|
---|
| 50 | def flareStarted(self, flareStart, flareStartFS):
|
---|
| 51 | """Called when the flare time has started."""
|
---|
| 52 | self._flareStart = flareStart
|
---|
| 53 | self._flareStartFS = flareStartFS
|
---|
| 54 |
|
---|
| 55 | def flareFinished(self, flareEnd, flareEndFS):
|
---|
| 56 | """Called when the flare time has ended.
|
---|
| 57 |
|
---|
| 58 | Return a tuple of the following items:
|
---|
| 59 | - a boolean indicating if FS time is used
|
---|
| 60 | - the flare time
|
---|
| 61 | """
|
---|
| 62 | if self.flareTimeFromFS:
|
---|
| 63 | return (True, flareEndFS - self._flareStartFS)
|
---|
| 64 | else:
|
---|
| 65 | return (False, flareEnd - self._flareStart)
|
---|
[8] | 66 |
|
---|
| 67 | def wait(self):
|
---|
| 68 | """Wait for the flight to end."""
|
---|
| 69 | with self._endCondition:
|
---|
| 70 | while self._stage!=const.STAGE_END:
|
---|
| 71 | self._endCondition.wait()
|
---|
| 72 |
|
---|
| 73 | #---------------------------------------------------------------------------------------
|
---|