source: xplra/test/multigettest.cc@ 97:28052c8e62c9

Last change on this file since 97:28052c8e62c9 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: 11.6 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/XPlane.h>
32#include <hu/varadiistvan/xplra/MultiGetter.h>
33
34#include <hu/varadiistvan/scpl/Thread.h>
35
36#include <cstdio>
37#include <cstring>
38
39//------------------------------------------------------------------------------
40
41using hu::varadiistvan::xplra::XPlane;
42using hu::varadiistvan::xplra::MultiGetter;
43using hu::varadiistvan::xplra::Exception;
44using hu::varadiistvan::xplra::ProtocolException;
45
46using hu::varadiistvan::scpl::Thread;
47
48//------------------------------------------------------------------------------
49
50int main(int argc, char* argv[])
51{
52 bool dontregister = false;
53 for(int i = 1; i<argc; ++i) {
54 if (strcmp(argv[i], "dontregister")==0) {
55 dontregister = true;
56 }
57 }
58
59 try {
60 XPlane xplane;
61
62 printf("Connecting to X-Plane...\n");
63 xplane.connect();
64 printf("Connected to X-Plane.\n\n");
65
66 MultiGetter& wrongGetter = xplane.createMultiGetter();
67 wrongGetter.addInt("sim/time/local_date_days");
68 wrongGetter.addInt("sim/time/paused");
69 wrongGetter.addInt("sim/time/hello_te_lo");
70 wrongGetter.addFloat("sim/time/zulu_time_sec");
71 wrongGetter.addInt("sim/operation/prefs/replay_mode");
72
73 printf("Executing a multi-dataref getter with an invalid dataref...\n");
74 try {
75 wrongGetter.execute();
76 printf(">>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!\n\n");
77 } catch(const ProtocolException& e) {
78 printf("Caught protocol exception: %s\n\n", e.what());
79 }
80
81 printf("Executing a registered multi-dataref getter with an invalid dataref...\n");
82 wrongGetter.registerInXPlane();
83 try {
84 wrongGetter.execute();
85 printf(">>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!\n\n");
86 } catch(const ProtocolException& e) {
87 printf("Caught protocol exception: %s\n\n", e.what());
88 }
89
90 MultiGetter& getter = xplane.createMultiGetter();
91
92 const size_t tailnumID = getter.addByteArray("sim/aircraft/view/acf_tailnum", 40);
93 const size_t daysID = getter.addInt("sim/time/local_date_days");
94 const size_t zuluSecID = getter.addFloat("sim/time/zulu_time_sec");
95 const size_t pausedID = getter.addInt("sim/time/paused");
96 const size_t latitudeID = getter.addDouble("sim/flightmodel/position/latitude");
97 const size_t longitudeID = getter.addDouble("sim/flightmodel/position/longitude");
98 const size_t replayID = getter.addInt("sim/operation/prefs/replay_mode");
99 const size_t overspeedID = getter.addInt("sim/flightmodel/failures/over_vne");
100 const size_t stalledID = getter.addInt("sim/flightmodel/failures/stallwarning");
101 const size_t onTheGroundID = getter.addInt("sim/flightmodel/failures/onground_any");
102 const size_t emptyWeightID = getter.addFloat("sim/aircraft/weight/acf_m_empty");
103 const size_t payloadWeightID = getter.addFloat("sim/flightmodel/weight/m_fixed");
104 const size_t grossWeightID = getter.addFloat("sim/flightmodel/weight/m_total");
105 const size_t headingID = getter.addFloat("sim/flightmodel/position/psi");
106 const size_t pitchID = getter.addFloat("sim/flightmodel/position/theta");
107 const size_t bankID = getter.addFloat("sim/flightmodel/position/phi");
108 const size_t iasID = getter.addFloat("sim/flightmodel/position/indicated_airspeed2");
109 const size_t machID = getter.addFloat("sim/flightmodel/misc/machno");
110 const size_t groundSpeedID = getter.addFloat("sim/flightmodel/position/groundspeed");
111 const size_t vsID = getter.addFloat("sim/flightmodel/position/vh_ind_fpm2");
112 const size_t radioAltitudeID = getter.addFloat("sim/flightmodel/position/y_agl");
113 const size_t altitudeID = getter.addFloat("sim/flightmodel/position/elevation");
114 const size_t gLoadID = getter.addFloat("sim/flightmodel/forces/g_nrml");
115 const size_t flapsControlID = getter.addFloat("sim/flightmodel/controls/flaprqst");
116 const size_t flapsLeftID = getter.addFloat("sim/flightmodel/controls/flaprat");
117 const size_t flapsRightID = getter.addFloat("sim/flightmodel/controls/flap2rat");
118 const size_t navLightsID = getter.addInt("sim/cockpit/electrical/nav_lights_on");
119 const size_t beaconLightsID = getter.addInt("sim/cockpit/electrical/beacon_lights_on");
120 const size_t strobeLightsID = getter.addInt("sim/cockpit/electrical/strobe_lights_on");
121 const size_t landingLightsID = getter.addInt("sim/cockpit/electrical/landing_lights_on");
122 const size_t pitotID = getter.addInt("sim/cockpit/switches/pitot_heat_on");
123 const size_t parkingID = getter.addFloat("sim/flightmodel/controls/parkbrake");
124 //const size_t gearControlID = getter.addInt("sim/cockpit/switches/gear_handle_status");
125 const size_t gearControlID = getter.addInt("sim/cockpit2/controls/gear_handle_down");
126 const size_t noseGearID = getter.addFloatArray("sim/flightmodel2/gear/deploy_ratio", 1);
127 const size_t altimeterID = getter.addFloat("sim/cockpit/misc/barometer_setting");
128 const size_t qnhID = getter.addFloat("sim/flightmodel/misc/Qstatic");
129 const size_t navTypesID = getter.addIntArray("sim/cockpit/radios/nav_type", 6);
130 const size_t busVoltsID = getter.addFloatArray("sim/cockpit2/electrical/bus_volts", 4);
131
132 if (dontregister) {
133 getter.finalize();
134 } else {
135 printf("Registering getter...\n");
136 getter.registerInXPlane();
137 printf("Registered getter.\n\n");
138 }
139
140 const int32_t& days = getter.getIntRef(daysID);
141 const float& zuluSec = getter.getFloatRef(zuluSecID);
142 const int32_t& paused = getter.getIntRef(pausedID);
143 const double& latitude = getter.getDoubleRef(latitudeID);
144 const double& longitude = getter.getDoubleRef(longitudeID);
145 // frozen
146 // slew
147 const int32_t& replay = getter.getIntRef(replayID);
148 const int32_t& overspeed = getter.getIntRef(overspeedID);
149 const int32_t& stalled = getter.getIntRef(stalledID);
150 const int32_t& onTheGround = getter.getIntRef(onTheGroundID);
151 const float& emptyWeight = getter.getFloatRef(emptyWeightID);
152 const float& payloadWeight = getter.getFloatRef(payloadWeightID);
153 const float& grossWeight = getter.getFloatRef(grossWeightID);
154 const float& heading = getter.getFloatRef(headingID);
155 const float& pitch = getter.getFloatRef(pitchID);
156 const float& bank = getter.getFloatRef(bankID);
157 const float& ias = getter.getFloatRef(iasID);
158 const float& mach = getter.getFloatRef(machID);
159 const float& groundSpeed = getter.getFloatRef(groundSpeedID);
160 const float& vs = getter.getFloatRef(vsID);
161 const float& radioAltitude = getter.getFloatRef(radioAltitudeID);
162 const float& altitude = getter.getFloatRef(altitudeID);
163 const float& gLoad = getter.getFloatRef(gLoadID);
164 const float& flapsControl = getter.getFloatRef(flapsControlID);
165 const float& flapsLeft = getter.getFloatRef(flapsLeftID);
166 const float& flapsRight = getter.getFloatRef(flapsRightID);
167 const int32_t& navLights = getter.getIntRef(navLightsID);
168 const int32_t& beaconLights = getter.getIntRef(beaconLightsID);
169 const int32_t& strobeLights = getter.getIntRef(strobeLightsID);
170 const int32_t& landingLights = getter.getIntRef(landingLightsID);
171 const int32_t& pitot = getter.getIntRef(pitotID);
172 const float& parking = getter.getFloatRef(parkingID);
173 const int32_t& gearControl = getter.getIntRef(gearControlID);
174 const float& noseGear = getter.getFloatArray(noseGearID)[0];
175 const float& altimeter = getter.getFloatRef(altimeterID);
176 const float& qnh = getter.getFloatRef(qnhID);
177 const int32_t* navTypes = getter.getIntArray(navTypesID);
178 const float* busVolts = getter.getFloatArray(busVoltsID);
179
180 while(true) {
181 getter.execute();
182 printf("tail number: '%s', days: %d, zuluSec: %f\n",
183 getter.getString(tailnumID).c_str(), days, zuluSec);
184 printf("paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d\n",
185 paused, replay, overspeed, stalled, onTheGround);
186 printf("emptyWeight=%f, payloadWeight=%f, grossWeight=%f\n",
187 emptyWeight, payloadWeight, grossWeight);
188 printf("latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f\n",
189 latitude, longitude, radioAltitude/.3048, altitude/.3048, gLoad);
190 printf("heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f\n",
191 heading, pitch,bank, ias, mach, groundSpeed, vs);
192 printf("flapsControl=%f, flapsLeft=%f, flapsRight=%f\n",
193 flapsControl, flapsLeft, flapsRight);
194 printf("Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d\n",
195 navLights, beaconLights, strobeLights, landingLights);
196 printf("pitot: %d, parking: %f, gearControl: %d, noseGear: %f\n",
197 pitot, parking, gearControl, noseGear);
198 printf("altimeter: %f, qnh: %f\n",
199 altimeter, qnh);
200 printf("NAV types: %d %d %d %d %d %d\n",
201 navTypes[0], navTypes[1], navTypes[2],
202 navTypes[3], navTypes[4], navTypes[5]);
203 printf("bus voltages: %f %f %f %f\n",
204 busVolts[0], busVolts[1], busVolts[2], busVolts[3]);
205 printf("\n");
206 Thread::sleep(1000);
207 }
208
209 //xplane.destroyMultiBuffer(getter);
210
211 return 0;
212 } catch(Exception& exception) {
213 printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
214
215 return 1;
216 }
217}
218
219//------------------------------------------------------------------------------
220
221// Local Variables:
222// mode: C++
223// c-basic-offset: 4
224// indent-tabs-mode: nil
225// End:
Note: See TracBrowser for help on using the repository browser.