Added getPOSI and getCTRL support to the C client.
This commit is contained in:
@@ -521,6 +521,38 @@ int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**** POSI functions ****/
|
/**** 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)
|
int sendPOSI(XPCSocket sock, float values[], int size, char ac)
|
||||||
{
|
{
|
||||||
// Validate input
|
// Validate input
|
||||||
@@ -565,6 +597,41 @@ int sendPOSI(XPCSocket sock, float values[], int size, char ac)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/**** CTRL functions ****/
|
/**** 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)
|
int sendCTRL(XPCSocket sock, float values[], int size, char ac)
|
||||||
{
|
{
|
||||||
// Validate input
|
// Validate input
|
||||||
|
|||||||
@@ -196,6 +196,14 @@ int getDREFs(XPCSocket sock, const char* drefs[], float* values[], unsigned char
|
|||||||
|
|
||||||
// Position
|
// 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.
|
/// Sets the position and orientation of the specified aircraft.
|
||||||
///
|
///
|
||||||
/// \param sock The socket to use to send the command.
|
/// \param sock The socket to use to send the command.
|
||||||
@@ -209,6 +217,16 @@ int sendPOSI(XPCSocket sock, float values[], int size, char ac);
|
|||||||
|
|
||||||
// Controls
|
// 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.
|
/// Sets the control surfaces of the specified aircraft.
|
||||||
///
|
///
|
||||||
/// \param sock The socket to use to send the command.
|
/// \param sock The socket to use to send the command.
|
||||||
|
|||||||
@@ -38,6 +38,33 @@ int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[
|
|||||||
return compareArray(expected, actual, 7);
|
return compareArray(expected, actual, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int doGETCTest(float values[7], int ac, float expected[7])
|
||||||
|
{
|
||||||
|
// Execute Test
|
||||||
|
float actual[7];
|
||||||
|
XPCSocket sock = openUDP(IP);
|
||||||
|
int result = sendCTRL(sock, values, 7, ac);
|
||||||
|
if (result >= 0)
|
||||||
|
{
|
||||||
|
result = getCTRL(sock, actual, ac);
|
||||||
|
}
|
||||||
|
closeUDP(sock);
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test values
|
||||||
|
for (int i = 0; i < 7; ++i)
|
||||||
|
{
|
||||||
|
if (fabs(expected[i] - actual[i]) > 1e-4)
|
||||||
|
{
|
||||||
|
return -10 - i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int basicCTRLTest(char** drefs, int ac)
|
int basicCTRLTest(char** drefs, int ac)
|
||||||
{
|
{
|
||||||
// Set control surfaces to known state.
|
// Set control surfaces to known state.
|
||||||
@@ -146,4 +173,16 @@ int testCTRL_Speedbrakes()
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int testGETC()
|
||||||
|
{
|
||||||
|
float CTRL[7] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F, -1.5F };
|
||||||
|
return doGETCTest(CTRL, 0, CTRL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int testGETC_NonPlayer()
|
||||||
|
{
|
||||||
|
float CTRL[7] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F, -1.5F };
|
||||||
|
return doGETCTest(CTRL, 2, CTRL);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -40,6 +40,33 @@ int doPOSITest(char* drefs[7], float values[], int size, int ac, float expected[
|
|||||||
return compareArray(expected, actual, 7);
|
return compareArray(expected, actual, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int doGETPTest(float values[7], int ac, float expected[7])
|
||||||
|
{
|
||||||
|
// Execute Test
|
||||||
|
float actual[7];
|
||||||
|
XPCSocket sock = openUDP(IP);
|
||||||
|
int result = sendPOSI(sock, values, 7, ac);
|
||||||
|
if (result >= 0)
|
||||||
|
{
|
||||||
|
result = getPOSI(sock, actual, ac);
|
||||||
|
}
|
||||||
|
closeUDP(sock);
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test values
|
||||||
|
for (int i = 0; i < 7; ++i)
|
||||||
|
{
|
||||||
|
if (fabs(expected[i] - actual[i]) > 1e-4)
|
||||||
|
{
|
||||||
|
return -10 - i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int basicPOSITest(char** drefs, int ac)
|
int basicPOSITest(char** drefs, int ac)
|
||||||
{
|
{
|
||||||
// Set psoition and initial orientation
|
// Set psoition and initial orientation
|
||||||
@@ -116,6 +143,16 @@ int testPOSI_NonPlayer()
|
|||||||
return basicPOSITest(drefs, 1);
|
return basicPOSITest(drefs, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int testGetPOSI_Player()
|
||||||
|
{
|
||||||
|
float POSI[7] = { 37.524F, -122.06899F, 2500, 0, 0, 0, 1 };
|
||||||
|
doGETPTest(POSI, 0, POSI);
|
||||||
|
}
|
||||||
|
|
||||||
|
int testGetPOSI_NonPlayer()
|
||||||
|
{
|
||||||
|
float POSI[7] = { 37.624F, -122.06899F, 1500, 0, 0, 0, 1 };
|
||||||
|
doGETPTest(POSI, 3, POSI);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -40,9 +40,13 @@ int main(int argc, const char * argv[])
|
|||||||
runTest(testCTRL_Player, "CTRL (player)");
|
runTest(testCTRL_Player, "CTRL (player)");
|
||||||
runTest(testCTRL_NonPlayer, "CTRL (non-player)");
|
runTest(testCTRL_NonPlayer, "CTRL (non-player)");
|
||||||
runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)");
|
runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)");
|
||||||
|
runTest(testGETC, "GETC (player)");
|
||||||
|
runTest(testGETC_NonPlayer, "GETC (Non-player)");
|
||||||
// POSI
|
// POSI
|
||||||
runTest(testPOSI_Player, "POSI (player)");
|
runTest(testPOSI_Player, "POSI (player)");
|
||||||
runTest(testPOSI_NonPlayer, "POSI (non-player)");
|
runTest(testPOSI_NonPlayer, "POSI (non-player)");
|
||||||
|
runTest(testGetPOSI_Player, "GETP (player)");
|
||||||
|
runTest(testGetPOSI_NonPlayer, "GETP (non-player)");
|
||||||
// Data
|
// Data
|
||||||
runTest(testDATA, "DATA");
|
runTest(testDATA, "DATA");
|
||||||
// Text
|
// Text
|
||||||
|
|||||||
@@ -530,7 +530,10 @@ namespace XPC
|
|||||||
*((float*)(response + 18)) = DataManager::GetFloat(DREF_Pitch, aircraft);
|
*((float*)(response + 18)) = DataManager::GetFloat(DREF_Pitch, aircraft);
|
||||||
*((float*)(response + 22)) = DataManager::GetFloat(DREF_Roll, aircraft);
|
*((float*)(response + 22)) = DataManager::GetFloat(DREF_Roll, aircraft);
|
||||||
*((float*)(response + 26)) = DataManager::GetFloat(DREF_HeadingTrue, aircraft);
|
*((float*)(response + 26)) = DataManager::GetFloat(DREF_HeadingTrue, aircraft);
|
||||||
*((float*)(response + 30)) = (float)DataManager::GetInt(DREF_GearHandle, aircraft);
|
|
||||||
|
float gear[10];
|
||||||
|
DataManager::GetFloatArray(DREF_GearDeploy, gear, 10, aircraft);
|
||||||
|
*((float*)(response + 30)) = gear[0];
|
||||||
|
|
||||||
sock->SendTo(response, 34, &connection.addr);
|
sock->SendTo(response, 34, &connection.addr);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user