Added getTERR function
Also corrected minor typos in comments.
This commit is contained in:
@@ -185,7 +185,7 @@ int sendUDP(XPCSocket sock, char buffer[], int len)
|
|||||||
/// \param sock The socket to read from.
|
/// \param sock The socket to read from.
|
||||||
/// \param buffer A pointer to the location to store the data.
|
/// \param buffer A pointer to the location to store the data.
|
||||||
/// \param len The number of bytes to read.
|
/// \param len The number of bytes to read.
|
||||||
/// \returns If an error occurs, a negative number. Otehrwise, the number of bytes read.
|
/// \returns If an error occurs, a negative number. Otherwise, the number of bytes read.
|
||||||
int readUDP(XPCSocket sock, char buffer[], int len)
|
int readUDP(XPCSocket sock, char buffer[], int len)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -378,9 +378,9 @@ int readDATA(XPCSocket sock, float data[][9], int rows)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**** DREF functions ****/
|
/**** DREF functions ****/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
int sendDREF(XPCSocket sock, const char* dref, float value[], int size)
|
int sendDREF(XPCSocket sock, const char* dref, float values[], int size)
|
||||||
{
|
{
|
||||||
return sendDREFs(sock, &dref, &value, &size, 1);
|
return sendDREFs(sock, &dref, &values, &size, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[], int count)
|
int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[], int count)
|
||||||
@@ -516,7 +516,7 @@ int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char
|
|||||||
int result = sendDREFRequest(sock, drefs, count);
|
int result = sendDREFRequest(sock, drefs, count);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
{
|
{
|
||||||
// A error ocurred while sending.
|
// An error ocurred while sending.
|
||||||
// sendDREFRequest will print an error message, so just return.
|
// sendDREFRequest will print an error message, so just return.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -524,7 +524,7 @@ int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char
|
|||||||
// Read Response
|
// Read Response
|
||||||
if (getDREFResponse(sock, values, count, sizes) < 0)
|
if (getDREFResponse(sock, values, count, sizes) < 0)
|
||||||
{
|
{
|
||||||
// A error ocurred while reading the response.
|
// An error ocurred while reading the response.
|
||||||
// getDREFResponse will print an error message, so just return.
|
// getDREFResponse will print an error message, so just return.
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
@@ -640,6 +640,83 @@ int sendPOSI(XPCSocket sock, double values[], int size, char ac)
|
|||||||
/**** End POSI functions ****/
|
/**** End POSI functions ****/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**** TERR functions ****/
|
||||||
|
/*****************************************************************************/
|
||||||
|
int sendTERRRequest(XPCSocket sock, double posi[3], char ac)
|
||||||
|
{
|
||||||
|
// Setup send command
|
||||||
|
char buffer[30] = "GETT";
|
||||||
|
buffer[5] = ac;
|
||||||
|
memcpy(&buffer[6], posi, 3 * sizeof(double));
|
||||||
|
|
||||||
|
// Send command
|
||||||
|
if (sendUDP(sock, buffer, 30) < 0)
|
||||||
|
{
|
||||||
|
printError("getTERR", "Failed to send command.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTERRResponse(XPCSocket sock, double values[11], char ac)
|
||||||
|
{
|
||||||
|
// Get response
|
||||||
|
char readBuffer[62];
|
||||||
|
int readResult = readUDP(sock, readBuffer, 62);
|
||||||
|
if (readResult < 0)
|
||||||
|
{
|
||||||
|
printError("getTERR", "Failed to read response.");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
if (readResult != 62)
|
||||||
|
{
|
||||||
|
printError("getTERR", "Unexpected response length.");
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy response into outputs
|
||||||
|
float f[8];
|
||||||
|
ac = readBuffer[5];
|
||||||
|
memcpy(values, readBuffer + 6, 3 * sizeof(double));
|
||||||
|
memcpy(f, readBuffer + 30, 8 * sizeof(float));
|
||||||
|
values[ 3] = (double)f[0];
|
||||||
|
values[ 4] = (double)f[1];
|
||||||
|
values[ 5] = (double)f[2];
|
||||||
|
values[ 6] = (double)f[3];
|
||||||
|
values[ 7] = (double)f[4];
|
||||||
|
values[ 8] = (double)f[5];
|
||||||
|
values[ 9] = (double)f[6];
|
||||||
|
values[10] = (double)f[7];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTERR(XPCSocket sock, double posi[3], double values[11], char ac)
|
||||||
|
{
|
||||||
|
// Send Command
|
||||||
|
int result = sendTERRRequest(sock, posi, ac);
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
// An error ocurred while sending.
|
||||||
|
// sendTERRRequest will print an error message, so just return.
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read Response
|
||||||
|
result = getTERRResponse(sock, values, ac);
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
// An error ocurred while reading the response.
|
||||||
|
// getTERRResponse will print an error message, so just return.
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/*****************************************************************************/
|
||||||
|
/**** End TERR functions ****/
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**** CTRL functions ****/
|
/**** CTRL functions ****/
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ int setCONN(XPCSocket* sock, unsigned short port);
|
|||||||
///
|
///
|
||||||
/// \param sock The socket to use to send the command.
|
/// \param sock The socket to use to send the command.
|
||||||
/// \param pause 0 to unpause the sim; 1 to pause, 100:119 to pause a/c 0:19, 200:219 to unpause a/c 0:19.
|
/// \param pause 0 to unpause the sim; 1 to pause, 100:119 to pause a/c 0:19, 200:219 to unpause a/c 0:19.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int pauseSim(XPCSocket sock, char pause);
|
int pauseSim(XPCSocket sock, char pause);
|
||||||
|
|
||||||
// X-Plane UDP DATA
|
// X-Plane UDP DATA
|
||||||
@@ -122,7 +122,7 @@ int pauseSim(XPCSocket sock, char pause);
|
|||||||
///
|
///
|
||||||
/// \details This command is compatible with the X-Plane data API.
|
/// \details This command is compatible with the X-Plane data API.
|
||||||
/// \param sock The socket to use to send the command.
|
/// \param sock The socket to use to send the command.
|
||||||
/// \param data A 2D array of data rows to read into.
|
/// \param data A 2D array of data rows to read into.
|
||||||
/// \param rows The number of rows in dataRef.
|
/// \param rows The number of rows in dataRef.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int readDATA(XPCSocket sock, float data[][9], int rows);
|
int readDATA(XPCSocket sock, float data[][9], int rows);
|
||||||
@@ -131,7 +131,7 @@ int readDATA(XPCSocket sock, float data[][9], int rows);
|
|||||||
///
|
///
|
||||||
/// \details This command is compatible with the X-Plane data API.
|
/// \details This command is compatible with the X-Plane data API.
|
||||||
/// \param sock The socket to use to send the command.
|
/// \param sock The socket to use to send the command.
|
||||||
/// \param data A 2D array of data rows to send.
|
/// \param data A 2D array of data rows to send.
|
||||||
/// \param rows The number of rows in dataRef.
|
/// \param rows The number of rows in dataRef.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int sendDATA(XPCSocket sock, float data[][9], int rows);
|
int sendDATA(XPCSocket sock, float data[][9], int rows);
|
||||||
@@ -144,12 +144,12 @@ int sendDATA(XPCSocket sock, float data[][9], int rows);
|
|||||||
/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
|
/// 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 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.
|
/// 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 sock The socket to use to send the command.
|
||||||
/// \param dref The name of the dataref to set.
|
/// \param dref The name of the dataref to set.
|
||||||
/// \param value An array of values representing the data to set.
|
/// \param values An array of values representing the data to set.
|
||||||
/// \param size The number of elements in values.
|
/// \param size The number of elements in values.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int sendDREF(XPCSocket sock, const char* dref, float value[], int size);
|
int sendDREF(XPCSocket sock, const char* dref, float values[], int size);
|
||||||
|
|
||||||
/// Sets the specified datarefs to the specified values.
|
/// Sets the specified datarefs to the specified values.
|
||||||
///
|
///
|
||||||
@@ -159,7 +159,7 @@ int sendDREF(XPCSocket sock, const char* dref, float value[], int size);
|
|||||||
/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
|
/// 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 sock The socket to use to send the command.
|
||||||
/// \param drefs The names of the datarefs to set.
|
/// \param drefs The names of the datarefs to set.
|
||||||
/// \param values A multidimensional array containing the values for each dataref to set.
|
/// \param values A 2D array array containing the values for each dataref to set.
|
||||||
/// \param sizes The number of elements in each array in values
|
/// \param sizes The number of elements in each array in values
|
||||||
/// \param count The number of datarefs being set.
|
/// \param count The number of datarefs being set.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
@@ -173,13 +173,13 @@ int sendDREFs(XPCSocket sock, const char* drefs[], float* values[], int sizes[],
|
|||||||
/// the type described on the wiki. This doesn't cause any data loss for most datarefs.
|
/// 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 sock The socket to use to send the command.
|
||||||
/// \param dref The name of the dataref to get.
|
/// \param dref The name of the dataref to get.
|
||||||
/// \param values The array in which the value of the dataref will be stored.
|
/// \param values The array in which the values of the dataref will be stored.
|
||||||
/// \param size The number of elements in values. The actual number of elements copied in will
|
/// \param size The number of elements in values. The actual number of elements copied in will
|
||||||
/// be set when the function returns.
|
/// be set when the function returns.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int getDREF(XPCSocket sock, const char* dref, float values[], int* size);
|
int getDREF(XPCSocket sock, const char* dref, float values[], int* size);
|
||||||
|
|
||||||
/// Gets the value of the specified dataref.
|
/// Gets the values of the specified datarefs.
|
||||||
///
|
///
|
||||||
/// \details dref names and their associated data types can be found on the XPSDK wiki at
|
/// \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
|
/// http://www.xsquawkbox.net/xpsdk/docs/DataRefs.html. The size of values should match
|
||||||
@@ -189,7 +189,7 @@ int getDREF(XPCSocket sock, const char* dref, float values[], int* size);
|
|||||||
/// \param drefs The names of the datarefs to get.
|
/// \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 values A 2D array in which the values of the datarefs will be stored.
|
||||||
/// \param count The number of datarefs being requested.
|
/// \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
|
/// \param sizes 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.
|
/// to the actual number of elements copied in for that row.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char count, int sizes[]);
|
int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char count, int sizes[]);
|
||||||
@@ -216,6 +216,24 @@ int getPOSI(XPCSocket sock, double values[7], char ac);
|
|||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int sendPOSI(XPCSocket sock, double values[], int size, char ac);
|
int sendPOSI(XPCSocket sock, double values[], int size, char ac);
|
||||||
|
|
||||||
|
// Terrain
|
||||||
|
|
||||||
|
/// Gets the terrain information of the specified aircraft.
|
||||||
|
///
|
||||||
|
/// \param sock The socket to use to send the command.
|
||||||
|
/// \param posi A double array representing position data about the aircraft. The format of values is
|
||||||
|
/// [Lat, Lon, Alt].
|
||||||
|
/// -998 used for [Lat, Lon, Alt] to request terrain info at the current aircraft position.
|
||||||
|
/// \param values A double array with the information for the terrain output. The format of values is
|
||||||
|
/// [Lat, Lon, Alt, Nx, Ny, Nz, Vx, Vy, Vz, wet, result]. The first three are for output of
|
||||||
|
/// the Lat and Lon of the aircraft with the terrain height directly below. The next three
|
||||||
|
/// represent the terrain normal. The next three represent the velocity of the terrain.
|
||||||
|
/// The wet variable is 0.0 if the terrain is dry and 1.0 if wet.
|
||||||
|
/// The last output is the terrain probe result parameter.
|
||||||
|
/// \param ac The aircraft number to get the terrain data of. 0 for the main/user's aircraft.
|
||||||
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
|
int getTERR(XPCSocket sock, double posi[3], double values[11], char ac);
|
||||||
|
|
||||||
// Controls
|
// Controls
|
||||||
|
|
||||||
/// Gets the control surface information for the specified aircraft.
|
/// Gets the control surface information for the specified aircraft.
|
||||||
@@ -224,7 +242,7 @@ int sendPOSI(XPCSocket sock, double values[], int size, char ac);
|
|||||||
/// \param values An array to store the position information returned by the
|
/// \param values An array to store the position information returned by the
|
||||||
/// plugin. The format of values is [Elevator, Aileron, Rudder,
|
/// plugin. The format of values is [Elevator, Aileron, Rudder,
|
||||||
/// Throttle, Gear, Flaps, Speed Brakes]
|
/// Throttle, Gear, Flaps, Speed Brakes]
|
||||||
/// \param ac The aircraft to set the control surfaces of. 0 is the main/user's aircraft.
|
/// \param ac The aircraft to get the control surfaces of. 0 is the main/user's aircraft.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
int getCTRL(XPCSocket sock, float values[7], char ac);
|
int getCTRL(XPCSocket sock, float values[7], char ac);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user