source: xplra/test/multigettest.py@ 114:0e60b2a26b42

Last change on this file since 114:0e60b2a26b42 was 41:a3f71b4eaca1, checked in by István Váradi <ivaradi@…>, 12 years ago

Added test cases for the 'unknown dataref' error with position information

File size: 6.4 KB
Line 
1# Multi-dataref query test program for the Python client library
2
3#------------------------------------------------------------------------------
4
5if __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 wrongGetter = xplane.createMultiGetter();
21 wrongGetter.addInt("sim/time/local_date_days");
22 wrongGetter.addInt("sim/time/paused");
23 wrongGetter.addInt("sim/time/hello_te_lo");
24 wrongGetter.addFloat("sim/time/zulu_time_sec");
25 wrongGetter.addInt("sim/operation/prefs/replay_mode");
26
27 print "Executing a multi-dataref getter with an invalid dataref..."
28 try:
29 wrongGetter.execute();
30 print ">>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!"
31 except ProtocolException, e:
32 print "Caught protocol exception: " + str(e)
33 print
34
35 print "Executing a registered multi-dataref getter with an invalid dataref..."
36 wrongGetter.register()
37 try:
38 wrongGetter.execute();
39 print ">>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!"
40 except ProtocolException, e:
41 print "Caught protocol exception: " + str(e)
42 print
43
44 getter = xplane.createMultiGetter()
45
46 tailnumID = getter.addByteArray("sim/aircraft/view/acf_tailnum", 40)
47 daysID = getter.addInt("sim/time/local_date_days")
48 zuluSecID = getter.addFloat("sim/time/zulu_time_sec")
49 pausedID = getter.addInt("sim/time/paused")
50 latitudeID = getter.addDouble("sim/flightmodel/position/latitude")
51 longitudeID = getter.addDouble("sim/flightmodel/position/longitude")
52 replayID = getter.addInt("sim/operation/prefs/replay_mode")
53 overspeedID = getter.addInt("sim/flightmodel/failures/over_vne")
54 stalledID = getter.addInt("sim/flightmodel/failures/stallwarning")
55 onTheGroundID = getter.addInt("sim/flightmodel/failures/onground_any")
56 emptyWeightID = getter.addFloat("sim/aircraft/weight/acf_m_empty")
57 payloadWeightID = getter.addFloat("sim/flightmodel/weight/m_fixed")
58 grossWeightID = getter.addFloat("sim/flightmodel/weight/m_total")
59 headingID = getter.addFloat("sim/flightmodel/position/psi")
60 pitchID = getter.addFloat("sim/flightmodel/position/theta")
61 bankID = getter.addFloat("sim/flightmodel/position/phi")
62 iasID = getter.addFloat("sim/flightmodel/position/indicated_airspeed2")
63 machID = getter.addFloat("sim/flightmodel/misc/machno")
64 groundSpeedID = getter.addFloat("sim/flightmodel/position/groundspeed")
65 vsID = getter.addFloat("sim/flightmodel/position/vh_ind_fpm2")
66 radioAltitudeID = getter.addFloat("sim/flightmodel/position/y_agl")
67 altitudeID = getter.addFloat("sim/flightmodel/position/elevation")
68 gLoadID = getter.addFloat("sim/flightmodel/forces/g_nrml")
69 flapsControlID = getter.addFloat("sim/flightmodel/controls/flaprqst")
70 flapsLeftID = getter.addFloat("sim/flightmodel/controls/flaprat")
71 flapsRightID = getter.addFloat("sim/flightmodel/controls/flap2rat")
72 navLightsID = getter.addInt("sim/cockpit/electrical/nav_lights_on")
73 beaconLightsID = getter.addInt("sim/cockpit/electrical/beacon_lights_on")
74 strobeLightsID = getter.addInt("sim/cockpit/electrical/strobe_lights_on")
75 landingLightsID = getter.addInt("sim/cockpit/electrical/landing_lights_on")
76 pitotID = getter.addInt("sim/cockpit/switches/pitot_heat_on")
77 parkingID = getter.addFloat("sim/flightmodel/controls/parkbrake")
78 gearControlID = getter.addInt("sim/cockpit2/controls/gear_handle_down")
79 noseGearID = getter.addFloatArray("sim/flightmodel2/gear/deploy_ratio", 1)
80 altimeterID = getter.addFloat("sim/cockpit/misc/barometer_setting")
81 qnhID = getter.addFloat("sim/flightmodel/misc/Qstatic")
82 navTypesID = getter.addIntArray("sim/cockpit/radios/nav_type", 6)
83 busVoltsID = getter.addFloatArray("sim/cockpit2/electrical/bus_volts", 4)
84
85 if dontregister:
86 getter.finalize()
87 else:
88 print "Registering getter..."
89 getter.register()
90 print "Registered getter."
91 print
92
93 while True:
94 getter.execute()
95 print "tail number: '%s', days: %d, zuluSec: %f" % \
96 (getter.getString(tailnumID), getter[daysID], getter[zuluSecID])
97 print "paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d" % \
98 (getter[pausedID], getter[replayID], getter[overspeedID],
99 getter[stalledID], getter[onTheGroundID])
100 print "emptyWeight=%f, payloadWeight=%f, grossWeight=%f" % \
101 (getter[emptyWeightID], getter[payloadWeightID],
102 getter[grossWeightID])
103 print "latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f" % \
104 (getter[latitudeID], getter[longitudeID],
105 getter[radioAltitudeID]/.3048, getter[altitudeID]/.3048,
106 getter[gLoadID])
107 print "heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f" % \
108 (getter[headingID], getter[pitchID], getter[bankID],
109 getter[iasID], getter[machID], getter[groundSpeedID],
110 getter[vsID]);
111 print "flapsControl=%f, flapsLeft=%f, flapsRight=%f" % \
112 (getter[flapsControlID], getter[flapsLeftID],
113 getter[flapsRightID]);
114 print "Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d" % \
115 (getter[navLightsID], getter[beaconLightsID],
116 getter[strobeLightsID], getter[landingLightsID]);
117 print "pitot: %d, parking: %f, gearControl: %d, noseGear: %f" % \
118 (getter[pitotID], getter[parkingID],
119 getter[gearControlID], getter[noseGearID][0]);
120 print "altimeter: %f, qnh: %f" % \
121 (getter[altimeterID], getter[qnhID]);
122 print "NAV types:", getter[navTypesID]
123 print "bus voltages:", getter[busVoltsID]
124 print
125 time.sleep(1.0)
126
127 except Exception as e:
128 print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
129 finally:
130 xplane.disconnect()
Note: See TracBrowser for help on using the repository browser.