1 | // Copyright (c) 2013 by István Váradi
|
---|
2 |
|
---|
3 | // This file is part of XPLRA, a remote-access plugin for X-Plane
|
---|
4 |
|
---|
5 | // Redistribution and use in source and binary forms, with or without
|
---|
6 | // modification, are permitted provided that the following conditions are met:
|
---|
7 |
|
---|
8 | // 1. Redistributions of source code must retain the above copyright notice, this
|
---|
9 | // list of conditions and the following disclaimer.
|
---|
10 | // 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
11 | // this list of conditions and the following disclaimer in the documentation
|
---|
12 | // and/or other materials provided with the distribution.
|
---|
13 |
|
---|
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
15 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
16 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
17 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
---|
18 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
19 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
20 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
---|
21 | // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
22 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
23 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
24 |
|
---|
25 | // The views and conclusions contained in the software and documentation are those
|
---|
26 | // of the authors and should not be interpreted as representing official policies,
|
---|
27 | // either expressed or implied, of the FreeBSD Project.
|
---|
28 |
|
---|
29 | //------------------------------------------------------------------------------
|
---|
30 |
|
---|
31 | #include "common.h"
|
---|
32 |
|
---|
33 | #include <hu/varadiistvan/xplra/XPlane.h>
|
---|
34 |
|
---|
35 | #include <hu/varadiistvan/scpl/Thread.h>
|
---|
36 |
|
---|
37 | #include <cstdio>
|
---|
38 | #include <cstring>
|
---|
39 |
|
---|
40 | //------------------------------------------------------------------------------
|
---|
41 |
|
---|
42 | using hu::varadiistvan::xplra::XPlane;
|
---|
43 | using hu::varadiistvan::xplra::Exception;
|
---|
44 | using hu::varadiistvan::xplra::ProtocolException;
|
---|
45 |
|
---|
46 | using hu::varadiistvan::scpl::Thread;
|
---|
47 |
|
---|
48 | using std::string;
|
---|
49 |
|
---|
50 | //------------------------------------------------------------------------------
|
---|
51 |
|
---|
52 | int main(int argc, char* argv[])
|
---|
53 | {
|
---|
54 | try {
|
---|
55 | XPlane xplane;
|
---|
56 |
|
---|
57 | printf("Connecting to X-Plane...\n");
|
---|
58 | connectXPlane(xplane, argc, argv);
|
---|
59 | printf("Connected to X-Plane.\n\n");
|
---|
60 |
|
---|
61 | int xplaneVersion = 0;
|
---|
62 | int xplmVersion = 0;
|
---|
63 | int xplraVersion = 0;
|
---|
64 |
|
---|
65 | printf("Showing a message...\n");
|
---|
66 | xplane.showMessage("[basictest] Starting tests", 5.0);
|
---|
67 | printf("\n");
|
---|
68 |
|
---|
69 | printf("Querying the versions...\n");
|
---|
70 | xplane.getVersions(xplaneVersion, xplmVersion, xplraVersion);
|
---|
71 | printf("X-Plane version: %d, XPLM: %d, XPLRA: %03d\n\n",
|
---|
72 | xplaneVersion, xplmVersion, xplraVersion);
|
---|
73 |
|
---|
74 | printf("Saving the situation...\n");
|
---|
75 | xplane.saveSituation("output/situations/test.sit");
|
---|
76 | printf("Saved the situation\n\n");
|
---|
77 |
|
---|
78 | printf("Querying the number of the engines...\n");
|
---|
79 | int numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines");
|
---|
80 | printf("The number of engines: %d\n\n", numEngines);
|
---|
81 |
|
---|
82 | try {
|
---|
83 | printf("Querying an invalid dataref...\n");
|
---|
84 | xplane.getInt("sim/aircraft/engine/num_engines");
|
---|
85 | printf("\n>>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!\n\n");
|
---|
86 | } catch(const ProtocolException& exception) {
|
---|
87 | printf("Exception caugth: %s\n\n", exception.what());
|
---|
88 | }
|
---|
89 |
|
---|
90 | printf("Querying the spool time of a jet engine...\n");
|
---|
91 | float spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_jet");
|
---|
92 | printf("The spool time: %f\n\n", spoolTime);
|
---|
93 |
|
---|
94 | printf("Querying the spool time of a propeller...\n");
|
---|
95 | spoolTime = xplane.getFloat("sim/aircraft/engine/acf_spooltime_prop");
|
---|
96 | printf("The spool time: %f\n\n", spoolTime);
|
---|
97 |
|
---|
98 | printf("Querying the coordinates...\n");
|
---|
99 | double latitude = xplane.getDouble("sim/flightmodel/position/latitude");
|
---|
100 | double longitude = xplane.getDouble("sim/flightmodel/position/longitude");
|
---|
101 | printf("The coordinates: %f, %f\n\n", latitude, longitude);
|
---|
102 |
|
---|
103 | printf("Querying the aircraft's description as an array of a fixed size...\n");
|
---|
104 | uint8_t result[260];
|
---|
105 | size_t length = xplane.getByteArray("sim/aircraft/view/acf_descrip",
|
---|
106 | result, sizeof(result)/sizeof(result[0]));
|
---|
107 | printf("Got %lu bytes, as a string: '%s'\n\n",
|
---|
108 | static_cast<unsigned long>(length), result);
|
---|
109 |
|
---|
110 | printf("Querying the aircraft's description as a dynamically created array...\n");
|
---|
111 | uint8_t* result1 = xplane.getByteArray("sim/aircraft/view/acf_descrip", length);
|
---|
112 | printf("Got %lu bytes, as a string: '%s'\n\n",
|
---|
113 | static_cast<unsigned long>(length), result1);
|
---|
114 |
|
---|
115 | printf("Querying the aircraft's description as a string, with an offset of 3...\n");
|
---|
116 | string result2 = xplane.getString("sim/aircraft/view/acf_descrip", 3);
|
---|
117 | printf("Got: '%s'\n\n", result2.c_str());
|
---|
118 |
|
---|
119 | printf("Querying the aircraft's engine types as an array of a fixed size...\n");
|
---|
120 | int32_t result3[8];
|
---|
121 | length = xplane.getIntArray("sim/aircraft/prop/acf_en_type",
|
---|
122 | result3, sizeof(result3)/sizeof(result3[0]));
|
---|
123 | printf("Got %lu values:", static_cast<unsigned long>(length));
|
---|
124 | for(size_t i = 0; i<length; ++i) {
|
---|
125 | if (i>0) printf(",");
|
---|
126 | printf(" %d", result3[i]);
|
---|
127 | }
|
---|
128 | printf("\n\n");
|
---|
129 |
|
---|
130 | printf("Querying the aircraft's engine types as a dynamically created array...\n");
|
---|
131 | length = 0;
|
---|
132 | int32_t* result4 = xplane.getIntArray("sim/aircraft/prop/acf_en_type", length);
|
---|
133 | printf("Got %lu values:", static_cast<unsigned long>(length));
|
---|
134 | for(size_t i = 0; i<length; ++i) {
|
---|
135 | if (i>0) printf(",");
|
---|
136 | printf(" %d", result4[i]);
|
---|
137 | }
|
---|
138 | printf("\n\n");
|
---|
139 |
|
---|
140 | printf("Querying the aircraft's propeller direction as an array of a fixed size...\n");
|
---|
141 | float result5[8];
|
---|
142 | length = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir",
|
---|
143 | result5, sizeof(result5)/sizeof(result5[0]));
|
---|
144 | printf("Got %lu values:", static_cast<unsigned long>(length));
|
---|
145 | for(size_t i = 0; i<length; ++i) {
|
---|
146 | if (i>0) printf(",");
|
---|
147 | printf(" %f", result5[i]);
|
---|
148 | }
|
---|
149 | printf("\n\n");
|
---|
150 |
|
---|
151 | printf("Querying the aircraft's propeller direction as a dynamically created array...\n");
|
---|
152 | length = 0;
|
---|
153 | float* result6 = xplane.getFloatArray("sim/aircraft/prop/acf_prop_dir", length);
|
---|
154 | printf("Got %lu values:", static_cast<unsigned long>(length));
|
---|
155 | for(size_t i = 0; i<length; ++i) {
|
---|
156 | if (i>0) printf(",");
|
---|
157 | printf(" %f", result6[i]);
|
---|
158 | }
|
---|
159 | printf("\n\n");
|
---|
160 |
|
---|
161 | if (xplaneVersion<12000 || xplaneVersion>12005) {
|
---|
162 | printf("Setting the number of the engines to %d...\n", numEngines + 1);
|
---|
163 | xplane.setInt("sim/aircraft/engine/acf_num_engines", numEngines + 1);
|
---|
164 | numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines");
|
---|
165 | printf("The new number of engines: %d\n\n", numEngines);
|
---|
166 | } else {
|
---|
167 | numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines");
|
---|
168 | printf("Not setting the number of engines, which is: %d\n\n", numEngines);
|
---|
169 | }
|
---|
170 |
|
---|
171 | float acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up");
|
---|
172 | printf("Setting the aircraft elevator up control from %f to %f...\n",
|
---|
173 | acfElevUp, acfElevUp + 15.0);
|
---|
174 | xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp + 15.0);
|
---|
175 | acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up");
|
---|
176 | printf("The aircraft elevator up control set to %f\n\n", acfElevUp);
|
---|
177 |
|
---|
178 | double localX = xplane.getDouble("sim/flightmodel/position/local_x");
|
---|
179 | printf("Setting the aircraft's local X-coordinate from %f to %f...\n",
|
---|
180 | localX, localX + 15.0);
|
---|
181 | xplane.setDouble("sim/flightmodel/position/local_x", localX + 15.0);
|
---|
182 | localX = xplane.getDouble("sim/flightmodel/position/local_x");
|
---|
183 | printf("The aircraft's local X-coordinate set to %f\n\n", localX);
|
---|
184 |
|
---|
185 | float numBlades[8];
|
---|
186 | length = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades",
|
---|
187 | numBlades, sizeof(numBlades)/sizeof(numBlades[0]));
|
---|
188 |
|
---|
189 | printf("Setting the number of blades\n from:");
|
---|
190 | for(size_t i = 0; i<length; ++i) {
|
---|
191 | if (i>0) printf(",");
|
---|
192 | printf(" %f", numBlades[i]);
|
---|
193 | }
|
---|
194 | printf("\n to:");
|
---|
195 | for(size_t i = 0; i<length; ++i) {
|
---|
196 | numBlades[i] += 2.5;
|
---|
197 | if (i>0) printf(",");
|
---|
198 | printf(" %f", numBlades[i]);
|
---|
199 | }
|
---|
200 | printf("\n");
|
---|
201 | xplane.setFloatArray("sim/aircraft/prop/acf_num_blades",
|
---|
202 | numBlades, length);
|
---|
203 | length = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades",
|
---|
204 | numBlades, sizeof(numBlades)/sizeof(numBlades[0]));
|
---|
205 | printf("The result:");
|
---|
206 | for(size_t i = 0; i<length; ++i) {
|
---|
207 | if (i>0) printf(",");
|
---|
208 | printf(" %f", numBlades[i]);
|
---|
209 | }
|
---|
210 | printf("\n\n");
|
---|
211 |
|
---|
212 | int32_t batteryArrayOn[8];
|
---|
213 | length = xplane.getIntArray("sim/cockpit/electrical/battery_array_on",
|
---|
214 | batteryArrayOn,
|
---|
215 | sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0]));
|
---|
216 |
|
---|
217 | printf("Setting the batteries\n from:");
|
---|
218 | for(size_t i = 0; i<length; ++i) {
|
---|
219 | if (i>0) printf(",");
|
---|
220 | printf(" %d", batteryArrayOn[i]);
|
---|
221 | }
|
---|
222 | printf("\n to:");
|
---|
223 | for(size_t i = 0; i<length; ++i) {
|
---|
224 | batteryArrayOn[i] = !batteryArrayOn[i];
|
---|
225 | numBlades[i] += 2.5;
|
---|
226 | if (i>0) printf(",");
|
---|
227 | printf(" %d", batteryArrayOn[i]);
|
---|
228 | }
|
---|
229 | printf("\n");
|
---|
230 | xplane.setIntArray("sim/cockpit/electrical/battery_array_on",
|
---|
231 | batteryArrayOn, length);
|
---|
232 | length = xplane.getIntArray("sim/cockpit/electrical/battery_array_on",
|
---|
233 | batteryArrayOn,
|
---|
234 | sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0]));
|
---|
235 | printf("The result:");
|
---|
236 | for(size_t i = 0; i<length; ++i) {
|
---|
237 | if (i>0) printf(",");
|
---|
238 | printf(" %d", batteryArrayOn[i]);
|
---|
239 | }
|
---|
240 | printf("\n\n");
|
---|
241 |
|
---|
242 | uint8_t tailNum[40];
|
---|
243 | memset(tailNum, 0, sizeof(tailNum));
|
---|
244 | strcpy(reinterpret_cast<char*>(tailNum), "HA-VAI");
|
---|
245 | printf("Setting the tail number to %s as a byte array...\n", tailNum);
|
---|
246 | xplane.setByteArray("sim/aircraft/view/acf_tailnum",
|
---|
247 | tailNum, sizeof(tailNum));
|
---|
248 | printf("The tail number is: '%s'\n\n",
|
---|
249 | xplane.getString("sim/aircraft/view/acf_tailnum").c_str());
|
---|
250 |
|
---|
251 | static const char* tailNum1 = "VAI";
|
---|
252 | printf("Setting the tail number to %s as a string...\n", tailNum1);
|
---|
253 | xplane.setString("sim/aircraft/view/acf_tailnum", tailNum1, 40);
|
---|
254 | printf("The tail number is: '%s'\n\n",
|
---|
255 | xplane.getString("sim/aircraft/view/acf_tailnum").c_str());
|
---|
256 |
|
---|
257 | try {
|
---|
258 | printf("Querying an invalid dataref...\n");
|
---|
259 | xplane.getInt("sim/aircraft/engine/num_engines");
|
---|
260 | printf("\n>>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!\n\n");
|
---|
261 | } catch(const ProtocolException& exception) {
|
---|
262 | printf("Exception caugth: %s\n\n", exception.what());
|
---|
263 | }
|
---|
264 |
|
---|
265 | printf("Preparing for the message tests, sleeping for 5 seconds...\n");
|
---|
266 | Thread::sleep(5*1000);
|
---|
267 |
|
---|
268 | printf("Showing a message for 10 seconds...\n");
|
---|
269 | xplane.showMessage("[basictest] this message appears for 10 seconds", 10.0);
|
---|
270 |
|
---|
271 | printf("Sleeping for 3 seconds...\n");
|
---|
272 | Thread::sleep(3*1000);
|
---|
273 |
|
---|
274 | printf("Showing another message interrupting the previous one for 3 seconds\n");
|
---|
275 | xplane.showMessage("[basictest] but this message interrupts it, and is displayed for 3 seconds", 3.0);
|
---|
276 |
|
---|
277 | printf("Sleeping for 5 seconds...\n");
|
---|
278 | Thread::sleep(5*1000);
|
---|
279 | xplane.showMessage("[basictest] and the tests come to an end!", 5.0);
|
---|
280 |
|
---|
281 | return 0;
|
---|
282 | } catch(const Exception& exception) {
|
---|
283 | printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
|
---|
284 |
|
---|
285 | return 1;
|
---|
286 | }
|
---|
287 | }
|
---|
288 |
|
---|
289 | //------------------------------------------------------------------------------
|
---|
290 |
|
---|
291 | // Local Variables:
|
---|
292 | // mode: C++
|
---|
293 | // c-basic-offset: 4
|
---|
294 | // indent-tabs-mode: nil
|
---|
295 | // End:
|
---|