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