[34] | 1 | # Multi-dataref query test program for the Python client library
|
---|
| 2 |
|
---|
| 3 | #------------------------------------------------------------------------------
|
---|
| 4 |
|
---|
| 5 | if __name__ == "__main__":
|
---|
| 6 | import sys
|
---|
| 7 | import time
|
---|
| 8 | from xplra import XPlane, ProtocolException
|
---|
| 9 |
|
---|
| 10 | xplane = XPlane()
|
---|
| 11 |
|
---|
| 12 | dontregister = "dontregister" in sys.argv
|
---|
| 13 |
|
---|
| 14 | try:
|
---|
| 15 | print "Connecting to X-Plane..."
|
---|
| 16 | xplane.connect()
|
---|
| 17 | print "Connected to X-Plane."
|
---|
| 18 | print
|
---|
| 19 |
|
---|
| 20 | getter = xplane.createMultiGetter()
|
---|
| 21 |
|
---|
| 22 | tailnumID = getter.addByteArray("sim/aircraft/view/acf_tailnum", 40)
|
---|
| 23 | daysID = getter.addInt("sim/time/local_date_days")
|
---|
| 24 | zuluSecID = getter.addFloat("sim/time/zulu_time_sec")
|
---|
| 25 | pausedID = getter.addInt("sim/time/paused")
|
---|
| 26 | latitudeID = getter.addDouble("sim/flightmodel/position/latitude")
|
---|
| 27 | longitudeID = getter.addDouble("sim/flightmodel/position/longitude")
|
---|
| 28 | replayID = getter.addInt("sim/operation/prefs/replay_mode")
|
---|
| 29 | overspeedID = getter.addInt("sim/flightmodel/failures/over_vne")
|
---|
| 30 | stalledID = getter.addInt("sim/flightmodel/failures/stallwarning")
|
---|
| 31 | onTheGroundID = getter.addInt("sim/flightmodel/failures/onground_any")
|
---|
| 32 | emptyWeightID = getter.addFloat("sim/aircraft/weight/acf_m_empty")
|
---|
| 33 | payloadWeightID = getter.addFloat("sim/flightmodel/weight/m_fixed")
|
---|
| 34 | grossWeightID = getter.addFloat("sim/flightmodel/weight/m_total")
|
---|
| 35 | headingID = getter.addFloat("sim/flightmodel/position/psi")
|
---|
| 36 | pitchID = getter.addFloat("sim/flightmodel/position/theta")
|
---|
| 37 | bankID = getter.addFloat("sim/flightmodel/position/phi")
|
---|
| 38 | iasID = getter.addFloat("sim/flightmodel/position/indicated_airspeed2")
|
---|
| 39 | machID = getter.addFloat("sim/flightmodel/misc/machno")
|
---|
| 40 | groundSpeedID = getter.addFloat("sim/flightmodel/position/groundspeed")
|
---|
| 41 | vsID = getter.addFloat("sim/flightmodel/position/vh_ind_fpm2")
|
---|
| 42 | radioAltitudeID = getter.addFloat("sim/flightmodel/position/y_agl")
|
---|
| 43 | altitudeID = getter.addFloat("sim/flightmodel/position/elevation")
|
---|
| 44 | gLoadID = getter.addFloat("sim/flightmodel/forces/g_nrml")
|
---|
| 45 | flapsControlID = getter.addFloat("sim/flightmodel/controls/flaprqst")
|
---|
| 46 | flapsLeftID = getter.addFloat("sim/flightmodel/controls/flaprat")
|
---|
| 47 | flapsRightID = getter.addFloat("sim/flightmodel/controls/flap2rat")
|
---|
| 48 | navLightsID = getter.addInt("sim/cockpit/electrical/nav_lights_on")
|
---|
| 49 | beaconLightsID = getter.addInt("sim/cockpit/electrical/beacon_lights_on")
|
---|
| 50 | strobeLightsID = getter.addInt("sim/cockpit/electrical/strobe_lights_on")
|
---|
| 51 | landingLightsID = getter.addInt("sim/cockpit/electrical/landing_lights_on")
|
---|
| 52 | pitotID = getter.addInt("sim/cockpit/switches/pitot_heat_on")
|
---|
| 53 | parkingID = getter.addFloat("sim/flightmodel/controls/parkbrake")
|
---|
| 54 | gearControlID = getter.addInt("sim/cockpit2/controls/gear_handle_down")
|
---|
| 55 | noseGearID = getter.addFloatArray("sim/flightmodel2/gear/deploy_ratio", 1)
|
---|
| 56 | altimeterID = getter.addFloat("sim/cockpit/misc/barometer_setting")
|
---|
| 57 | qnhID = getter.addFloat("sim/flightmodel/misc/Qstatic")
|
---|
| 58 | navTypesID = getter.addIntArray("sim/cockpit/radios/nav_type", 6)
|
---|
| 59 | busVoltsID = getter.addFloatArray("sim/cockpit2/electrical/bus_volts", 4)
|
---|
| 60 |
|
---|
| 61 | if dontregister:
|
---|
| 62 | getter.finalize()
|
---|
| 63 | else:
|
---|
| 64 | print "Registering getter..."
|
---|
| 65 | getter.register()
|
---|
| 66 | print "Registered getter."
|
---|
| 67 | print
|
---|
| 68 |
|
---|
| 69 | while True:
|
---|
| 70 | getter.execute()
|
---|
| 71 | print "tail number: '%s', days: %d, zuluSec: %f" % \
|
---|
| 72 | (getter.getString(tailnumID), getter[daysID], getter[zuluSecID])
|
---|
| 73 | print "paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d" % \
|
---|
| 74 | (getter[pausedID], getter[replayID], getter[overspeedID],
|
---|
| 75 | getter[stalledID], getter[onTheGroundID])
|
---|
| 76 | print "emptyWeight=%f, payloadWeight=%f, grossWeight=%f" % \
|
---|
| 77 | (getter[emptyWeightID], getter[payloadWeightID],
|
---|
| 78 | getter[grossWeightID])
|
---|
| 79 | print "latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f" % \
|
---|
| 80 | (getter[latitudeID], getter[longitudeID],
|
---|
| 81 | getter[radioAltitudeID]/.3048, getter[altitudeID]/.3048,
|
---|
| 82 | getter[gLoadID])
|
---|
| 83 | print "heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f" % \
|
---|
| 84 | (getter[headingID], getter[pitchID], getter[bankID],
|
---|
| 85 | getter[iasID], getter[machID], getter[groundSpeedID],
|
---|
| 86 | getter[vsID]);
|
---|
| 87 | print "flapsControl=%f, flapsLeft=%f, flapsRight=%f" % \
|
---|
| 88 | (getter[flapsControlID], getter[flapsLeftID],
|
---|
| 89 | getter[flapsRightID]);
|
---|
| 90 | print "Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d" % \
|
---|
| 91 | (getter[navLightsID], getter[beaconLightsID],
|
---|
| 92 | getter[strobeLightsID], getter[landingLightsID]);
|
---|
| 93 | print "pitot: %d, parking: %f, gearControl: %d, noseGear: %f" % \
|
---|
| 94 | (getter[pitotID], getter[parkingID],
|
---|
| 95 | getter[gearControlID], getter[noseGearID][0]);
|
---|
| 96 | print "altimeter: %f, qnh: %f" % \
|
---|
| 97 | (getter[altimeterID], getter[qnhID]);
|
---|
| 98 | print "NAV types:", getter[navTypesID].tolist()
|
---|
| 99 | print "bus voltages:", getter[busVoltsID].tolist()
|
---|
| 100 | print
|
---|
| 101 | time.sleep(1.0)
|
---|
| 102 |
|
---|
| 103 | except Exception as e:
|
---|
| 104 | print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
|
---|
| 105 | finally:
|
---|
| 106 | xplane.disconnect()
|
---|