source: src/mlx/flight.py@ 55:f6a3ee5f8855

Last change on this file since 55:f6a3ee5f8855 was 31:c9ed7a60bf3b, checked in by István Váradi <ivaradi@…>, 13 years ago

Various information about the flight is displayed in the status icon's tooltip or menu

File size: 3.3 KB
Line 
1# Module related to the high-level tracking of the flight
2
3#---------------------------------------------------------------------------------------
4
5import const
6
7import threading
8
9#---------------------------------------------------------------------------------------
10
11class 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
20class 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 gui.resetFlightStatus()
32
33 self.cruiseAltitude = None
34 self.flareTimeFromFS = False
35 self.entranceExam = False
36 self.zfw = 50000
37
38 self.options = Options()
39
40 self.aircraftType = None
41 self.aircraft = None
42 self.simulator = None
43
44 self._endCondition = threading.Condition()
45
46 self._flareStart = None
47 self._flareStartFS = None
48
49 @property
50 def stage(self):
51 """Get the flight stage."""
52 return self._stage
53
54 def setStage(self, timestamp, stage):
55 """Set the flight stage.
56
57 Returns if the stage has really changed."""
58 if stage!=self._stage:
59 self._stage = stage
60 self.logger.stage(timestamp, stage)
61 self._gui.setStage(stage)
62 if stage==const.STAGE_END:
63 with self._endCondition:
64 self._endCondition.notify()
65 return True
66 else:
67 return False
68
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)
77 self._gui.setRating(self.logger.getRating())
78
79 def handleNoGo(self, faultID, timestamp, what, shortReason):
80 """Handle a No-Go fault."""
81 self.logger.noGo(faultID, timestamp, what)
82 self._gui.setNoGo(shortReason)
83
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)
100
101 def wait(self):
102 """Wait for the flight to end."""
103 with self._endCondition:
104 while self._stage!=const.STAGE_END:
105 self._endCondition.wait(1)
106
107#---------------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.