diff --git a/C/monitorExample/main.c b/C/monitorExample/main.c index b9f7c43..e78f0cf 100644 --- a/C/monitorExample/main.c +++ b/C/monitorExample/main.c @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2016 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // DISCLAIMERS diff --git a/C/playbackExample/src/chrome.c b/C/playbackExample/src/chrome.c index 652de96..f1850dd 100644 --- a/C/playbackExample/src/chrome.c +++ b/C/playbackExample/src/chrome.c @@ -1,4 +1,4 @@ -//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//Copyright (c) 2013-2016 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. // //DISCLAIMERS diff --git a/C/playbackExample/src/chrome.h b/C/playbackExample/src/chrome.h index d0da842..fd240e6 100644 --- a/C/playbackExample/src/chrome.h +++ b/C/playbackExample/src/chrome.h @@ -1,4 +1,4 @@ -//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//Copyright (c) 2013-2016 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. // //DISCLAIMERS diff --git a/C/playbackExample/src/main.c b/C/playbackExample/src/main.c index c796edd..abdeb33 100644 --- a/C/playbackExample/src/main.c +++ b/C/playbackExample/src/main.c @@ -1,4 +1,4 @@ -//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//Copyright (c) 2013-2016 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. // //DISCLAIMERS diff --git a/C/playbackExample/src/playback.c b/C/playbackExample/src/playback.c index 75ad523..3226c5a 100644 --- a/C/playbackExample/src/playback.c +++ b/C/playbackExample/src/playback.c @@ -1,4 +1,4 @@ -//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//Copyright (c) 2013-2016 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. // //DISCLAIMERS diff --git a/C/playbackExample/src/playback.h b/C/playbackExample/src/playback.h index e54a3b1..98fa54b 100644 --- a/C/playbackExample/src/playback.h +++ b/C/playbackExample/src/playback.h @@ -1,4 +1,4 @@ -//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//Copyright (c) 2013-2016 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. // //DISCLAIMERS diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 24fb56e..e201a75 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -1,4 +1,4 @@ -//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//Copyright (c) 2013-2016 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. // //DISCLAIMERS @@ -38,6 +38,7 @@ // CONTRIBUTORS // CT: Christopher Teubert (christopher.a.teubert@nasa.gov) // JW: Jason Watkins (jason.w.watkins@nasa.gov) + #include "xplaneConnect.h" #include @@ -46,12 +47,18 @@ #include #include #include + +#ifdef _WIN32 #include +#else +#include +#endif int sendUDP(XPCSocket sock, char buffer[], int len); int readUDP(XPCSocket sock, char buffer[], int len); int sendDREFRequest(XPCSocket sock, const char* drefs[], unsigned char count); int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int sizes[]); + void printError(char *functionName, char *format, ...) { va_list args; @@ -306,8 +313,9 @@ int sendDATA(XPCSocket sock, float data[][9], int rows) // 5 byte header + 134 rows * 9 values * 4 bytes per value => 4829 byte max length. char buffer[4829] = "DATA"; int len = 5 + rows * 9 * sizeof(float); - unsigned short step = 9 * sizeof(float); - for (int i=0;i 134) { - printError("sendDATA", "Too many rows."); + printError("readDATA", "Too many rows."); // Read as much as we can anyway rows = 134; } // Read data char buffer[4829] = { 0 }; - int result = readUDP(sock, buffer, 5120); + int result = readUDP(sock, buffer, 4829); if (result <= 0) { printError("readDATA", "Failed to read from socket."); @@ -346,12 +354,17 @@ int readDATA(XPCSocket sock, float data[][9], int rows) if (readRows > rows) { printError("readDATA", "Read more rows than will fit in dataRef."); - // Copy as much data as we can anyway + } + else if (readRows < rows) + { + printError("readDATA", "Read fewer rows than expected."); + // Copy as much data as we read anyway rows = readRows; } // Parse data - for (int i = 0; i < rows; ++i) + int i; // iterator + for (i = 0; i < rows; ++i) { data[i][0] = buffer[5 + i * 36]; memcpy(&data[i][1], &buffer[9 + i * 36], 8 * sizeof(float)); @@ -376,7 +389,8 @@ int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[], // Max size is technically unlimited. unsigned char buffer[65536] = "DREF"; int pos = 5; - for (int i = 0; i < count; ++i) + int i; // Iterator + for (i = 0; i < count; ++i) { int drefLen = strnlen(drefs[i], 256); if (pos + drefLen + sizes[i] * 4 + 2 > 65536) @@ -422,7 +436,8 @@ int sendDREFRequest(XPCSocket sock, const char* drefs[], unsigned char count) unsigned char buffer[65536] = "GETD"; buffer[5] = count; int len = 6; - for (int i = 0; i < count; ++i) + int i; // iterator + for (i = 0; i < count; ++i) { size_t drefLen = strnlen(drefs[i], 256); if (drefLen > 255) @@ -470,7 +485,8 @@ int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int si } int cur = 6; - for (int i = 0; i < count; ++i) + int i; // Iterator + for (i = 0; i < count; ++i) { int l = buffer[cur++]; if (l > sizes[i]) @@ -571,7 +587,8 @@ int sendPOSI(XPCSocket sock, float values[], int size, char ac) // 5 byte header + up to 7 values * 5 bytes each unsigned char buffer[40] = "POSI"; buffer[5] = ac; - for (int i = 0; i < 7; i++) + int i; // iterator + for (i = 0; i < 7; i++) { float val = -998; @@ -650,7 +667,8 @@ int sendCTRL(XPCSocket sock, float values[], int size, char ac) // 5 byte header + 5 float values * 4 + 2 byte values unsigned char buffer[31] = "CTRL"; int cur = 5; - for (int i = 0; i < 6; i++) + int i; // iterator + for (i = 0; i < 6; i++) { float val = -998; diff --git a/C/src/xplaneConnect.h b/C/src/xplaneConnect.h index 161178a..b701c88 100644 --- a/C/src/xplaneConnect.h +++ b/C/src/xplaneConnect.h @@ -1,4 +1,4 @@ -//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//Copyright (c) 2013-2016 United States Government as represented by the Administrator of the //National Aeronautics and Space Administration. All Rights Reserved. // //DISCLAIMERS diff --git a/Java/src/ViewType.java b/Java/src/ViewType.java index 2f24c3d..0457050 100644 --- a/Java/src/ViewType.java +++ b/Java/src/ViewType.java @@ -1,5 +1,5 @@ //NOTICES: -// Copyright ã 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2016 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // DISCLAIMERS diff --git a/Java/src/WaypointOp.java b/Java/src/WaypointOp.java index 2424d30..116d848 100644 --- a/Java/src/WaypointOp.java +++ b/Java/src/WaypointOp.java @@ -1,5 +1,5 @@ //NOTICES: -// Copyright ã 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2016 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // DISCLAIMERS diff --git a/Java/src/XPlaneConnect.java b/Java/src/XPlaneConnect.java index f98816e..8b1f228 100644 --- a/Java/src/XPlaneConnect.java +++ b/Java/src/XPlaneConnect.java @@ -1,5 +1,5 @@ //NOTICES: -// Copyright ã 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2016 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // DISCLAIMERS diff --git a/MATLAB/+XPlaneConnect/readDATA.m b/MATLAB/+XPlaneConnect/readDATA.m index 80f888e..1667c71 100644 --- a/MATLAB/+XPlaneConnect/readDATA.m +++ b/MATLAB/+XPlaneConnect/readDATA.m @@ -37,7 +37,7 @@ import XPlaneConnect.* %% Get client global clients; if ~exist('socket', 'var') - assert(istrue(length(clients) < 2), '[readDATA] ERROR: Multiple clients open. You must specify which client to use.'); + assert(isequal((length(clients) < 2),1), '[readDATA] ERROR: Multiple clients open. You must specify which client to use.'); if isempty(clients) socket = openUDP(); else @@ -46,7 +46,7 @@ if ~exist('socket', 'var') end %% Get data -result.raw = socket.readDATA(); +result.raw = socket.readData(); %% Format data rows = (length(result.raw) - 5) / 9; diff --git a/MATLAB/+XPlaneConnect/selectDATA.m b/MATLAB/+XPlaneConnect/selectDATA.m index dc54fdc..47293f2 100644 --- a/MATLAB/+XPlaneConnect/selectDATA.m +++ b/MATLAB/+XPlaneConnect/selectDATA.m @@ -19,7 +19,7 @@ import XPlaneConnect.* %% Get client global clients; if ~exist('socket', 'var') - assert(istrue(length(clients) < 2), '[selectDATA] ERROR: Multiple clients open. You must specify which client to use.'); + assert(isequal((length(clients) < 2),1), '[selectDATA] ERROR: Multiple clients open. You must specify which client to use.'); if isempty(clients) socket = openUDP(); else diff --git a/README.md b/README.md index 5af7622..2e54417 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ against the "develop" branch. Pull requests will be evaluated and integrated int the next official release. ###Notices -Copyright ©2013-2015 United States Government as represented by the Administrator +Copyright ©2013-2016 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved. No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY diff --git a/TestScripts/C Tests.win/CTests.vcxproj b/TestScripts/C Tests.win/CTests.vcxproj index 6c55744..70937c9 100644 --- a/TestScripts/C Tests.win/CTests.vcxproj +++ b/TestScripts/C Tests.win/CTests.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -44,26 +44,26 @@ Application true - v120 + v140 MultiByte Application true - v120 + v140 MultiByte Application false - v120 + v140 true MultiByte Application false - v120 + v140 true MultiByte diff --git a/TestScripts/C Tests.win/CTests.vcxproj.filters b/TestScripts/C Tests.win/CTests.vcxproj.filters index 6e294b0..fca300e 100644 --- a/TestScripts/C Tests.win/CTests.vcxproj.filters +++ b/TestScripts/C Tests.win/CTests.vcxproj.filters @@ -56,5 +56,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/TestScripts/C Tests/CtrlTests.h b/TestScripts/C Tests/CtrlTests.h index 7b9e445..572ea07 100644 --- a/TestScripts/C Tests/CtrlTests.h +++ b/TestScripts/C Tests/CtrlTests.h @@ -6,7 +6,7 @@ #include "Test.h" #include "xplaneConnect.h" -int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[7]) +int doCTRLTest(XPCSocket *sock, char* drefs[7], float values[], int size, int ac, float expected[7]) { float* data[7]; int sizes[7]; @@ -17,13 +17,13 @@ int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[ } // Execute command - XPCSocket sock = openUDP(IP); - int result = sendCTRL(sock, values, size, ac); + int result = sendCTRL(*sock, values, size, ac); + int d = 0.0f; if (result >= 0) { - result = getDREFs(sock, drefs, data, 7, sizes); + result = getDREFs(*sock, drefs, data, 7, sizes); } - closeUDP(sock); + if (result < 0) { return -1; @@ -35,6 +35,7 @@ int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[ { actual[i] = data[i][0]; } + return compareArray(expected, actual, 7); } @@ -70,11 +71,14 @@ int basicCTRLTest(char** drefs, int ac) // Set control surfaces to known state. float CTRL[6] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F }; float expected[7] = { 0.0F, 0.0F, 0.0F, NAN, NAN, NAN, NAN }; - int result = doCTRLTest(drefs, CTRL, 3, ac, expected); + XPCSocket sock = openUDP(IP); + pauseSim(sock, 1); // Pause so the controls wont change between 2 and 3 + int result = doCTRLTest(&sock, drefs, CTRL, 3, ac, expected); if (result < 0) { return -10000 + result; } + crossPlatformUSleep(SLEEP_AMOUNT); // Test control surfaces and set other values to known state. expected[0] = CTRL[0] = 0.2F; @@ -83,22 +87,29 @@ int basicCTRLTest(char** drefs, int ac) expected[3] = 0.8F; expected[4] = 1.0F; expected[5] = 0.5F; - result = doCTRLTest(drefs, CTRL, 6, ac, expected); + result = doCTRLTest(&sock, drefs, CTRL, 6, ac, expected); if (result < 0) { return -20000 + result; } + crossPlatformUSleep(SLEEP_AMOUNT); // Test other values and verify control surfaces unchanged. - CTRL[0] = -998; - CTRL[1] = -998; - CTRL[2] = -998; + expected[0] = CTRL[0] = 0.15F; + expected[1] = CTRL[1] = 0.15F; + expected[2] = CTRL[2] = 0.15F; expected[3] = CTRL[3] = 0.9F; - expected[4] = CTRL[4] = 0.0F; - expected[5] = CTRL[5] = 0.75F; - result = doCTRLTest(drefs, CTRL, 6, ac, expected); + CTRL[4] = -998; + CTRL[5] = -998; + result = doCTRLTest(&sock, drefs, CTRL, 6, ac, expected); + + pauseSim(sock, 0); + closeUDP(sock); if (result < 0) { + if (result == -1004) { + printf("GEAR FAILURE... ARE YOU USING AN AIRCRAFT WITH FIXED GEARS? "); + } return -30000 + result; } return 0; @@ -129,7 +140,7 @@ int testCTRL_NonPlayer() "sim/multiplayer/position/plane1_throttle", "sim/multiplayer/position/plane1_gear_deploy", "sim/multiplayer/position/plane1_flap_ratio", - "sim/multiplayer/position/plane1_sbrkrqst" + "sim/multiplayer/position/plane1_speedbrake_ratio" }; return basicCTRLTest(drefs, 1); } @@ -150,7 +161,9 @@ int testCTRL_Speedbrakes() // Arm float CTRL[7] = { -998, -998, -998, -998, -998, -998, -0.5F }; float expected[7] = { NAN, NAN, NAN, NAN, NAN, NAN, -0.5F }; - int result = doCTRLTest(drefs, CTRL, 7, 0, expected); + XPCSocket sock = openUDP(IP); + pauseSim(sock, 1); // Pause so the controls wont change between 2 and 3 + int result = doCTRLTest(&sock, drefs, CTRL, 7, 0, expected); if (result < 0) { return -10000 + result; @@ -158,7 +171,7 @@ int testCTRL_Speedbrakes() // Set to full expected[6] = CTRL[6] = 1.5F; - result = doCTRLTest(drefs, CTRL, 7, 0, expected); + result = doCTRLTest(&sock, drefs, CTRL, 7, 0, expected); if (result < 0) { return -20000 + result; @@ -166,7 +179,9 @@ int testCTRL_Speedbrakes() // Retract expected[6] = CTRL[6] = 0.0F; - result = doCTRLTest(drefs, CTRL, 7, 0, expected); + result = doCTRLTest(&sock, drefs, CTRL, 7, 0, expected); + pauseSim(sock, 0); + closeUDP(sock); if (result < 0) { return -30000 + result; diff --git a/TestScripts/C Tests/Test.c b/TestScripts/C Tests/Test.c index cce713c..11ddc48 100644 --- a/TestScripts/C Tests/Test.c +++ b/TestScripts/C Tests/Test.c @@ -21,6 +21,14 @@ void runTest(int(*test)(), char* name) } } +void crossPlatformUSleep(int uSleep) { +#ifdef _WIN32 + Sleep(uSleep/1000); +#else + usleep(uSleep); +#endif +} + int compareFloat(float expected, float actual) { return feq(expected, actual) || isnan(expected) ? 0 : -1; diff --git a/TestScripts/C Tests/Test.h b/TestScripts/C Tests/Test.h index c05a5eb..5c40d40 100644 --- a/TestScripts/C Tests/Test.h +++ b/TestScripts/C Tests/Test.h @@ -9,10 +9,22 @@ #include #include +#ifdef LINUX +#include +#endif +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include +#endif + +#define SLEEP_AMOUNT 100000 + #define feq(x, y) (fabs(x - y) < 1e-4) #define IP "127.0.0.1" +void crossPlatformUSleep(int uSleep); + extern int testFailed; extern int testPassed; diff --git a/TestScripts/C Tests/main.c b/TestScripts/C Tests/main.c index 26428eb..ec2b752 100644 --- a/TestScripts/C Tests/main.c +++ b/TestScripts/C Tests/main.c @@ -11,8 +11,7 @@ #include "ViewTests.h" #include "WyptTests.h" -int main(int argc, const char * argv[]) -{ +int main(int argc, const char * argv[]) { printf("XPC Tests-c "); #ifdef _WIN32 @@ -27,36 +26,58 @@ int main(int argc, const char * argv[]) // Basic Networking runTest(testOpen, "open"); + crossPlatformUSleep(SLEEP_AMOUNT); runTest(testClose, "close"); + crossPlatformUSleep(SLEEP_AMOUNT); + // Datarefs runTest(testGETD_Basic, "GETD"); + crossPlatformUSleep(SLEEP_AMOUNT); runTest(testGETD_Types, "GETD (types)"); + crossPlatformUSleep(SLEEP_AMOUNT); runTest(testGETD_TestFloat, "GETD (test float)"); + crossPlatformUSleep(SLEEP_AMOUNT); runTest(testDREF, "DREF"); // Pause - runTest(testSIMU_Basic, "SIMU"); - runTest(testSIMU_Toggle, "SIMU (toggle)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testSIMU_Basic, "SIMU"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testSIMU_Toggle, "SIMU (toggle)"); // CTRL - runTest(testCTRL_Player, "CTRL (player)"); - runTest(testCTRL_NonPlayer, "CTRL (non-player)"); - runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)"); - runTest(testGETC, "GETC (player)"); - runTest(testGETC_NonPlayer, "GETC (Non-player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testCTRL_Player, "CTRL (player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testCTRL_NonPlayer, "CTRL (non-player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testGETC, "GETC (player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testGETC_NonPlayer, "GETC (Non-player)"); // POSI - runTest(testPOSI_Player, "POSI (player)"); - runTest(testPOSI_NonPlayer, "POSI (non-player)"); - runTest(testGetPOSI_Player, "GETP (player)"); - runTest(testGetPOSI_NonPlayer, "GETP (non-player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testPOSI_Player, "POSI (player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testPOSI_NonPlayer, "POSI (non-player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testGetPOSI_Player, "GETP (player)"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testGetPOSI_NonPlayer, "GETP (non-player)"); // Data - runTest(testDATA, "DATA"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testDATA, "DATA"); // Text - runTest(testTEXT, "TEXT"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testTEXT, "TEXT"); // Waypoints - runTest(testWYPT, "WYPT"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testWYPT, "WYPT"); // View - runTest(testView, "VIEW"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testView, "VIEW"); // setConn - runTest(testCONN, "CONN"); + crossPlatformUSleep(SLEEP_AMOUNT); + runTest(testCONN, "CONN"); printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed ); printf("Press any key to exit."); diff --git a/xpcPlugin/DataManager.cpp b/xpcPlugin/DataManager.cpp index 4571006..3db7a5b 100644 --- a/xpcPlugin/DataManager.cpp +++ b/xpcPlugin/DataManager.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // X-Plane API @@ -680,6 +680,17 @@ namespace XPC pos[2] = (float)GetDouble(DREF_Elevation, aircraft); } + // See: http://www.xsquawkbox.net/xpsdk/mediawiki/MovingThePlane + // Need to get the aircraft's current orientation before moving and + // reset the orientation after moving to update the quaternion + float orient[3]; + orient[0] = GetFloat(DREF_Pitch, aircraft); + orient[1] = GetFloat(DREF_Roll, aircraft); + orient[2] = GetFloat(DREF_HeadingTrue, aircraft); + + // Now set the aircraft's position. Need to set world position for + // "long" moves, but since there isn't an easy way to calculate "long", + // we just set it every time. double local[3]; XPLMWorldToLocal(pos[0], pos[1], pos[2], &local[0], &local[1], &local[2]); // If the sim is paused, setting global position won't update the @@ -691,6 +702,9 @@ namespace XPC Set(DREF_Latitude, (double)pos[0], aircraft); Set(DREF_Longitude, (double)pos[1], aircraft); Set(DREF_Elevation, (double)pos[2], aircraft); + + // Now reset orientation to update q + SetOrientation(orient, aircraft); } void DataManager::SetOrientation(float orient[3], char aircraft) diff --git a/xpcPlugin/DataManager.h b/xpcPlugin/DataManager.h index cc38619..c0e80c2 100644 --- a/xpcPlugin/DataManager.h +++ b/xpcPlugin/DataManager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #ifndef XPCPLUGIN_DATAMANAGER_H_ #define XPCPLUGIN_DATAMANAGER_H_ diff --git a/xpcPlugin/Drawing.cpp b/xpcPlugin/Drawing.cpp index d7539b6..d737e36 100644 --- a/xpcPlugin/Drawing.cpp +++ b/xpcPlugin/Drawing.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // X-Plane API diff --git a/xpcPlugin/Drawing.h b/xpcPlugin/Drawing.h index 139c1d2..51c39de 100644 --- a/xpcPlugin/Drawing.h +++ b/xpcPlugin/Drawing.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #ifndef XPCPLUGIN_DRAWING_H_ #define XPCPLUGIN_DRAWING_H_ diff --git a/xpcPlugin/Log.cpp b/xpcPlugin/Log.cpp index 7b849dd..a059ebb 100644 --- a/xpcPlugin/Log.cpp +++ b/xpcPlugin/Log.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #include "Log.h" @@ -111,7 +111,7 @@ namespace XPC std::fprintf(fd, "X-Plane Connect [Version %s]\n", version.c_str()); std::fprintf(fd, "Compiled %s %s\n", __DATE__, __TIME__); - std::fprintf(fd, "Copyright (c) 2013-2015 United States Government as represented by the\n"); + std::fprintf(fd, "Copyright (c) 2013-2017 United States Government as represented by the\n"); std::fprintf(fd, "Administrator of the National Aeronautics and Space Administration.\n"); std::fprintf(fd, "All Rights Reserved.\n\n"); diff --git a/xpcPlugin/Log.h b/xpcPlugin/Log.h index 018bf6c..cd6b6ba 100644 --- a/xpcPlugin/Log.h +++ b/xpcPlugin/Log.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #ifndef XPCPLUGIN_LOG_H_ #define XPCPLUGIN_LOG_H_ diff --git a/xpcPlugin/Message.cpp b/xpcPlugin/Message.cpp index 3563a09..81c5c9c 100644 --- a/xpcPlugin/Message.cpp +++ b/xpcPlugin/Message.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #include "Message.h" #include "Log.h" diff --git a/xpcPlugin/Message.h b/xpcPlugin/Message.h index 095b77d..34071cb 100644 --- a/xpcPlugin/Message.h +++ b/xpcPlugin/Message.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #ifndef XPCPLUGIN_MESSAGE_H_ #define XPCPLUGIN_MESSAGE_H_ @@ -26,9 +26,6 @@ namespace XPC /// with the size set to 0. static Message ReadFrom(const UDPSocket& sock); - /// Gets the message header in binary form. - unsigned long GetMagicNumber() const; - /// Gets the message header. std::string GetHead() const; diff --git a/xpcPlugin/MessageHandlers.cpp b/xpcPlugin/MessageHandlers.cpp index d94be09..89d6852 100644 --- a/xpcPlugin/MessageHandlers.cpp +++ b/xpcPlugin/MessageHandlers.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // X-Plane API diff --git a/xpcPlugin/MessageHandlers.h b/xpcPlugin/MessageHandlers.h index d7f317d..3a48007 100644 --- a/xpcPlugin/MessageHandlers.h +++ b/xpcPlugin/MessageHandlers.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #ifndef XPCPLUGIN_MESSAGEHANDLERS_H_ #define XPCPLUGIN_MESSAGEHANDLERS_H_ diff --git a/xpcPlugin/UDPSocket.cpp b/xpcPlugin/UDPSocket.cpp index 210cc56..8f4577f 100644 --- a/xpcPlugin/UDPSocket.cpp +++ b/xpcPlugin/UDPSocket.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #include "Log.h" #include "UDPSocket.h" diff --git a/xpcPlugin/UDPSocket.h b/xpcPlugin/UDPSocket.h index 5b87439..6a4b785 100644 --- a/xpcPlugin/UDPSocket.h +++ b/xpcPlugin/UDPSocket.h @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. #ifndef XPCPLUGIN_SOCKET_H_ #define XPCPLUGIN_SOCKET_H_ diff --git a/xpcPlugin/XPCPlugin.cpp b/xpcPlugin/XPCPlugin.cpp index f94b98a..e02f1d2 100755 --- a/xpcPlugin/XPCPlugin.cpp +++ b/xpcPlugin/XPCPlugin.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +// Copyright (c) 2013-2017 United States Government as represented by the Administrator of the // National Aeronautics and Space Administration. All Rights Reserved. // // DISCLAIMERS @@ -79,8 +79,6 @@ double start; double lap; static double timeConvert = 0.0; int benchmarkingSwitch = 0; // 1 = time for operations, 2 = time for op + cycle; -int cyclesToClear = -1; // Clear message bus every n cycles. -1 == dont clear -int counter = 0; PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc); PLUGIN_API void XPluginStop(void); @@ -91,9 +89,9 @@ static float XPCFlightLoopCallback(float inElapsedSinceLastCall, float inElapsed PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc) { - strcpy(outName, "X-Plane Connect [Version 1.2.0]"); + strcpy(outName, "X-Plane Connect [Version 1.2.1]"); strcpy(outSig, "NASA.XPlaneConnect"); - strcpy(outDesc, "X Plane Communications Toolbox\nCopyright (c) 2013-2015 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved."); + strcpy(outDesc, "X Plane Communications Toolbox\nCopyright (c) 2013-2017 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved."); #if (__APPLE__) if ( abs(timeConvert) <= 1e-9 ) // is about 0 @@ -105,7 +103,7 @@ PLUGIN_API int XPluginStart(char* outName, char* outSig, char* outDesc) 1000000000.0; } #endif - XPC::Log::Initialize("1.1.1"); + XPC::Log::Initialize("1.2.1"); XPC::Log::WriteLine(LOG_INFO, "EXEC", "Plugin Start"); XPC::DataManager::Initialize(); @@ -170,13 +168,13 @@ float XPCFlightLoopCallback(float inElapsedSinceLastCall, double diff_t; #endif - counter++; if (benchmarkingSwitch > 1) { XPC::Log::FormatLine(LOG_DEBUG, "EXEC", "Cycle time %.6f", inElapsedSinceLastCall); } - for (int i = 0; i < OPS_PER_CYCLE; i++) + int ops; + for (ops = 0; ops < OPS_PER_CYCLE; ops++) { if (benchmarkingSwitch > 0) { @@ -202,11 +200,18 @@ float XPCFlightLoopCallback(float inElapsedSinceLastCall, } } - if (cyclesToClear != -1 && counter%cyclesToClear == 0) + // If we have processed the maximum number of requests in a single frame, + // the socket is probably overloaded. Hopefully this is caused by a + // transitory event like a long load inside X-Plane that caused us to stop + // responding to requests for a while. We drop the current socket and + // re-create it to drop any old packets that have probably already timed + // out on the client side. + if (ops == OPS_PER_CYCLE) { - XPC::Log::WriteLine(LOG_DEBUG, "EXEC", "Cleared UDP Buffer"); + XPC::Log::WriteLine(LOG_WARN, "EXEC", "Cleared UDP Buffer"); delete sock; sock = new XPC::UDPSocket(RECVPORT); + XPC::MessageHandlers::SetSocket(sock); } return -1; } diff --git a/xpcPlugin/XPlaneConnect/64/lin.xpl b/xpcPlugin/XPlaneConnect/64/lin.xpl index 476986c..47cf274 100755 Binary files a/xpcPlugin/XPlaneConnect/64/lin.xpl and b/xpcPlugin/XPlaneConnect/64/lin.xpl differ diff --git a/xpcPlugin/XPlaneConnect/64/win.xpl b/xpcPlugin/XPlaneConnect/64/win.xpl index 1328419..d706dc7 100644 Binary files a/xpcPlugin/XPlaneConnect/64/win.xpl and b/xpcPlugin/XPlaneConnect/64/win.xpl differ diff --git a/xpcPlugin/XPlaneConnect/lin.xpl b/xpcPlugin/XPlaneConnect/lin.xpl index a1780c7..c1c2383 100755 Binary files a/xpcPlugin/XPlaneConnect/lin.xpl and b/xpcPlugin/XPlaneConnect/lin.xpl differ diff --git a/xpcPlugin/XPlaneConnect/mac.xpl b/xpcPlugin/XPlaneConnect/mac.xpl index aa4d819..1ecf5ca 100755 Binary files a/xpcPlugin/XPlaneConnect/mac.xpl and b/xpcPlugin/XPlaneConnect/mac.xpl differ diff --git a/xpcPlugin/XPlaneConnect/win.xpl b/xpcPlugin/XPlaneConnect/win.xpl index 0813198..20d6094 100644 Binary files a/xpcPlugin/XPlaneConnect/win.xpl and b/xpcPlugin/XPlaneConnect/win.xpl differ diff --git a/xpcPlugin/xpcPlugin.xcodeproj/project.pbxproj b/xpcPlugin/xpcPlugin.xcodeproj/project.pbxproj index 4dbd663..a7ed423 100755 --- a/xpcPlugin/xpcPlugin.xcodeproj/project.pbxproj +++ b/xpcPlugin/xpcPlugin.xcodeproj/project.pbxproj @@ -365,7 +365,9 @@ "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/xplaneConnect-asdjuezcjkhojuewbyxhyhabxfwc/Build/Products/Debug", ); MACH_O_TYPE = mh_bundle; + ONLY_ACTIVE_ARCH = NO; + PRODUCT_NAME = mac; SDKROOT = macosx; STRIP_INSTALLED_PRODUCT = YES; diff --git a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj index 70c01f1..2f48de6 100644 --- a/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj +++ b/xpcPlugin/xpcPlugin/xpcPlugin.vcxproj @@ -22,30 +22,31 @@ {6AEF5D28-2701-44FF-AE10-1DEF07C5CAEA} Win32Proj xpcPlugin + 8.1 DynamicLibrary true - v120 + v140 MultiByte DynamicLibrary true - v120 + v140 MultiByte DynamicLibrary true - v120 + v140 MultiByte DynamicLibrary true - v120 + v140 MultiByte