source: xplra/test/basictest.py@ 99:bb320ead601d

Last change on this file since 99:bb320ead601d was 89:69ba1a2b5897, checked in by István Váradi <ivaradi@…>, 12 years ago

Added calls to save the current situation

File size: 6.4 KB
Line 
1# Basic test program for the Python client library
2
3#------------------------------------------------------------------------------
4
5import time
6
7#------------------------------------------------------------------------------
8
9if __name__ == "__main__":
10 from xplra import XPlane, ProtocolException
11
12 xplane = XPlane()
13
14 try:
15 print "Connecting to X-Plane..."
16 xplane.connect()
17 print "Connected to X-Plane."
18 print
19
20 print "Showing a message..."
21 xplane.showMessage("[basictest] Starting tests", 5.0)
22 print
23
24 print "Querying the versions..."
25 (xplaneVersion, xplmVersion, xplraVersion) = xplane.getVersions()
26 print "X-Plane version: %d, XPLM: %d, XPLRA: %03d" % \
27 (xplaneVersion, xplmVersion, xplraVersion)
28 print
29
30 print "Saving the situation..."
31 xplane.saveSituation("output/situations/test.sit")
32 print "Saved the situation"
33 print
34
35 print "Querying the number of the engines..."
36 numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines")
37 print "The number of engines:", numEngines
38 print
39
40 try:
41 print "Querying an invalid dataref..."
42 xplane.getInt("sim/aircraft/engine/num_engines")
43 print
44 print ">>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!"
45 except ProtocolException as e:
46 print "Exception caugth:", str(e)
47 print
48
49 print "Querying the spool time of a jet engine..."
50 spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_jet")
51 print "The spool time:", spoolTime
52 print
53
54 print "Querying the spool time of a propeller..."
55 spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_prop")
56 print "The spool time:", spoolTime
57 print
58
59 print "Querying the coordinates..."
60 latitude = xplane.getDouble("sim/flightmodel/position/latitude")
61 longitude = xplane.getDouble("sim/flightmodel/position/longitude")
62 print "The coordinates: " + `latitude` + ", " + `longitude`
63 print
64
65 print "Querying the aircraft's description..."
66 result = xplane.getByteArray("sim/aircraft/view/acf_descrip")
67 print "The description:", result
68 print
69
70 print "Querying the aircraft's description as a string, with an offset of 3..."
71 result2 = xplane.getString("sim/aircraft/view/acf_descrip", offset = 3);
72 print "Got: '" + result2 + "' (" + `len(result2)` + ")"
73 print result2=="h 8 Q400"
74 print
75
76 print "Querying the aircraft's engine types..."
77 result3 = xplane.getIntArray("sim/aircraft/prop/acf_en_type")
78 print "Got:", result3
79 print
80
81 print "Querying the aircraft's propeller directions..."
82 result5 = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir")
83 print "Got:", result5
84 print
85
86 print "Setting the number of the engines to", numEngines + 1
87 xplane.setInt("sim/aircraft/engine/acf_num_engines", numEngines + 1)
88 numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines")
89 print "The new number of engines:", numEngines
90 print
91
92 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up")
93 print "Setting the aircraft elevator up control from %f to %f..." % \
94 (acfElevUp, acfElevUp + 15.0)
95 xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp + 15.0)
96 acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up")
97 print "The aircraft elevator up control set to", acfElevUp
98 print
99
100 localX = xplane.getDouble("sim/flightmodel/position/local_x")
101 print "Setting the aircraft's local X-coordinate from %f to %f..." % \
102 (localX, localX + 15.0)
103 xplane.setDouble("sim/flightmodel/position/local_x", localX + 15.0)
104 localX = xplane.getDouble("sim/flightmodel/position/local_x")
105 print "The aircraft's local X-coordinate set to", localX
106 print
107
108 numBlades = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades")
109 print "Setting the number of blades"
110 print " from:", numBlades
111 numBlades = [n+2.5 for n in numBlades]
112 print " to:", numBlades
113 xplane.setFloatArray("sim/aircraft/prop/acf_num_blades", numBlades)
114
115 numBlades = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades")
116 print "The result:", numBlades
117 print
118
119 batteryArrayOn = xplane.getIntArray("sim/cockpit/electrical/battery_array_on")
120 print "Setting the batteries"
121 print " from:", batteryArrayOn
122 batteryArrayOn = [1 if b==0 else 0 for b in batteryArrayOn]
123 print " to:", batteryArrayOn
124 xplane.setIntArray("sim/cockpit/electrical/battery_array_on", batteryArrayOn)
125 batteryArrayOn = xplane.getIntArray("sim/cockpit/electrical/battery_array_on")
126 print "The result:", batteryArrayOn
127 print
128
129 tailNum = [0] * 40
130 tailNum[0] = ord('H')
131 tailNum[1] = ord('A')
132 tailNum[2] = ord('-')
133 tailNum[3] = ord('V')
134 tailNum[4] = ord('A')
135 tailNum[5] = ord('I')
136
137 print "Setting the tail number to %s as a byte array..." % (tailNum,)
138 xplane.setByteArray("sim/aircraft/view/acf_tailnum", tailNum)
139 print "The tail number is:", xplane.getString("sim/aircraft/view/acf_tailnum")
140 print
141
142 tailNum1 = "VAIS"
143 print "Setting the tail number to " + tailNum1 + " as a string..."
144 xplane.setString("sim/aircraft/view/acf_tailnum", tailNum1, 40)
145 print "The tail number is:", xplane.getString("sim/aircraft/view/acf_tailnum")
146 print
147
148 print "Preparing for the message tests, sleeping for 5 seconds..."
149 time.sleep(5.0)
150
151 print "Showing a message for 10 seconds..."
152 xplane.showMessage("[basictest] this message appears for 10 seconds", 10.0)
153
154 print "Sleeping for 3 seconds..."
155 time.sleep(3.0)
156
157 print "Showing another message interrupting the previous one for 3 seconds"
158 xplane.showMessage("[basictest] but this message interrupts it, and is displayed for 3 seconds", 3.0)
159
160 print "Sleeping for 5 seconds..."
161 time.sleep(5.0)
162 xplane.showMessage("[basictest] and the tests come to an end!", 5.0)
163
164 except Exception as e:
165 print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
166 finally:
167 xplane.disconnect()
Note: See TracBrowser for help on using the repository browser.