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 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 |
|
---|
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."""
|
---|
25 | def __init__(self, logger, gui):
|
---|
26 | """Construct the flight."""
|
---|
27 | self._stage = None
|
---|
28 | self.logger = logger
|
---|
29 | self._gui = gui
|
---|
30 |
|
---|
31 | self.cruiseAltitude = None
|
---|
32 | self.flareTimeFromFS = False
|
---|
33 | self.entranceExam = False
|
---|
34 | self.zfw = 50000
|
---|
35 |
|
---|
36 | self.options = Options()
|
---|
37 |
|
---|
38 | self.aircraftType = None
|
---|
39 | self.aircraft = None
|
---|
40 | self.simulator = None
|
---|
41 |
|
---|
42 | self._endCondition = threading.Condition()
|
---|
43 |
|
---|
44 | self._flareStart = None
|
---|
45 | self._flareStartFS = None
|
---|
46 |
|
---|
47 | @property
|
---|
48 | def stage(self):
|
---|
49 | """Get the flight stage."""
|
---|
50 | return self._stage
|
---|
51 |
|
---|
52 | def setStage(self, timestamp, stage):
|
---|
53 | """Set the flight stage.
|
---|
54 |
|
---|
55 | Returns if the stage has really changed."""
|
---|
56 | if stage!=self._stage:
|
---|
57 | self._stage = stage
|
---|
58 | self.logger.stage(timestamp, stage)
|
---|
59 | if stage==const.STAGE_END:
|
---|
60 | with self._endCondition:
|
---|
61 | self._endCondition.notify()
|
---|
62 | return True
|
---|
63 | else:
|
---|
64 | return False
|
---|
65 |
|
---|
66 | def flareStarted(self, flareStart, flareStartFS):
|
---|
67 | """Called when the flare time has started."""
|
---|
68 | self._flareStart = flareStart
|
---|
69 | self._flareStartFS = flareStartFS
|
---|
70 |
|
---|
71 | def flareFinished(self, flareEnd, flareEndFS):
|
---|
72 | """Called when the flare time has ended.
|
---|
73 |
|
---|
74 | Return a tuple of the following items:
|
---|
75 | - a boolean indicating if FS time is used
|
---|
76 | - the flare time
|
---|
77 | """
|
---|
78 | if self.flareTimeFromFS:
|
---|
79 | return (True, flareEndFS - self._flareStartFS)
|
---|
80 | else:
|
---|
81 | return (False, flareEnd - self._flareStart)
|
---|
82 |
|
---|
83 | def wait(self):
|
---|
84 | """Wait for the flight to end."""
|
---|
85 | with self._endCondition:
|
---|
86 | while self._stage!=const.STAGE_END:
|
---|
87 | self._endCondition.wait(1)
|
---|
88 |
|
---|
89 | #---------------------------------------------------------------------------------------
|
---|