source: src/flight.py@ 16:eb7e301a7d8b

Last change on this file since 16:eb7e301a7d8b was 14:fc4a47645f76, checked in by István Váradi <ivaradi@…>, 13 years ago

The waiting uses timeout so that the test program can be killed with Ctrl-C

File size: 2.6 KB
RevLine 
[8]1# Module related to the high-level tracking of the flight
2
3#---------------------------------------------------------------------------------------
4
5import const
6
7import threading
8
9#---------------------------------------------------------------------------------------
10
[11]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
[8]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):
26 """Construct the flight."""
27 self._stage = None
28 self.logger = logger
[11]29
[8]30 self.cruiseAltitude = None
[9]31 self.flareTimeFromFS = False
[11]32 self.entranceExam = False
33 self.zfw = 50000
34
35 self.options = Options()
36
[8]37 self.aircraftType = None
38 self.aircraft = None
39 self.simulator = None
40
41 self._endCondition = threading.Condition()
42
[9]43 self._flareStart = None
44 self._flareStartFS = None
45
[8]46 @property
47 def stage(self):
48 """Get the flight stage."""
49 return self._stage
50
51 def setStage(self, timestamp, stage):
[9]52 """Set the flight stage.
53
54 Returns if the stage has really changed."""
[8]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()
[9]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)
[8]81
82 def wait(self):
83 """Wait for the flight to end."""
84 with self._endCondition:
85 while self._stage!=const.STAGE_END:
[14]86 self._endCondition.wait(1)
[8]87
88#---------------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.