source: src/acft.py@ 6:db83d19666dc

Last change on this file since 6:db83d19666dc was 5:90eade9afbcb, checked in by István Váradi <ivaradi@…>, 13 years ago

Added some further data to those queried and reworked a bit the way the model changes are handled

File size: 7.1 KB
RevLine 
[4]1# Module for the simulator-independent aircraft classes
2
3#---------------------------------------------------------------------------------------
4
5import time
6
7#---------------------------------------------------------------------------------------
8
9class Aircraft(object):
10 """Base class for aircraft."""
11 def __init__(self, type):
12 """Construct the aircraft for the given type."""
13 self._type = type
14 self._aircraftState = None
15
16 @property
17 def type(self):
18 """Get the type of the aircraft."""
19 return self._type
20
21 def modelChanged(self, aircraftName, modelName):
22 """Called when the simulator's aircraft changes."""
23 print "Aircraft.modelChanged: aircraftName='%s', modelName='%s'" % \
24 (aircraftName, modelName)
25
26 def handleState(self, aircraftState):
27 """Called when the state of the aircraft changes."""
28 timeStr = time.ctime(aircraftState.timestamp)
29
30 if self._aircraftState is None or \
31 self._aircraftState.paused != aircraftState.paused:
32 print "Aircraft.handleState: %s: paused=%d" % \
33 (timeStr, aircraftState.paused)
34
35 if self._aircraftState is None or \
36 self._aircraftState.trickMode != aircraftState.trickMode:
37 print "Aircraft.handleState: %s: trickMode=%d" % \
38 (timeStr, aircraftState.trickMode)
39
40 if self._aircraftState is None or \
41 self._aircraftState.overspeed != aircraftState.overspeed:
42 print "Aircraft.handleState: %s: overspeed=%d" % \
43 (timeStr, aircraftState.overspeed)
44
45 if self._aircraftState is None or \
46 self._aircraftState.stalled != aircraftState.stalled:
47 print "Aircraft.handleState: %s: stalled=%d" % \
48 (timeStr, aircraftState.stalled)
49
50 if self._aircraftState is None or \
[5]51 self._aircraftState.onTheGround != aircraftState.onTheGround:
52 print "Aircraft.handleState: %s: onTheGround=%d" % \
53 (timeStr, aircraftState.onTheGround)
54
55 if self._aircraftState is None or \
[4]56 self._aircraftState.grossWeight != aircraftState.grossWeight:
57 print "Aircraft.handleState: %s: grossWeight=%f" % \
58 (timeStr, aircraftState.grossWeight)
59
60 if self._aircraftState is None or \
61 self._aircraftState.heading != aircraftState.heading:
62 print "Aircraft.handleState: %s: heading=%f" % \
63 (timeStr, aircraftState.heading)
64
65 if self._aircraftState is None or \
66 self._aircraftState.pitch != aircraftState.pitch:
67 print "Aircraft.handleState: %s: pitch=%f" % \
68 (timeStr, aircraftState.pitch)
69
70 if self._aircraftState is None or \
71 self._aircraftState.bank != aircraftState.bank:
72 print "Aircraft.handleState: %s: bank=%f" % \
73 (timeStr, aircraftState.bank)
74
75 if self._aircraftState is None or \
76 self._aircraftState.ias != aircraftState.ias:
77 print "Aircraft.handleState: %s: ias=%f" % \
78 (timeStr, aircraftState.ias)
79
80 if self._aircraftState is None or \
[5]81 self._aircraftState.groundSpeed != aircraftState.groundSpeed:
82 print "Aircraft.handleState: %s: groundSpeed=%f" % \
83 (timeStr, aircraftState.groundSpeed)
84
85 if self._aircraftState is None or \
[4]86 self._aircraftState.vs != aircraftState.vs:
87 print "Aircraft.handleState: %s: vs=%f" % \
88 (timeStr, aircraftState.vs)
89
90 if self._aircraftState is None or \
91 self._aircraftState.altitude != aircraftState.altitude:
92 print "Aircraft.handleState: %s: altitude=%f" % \
93 (timeStr, aircraftState.altitude)
94
95 if self._aircraftState is None or \
[5]96 self._aircraftState.gLoad != aircraftState.gLoad:
97 print "Aircraft.handleState: %s: gLoad=%f" % \
98 (timeStr, aircraftState.gLoad)
99
100 if self._aircraftState is None or \
[4]101 self._aircraftState.flapsSet != aircraftState.flapsSet:
102 print "Aircraft.handleState: %s: flapsSet=%f" % \
103 (timeStr, aircraftState.flapsSet)
104
105 if self._aircraftState is None or \
106 self._aircraftState.flaps != aircraftState.flaps:
107 print "Aircraft.handleState: %s: flaps=%f" % \
108 (timeStr, aircraftState.flaps)
109
110 if self._aircraftState is None or \
111 self._aircraftState.navLightsOn != aircraftState.navLightsOn:
112 print "Aircraft.handleState: %s: navLightsOn=%d" % \
113 (timeStr, aircraftState.navLightsOn)
114
115 if self._aircraftState is None or \
116 self._aircraftState.antiCollisionLightsOn != aircraftState.antiCollisionLightsOn:
117 print "Aircraft.handleState: %s: antiCollisionLightsOn=%d" % \
118 (timeStr, aircraftState.antiCollisionLightsOn)
119
120 if self._aircraftState is None or \
121 self._aircraftState.strobeLightsOn != aircraftState.strobeLightsOn:
122 print "Aircraft.handleState: %s: strobeLightsOn=%d" % \
123 (timeStr, aircraftState.strobeLightsOn)
124
125 if self._aircraftState is None or \
126 self._aircraftState.landingLightsOn != aircraftState.landingLightsOn:
127 print "Aircraft.handleState: %s: landingLightsOn=%d" % \
128 (timeStr, aircraftState.landingLightsOn)
129
130 if self._aircraftState is None or \
131 self._aircraftState.pitotHeatOn != aircraftState.pitotHeatOn:
132 print "Aircraft.handleState: %s: pitotHeatOn=%d" % \
133 (timeStr, aircraftState.pitotHeatOn)
134
135 if self._aircraftState is None or \
136 self._aircraftState.gearsDown != aircraftState.gearsDown:
137 print "Aircraft.handleState: %s: gearsDown=%f" % \
138 (timeStr, aircraftState.gearsDown)
139
140 if self._aircraftState is None or \
141 self._aircraftState.spoilersArmed != aircraftState.spoilersArmed:
142 print "Aircraft.handleState: %s: spoilersArmed=%f" % \
143 (timeStr, aircraftState.spoilersArmed)
144
145 if self._aircraftState is None or \
146 self._aircraftState.spoilersExtension != aircraftState.spoilersExtension:
147 print "Aircraft.handleState: %s: spoilersExtension=%f" % \
148 (timeStr, aircraftState.spoilersExtension)
149
[5]150 if self._aircraftState is None or \
151 self._aircraftState.altimeter != aircraftState.altimeter:
152 print "Aircraft.handleState: %s: altimeter=%f" % \
153 (timeStr, aircraftState.altimeter)
154
155 if self._aircraftState is None or \
156 self._aircraftState.nav1 != aircraftState.nav1:
157 print "Aircraft.handleState: %s: nav1=%s" % \
158 (timeStr, aircraftState.nav1)
159
160 if self._aircraftState is None or \
161 self._aircraftState.nav2 != aircraftState.nav2:
162 print "Aircraft.handleState: %s: nav2=%s" % \
163 (timeStr, aircraftState.nav2)
164
[4]165 self._aircraftState = aircraftState
166
167#---------------------------------------------------------------------------------------
168
Note: See TracBrowser for help on using the repository browser.