diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 9157b35..98be7f5 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -560,13 +560,13 @@ int sendCTRL(XPCSocket sock, float values[], int size, char ac) } 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; } // Setup Command // 5 byte header + 5 float values * 4 + 2 byte values - unsigned char buffer[27] = "CTRL"; + unsigned char buffer[31] = "CTRL"; int cur = 5; for (int i = 0; i < 6; i++) { @@ -587,9 +587,10 @@ int sendCTRL(XPCSocket sock, float values[], int size, char ac) } } buffer[26] = ac; + *((float*)(buffer + 27)) = size == 7 ? values[6]: -998; // Send Command - if (sendUDP(sock, buffer, 27) < 0) + if (sendUDP(sock, buffer, 31) < 0) { printError("sendCTRL", "Failed to send command"); return -3; diff --git a/C/src/xplaneConnect.h b/C/src/xplaneConnect.h index e8520c3..abcfd1f 100644 --- a/C/src/xplaneConnect.h +++ b/C/src/xplaneConnect.h @@ -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 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. +/// [Elevator, Aileron, Rudder, Throttle, Gear, Flaps, Speed Brakes]. 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. diff --git a/TestScripts/C Tests/main.c b/TestScripts/C Tests/main.c index 83a23c8..2718c3d 100644 --- a/TestScripts/C Tests/main.c +++ b/TestScripts/C Tests/main.c @@ -516,6 +516,97 @@ int sendCTRLTest() 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 { // Initialization @@ -952,6 +1043,7 @@ int main(int argc, const char * argv[]) runTest(sendDATATest, "DATA"); runTest(sendCTRLTest, "CTRL"); runTest(psendCTRLTest, "CTRL (player)"); + runTest(sendCTRLspeedbrakeTest, "CTRL (speedbrake)"); runTest(sendPOSITest, "POSI"); runTest(psendPOSITest, "POSI (player)"); runTest(sendWYPTTest, "WYPT");