source: src/mlx/fs.py@ 74:1aba83981490

Last change on this file since 74:1aba83981490 was 59:a3e0b8455dc8, checked in by István Váradi <ivaradi@…>, 13 years ago

Implemented better connection and connection failure handling.

File size: 5.1 KB
Line 
1# Module for generic flight-simulator interfaces
2
3#-------------------------------------------------------------------------------
4
5import const
6
7import fsuipc
8
9#-------------------------------------------------------------------------------
10
11class 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
28class SimulatorException(Exception):
29 """Exception thrown by the simulator interface for communication failure."""
30
31#-------------------------------------------------------------------------------
32
33def 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
46class 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 - paused: a boolean indicating if the flight simulator is paused for
54 whatever reason (it could be a pause mode, or a menu, a dialog, or a
55 replay, etc.)
56 - trickMode: a boolean indicating if some "trick" mode (e.g. "SLEW" in
57 MSFS) is activated
58 - overspeed: a boolean indicating if the aircraft is in overspeed
59 - stalled: a boolean indicating if the aircraft is stalled
60 - onTheGround: a boolean indicating if the aircraft is on the ground
61 - zfw: the zero-fuel weight in kilograms (float)
62 - grossWeight: the gross weight in kilograms (float)
63 - heading: the heading of the aircraft in degrees (float)
64 - pitch: the pitch of the aircraft in degrees. Positive means pitch down,
65 negative means pitch up (float)
66 - bank: the bank of the aircraft in degrees. Positive means bank left,
67 negative means bank right (float)
68 - ias: the indicated airspeed in knots (float)
69 - mach: the airspeed in mach (float)
70 - groundSpeed: the ground speed (float)
71 - vs: the vertical speed in feet/minutes (float)
72 - radioAltitude: the radio altitude of the aircraft in feet (float)
73 - altitude: the altitude of the aircraft in feet (float)
74 - gLoad: G-load (float)
75 - flapsSet: the selected degrees of the flaps (float)
76 - flaps: the actual degrees of the flaps (float)
77 - fuelWeight[]: the fuel weights in the different tanks in kgs (array of
78 floats of as many items as the number fuel tanks)
79 - n1[]: the N1 values of the turbine engines (array of floats
80 of as many items as the number of engines, present only for aircraft with
81 turbines)
82 - rpm[]: the RPM values of the piston engines (array of floats
83 of as many items as the number of engines, present only for aircraft with
84 pistons)
85 - reverser[]: an array of booleans indicating if the thrust reversers are
86 activated on any of the engines. The number of items equals to the number
87 of engines with a reverser.
88 - navLightsOn: a boolean indicating if the navigation lights are on
89 - antiCollisionLightsOn: a boolean indicating if the anti-collision lights are on
90 - strobeLightsOn: a boolean indicating if the strobe lights are on
91 - landingLightsOn: a boolean indicating if the landing lights are on
92 - pitotHeatOn: a boolean indicating if the pitot heat is on
93 - parking: a boolean indicating if the parking brake is set
94 - gearsDown: a boolean indicating if the gears are down
95 - spoilersArmed: a boolean indicating if the spoilers have been armed for
96 automatic deployment
97 - spoilersExtension: the percentage of how much the spoiler is extended
98 (float)
99 - altimeter: the altimeter setting in hPa (float)
100 - nav1: the frequency of the NAV1 radio in MHz (string)
101 - nav2: the frequency of the NAV1 radio in MHz (string)
102 - squawk: the transponder code (string)
103 - windSpeed: the speed of the wind at the aircraft in knots (float)
104 - windDirection: the direction of the wind at the aircraft in degrees (float)
105
106 FIXME: needed when taxiing only:
107 - payload weight
108
109 FIXME: needed rarely:
110 - latitude, longitude
111 - transporter
112 - visibility
113 """
114
Note: See TracBrowser for help on using the repository browser.