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