Merge branch 'master' into develop

# Conflicts:
#	xpcPlugin/XPlaneConnect/mac.xpl
#	xpcPlugin/xpcPlugin.xcodeproj/project.pbxproj
This commit is contained in:
Chris Teubert
2016-02-29 12:48:30 -08:00
parent 8d5af7e47e
commit cfdd183214
100 changed files with 4224 additions and 1912 deletions

View File

@@ -117,7 +117,7 @@ XPCSocket aopenUDP(const char *xpIP, unsigned short xpPort, unsigned short port)
#else
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 1000;
timeout.tv_usec = 250000;
#endif
if (setsockopt(sock.sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout)) < 0)
{
@@ -368,32 +368,46 @@ int readDATA(XPCSocket sock, float data[][9], int rows)
/*****************************************************************************/
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);
return sendDREFs(sock, &dref, &value, &size, 1);
}
// Copy values to buffer
buffer[6 + drefLen] = (unsigned char)size;
memcpy(buffer + 7 + drefLen, value, size * sizeof(float));
int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[], int count)
{
// Setup command
// Max size is technically unlimited.
unsigned char buffer[65536] = "DREF";
int pos = 5;
for (int i = 0; i < count; ++i)
{
int drefLen = strnlen(drefs[i], 256);
if (pos + drefLen + sizes[i] * 4 + 2 > 65536)
{
printError("sendDREF", "About to overrun the send buffer!");
return -4;
}
if (drefLen > 255)
{
printError("sendDREF", "dref %d is too long. Must be less than 256 characters.", i);
return -1;
}
if (sizes[i] > 255)
{
printError("sendDREF", "size %d is too big. Must be less than 256.", i);
return -2;
}
// Copy dref to buffer
buffer[pos++] = (unsigned char)drefLen;
memcpy(buffer + pos, drefs[i], drefLen);
pos += drefLen;
// Copy values to buffer
buffer[pos++] = (unsigned char)sizes[i];
memcpy(buffer + pos, values[i], sizes[i] * sizeof(float));
pos += sizes[i] * sizeof(float);
}
// Send command
if (sendUDP(sock, buffer, len) < 0)
if (sendUDP(sock, buffer, pos) < 0)
{
printError("setDREF", "Failed to send command");
return -3;
@@ -508,6 +522,38 @@ int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char
/*****************************************************************************/
/**** POSI functions ****/
/*****************************************************************************/
int getPOSI(XPCSocket sock, float values[7], char ac)
{
// Setup send command
unsigned char buffer[6] = "GETP";
buffer[5] = ac;
// Send command
if (sendUDP(sock, buffer, 6) < 0)
{
printError("getPOSI", "Failed to send command.");
return -1;
}
// Get response
unsigned char readBuffer[34];
int readResult = readUDP(sock, readBuffer, 34);
if (readResult < 0)
{
printError("getPOSI", "Failed to read response.");
return -2;
}
if (readResult != 34)
{
printError("getPOSI", "Unexpected response length.");
return -3;
}
// Copy response into values
memcpy(values, readBuffer + 6, 7 * sizeof(float));
return 0;
}
int sendPOSI(XPCSocket sock, float values[], int size, char ac)
{
// Validate input
@@ -552,6 +598,41 @@ int sendPOSI(XPCSocket sock, float values[], int size, char ac)
/*****************************************************************************/
/**** CTRL functions ****/
/*****************************************************************************/
int getCTRL(XPCSocket sock, float values[7], char ac)
{
// Setup send command
unsigned char buffer[6] = "GETC";
buffer[5] = ac;
// Send command
if (sendUDP(sock, buffer, 6) < 0)
{
printError("getCTRL", "Failed to send command.");
return -1;
}
// Get response
unsigned char readBuffer[31];
int readResult = readUDP(sock, readBuffer, 31);
if (readResult < 0)
{
printError("getCTRL", "Failed to read response.");
return -2;
}
if (readResult != 31)
{
printError("getCTRL", "Unexpected response length.");
return -3;
}
// Copy response into values
memcpy(values, readBuffer + 5, 4 * sizeof(float));
values[4] = readBuffer[21];
values[5] = *((float*)(readBuffer + 22));
values[6] = *((float*)(readBuffer + 27));
return 0;
}
int sendCTRL(XPCSocket sock, float values[], int size, char ac)
{
// Validate input
@@ -672,7 +753,7 @@ int sendWYPT(XPCSocket sock, WYPT_OP op, float points[], int count)
memcpy(buffer + 7, points, ptLen);
// Send Command
if (sendUDP(sock, buffer, 40) < 0)
if (sendUDP(sock, buffer, 7 + 12 * count) < 0)
{
printError("sendWYPT", "Failed to send command");
return -2;
@@ -682,3 +763,31 @@ int sendWYPT(XPCSocket sock, WYPT_OP op, float points[], int count)
/*****************************************************************************/
/**** End Drawing functions ****/
/*****************************************************************************/
/*****************************************************************************/
/**** View functions ****/
/*****************************************************************************/
int sendVIEW(XPCSocket sock, VIEW_TYPE view)
{
// Validate Input
if (view < XPC_VIEW_FORWARDS || view > XPC_VIEW_FULLSCREENNOHUD)
{
printError("sendVIEW", "Unrecognized view");
return -1;
}
// Setup Command
char buffer[9] = "VIEW";
*((int*)(buffer + 5)) = view;
// Send Command
if (sendUDP(sock, buffer, 9) < 0)
{
printError("sendVIEW", "Failed to send command");
return -2;
}
return 0;
}
/*****************************************************************************/
/**** End View functions ****/
/*****************************************************************************/

View File

@@ -61,6 +61,23 @@ typedef enum
XPC_WYPT_DEL = 2,
XPC_WYPT_CLR = 3
} WYPT_OP;
typedef enum
{
XPC_VIEW_FORWARDS = 73,
XPC_VIEW_DOWN,
XPC_VIEW_LEFT,
XPC_VIEW_RIGHT,
XPC_VIEW_BACK,
XPC_VIEW_TOWER,
XPC_VIEW_RUNWAY,
XPC_VIEW_CHASE,
XPC_VIEW_FOLLOW,
XPC_VIEW_FOLLOWWITHPANEL,
XPC_VIEW_SPOT,
XPC_VIEW_FULLSCREENWITHHUD,
XPC_VIEW_FULLSCREENNOHUD,
} VIEW_TYPE;
// Low Level UDP Functions
@@ -127,13 +144,27 @@ int sendDATA(XPCSocket sock, float data[][9], int rows);
/// 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.
/// \param sock The socket to use to send the command.
/// \param dref The name of the dataref to set.
/// \param value 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);
/// Sets the specified datarefs to the specified values.
///
/// \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 set.
/// \param values A multidimensional array containing the values for each dataref to set.
/// \param sizes The number of elements in each array in values
/// \param count The number of datarefs being set.
/// \returns 0 if successful, otherwise a negative value.
int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[], int count);
/// Gets the value of the specified dataref.
///
/// \details dref names and their associated data types can be found on the XPSDK wiki at
@@ -165,6 +196,14 @@ int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char
// Position
/// Gets the position and orientation of the specified aircraft.
///
/// \param sock The socket used to send the command and receive the response.
/// \param values An array to store the position information returned by the
/// plugin. The format of values is [Lat, Lon, Alt, Pitch, Roll, Yaw, Gear]
/// \returns 0 if successful, otherwise a negative value.
int getPOSI(XPCSocket sock, float values[7], char ac);
/// Sets the position and orientation of the specified aircraft.
///
/// \param sock The socket to use to send the command.
@@ -178,6 +217,16 @@ int sendPOSI(XPCSocket sock, float values[], int size, char ac);
// Controls
/// Gets the control surface information for the specified aircraft.
///
/// \param sock The socket used to send the command and receive the response.
/// \param values An array to store the position information returned by the
/// plugin. The format of values is [Elevator, Aileron, Rudder,
/// Throttle, Gear, Flaps, Speed Brakes]
/// \param ac The aircraft to set the control surfaces of. 0 is the main/player aircraft.
/// \returns 0 if successful, otherwise a negative value.
int getCTRL(XPCSocket sock, float values[7], char ac);
/// Sets the control surfaces of the specified aircraft.
///
/// \param sock The socket to use to send the command.
@@ -200,6 +249,13 @@ int sendCTRL(XPCSocket sock, float values[], int size, char ac);
/// \returns 0 if successful, otherwise a negative value.
int sendTEXT(XPCSocket sock, char* msg, int x, int y);
/// Sets the camera view in X-Plane.
///
/// \param sock The socket to use to send the command.
/// \param view The view to use.
/// \returns 0 if successful, otherwise a negative value.
int sendVIEW(XPCSocket sock, VIEW_TYPE view);
/// Adds, removes, or clears a set of waypoints. If the command is clear, the points are ignored
/// and all points are removed.
///