From 0b984c3d4967d656b056657d72b46078098e3346 Mon Sep 17 00:00:00 2001 From: Jason Watkins Date: Fri, 1 May 2015 14:55:36 -0700 Subject: [PATCH] Updated C client to support "switch" argument in SIMU command. --- C/src/xplaneConnect.c | 10 +++++++- TestScripts/C Tests/main.c | 49 ++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/C/src/xplaneConnect.c b/C/src/xplaneConnect.c index 48c29dc..89b063c 100755 --- a/C/src/xplaneConnect.c +++ b/C/src/xplaneConnect.c @@ -264,9 +264,17 @@ int setCONN(XPCSocket* sock, unsigned short port) int pauseSim(XPCSocket sock, char pause) { + // Validte input + if (pause < 0 || pause > 2) + { + printError("pauseSim", "Invalid argument: %i", pause); + return; + } + // Setup command char buffer[6] = "SIMU"; - buffer[5] = pause == 0 ? 0 : 1; + buffer[5] = pause; + // Send command if (sendUDP(sock, buffer, 6) < 0) { diff --git a/TestScripts/C Tests/main.c b/TestScripts/C Tests/main.c index 4a92c3e..83a23c8 100644 --- a/TestScripts/C Tests/main.c +++ b/TestScripts/C Tests/main.c @@ -833,56 +833,63 @@ int sendWYPTTest() int pauseTest() // pauseSim test { - // Initialize + // Setup // Note: Always run this test to the end so that the sim ends up unpaused in the // case where commands are working but reading results isn't. int result = 0; - char* drefs[100] = - { - "sim/operation/override/override_planepath" - }; - float* data[100]; - int sizes[100]; + char* dref = "sim/operation/override/override_planepath"; + int size = 20; + float data[20]; XPCSocket sock = openUDP(IP); - // Setup - for (int i = 0; i < 100; i++) - { - data[i] = (float*)malloc(40 * sizeof(float)); - sizes[i] = 40; - } - // Execute - pauseSim(sock, 1); - result = getDREF(sock, drefs[0], data[0], sizes); + pauseSim(sock, 0); + result = getDREF(sock, dref, data, &size); // Test if (result < 0) { result = -1; } - if (data[0][0] != 1) + else if (data[0] != 0) { result = -2; - } + } if (result == 0) { // Execute 2 - pauseSim(sock, 0); - result = getDREF(sock, drefs[0], data[0], sizes); + pauseSim(sock, 2); + result = getDREF(sock, dref, data, &size); // Test 2 if (result < 0) { result = -3; } - if (data[0][0] != 0) + else if (data[0] != 1) { result = -4; } } + if (result == 0) + { + // Execute 3 + pauseSim(sock, 0); + result = getDREF(sock, dref, data, &size); + + // Test 2 + if (result < 0) + { + result = -5; + } + else if (data[0] != 0) + { + result = -6; + } + } + // Close closeUDP(sock);