source: xplra/test/multigetctest.c@ 64:29a745311929

Last change on this file since 64:29a745311929 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: 16.5 KB
Line 
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 <hu/varadiistvan/xplra/xplra.h>
32
33#include <stdlib.h>
34#include <stdio.h>
35#include <string.h>
36
37#ifdef _WIN32
38#include <windows.h>
39#else
40#include <unistd.h>
41#endif
42
43//------------------------------------------------------------------------------
44
45int main(int argc, char* argv[])
46{
47 int retval = 0;
48 const char* errorString;
49
50 int i;
51
52 int connectionID = -1;
53 int wrongGetterID = -1;
54 int getterID = -1;
55
56 size_t tailnumID = INVALID_DATAREF_ID;
57 size_t daysID = INVALID_DATAREF_ID;
58 size_t zuluSecID = INVALID_DATAREF_ID;
59 size_t pausedID = INVALID_DATAREF_ID;
60 size_t latitudeID = INVALID_DATAREF_ID;
61 size_t longitudeID = INVALID_DATAREF_ID;
62 size_t replayID = INVALID_DATAREF_ID;
63 size_t overspeedID = INVALID_DATAREF_ID;
64 size_t stalledID = INVALID_DATAREF_ID;
65 size_t onTheGroundID = INVALID_DATAREF_ID;
66 size_t emptyWeightID = INVALID_DATAREF_ID;
67 size_t payloadWeightID = INVALID_DATAREF_ID;
68 size_t grossWeightID = INVALID_DATAREF_ID;
69 size_t headingID = INVALID_DATAREF_ID;
70 size_t pitchID = INVALID_DATAREF_ID;
71 size_t bankID = INVALID_DATAREF_ID;
72 size_t iasID = INVALID_DATAREF_ID;
73 size_t machID = INVALID_DATAREF_ID;
74 size_t groundSpeedID = INVALID_DATAREF_ID;
75 size_t vsID = INVALID_DATAREF_ID;
76 size_t radioAltitudeID = INVALID_DATAREF_ID;
77 size_t altitudeID = INVALID_DATAREF_ID;
78 size_t gLoadID = INVALID_DATAREF_ID;
79 size_t flapsControlID = INVALID_DATAREF_ID;
80 size_t flapsLeftID = INVALID_DATAREF_ID;
81 size_t flapsRightID = INVALID_DATAREF_ID;
82 size_t navLightsID = INVALID_DATAREF_ID;
83 size_t beaconLightsID = INVALID_DATAREF_ID;
84 size_t strobeLightsID = INVALID_DATAREF_ID;
85 size_t landingLightsID = INVALID_DATAREF_ID;
86 size_t pitotID = INVALID_DATAREF_ID;
87 size_t parkingID = INVALID_DATAREF_ID;
88 size_t gearControlID = INVALID_DATAREF_ID;
89 size_t noseGearID = INVALID_DATAREF_ID;
90 size_t altimeterID = INVALID_DATAREF_ID;
91 size_t qnhID = INVALID_DATAREF_ID;
92 size_t navTypesID = INVALID_DATAREF_ID;
93 size_t busVoltsID = INVALID_DATAREF_ID;
94
95 const char* tailnum = 0;
96 const int32_t* days = 0;
97 const float* zuluSec = 0;
98 const int32_t* paused = 0;
99 const double* latitude = 0;
100 const double* longitude = 0;
101 const int32_t* replay = 0;
102 const int32_t* overspeed = 0;
103 const int32_t* stalled = 0;
104 const int32_t* onTheGround = 0;
105 const float* emptyWeight = 0;
106 const float* payloadWeight = 0;
107 const float* grossWeight = 0;
108 const float* heading = 0;
109 const float* pitch = 0;
110 const float* bank = 0;
111 const float* ias = 0;
112 const float* mach = 0;
113 const float* groundSpeed = 0;
114 const float* vs = 0;
115 const float* radioAltitude = 0;
116 const float* altitude = 0;
117 const float* gLoad = 0;
118 const float* flapsControl = 0;
119 const float* flapsLeft = 0;
120 const float* flapsRight = 0;
121 const int32_t* navLights = 0;
122 const int32_t* beaconLights = 0;
123 const int32_t* strobeLights = 0;
124 const int32_t* landingLights = 0;
125 const int32_t* pitot = 0;
126 const float* parking = 0;
127 const int32_t* gearControl = 0;
128 const float* noseGear = 0;
129 const float* altimeter = 0;
130 const float* qnh = 0;
131 const int32_t* navTypes = 0;
132 const float* busVolts = 0;
133
134 int dontregister = 0;
135
136 for(i = 1; i<argc; ++i) {
137 if (strcmp(argv[i], "dontregister")==0) {
138 dontregister = 1;
139 }
140 }
141
142 printf("Connecting to X-Plane...\n");
143 connectionID = xplra_connect();
144 if (connectionID>=0) {
145 printf("Connected to X-Plane.\n\n");
146 } else {
147 printf("Connection failed.\n\n");
148 goto cleanup;
149 }
150
151 wrongGetterID = xplra_multi_create_getter(connectionID);
152 if (wrongGetterID<0) goto error;
153 xplra_multi_add_int(wrongGetterID, "sim/time/local_date_days");
154 xplra_multi_add_int(wrongGetterID, "sim/time/paused");
155 xplra_multi_add_int(wrongGetterID, "sim/time/hello_te_lo");
156 xplra_multi_add_float(wrongGetterID, "sim/time/zulu_time_sec");
157 xplra_multi_add_int(wrongGetterID, "sim/operation/prefs/replay_mode");
158
159 printf("Executing a multi-dataref getter with an invalid dataref...\n");
160 if (xplra_multi_execute(wrongGetterID)<0) {
161 printf("Error occured: %s\n\n",
162 xplra_get_last_error_string(connectionID));
163 xplra_clear_last_error(connectionID);
164 } else {
165 printf(">>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!\n\n");
166 }
167
168 printf("Executing a registered multi-dataref getter with an invalid dataref...\n");
169 if (xplra_multi_register(wrongGetterID)<0) goto error;
170 if (xplra_multi_execute(wrongGetterID)<0) {
171 printf("Error occured: %s\n\n",
172 xplra_get_last_error_string(connectionID));
173 xplra_clear_last_error(connectionID);
174 } else {
175 printf(">>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!\n\n");
176 }
177
178
179 getterID = xplra_multi_create_getter(connectionID);
180 if (getterID<0) goto error;
181
182 tailnumID = xplra_multi_add_byte_array(getterID, "sim/aircraft/view/acf_tailnum", 40, 0);
183 daysID = xplra_multi_add_int(getterID, "sim/time/local_date_days");
184 zuluSecID = xplra_multi_add_float(getterID, "sim/time/zulu_time_sec");
185 pausedID = xplra_multi_add_int(getterID, "sim/time/paused");
186 latitudeID = xplra_multi_add_double(getterID, "sim/flightmodel/position/latitude");
187 longitudeID = xplra_multi_add_double(getterID, "sim/flightmodel/position/longitude");
188 replayID = xplra_multi_add_int(getterID, "sim/operation/prefs/replay_mode");
189 overspeedID = xplra_multi_add_int(getterID, "sim/flightmodel/failures/over_vne");
190 stalledID = xplra_multi_add_int(getterID, "sim/flightmodel/failures/stallwarning");
191 onTheGroundID = xplra_multi_add_int(getterID, "sim/flightmodel/failures/onground_any");
192 emptyWeightID = xplra_multi_add_float(getterID, "sim/aircraft/weight/acf_m_empty");
193 payloadWeightID = xplra_multi_add_float(getterID, "sim/flightmodel/weight/m_fixed");
194 grossWeightID = xplra_multi_add_float(getterID, "sim/flightmodel/weight/m_total");
195 headingID = xplra_multi_add_float(getterID, "sim/flightmodel/position/psi");
196 pitchID = xplra_multi_add_float(getterID, "sim/flightmodel/position/theta");
197 bankID = xplra_multi_add_float(getterID, "sim/flightmodel/position/phi");
198 iasID = xplra_multi_add_float(getterID, "sim/flightmodel/position/indicated_airspeed2");
199 machID = xplra_multi_add_float(getterID, "sim/flightmodel/misc/machno");
200 groundSpeedID = xplra_multi_add_float(getterID, "sim/flightmodel/position/groundspeed");
201 vsID = xplra_multi_add_float(getterID, "sim/flightmodel/position/vh_ind_fpm2");
202 radioAltitudeID = xplra_multi_add_float(getterID, "sim/flightmodel/position/y_agl");
203 altitudeID = xplra_multi_add_float(getterID, "sim/flightmodel/position/elevation");
204 gLoadID = xplra_multi_add_float(getterID, "sim/flightmodel/forces/g_nrml");
205 flapsControlID = xplra_multi_add_float(getterID, "sim/flightmodel/controls/flaprqst");
206 flapsLeftID = xplra_multi_add_float(getterID, "sim/flightmodel/controls/flaprat");
207 flapsRightID = xplra_multi_add_float(getterID, "sim/flightmodel/controls/flap2rat");
208 navLightsID = xplra_multi_add_int(getterID, "sim/cockpit/electrical/nav_lights_on");
209 beaconLightsID = xplra_multi_add_int(getterID, "sim/cockpit/electrical/beacon_lights_on");
210 strobeLightsID = xplra_multi_add_int(getterID, "sim/cockpit/electrical/strobe_lights_on");
211 landingLightsID = xplra_multi_add_int(getterID, "sim/cockpit/electrical/landing_lights_on");
212 pitotID = xplra_multi_add_int(getterID, "sim/cockpit/switches/pitot_heat_on");
213 parkingID = xplra_multi_add_float(getterID, "sim/flightmodel/controls/parkbrake");
214 gearControlID = xplra_multi_add_int(getterID, "sim/cockpit2/controls/gear_handle_down");
215 noseGearID = xplra_multi_add_float_array(getterID, "sim/flightmodel2/gear/deploy_ratio", 1, 0);
216 altimeterID = xplra_multi_add_float(getterID, "sim/cockpit/misc/barometer_setting");
217 qnhID = xplra_multi_add_float(getterID, "sim/flightmodel/misc/Qstatic");
218 navTypesID = xplra_multi_add_int_array(getterID, "sim/cockpit/radios/nav_type", 6, 0);
219 busVoltsID = xplra_multi_add_float_array(getterID, "sim/cockpit2/electrical/bus_volts", 4, 0);
220
221 if (dontregister) {
222 xplra_multi_finalize(getterID);
223 } else {
224 printf("Registering getter...\n");
225 if (xplra_multi_register(getterID)<0) goto error;
226 printf("Registered getter.\n\n");
227 }
228
229 tailnum = xplra_multi_get_string_ptr(getterID, tailnumID, 0);
230 days = xplra_multi_get_int_ptr(getterID, daysID);
231 zuluSec = xplra_multi_get_float_ptr(getterID, zuluSecID);
232 paused = xplra_multi_get_int_ptr(getterID, pausedID);
233 latitude = xplra_multi_get_double_ptr(getterID, latitudeID);
234 longitude = xplra_multi_get_double_ptr(getterID, longitudeID);
235 // frozen
236 // slew
237 replay = xplra_multi_get_int_ptr(getterID, replayID);
238 overspeed = xplra_multi_get_int_ptr(getterID, overspeedID);
239 stalled = xplra_multi_get_int_ptr(getterID, stalledID);
240 onTheGround = xplra_multi_get_int_ptr(getterID, onTheGroundID);
241 emptyWeight = xplra_multi_get_float_ptr(getterID, emptyWeightID);
242 payloadWeight = xplra_multi_get_float_ptr(getterID, payloadWeightID);
243 grossWeight = xplra_multi_get_float_ptr(getterID, grossWeightID);
244 heading = xplra_multi_get_float_ptr(getterID, headingID);
245 pitch = xplra_multi_get_float_ptr(getterID, pitchID);
246 bank = xplra_multi_get_float_ptr(getterID, bankID);
247 ias = xplra_multi_get_float_ptr(getterID, iasID);
248 mach = xplra_multi_get_float_ptr(getterID, machID);
249 groundSpeed = xplra_multi_get_float_ptr(getterID, groundSpeedID);
250 vs = xplra_multi_get_float_ptr(getterID, vsID);
251 radioAltitude = xplra_multi_get_float_ptr(getterID, radioAltitudeID);
252 altitude = xplra_multi_get_float_ptr(getterID, altitudeID);
253 gLoad = xplra_multi_get_float_ptr(getterID, gLoadID);
254 flapsControl = xplra_multi_get_float_ptr(getterID, flapsControlID);
255 flapsLeft = xplra_multi_get_float_ptr(getterID, flapsLeftID);
256 flapsRight = xplra_multi_get_float_ptr(getterID, flapsRightID);
257 navLights = xplra_multi_get_int_ptr(getterID, navLightsID);
258 beaconLights = xplra_multi_get_int_ptr(getterID, beaconLightsID);
259 strobeLights = xplra_multi_get_int_ptr(getterID, strobeLightsID);
260 landingLights = xplra_multi_get_int_ptr(getterID, landingLightsID);
261 pitot = xplra_multi_get_int_ptr(getterID, pitotID);
262 parking = xplra_multi_get_float_ptr(getterID, parkingID);
263 gearControl = xplra_multi_get_int_ptr(getterID, gearControlID);
264 noseGear = xplra_multi_get_float_array_ptr(getterID, noseGearID, 0);
265 altimeter = xplra_multi_get_float_ptr(getterID, altimeterID);
266 qnh = xplra_multi_get_float_ptr(getterID, qnhID);
267 navTypes = xplra_multi_get_int_array_ptr(getterID, navTypesID, 0);
268 busVolts = xplra_multi_get_float_array_ptr(getterID, busVoltsID, 0);
269
270 while(1) {
271 if (xplra_multi_execute(getterID)<0) goto error;
272 printf("tail number: '%s', days: %d, zuluSec: %f\n",
273 tailnum, *days, *zuluSec);
274 printf("paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d\n",
275 *paused, *replay, *overspeed, *stalled, *onTheGround);
276 printf("emptyWeight=%f, payloadWeight=%f, grossWeight=%f\n",
277 *emptyWeight, *payloadWeight, *grossWeight);
278 printf("latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f\n",
279 *latitude, *longitude, (*radioAltitude)/.3048, (*altitude)/.3048, *gLoad);
280 printf("heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f\n",
281 *heading, *pitch, *bank, *ias, *mach, *groundSpeed, *vs);
282 printf("flapsControl=%f, flapsLeft=%f, flapsRight=%f\n",
283 *flapsControl, *flapsLeft, *flapsRight);
284 printf("Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d\n",
285 *navLights, *beaconLights, *strobeLights, *landingLights);
286 printf("pitot: %d, parking: %f, gearControl: %d, noseGear: %f\n",
287 *pitot, *parking, *gearControl, *noseGear);
288 printf("altimeter: %f, qnh: %f\n",
289 *altimeter, *qnh);
290 printf("NAV types: %d %d %d %d %d %d\n",
291 navTypes[0], navTypes[1], navTypes[2],
292 navTypes[3], navTypes[4], navTypes[5]);
293 printf("bus voltages: %f %f %f %f\n",
294 busVolts[0], busVolts[1], busVolts[2], busVolts[3]);
295 printf("\n");
296#ifdef _WIN32
297 Sleep(1000);
298#else
299 usleep(1000*1000);
300#endif
301 }
302
303 goto cleanup;
304
305error:
306 errorString = xplra_get_last_error_string(connectionID);
307 if (errorString==0) {
308 printf("\nUnknown error occured!\n");
309 } else {
310 printf("\nError: %s\n", errorString);
311 }
312
313 retval = 1;
314
315cleanup:
316 if (connectionID>=0) xplra_disconnect(connectionID);
317 return retval;
318
319 // try {
320
321
322 // while(true) {
323 // getter.execute();
324 // printf("tail number: '%s', days: %d, zuluSec: %f\n",
325 // getter.getString(tailnumID).c_str(), days, zuluSec);
326 // printf("paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d\n",
327 // paused, replay, overspeed, stalled, onTheGround);
328 // printf("emptyWeight=%f, payloadWeight=%f, grossWeight=%f\n",
329 // emptyWeight, payloadWeight, grossWeight);
330 // printf("latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f\n",
331 // latitude, longitude, radioAltitude/.3048, altitude/.3048, gLoad);
332 // printf("heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f\n",
333 // heading, pitch,bank, ias, mach, groundSpeed, vs);
334 // printf("flapsControl=%f, flapsLeft=%f, flapsRight=%f\n",
335 // flapsControl, flapsLeft, flapsRight);
336 // printf("Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d\n",
337 // navLights, beaconLights, strobeLights, landingLights);
338 // printf("pitot: %d, parking: %f, gearControl: %d, noseGear: %f\n",
339 // pitot, parking, gearControl, noseGear);
340 // printf("altimeter: %f, qnh: %f\n",
341 // altimeter, qnh);
342 // printf("NAV types: %d %d %d %d %d %d\n",
343 // navTypes[0], navTypes[1], navTypes[2],
344 // navTypes[3], navTypes[4], navTypes[5]);
345 // printf("bus voltages: %f %f %f %f\n",
346 // busVolts[0], busVolts[1], busVolts[2], busVolts[3]);
347 // printf("\n");
348 // Thread::sleep(1000);
349 // }
350
351 // //xplane.destroyMultiBuffer(getter);
352
353 // return 0;
354 // } catch(Exception& exception) {
355 // printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
356
357 // return 1;
358 // }
359}
360
361//------------------------------------------------------------------------------
362
363// Local Variables:
364// mode: C++
365// c-basic-offset: 4
366// indent-tabs-mode: nil
367// End:
Note: See TracBrowser for help on using the repository browser.