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