Added C client support for multiplayer sendCTRL commands.

This commit is contained in:
Jason Watkins
2015-04-06 14:41:23 -07:00
parent 79f632f9a3
commit abf2a426d2
3 changed files with 123 additions and 57 deletions

View File

@@ -373,7 +373,12 @@ short sendPOSI(struct xpcSocket recfd, short ACNum, short numArgs, float valueAr
short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]) 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; int i;
short position = 5; short position = 5;
@@ -406,11 +411,11 @@ short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[])
// Float Values // Float Values
memcpy(&message[position],&val,sizeof(float)); memcpy(&message[position],&val,sizeof(float));
position += sizeof(float); position += sizeof(float);
} }
} }
message[position] = acNum;
sendUDP(recfd, message, 26); sendUDP(recfd, message, 27);
return 0; return 0;
} }

View File

@@ -70,8 +70,9 @@
// Controls // Controls
xpcCtrl parseCTRL(const char data[]); xpcCtrl parseCTRL(const char data[]);
xpcCtrl readCTRL(struct xpcSocket recfd); xpcCtrl readCTRL(struct xpcSocket recfd);
short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]); short sendCTRL(struct xpcSocket recfd, short numArgs, float valueArray[]);
short sendpCTRL(struct xpcSocket recfd, short numArgs, float valueArray[], char acNum);
// DREF Manipulation // DREF Manipulation
short readDREF(struct xpcSocket recfd, float *resultArray[], short arraySizes[]); short readDREF(struct xpcSocket recfd, float *resultArray[], short arraySizes[]);

View File

@@ -234,59 +234,118 @@ short sendDATATest() // sendDATA test
short sendCTRLTest() // sendCTRL test short sendCTRLTest() // sendCTRL test
{ {
printf("sendCTRL - "); printf("sendCTRL - ");
// Initialize // Initialize
int i; // Iterator int i; // Iterator
char DREFArray[100][100]; char DREFArray[100][100];
float CTRL[6] = {0.0}; float CTRL[6] = { 0.0 };
float *recDATA[100]; float *recDATA[100];
short DREFSizes[100]; short DREFSizes[100];
struct xpcSocket sendPort, recvPort; struct xpcSocket sendPort, recvPort;
short result; short result;
// Setup // Setup
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
recDATA[i] = (float *) malloc(40*sizeof(float)); recDATA[i] = (float *)malloc(40 * sizeof(float));
memset(DREFArray[i],0,100); memset(DREFArray[i], 0, 100);
} }
sendPort = openUDP( 49066, "127.0.0.1", 49009 ); sendPort = openUDP(49066, "127.0.0.1", 49009);
recvPort = openUDP( 49008, "127.0.0.1", 49009 ); recvPort = openUDP(49008, "127.0.0.1", 49009);
strcpy(DREFArray[0],"sim/cockpit2/controls/yoke_pitch_ratio"); strcpy(DREFArray[0], "sim/cockpit2/controls/yoke_pitch_ratio");
strcpy(DREFArray[1],"sim/cockpit2/controls/yoke_roll_ratio"); strcpy(DREFArray[1], "sim/cockpit2/controls/yoke_roll_ratio");
strcpy(DREFArray[2],"sim/cockpit2/controls/yoke_heading_ratio"); strcpy(DREFArray[2], "sim/cockpit2/controls/yoke_heading_ratio");
strcpy(DREFArray[3],"sim/flightmodel/engine/ENGN_thro"); strcpy(DREFArray[3], "sim/flightmodel/engine/ENGN_thro");
strcpy(DREFArray[4],"sim/cockpit/switches/gear_handle_status"); strcpy(DREFArray[4], "sim/cockpit/switches/gear_handle_status");
strcpy(DREFArray[5],"sim/flightmodel/controls/flaprqst"); strcpy(DREFArray[5], "sim/flightmodel/controls/flaprqst");
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
DREFSizes[i] = (int)strlen(DREFArray[i]); DREFSizes[i] = (int)strlen(DREFArray[i]);
} }
CTRL[3] = 0.8; // Throttle CTRL[3] = 0.8; // Throttle
CTRL[4] = 1; // Gear CTRL[4] = 1; // Gear
CTRL[5] = 0.5; // Flaps 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;
}
}
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 short sendPOSITest() // sendPOSI test
@@ -486,8 +545,9 @@ int main(int argc, const char * argv[])
runTest(sendReadTest); runTest(sendReadTest);
runTest(requestDREFTest); runTest(requestDREFTest);
runTest(sendDREFTest); runTest(sendDREFTest);
runTest(sendDATATest); runTest(sendDATATest);
runTest(sendCTRLTest); runTest(sendCTRLTest);
runTest(sendpCTRLTest);
runTest(sendPOSITest); runTest(sendPOSITest);
runTest(pauseTest); runTest(pauseTest);
runTest(connTest); runTest(connTest);