Added support for setting speed brakes to C client.
This commit is contained in:
@@ -560,13 +560,13 @@ int sendCTRL(XPCSocket sock, float values[], int size, char ac)
|
|||||||
}
|
}
|
||||||
if (size < 1 || size > 7)
|
if (size < 1 || size > 7)
|
||||||
{
|
{
|
||||||
printError("sendCTRL", "size should be a value between 1 and 6.");
|
printError("sendCTRL", "size should be a value between 1 and 7.");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Command
|
// Setup Command
|
||||||
// 5 byte header + 5 float values * 4 + 2 byte values
|
// 5 byte header + 5 float values * 4 + 2 byte values
|
||||||
unsigned char buffer[27] = "CTRL";
|
unsigned char buffer[31] = "CTRL";
|
||||||
int cur = 5;
|
int cur = 5;
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
@@ -587,9 +587,10 @@ int sendCTRL(XPCSocket sock, float values[], int size, char ac)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer[26] = ac;
|
buffer[26] = ac;
|
||||||
|
*((float*)(buffer + 27)) = size == 7 ? values[6]: -998;
|
||||||
|
|
||||||
// Send Command
|
// Send Command
|
||||||
if (sendUDP(sock, buffer, 27) < 0)
|
if (sendUDP(sock, buffer, 31) < 0)
|
||||||
{
|
{
|
||||||
printError("sendCTRL", "Failed to send command");
|
printError("sendCTRL", "Failed to send command");
|
||||||
return -3;
|
return -3;
|
||||||
|
|||||||
@@ -182,8 +182,8 @@ int sendPOSI(XPCSocket sock, float values[], int size, char ac);
|
|||||||
///
|
///
|
||||||
/// \param sock The socket to use to send the command.
|
/// \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
|
/// \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
|
/// [Elevator, Aileron, Rudder, Throttle, Gear, Flaps, Speed Brakes]. If less than
|
||||||
/// specified, the unspecified values will be left unchanged.
|
/// 6 values are specified, the unspecified values will be left unchanged.
|
||||||
/// \param size The number of elements in values.
|
/// \param size The number of elements in values.
|
||||||
/// \param ac The aircraft number to set the control surfaces of. 0 for the player aircraft.
|
/// \param ac The aircraft number to set the control surfaces of. 0 for the player aircraft.
|
||||||
/// \returns 0 if successful, otherwise a negative value.
|
/// \returns 0 if successful, otherwise a negative value.
|
||||||
|
|||||||
@@ -516,6 +516,97 @@ int sendCTRLTest()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int sendCTRLspeedbrakeTest() // sendCTRL test
|
||||||
|
{
|
||||||
|
// Initialize
|
||||||
|
char* dref = "sim/flightmodel/controls/sbrkrqst";
|
||||||
|
float data;
|
||||||
|
int size = 1;
|
||||||
|
float CTRL[7] = { -998.0F, -998.0F, -998.0F, -998.0F, -998.0F, -998.0F, -0.5F };
|
||||||
|
XPCSocket sock = openUDP(IP);
|
||||||
|
|
||||||
|
// Execute 1
|
||||||
|
// Arm speedbrakes
|
||||||
|
sendCTRL(sock, CTRL, 7, 0);
|
||||||
|
int result = getDREF(sock, dref, &data, &size);
|
||||||
|
|
||||||
|
// Close socket
|
||||||
|
closeUDP(sock);
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (data != 0.5F)
|
||||||
|
{
|
||||||
|
return -11;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock = openUDP(IP);
|
||||||
|
// Execute 2
|
||||||
|
// Set full speedbrakes
|
||||||
|
CTRL[6] = 1.0F;
|
||||||
|
sendCTRL(sock, CTRL, 7, 0);
|
||||||
|
result = getDREF(sock, dref, &data, &size);
|
||||||
|
|
||||||
|
// Close socket
|
||||||
|
closeUDP(sock);
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
if (data != 1.0F)
|
||||||
|
{
|
||||||
|
return -21;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock = openUDP(IP);
|
||||||
|
// Execute 3
|
||||||
|
// Retract speedbrakes
|
||||||
|
CTRL[6] = 0.0F;
|
||||||
|
sendCTRL(sock, CTRL, 6, 0);
|
||||||
|
result = getDREF(sock, dref, &data, &size);
|
||||||
|
|
||||||
|
// Close socket
|
||||||
|
closeUDP(sock);
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
if (data != 0.0F)
|
||||||
|
{
|
||||||
|
return -31;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock = openUDP(IP);
|
||||||
|
// Execute 4
|
||||||
|
// Verify -998 does not change value.
|
||||||
|
CTRL[6] = -998.0F;
|
||||||
|
sendCTRL(sock, CTRL, 6, 0);
|
||||||
|
result = getDREF(sock, dref, &data, &size);
|
||||||
|
|
||||||
|
// Close socket
|
||||||
|
closeUDP(sock);
|
||||||
|
|
||||||
|
// Tests
|
||||||
|
if (result < 0)
|
||||||
|
{
|
||||||
|
return -4;
|
||||||
|
}
|
||||||
|
if (data != 0.0F)
|
||||||
|
{
|
||||||
|
return -41;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int psendPOSITest() // sendPOSI test
|
int psendPOSITest() // sendPOSI test
|
||||||
{
|
{
|
||||||
// Initialization
|
// Initialization
|
||||||
@@ -952,6 +1043,7 @@ int main(int argc, const char * argv[])
|
|||||||
runTest(sendDATATest, "DATA");
|
runTest(sendDATATest, "DATA");
|
||||||
runTest(sendCTRLTest, "CTRL");
|
runTest(sendCTRLTest, "CTRL");
|
||||||
runTest(psendCTRLTest, "CTRL (player)");
|
runTest(psendCTRLTest, "CTRL (player)");
|
||||||
|
runTest(sendCTRLspeedbrakeTest, "CTRL (speedbrake)");
|
||||||
runTest(sendPOSITest, "POSI");
|
runTest(sendPOSITest, "POSI");
|
||||||
runTest(psendPOSITest, "POSI (player)");
|
runTest(psendPOSITest, "POSI (player)");
|
||||||
runTest(sendWYPTTest, "WYPT");
|
runTest(sendWYPTTest, "WYPT");
|
||||||
|
|||||||
Reference in New Issue
Block a user