[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] | 11 | class Options(object):
|
---|
| 12 | """Various configuration options."""
|
---|
| 13 | def __init__(self):
|
---|
| 14 | """Construct the object with default values."""
|
---|
| 15 | self.fs2Crew = False
|
---|
| 16 | self.compensation = None
|
---|
| 17 |
|
---|
| 18 | #---------------------------------------------------------------------------------------
|
---|
| 19 |
|
---|
[8] | 20 | class Flight(object):
|
---|
| 21 | """The object with the global flight state.
|
---|
| 22 |
|
---|
| 23 | It is also the hub for the other main objects participating in the handling of
|
---|
| 24 | the flight."""
|
---|
[29] | 25 | def __init__(self, logger, gui):
|
---|
[8] | 26 | """Construct the flight."""
|
---|
| 27 | self._stage = None
|
---|
| 28 | self.logger = logger
|
---|
[29] | 29 | self._gui = gui
|
---|
[11] | 30 |
|
---|
[31] | 31 | gui.resetFlightStatus()
|
---|
| 32 |
|
---|
[8] | 33 | self.cruiseAltitude = None
|
---|
[9] | 34 | self.flareTimeFromFS = False
|
---|
[11] | 35 | self.entranceExam = False
|
---|
| 36 | self.zfw = 50000
|
---|
| 37 |
|
---|
| 38 | self.options = Options()
|
---|
| 39 |
|
---|
[8] | 40 | self.aircraftType = None
|
---|
| 41 | self.aircraft = None
|
---|
| 42 | self.simulator = None
|
---|
| 43 |
|
---|
| 44 | self._endCondition = threading.Condition()
|
---|
| 45 |
|
---|
[9] | 46 | self._flareStart = None
|
---|
| 47 | self._flareStartFS = None
|
---|
| 48 |
|
---|
[8] | 49 | @property
|
---|
| 50 | def stage(self):
|
---|
| 51 | """Get the flight stage."""
|
---|
| 52 | return self._stage
|
---|
| 53 |
|
---|
| 54 | def setStage(self, timestamp, stage):
|
---|
[9] | 55 | """Set the flight stage.
|
---|
| 56 |
|
---|
| 57 | Returns if the stage has really changed."""
|
---|
[8] | 58 | if stage!=self._stage:
|
---|
| 59 | self._stage = stage
|
---|
| 60 | self.logger.stage(timestamp, stage)
|
---|
[31] | 61 | self._gui.setStage(stage)
|
---|
[8] | 62 | if stage==const.STAGE_END:
|
---|
| 63 | with self._endCondition:
|
---|
| 64 | self._endCondition.notify()
|
---|
[9] | 65 | return True
|
---|
| 66 | else:
|
---|
| 67 | return False
|
---|
| 68 |
|
---|
[30] | 69 | def handleFault(self, faultID, timestamp, what, score):
|
---|
| 70 | """Handle the given fault.
|
---|
| 71 |
|
---|
| 72 | faultID as a unique ID for the given kind of fault. If another fault of
|
---|
| 73 | this ID has been reported earlier, it will be reported again only if
|
---|
| 74 | the score is greater than last time. This ID can be, e.g. the checker
|
---|
| 75 | the report comes from."""
|
---|
| 76 | self.logger.fault(faultID, timestamp, what, score)
|
---|
[31] | 77 | self._gui.setRating(self.logger.getRating())
|
---|
[30] | 78 |
|
---|
| 79 | def handleNoGo(self, faultID, timestamp, what, shortReason):
|
---|
| 80 | """Handle a No-Go fault."""
|
---|
| 81 | self.logger.noGo(faultID, timestamp, what)
|
---|
[31] | 82 | self._gui.setNoGo(shortReason)
|
---|
[30] | 83 |
|
---|
[9] | 84 | def flareStarted(self, flareStart, flareStartFS):
|
---|
| 85 | """Called when the flare time has started."""
|
---|
| 86 | self._flareStart = flareStart
|
---|
| 87 | self._flareStartFS = flareStartFS
|
---|
| 88 |
|
---|
| 89 | def flareFinished(self, flareEnd, flareEndFS):
|
---|
| 90 | """Called when the flare time has ended.
|
---|
| 91 |
|
---|
| 92 | Return a tuple of the following items:
|
---|
| 93 | - a boolean indicating if FS time is used
|
---|
| 94 | - the flare time
|
---|
| 95 | """
|
---|
| 96 | if self.flareTimeFromFS:
|
---|
| 97 | return (True, flareEndFS - self._flareStartFS)
|
---|
| 98 | else:
|
---|
| 99 | return (False, flareEnd - self._flareStart)
|
---|
[8] | 100 |
|
---|
| 101 | def wait(self):
|
---|
| 102 | """Wait for the flight to end."""
|
---|
| 103 | with self._endCondition:
|
---|
| 104 | while self._stage!=const.STAGE_END:
|
---|
[14] | 105 | self._endCondition.wait(1)
|
---|
[8] | 106 |
|
---|
| 107 | #---------------------------------------------------------------------------------------
|
---|