// Copyright (c) 2013 by István Váradi // This file is part of XPLRA, a remote-access plugin for X-Plane // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // The views and conclusions contained in the software and documentation are those // of the authors and should not be interpreted as representing official policies, // either expressed or implied, of the FreeBSD Project. //------------------------------------------------------------------------------ #include #include #include #include "common.h" #include #include //------------------------------------------------------------------------------ using hu::varadiistvan::xplra::XPlane; using hu::varadiistvan::xplra::MultiGetter; using hu::varadiistvan::xplra::Exception; using hu::varadiistvan::xplra::ProtocolException; using hu::varadiistvan::scpl::Thread; //------------------------------------------------------------------------------ int main(int argc, char* argv[]) { bool dontregister = false; for(int i = 1; i>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!\n\n"); } catch(const ProtocolException& e) { printf("Caught protocol exception: %s\n\n", e.what()); } printf("Executing a registered multi-dataref getter with an invalid dataref...\n"); wrongGetter.registerInXPlane(); try { wrongGetter.execute(); printf(">>>>>>>>>>>>>>>>>>>>> Succeeded, but it should not have!!!!\n\n"); } catch(const ProtocolException& e) { printf("Caught protocol exception: %s\n\n", e.what()); } MultiGetter& getter = xplane.createMultiGetter(); const size_t tailnumID = getter.addByteArray("sim/aircraft/view/acf_tailnum", 40); const size_t daysID = getter.addInt("sim/time/local_date_days"); const size_t zuluSecID = getter.addFloat("sim/time/zulu_time_sec"); const size_t pausedID = getter.addInt("sim/time/paused"); const size_t latitudeID = getter.addDouble("sim/flightmodel/position/latitude"); const size_t longitudeID = getter.addDouble("sim/flightmodel/position/longitude"); const size_t replayID = getter.addInt("sim/operation/prefs/replay_mode"); const size_t overspeedID = getter.addInt("sim/flightmodel/failures/over_vne"); const size_t stalledID = getter.addInt("sim/flightmodel/failures/stallwarning"); const size_t onTheGroundID = getter.addInt("sim/flightmodel/failures/onground_any"); const size_t emptyWeightID = getter.addFloat("sim/aircraft/weight/acf_m_empty"); const size_t payloadWeightID = getter.addFloat("sim/flightmodel/weight/m_fixed"); const size_t grossWeightID = getter.addFloat("sim/flightmodel/weight/m_total"); const size_t headingID = getter.addFloat("sim/flightmodel/position/psi"); const size_t pitchID = getter.addFloat("sim/flightmodel/position/theta"); const size_t bankID = getter.addFloat("sim/flightmodel/position/phi"); const size_t iasID = getter.addFloat("sim/flightmodel/position/indicated_airspeed2"); const size_t machID = getter.addFloat("sim/flightmodel/misc/machno"); const size_t groundSpeedID = getter.addFloat("sim/flightmodel/position/groundspeed"); const size_t vsID = getter.addFloat("sim/flightmodel/position/vh_ind_fpm2"); const size_t radioAltitudeID = getter.addFloat("sim/flightmodel/position/y_agl"); const size_t altitudeID = getter.addFloat("sim/flightmodel/position/elevation"); const size_t gLoadID = getter.addFloat("sim/flightmodel/forces/g_nrml"); const size_t flapsControlID = getter.addFloat("sim/flightmodel/controls/flaprqst"); const size_t flapsLeftID = getter.addFloat("sim/flightmodel/controls/flaprat"); const size_t flapsRightID = getter.addFloat("sim/flightmodel/controls/flap2rat"); const size_t navLightsID = getter.addInt("sim/cockpit/electrical/nav_lights_on"); const size_t beaconLightsID = getter.addInt("sim/cockpit/electrical/beacon_lights_on"); const size_t strobeLightsID = getter.addInt("sim/cockpit/electrical/strobe_lights_on"); const size_t landingLightsID = getter.addInt("sim/cockpit/electrical/landing_lights_on"); const size_t pitotID = getter.addInt("sim/cockpit/switches/pitot_heat_on"); const size_t parkingID = getter.addFloat("sim/flightmodel/controls/parkbrake"); //const size_t gearControlID = getter.addInt("sim/cockpit/switches/gear_handle_status"); const size_t gearControlID = getter.addInt("sim/cockpit2/controls/gear_handle_down"); const size_t noseGearID = getter.addFloatArray("sim/flightmodel2/gear/deploy_ratio", 1); const size_t altimeterID = getter.addFloat("sim/cockpit/misc/barometer_setting"); const size_t qnhID = getter.addFloat("sim/flightmodel/misc/Qstatic"); const size_t navTypesID = getter.addIntArray("sim/cockpit/radios/nav_type", 6); const size_t busVoltsID = getter.addFloatArray("sim/cockpit2/electrical/bus_volts", 4); if (dontregister) { getter.finalize(); } else { printf("Registering getter...\n"); getter.registerInXPlane(); printf("Registered getter.\n\n"); } const int32_t& days = getter.getIntRef(daysID); const float& zuluSec = getter.getFloatRef(zuluSecID); const int32_t& paused = getter.getIntRef(pausedID); const double& latitude = getter.getDoubleRef(latitudeID); const double& longitude = getter.getDoubleRef(longitudeID); // frozen // slew const int32_t& replay = getter.getIntRef(replayID); const int32_t& overspeed = getter.getIntRef(overspeedID); const int32_t& stalled = getter.getIntRef(stalledID); const int32_t& onTheGround = getter.getIntRef(onTheGroundID); const float& emptyWeight = getter.getFloatRef(emptyWeightID); const float& payloadWeight = getter.getFloatRef(payloadWeightID); const float& grossWeight = getter.getFloatRef(grossWeightID); const float& heading = getter.getFloatRef(headingID); const float& pitch = getter.getFloatRef(pitchID); const float& bank = getter.getFloatRef(bankID); const float& ias = getter.getFloatRef(iasID); const float& mach = getter.getFloatRef(machID); const float& groundSpeed = getter.getFloatRef(groundSpeedID); const float& vs = getter.getFloatRef(vsID); const float& radioAltitude = getter.getFloatRef(radioAltitudeID); const float& altitude = getter.getFloatRef(altitudeID); const float& gLoad = getter.getFloatRef(gLoadID); const float& flapsControl = getter.getFloatRef(flapsControlID); const float& flapsLeft = getter.getFloatRef(flapsLeftID); const float& flapsRight = getter.getFloatRef(flapsRightID); const int32_t& navLights = getter.getIntRef(navLightsID); const int32_t& beaconLights = getter.getIntRef(beaconLightsID); const int32_t& strobeLights = getter.getIntRef(strobeLightsID); const int32_t& landingLights = getter.getIntRef(landingLightsID); const int32_t& pitot = getter.getIntRef(pitotID); const float& parking = getter.getFloatRef(parkingID); const int32_t& gearControl = getter.getIntRef(gearControlID); const float& noseGear = getter.getFloatArray(noseGearID)[0]; const float& altimeter = getter.getFloatRef(altimeterID); const float& qnh = getter.getFloatRef(qnhID); const int32_t* navTypes = getter.getIntArray(navTypesID); const float* busVolts = getter.getFloatArray(busVoltsID); while(true) { getter.execute(); printf("tail number: '%s', days: %d, zuluSec: %f\n", getter.getString(tailnumID).c_str(), days, zuluSec); printf("paused=%d, replay=%d, overspeed=%d, stalled=%d, onTheGround=%d\n", paused, replay, overspeed, stalled, onTheGround); printf("emptyWeight=%f, payloadWeight=%f, grossWeight=%f\n", emptyWeight, payloadWeight, grossWeight); printf("latitude=%f, longitude=%f, radioAltitude=%f, altitude=%f, gLoad=%f\n", latitude, longitude, radioAltitude/.3048, altitude/.3048, gLoad); printf("heading=%f, pitch=%f, bank=%f, ias=%f, mach=%f, groundSpeed=%f, vs=%f\n", heading, pitch,bank, ias, mach, groundSpeed, vs); printf("flapsControl=%f, flapsLeft=%f, flapsRight=%f\n", flapsControl, flapsLeft, flapsRight); printf("Lights: NAV: %d, beacon: %d, strobe: %d, landing: %d\n", navLights, beaconLights, strobeLights, landingLights); printf("pitot: %d, parking: %f, gearControl: %d, noseGear: %f\n", pitot, parking, gearControl, noseGear); printf("altimeter: %f, qnh: %f\n", altimeter, qnh); printf("NAV types: %d %d %d %d %d %d\n", navTypes[0], navTypes[1], navTypes[2], navTypes[3], navTypes[4], navTypes[5]); printf("bus voltages: %f %f %f %f\n", busVolts[0], busVolts[1], busVolts[2], busVolts[3]); printf("\n"); Thread::sleep(1000); } //xplane.destroyMultiBuffer(getter); return 0; } catch(Exception& exception) { printf("\n>>>>>>>>>>>>>>>>> Exception caugth: %s\n", exception.what()); return 1; } } //------------------------------------------------------------------------------ // Local Variables: // mode: C++ // c-basic-offset: 4 // indent-tabs-mode: nil // End: