[19] | 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")) {
|
---|
| 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 pausedID = getter.addInt("sim/time/paused");
|
---|
| 68 | const size_t latitudeID = getter.addDouble("sim/flightmodel/position/latitude");
|
---|
| 69 | const size_t longitudeID = getter.addDouble("sim/flightmodel/position/longitude");
|
---|
| 70 | const size_t replayID = getter.addInt("sim/operation/prefs/replay_mode");
|
---|
| 71 | const size_t overspeedID = getter.addInt("sim/flightmodel/failures/over_vne");
|
---|
| 72 | const size_t stalledID = getter.addInt("sim/flightmodel/failures/stallwarning");
|
---|
| 73 | const size_t onTheGroundID = getter.addInt("sim/flightmodel/failures/onground_any");
|
---|
| 74 | const size_t emptyWeightID = getter.addFloat("sim/aircraft/weight/acf_m_empty");
|
---|
| 75 | const size_t payloadWeightID = getter.addFloat("sim/flightmodel/weight/m_fixed");
|
---|
| 76 | const size_t grossWeightID = getter.addFloat("sim/flightmodel/weight/m_total");
|
---|
| 77 | const size_t headingID = getter.addFloat("sim/flightmodel/position/psi");
|
---|
| 78 | const size_t pitchID = getter.addFloat("sim/flightmodel/position/theta");
|
---|
| 79 | const size_t bankID = getter.addFloat("sim/flightmodel/position/phi");
|
---|
| 80 | const size_t iasID = getter.addFloat("sim/flightmodel/position/indicated_airspeed2");
|
---|
| 81 | const size_t machID = getter.addFloat("sim/flightmodel/misc/machno");
|
---|
| 82 | const size_t groundSpeedID = getter.addFloat("sim/flightmodel/position/groundspeed");
|
---|
| 83 | const size_t vsID = getter.addFloat("sim/flightmodel/position/vh_ind_fpm2");
|
---|
| 84 | const size_t radioAltitudeID = getter.addFloat("sim/flightmodel/position/y_agl");
|
---|
| 85 | const size_t altitudeID = getter.addFloat("sim/flightmodel/position/elevation");
|
---|
| 86 | const size_t gLoadID = getter.addFloat("sim/flightmodel/forces/g_nrml");
|
---|
| 87 | const size_t flapsControlID = getter.addFloat("sim/flightmodel/controls/flaprqst");
|
---|
| 88 | const size_t flapsLeftID = getter.addFloat("sim/flightmodel/controls/flaprat");
|
---|
| 89 | const size_t flapsRightID = getter.addFloat("sim/flightmodel/controls/flap2rat");
|
---|
| 90 | const size_t navLightsID = getter.addInt("sim/cockpit/electrical/nav_lights_on");
|
---|
| 91 | const size_t beaconLightsID = getter.addInt("sim/cockpit/electrical/beacon_lights_on");
|
---|
| 92 | const size_t strobeLightsID = getter.addInt("sim/cockpit/electrical/strobe_lights_on");
|
---|
| 93 | const size_t landingLightsID = getter.addInt("sim/cockpit/electrical/landing_lights_on");
|
---|
| 94 | const size_t pitotID = getter.addInt("sim/cockpit/switches/pitot_heat_on");
|
---|
| 95 | const size_t parkingID = getter.addFloat("sim/flightmodel/controls/parkbrake");
|
---|
| 96 | //const size_t gearControlID = getter.addInt("sim/cockpit/switches/gear_handle_status");
|
---|
| 97 | const size_t gearControlID = getter.addInt("sim/cockpit2/controls/gear_handle_down");
|
---|
| 98 | const size_t noseGearID = getter.addFloatArray("sim/flightmodel2/gear/deploy_ratio", 1);
|
---|
| 99 | const size_t altimeterID = getter.addFloat("sim/cockpit/misc/barometer_setting");
|
---|
| 100 | const size_t qnhID = getter.addFloat("sim/flightmodel/misc/Qstatic");
|
---|
| 101 |
|
---|
| 102 | if (dontregister) {
|
---|
| 103 | getter.finalize();
|
---|
| 104 | } else {
|
---|
| 105 | printf("Registering getter\n\n");
|
---|
| 106 | getter.registerInXPlane();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | const int32_t& paused = getter.getIntRef(pausedID);
|
---|
| 110 | const double& latitude = getter.getDoubleRef(latitudeID);
|
---|
| 111 | const double& longitude = getter.getDoubleRef(longitudeID);
|
---|
| 112 | // frozen
|
---|
| 113 | // slew
|
---|
| 114 | const int32_t& replay = getter.getIntRef(replayID);
|
---|
| 115 | const int32_t& overspeed = getter.getIntRef(overspeedID);
|
---|
| 116 | const int32_t& stalled = getter.getIntRef(stalledID);
|
---|
| 117 | const int32_t& onTheGround = getter.getIntRef(onTheGroundID);
|
---|
| 118 | const float& emptyWeight = getter.getFloatRef(emptyWeightID);
|
---|
| 119 | const float& payloadWeight = getter.getFloatRef(payloadWeightID);
|
---|
| 120 | const float& grossWeight = getter.getFloatRef(grossWeightID);
|
---|
| 121 | const float& heading = getter.getFloatRef(headingID);
|
---|
| 122 | const float& pitch = getter.getFloatRef(pitchID);
|
---|
| 123 | const float& bank = getter.getFloatRef(bankID);
|
---|
| 124 | const float& ias = getter.getFloatRef(iasID);
|
---|
| 125 | const float& mach = getter.getFloatRef(machID);
|
---|
| 126 | const float& groundSpeed = getter.getFloatRef(groundSpeedID);
|
---|
| 127 | const float& vs = getter.getFloatRef(vsID);
|
---|
| 128 | const float& radioAltitude = getter.getFloatRef(radioAltitudeID);
|
---|
| 129 | const float& altitude = getter.getFloatRef(altitudeID);
|
---|
| 130 | const float& gLoad = getter.getFloatRef(gLoadID);
|
---|
| 131 | const float& flapsControl = getter.getFloatRef(flapsControlID);
|
---|
| 132 | const float& flapsLeft = getter.getFloatRef(flapsLeftID);
|
---|
| 133 | const float& flapsRight = getter.getFloatRef(flapsRightID);
|
---|
| 134 | const int32_t& navLights = getter.getIntRef(navLightsID);
|
---|
| 135 | const int32_t& beaconLights = getter.getIntRef(beaconLightsID);
|
---|
| 136 | const int32_t& strobeLights = getter.getIntRef(strobeLightsID);
|
---|
| 137 | const int32_t& landingLights = getter.getIntRef(landingLightsID);
|
---|
| 138 | const int32_t& pitot = getter.getIntRef(pitotID);
|
---|
| 139 | const float& parking = getter.getFloatRef(parkingID);
|
---|
| 140 | const int32_t& gearControl = getter.getInt(gearControlID);
|
---|
| 141 | const float& noseGear = getter.getFloatArray(noseGearID)[0];
|
---|
| 142 | const float& altimeter = getter.getFloatRef(altimeterID);
|
---|
| 143 | const float& qnh = getter.getFloatRef(qnhID);
|
---|
| 144 |
|
---|
| 145 | while(true) {
|
---|
| 146 | getter.execute();
|
---|
| 147 | printf("paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d\n",
|
---|
| 148 | paused, replay, overspeed, stalled, onTheGround);
|
---|
| 149 | printf("emptyWeight=%f, payloadWeight=%f, grossWeight=%f\n",
|
---|
| 150 | emptyWeight, payloadWeight, grossWeight);
|
---|
| 151 | printf("latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f\n",
|
---|
| 152 | latitude, longitude, radioAltitude/.3048, altitude/.3048, gLoad);
|
---|
| 153 | printf("heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f\n",
|
---|
| 154 | heading, pitch,bank, ias, mach, groundSpeed, vs);
|
---|
| 155 | printf("flapsControl=%f, flapsLeft=%f, flapsRight=%f\n",
|
---|
| 156 | flapsControl, flapsLeft, flapsRight);
|
---|
| 157 | printf("Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d\n",
|
---|
| 158 | navLights, beaconLights, strobeLights, landingLights);
|
---|
| 159 | printf("pitot: %d, parking: %f, gearControl: %d, noseGear: %f\n",
|
---|
| 160 | pitot, parking, gearControl, noseGear);
|
---|
| 161 | printf("altimeter: %f, qnh: %f\n",
|
---|
| 162 | altimeter, qnh);
|
---|
| 163 | printf("\n");
|
---|
| 164 | Thread::sleep(1000);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | return 0;
|
---|
| 168 | } catch(Exception& exception) {
|
---|
| 169 | printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what());
|
---|
| 170 |
|
---|
| 171 | return 1;
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | //------------------------------------------------------------------------------
|
---|
| 176 |
|
---|
| 177 | // Local Variables:
|
---|
| 178 | // mode: C++
|
---|
| 179 | // c-basic-offset: 4
|
---|
| 180 | // indent-tabs-mode: nil
|
---|
| 181 | // End:
|
---|