// 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 //------------------------------------------------------------------------------ int main() { int retval = 0; const char* errorString = 0; int numEngines = 0; float spoolTime = 0.0; double latitude = 0.0, longitude = 0.0; ssize_t length, i; size_t length1, j; uint8_t result[260]; uint8_t* result1 = 0; int32_t result3[8]; int32_t* result4 = 0; float result5[8]; float* result6 = 0; printf("Connection to X-Plane...\n"); int connectionID = xplra_connect(); if (connectionID>=0) { printf("Connected.\n\n"); } else { printf("Connection failed.\n"); goto cleanup; } printf("Querying the number of the engines...\n"); if (xplra_get_int(&numEngines, connectionID, "sim/aircraft/engine/acf_num_engines")<0) { goto error; } printf("The number of engines: %d\n\n", numEngines); printf("Querying an invalid dataref...\n"); if (xplra_get_int(&numEngines, connectionID, "sim/aircraft/engine/num_engines")==0) { printf("\n>>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!\n\n"); } else { printf("Error occured: %s\n\n", xplra_get_last_error_string(connectionID)); xplra_clear_last_error(connectionID); } printf("Querying the spool time of a jet engine...\n"); if (xplra_get_float(&spoolTime, connectionID, "sim/aircraft/engine/acf_spooltime_jet")<0) { goto error; } printf("The spool time: %f\n\n", spoolTime); printf("Querying the spool time of a propeller...\n"); if (xplra_get_float(&spoolTime, connectionID, "sim/aircraft/engine/acf_spooltime_prop")<0) { goto error; } printf("The spool time: %f\n\n", spoolTime); printf("Querying the coordinates...\n"); if (xplra_get_double(&latitude, connectionID, "sim/flightmodel/position/latitude")<0) { goto error; } if (xplra_get_double(&longitude, connectionID, "sim/flightmodel/position/longitude")<0) { goto error; } printf("The coordinates: %f, %f\n\n", latitude, longitude); printf("Querying the aircraft's description as an array of a fixed size...\n"); length = xplra_get_byte_array(result, sizeof(result)/sizeof(result[0]), 0, connectionID, "sim/aircraft/view/acf_descrip"); if (length<0) goto error; printf("Got %zu bytes, as a string: '%s'\n\n", length, result); printf("Querying the aircraft's description as a dynamically created array with an offset of 3...\n"); length1 = 0; result1 = xplra_get_byte_array_new(&length1, 3, connectionID, "sim/aircraft/view/acf_descrip"); if (result1==0) goto error; printf("Got %zu bytes, as a string: '%s'\n\n", length1, result1); printf("Querying the aircraft's engine types as an array of a fixed size...\n"); length = xplra_get_int_array(result3, sizeof(result3)/sizeof(result3[0]), 0, connectionID, "sim/aircraft/prop/acf_en_type"); if (length<0) goto error; printf("Got %zd values:", length); for(i = 0; i0) printf(","); printf(" %d", result3[i]); } printf("\n\n"); printf("Querying the aircraft's engine types as a dynamically created array...\n"); length1 = 0; result4 = xplra_get_int_array_new(&length1, 0, connectionID, "sim/aircraft/prop/acf_en_type"); printf("Got %zu values:", length1); for(j = 0; j0) printf(","); printf(" %d", result4[j]); } printf("\n\n"); printf("Querying the aircraft's propeller direction as an array of a fixed size...\n"); length = xplra_get_float_array(result5, sizeof(result5)/sizeof(result5[0]), 0, connectionID, "sim/aircraft/prop/acf_prop_dir"); printf("Got %zd values:", length); for(i = 0; i0) printf(","); printf(" %f", result5[i]); } printf("\n\n"); printf("Querying the aircraft's propeller direction as a dynamically created array...\n"); length1 = 0; result6 = xplra_get_float_array_new(&length1, 0, connectionID, "sim/aircraft/prop/acf_prop_dir"); printf("Got %zu values:", length1); for(j = 0; j0) printf(","); printf(" %f", result6[j]); } printf("\n\n"); goto cleanup; error: errorString = xplra_get_last_error_string(connectionID); if (errorString==0) { printf("\nUnknown error occured!\n"); } else { printf("\nError: %s\n", errorString); } retval = 1; cleanup: if (connectionID>=0) xplra_disconnect(connectionID); return retval; // try { // printf("Setting the number of the engines to %d...\n", numEngines + 1); // xplane.setInt("sim/aircraft/engine/acf_num_engines", numEngines + 1); // numEngines = xplane.getInt("sim/aircraft/engine/acf_num_engines"); // printf("The new number of engines: %d\n\n", numEngines); // float acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up"); // printf("Setting the aircraft elevator up control from %f to %f...\n", // acfElevUp, acfElevUp + 15.0); // xplane.setFloat("sim/aircraft/controls/acf_elev_up", acfElevUp); // acfElevUp = xplane.getFloat("sim/aircraft/controls/acf_elev_up"); // printf("The aircraft elevator up control set to %f\n\n", acfElevUp); // double localX = xplane.getDouble("sim/flightmodel/position/local_x"); // printf("Setting the aircraft's local X-coordinate from %f to %f...\n", // localX, localX + 15.0); // xplane.setDouble("sim/flightmodel/position/local_x", localX + 15.0); // localX = xplane.getDouble("sim/flightmodel/position/local_x"); // printf("The aircraft's local X-coordinate set to %f\n\n", localX); // float numBlades[8]; // length = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades", // numBlades, sizeof(numBlades)/sizeof(numBlades[0])); // printf("Setting the number of blades\n from:"); // for(size_t i = 0; i0) printf(","); // printf(" %f", numBlades[i]); // } // printf("\n to:"); // for(size_t i = 0; i0) printf(","); // printf(" %f", numBlades[i]); // } // printf("\n"); // xplane.setFloatArray("sim/aircraft/prop/acf_num_blades", // numBlades, length); // length = xplane.getFloatArray("sim/aircraft/prop/acf_num_blades", // numBlades, sizeof(numBlades)/sizeof(numBlades[0])); // printf("The result:"); // for(size_t i = 0; i0) printf(","); // printf(" %f", numBlades[i]); // } // printf("\n\n"); // int32_t batteryArrayOn[8]; // length = xplane.getIntArray("sim/cockpit/electrical/battery_array_on", // batteryArrayOn, // sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0])); // printf("Setting the batteries\n from:"); // for(size_t i = 0; i0) printf(","); // printf(" %d", batteryArrayOn[i]); // } // printf("\n to:"); // for(size_t i = 0; i0) printf(","); // printf(" %d", batteryArrayOn[i]); // } // printf("\n"); // xplane.setIntArray("sim/cockpit/electrical/battery_array_on", // batteryArrayOn, length); // length = xplane.getIntArray("sim/cockpit/electrical/battery_array_on", // batteryArrayOn, // sizeof(batteryArrayOn)/sizeof(batteryArrayOn[0])); // printf("The result:"); // for(size_t i = 0; i0) printf(","); // printf(" %d", batteryArrayOn[i]); // } // printf("\n\n"); // uint8_t tailNum[40]; // memset(tailNum, 0, sizeof(tailNum)); // strcpy(reinterpret_cast(tailNum), "HA-VAI"); // printf("Setting the tail number to %s as a byte array...\n", tailNum); // xplane.setByteArray("sim/aircraft/view/acf_tailnum", // tailNum, sizeof(tailNum)); // printf("The tail number is: '%s'\n\n", // xplane.getString("sim/aircraft/view/acf_tailnum").c_str()); // static const char* tailNum1 = "VAI"; // printf("Setting the tail number to %s as a string...\n", tailNum1); // xplane.setString("sim/aircraft/view/acf_tailnum", tailNum1, 40); // printf("The tail number is: '%s'\n\n", // xplane.getString("sim/aircraft/view/acf_tailnum").c_str()); // try { // printf("Querying an invalid dataref...\n"); // xplane.getInt("sim/aircraft/engine/num_engines"); // printf("\n>>>>>>>>>>>> Succeeded!!!!!!!!!!!!!!!!!!!!!!\n\n"); // } catch(const ProtocolException& exception) { // printf("Exception caugth: %s\n\n", exception.what()); // } // return 0; // } catch(const 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: