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