source: src/mlx/fs.py@ 59:a3e0b8455dc8

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

Implemented better connection and connection failure handling.

File size: 5.1 KB
RevLine 
[3]1# Module for generic flight-simulator interfaces
2
[4]3#-------------------------------------------------------------------------------
[3]4
[4]5import const
[3]6
[59]7import fsuipc
8
[4]9#-------------------------------------------------------------------------------
[3]10
[4]11class ConnectionListener(object):
[3]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
[59]18 def connectionFailed(self):
19 """Called when the connection could not be established."""
20 print "fs.ConnectionListener.connectionFailed"
21
[3]22 def disconnected(self):
23 """Called when a connection to the flight simulator has been broken."""
24 print "fs.ConnectionListener.disconnected"
25
[4]26#-------------------------------------------------------------------------------
27
28class SimulatorException(Exception):
29 """Exception thrown by the simulator interface for communication failure."""
30
31#-------------------------------------------------------------------------------
32
[15]33def createSimulator(type, connectionListener):
[4]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 """
[15]40 assert type in [const.SIM_MSFS9, const.SIM_MSFSX], \
41 "Only MS Flight Simulator 2004 and X are supported"
[59]42 return fsuipc.Simulator(connectionListener, connectAttempts = 3)
[4]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
[9]61 - zfw: the zero-fuel weight in kilograms (float)
[4]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)
[9]69 - mach: the airspeed in mach (float)
[5]70 - groundSpeed: the ground speed (float)
[4]71 - vs: the vertical speed in feet/minutes (float)
[8]72 - radioAltitude: the radio altitude of the aircraft in feet (float)
[4]73 - altitude: the altitude of the aircraft in feet (float)
[5]74 - gLoad: G-load (float)
[4]75 - flapsSet: the selected degrees of the flaps (float)
76 - flaps: the actual degrees of the flaps (float)
[5]77 - fuelWeight[]: the fuel weights in the different tanks in kgs (array of
78 floats of as many items as the number fuel tanks)
[4]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
[11]87 of engines with a reverser.
[4]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
[15]91 - landingLightsOn: a boolean indicating if the landing lights are on
[4]92 - pitotHeatOn: a boolean indicating if the pitot heat is on
[8]93 - parking: a boolean indicating if the parking brake is set
[4]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)
[5]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)
[15]102 - squawk: the transponder code (string)
[9]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)
[4]105
106 FIXME: needed when taxiing only:
[5]107 - payload weight
[4]108
[5]109 FIXME: needed rarely:
110 - latitude, longitude
111 - transporter
112 - visibility
[4]113 """
114
Note: See TracBrowser for help on using the repository browser.