[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 |
|
---|
[9] | 33 | self.flareTimeFromFS = False
|
---|
[11] | 34 | self.entranceExam = False
|
---|
| 35 |
|
---|
| 36 | self.options = Options()
|
---|
| 37 |
|
---|
[8] | 38 | self.aircraftType = None
|
---|
| 39 | self.aircraft = None
|
---|
| 40 | self.simulator = None
|
---|
| 41 |
|
---|
| 42 | self._endCondition = threading.Condition()
|
---|
| 43 |
|
---|
[9] | 44 | self._flareStart = None
|
---|
| 45 | self._flareStartFS = None
|
---|
| 46 |
|
---|
[8] | 47 | @property
|
---|
| 48 | def stage(self):
|
---|
| 49 | """Get the flight stage."""
|
---|
| 50 | return self._stage
|
---|
| 51 |
|
---|
[84] | 52 | @property
|
---|
| 53 | def zfw(self):
|
---|
| 54 | """Get the Zero-Fuel Weight of the flight."""
|
---|
| 55 | return self._gui.zfw
|
---|
| 56 |
|
---|
| 57 | @property
|
---|
| 58 | def cruiseAltitude(self):
|
---|
| 59 | """Get the cruise altitude of the flight."""
|
---|
| 60 | return self._gui.cruiseAltitude
|
---|
| 61 |
|
---|
| 62 | @property
|
---|
| 63 | def v1(self):
|
---|
| 64 | """Get the V1 speed of the flight."""
|
---|
| 65 | return self._gui.v1
|
---|
| 66 |
|
---|
| 67 | @property
|
---|
| 68 | def vr(self):
|
---|
| 69 | """Get the Vr speed of the flight."""
|
---|
| 70 | return self._gui.vr
|
---|
| 71 |
|
---|
| 72 | @property
|
---|
| 73 | def v2(self):
|
---|
| 74 | """Get the V2 speed of the flight."""
|
---|
| 75 | return self._gui.v2
|
---|
| 76 |
|
---|
[8] | 77 | def setStage(self, timestamp, stage):
|
---|
[9] | 78 | """Set the flight stage.
|
---|
| 79 |
|
---|
| 80 | Returns if the stage has really changed."""
|
---|
[8] | 81 | if stage!=self._stage:
|
---|
| 82 | self._stage = stage
|
---|
[84] | 83 | self._gui.setStage(stage)
|
---|
[8] | 84 | self.logger.stage(timestamp, stage)
|
---|
| 85 | if stage==const.STAGE_END:
|
---|
| 86 | with self._endCondition:
|
---|
| 87 | self._endCondition.notify()
|
---|
[9] | 88 | return True
|
---|
| 89 | else:
|
---|
| 90 | return False
|
---|
| 91 |
|
---|
[30] | 92 | def handleFault(self, faultID, timestamp, what, score):
|
---|
| 93 | """Handle the given fault.
|
---|
| 94 |
|
---|
| 95 | faultID as a unique ID for the given kind of fault. If another fault of
|
---|
| 96 | this ID has been reported earlier, it will be reported again only if
|
---|
| 97 | the score is greater than last time. This ID can be, e.g. the checker
|
---|
| 98 | the report comes from."""
|
---|
| 99 | self.logger.fault(faultID, timestamp, what, score)
|
---|
[31] | 100 | self._gui.setRating(self.logger.getRating())
|
---|
[30] | 101 |
|
---|
| 102 | def handleNoGo(self, faultID, timestamp, what, shortReason):
|
---|
| 103 | """Handle a No-Go fault."""
|
---|
| 104 | self.logger.noGo(faultID, timestamp, what)
|
---|
[31] | 105 | self._gui.setNoGo(shortReason)
|
---|
[30] | 106 |
|
---|
[9] | 107 | def flareStarted(self, flareStart, flareStartFS):
|
---|
| 108 | """Called when the flare time has started."""
|
---|
| 109 | self._flareStart = flareStart
|
---|
| 110 | self._flareStartFS = flareStartFS
|
---|
| 111 |
|
---|
| 112 | def flareFinished(self, flareEnd, flareEndFS):
|
---|
| 113 | """Called when the flare time has ended.
|
---|
| 114 |
|
---|
| 115 | Return a tuple of the following items:
|
---|
| 116 | - a boolean indicating if FS time is used
|
---|
| 117 | - the flare time
|
---|
| 118 | """
|
---|
| 119 | if self.flareTimeFromFS:
|
---|
| 120 | return (True, flareEndFS - self._flareStartFS)
|
---|
| 121 | else:
|
---|
| 122 | return (False, flareEnd - self._flareStart)
|
---|
[8] | 123 |
|
---|
| 124 | def wait(self):
|
---|
| 125 | """Wait for the flight to end."""
|
---|
| 126 | with self._endCondition:
|
---|
| 127 | while self._stage!=const.STAGE_END:
|
---|
[14] | 128 | self._endCondition.wait(1)
|
---|
[8] | 129 |
|
---|
| 130 | #---------------------------------------------------------------------------------------
|
---|