1 | # Module for generic flight-simulator interfaces
|
---|
2 |
|
---|
3 | #-------------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | import const
|
---|
6 |
|
---|
7 | import fsuipc
|
---|
8 |
|
---|
9 | #-------------------------------------------------------------------------------
|
---|
10 |
|
---|
11 | class ConnectionListener(object):
|
---|
12 | """Base class for listeners on connections to the flight simulator."""
|
---|
13 | def connected(self, fsType, descriptor):
|
---|
14 | """Called when a connection has been established to the flight
|
---|
15 | simulator of the given type."""
|
---|
16 | print "fs.ConnectionListener.connected, fsType:", fsType, ", descriptor:", descriptor
|
---|
17 |
|
---|
18 | def connectionFailed(self):
|
---|
19 | """Called when the connection could not be established."""
|
---|
20 | print "fs.ConnectionListener.connectionFailed"
|
---|
21 |
|
---|
22 | def disconnected(self):
|
---|
23 | """Called when a connection to the flight simulator has been broken."""
|
---|
24 | print "fs.ConnectionListener.disconnected"
|
---|
25 |
|
---|
26 | #-------------------------------------------------------------------------------
|
---|
27 |
|
---|
28 | class SimulatorException(Exception):
|
---|
29 | """Exception thrown by the simulator interface for communication failure."""
|
---|
30 |
|
---|
31 | #-------------------------------------------------------------------------------
|
---|
32 |
|
---|
33 | def createSimulator(type, connectionListener):
|
---|
34 | """Create a simulator instance for the given simulator type with the given
|
---|
35 | connection listener.
|
---|
36 |
|
---|
37 | The returned object should provide the following members:
|
---|
38 | FIXME: add info
|
---|
39 | """
|
---|
40 | assert type in [const.SIM_MSFS9, const.SIM_MSFSX], \
|
---|
41 | "Only MS Flight Simulator 2004 and X are supported"
|
---|
42 | return fsuipc.Simulator(connectionListener, connectAttempts = 3)
|
---|
43 |
|
---|
44 | #-------------------------------------------------------------------------------
|
---|
45 |
|
---|
46 | class AircraftState(object):
|
---|
47 | """Base class for the aircraft state produced by the aircraft model based
|
---|
48 | on readings from the simulator.
|
---|
49 |
|
---|
50 | The following data members should be provided at least:
|
---|
51 | - timestamp: the simulator time of the measurement in seconds since the
|
---|
52 | epoch (float)
|
---|
53 | - latitude (in degrees, North is positive)
|
---|
54 | - longitude (in degrees, East is positive)
|
---|
55 | - paused: a boolean indicating if the flight simulator is paused for
|
---|
56 | whatever reason (it could be a pause mode, or a menu, a dialog, or a
|
---|
57 | replay, etc.)
|
---|
58 | - trickMode: a boolean indicating if some "trick" mode (e.g. "SLEW" in
|
---|
59 | MSFS) is activated
|
---|
60 | - overspeed: a boolean indicating if the aircraft is in overspeed
|
---|
61 | - stalled: a boolean indicating if the aircraft is stalled
|
---|
62 | - onTheGround: a boolean indicating if the aircraft is on the ground
|
---|
63 | - zfw: the zero-fuel weight in kilograms (float)
|
---|
64 | - grossWeight: the gross weight in kilograms (float)
|
---|
65 | - heading: the heading of the aircraft in degrees (float)
|
---|
66 | - pitch: the pitch of the aircraft in degrees. Positive means pitch down,
|
---|
67 | negative means pitch up (float)
|
---|
68 | - bank: the bank of the aircraft in degrees. Positive means bank left,
|
---|
69 | negative means bank right (float)
|
---|
70 | - ias: the indicated airspeed in knots (float)
|
---|
71 | - mach: the airspeed in mach (float)
|
---|
72 | - groundSpeed: the ground speed (float)
|
---|
73 | - vs: the vertical speed in feet/minutes (float)
|
---|
74 | - radioAltitude: the radio altitude of the aircraft in feet (float)
|
---|
75 | - altitude: the altitude of the aircraft in feet (float)
|
---|
76 | - gLoad: G-load (float)
|
---|
77 | - flapsSet: the selected degrees of the flaps (float)
|
---|
78 | - flaps: the actual degrees of the flaps (float)
|
---|
79 | - fuelWeight[]: the fuel weights in the different tanks in kgs (array of
|
---|
80 | floats of as many items as the number fuel tanks)
|
---|
81 | - n1[]: the N1 values of the turbine engines (array of floats
|
---|
82 | of as many items as the number of engines, present only for aircraft with
|
---|
83 | turbines)
|
---|
84 | - rpm[]: the RPM values of the piston engines (array of floats
|
---|
85 | of as many items as the number of engines, present only for aircraft with
|
---|
86 | pistons)
|
---|
87 | - reverser[]: an array of booleans indicating if the thrust reversers are
|
---|
88 | activated on any of the engines. The number of items equals to the number
|
---|
89 | of engines with a reverser.
|
---|
90 | - navLightsOn: a boolean indicating if the navigation lights are on
|
---|
91 | - antiCollisionLightsOn: a boolean indicating if the anti-collision lights are on
|
---|
92 | - strobeLightsOn: a boolean indicating if the strobe lights are on
|
---|
93 | - landingLightsOn: a boolean indicating if the landing lights are on
|
---|
94 | - pitotHeatOn: a boolean indicating if the pitot heat is on
|
---|
95 | - parking: a boolean indicating if the parking brake is set
|
---|
96 | - gearsDown: a boolean indicating if the gears are down
|
---|
97 | - spoilersArmed: a boolean indicating if the spoilers have been armed for
|
---|
98 | automatic deployment
|
---|
99 | - spoilersExtension: the percentage of how much the spoiler is extended
|
---|
100 | (float)
|
---|
101 | - altimeter: the altimeter setting in hPa (float)
|
---|
102 | - nav1: the frequency of the NAV1 radio in MHz (string)
|
---|
103 | - nav2: the frequency of the NAV1 radio in MHz (string)
|
---|
104 | - squawk: the transponder code (string)
|
---|
105 | - windSpeed: the speed of the wind at the aircraft in knots (float)
|
---|
106 | - windDirection: the direction of the wind at the aircraft in degrees (float)
|
---|
107 |
|
---|
108 | FIXME: needed when taxiing only:
|
---|
109 | - payload weight
|
---|
110 |
|
---|
111 | FIXME: needed rarely:
|
---|
112 | - latitude, longitude
|
---|
113 | - transporter
|
---|
114 | - visibility
|
---|
115 | """
|
---|
116 |
|
---|