Implemented plugin support for handling WYPT commands.
This commit is contained in:
@@ -434,6 +434,32 @@ short sendTEXT(struct xpcSocket sendfd, char* msg, int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
short sendWYPT(struct xpcSocket sendfd, WYPT_OP op, float points[], int numPoints)
|
||||
{
|
||||
char buf[255] = "WYPT";
|
||||
//Preconditions
|
||||
//Validate operation
|
||||
if (op < xpc_WYPT_ADD || op > xpc_WYPT_CLR)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
//Validate number of points
|
||||
else if (numPoints > 19)
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
//Everything checks out; send the message
|
||||
else
|
||||
{
|
||||
buf[5] = op;
|
||||
buf[6] = numPoints;
|
||||
size_t len = sizeof(float) * numPoints;
|
||||
memcpy(buf + 7, points, len);
|
||||
sendUDP(sendfd, buf, len + 7);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//READ
|
||||
//----------------------------------------
|
||||
short readUDP(struct xpcSocket recfd, char *dataRef, struct sockaddr *recvaddr)
|
||||
@@ -669,3 +695,40 @@ xpcCtrl parseCTRL(const char data[])
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
xpcWypt parseWYPT(const char data[])
|
||||
{
|
||||
xpcWypt result;
|
||||
unsigned char len = data[4];
|
||||
//Preconditions
|
||||
//Validate message prefix to ensure we are looking at the right kind of packet.
|
||||
if (strncmp(data, "WYPT", 4) != 0)
|
||||
{
|
||||
result.op = -1;
|
||||
}
|
||||
//Validate operation
|
||||
else if (data[5] < xpc_WYPT_ADD || data[5] > xpc_WYPT_CLR)
|
||||
{
|
||||
result.op = -1;
|
||||
}
|
||||
//Validate number of points
|
||||
else if (data[6] > 19)
|
||||
{
|
||||
result.op = -2;
|
||||
}
|
||||
//Everything checks out; copy the points into result
|
||||
else
|
||||
{
|
||||
result.op = data[5];
|
||||
result.numPoints = data[6];
|
||||
char* ptr = data[7];
|
||||
for (size_t i = 0; i < result.numPoints; ++i)
|
||||
{
|
||||
result.points[i].latitude = *((float*)ptr);
|
||||
result.points[i].longitude = *((float*)(ptr + 4));
|
||||
result.points[i].altitude = *((float*)(ptr + 8));
|
||||
ptr += 12;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,27 @@
|
||||
float flaps;
|
||||
char aircraft;
|
||||
} xpcCtrl;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double latitude;
|
||||
double longitude;
|
||||
double altitude;
|
||||
} Waypoint;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
xpc_WYPT_ADD = 1,
|
||||
xpc_WYPT_DEL = 2,
|
||||
xpc_WYPT_CLR = 3
|
||||
} WYPT_OP;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
WYPT_OP op;
|
||||
Waypoint points[20];
|
||||
size_t numPoints;
|
||||
} xpcWypt;
|
||||
|
||||
// Basic Functions
|
||||
struct xpcSocket openUDP(unsigned short port, const char *xpIP, unsigned short xpPort);
|
||||
@@ -83,6 +104,10 @@
|
||||
short parseRequest(const char my_message[], float *resultArray[], short arraySizes[]);
|
||||
short readRequest(struct xpcSocket recfd, float *dataRef[], short arraySizes[], struct sockaddr *recvaddr);
|
||||
|
||||
// Waypoints
|
||||
xpcWypt parseWYPT(const char data[]);
|
||||
short sendWYPT(struct xpcSocket sendfd, WYPT_OP op, float points[], int numPoints);
|
||||
|
||||
// Screen Text
|
||||
short sendTEXT(struct xpcSocket sendfd, char* msg, int x, int y);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user