From 579cad0655c4ba47ab6d10040f741997ed66dd2d Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Fri, 8 May 2015 13:09:34 -0700 Subject: [PATCH] Added support for VIEW command to the C client. --- C/src/xplaneConnect.c | 31 +++++++++-- C/src/xplaneConnect.h | 24 +++++++++ TestScripts/C Tests.win/CTests.vcxproj | 1 + TestScripts/C Tests/ViewTests.h | 73 ++++++++++++++++++++++++++ TestScripts/C Tests/main.c | 5 ++ 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 TestScripts/C Tests/ViewTests.h diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 74b098d..f6f0a5d 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -48,9 +48,6 @@ #include #include - - - void printError(char *functionName, char *format, ...) { va_list args; @@ -694,3 +691,31 @@ int sendWYPT(XPCSocket sock, WYPT_OP op, float points[], int count) /*****************************************************************************/ /**** End Drawing functions ****/ /*****************************************************************************/ + +/*****************************************************************************/ +/**** View functions ****/ +/*****************************************************************************/ +int sendVIEW(XPCSocket sock, VIEW_TYPE view) +{ + // Validate Input + if (view < XPC_VIEW_FORWARDS || view > XPC_VIEW_FULLSCREENNOHUD) + { + printError("sendVIEW", "Unrecognized view"); + return -1; + } + + // Setup Command + char buffer[9] = "VIEW"; + *((int*)(buffer + 5)) = view; + + // Send Command + if (sendUDP(sock, buffer, 9) < 0) + { + printError("sendVIEW", "Failed to send command"); + return -2; + } + return 0; +} +/*****************************************************************************/ +/**** End View functions ****/ +/*****************************************************************************/ \ No newline at end of file diff --git a/C/src/xplaneConnect.h b/C/src/xplaneConnect.h index 391ec54..3827a68 100644 --- a/C/src/xplaneConnect.h +++ b/C/src/xplaneConnect.h @@ -61,6 +61,23 @@ typedef enum XPC_WYPT_DEL = 2, XPC_WYPT_CLR = 3 } WYPT_OP; + +typedef enum +{ + XPC_VIEW_FORWARDS = 73, + XPC_VIEW_DOWN, + XPC_VIEW_LEFT, + XPC_VIEW_RIGHT, + XPC_VIEW_BACK, + XPC_VIEW_TOWER, + XPC_VIEW_RUNWAY, + XPC_VIEW_CHASE, + XPC_VIEW_FOLLOW, + XPC_VIEW_FOLLOWWITHPANEL, + XPC_VIEW_SPOT, + XPC_VIEW_FULLSCREENWITHHUD, + XPC_VIEW_FULLSCREENNOHUD, +} VIEW_TYPE; // Low Level UDP Functions @@ -214,6 +231,13 @@ int sendCTRL(XPCSocket sock, float values[], int size, char ac); /// \returns 0 if successful, otherwise a negative value. int sendTEXT(XPCSocket sock, char* msg, int x, int y); +/// Sets the camera view in X-Plane. +/// +/// \param sock The socket to use to send the command. +/// \param view The view to use. +/// \returns 0 if successful, otherwise a negative value. +int sendVIEW(XPCSocket sock, VIEW_TYPE view); + /// Adds, removes, or clears a set of waypoints. If the command is clear, the points are ignored /// and all points are removed. /// diff --git a/TestScripts/C Tests.win/CTests.vcxproj b/TestScripts/C Tests.win/CTests.vcxproj index b546a64..6c55744 100644 --- a/TestScripts/C Tests.win/CTests.vcxproj +++ b/TestScripts/C Tests.win/CTests.vcxproj @@ -33,6 +33,7 @@ + diff --git a/TestScripts/C Tests/ViewTests.h b/TestScripts/C Tests/ViewTests.h new file mode 100644 index 0000000..a25c14f --- /dev/null +++ b/TestScripts/C Tests/ViewTests.h @@ -0,0 +1,73 @@ +//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the +//National Aeronautics and Space Administration. All Rights Reserved. +#ifndef VIEWTESTS_H +#define VIEWTESTS_H + +#include "Test.h" +#include "xplaneConnect.h" + +typedef enum +{ + XPC_VDREF_FORWARDS = 1000, + XPC_VDREF_DOWN4 = 1001, + XPC_VDREF_DOWN8 = 1002, + XPC_VDREF_LEFT45 = 1004, + XPC_VDREF_RIGHT45 = 1005, + XPC_VDREF_LEFT90 = 1006, + XPC_VDREF_RIGHT90 = 1007, + XPC_VDREF_LEFT135 = 1008, + XPC_VDREF_RIGHT135 = 1009, + XPC_VDREF_BACKWARD = 1010, + XPC_VDREF_LEFTUP = 1011, + XPC_VDREF_RIGHTUP = 1012, + XPC_VDREF_AIRPORTBEACONTOWER = 1014, + XPC_VDREF_ONRUNWAY = 1015, + XPC_VDREF_CHASE = 1017, + XPC_VDREF_FOLLOW = 1018, + XPC_VDREF_FOLLOWWITHPANEL = 1019, + XPC_VDREF_SPOT = 1020, + XPC_VDREF_SPOTMOVING = 1021, + XPC_VDREF_FULLSCREENWITHHUD = 1023, + XPC_VDREF_FULLSCREENNOHUD = 1024, + XPC_VDREF_STRAIGHTDOWN = 1025, + XPC_VDREF_3DCOCKPIT = 1026 +} VIEW_DREF; + +int doViewTest(VIEW_TYPE viewCommand, VIEW_DREF viewResult) +{ + // Setup + char* dref = "sim/graphics/view/view_type"; + float value; + int size = 1; + + // Execute command + XPCSocket sock = openUDP(IP); + int result = sendVIEW(sock, viewCommand); + if (result >= 0) + { + result = getDREF(sock, dref, &value, &size); + } + closeUDP(sock); + if (result < 0) + { + return -1; + } + + if ((int)value != viewResult) + { + return -2; + } + return 0; +} + +int testView() +{ + int result = doViewTest(XPC_VIEW_FORWARDS, XPC_VDREF_FORWARDS); + if (result < 0) + { + return -1; + } + + return doViewTest(XPC_VIEW_CHASE, XPC_VDREF_CHASE); +} +#endif \ No newline at end of file diff --git a/TestScripts/C Tests/main.c b/TestScripts/C Tests/main.c index ae01451..0f5cdd9 100644 --- a/TestScripts/C Tests/main.c +++ b/TestScripts/C Tests/main.c @@ -8,6 +8,7 @@ #include "PosiTests.h" #include "DataTests.h" #include "TextTests.h" +#include "ViewTests.h" #include "WyptTests.h" int main(int argc, const char * argv[]) @@ -48,10 +49,14 @@ int main(int argc, const char * argv[]) runTest(testTEXT, "TEXT"); // Waypoints runTest(testWYPT, "WYPT"); + // View + runTest(testView, "VIEW"); // setConn runTest(testCONN, "CONN"); printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed ); + printf("Press any key to exit."); + getchar(); return 0; }