diff --git a/C/User Guide (C).txt b/C/User Guide (C).txt
deleted file mode 100644
index 7fcc94e..0000000
--- a/C/User Guide (C).txt
+++ /dev/null
@@ -1,192 +0,0 @@
-X-Plane Connect-C (XPC-C) Readme
-
-DESCRIPTION
- XPC-C is a series of C functions that facilitate communication with X-Plane.
-
------------------------------------
-SETUP
- Before using XPC Functions you must
- 1. Copy the folder "[XPC Directory]/xpcPlugin/XPlaneConnect" to the "[X-Plane Directory]/Resources/plugins" directory.
- 2. Put in X-Plane CD 1 or X-Plane USB Key.
- 3. Start X-Plane.
- 4. #include "xplaneConnect.h"
-
------------------------------------
-BASIC FUNCTIONS
- 1. openUDP opens a UDP Socket for communication. This is used to send data or receive.
- INPUT:
- port (unsigned short): Port Number (ex:49067)
- xpIP (char *): IP Address of the computer running x-plane
- xpPort (unsigned short): Port number that the X-Plane/ xpcPlugin Receives on (send -1 for default (49009), Typically xpcPlugin is 49009)
-
- OUTPUT:
- socket (xpcSocket): The Opened Socket
-
- USE:
- unsigned short portNumber = 49067;
- struct xpcSocket theSocket = openUDP(portNumber, “127.0.0.1”, 49009);
-
- 2. closeUDP closes an opened UDP Socket for communication. This is to be done after the program has finished using that socket. Use opedUDP to open socket.
- INPUT:
- socket (xpcSocket): The Opened Socket
-
- USE:
- closeUDP(theSocket);
-
- 3. setCONN sets the return port for requested datarefs.
- INPUT:
- socket (xpcSocket): Socket to use to send the command
- recPort (unsigned Short): Port number for requested dataref values to be sent to
-
- OUTPUT:
- status (short): 0 if successful
-
- USE:
- char IP[16] = "127.0.0.1";
- struct xpcSocket theSocket = openUDP(49067);
- setCONN(theSocket,IP,49009,49022); // Sets receive address to 49022;
-
- 4. pauseSim pauses/resumes the x-plane simulation
- INPUT:
- socket (xpcSocket): Socket to use to send the command
- pause (short): 1=Pause, 0=Resume
-
- OUTPUT:
- status (short): 0 if successful
-
- USE:
- char IP[16] = "127.0.0.1";
- struct xpcSocket theSocket = openUDP(49067);
- pauseSim(theSocket, IP, 49009, 1);
-
- 5. sendDATA set the value of a state in the "DATA Input & Output" Table
- INPUT:
- socket (xpcSocket): Socket to use to send the command
- dataArray (float[][9]): Array of data to be sent. The first element of each row is the item # (corresponding to the number on the X-Plane "DATA Input & Output" Screen). Send -999 to leave the value unchanged.
- rows (unsigned short): Number of rows of data being sent
-
- OUTPUT:
- status (short): 0 if successful
-
- USE:
- char IP[16] = "127.0.0.1";
- struct xpcSocket theSocket = openUDP(49067);
- float data[] = {{14, 1, -999, -999, -999, -999, -999, -999, -999},{25, 0.8, 0.8, -999, -999, -999, -999, -999, -999}}; // Gear and Throttle
- sendDATA(theSocket,IP,49009,data,2);
-
- 6. sendPOSI set the position of an aircraft
- INPUT:
- socket (xpcSocket): Socket to use to send the command
- ACNum (short): Number of aircraft to be moved, use 0 for main aircraft (ownPlane).
- numArgs (short): Number of Arguments to be sent (size of position array)
- position (float []): Arguments corresponding to aircrafts position
- position[0] = Latitude
- position[1] = Longitude
- position[2] = Altitude (m MSL)
- position[3] = Roll (deg)
- position[4] = Pitch (deg)
- position[5] = True Heading (deg)
- position[6] = Gear (0=up, 1=down)
-
- OUTPUT:
- status (short): 0 if successful
-
- USE:
- char IP[16] = "127.0.0.1";
- struct xpcSocket theSocket = openUDP(49067);
- float posit[] = {37.5242422, -122.06899, 2500, 0, 0, 0, 1};
- sendPOSI(theSocket, IP, 49009, 7, posit);
-
- 7. sendCTRL send control commands to the aircraft
- INPUT:
- socket (xpcSocket): Socket to use to send the command
- numArgs (short): Number of Arguments to be sent (size of control array)
- control (float []): Arguments corresponding to aircraft control command
- control[0] = Latitudinal Stick [-1,1]
- control[1] = Longitudinal Stick [-1,1]
- control[2] = Pedal [-1, 1]
- control[3] = Throttle [-1, 1]
- control[4] = Gear (0=up, 1=down)
- control[5] = Flaps [0, 1]
-
- OUTPUT:
- status (short): 0 if successful
-
- USE:
- char IP[16] = "127.0.0.1";
- struct xpcSocket theSocket = openUDP(49067);
- float ctrl[] = {0, 0, 0, 0.8, 0, 1};
- sendCTRL(theSocket, IP, 49009, 6, ctrl);
-
- 8. sendDREF set the value of a specific dataref. Dataref list found at http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html
- INPUT:
- socket (xpcSocket): Socket to use to send the command
- dataRef (char *): Dataref to be set (with or without "sim/" preceeding it)
- length (short): length of dataref string
- values (float *): Array of values to be sent
- length2 (short): Number of values in values array
-
- OUTPUT:
- status (short): 0 if successful
-
- USE:
- char IP[16] = "127.0.0.1";
- struct xpcSocket theSocket = openUDP(49067);
- char theDREF[] = "cockpit/switches/gear_handle_status";
- float value = 1;
- sendDREF(theSocket, IP, 49009, theDREF, strlen(theDREF), &value, 1);
-
- 9. requestDREF Request the value of specific dref(s). Dataref list found at http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html
- INPUT:
- outSocket (xpcSocket): Socket to use to send the command
- inSocket (xpcSocket): Socket to use to receive the result
- DREFArray (char[][100]): Array of DataRefs to be requested
- DREFSizes (int[]): Array of string lengths for each DataRef in DREFArray
- listLength (short): Number of DataRefs in DREFArray
- result (*float[]): Array of pointers to the values returned
- arrayLen (short[]): Array where each element corresponds to the number of elements in the float array.
-
- OUTPUT:
- length (short): Number of Values Returned
-
- USE:
- char IP[16] = "127.0.0.1";
- struct xpcSocket theSocket = openUDP(49067);
- char DREFArray[][100] = {"sim/cockpit/switches/gear_handle_status"};
- requestDREF(theSocket, IP, 49009, DREFArray, strlen(DREFArray[0]),1);
-
- 10. sendTEXT write some text to the screen.
- INPUT:
- outSocket (xpcSocket): Socket to use to send the command
- message (char*): The string to be wrote to the screen
- x (int): The x position where the text will be written. Set to -1 to use default position.
- y (int): The y position where the text will be written. Set to -1 to use default position.
-
------------------------------------
-ADVANCED FUNCTIONS (These are mostly used by the xpcPlugin to read requests)
- 1. sendUDP
- 2. readUDP
- 3. readDATA
- 4. parseDATA
- 5. readPOSI
- 6. parsePOSI
- 7. readCTRL
- 8. parseCTRL
- 9. readRequest
- 10. parseRequest
- 11. parseDREF
- 12. readDREF
-
------------------------------------
-PLANNED FUNCTIONS
- 1. sendVIEW
- 2. parseVIEW
- 3. readVIEW
- 4. sendWYPT
- 5. parseWYPT
- 6. readWYPT
- 7. selectDATA
-
------------------------------------
-CONTACT
- Email Christopher Teubert (christopher.a.teubert@nasa.gov) with any questions.
diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c
index 7dae28b..ce65c76 100755
--- a/C/src/xplaneConnect.c
+++ b/C/src/xplaneConnect.c
@@ -1,734 +1,675 @@
+//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
+//National Aeronautics and Space Administration. All Rights Reserved.
//
-// xPlaneConnect.c Beta
+//DISCLAIMERS
+// No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND,
+// EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY
+// THAT THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED,
+// WILL CONFORM TO THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN
+// ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS, RESULTING DESIGNS,
+// HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING FROM USE OF THE SUBJECT
+// SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING
+// THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT "AS IS."
+//
+// Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST THE UNITED STATES
+// GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT. IF
+// RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES
+// OR LOSSES ARISING FROM SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING
+// FROM, RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS THE
+// UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT,
+// TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE
+// IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.
+
+// X-Plane Connect Client
//
// DESCRIPTION
-// XPLANECONNECT (XPC) Facilitates Communication to and from the XPCPlugin
-//
-// REQUIREMENTS
-// 1. X-Plane Version 9.0 or newer (untested on previous versions)
-// 2. XPCPlugin.xpl-must be placed in [X-Plane Directory]/Resources/plugins
-// 3. OS X 10.8 or newer (untested on previous versions)
+// Communicates with the XPC plugin to facilitate controling and gathering data from X-Plane.
//
// INSTRUCTIONS
-// 1. Include the header "xplaneConnect.h"
-// EXAMPLE: #include "xplaneConnect.h"
-// 2. Open UDP Socket using openUDP
-// EXAMPLE: struct xpcSocket theSocket = openUDP(port_number);
-// NOTE: Do not send/receive on the same socket
-// 3. Use functions described below
-// 4. Close UDP Socket using closeUDP
-//
-// NOTICES:
-// Copyright ã 2013-2014 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. All Rights Reserved.
-//
-// DISCLAIMERS
-// No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS, RESULTING DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING FROM USE OF THE SUBJECT SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT "AS IS."
-//
-// Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT. IF RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR LOSSES ARISING FROM SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING FROM, RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.
-//
-// X-Plane API
-// Copyright (c) 2008, Sandy Barbour and Ben Supnik All rights reserved.
-// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-// * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-// * Neither the names of the authors nor that of X-Plane or Laminar Research may be used to endorse or promote products derived from this software without specific prior written permission from the authors or Laminar Research, respectively.
-//
-// X-Plane API 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.
+// See Readme.md in the root of this repository or the wiki hosted on GitHub at
+// https://github.com/nasa/XPlaneConnect/wiki for requirements, installation instructions,
+// and detailed documentation.
//
// CONTACT
// For questions email Christopher Teubert (christopher.a.teubert@nasa.gov)
//
-// TO DO
-// 1. Update SelectData
-// 2. RequestDREF: look into removing DREFSizes
-//
-// BEGIN CODE
+// CONTRIBUTORS
+// CT: Christopher Teubert (christopher.a.teubert@nasa.gov)
+// JW: Jason Watkins (jason.w.watkins@nasa.gov)
+#include "xplaneConnect.h"
+#include
+#include
#include
#include
-#include
#include
#include
#include
-#include
-#include "xplaneConnect.h"
-#ifdef _WIN32 /* WIN32 SYSTEM */
- #include
- #define strcasecmp _stricmp
- #define strncasecmp _strnicmp
- #define snprintf sprintf_s
- #define socklen_t int
+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 usleep(__int64 usec)
- { // From http://www.c-plusplus.de/forum/109539-full
- HANDLE timer;
- LARGE_INTEGER ft;
-
- ft.QuadPart = -(10*usec); // Convert to 100 nanosecond interval, negative value indicates relative time
-
- timer = CreateWaitableTimer(NULL, TRUE, NULL);
- SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
- WaitForSingleObject(timer, INFINITE);
- CloseHandle(timer);
- }
-#endif
-
-short errorReport(char *functionName, char *errorMessage);
-short sendRequest(struct xpcSocket recfd, char DREFArray[][100], short DREFSizes[], short listLength);
-
-short errorReport(char *functionName, char *errorMessage)
+void printError(char *functionName, char *format, ...)
{
- printf("ERROR: %s-%s\n", functionName, errorMessage);
- return -1;
+ va_list args;
+ va_start(args, format);
+
+ printf("[%s] ERROR: ", functionName);
+ vprintf(format, args);
+ printf("\n");
+
+ va_end(args);
}
-struct xpcSocket openUDP(unsigned short port_number, const char *xpIP, unsigned short xpPort)
+/*****************************************************************************/
+/**** Low Level UDP functions ****/
+/*****************************************************************************/
+XPCSocket openUDP(const char *xpIP)
{
- struct xpcSocket theSocket;
- struct sockaddr_in server;
-
-#if (__APPLE__ || __linux)
- struct timeval tv;
- int optval = 1;
-#endif
-
- // Setup Port
- server.sin_family = AF_INET;
- server.sin_addr.s_addr = INADDR_ANY;
- server.sin_port = htons(port_number);
-
- // Set X-Plane Port and IP
- if (strcasecmp(xpIP,"localhost") == 0) // IP
- {
- strncpy(theSocket.xpIP,"127.0.0.1",9); // Default
- }
- else
- {
- memcpy(theSocket.xpIP,xpIP,(size_t) fminl(strlen(xpIP),16));
- }
-
- if (xpPort <= 0) // Default Port
- {
- theSocket.xpPort = 49009; // Default
- }
- else
- {
- theSocket.xpPort = xpPort;
- }
-
-#ifdef _WIN32
- WSADATA wsa;
- if (WSAStartup(MAKEWORD(2,2),&wsa) != 0)
- {
- perror("ERROR: openUDP- ");
- return theSocket;
- //ERROR IN Socket Message
- }
-
- if ((theSocket.sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET)
- {
- perror("ERROR: openUDP- ");
- return theSocket;
- //ERROR IN Socket Message
- }
-
- if (bind(theSocket.sock, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR)
- {
- perror("ERROR: openUDP- ");
- return theSocket;
- //ERROR IN Socket Message
- }
-#elif (__APPLE__ || __linux)
- // Create a SOCKET
- if ((theSocket.sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
- {
- perror((char*) "ERROR: openUDP- ");
- return theSocket;
- }
-
- // Options
- setsockopt(theSocket.sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
- setsockopt(theSocket.sock, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
-
- //Bind
- if ( bind(theSocket.sock, (struct sockaddr *) &server, sizeof(server)) == -1)
- {
- perror( (char*) "ERROR: openUDP- ");
- return theSocket;
- }
-#endif
-
- //Set Timout
- int usTimeOut = 500;
-
-#ifdef _WIN32
- DWORD msTimeOutWin = 1; // Minimum socket timeout in Windows is 1ms
- setsockopt(theSocket.sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&msTimeOutWin, sizeof(msTimeOutWin));
-#else
- tv.tv_sec = 0; /* Sec Timeout */
- tv.tv_usec = usTimeOut; // Microsec Timeout
- setsockopt(theSocket.sock, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof(struct timeval));
-#endif
-
- return theSocket;
+ return aopenUDP(xpIP, 49009, 0);
}
-void closeUDP(struct xpcSocket socketNumber)
+XPCSocket aopenUDP(const char *xpIP, unsigned short xpPort, unsigned short port)
{
-#ifdef _WIN32
- closesocket(socketNumber.sock);
-#elif (__APPLE__ || __linux)
- close(socketNumber.sock);
-#endif
-}
-
-short sendUDP(struct xpcSocket recfd, char my_message[], short messageLength)
-{
- struct sockaddr_in servaddr;
-
- my_message[4] = (char) messageLength;
-
- // Preconditions
- if (messageLength <= 0)// Positive Message Length
+ XPCSocket sock;
+
+ // Setup Port
+ struct sockaddr_in recvaddr;
+ recvaddr.sin_family = AF_INET;
+ recvaddr.sin_addr.s_addr = INADDR_ANY;
+ recvaddr.sin_port = htons(port);
+
+ // Set X-Plane Port and IP
+ if (strcmp(xpIP, "localhost") == 0)
{
- return errorReport("sendUDP", "message length must be positive >0");
+ xpIP = "127.0.0.1";
}
-
- // Code
- servaddr.sin_family = AF_INET;
- servaddr.sin_port = htons(recfd.xpPort);
- servaddr.sin_addr.s_addr = inet_addr(recfd.xpIP);
-
+ strncpy(sock.xpIP, xpIP, 16);
+ sock.xpPort = xpPort == 0 ? 49009 : xpPort;
+
#ifdef _WIN32
- const char on = 1;
-#else
- int on=1;
-#endif
-
- setsockopt(recfd.sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));
-
- if (sendto(recfd.sock, my_message, (int) messageLength, 0, (const struct sockaddr *) &servaddr, sizeof(servaddr))<0)
- {
- perror("ERROR: sendUDP-");
- exit(EXIT_FAILURE);
- }
-
- return 0;
-}
-
-short sendDATA(struct xpcSocket recfd, float dataRef[][9], unsigned short rows)
-{
- int i;
- unsigned short length = rows*9*sizeof(float) + 5;
- char message[5000];
- unsigned short step = 9*sizeof(float);
-
- strncpy(message,"DATA",4);
-
- for (i=0;i xpc_WYPT_CLR)
+#endif
+
+ if ((sock.sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
{
+ printError("OpenUDP", "Socket creation failed");
+ exit(EXIT_FAILURE);
+ }
+ if (bind(sock.sock, (struct sockaddr*)&recvaddr, sizeof(recvaddr)) == -1)
+ {
+ printError("OpenUDP", "Socket bind failed");
+ exit(EXIT_FAILURE);
+ }
+
+ // Set timeout to 100ms
+#ifdef _WIN32
+ DWORD timeout = 100;
+#else
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000;
+#endif
+ if (setsockopt(sock.sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0)
+ {
+ printError("OpenUDP", "Failed to set timeout");
+ }
+ return sock;
+}
+
+void closeUDP(XPCSocket sock)
+{
+#ifdef _WIN32
+ int result = closesocket(sock.sock);
+#else
+ int result = close(sock.sock);
+#endif
+ if (result < 0)
+ {
+ printError("closeUDP", "Failed to close socket");
+ exit(EXIT_FAILURE);
+ }
+}
+
+/// Sends the given data to the X-Plane plugin.
+///
+/// \param sock The socket to use to send the data.
+/// \param buffer A pointer to the data to send.
+/// \param len The number of bytes to send.
+/// \returns If an error occurs, a negative number. Otehrwise, the number of bytes sent.
+int sendUDP(XPCSocket sock, char buffer[], int len)
+{
+ // Preconditions
+ if (len <= 0)
+ {
+ printError("sendUDP", "Message length must be positive.");
return -1;
}
- //Validate number of points
- else if (numPoints > 19)
+
+ // Set up destination address
+ struct sockaddr_in dst;
+ dst.sin_family = AF_INET;
+ dst.sin_port = htons(sock.xpPort);
+ inet_pton(AF_INET, sock.xpIP, &dst.sin_addr.s_addr);
+
+ int result = sendto(sock.sock, buffer, len, 0, (const struct sockaddr*)&dst, sizeof(dst));
+ if (result < 0)
{
+ printError("sendUDP", "Send operation failed.");
return -2;
}
- //Everything checks out; send the message
- else
+ if (result < len)
{
- buf[5] = op;
- buf[6] = numPoints;
- size_t len = sizeof(float) * 3 * numPoints;
- memcpy(buf + 7, points, len);
- sendUDP(sendfd, buf, len + 7);
- return 0;
- }
-}
-
-//READ
-//----------------------------------------
-short readUDP(struct xpcSocket recfd, char *dataRef, struct sockaddr *recvaddr)
-{
- socklen_t recvaddrlen = sizeof(*recvaddr);
- int status = 0;
-
-#ifdef _WIN32
- // Windows readUDP needs the select command- minimum timeout is 1ms.
- // Without this playback becomes choppy
-
- // Definitions
- FD_SET stReadFDS;
- FD_SET stExceptFDS;
- struct timeval tv;
- struct sockaddr_in testaddr;
- int error = 0;
-
- // Setup for Select
- FD_ZERO(&stReadFDS);
- FD_SET(recfd.sock, &stReadFDS);
- FD_ZERO(&stExceptFDS);
- FD_SET(recfd.sock, &stExceptFDS);
- tv.tv_sec = 0; /* Sec Timeout */
- tv.tv_usec = 250; // Microsec Timeout
-
- // Select Command
- int tmp = select(-1, &stReadFDS, (FD_SET *)0, &stExceptFDS, &tv);
- if (tmp <= 0) // No Data or error
- {
- return -1;
- }
-
- // If no error: Read Data
- recvaddrlen = sizeof(testaddr);
- status = (int) recvfrom(recfd.sock,dataRef,5000,0,(SOCKADDR *) &testaddr,&recvaddrlen);
- if (status == SOCKET_ERROR)
- {
- error = WSAGetLastError();
- }
-#else
- // For apple or linux-just read - will timeout in 0.5 ms
- status = (int) recvfrom(recfd.sock,dataRef,5000,0,recvaddr,&recvaddrlen);
-#endif
-
- return status;
-}
-
-short readDATA(struct xpcSocket recfd, float dataRef[][9])
-{
- char buf[5000];
- int buflen = readUDP(recfd,buf, NULL);
-
- if (buf[0]!= '\0')
- {
- return parseDATA(buf, buflen, dataRef);
- }
- return -1;
-}
-
-short readRequest(struct xpcSocket recfd, float *dataRef[], short arraySizes[], struct sockaddr *recvaddr)
-{
- char buf[5000];
- readUDP(recfd,buf, recvaddr);
- if (buf[0]!= '\0')
- {
- return parseRequest(buf, dataRef, arraySizes);
- }
- return -1;
-}
-
-short readDREF(struct xpcSocket recfd, float *resultArray[], short arraySizes[])
-{
- char buf[5000] = {0};
- readUDP(recfd,buf, NULL);
-
- if (buf[0]!= '\0')
- {
- return parseRequest(buf, resultArray, arraySizes);
- }
- return -1;
-}
-
-short readPOSI(struct xpcSocket recfd, float resultArray[], int arraySize, float *gear)
-{
- char buf[5000] = {0};
- readUDP(recfd,buf, NULL);
-
- if (buf[0]!= '\0') // Buffer is not empty
- {
- return parsePOSI(buf, resultArray, arraySize, gear);
- }
- return -1;
-}
-
-xpcCtrl readCTRL(struct xpcSocket recfd)
-{
- xpcCtrl result;
- char buf[5000] = { 0 };
- readUDP(recfd, buf, NULL);
-
- if (buf[0] != '\0') // Buffer is not empty
- {
- result = parseCTRL(buf);
- }
- else
- {
- result.aircraft = -1;
- }
- return result;
-}
-
-//PARSE
-//---------------------
-short parseDATA(const char my_message[], short messageLength, float dataRef[][9])
-{
- int i, j;
- unsigned short totalColumns = ((messageLength-5)/36);
- float tmp;
- float data[20][9];
-
- // Input Validation
-
- for (i=0;i xpc_WYPT_CLR)
- {
- result.op = -1;
- }
- //Validate number of points
- else if (data[6] > 19)
- {
- result.op = -2;
- }
- //Everything checks out; copy the points into result
- else
- {
- result.op = data[5];
- result.numPoints = data[6];
- char* ptr = data + 7;
- for (size_t i = 0; i < result.numPoints; ++i)
- {
- result.points[i].latitude = *((float*)ptr);
- result.points[i].longitude = *((float*)(ptr + 4));
- result.points[i].altitude = *((float*)(ptr + 8));
- ptr += 12;
- }
+ printError("sendUDP", "Unexpected number of bytes sent.");
}
return result;
}
+
+/// Reads a datagram from the specified socket.
+///
+/// \param sock The socket to read from.
+/// \param buffer A pointer to the location to store the data.
+/// \param len The number of bytes to read.
+/// \returns If an error occurs, a negative number. Otehrwise, the number of bytes read.
+int readUDP(XPCSocket sock, char buffer[], int len)
+{
+#ifdef _WIN32
+ // Windows readUDP needs the select command- minimum timeout is 1ms.
+ // Without this playback becomes choppy
+
+ // Definitions
+ FD_SET stReadFDS;
+ FD_SET stExceptFDS;
+
+ // Setup for Select
+ FD_ZERO(&stReadFDS);
+ FD_SET(sock.sock, &stReadFDS);
+ FD_ZERO(&stExceptFDS);
+ FD_SET(sock.sock, &stExceptFDS);
+
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 100000;
+
+ // Select Command
+ int status = select(-1, &stReadFDS, (FD_SET*)0, &stExceptFDS, &tv);
+ if (status < 0)
+ {
+ printError("readUDP", "Select command error");
+ return -1;
+ }
+ if (status == 0)
+ {
+ // No data
+ return 0;
+ }
+ status = recv(sock.sock, buffer, len, 0);
+#else
+ // For apple or linux-just read - will timeout in 0.5 ms
+ int status = (int)recv(sock.sock, buffer, len, 0);
+#endif
+ if (status < 0)
+ {
+ printError("readUDP", "Error reading socket");
+ }
+ return status;
+}
+/*****************************************************************************/
+/**** End Low Level UDP functions ****/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/**** Configuration functions ****/
+/*****************************************************************************/
+int setCONN(XPCSocket* sock, unsigned short port)
+{
+ // Set up command
+ char buffer[32] = "CONN";
+ memcpy(&buffer[5], &port, 2);
+
+ // Send command
+ if (sendUDP(*sock, buffer, 7) < 0)
+ {
+ printError("setCONN", "Failed to send command");
+ return -1;
+ }
+
+ // Switch socket
+ closeUDP(*sock);
+ *sock = aopenUDP(sock->xpIP, sock->xpPort, port);
+
+ // Read response
+ int result = readUDP(*sock, buffer, 32);
+
+ if (result <= 0)
+ {
+ printError("setCONN", "Failed to read response");
+ return -2;
+ }
+ if (strncmp(buffer, "CONF", 4) == 0)
+ {
+ // Response received succesfully.
+ return 0;
+ }
+ // Response incorrect
+ return -3;
+}
+
+int pauseSim(XPCSocket sock, char pause)
+{
+ // Setup command
+ char buffer[6] = "SIMU";
+ buffer[5] = pause == 0 ? 0 : 1;
+ // Send command
+ if (sendUDP(sock, buffer, 6) < 0)
+ {
+ printError("pauseSim", "Failed to send command");
+ return -1;
+ }
+ return 0;
+}
+/*****************************************************************************/
+/**** End Configuration functions ****/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/**** X-Plane UDP Data functions ****/
+/*****************************************************************************/
+int sendDATA(XPCSocket sock, float data[][9], int rows)
+{
+ // Preconditions
+ // There are only 134 DATA rows in X-Plane. Realistically, clients probably
+ // shouldn't be trying to set nearly this much data at once anyway.
+ if (rows > 134)
+ {
+ printError("sendDATA", "Too many rows.");
+ return -1;
+ }
+
+ // Setup command
+ // 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.");
+ // Read as much as we can anyway
+ rows = 134;
+ }
+
+ // Read data
+ char buffer[4829] = { 0 };
+ int result = readUDP(sock, buffer, 5120);
+ if (result <= 0)
+ {
+ printError("readDATA", "Failed to read from socket.");
+ return -1;
+ }
+ // Validate data
+ int readRows = (result - 5) / 36;
+ if (readRows > rows)
+ {
+ printError("readDATA", "Read more rows than will fit in dataRef.");
+ // Copy as much data as we can anyway
+ rows = readRows;
+ }
+
+ // Parse data
+ for (int i = 0; i < rows; ++i)
+ {
+ data[i][0] = buffer[5 + i * 36];
+ memcpy(&data[i][1], &buffer[9 + i * 36], 8 * sizeof(float));
+ }
+ return rows;
+}
+/*****************************************************************************/
+/**** End X-Plane UDP Data functions ****/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/**** DREF functions ****/
+/*****************************************************************************/
+int sendDREF(XPCSocket sock, const char* dref, float value[], int size)
+{
+ // Setup command
+ // 5 byte header + max 255 char dref name + max 255 values * 4 bytes per value = 1279
+ unsigned char buffer[1279] = "DREF";
+ int drefLen = strnlen(dref, 256);
+ if (drefLen > 255)
+ {
+ printError("setDREF", "dref length is too long. Must be less than 256 characters.");
+ return -1;
+ }
+ if (size > 255)
+ {
+ printError("setDREF", "size is too big. Must be less than 256.");
+ return -2;
+ }
+ int len = 7 + drefLen + size * sizeof(float);
+
+ // Copy dref to buffer
+ buffer[5] = (unsigned char)drefLen;
+ memcpy(buffer + 6, dref, drefLen);
+
+ // Copy values to buffer
+ buffer[6 + drefLen] = (unsigned char)size;
+ memcpy(buffer + 7 + drefLen, value, size * sizeof(float));
+
+ // Send command
+ if (sendUDP(sock, buffer, len) < 0)
+ {
+ printError("setDREF", "Failed to send command");
+ return -3;
+ }
+ return 0;
+}
+
+int sendDREFRequest(XPCSocket sock, const char* drefs[], unsigned char count)
+{
+ // Setup command
+ // 6 byte header + potentially 255 drefs, each 256 chars long.
+ // Easiest to just round to an even 2^16.
+ unsigned char buffer[65536] = "GETD";
+ buffer[5] = count;
+ int len = 6;
+ for (int i = 0; i < count; ++i)
+ {
+ size_t drefLen = strnlen(drefs[i], 256);
+ if (drefLen > 255)
+ {
+ printError("getDREFs", "dref %d is too long.", i);
+ return -1;
+ }
+ buffer[len++] = (unsigned char)drefLen;
+ strncpy(buffer + len, drefs[i], drefLen);
+ len += drefLen;
+ }
+ // Send Command
+ if (sendUDP(sock, buffer, len) < 0)
+ {
+ printError("getDREFs", "Failed to send command");
+ return -2;
+ }
+ return 0;
+}
+
+int getDREFResponse(XPCSocket sock, float* values[], unsigned char count, int sizes[])
+{
+ unsigned char buffer[65536];
+ int result = readUDP(sock, buffer, 65536);
+
+ if (result < 0)
+ {
+#ifdef _WIN32
+ printError("getDREFs", "Read operation failed. (%d)", WSAGetLastError());
+#else
+ printError("getDREFs", "Read operation failed.");
+#endif
+ return -1;
+ }
+
+ if (result < 6)
+ {
+ printError("getDREFs", "Response was too short. Expected at least 6 bytes, but only got %d.", result);
+ return -2;
+ }
+ if (buffer[5] != count)
+ {
+ printError("getDREFs", "Unexpected response size. Expected %d rows, got %d instead.", count, buffer[5]);
+ return -3;
+ }
+
+ int cur = 6;
+ for (int i = 0; i < count; ++i)
+ {
+ int l = buffer[cur++];
+ if (l > sizes[i])
+ {
+ printError("getDREFs", "values is too small. Row had %d values, only room for %d.", l, sizes[i]);
+ // Copy as many values as we can anyway
+ memcpy(values[i], buffer + cur, sizes[i] * sizeof(float));
+ }
+ else
+ {
+ memcpy(values[i], buffer + cur, l * sizeof(float));
+ sizes[i] = l;
+ }
+ cur += l * sizeof(float);
+ }
+ return 0;
+}
+
+int getDREF(XPCSocket sock, const char* dref, float values[], int* size)
+{
+ return getDREFs(sock, &dref, &values, 1, size);
+}
+
+int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char count, int sizes[])
+{
+ // Send Command
+ int result = sendDREFRequest(sock, drefs, count);
+ if (result < 0)
+ {
+ // A error ocurred while sending.
+ // sendDREFRequest will print an error message, so just return.
+ return -1;
+ }
+
+ // Read Response
+ if (getDREFResponse(sock, values, count, sizes) < 0)
+ {
+ // A error ocurred while reading the response.
+ // getDREFResponse will print an error message, so just return.
+ return -2;
+ }
+ return 0;
+}
+/*****************************************************************************/
+/**** End DREF functions ****/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/**** POSI functions ****/
+/*****************************************************************************/
+int sendPOSI(XPCSocket sock, float values[], int size, char ac)
+{
+ // Validate input
+ if (ac < 0 || ac > 20)
+ {
+ printError("sendPOSI", "aircraft should be a value between 0 and 20.");
+ return -1;
+ }
+ if (size < 1 || size > 7)
+ {
+ printError("sendPOSI", "size should be a value between 1 and 7.");
+ return -2;
+ }
+
+ // Setup command
+ // 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++)
+ {
+ float val = -998;
+
+ if (i < size)
+ {
+ val = values[i];
+ }
+ *((float*)(buffer + 6 + i * 4)) = val;
+ }
+
+ // Send Command
+ if (sendUDP(sock, buffer, 40) < 0)
+ {
+ printError("sendPOSI", "Failed to send command");
+ return -3;
+ }
+ return 0;
+}
+/*****************************************************************************/
+/**** End POSI functions ****/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/**** CTRL functions ****/
+/*****************************************************************************/
+int sendCTRL(XPCSocket sock, float values[], int size, char ac)
+{
+ // Validate input
+ if (ac < 0 || ac > 20)
+ {
+ printError("sendCTRL", "aircraft should be a value between 0 and 20.");
+ return -1;
+ }
+ if (size < 1 || size > 7)
+ {
+ printError("sendCTRL", "size should be a value between 1 and 6.");
+ return -2;
+ }
+
+ // Setup Command
+ // 5 byte header + 5 float values * 4 + 2 byte values
+ unsigned char buffer[27] = "CTRL";
+ int cur = 5;
+ for (int i = 0; i < 6; i++)
+ {
+ float val = -998;
+
+ if (i < size)
+ {
+ val = values[i];
+ }
+ if (i == 4)
+ {
+ buffer[cur++] = val == -998 ? -1 : (unsigned char)val;
+ }
+ else
+ {
+ *((float*)(buffer + cur)) = val;
+ cur += sizeof(float);
+ }
+ }
+ buffer[26] = ac;
+
+ // Send Command
+ if (sendUDP(sock, buffer, 27) < 0)
+ {
+ printError("sendCTRL", "Failed to send command");
+ return -3;
+ }
+ return 0;
+}
+/*****************************************************************************/
+/**** End CTRL functions ****/
+/*****************************************************************************/
+
+/*****************************************************************************/
+/**** Drawing functions ****/
+/*****************************************************************************/
+int sendTEXT(XPCSocket sock, char* msg, int x, int y)
+{
+ if (msg == NULL)
+ {
+ msg = "";
+ }
+ size_t msgLen = strnlen(msg, 255);
+ // Input Validation
+ if (x < -1)
+ {
+ printError("sendTEXT", "x should be positive (or -1 for default).");
+ // Technically, this should work, and may print something to the screen.
+ }
+ if (y < -1)
+ {
+ printError("sendTEXT", "y should be positive (or -1 for default).");
+ // Negative y will never result in text being displayed.
+ return -1;
+ }
+ if (msgLen > 255)
+ {
+ printError("sendTEXT", "msg must be less than 255 bytes.");
+ return -2;
+ }
+
+ // Setup command
+ // 5 byte header + 8 byte position + up to 256 byte message
+ char buffer[269] = "TEXT";
+ size_t len = 14 + msgLen;
+ memcpy(buffer + 5, &x, sizeof(int));
+ memcpy(buffer + 9, &y, sizeof(int));
+ buffer[13] = msgLen;
+ strncpy(buffer + 14, msg, msgLen);
+
+ // Send Command
+ if (sendUDP(sock, buffer, len) < 0)
+ {
+ printError("sendTEXT", "Failed to send command");
+ return -3;
+ }
+ return 0;
+}
+
+int sendWYPT(XPCSocket sock, WYPT_OP op, float points[], int count)
+{
+ // Input Validation
+ if (op < XPC_WYPT_ADD || op > XPC_WYPT_CLR)
+ {
+ printError("sendWYPT", "Unrecognized operation.");
+ return -1;
+ }
+ if (count > 255)
+ {
+ printError("sendWYPT", "Too many points. Must be less than 256.");
+ return -2;
+ }
+
+ // Setup Command
+ // 7 byte header + 12 bytes * count
+ char buffer[3067] = "WYPT";
+ buffer[5] = (unsigned char)op;
+ buffer[6] = (unsigned char)count;
+ size_t ptLen = sizeof(float) * 3 * count;
+ memcpy(buffer + 7, points, ptLen);
+
+ // Send Command
+ if (sendUDP(sock, buffer, 40) < 0)
+ {
+ printError("sendWYPT", "Failed to send command");
+ return -2;
+ }
+ return 0;
+}
+/*****************************************************************************/
+/**** End Drawing functions ****/
+/*****************************************************************************/
diff --git a/C/src/xplaneConnect.h b/C/src/xplaneConnect.h
index 86b1615..e8520c3 100644
--- a/C/src/xplaneConnect.h
+++ b/C/src/xplaneConnect.h
@@ -1,119 +1,217 @@
+//Copyright (c) 2013-2015 United States Government as represented by the Administrator of the
+//National Aeronautics and Space Administration. All Rights Reserved.
//
-// xplaneConnect.h
-//
-// Created by Chris Teubert on 12/2/13.
+//DISCLAIMERS
+// No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND,
+// EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT
+// THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY
+// THAT THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED,
+// WILL CONFORM TO THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN
+// ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS, RESULTING DESIGNS,
+// HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING FROM USE OF THE SUBJECT
+// SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING
+// THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT "AS IS."
//
+// Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST THE UNITED STATES
+// GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT. IF
+// RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES
+// OR LOSSES ARISING FROM SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING
+// FROM, RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS THE
+// UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT,
+// TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE
+// IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.
+#ifndef xplaneConnect_h
+#define xplaneConnect_h
#ifdef __cplusplus
- extern "C" {
+extern "C" {
#endif
- #ifndef xplaneConnect_h
- #define xplaneConnect_h
+#include "stdlib.h"
+#ifdef _WIN32 /* WIN32 SYSTEM */
+#include
+#include
+#pragma comment(lib,"ws2_32.lib") //Winsock Library
+#elif (__APPLE__ || __linux)
+#include
+#include
+#include
+#include
+#endif
- #ifdef _WIN32 /* WIN32 SYSTEM */
- #include
- #include
- #pragma comment(lib,"ws2_32.lib") //Winsock Library
- #elif (__APPLE__ || __linux)
- #include
- #include
- #include
- #include
- #endif
-
- struct xpcSocket {
- short open;
- unsigned short port;
-
- // X-Plane IP and Port
- char xpIP[16];
- unsigned short xpPort;
-
- #ifdef _WIN32 /* WIN32 SYSTEM */
- SOCKET sock;
- #elif (__APPLE__ || __linux) //OS X/Linux
- int sock;
- #endif
- };
+typedef struct xpcSocket
+{
+ unsigned short port;
- typedef struct
- {
- float pitch;
- float roll;
- float yaw;
- float throttle;
- char gear;
- float flaps;
- char aircraft;
- } xpcCtrl;
+ // X-Plane IP and Port
+ char xpIP[16];
+ unsigned short xpPort;
- typedef struct
- {
- double latitude;
- double longitude;
- double altitude;
- } Waypoint;
+#ifdef _WIN32
+ SOCKET sock;
+#else
+ int sock;
+#endif
+} XPCSocket;
- typedef enum
- {
- xpc_WYPT_ADD = 1,
- xpc_WYPT_DEL = 2,
- xpc_WYPT_CLR = 3
- } WYPT_OP;
+typedef enum
+{
+ XPC_WYPT_ADD = 1,
+ XPC_WYPT_DEL = 2,
+ XPC_WYPT_CLR = 3
+} WYPT_OP;
+
+// Low Level UDP Functions
- typedef struct
- {
- WYPT_OP op;
- Waypoint points[20];
- size_t numPoints;
- } xpcWypt;
-
- // Basic Functions
- struct xpcSocket openUDP(unsigned short port, const char *xpIP, unsigned short xpPort);
- void closeUDP(struct xpcSocket);
- short sendUDP(struct xpcSocket recfd, char my_message[], short messageLength);
- short readUDP(struct xpcSocket recfd, char *dataRef, struct sockaddr *recvaddr);
-
- // Configuration
- short setCONN(struct xpcSocket recfd, unsigned short recPort);
- short pauseSim(struct xpcSocket recfd, short);
-
- // UDP DATA
- short parseDATA(const char my_message[], short messageLength, float dataRef[][9]);
- short readDATA(struct xpcSocket recfd, float dataRef[][9]);
- short sendDATA(struct xpcSocket recfd, float dataRef[][9], unsigned short rows);
-
- // Position
- short parsePOSI(const char my_message[], float resultArray[], int arraySize, float *gear);
- short readPOSI(struct xpcSocket recfd, float resultArray[], int arraySize, float *gear);
- short sendPOSI(struct xpcSocket recfd, short ACNum, short numArgs, float valueArray[]);
-
- // Controls
- xpcCtrl parseCTRL(const char data[]);
- xpcCtrl readCTRL(struct xpcSocket recfd);
- short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]);
- short sendpCTRL(struct xpcSocket recfd, short numArgs, float valueArray[], char acNum);
-
- // DREF Manipulation
- short readDREF(struct xpcSocket recfd, float *resultArray[], short arraySizes[]);
- short parseDREF(const char my_message[], char *dataRef, unsigned short *length_of_DREF, float *values, unsigned short *number_of_values);
- short sendDREF(struct xpcSocket recfd, const char *dataRef, unsigned short length_of_DREF, float *values, unsigned short number_of_values);
- short requestDREF(struct xpcSocket sendfd, struct xpcSocket recfd, char DREFArray[][100], short DREFSizes[], short listLength, float *resultArray[], short arraySizes[]);
- int parseGETD(const char my_message[], char *DREFArray[], int DREFSizes[]);
- short parseRequest(const char my_message[], float *resultArray[], short arraySizes[]);
- short readRequest(struct xpcSocket recfd, float *dataRef[], short arraySizes[], struct sockaddr *recvaddr);
+/// Opens a new connection to XPC on an OS chosen port.
+///
+/// \param xpIP A string representing the IP address of the host running X-Plane.
+/// \returns An XPCSocket struct representing the newly created connection.
+XPCSocket openUDP(const char *xpIP);
- // Waypoints
- xpcWypt parseWYPT(const char data[]);
- short sendWYPT(struct xpcSocket sendfd, WYPT_OP op, float points[], int numPoints);
+/// Opens a new connection to XPC on the specified port.
+///
+/// \param xpIP A string representing the IP address of the host running X-Plane.
+/// \param xpPort The port of the X-Plane Connect plugin is listening on. Usually 49009.
+/// \param port The local port to use when sending and receiving data from XPC.
+/// \returns An XPCSocket struct representing the newly created connection.
+XPCSocket aopenUDP(const char *xpIP, unsigned short xpPort, unsigned short port);
- // Screen Text
- short sendTEXT(struct xpcSocket sendfd, char* msg, int x, int y);
+/// Closes the specified connection and releases resources associated with it.
+///
+/// \param sock The socket to close.
+void closeUDP(XPCSocket sock);
+// Configuration
+
+/// Sets the port on which the socket sends and receives data.
+///
+/// \param sock A pointer to the socket to change.
+/// \param port The new port to use.
+/// \returns 0 if successful, otherwise a negative value.
+int setCONN(XPCSocket* sock, unsigned short port);
+
+/// Pause or unpause the simulation.
+///
+/// \param sock The socket to use to send the command.
+/// \param pause 0 to unpause the sim; any other value to pause.
+/// \returns 0 if successful, otherwise a negative value.
+int pauseSim(XPCSocket sock, char pause);
- #endif //ifdef _h
+// X-Plane UDP DATA
+
+/// Reads X-Plane data from the specified socket.
+///
+/// \details This command is compatible with the X-Plane data API.
+/// \param sock The socket to use to send the command.
+/// \param data A 2D array of data rows to read into.
+/// \param rows The number of rows in dataRef.
+/// \returns 0 if successful, otherwise a negative value.
+int readDATA(XPCSocket sock, float data[][9], int rows);
+
+/// Sends X-Plane data on the specified socket.
+///
+/// \details This command is compatible with the X-Plane data API.
+/// \param sock The socket to use to send the command.
+/// \param data A 2D array of data rows to send.
+/// \param rows The number of rows in dataRef.
+/// \returns 0 if successful, otherwise a negative value.
+int sendDATA(XPCSocket sock, float data[][9], int rows);
+
+// DREF Manipulation
+
+/// Sets the specified dataref to the specified value.
+///
+/// \details dref names and their associated data types can be found on the XPSDK wiki at
+/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
+/// the size given on that page. XPC currently sends all values as floats regardless of
+/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
+/// \param sock The socket to use to send the command.
+/// \param dref The name of the dataref to set.
+/// \param values An array of values representing the data to set.
+/// \param size The number of elements in values.
+/// \returns 0 if successful, otherwise a negative value.
+int sendDREF(XPCSocket sock, const char* dref, float value[], int size);
+
+/// Gets the value of the specified dataref.
+///
+/// \details dref names and their associated data types can be found on the XPSDK wiki at
+/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
+/// the size given on that page. XPC currently sends all values as floats regardless of
+/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
+/// \param sock The socket to use to send the command.
+/// \param dref The name of the dataref to get.
+/// \param values The array in which the value of the dataref will be stored.
+/// \param size The number of elements in values. The actual number of elements copied in will
+/// be set when the function returns.
+/// \returns 0 if successful, otherwise a negative value.
+int getDREF(XPCSocket sock, const char* dref, float values[], int* size);
+
+/// Gets the value of the specified dataref.
+///
+/// \details dref names and their associated data types can be found on the XPSDK wiki at
+/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
+/// the size given on that page. XPC currently sends all values as floats regardless of
+/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
+/// \param sock The socket to use to send the command.
+/// \param drefs The names of the datarefs to get.
+/// \param values A 2D array in which the values of the datarefs will be stored.
+/// \param count The number of datarefs being requested.
+/// \param size The number of elements in each row of values. The size of each row will be set
+/// to the actual number of elements copied in for that row.
+/// \returns 0 if successful, otherwise a negative value.
+int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char count, int sizes[]);
+// Position
+
+/// Sets the position and orientation of the specified aircraft.
+///
+/// \param sock The socket to use to send the command.
+/// \param values An array representing position data about the aircraft. The format of values is
+/// [Lat, Lon, Alt, Pitch, Roll, Yaw, Gear]. If less than 7 values are specified,
+/// the unspecified values will be left unchanged.
+/// \param size The number of elements in values.
+/// \param ac The aircraft number to set the position of. 0 for the player aircraft.
+/// \returns 0 if successful, otherwise a negative value.
+int sendPOSI(XPCSocket sock, float values[], int size, char ac);
+
+// Controls
+
+/// Sets the control surfaces of the specified aircraft.
+///
+/// \param sock The socket to use to send the command.
+/// \param values An array representing position data about the aircraft. The format of values is
+/// [Elevator, Aileron, Rudder, Throttle, Gear, Flaps]. If less than 6 values are
+/// specified, the unspecified values will be left unchanged.
+/// \param size The number of elements in values.
+/// \param ac The aircraft number to set the control surfaces of. 0 for the player aircraft.
+/// \returns 0 if successful, otherwise a negative value.
+int sendCTRL(XPCSocket sock, float values[], int size, char ac);
+
+// Drawing
+
+/// Sets a string to be printed on the screen in X-Plane.
+///
+/// \param sock The socket to use to send the command.
+/// \param msg The message to print of the screen.
+/// \param x The distance in pixels from the left edge of the screen to print the text.
+/// \param y The distance in pixels from the bottom edge of the screen to print the top line of text.
+/// \returns 0 if successful, otherwise a negative value.
+int sendTEXT(XPCSocket sock, char* msg, int x, int y);
+
+/// Adds, removes, or clears a set of waypoints. If the command is clear, the points are ignored
+/// and all points are removed.
+///
+/// \param sock The socket to use to send the command.
+/// \param op The operation to perform. 1=add, 2=remove, 3=clear.
+/// \param points An array of values representing points. Each triplet in the array will be
+/// interpreted as a (Lat, Lon, Alt) point.
+/// \param count The number of points. There should be 3 * count elements in points.
+/// \returns 0 if successful, otherwise a negative value.
+int sendWYPT(XPCSocket sock, WYPT_OP op, float points[], int count);
+
#ifdef __cplusplus
}
#endif
+#endif
diff --git a/C/xpcExample/xpcExample/src/main.cpp b/C/xpcExample/xpcExample/src/main.cpp
index f4ba86b..17b2a81 100644
--- a/C/xpcExample/xpcExample/src/main.cpp
+++ b/C/xpcExample/xpcExample/src/main.cpp
@@ -16,38 +16,17 @@
#define sleep(n) Sleep(n * 1000)
#endif
-int main() {
- int i, j;
- struct xpcSocket sendfd, readfd;
- float data[4][9] = { 0 };
- char DREF[100] = { 0 };
- char DREFArray[100][100];
- char DREFArray2[100][100];
- short DREFSizes[100];
- float *recDATA[100];
- float POSI[9] = { 0.0 };
- float CTRL[5] = { 0.0 };
- float gear;
- char IP[16] = "127.0.0.1"; //IP Address of computer running X-Plane
- short PORT = 49009; //xpcPlugin Receiving port (usually 49009)
+int main()
+{
+ printf("XPlaneConnect Example Script\n- Setting up Simulation\n");
- printf("xplaneconnect Example Script\n- Setting up Simulation\n");
-
- for (i = 0; i < 100; i++) {
- recDATA[i] = (float *)malloc(40 * sizeof(float));
- memset(DREFArray[i], 0, 100);
- memset(DREFArray2[i], 0, 100);
- }
-
- // Open Sockets
- readfd = openUDP(49055, IP, PORT); //Open socket for receiving
- sendfd = openUDP(49077, IP, PORT); //Open socket for sending
-
- // Set up Connection
- setCONN(sendfd, 49055); // Setup so data will be received on port 49055
+ // Open Socket
+ const char* IP = "127.0.0.1"; //IP Address of computer running X-Plane
+ XPCSocket sock = openUDP(IP);
// Set Location/Orientation (sendPOSI)
// Set Up Position Array
+ float POSI[9] = { 0.0 };
POSI[0] = 37.524; // Lat
POSI[1] = -122.06899; // Lon
POSI[2] = 2500; // Alt
@@ -56,22 +35,30 @@ int main() {
POSI[5] = 0; // Heading
POSI[6] = 1; // Gear
- sendPOSI(sendfd, 0, 7, POSI);
+ // Set position of the player aircraft
+ sendPOSI(sock, POSI, 7, 0);
+
POSI[0] = 37.52465; // Move a second aircraft a bit North of us
POSI[4] = 20; // Give that aircraft a bit or right roll
- sendPOSI(sendfd, 1, 7, POSI);
+ // Set position of a multiplayer aircraft
+ sendPOSI(sock, POSI, 7, 1);
// Set Rates (sendDATA)
-
- for (i = 0; i < 4; i++) { // Set array to -999
- for (j = 0; j < 9; j++) data[i][j] = -999;
+ float data[3][9] = { 0 };
+ // Initialize data values to -998 to not overwrite values.
+ for (int i = 0; i < 3; i++)
+ {
+ for (int j = 0; j < 9; j++)
+ {
+ data[i][j] = -998;
+ }
}
// Set up Data Array (first item in row is item number (example: 20=position)
data[0][0] = 18; // Alpha
data[0][1] = 0;
data[0][3] = 0;
- data[1][0] = 3;//21; //Velocity
+ data[1][0] = 3; //Velocity
data[1][1] = 130;
data[1][2] = 130;
data[1][3] = 130;
@@ -82,21 +69,19 @@ int main() {
data[2][2] = 0;
data[2][3] = 0;
- sendDATA(sendfd, data, 3); // Velocity/Alpha/PQR
+ sendDATA(sock, data, 3);
- // Set CTRL
+ // Set throttle on the player aircraft using sendCTRL
+ float CTRL[5] = { 0.0 };
CTRL[3] = 0.8; // Throttle
-
- sendCTRL(sendfd, 4, CTRL);
+ sendCTRL(sock, CTRL, 5, 0);
// pauseSim
- pauseSim(sendfd, 1); // Sending 1 to pause
-
- // Pause for 5 seconds
- sleep(5);
+ pauseSim(sock, 1); // Sending 1 to pause
+ sleep(5); // Pause for 5 seconds
// Unpause
- pauseSim(sendfd, 0); // Sending 0 to unpause
+ pauseSim(sock, 0); // Sending 0 to unpause
printf("- Resuming Simulation\n");
// Simulate for 10 seconds
@@ -105,28 +90,34 @@ int main() {
// SendDREF (Landing Gear)
printf("- Stowing Landing Gear\n");
- strcpy(DREF, "sim/cockpit/switches/gear_handle_status"); // Gear handle data reference
- DREFSizes[0] = strlen(DREF);
- gear = 1; // Stow gear
-
- sendDREF(sendfd, DREF, DREFSizes[0], &gear, 1); // Set gear to stow
+ const char* dref = "sim/cockpit/switches/gear_handle_status"; // Gear handle data reference
+ float gear = 0; // Stow gear
+ sendDREF(sock, dref, &gear, 1); // Set gear to stow
// Simulate for 10 seconds
sleep(10);
// Check Landing gear, Pause
printf("- Confirming Gear Status\n");
- strcpy(DREFArray2[0], "sim/cockpit/switches/gear_handle_status");
- strcpy(DREFArray2[1], "sim/operation/override/override_planepath");
- for (i = 0; i < 2; i++) {
- DREFSizes[i] = (int)strlen(DREFArray2[i]);
+ const char* drefs[2] =
+ {
+ "sim/cockpit/switches/gear_handle_status",
+ "sim/operation/override/override_planepath"
+ };
+ float* results[2];
+ int sizes[2] = { 20, 20 };
+ for (int i = 0; i < 2; ++i)
+ {
+ results[i] = (float*)malloc(20 * sizeof(float));
}
- requestDREF(sendfd, readfd, DREFArray2, DREFSizes, 2, recDATA, DREFSizes); // Request 2 values
+ getDREFs(sock, drefs, results, 2, sizes);
- if (*(recDATA[0]) == 0) {
+ if (results[0][0] == 0)
+ {
printf("\tGear Stowed\n");
}
- else {
+ else
+ {
printf("\tERROR: Gear Stowage unsuccessful\n");
}
diff --git a/Docs/Interface Control Document.xlsx b/Docs/Interface Control Document.xlsx
index d31f18b..c989b60 100644
Binary files a/Docs/Interface Control Document.xlsx and b/Docs/Interface Control Document.xlsx differ
diff --git a/Java/Examples/BasicOperation/src/Main.java b/Java/Examples/BasicOperation/src/Main.java
index 76f8805..1ab5bcc 100644
--- a/Java/Examples/BasicOperation/src/Main.java
+++ b/Java/Examples/BasicOperation/src/Main.java
@@ -82,7 +82,7 @@ public class Main
"sim/cockpit/switches/gear_handle_status",
"sim/operation/override/override_planepath"
};
- float[][] results = xpc.requestDREFs(drefs);
+ float[][] results = xpc.getDREFs(drefs);
if(results[0][0] == 1)
{
diff --git a/Java/src/XPlaneConnect.java b/Java/src/XPlaneConnect.java
index 4215038..245e7c8 100644
--- a/Java/src/XPlaneConnect.java
+++ b/Java/src/XPlaneConnect.java
@@ -44,8 +44,7 @@ import java.util.Arrays;
public class XPlaneConnect implements AutoCloseable
{
private static int clientNum;
- private DatagramSocket outSocket;
- private DatagramSocket inSocket;
+ private DatagramSocket socket;
private InetAddress xplaneAddr;
private int xplanePort;
@@ -54,7 +53,7 @@ public class XPlaneConnect implements AutoCloseable
*
* @return The incoming port number.
*/
- public int getRecvPort() { return inSocket.getLocalPort(); }
+ public int getRecvPort() { return socket.getLocalPort(); }
/**
* Gets the port on which the client sends data to X-Plane.
@@ -116,62 +115,55 @@ public class XPlaneConnect implements AutoCloseable
*/
public XPlaneConnect(int timeout) throws SocketException
{
- this.inSocket = new DatagramSocket(49008);
- this.outSocket = new DatagramSocket(50000 + ++clientNum);
+ this.socket = new DatagramSocket(0);
this.xplaneAddr = InetAddress.getLoopbackAddress();
this.xplanePort = 49009;
- this.inSocket.setSoTimeout(timeout);
+ this.socket.setSoTimeout(timeout);
}
/**
* Initializes a new instance of the {@code XPlaneConnect} class using the specified ports and X-Plane host.
*
- * @param port The port on which the X-Plane Connect plugin is sending data.
- * @param xplaneHost The network host on which X-Plane is running.
- * @param xplanePort The port on which the X-Plane Connect plugin is listening.
+ * @param xpHost The network host on which X-Plane is running.
+ * @param xpPort The port on which the X-Plane Connect plugin is listening.
+ * @param port The local port to use when sending and receiving data from XPC.
* @throws java.net.SocketException If this instance is unable to bind to the specified port.
* @throws java.net.UnknownHostException If the specified hostname can not be resolved.
*/
- public XPlaneConnect(int port, String xplaneHost, int xplanePort)
+ public XPlaneConnect(String xpHost, int xpPort, int port)
throws java.net.SocketException, java.net.UnknownHostException
{
- this(port, xplaneHost, xplanePort, 100);
+ this(xpHost, xpPort, port, 100);
}
/**
* Initializes a new instance of the {@code XPlaneConnect} class using the specified ports, hostname, and timeout.
*
- * @param port The port on which the X-Plane Connect plugin is sending data.
- * @param xplaneHost The network host on which X-Plane is running.
- * @param xplanePort The port on which the X-Plane Connect plugin is listening.
+ * @param xpHost The network host on which X-Plane is running.
+ * @param xpPort The port on which the X-Plane Connect plugin is listening.
+ * @param port The port on which the X-Plane Connect plugin is sending data.
* @param timeout The time, in milliseconds, after which read attempts will timeout.
* @throws java.net.SocketException If this instance is unable to bind to the specified port.
* @throws java.net.UnknownHostException If the specified hostname can not be resolved.
*/
- public XPlaneConnect(int port, String xplaneHost, int xplanePort, int timeout)
+ public XPlaneConnect(String xpHost, int xpPort, int port, int timeout)
throws java.net.SocketException, java.net.UnknownHostException
{
- this.inSocket = new DatagramSocket(port);
- this.outSocket = new DatagramSocket(50000 + ++clientNum);
- this.xplaneAddr = InetAddress.getByName(xplaneHost);
- this.xplanePort = xplanePort;
- this.inSocket.setSoTimeout(timeout);
+ this.socket = new DatagramSocket(port);
+ this.xplaneAddr = InetAddress.getByName(xpHost);
+ this.xplanePort = xpPort;
+ this.socket.setSoTimeout(timeout);
}
/**
- * Closes the underlying inSocket.
+ * Closes the underlying socket.
*/
public void close()
{
- if(inSocket != null)
+ if(socket != null)
{
- inSocket.close();
- inSocket = null;
- }
- if(outSocket != null)
- {
- outSocket.close();
- outSocket = null;
+ socket.close();
+ socket = null;
}
}
@@ -181,14 +173,14 @@ public class XPlaneConnect implements AutoCloseable
* @return The data send from X-Plane.
* @throws IOException If the read operation fails
*/
- private byte[] readUDP() throws IOException //TODO: Store data in a class level buffer to account for partial messages
+ private byte[] readUDP() throws IOException
{
byte[] buffer = new byte[2048];
DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
try
{
- inSocket.receive(packet);
- return Arrays.copyOf(buffer, buffer[4]);
+ socket.receive(packet);
+ return Arrays.copyOf(buffer, packet.getLength());
}
catch (SocketTimeoutException ex)
{
@@ -197,22 +189,15 @@ public class XPlaneConnect implements AutoCloseable
}
/**
- * Send the given data to the X-Plane plugin. This method automatically sets the length byte before sending,
- * overwriting any value previously stored in @{code buffer[4]}.
+ * Send the given data to the X-Plane plugin.
*
* @param buffer The data to send.
* @throws IOException If the send operation fails.
*/
private void sendUDP(byte[] buffer) throws IOException
{
- if(buffer.length < 5 || buffer.length > 255)
- {
- throw new IllegalArgumentException("buffer must be between 5 and 255 bytes long.");
- }
- buffer[4] = (byte)buffer.length;
-
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, xplaneAddr, xplanePort);
- outSocket.send(packet);
+ socket.send(packet);
}
/**
@@ -236,9 +221,9 @@ public class XPlaneConnect implements AutoCloseable
* @return A byte array representing data dependent on the dref requested.
* @throws IOException If either the request or the response fails.
*/
- public float[] requestDREF(String dref) throws IOException
+ public float[] getDREF(String dref) throws IOException
{
- return requestDREFs(new String[]{dref})[0];
+ return getDREFs(new String[] {dref})[0];
}
/**
@@ -248,7 +233,7 @@ public class XPlaneConnect implements AutoCloseable
* @return A multidimensional array representing the data for each requested dref.
* @throws IOException If either the request or the response fails.
*/
- public float[][] requestDREFs(String[] drefs) throws IOException
+ public float[][] getDREFs(String[] drefs) throws IOException
{
//Preconditions
if(drefs == null || drefs.length == 0)
@@ -329,7 +314,7 @@ public class XPlaneConnect implements AutoCloseable
/**
* Sends a command to X-Plane that sets the given DREF.
*
- * @param dref The name of the DREF to set.
+ * @param dref The name of the X-Plane dataref to set.
* @param value An array of floating point values whose structure depends on the dref specified.
* @throws IOException If the command cannot be sent.
*/
@@ -375,33 +360,33 @@ public class XPlaneConnect implements AutoCloseable
}
/**
- * Sends command to X-Plane setting control surfaces on the player aircraft.
+ * Sends command to X-Plane setting control surfaces on the player ac.
*
- * @param ctrl
An array containing zero to six values representing control surface data as follows:
- *
- *
Latitudinal Stick [-1,1]
- *
Longitudinal Stick [-1,1]
- *
Rudder Pedals [-1, 1]
- *
Throttle [-1, 1]
- *
Gear (0=up, 1=down)
- *
Flaps [0, 1]
- *
- *
- * If @{code ctrl} is less than 6 elements long, The missing elements will not be changed. To
- * change values in the middle of the array without affecting the preceding values, set the
- * preceding values to -998.
- *
+ * @param values
An array containing zero to six values representing control surface data as follows:
+ *
+ *
Latitudinal Stick [-1,1]
+ *
Longitudinal Stick [-1,1]
+ *
Rudder Pedals [-1, 1]
+ *
Throttle [-1, 1]
+ *
Gear (0=up, 1=down)
+ *
Flaps [0, 1]
+ *
+ *
+ * If @{code ctrl} is less than 6 elements long, The missing elements will not be changed. To
+ * change values in the middle of the array without affecting the preceding values, set the
+ * preceding values to -998.
+ *
* @throws IOException If the command cannot be sent.
*/
- public void sendCTRL(float[] ctrl) throws IOException
+ public void sendCTRL(float[] values) throws IOException
{
- sendCTRL(ctrl, 0);
+ sendCTRL(values, 0);
}
/**
- * Sends command to X-Plane setting control surfaces on the specified aircraft.
+ * Sends command to X-Plane setting control surfaces on the specified ac.
*
- * @param ctrl
An array containing zero to six values representing control surface data as follows:
+ * @param values
An array containing zero to six values representing control surface data as follows:
*
*
Latitudinal Stick [-1,1]
*
Longitudinal Stick [-1,1]
@@ -415,23 +400,23 @@ public class XPlaneConnect implements AutoCloseable
* change values in the middle of the array without affecting the preceding values, set the
* preceding values to -998.
*
- * @param aircraft The aircraft to set. 0 for the player's aircraft.
+ * @param ac The ac to set. 0 for the player's ac.
* @throws IOException If the command cannot be sent.
*/
- public void sendCTRL(float[] ctrl, int aircraft) throws IOException
+ public void sendCTRL(float[] values, int ac) throws IOException
{
//Preconditions
- if(ctrl == null)
+ if(values == null)
{
throw new IllegalArgumentException("ctrl must no be null.");
}
- if(ctrl.length > 6)
+ if(values.length > 6)
{
throw new IllegalArgumentException("ctrl must have 6 or fewer elements.");
}
- if(aircraft < 0 || aircraft > 9)
+ if(ac < 0 || ac > 9)
{
- throw new IllegalArgumentException("aircraft must be non-negative and less than 9.");
+ throw new IllegalArgumentException("ac must be non-negative and less than 9.");
}
//Pad command values and convert to bytes
@@ -439,16 +424,16 @@ public class XPlaneConnect implements AutoCloseable
int cur = 0;
ByteBuffer bb = ByteBuffer.allocate(22);
bb.order(ByteOrder.LITTLE_ENDIAN);
- for(i = 0; i < ctrl.length; ++i)
+ for(i = 0; i < values.length; ++i)
{
if(i == 4)
{
- bb.put(cur, (byte) ctrl[i]);
+ bb.put(cur, (byte) values[i]);
cur += 1;
}
else
{
- bb.putFloat(cur, ctrl[i]);
+ bb.putFloat(cur, values[i]);
cur += 4;
}
}
@@ -465,7 +450,7 @@ public class XPlaneConnect implements AutoCloseable
cur += 4;
}
}
- bb.put(cur, (byte) aircraft);
+ bb.put(cur, (byte) ac);
//Build and send message
ByteArrayOutputStream os = new ByteArrayOutputStream();
@@ -476,11 +461,11 @@ public class XPlaneConnect implements AutoCloseable
}
/**
- * Sets the position of the player aircraft.
+ * Sets the position of the player ac.
*
- * @param posi
An array containing position elements as follows:
+ * @param values
An array containing position elements as follows:
*
- *
Latitiude (deg)
+ *
Latitude (deg)
*
Longitude (deg)
*
Altitude (m above MSL)
*
Roll (deg)
@@ -495,17 +480,17 @@ public class XPlaneConnect implements AutoCloseable
*
* @throws IOException If the command can not be sent.
*/
- public void sendPOSI(float[] posi) throws IOException
+ public void sendPOSI(float[] values) throws IOException
{
- sendPOSI(posi, 0);
+ sendPOSI(values, 0);
}
/**
- * Sets the position of the specified aircraft.
+ * Sets the position of the specified ac.
*
- * @param posi
An array containing position elements as follows:
+ * @param values
An array containing position elements as follows:
*
- *
Latitiude (deg)
+ *
Latitude (deg)
*
Longitude (deg)
*
Altitude (m above MSL)
*
Roll (deg)
@@ -518,32 +503,32 @@ public class XPlaneConnect implements AutoCloseable
* change values in the middle of the array without affecting the preceding values, set the
* preceding values to -998.
*
- * @param aircraft The aircraft to set. 0 for the player aircraft.
+ * @param ac The ac to set. 0 for the player ac.
* @throws IOException If the command can not be sent.
*/
- public void sendPOSI(float[] posi, int aircraft) throws IOException
+ public void sendPOSI(float[] values, int ac) throws IOException
{
//Preconditions
- if(posi == null)
+ if(values == null)
{
throw new IllegalArgumentException("posi must no be null.");
}
- if(posi.length > 7)
+ if(values.length > 7)
{
throw new IllegalArgumentException("posi must have 7 or fewer elements.");
}
- if(aircraft < 0 || aircraft > 255)
+ if(ac < 0 || ac > 255)
{
- throw new IllegalArgumentException("aircraft must be between 0 and 255.");
+ throw new IllegalArgumentException("ac must be between 0 and 255.");
}
//Pad command values and convert to bytes
int i;
ByteBuffer bb = ByteBuffer.allocate(28);
bb.order(ByteOrder.LITTLE_ENDIAN);
- for(i = 0; i < posi.length; ++i)
+ for(i = 0; i < values.length; ++i)
{
- bb.putFloat(i * 4, posi[i]);
+ bb.putFloat(i * 4, values[i]);
}
for(; i < 7; ++i)
{
@@ -554,11 +539,41 @@ public class XPlaneConnect implements AutoCloseable
ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write("POSI".getBytes(StandardCharsets.UTF_8));
os.write(0xFF); //Placeholder for message length
- os.write(aircraft);
+ os.write(ac);
os.write(bb.array());
sendUDP(os.toByteArray());
}
+ /**
+ * Reads X-Plane data
+ *
+ * @return The data read.
+ * @throws IOException If the read operation fails.
+ */
+ public float[][] readData() throws IOException
+ {
+ byte[] buffer = readUDP();
+ ByteBuffer bb = ByteBuffer.wrap(buffer);
+ int cur = 5;
+ int len = bb.get(cur++);
+ float[][] result = new float[bb.get(len)][9];
+ for(int i = 0; i < len; ++i)
+ {
+ for(int j = 0; j < 9; ++j)
+ {
+ result[i][j] = bb.getFloat(cur);
+ cur += 4;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Sends data to X-Plane
+ *
+ * @param data The data to send.
+ * @throws IOException If the command cannot be sent.
+ */
public void sendDATA(float[][] data) throws IOException
{
//Preconditions
@@ -594,6 +609,36 @@ public class XPlaneConnect implements AutoCloseable
sendUDP(os.toByteArray());
}
+ /**
+ * Selects what data X-Plane will export over UDP.
+ *
+ * @param rows The row numbers to select.
+ * @throws IOException If the command cannot be sent.
+ */
+ public void selectDATA(int[] rows) throws IOException
+ {
+ //Preconditions
+ if(rows == null || rows.length == 0)
+ {
+ throw new IllegalArgumentException("rows must be a non-null, non-empty array.");
+ }
+
+ //Convert data to bytes
+ ByteBuffer bb = ByteBuffer.allocate(4 * rows.length);
+ bb.order(ByteOrder.LITTLE_ENDIAN);
+ for(int i = 0; i < rows.length; ++i)
+ {
+ bb.putInt(i * 4, rows[i]);
+ }
+
+ //Build and send message
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ os.write("DSEL".getBytes(StandardCharsets.UTF_8));
+ os.write(0xFF); //Placeholder for message length
+ os.write(bb.array());
+ sendUDP(os.toByteArray());
+ }
+
/**
* Sets a message to be displayed on the screen in X-Plane at the default screen location.
*
@@ -643,6 +688,15 @@ public class XPlaneConnect implements AutoCloseable
sendUDP(os.toByteArray());
}
+ /**
+ * Adds, removes, or clears a set of waypoints. If the command is clear, the points are ignored
+ * and all points are removed.
+ *
+ * @param op The operation to perform.
+ * @param points An array of values representing points. Each triplet in the array will be
+ * interpreted as a (Lat, Lon, Alt) point.
+ * @throws IOException If the command cannot be sent.
+ */
public void sendWYPT(WaypointOp op, float[] points) throws IOException
{
//Preconditions
@@ -650,6 +704,10 @@ public class XPlaneConnect implements AutoCloseable
{
throw new IllegalArgumentException("points.length should be divisible by 3.");
}
+ if(points.length / 3 > 255)
+ {
+ throw new IllegalArgumentException("Too many points. Must be less than 256.");
+ }
//Convert points to bytes
ByteBuffer bb = ByteBuffer.allocate(4 * points.length);
@@ -672,12 +730,12 @@ public class XPlaneConnect implements AutoCloseable
/**
* Sets the port on which the client will receive data from X-Plane.
*
- * @param recvPort The new incoming port number.
- * @throws IOException If the command cannnot be sent.
+ * @param port The new incoming port number.
+ * @throws IOException If the command cannot be sent.
*/
- public void setCONN(int recvPort) throws IOException
+ public void setCONN(int port) throws IOException
{
- if(recvPort < 0 || recvPort >= 0xFFFF)
+ if(port < 0 || port >= 0xFFFF)
{
throw new IllegalArgumentException("Invalid port (must be non-negative and less than 65536).");
}
@@ -685,13 +743,14 @@ public class XPlaneConnect implements AutoCloseable
ByteArrayOutputStream os = new ByteArrayOutputStream();
os.write("CONN".getBytes(StandardCharsets.UTF_8));
os.write(0xFF); //Placeholder for message length
- os.write((byte) recvPort);
- os.write((byte) (recvPort >> 8));
+ os.write((byte) port);
+ os.write((byte) (port >> 8));
sendUDP(os.toByteArray());
- int soTimeout = inSocket.getSoTimeout();
- inSocket.close();
- inSocket = new DatagramSocket(recvPort);
- inSocket.setSoTimeout(soTimeout);
+ int soTimeout = socket.getSoTimeout();
+ socket.close();
+ socket = new DatagramSocket(port);
+ socket.setSoTimeout(soTimeout);
+ readUDP(); // Try to read response
}
}
diff --git a/MATLAB/+XPlaneConnect/XPlaneConnect.jar b/MATLAB/+XPlaneConnect/XPlaneConnect.jar
new file mode 100644
index 0000000..997803d
Binary files /dev/null and b/MATLAB/+XPlaneConnect/XPlaneConnect.jar differ
diff --git a/MATLAB/+XPlaneConnect/clearUDPBuffer.m b/MATLAB/+XPlaneConnect/clearUDPBuffer.m
deleted file mode 100644
index 8237bd5..0000000
--- a/MATLAB/+XPlaneConnect/clearUDPBuffer.m
+++ /dev/null
@@ -1,33 +0,0 @@
-function socket = clearUDPBuffer(socket,varargin)
-% clearUDPBuffer Script that clears an UDP Socket Buffer by closing and
-% reopening the socket
-%
-% Inputs
-% Socket: UDP Socket to be cleared
-%
-% Outputs
-% Socket: UDP Socket
-%
-% Use
-% 1. import XPlaneConnect.*;
-% 2. Socket = openUDP(49005);
-% 3. Socket = clearUDPBuffer(Socket);
-%
-% Contributors
-% [CT] Christopher Teubert (SGT, Inc.)
-% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
-
- import XPlaneConnect.*
-
- %% Close and reopen socket
- if ~socket.isClosed()
- port = socket.getLocalPort(); %get port of socket
- socket.close; %Close Socket
- socket = openUDP(port,varargin); %open new socket
- end
-end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/closeUDP.m b/MATLAB/+XPlaneConnect/closeUDP.m
index 0575ddb..4941ae1 100644
--- a/MATLAB/+XPlaneConnect/closeUDP.m
+++ b/MATLAB/+XPlaneConnect/closeUDP.m
@@ -1,28 +1,31 @@
-function [socket] = closeUDP(socket)
-% closeUDP Script that closes a UDP Socket
+function closeUDP(socket)
+% closeUDP Closes the specified connection and releases resources associated with it.
%
% Inputs
-% Socket: UDP Socket to be closed
-%
-% Outputs
-% Socket: Closed Socket
+% socket: An XPC client to close
%
% Use
% 1. import XPlaneConnect.*;
-% 2. Socket = openUDP(49005);
-% 3. Status = closeUDP(Socket);
+% 2. socket = openUDP();
+% 3. closeUDP(socket);
%
% Contributors
% [CT] Christopher Teubert (SGT, Inc.)
% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
+% [JW] Jason Watkins
+% jason.w.watkins@nasa.gov
+%% Close the socket
+assert(isequal(class(socket), 'gov.nasa.xpc.XPlaneConnect'),...
+ '[closeUDP] ERROR: socket was not an XPC client.');
socket.close;
-assert(isequal(socket.isClosed(),1),'closeUDP: Error- Could not close socket');
+%% Track open clients
+global clients;
+for i = 1:length(clients)
+ if socket == clients(i)
+ clients = [clients(1:i-1) clients(i+1:length(clients))];
+ end
+end
end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/getDREFs.m b/MATLAB/+XPlaneConnect/getDREFs.m
new file mode 100644
index 0000000..dc23958
--- /dev/null
+++ b/MATLAB/+XPlaneConnect/getDREFs.m
@@ -0,0 +1,38 @@
+function result = getDREFs( drefs, socket )
+%requestDREF request the value of a specific DataRef from X-Plane over UDP
+%
+%Inputs
+% drefs: Cell Array of DataRefs to be requested
+% socket (optional): The client to use when sending the command.
+%Outputs
+% result: cell array of resulting data.
+%
+%Use
+% 1. import XPlaneConnect.*;
+% 2. socket = opendUDP();
+% 3. drefs = {'sim/cockpit2/controls/yoke_heading_ratio','sim/cockpit2/controls/yoke_roll_ratio'};
+% 4. result = requestDREF(drefs, socket);
+%
+% Contributors
+% [CT] Christopher Teubert (SGT, Inc.)
+% christopher.a.teubert@nasa.gov
+% [JW] Jason Watkins
+% jason.w.watkins@nasa.gov
+
+import XPlaneConnect.*
+
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[getDREFs] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
+ end
+end
+
+%% Send command
+result = socket.getDREFs(drefs);
+
+end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/openUDP.m b/MATLAB/+XPlaneConnect/openUDP.m
index 77aa43f..c38e087 100644
--- a/MATLAB/+XPlaneConnect/openUDP.m
+++ b/MATLAB/+XPlaneConnect/openUDP.m
@@ -1,41 +1,42 @@
-function [socket] = openUDP(port, varargin)
-%openUDP Script that opens an UDP Socket
+function [ socket ] = openUDP(varargin)
+%openUDP Initializes a new instance of the XPC client and returns it.
%
%Inputs
-% port: UDP Port for socket
+% xpHost: The network host on which X-Plane is running.
+% xpPort: The port on which the X-Plane Connect plugin is listening.
+% port: The local port to use when sending and receiving data from XPC.
% timeout (optional): Optional parameter for time to UDP timeout (in ms)
%Outputs
-% Socket: UDP Socket
+% socket: An instance of the XPC client.
%
% Use
% 1. import XPlaneConnect.*;
-% 2. Socket = openUDP(49005); %Open socket at port 49005 with timeout=0.1 sec
+% 2. socket = openUDP(); % Open a socket using the default settings
% or
-% 2. Socket = openUDP(49005); %Open socket at port 49005 with timeout=0.2 sec
+% 2. Socket = openUDP('127.0.0.1', 49008, 49005); % Open a socket to connect to X-Plane on the local machine and receive data on port 49005
%
% Contributors
% [CT] Christopher Teubert (SGT, Inc.)
% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
+% [JW] Jason Watkins
+% jason.w.watkins@nasa.gov
-import java.net.DatagramSocket
+%% Handle input
+p = inputParser;
+addOptional(p,'xpHost','127.0.0.1',@ischar);
+addOptional(p,'xpPort',49009,@isnumeric);
+addOptional(p,'port',0,@isnumeric);
+parse(p,varargin{:});
-%% create socket
- socket = DatagramSocket(port);
- socket.setSoTimeout(100);
- socket.setReceiveBufferSize(2000);
-
-%% interpret input
-if ~isempty(varargin)
- if isnumeric(varargin(1))
- socket.setSoTimeout(varargin(1));
- end
+%% Create client
+if ~exist('gov.nasa.xpc.XPlaneConnect', 'class')
+ [folder, ~, ~] = fileparts(which('XPlaneConnect.openUDP'));
+ javaaddpath(fullfile(folder, 'XPlaneConnect.jar'));
end
+socket = gov.nasa.xpc.XPlaneConnect(p.Results.xpHost, p.Results.xpPort, p.Results.port);
-assert(isequal(socket.isClosed(),0),'openUDP: Error- Could not open port');
+%% Track open clients
+global clients;
+clients = [clients, socket];
-end
+end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/pauseSim.m b/MATLAB/+XPlaneConnect/pauseSim.m
index 4903236..c15f809 100644
--- a/MATLAB/+XPlaneConnect/pauseSim.m
+++ b/MATLAB/+XPlaneConnect/pauseSim.m
@@ -1,13 +1,9 @@
-function status = pauseSim( pause, varargin )
-%pauseSim pause Simulation
+function pauseSim( pause, socket )
+%pauseSim Pauses or unpauses X-Plane.
%
%Inputs
-% Pause: binary value 0=run, 1=pause
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin
-%
-%Outputs
-% status: If there was an error. Status<0 means there was an error.
+% pause: binary value 0=run, 1=pause
+% socket (optional): The client to use when sending the command.
%
%Use
% 1. import XPlaneConnect.*;
@@ -16,29 +12,26 @@ function status = pauseSim( pause, varargin )
% Contributors
% [CT] Christopher Teubert (SGT, Inc.)
% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-%BEGIN CODE
+% [JW] Jason Watkins
+% jason.w.watkins@nasa.gov
import XPlaneConnect.*
-%% Handle Input
- % Optional parameters
- p = inputParser;
- addRequired(p,'pause',@isnumeric);
- addOptional(p,'IP','127.0.0.1',@ischar);
- addOptional(p,'port',49009,@isnumeric);
- parse(p,pause,varargin{:});
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[pauseSim] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
+ end
+end
- % Check format of input-TODO
+%% Validate input
+pause = logical(pause);
-%% BODY
- message = zeros(1,6);
-
- message(1:4) = 'SIMU'-0;
- message(6) = uint8(p.Results.pause);
+%% Send command
+socket.pauseSim(pause);
- status = sendUDP(message, p.Results.IP, p.Results.port);
end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/readDATA.m b/MATLAB/+XPlaneConnect/readDATA.m
index f0492a5..80f888e 100644
--- a/MATLAB/+XPlaneConnect/readDATA.m
+++ b/MATLAB/+XPlaneConnect/readDATA.m
@@ -1,9 +1,8 @@
-function [ sensor ] = readDATA( socket )
+function [ result ] = readDATA( socket )
% readDATA Reads UDP Socket and interprets data
%
% Inputs
-% location: Either an opened UDP Socket or integer port number
-%
+% socket (optional): The client to read from.
% Outputs
% If data is X-Plane data format:
% data: Matlab X-Plane DATA Structure
@@ -30,62 +29,30 @@ function [ sensor ] = readDATA( socket )
% NOTE: sending in a port number instead of an opened socket clears the UDP buffer. This only works if the data is being sent at a fast rate. Sending in a UDP Socket reads the first packet in the buffer.
%
% Contributors
-% [CT] Christopher Teubert (SGT, Inc.)
-% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
+% Christopher Teubert (SGT, Inc.)
+% Jason Watkins
- import XPlaneConnect.*
+import XPlaneConnect.*
- %% Read UDP Socket
- [ sensor.raw] = readUDP(socket);
-
- %% Interpret Input
- bits = size(sensor.raw);
- if sensor.raw ~= -998 %If the signal exists
- header = char(sensor.raw(1:4)');
- if strcmp(header,'DATA') %DATA signal type
- Values = floor((bits-5)/36);
- sensor.d = [];
- sensor.h = zeros(Values(1),1);
- for i=1:Values(1)
- sensor.h(i) = sensor.raw(6+(i-1)*36);
- sensor.d = [sensor.d; typecast(uint8(sensor.raw(10+(i-1)*36:5+i*36))','single')];
- end
- elseif strcmp(header,'STRU') %STRU signal type
- a = 6;
- while a % no data
-
-%% Handle Input
-p = inputParser;
-addRequired(p,'DREFArray');
-addOptional(p,'IP','127.0.0.1',@ischar);
-addOptional(p,'port',49009,@isnumeric);
-parse(p,DREFArray,varargin{:});
-
-%% BODY
- % Header
- message(1:4) = 'GETD'-0;
- message(6) = length(p.Results.DREFArray);
-
- % DREFS
- for i=1:length(p.Results.DREFArray)
- message(len) = length(p.Results.DREFArray{i});
- message(len+1:len+message(len)) = p.Results.DREFArray{i};
- len = len+1+message(len);
- end
-
- % Send UDP
- status = sendUDP(message, p.Results.IP, p.Results.port);
-
- % Look for response
- for i=1:40
- data = readUDP();
- if length(data) > 1 % Received Data
- status = 0;
- counter = 7;
- nArrays = data(6);
- result = cell(nArrays,1);
- for j=1:nArrays
- sizeArray = data(counter);
- result{j} = typecast(uint8(data(counter+1:counter+sizeArray*4))','single');
- counter = counter + 1 + sizeArray * 4;
- end
- break;
- else
- result = cell(0,1);
- end
- end
-end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/selectDATA.m b/MATLAB/+XPlaneConnect/selectDATA.m
index 49efca1..dc54fdc 100644
--- a/MATLAB/+XPlaneConnect/selectDATA.m
+++ b/MATLAB/+XPlaneConnect/selectDATA.m
@@ -1,13 +1,9 @@
-function [ status ] = selectDATA( index, varargin )
+function selectDATA( rows, socket )
% selectDATA Choose specific X-Plane parameters to be send over UDP
%
% Inputs
-% index: An array of the values that to be sent. Corresponds to the numbers on the XPlane Output screen
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-%
-% Outputs
-% status: If there was an error. Status<0 means there was an error.
+% rows: An array of the values that to be sent. Corresponds to the numbers on the XPlane Output screen
+% socket (optional): The client to use when sending the command.
%
% Use
% 1. import XPlaneConnect.*;
@@ -15,29 +11,24 @@ function [ status ] = selectDATA( index, varargin )
% 3. status = selectDATA( values, '127.0.0.1', 49005 ); % send to localhose port 49005
%
% Contributors
-% [CT] Christopher Teubert (SGT, Inc.)
-% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
+% Christopher Teubert (SGT, Inc.)
+% Jason Watkins
import XPlaneConnect.*
-%% Handle Input
-p = inputParser;
-addRequired(p,'index');
-addOptional(p,'IP','127.0.0.1',@ischar);
-addOptional(p,'port',49009,@isnumeric);
-parse(p,index,varargin{:});
-
-%% BODY
- dataString = ['DSEL'-0,0];
- for i=1:length(index)
- dataString = [dataString, p.Results.index(i), 0, 0, 0];
+%% 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.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
end
- status = sendUDP(dataStream, p.Results.IP, p.Results.port);
-
end
+%% Validate input
+rows = int32(rows);
+
+%% Send command
+socket.selectDATA(rows);
diff --git a/MATLAB/+XPlaneConnect/sendCTRL.m b/MATLAB/+XPlaneConnect/sendCTRL.m
index 821efd0..b3d85b3 100644
--- a/MATLAB/+XPlaneConnect/sendCTRL.m
+++ b/MATLAB/+XPlaneConnect/sendCTRL.m
@@ -1,64 +1,53 @@
-function [ status ] = sendCTRL( ctrl, acft, IP, port )
-% sendCTRL Send X-Plane Aircraft Control Commands over UDP
+function sendCTRL( values, ac, socket )
+% sendCTRL Sends command to X-Plane setting control surfaces on the specified aircraft.
%
% Inputs
-% ctrl: control array where the elements are as follows:
+% values: control array where the elements are as follows:
% 1. Latitudinal Stick [-1,1]
% 2. Longitudinal Stick [-1,1]
% 3. Pedal [-1, 1]
% 4. Throttle [-1, 1]
% 5. Gear (0=up, 1=down)
% 6. Flaps [0, 1]
-% acft (optional): Aircraft # (default is 0; 0 = own aircraft)
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
+% ac (optional): The aircraft to set. 0 for the player aircraft.
+% socket (optional): The client to use when sending the command.
%
% Outputs
% status: If there was an error. Status<0 means there was an error.
%
% Use
% 1. import XPlaneConnect.*;
-% 2. #Send the data array to port 49009 on the computer at IP address 172.0.100.54.
-% 3. status = sendCTRL([0, 0, 0, 0.8, 0, 1], 1, '172.0.100.54',49009);
+% 2. socket = openUDP();
+% 3. status = sendCTRL([0, 0, 0, 0.8, 0, 1], 0, socket); % Set throttle and flaps on the player aircraft.
%
-% Note: send the value -998 to not overwrite that parameter. That is, if -998 is sent, the parameter will stay at the current X-Plane value
+% Note: send the value -998 to not overwrite that parameter. That is, if
+% -998 is sent, the parameter will stay at the current X-Plane value.
%
% Contributors
-% [CT] Christopher Teubert (SGT, Inc.)
-% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
+% Christopher Teubert (SGT, Inc.)
+% Jason Watkins
import XPlaneConnect.*
-%% Handle Input
- % Optional parameters
- if ~exist('IP','var'), IP = '127.0.0.1'; end
- if ~exist('port','var'), port = 49009; end
- if ~exist('acft','var'), acft = 0; end
-
- % Check format of input-TODO
-
-%%BODY
- header = ['CTRL'-0,0];
- dataStream = header; %TODO-ADD ACFT
-
- % Deal with position update
- control = [-998.5, -998.5, -998.5, -998.5, -998.5, -998.5];
-
- for i=1:min(length(ctrl),length(control))
- control(i) = ctrl(i);
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[sendCTRL] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
end
- dataStream = [dataStream, typecast(single(control(1:4)),'uint8')];
- dataStream = [dataStream, uint8(control(5))];
- dataStream = [dataStream, typecast(single(control(6)),'uint8')];
- dataStream = [dataStream, uint8(acft)];
-
- % Send DATA
- status = sendUDP(dataStream, IP, port);
-
end
+%% Validate input
+values = single(values);
+if ~exist('ac', 'var')
+ ac = 0;
+end
+ac = logical(ac);
+
+%% Send command
+socket.sendCTRL(values, ac);
+
+end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/sendDATA.m b/MATLAB/+XPlaneConnect/sendDATA.m
index f051fbe..8e4c461 100644
--- a/MATLAB/+XPlaneConnect/sendDATA.m
+++ b/MATLAB/+XPlaneConnect/sendDATA.m
@@ -1,15 +1,11 @@
-function [ status ] = sendDATA(data, varargin)
+function sendDATA(data, socket)
% sendDATA Send X-Plane formatted DATA over UDP
%
% Inputs
% data: X-Plane formatted data. Is a matlab structure with the following fields:
% .h: Header array containing header numbers corresponding to values in the X-Plane UDP Data screen.
% .d: 2-D Data array. Each row contains eight values corresponding to the header value (.h(1) corresponds to .d(1,:))
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent . Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp interface.
-%
-% Outputs
-% status: 0: no error, <0: error
+% socket (optional): The client to use when sending the command.
%
% Use
% 1. import XPlaneConnect.*;
@@ -29,29 +25,23 @@ function [ status ] = sendDATA(data, varargin)
import XPlaneConnect.*
-%% Handle Input
-p = inputParser;
-addRequired(p,'data');
-addOptional(p,'IP','127.0.0.1',@ischar);
-addOptional(p,'port',49009,@isnumeric);
-parse(p,data,varargin{:});
-
-%% BODY
-
- header = ['DATA'-0,0];
- dataStream = header;
-
- for i=1:length(p.Results.data.h)
- dataStream = [dataStream, p.Results.data.h(i), 0, 0, 0, typecast(single(p.Results.data.d(i,1:8)),'uint8')]; %#ok
- end
-
- % Send DATA
- if length(dataStream) > 5
- status = sendUDP(dataStream, p.Results.IP, p.Results.port);
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[sendDATA] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
else
- disp('Warning in sendDATA: Sending empty dataStream')
- status = -2;
+ socket = clients(1);
end
-
end
+%% Validate input
+javaData = [];
+for i = 1:length(data.h);
+ javaData = [javaData; data.h(i) data.d(i, 1:8)];
+end
+
+%% Send command
+socket.sendDATA(javaData);
+
diff --git a/MATLAB/+XPlaneConnect/sendDREF.m b/MATLAB/+XPlaneConnect/sendDREF.m
index 4632d67..cbf2119 100644
--- a/MATLAB/+XPlaneConnect/sendDREF.m
+++ b/MATLAB/+XPlaneConnect/sendDREF.m
@@ -1,58 +1,38 @@
-function status = sendDREF( dataRef, Value, varargin )
-% sendDREF Send a command to change any DataRef in X-Plane over UDP. This requires the X-Plane Connect Plugin to be running
+function sendDREF( dref, value, socket )
+% sendDREF Sends a command to X-Plane that sets the given DREF.
%
% Inputs
-% dataRef: The X-Plane Dataref that will be chaged
-% Value: The value that the above dataref is set to
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-%
-% Outputs
-% status: If there was an error. status<0 means there was an error.
+% dref: The name of the X-Plane dataref to set.
+% Value: An array of floating point values whose structure depends on the dref specified.
+% socket (optional): The client to use when sending the command.
%
% Use
% 1. import XPlaneConnect.*
% 2. dataRef = 'sim/aircraft/parts/acf_gear_deploy'; // Landing Gear
% 3. Value = 0;
-% 4. status = sendDREF(dataRef, Value);
+% 4. status = setDREF(dataRef, Value);
%
% Contributors
% [CT] Christopher Teubert (SGT, Inc.)
% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
+% [JW] Jason Watkins
+% jason.w.watkins@nasa.gov
import XPlaneConnect.*
-status = 0;
-
-%% Handle Input
-p = inputParser;
-addRequired(p,'dataRef');
-addRequired(p,'Value');
-addOptional(p,'IP','127.0.0.1',@ischar);
-addOptional(p,'port',49009,@isnumeric);
-parse(p,dataRef, Value ,varargin{:});
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[setDREF] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
+ end
+end
-%% BODY
- dataStream = zeros(1,7+length(p.Results.dataRef)+length(p.Results.Value)*4);
- % Build Header
- dataStream(1:4) = 'DREF'-0;
-
- % Add DREF
- dataStream(6) = uint8(length(p.Results.dataRef));
- len = 6+length(p.Results.dataRef);
- dataStream(7:len)=p.Results.dataRef-0;
-
- % Add Value
- dataStream(len+1) =uint8(length(p.Results.Value));
- dataStream(len+2:end)=typecast(single(p.Results.Value),'uint8');
+%% Validate input
+value = single(value);
- % Send DREF
- if length(dataStream) > 5
- status = sendUDP(dataStream, p.Results.IP, p.Results.port);
- end
-end
\ No newline at end of file
+%%Send command
+socket.sendDREF(dref, value);
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/sendPOSI.m b/MATLAB/+XPlaneConnect/sendPOSI.m
index 4f85735..bff56fb 100644
--- a/MATLAB/+XPlaneConnect/sendPOSI.m
+++ b/MATLAB/+XPlaneConnect/sendPOSI.m
@@ -1,5 +1,5 @@
-function [ status ] = sendPOSI( posi, varargin )
-% sendPOSI Send X-Plane Aircraft Position over UDP
+function sendPOSI( posi, ac, socket )
+% sendPOSI Sets the position of the specified aircraft.
%
% Inputs
% posi: Position array where the elements are as follows:
@@ -10,52 +10,43 @@ function [ status ] = sendPOSI( posi, varargin )
% 5. Pitch (deg)
% 6. True Heading (deg)
% 7. Gear (0=up, 1=down)
-% acft (optional): Aircraft # (default is 0; 0 = own aircraft)
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-%
-% Outputs
-% status: If there was an error. Status<0 means there was an error.
+% acft (optional): The aircraft to set. 0 for the player aircraft.
+% socket (optional): The client to use when sending the command.
%
% Use
-% 1. import XPlaneConnect.*;
-% 2. #Send the data array to port 49009 on the computer at IP address 172.0.100.54.
-% 3. status = sendPOSI([37.5242422, -122.06899, 2500, 0, 0, 0, 1], 1, '172.0.100.54');
+% 1. import XPlaneConnect.*;
+% 2. sendPOSI([37.5242422, -122.06899, 2500, 0, 0, 0, 1], 1);
%
-% Note: send the value -998 to not overwrite that parameter. That is, if -998 is sent, the parameter will stay at the current X-Plane value
+% Note: send the value -998 to not overwrite that parameter. That is, if
+% -998 is sent, the parameter will stay at the current X-Plane value.
%
% Contributors
% [CT] Christopher Teubert (SGT, Inc.)
% christopher.a.teubert@nasa.gov
-%
-% To Do
-%
-% BEGIN CODE
+% [JW] Jason Watkins
+% jason.w.watkins@nasa.gov
import XPlaneConnect.*
-%% Handle Input
-p = inputParser;
-addRequired(p,'posi');
-addOptional(p,'acft',0,@isnumeric);
-addOptional(p,'IP','127.0.0.1',@ischar);
-addOptional(p,'port',49009,@isnumeric);
-parse(p,posi,varargin{:});
-
-%% BODY
- header = ['POSI'-0,0];
- dataStream = [header, p.Results.acft];
-
- % Deal with position update
- position = [37.4185718,-121.935565,500,0,0,0, 0];
-
- for i=1:min(length(position),length(p.Results.posi))
- position(i) = p.Results.posi(i);
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[sendPOSI] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
end
- dataStream = [dataStream, typecast(single(position),'uint8')];
-
- % Send POSI
- status = sendUDP(dataStream, p.Results.IP, p.Results.port);
-
end
+%% Validate input
+posi = single(posi);
+if ~exist('ac', 'var')
+ ac = 0;
+end
+ac = logical(ac);
+
+%% Send command
+socket.sendPOSI(posi, ac);
+
+end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/sendSTRU.m b/MATLAB/+XPlaneConnect/sendSTRU.m
deleted file mode 100644
index e00898a..0000000
--- a/MATLAB/+XPlaneConnect/sendSTRU.m
+++ /dev/null
@@ -1,57 +0,0 @@
-function [ status ] = sendSTRU( STRU, varargin )
-%sendSTRU Send a MATLAB structure over UDP
-%
-%Inputs
-% stru: A MATLAB structure
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin
-%
-%Outputs
-% status: If there was an error. Status<0 means there was an error.
-%
-%Use
-% 1. import XPlaneConnect.*;
-% 2. data = struct('a',[1:20],'b',1.853,'name','Example Structure');
-% 3. #Send the data structure to port 49005 on the computer at IP address 172.0.100.54
-% 4. status = sendUDP( data, '172.0.100.54', 49005 );
-%
-% Contributors
-% [CT] Christopher Teubert (SGT, Inc.)
-% christopher.a.teubert@nasa.gov
-%
-% To Do
-%
-%BEGIN CODE
-
- import XPlaneConnect.*
-
- %% Handle Input
- p = inputParser;
- addRequired(p,'STRU');
- addOptional(p,'IP','127.0.0.1',@ischar);
- addOptional(p,'port',49009,@isnumeric);
- parse(p,STRU,varargin{:});
-
- %% Form Data Array representing the structure
- DATA = ['STRU'-0,0]; %array header
- fieldName = fieldnames(p.Results.STRU); %all Struct fields
- for i=1:length(fieldName) %for each field
- field = getfield(p.Results.STRU,fieldName{i}); %get field
- if ischar(field) %String
- dim1 = 0; %Indicates string
- dim2 = length(field); %length
- data = field-0; %data
- else %Numeric
- dim1 = size(field,1); %Array Dim1
- dim2 = size(field,2); %Array Dim2
- data = typecast(single(reshape(field',1,dim1*dim2)),'uint8'); %Data
- end
-
- DATA = [DATA,length(fieldName{i}),fieldName{i}-0,dim1,dim2,data]; %add to array
- end
-
- %% Send Array
- status = sendUDP(DATA, p.Results.IP, p.Results.port);
-
-end
-
diff --git a/MATLAB/+XPlaneConnect/sendTEXT.m b/MATLAB/+XPlaneConnect/sendTEXT.m
index 499c12b..5edfaeb 100644
--- a/MATLAB/+XPlaneConnect/sendTEXT.m
+++ b/MATLAB/+XPlaneConnect/sendTEXT.m
@@ -1,4 +1,4 @@
-function [ status ] = sendTEXT( msg, varargin )
+function sendTEXT( msg, x, y, socket )
% sendTEXT Sends a string to be displayed in X-Plane.
%
% Inputs
@@ -13,35 +13,35 @@ function [ status ] = sendTEXT( msg, varargin )
%
% Use
% 1. import XPlaneConnect.*;
-% 2. #Set a message to be displayed near the top middle of the screen.
+% 2. % Set a message to be displayed near the top middle of the screen.
% 3. status = sendTEXT('Some text', 512, 600);
%
% Contributors
-% Jason Watkins
-% jason.w.watkins@nasa.gov
-%
-% To Do
-%
-% BEGIN CODE
+% Jason Watkins (jason.w.watkins@nasa.gov)
import XPlaneConnect.*
-%% Handle Input
-p = inputParser;
-addRequired(p,'msg');
-addOptional(p,'x',-1,@isnumeric);
-addOptional(p,'y',-1,@isnumeric);
-addOptional(p,'IP','127.0.0.1',@ischar);
-addOptional(p,'port',49009,@isnumeric);
-parse(p,msg,varargin{:});
-%% Body
- header = ['TEXT'-0,0];
- dataStream = [header,...
- typecast(uint32(p.Results.x), 'uint8'),...
- typecast(uint32(p.Results.y), 'uint8'),...
- uint8(length(msg)), msg-0];
-
- % Send TEXT
- status = sendUDP(dataStream, p.Results.IP, p.Results.port);
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[sendTEXT] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
+ end
end
+%% Validate input
+if ~exist('x', 'var')
+ x = -1;
+end
+if ~exist('y', 'var')
+ y = -1;
+end
+x = int32(x);
+y = int32(y);
+
+%% Send command
+socket.sendTEXT(msg, x, y);
+end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/sendUDP.m b/MATLAB/+XPlaneConnect/sendUDP.m
deleted file mode 100644
index 6b0b112..0000000
--- a/MATLAB/+XPlaneConnect/sendUDP.m
+++ /dev/null
@@ -1,49 +0,0 @@
-function [ status ] = sendUDP( data, IP, port )
-%sendUDP Send an one dimensional array of type uint8 data over an UDP connection using a java DatagramSocket
-%
-%Inputs
-% Data: 1-D array of type uint8 data to be sent
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin
-%
-%Outputs
-% status: If there was an error. Status<0 means there was an error.
-%
-%Use
-% 1. import XPlaneConnect.*;
-% 2. data = uint8([1:20]);
-% 3. #Send the data array to port 49005 on the computer at IP address 172.0.100.54.
-% 4. status = sendUDP( data, '172.0.100.54', 49005 );
-%
-% Contributors
-% [CT] Christopher Teubert (SGT, Inc.)
-% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-%BEGIN CODE
-
- import java.net.DatagramSocket
- import java.net.DatagramPacket
- import java.net.InetAddress
-
- data(5) = length(data);
- status = 0;
-
- %% Send array
- persistent socket
- if isempty(socket)
- try
- socket = DatagramSocket;
- catch err
- status = 1;
- disp(err)
- end
- end
-
- IP = InetAddress.getByName(IP);
- packet = DatagramPacket(data, length(data), IP, port); %create packet
- socket.send(packet);
-end
-
diff --git a/MATLAB/+XPlaneConnect/sendWYPT.m b/MATLAB/+XPlaneConnect/sendWYPT.m
index ed64b04..a366c89 100644
--- a/MATLAB/+XPlaneConnect/sendWYPT.m
+++ b/MATLAB/+XPlaneConnect/sendWYPT.m
@@ -1,53 +1,50 @@
-function [ status ] = sendWYPT( op, points, varargin )
+function sendWYPT( op, points, socket )
% sendWYPT Adds, removes, or clears a set of waypoints to be rendered in
% the simulator.
%
% Inputs
-% msg: The string to be displayed
-% x (optional): The distance from the left edge of the screen to display the message.
-% y (optional): The distance from the bottom edge of the screen to display the message.
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-%
-% Outputs
-% status: 0 if successful, otherwise a negative value.
+% op: The operation to perform. 1=add, 2=remove, 3=clear.
+% points: An array of values representing points. Each triplet in the
+% array will be interpreted as a (Lat, Lon, Alt) point.
+% socket (optional): The client to use when sending the command.
%
% Use
% 1. import XPlaneConnect.*;
-% 2. #Set a message to be displayed near the top middle of the screen.
+% 2. %Set a message to be displayed near the top middle of the screen.
% 3. status = sendTEXT('Some text', 512, 600);
%
% Contributors
-% Jason Watkins
-% jason.w.watkins@nasa.gov
+% Jason Watkins (jason.w.watkins@nasa.gov)
%
% To Do
%
% BEGIN CODE
import XPlaneConnect.*
-%% Handle Input
-p = inputParser;
-addRequired(p,'op');
-addRequired(p,'points');
-addOptional(p,'IP','127.0.0.1',@ischar);
-addOptional(p,'port',49009,@isnumeric);
-parse(p,op,points,varargin{:});
-%% Validate Input
-len = uint32(length(points));
-assert(op > 0 && op < 4);
-assert(mod(len, 3) == 0);
-assert(len / 3 < 20);
-
-%% Body
-header = ['WYPT'-0,0];
-dataStream = [header,...
- uint8(op),...
- uint8(len / 3),...
- typecast(single(points), 'uint8')];
-
-% Send TEXT
-status = sendUDP(dataStream, p.Results.IP, p.Results.port);
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[sendWYPT] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
+ end
end
+%% Validate input
+len = uint32(length(points));
+assert(op > 0 && op < 4);
+wyptOp = gov.nasa.xpc.WaypointOp.Add;
+if isequal(op, 2)
+ wyptOp = gov.nasa.xpc.WaypointOp.Del;
+elseif isequal(op, 3)
+ wyptOp = gov.nasa.xpc.WaypointOp.Clr;
+end
+assert(mod(len, 3) == 0);
+
+%% Send command
+socket.sendWYPT(wyptOp, points);
+
+end
\ No newline at end of file
diff --git a/MATLAB/+XPlaneConnect/setConn.m b/MATLAB/+XPlaneConnect/setConn.m
index ad757a4..905c440 100644
--- a/MATLAB/+XPlaneConnect/setConn.m
+++ b/MATLAB/+XPlaneConnect/setConn.m
@@ -1,50 +1,36 @@
-function status = setConn( recvPort, IP, port )
+function setConn(port, socket)
% setConn Send a command to set up the port where you will receive data on
% this computer.
%
% Inputs
-% Receiving Port: Port that data will be sent to in the future for this connection
-% IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-% port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-%
-% Outputs
-% status: If there was an error. status<0 means there was an error.
+% port: Port that data will be sent to in the future for this connection.
+% socket (optional): The client to use when sending the command.
%
% Use
% 1. import XPlaneConnect.*
% 2. status = setConn(49011);
%
% Contributors
-% [CT] Christopher Teubert (SGT, Inc.)
-% christopher.a.teubert@nasa.gov
-%
-% To Do
-% 1. Verify Input
-%
-% BEGIN CODE
- import XPlaneConnect.*
+% Christopher Teubert (SGT, Inc.)
+% Jason Watkins
- status = 0;
- message = zeros(1,7);
-
-%% Handle Input
- % Optional parameters
- if ~exist('IP','var'), IP = '127.0.0.1'; end
- if ~exist('port','var'), port = 49009; end
+import XPlaneConnect.*
- % Check format of input-TODO
+%% Get client
+global clients;
+if ~exist('socket', 'var')
+ assert(isequal(length(clients) < 2, 1), '[setCONN] ERROR: Multiple clients open. You must specify which client to use.');
+ if isempty(clients)
+ socket = openUDP();
+ else
+ socket = clients(1);
+ end
+end
-%% BODY
- % Header
- message(1:4) = 'CONN'-0;
-
- % RecvPort
- message(6:7) = typecast(uint16(recvPort),'uint8');
-
- % Send
- sendUDP(message,IP,port);
-
- global udpReadPort;
- udpReadPort = recvPort;
+%% Validate input
+port = int32(port);
+
+%% Send command
+socket.setCONN(port);
end
\ No newline at end of file
diff --git a/MATLAB/Documentation (MATLAB).html b/MATLAB/Documentation (MATLAB).html
deleted file mode 100644
index 87ba7c9..0000000
--- a/MATLAB/Documentation (MATLAB).html
+++ /dev/null
@@ -1,115 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox
-
-
-
-
-
-XPC-MATLAB is a series of MATLAB functions that facilitate communication with X-Plane. This toolbox allows for the real-time application of active control to an XPlane simulation, flight visualization, record state during a flight, or interact with a mission using UDP.
-
-
-Before using XPC Functions you must
-1. Install X-Plane (http://www.x-plane.com)
-2. Copy the file xpcPlugin.xpl to the "[X-Plane Directory]/Resources/plugins" directory.
- a. For Mac xpcPlugin can be found in the "[XPlaneConnect]/xpcPlugin/Mac" directory.
- a. For Windows xpcPlugin can be found in the "[XPlaneConnect]/xpcPlugin/Win" directory.
-3. Insert X-Plane CD 1 or X-Plane USB Key.
-4. Start X-Plane.
-5. import XPlaneConnect.*
-
-
No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS, RESULTING DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING FROM USE OF THE SUBJECT SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT "AS IS."
-
-
Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT. IF RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR LOSSES ARISING FROM SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING FROM, RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD HARMLESS THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.
-
- X-Plane API
-Copyright (c) 2008, Sandy Barbour and Ben Supnik All rights reserved.
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Neither the names of the authors nor that of X-Plane or Laminar Research may be used to endorse or promote products derived from this software without specific prior written permission from the authors or Laminar Research, respectively.
-
-
-
X-Plane API 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.
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-09/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/openUDP.html b/MATLAB/pages/openUDP.html
deleted file mode 100644
index d13ed2b..0000000
--- a/MATLAB/pages/openUDP.html
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-openUDP
-
-
-
-
-<-- Back
-
openUDP
-Script that opens a UDP Socket
-
-
Inputs
-
-
port: UDP Port for socket
-
timeout (optional): Optional parameter for time to UDP timeout (in ms)-Default 0.1 seconds
-
-
-
Outputs
-
-
Socket: UDP Socket
-
-
-
Use
-1. import XPlaneConnect.*;
-2. Socket = openUDP(49005);%Open socket at port 49005 with timeout of 0.1 seconds
-or
-2. Socket = openUDP(49005,200);%Open socket at port 49005 with timeout of 0.2 seconds
-
-
Change Log
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-09/12/13: [CT] Added optional timeout input argument
-09/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/pauseSim.html b/MATLAB/pages/pauseSim.html
deleted file mode 100644
index bf799c0..0000000
--- a/MATLAB/pages/pauseSim.html
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-pauseSim
-
-
-
-
-<-- Back
-
pauseSim
-
-
Inputs
-
-
Pause: binary value 0=run, 1=pause
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. status<0 means there was an error.
-
-
-
Use
-1. import XPlaneConnect.*;
-2. status = pauseSim(1);
-
-
Change Log
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-06/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/readDATA.html b/MATLAB/pages/readDATA.html
deleted file mode 100644
index 12cef1b..0000000
--- a/MATLAB/pages/readDATA.html
+++ /dev/null
@@ -1,59 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-readDATA
-
-
-
-
-<-- Back
-
readDATA
-Reads UDP Socket and interprets data
-
-
Inputs
-
-
location: Either an opened UDP Socket or integer port number
-
-
-
Outputs
-If data is X-Plane data format:
-
-
data: Matlab X-Plane DATA Structure
-
.h: Header array containing header numbers corresponding to values in the X-Plane UDP Data screen.
-
.d: 2-D Data array. Each row contains eight values corresponding to the header value (.h(1) corresponds to .d(1,:))
-
.raw: raw UDP data array received by readUDP
-
-If data is matlab structure:
-
-
data: Matlab Structure. Raw udp data saved to data.raw
-
-If data is any other format:
-
-
data: Matlab Structure containing one field
-
.raw & .d: raw UDP data array received by readUDP
-
-
-
Use
-1. import XPlaneConnect.*;
-2. socket = openUDP(49005);
-3. data = readDATA(socket);
-4. status = closeUDP(socket);
-
-or
-
-1. import XPlaneConnect.*;
-2. data = readDATA(49005);
-
-
Note
-NOTE: sending in a port number instead of an opened socket clears the UDP buffer. This only works if the data is being sent at a fast rate. Sending in a UDP Socket reads the first packet in the buffer.
-
-
Change Log
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-09/10/13: [CT] Updated to receive UDP socket or port number
-06/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/readUDP.html b/MATLAB/pages/readUDP.html
deleted file mode 100644
index 8a636f2..0000000
--- a/MATLAB/pages/readUDP.html
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-readUDP
-
-
-
-
-<-- Back
-
readUDP
-Read Array from UDP Socket
-
-
Inputs
-
-
location: Either an opened UDP Socket or integer port number
-
-
-
Outputs
-
-
data: UDP uint8 Array. Equal to -998 in the case of an error.
-
-
-
Use
-1. import XPlaneConnect.*;
-2. socket = openUDP(49005);
-3. data = readUDP(socket);
-4. status = closeUDP(socket);
-
-or
-
-1. import XPlaneConnect.*;
-2. data = readUDP(49005);
-
-
Note
-NOTE: sending in a port number instead of an opened socket clears the UDP buffer. This only works if the data is being sent at a fast rate. Sending in a UDP Socket reads the first packet in the buffer.
-
-
Change Log
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-09/08/13: [CT] Added option for either UDP Socket or port number input
-06/10/13: [CT] Code created
-<-- Back
\ No newline at end of file
diff --git a/MATLAB/pages/requestDREF.html b/MATLAB/pages/requestDREF.html
deleted file mode 100644
index ff822de..0000000
--- a/MATLAB/pages/requestDREF.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-requestDREF
-
-
-
-
-<-- Back
-
requestDREF
-
-
Inputs
-
-
DREFArray: Cell Array of DataRefs to be requested
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin
-
-
-
Outputs
-
-
status: If there was an error. status<0 means there was an error.
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-06/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/selectDATA.html b/MATLAB/pages/selectDATA.html
deleted file mode 100644
index 2a9e3e0..0000000
--- a/MATLAB/pages/selectDATA.html
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-selectDATA
-
-
-
-
-<-- Back
-
selectDATA
-Choose specific X-Plane parameters to be send over UDP
-
-
Inputs
-
-
index: An array of the values that to be sent. Corresponds to the numbers on the XPlane Output screen (ACTUAL NAME?)
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. Status<0 means there was an error.
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-04/18/14: [CT] V0.2: Added Versioning
-06/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/sendCTRL.html b/MATLAB/pages/sendCTRL.html
deleted file mode 100644
index 9bb501a..0000000
--- a/MATLAB/pages/sendCTRL.html
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-sendCTRL
-
-
-
-
-<-- Back
-
sendCTRL
-Send position and orientation update command to X-Plane over UDP. This requires the X-Plane Connect Plugin to be running
-
-
Inputs
-
-
ctrl: Array of 6 values where:
-
-
ctrl(1) Latitudinal Stick [-1,1]
-
ctrl(2) Longitudinal Stick [-1,1]
-
ctrl(3) Pedal [-1, 1]
-
ctrl(4) Throttle [-1, 1]
-
ctrl(5) Gear (0=up, 1=down)
-
ctrl(6) Flaps [0, 1]
-
-
aircraft number (optional): 0=own aircraft
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. status<0 means there was an error.
-
-
-
Use
-1. import XPlaneConnect.*;
-2. ctrl = [0, 0, 0, 0.8, 0, 0];
-3. status = sendCTRL(ctrl); % Set position of own aircraft
-4. status2 = sendCTRL(ctrl,1); % Set position of aircraft 1
-
-
Change Log
-10/02/14: [CT] V0.9 Updated to use new xpcPlugin
-09/26/14: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/sendDATA.html b/MATLAB/pages/sendDATA.html
deleted file mode 100644
index 02df49d..0000000
--- a/MATLAB/pages/sendDATA.html
+++ /dev/null
@@ -1,46 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-sendDATA
-
-
-
-
-<-- Back
-
sendDATA
-Send X-Plane formatted DATA over UDP. This function is used to change one of the parameters listed in the x-plane udp data screen (see http://www.nuclearprojects.com/xplane/images/xp_datainout.jpg)
-
-
Inputs
-
-
data: X-Plane formatted data. Is a matlab structure with the following fields:
-
-
.h: Header array containing header numbers corresponding to values in the X-Plane UDP Data screen.
-
.d: 2-D Data array. Each row contains eight values corresponding to the header value (.h(1) corresponds to .d(1,:))
-
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. Status=1 means there was an error.
-
-
-
Use
-1. import XPlaneConnect.*;
-2. data = struct('h',14,'d',[1,-998,-998,-998,-998,-998,-998,-998]); %Set Gear
-3. %Send the data array to port 49005 on the computer at IP address 172.0.100.54.
-4. status = sendDATA(data, '172.0.100.54', 49005);
-
-
note
-Note: send the value -998 to not overwrite that parameter. That is, if -998 is sent, the parameter will stay at the current X-Plane value
-
-
Change Log
-10/01/14: [CT] V0.9: updated to function with new xpcPlugin
-06/10/13: [CT] First created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/sendDREF.html b/MATLAB/pages/sendDREF.html
deleted file mode 100644
index c5dd742..0000000
--- a/MATLAB/pages/sendDREF.html
+++ /dev/null
@@ -1,48 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-sendCTRL
-
-
-
-
-<-- Back
-
sendCTRL
-Send position and orientation update command to X-Plane over UDP. This requires the X-Plane Connect Plugin to be running
-
-
Inputs
-
-
-
data(1) Latitudinal Stick [-1,1]
-
data(2) Longitudinal Stick [-1,1]
-
data(3) Pedal [-1, 1]
-
data(4) Throttle [-1, 1]
-
data(5) Gear (0=up, 1=down)
-
data(6) Flaps [0, 1]
-
-
aircraft number (optional): 0=own aircraft
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. status<0 means there was an error.
-10/02/14: [CT] V0.9: Updated to use new xpcPlugin
-06/10/13: [CT] Code created
-
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/sendPOSI.html b/MATLAB/pages/sendPOSI.html
deleted file mode 100644
index 4642b96..0000000
--- a/MATLAB/pages/sendPOSI.html
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-sendDREF
-
-
-
-
-<-- Back
-
sendPosition
-Send position and orientation update command to X-Plane over UDP. This requires the X-Plane Connect Plugin to be running
-
-
Inputs
-
-
data: Array of 6 values where:
-
-
data(1) is the aircraft's Latitude (degrees)
-
data(2) is the aircraft's Longitude (degrees)
-
data(3) is the aircraft's altitude (meters above sea level)
-
data(4) is the aircraft's roll angle (degrees)
-
data(5) is the aircraft's pitch angle (degrees)
-
data(6) is the aircraft's heading/yaw angle (degrees)
-
-
aircraft number (optional): 0=own aircraft
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. status<0 means there was an error.
-
-
-
Use
-1. import XPlaneConnect.*;
-2. latlon = [37.4185718,-121.935565]; %Lat,lon of NASA Ames Research Center
-3. alt = 500; %meters above sea level
-4. orient = [0,20,180]; %Orientation (roll,pitch,yaw/heading). 20 degrees yaw, heading south
-5. status = sendPOSI([latlon,alt,orient]); % Set position of own aircraft
-6. status2 = sendPOSI([[latlon(1)+0.005,latlon(2)],alt,orient],1); % Set position of aircraft 1
-
-
Change Log
-10/02/14: [CT] V0.9 Updated to use new xpcPlugin
-06/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/sendSTRU.html b/MATLAB/pages/sendSTRU.html
deleted file mode 100644
index 7ec9b57..0000000
--- a/MATLAB/pages/sendSTRU.html
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-sendSTRU
-
-
-
-
-<-- Back
-
sendSTRU
-Send a MATLAB structure over UDP
-
-
Inputs
-
-
stru: A MATLAB structure
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin
-
-
-
Outputs
-
-
status: If there was an error. Status<0 means there was an error.
-
-
-
Use
-1. import XPlaneConnect.*;
-2. data = struct('a',[1:20],'b',1.853,'name','Example Structure');
-3. #Send the data structure to port 49005 on the computer at IP address 172.0.100.54
-4. status = sendSTRU( data, '172.0.100.54', 49005 );
-
-
Change Log
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-08/01/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/sendUDP.html b/MATLAB/pages/sendUDP.html
deleted file mode 100644
index 92e4ae4..0000000
--- a/MATLAB/pages/sendUDP.html
+++ /dev/null
@@ -1,39 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-sendUDP
-
-
-
-
-<-- Back
-
sendUDP
-Send an one dimensional array of type uint8 data over an UDP connection
-
-
Inputs
-
-
data: 1-D array of type uint8 data to be sent
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. Status=1 means there was an error.
-
-
-
Use
-1. import XPlaneConnect.*;
-2. data = uint8([1:20]);
-3. #Send the data array to port 49005 on the computer at IP address 172.0.100.54.
-4. status = sendUDP( data, '172.0.100.54', 49005 );
-
-
Change Log
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-06/10/13: [CT] Code created
-<-- Back
-
-
-
\ No newline at end of file
diff --git a/MATLAB/pages/setConn.html b/MATLAB/pages/setConn.html
deleted file mode 100644
index 568f929..0000000
--- a/MATLAB/pages/setConn.html
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
-
-
- XPlaneConnect Toolbox-setConn
-
-
-
-
-<-- Back
-
setConn
-Send a command to set up the port where you will receive data on this computer.
-
-
Inputs
-
-
Receiving Port: Port that data will be sent to in the future for this connection
-
IP Address (optional): IP Address of the machine that will receive the data as a character array. Default is '127.0.0.1' (local machine)
-
port (optional): Port on the receiving machine where the data will be sent. Default is 49009 (XPlaneConnect). In general use 49009 to send to the plugin and 49005 to send to the x-plane udp
-
-
-
Outputs
-
-
status: If there was an error. status<0 means there was an error.
-
-
-
Use
-1. import XPlaneConnect.*
-2. status = setConn(49011);
-
-
Change Log
-10/02/14: [CT] V0.9: Updated to work with updated xpcPlugin
-04/21/14: [CT] V0.2: First Version