diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 9b72ef8..9cc8575 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -373,7 +373,12 @@ short sendPOSI(struct xpcSocket recfd, short ACNum, short numArgs, float valueAr short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]) { - char message[26] = {0}; + return sendpCTRL(recfd, numArgs, valueArray, 0); +} + +short sendpCTRL(struct xpcSocket recfd, short numArgs, float valueArray[], char acNum) +{ + char message[27] = { 0 }; int i; short position = 5; @@ -406,11 +411,11 @@ short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]) // Float Values memcpy(&message[position],&val,sizeof(float)); position += sizeof(float); - } - + } } + message[position] = acNum; - sendUDP(recfd, message, 26); + sendUDP(recfd, message, 27); return 0; } diff --git a/C/src/xplaneConnect.h b/C/src/xplaneConnect.h index e158a3c..dff7b5d 100644 --- a/C/src/xplaneConnect.h +++ b/C/src/xplaneConnect.h @@ -70,8 +70,9 @@ // Controls xpcCtrl parseCTRL(const char data[]); - xpcCtrl readCTRL(struct xpcSocket recfd); - short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]); + xpcCtrl readCTRL(struct xpcSocket recfd); + short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]); + short sendpCTRL(struct xpcSocket recfd, short numArgs, float valueArray[], char acNum); // DREF Manipulation short readDREF(struct xpcSocket recfd, float *resultArray[], short arraySizes[]); diff --git a/TestScripts/C Tests/main.c b/TestScripts/C Tests/main.c index 0a536bb..148637f 100644 --- a/TestScripts/C Tests/main.c +++ b/TestScripts/C Tests/main.c @@ -234,59 +234,118 @@ short sendDATATest() // sendDATA test short sendCTRLTest() // sendCTRL test { - printf("sendCTRL - "); - - // Initialize - int i; // Iterator - char DREFArray[100][100]; - float CTRL[6] = {0.0}; - float *recDATA[100]; - short DREFSizes[100]; - struct xpcSocket sendPort, recvPort; - short result; - - // Setup - for (i = 0; i < 100; i++) { - recDATA[i] = (float *) malloc(40*sizeof(float)); - memset(DREFArray[i],0,100); - } - sendPort = openUDP( 49066, "127.0.0.1", 49009 ); - recvPort = openUDP( 49008, "127.0.0.1", 49009 ); - strcpy(DREFArray[0],"sim/cockpit2/controls/yoke_pitch_ratio"); - strcpy(DREFArray[1],"sim/cockpit2/controls/yoke_roll_ratio"); - strcpy(DREFArray[2],"sim/cockpit2/controls/yoke_heading_ratio"); - strcpy(DREFArray[3],"sim/flightmodel/engine/ENGN_thro"); - strcpy(DREFArray[4],"sim/cockpit/switches/gear_handle_status"); - strcpy(DREFArray[5],"sim/flightmodel/controls/flaprqst"); + printf("sendCTRL - "); + + // Initialize + int i; // Iterator + char DREFArray[100][100]; + float CTRL[6] = { 0.0 }; + float *recDATA[100]; + short DREFSizes[100]; + struct xpcSocket sendPort, recvPort; + short result; + + // Setup + for (i = 0; i < 100; i++) { + recDATA[i] = (float *)malloc(40 * sizeof(float)); + memset(DREFArray[i], 0, 100); + } + sendPort = openUDP(49066, "127.0.0.1", 49009); + recvPort = openUDP(49008, "127.0.0.1", 49009); + strcpy(DREFArray[0], "sim/cockpit2/controls/yoke_pitch_ratio"); + strcpy(DREFArray[1], "sim/cockpit2/controls/yoke_roll_ratio"); + strcpy(DREFArray[2], "sim/cockpit2/controls/yoke_heading_ratio"); + strcpy(DREFArray[3], "sim/flightmodel/engine/ENGN_thro"); + strcpy(DREFArray[4], "sim/cockpit/switches/gear_handle_status"); + strcpy(DREFArray[5], "sim/flightmodel/controls/flaprqst"); for (i = 0; i < 100; i++) { DREFSizes[i] = (int)strlen(DREFArray[i]); } - CTRL[3] = 0.8; // Throttle - CTRL[4] = 1; // Gear - CTRL[5] = 0.5; // Flaps - - // Execute - sendCTRL(sendPort, 6, CTRL); - result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 6, recDATA, DREFSizes); // Test - - // Close - closeUDP(sendPort); - closeUDP(recvPort); - - // Tests - if ( result < 0 )// Request 1 value - { - return -6; - } - for (i=0;i<6;i++) - { - if (fabs(recDATA[i][0]-CTRL[i])>1e-4) - { - return -i - 1; - } - } + CTRL[3] = 0.8; // Throttle + CTRL[4] = 1; // Gear + CTRL[5] = 0.5; // Flaps - return 0; + // Execute + sendCTRL(sendPort, 6, CTRL); + result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 6, recDATA, DREFSizes); // Test + + // Close + closeUDP(sendPort); + closeUDP(recvPort); + + // Tests + if (result < 0)// Request 1 value + { + return -6; + } + for (i = 0; i<6; i++) + { + if (fabs(recDATA[i][0] - CTRL[i])>1e-4) + { + return -i - 1; + } + } + + return 0; +} + +short sendpCTRLTest() +{ + printf("sendNonPlayerCTRL - "); + + // Initialize + int i; // Iterator + char DREFArray[100][100]; + float CTRL[6] = { 0.0 }; + float *recDATA[100]; + short DREFSizes[100]; + struct xpcSocket sendPort, recvPort; + short result; + + // Setup + for (i = 0; i < 100; i++) + { + recDATA[i] = (float *)malloc(40 * sizeof(float)); + memset(DREFArray[i], 0, 100); + } + sendPort = openUDP(49066, "127.0.0.1", 49009); + recvPort = openUDP(49008, "127.0.0.1", 49009); + strcpy(DREFArray[0], "sim/multiplayer/position/plane1_yolk_pitch"); + strcpy(DREFArray[1], "sim/multiplayer/position/plane1_yolk_roll"); + strcpy(DREFArray[2], "sim/multiplayer/position/plane1_yolk_yaw"); + strcpy(DREFArray[3], "sim/multiplayer/position/plane1_throttle"); + strcpy(DREFArray[4], "sim/multiplayer/position/plane1_gear_deploy"); + strcpy(DREFArray[5], "sim/multiplayer/position/plane1_flap_ratio"); + for (i = 0; i < 100; i++) + { + DREFSizes[i] = (int)strlen(DREFArray[i]); + } + CTRL[3] = 0.8; // Throttle + CTRL[4] = 1; // Gear + CTRL[5] = 0.5; // Flaps + + // Execute + sendpCTRL(sendPort, 6, CTRL, 1); + result = requestDREF(sendPort, recvPort, DREFArray, DREFSizes, 9, recDATA, DREFSizes); // Test + + // Close + closeUDP(sendPort); + closeUDP(recvPort); + + // Tests + if (result < 0)// Request 1 value + { + return -6; + } + for (i = 0; i<6; i++) + { + if (fabs(recDATA[i][0] - CTRL[i])>1e-4) + { + return -i - 1; + } + } + + return 0; } short sendPOSITest() // sendPOSI test @@ -486,8 +545,9 @@ int main(int argc, const char * argv[]) runTest(sendReadTest); runTest(requestDREFTest); runTest(sendDREFTest); - runTest(sendDATATest); - runTest(sendCTRLTest); + runTest(sendDATATest); + runTest(sendCTRLTest); + runTest(sendpCTRLTest); runTest(sendPOSITest); runTest(pauseTest); runTest(connTest);