Merge branch 'develop' into master

This commit is contained in:
Jason Watkins
2017-05-07 21:58:43 -07:00
committed by GitHub
40 changed files with 190 additions and 94 deletions

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// DISCLAIMERS // DISCLAIMERS

View File

@@ -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. //National Aeronautics and Space Administration. All Rights Reserved.
// //
//DISCLAIMERS //DISCLAIMERS

View File

@@ -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. //National Aeronautics and Space Administration. All Rights Reserved.
// //
//DISCLAIMERS //DISCLAIMERS

View File

@@ -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. //National Aeronautics and Space Administration. All Rights Reserved.
// //
//DISCLAIMERS //DISCLAIMERS

View File

@@ -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. //National Aeronautics and Space Administration. All Rights Reserved.
// //
//DISCLAIMERS //DISCLAIMERS

View File

@@ -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. //National Aeronautics and Space Administration. All Rights Reserved.
// //
//DISCLAIMERS //DISCLAIMERS

View File

@@ -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. //National Aeronautics and Space Administration. All Rights Reserved.
// //
//DISCLAIMERS //DISCLAIMERS
@@ -38,6 +38,7 @@
// CONTRIBUTORS // CONTRIBUTORS
// CT: Christopher Teubert (christopher.a.teubert@nasa.gov) // CT: Christopher Teubert (christopher.a.teubert@nasa.gov)
// JW: Jason Watkins (jason.w.watkins@nasa.gov) // JW: Jason Watkins (jason.w.watkins@nasa.gov)
#include "xplaneConnect.h" #include "xplaneConnect.h"
#include <math.h> #include <math.h>
@@ -46,12 +47,18 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef _WIN32
#include <time.h> #include <time.h>
#else
#include <sys/time.h>
#endif
int sendUDP(XPCSocket sock, char buffer[], int len); int sendUDP(XPCSocket sock, char buffer[], int len);
int readUDP(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 sendDREFRequest(XPCSocket sock, const char* drefs[], unsigned char count);
int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int sizes[]); int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int sizes[]);
void printError(char *functionName, char *format, ...) void printError(char *functionName, char *format, ...)
{ {
va_list args; 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. // 5 byte header + 134 rows * 9 values * 4 bytes per value => 4829 byte max length.
char buffer[4829] = "DATA"; char buffer[4829] = "DATA";
int len = 5 + rows * 9 * sizeof(float); int len = 5 + rows * 9 * sizeof(float);
unsigned short step = 9 * sizeof(float); unsigned short step = 9 * sizeof(float);
for (int i=0;i<rows;i++) int i; // iterator
for (i = 0; i < rows; i++)
{ {
buffer[5 + i * step] = (char)data[i][0]; buffer[5 + i * step] = (char)data[i][0];
memcpy(&buffer[9 + i*step], &data[i][1], 8 * sizeof(float)); memcpy(&buffer[9 + i*step], &data[i][1], 8 * sizeof(float));
@@ -328,14 +336,14 @@ int readDATA(XPCSocket sock, float data[][9], int rows)
// shouldn't be trying to read nearly this much data at once anyway. // shouldn't be trying to read nearly this much data at once anyway.
if (rows > 134) if (rows > 134)
{ {
printError("sendDATA", "Too many rows."); printError("readDATA", "Too many rows.");
// Read as much as we can anyway // Read as much as we can anyway
rows = 134; rows = 134;
} }
// Read data // Read data
char buffer[4829] = { 0 }; char buffer[4829] = { 0 };
int result = readUDP(sock, buffer, 5120); int result = readUDP(sock, buffer, 4829);
if (result <= 0) if (result <= 0)
{ {
printError("readDATA", "Failed to read from socket."); printError("readDATA", "Failed to read from socket.");
@@ -346,12 +354,17 @@ int readDATA(XPCSocket sock, float data[][9], int rows)
if (readRows > rows) if (readRows > rows)
{ {
printError("readDATA", "Read more rows than will fit in dataRef."); 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; rows = readRows;
} }
// Parse data // 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]; data[i][0] = buffer[5 + i * 36];
memcpy(&data[i][1], &buffer[9 + i * 36], 8 * sizeof(float)); 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. // Max size is technically unlimited.
unsigned char buffer[65536] = "DREF"; unsigned char buffer[65536] = "DREF";
int pos = 5; 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); int drefLen = strnlen(drefs[i], 256);
if (pos + drefLen + sizes[i] * 4 + 2 > 65536) 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"; unsigned char buffer[65536] = "GETD";
buffer[5] = count; buffer[5] = count;
int len = 6; 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); size_t drefLen = strnlen(drefs[i], 256);
if (drefLen > 255) if (drefLen > 255)
@@ -470,7 +485,8 @@ int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int si
} }
int cur = 6; int cur = 6;
for (int i = 0; i < count; ++i) int i; // Iterator
for (i = 0; i < count; ++i)
{ {
int l = buffer[cur++]; int l = buffer[cur++];
if (l > sizes[i]) 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 // 5 byte header + up to 7 values * 5 bytes each
unsigned char buffer[40] = "POSI"; unsigned char buffer[40] = "POSI";
buffer[5] = ac; buffer[5] = ac;
for (int i = 0; i < 7; i++) int i; // iterator
for (i = 0; i < 7; i++)
{ {
float val = -998; 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 // 5 byte header + 5 float values * 4 + 2 byte values
unsigned char buffer[31] = "CTRL"; unsigned char buffer[31] = "CTRL";
int cur = 5; int cur = 5;
for (int i = 0; i < 6; i++) int i; // iterator
for (i = 0; i < 6; i++)
{ {
float val = -998; float val = -998;

View File

@@ -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. //National Aeronautics and Space Administration. All Rights Reserved.
// //
//DISCLAIMERS //DISCLAIMERS

View File

@@ -1,5 +1,5 @@
//NOTICES: //NOTICES:
// Copyright <EFBFBD> 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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// DISCLAIMERS // DISCLAIMERS

View File

@@ -1,5 +1,5 @@
//NOTICES: //NOTICES:
// Copyright <EFBFBD> 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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// DISCLAIMERS // DISCLAIMERS

View File

@@ -1,5 +1,5 @@
//NOTICES: //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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// DISCLAIMERS // DISCLAIMERS

View File

@@ -37,7 +37,7 @@ import XPlaneConnect.*
%% Get client %% Get client
global clients; global clients;
if ~exist('socket', 'var') 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) if isempty(clients)
socket = openUDP(); socket = openUDP();
else else
@@ -46,7 +46,7 @@ if ~exist('socket', 'var')
end end
%% Get data %% Get data
result.raw = socket.readDATA(); result.raw = socket.readData();
%% Format data %% Format data
rows = (length(result.raw) - 5) / 9; rows = (length(result.raw) - 5) / 9;

View File

@@ -19,7 +19,7 @@ import XPlaneConnect.*
%% Get client %% Get client
global clients; global clients;
if ~exist('socket', 'var') 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) if isempty(clients)
socket = openUDP(); socket = openUDP();
else else

View File

@@ -66,8 +66,9 @@ If you would like to contribute directly, please feel free to open a pull reques
against the "develop" branch. Pull requests will be evaluated and integrated into against the "develop" branch. Pull requests will be evaluated and integrated into
the next official release. the next official release.
### Notices ### Notices
Copyright ©2013-2015 United States Government as represented by the Administrator Copyright ©2013-2017 United States Government as represented by the Administrator
of the National Aeronautics and Space Administration. All Rights Reserved. of the National Aeronautics and Space Administration. All Rights Reserved.
No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations"> <ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32"> <ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration> <Configuration>Debug</Configuration>
@@ -44,26 +44,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries> <UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization> <WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>

View File

@@ -56,5 +56,8 @@
<ClInclude Include="..\C Tests\Test.h"> <ClInclude Include="..\C Tests\Test.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\C Tests\ViewTests.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -6,7 +6,7 @@
#include "Test.h" #include "Test.h"
#include "xplaneConnect.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]; float* data[7];
int sizes[7]; int sizes[7];
@@ -17,13 +17,13 @@ int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[
} }
// Execute command // 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) if (result >= 0)
{ {
result = getDREFs(sock, drefs, data, 7, sizes); result = getDREFs(*sock, drefs, data, 7, sizes);
} }
closeUDP(sock);
if (result < 0) if (result < 0)
{ {
return -1; return -1;
@@ -35,6 +35,7 @@ int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[
{ {
actual[i] = data[i][0]; actual[i] = data[i][0];
} }
return compareArray(expected, actual, 7); return compareArray(expected, actual, 7);
} }
@@ -70,11 +71,14 @@ int basicCTRLTest(char** drefs, int ac)
// Set control surfaces to known state. // Set control surfaces to known state.
float CTRL[6] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F }; 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 }; 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) if (result < 0)
{ {
return -10000 + result; return -10000 + result;
} }
crossPlatformUSleep(SLEEP_AMOUNT);
// Test control surfaces and set other values to known state. // Test control surfaces and set other values to known state.
expected[0] = CTRL[0] = 0.2F; expected[0] = CTRL[0] = 0.2F;
@@ -83,22 +87,29 @@ int basicCTRLTest(char** drefs, int ac)
expected[3] = 0.8F; expected[3] = 0.8F;
expected[4] = 1.0F; expected[4] = 1.0F;
expected[5] = 0.5F; expected[5] = 0.5F;
result = doCTRLTest(drefs, CTRL, 6, ac, expected); result = doCTRLTest(&sock, drefs, CTRL, 6, ac, expected);
if (result < 0) if (result < 0)
{ {
return -20000 + result; return -20000 + result;
} }
crossPlatformUSleep(SLEEP_AMOUNT);
// Test other values and verify control surfaces unchanged. // Test other values and verify control surfaces unchanged.
CTRL[0] = -998; expected[0] = CTRL[0] = 0.15F;
CTRL[1] = -998; expected[1] = CTRL[1] = 0.15F;
CTRL[2] = -998; expected[2] = CTRL[2] = 0.15F;
expected[3] = CTRL[3] = 0.9F; expected[3] = CTRL[3] = 0.9F;
expected[4] = CTRL[4] = 0.0F; CTRL[4] = -998;
expected[5] = CTRL[5] = 0.75F; CTRL[5] = -998;
result = doCTRLTest(drefs, CTRL, 6, ac, expected); result = doCTRLTest(&sock, drefs, CTRL, 6, ac, expected);
pauseSim(sock, 0);
closeUDP(sock);
if (result < 0) if (result < 0)
{ {
if (result == -1004) {
printf("GEAR FAILURE... ARE YOU USING AN AIRCRAFT WITH FIXED GEARS? ");
}
return -30000 + result; return -30000 + result;
} }
return 0; return 0;
@@ -129,7 +140,7 @@ int testCTRL_NonPlayer()
"sim/multiplayer/position/plane1_throttle", "sim/multiplayer/position/plane1_throttle",
"sim/multiplayer/position/plane1_gear_deploy", "sim/multiplayer/position/plane1_gear_deploy",
"sim/multiplayer/position/plane1_flap_ratio", "sim/multiplayer/position/plane1_flap_ratio",
"sim/multiplayer/position/plane1_sbrkrqst" "sim/multiplayer/position/plane1_speedbrake_ratio"
}; };
return basicCTRLTest(drefs, 1); return basicCTRLTest(drefs, 1);
} }
@@ -150,7 +161,9 @@ int testCTRL_Speedbrakes()
// Arm // Arm
float CTRL[7] = { -998, -998, -998, -998, -998, -998, -0.5F }; float CTRL[7] = { -998, -998, -998, -998, -998, -998, -0.5F };
float expected[7] = { NAN, NAN, NAN, NAN, NAN, NAN, -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) if (result < 0)
{ {
return -10000 + result; return -10000 + result;
@@ -158,7 +171,7 @@ int testCTRL_Speedbrakes()
// Set to full // Set to full
expected[6] = CTRL[6] = 1.5F; expected[6] = CTRL[6] = 1.5F;
result = doCTRLTest(drefs, CTRL, 7, 0, expected); result = doCTRLTest(&sock, drefs, CTRL, 7, 0, expected);
if (result < 0) if (result < 0)
{ {
return -20000 + result; return -20000 + result;
@@ -166,7 +179,9 @@ int testCTRL_Speedbrakes()
// Retract // Retract
expected[6] = CTRL[6] = 0.0F; 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) if (result < 0)
{ {
return -30000 + result; return -30000 + result;

View File

@@ -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) int compareFloat(float expected, float actual)
{ {
return feq(expected, actual) || isnan(expected) ? 0 : -1; return feq(expected, actual) || isnan(expected) ? 0 : -1;

View File

@@ -9,10 +9,21 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#ifdef LINUX
#include <unistd.h>
#endif
#ifdef WINDOWS
#include <windows.h>
#endif
#define SLEEP_AMOUNT 100000
#define feq(x, y) (fabs(x - y) < 1e-4) #define feq(x, y) (fabs(x - y) < 1e-4)
#define IP "127.0.0.1" #define IP "127.0.0.1"
void crossPlatformUSleep(int uSleep);
extern int testFailed; extern int testFailed;
extern int testPassed; extern int testPassed;

View File

@@ -11,8 +11,7 @@
#include "ViewTests.h" #include "ViewTests.h"
#include "WyptTests.h" #include "WyptTests.h"
int main(int argc, const char * argv[]) int main(int argc, const char * argv[]) {
{
printf("XPC Tests-c "); printf("XPC Tests-c ");
#ifdef _WIN32 #ifdef _WIN32
@@ -27,36 +26,58 @@ int main(int argc, const char * argv[])
// Basic Networking // Basic Networking
runTest(testOpen, "open"); runTest(testOpen, "open");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testClose, "close"); runTest(testClose, "close");
crossPlatformUSleep(SLEEP_AMOUNT);
// Datarefs // Datarefs
runTest(testGETD_Basic, "GETD"); runTest(testGETD_Basic, "GETD");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETD_Types, "GETD (types)"); runTest(testGETD_Types, "GETD (types)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETD_TestFloat, "GETD (test float)"); runTest(testGETD_TestFloat, "GETD (test float)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testDREF, "DREF"); runTest(testDREF, "DREF");
// Pause // Pause
runTest(testSIMU_Basic, "SIMU"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testSIMU_Toggle, "SIMU (toggle)"); runTest(testSIMU_Basic, "SIMU");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testSIMU_Toggle, "SIMU (toggle)");
// CTRL // CTRL
runTest(testCTRL_Player, "CTRL (player)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testCTRL_NonPlayer, "CTRL (non-player)"); runTest(testCTRL_Player, "CTRL (player)");
runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETC, "GETC (player)"); runTest(testCTRL_NonPlayer, "CTRL (non-player)");
runTest(testGETC_NonPlayer, "GETC (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 // POSI
runTest(testPOSI_Player, "POSI (player)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testPOSI_NonPlayer, "POSI (non-player)"); runTest(testPOSI_Player, "POSI (player)");
runTest(testGetPOSI_Player, "GETP (player)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGetPOSI_NonPlayer, "GETP (non-player)"); runTest(testPOSI_NonPlayer, "POSI (non-player)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGetPOSI_Player, "GETP (player)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGetPOSI_NonPlayer, "GETP (non-player)");
// Data // Data
runTest(testDATA, "DATA"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testDATA, "DATA");
// Text // Text
runTest(testTEXT, "TEXT"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testTEXT, "TEXT");
// Waypoints // Waypoints
runTest(testWYPT, "WYPT"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testWYPT, "WYPT");
// View // View
runTest(testView, "VIEW"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testView, "VIEW");
// setConn // setConn
runTest(testCONN, "CONN"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testCONN, "CONN");
printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed ); printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed );
printf("Press any key to exit."); printf("Press any key to exit.");

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// X-Plane API // X-Plane API
@@ -680,6 +680,17 @@ namespace XPC
pos[2] = (float)GetDouble(DREF_Elevation, aircraft); 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]; double local[3];
XPLMWorldToLocal(pos[0], pos[1], pos[2], &local[0], &local[1], &local[2]); 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 // 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_Latitude, (double)pos[0], aircraft);
Set(DREF_Longitude, (double)pos[1], aircraft); Set(DREF_Longitude, (double)pos[1], aircraft);
Set(DREF_Elevation, (double)pos[2], 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) void DataManager::SetOrientation(float orient[3], char aircraft)

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPCPLUGIN_DATAMANAGER_H_ #ifndef XPCPLUGIN_DATAMANAGER_H_
#define XPCPLUGIN_DATAMANAGER_H_ #define XPCPLUGIN_DATAMANAGER_H_

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// X-Plane API // X-Plane API

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPCPLUGIN_DRAWING_H_ #ifndef XPCPLUGIN_DRAWING_H_
#define XPCPLUGIN_DRAWING_H_ #define XPCPLUGIN_DRAWING_H_

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#include "Log.h" #include "Log.h"

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPCPLUGIN_LOG_H_ #ifndef XPCPLUGIN_LOG_H_
#define XPCPLUGIN_LOG_H_ #define XPCPLUGIN_LOG_H_

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#include "Message.h" #include "Message.h"
#include "Log.h" #include "Log.h"

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPCPLUGIN_MESSAGE_H_ #ifndef XPCPLUGIN_MESSAGE_H_
#define XPCPLUGIN_MESSAGE_H_ #define XPCPLUGIN_MESSAGE_H_
@@ -26,9 +26,6 @@ namespace XPC
/// with the size set to 0. /// with the size set to 0.
static Message ReadFrom(const UDPSocket& sock); static Message ReadFrom(const UDPSocket& sock);
/// Gets the message header in binary form.
unsigned long GetMagicNumber() const;
/// Gets the message header. /// Gets the message header.
std::string GetHead() const; std::string GetHead() const;

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// X-Plane API // X-Plane API

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPCPLUGIN_MESSAGEHANDLERS_H_ #ifndef XPCPLUGIN_MESSAGEHANDLERS_H_
#define XPCPLUGIN_MESSAGEHANDLERS_H_ #define XPCPLUGIN_MESSAGEHANDLERS_H_

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#include "Log.h" #include "Log.h"
#include "UDPSocket.h" #include "UDPSocket.h"

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
#ifndef XPCPLUGIN_SOCKET_H_ #ifndef XPCPLUGIN_SOCKET_H_
#define XPCPLUGIN_SOCKET_H_ #define XPCPLUGIN_SOCKET_H_

View File

@@ -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. // National Aeronautics and Space Administration. All Rights Reserved.
// //
// DISCLAIMERS // DISCLAIMERS
@@ -79,8 +79,6 @@ double start;
double lap; double lap;
static double timeConvert = 0.0; static double timeConvert = 0.0;
int benchmarkingSwitch = 0; // 1 = time for operations, 2 = time for op + cycle; 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 int XPluginStart(char* outName, char* outSig, char* outDesc);
PLUGIN_API void XPluginStop(void); 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) 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(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 (__APPLE__)
if ( abs(timeConvert) <= 1e-9 ) // is about 0 if ( abs(timeConvert) <= 1e-9 ) // is about 0
@@ -170,13 +168,13 @@ float XPCFlightLoopCallback(float inElapsedSinceLastCall,
double diff_t; double diff_t;
#endif #endif
counter++;
if (benchmarkingSwitch > 1) if (benchmarkingSwitch > 1)
{ {
XPC::Log::FormatLine(LOG_DEBUG, "EXEC", "Cycle time %.6f", inElapsedSinceLastCall); 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) 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; delete sock;
sock = new XPC::UDPSocket(RECVPORT); sock = new XPC::UDPSocket(RECVPORT);
XPC::MessageHandlers::SetSocket(sock);
} }
return -1; return -1;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -365,7 +365,9 @@
"$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/xplaneConnect-asdjuezcjkhojuewbyxhyhabxfwc/Build/Products/Debug", "$(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/xplaneConnect-asdjuezcjkhojuewbyxhyhabxfwc/Build/Products/Debug",
); );
MACH_O_TYPE = mh_bundle; MACH_O_TYPE = mh_bundle;
ONLY_ACTIVE_ARCH = NO; ONLY_ACTIVE_ARCH = NO;
PRODUCT_NAME = mac; PRODUCT_NAME = mac;
SDKROOT = macosx; SDKROOT = macosx;
STRIP_INSTALLED_PRODUCT = YES; STRIP_INSTALLED_PRODUCT = YES;

View File

@@ -22,30 +22,31 @@
<ProjectGuid>{6AEF5D28-2701-44FF-AE10-1DEF07C5CAEA}</ProjectGuid> <ProjectGuid>{6AEF5D28-2701-44FF-AE10-1DEF07C5CAEA}</ProjectGuid>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<RootNamespace>xpcPlugin</RootNamespace> <RootNamespace>xpcPlugin</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType> <ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset> <PlatformToolset>v140</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />