Implemented plugin support for handling WYPT commands.

This commit is contained in:
Jason Watkins
2015-04-09 09:42:26 -07:00
parent 8fed5d916c
commit 1a83517bee
5 changed files with 121 additions and 18 deletions

View File

@@ -120,7 +120,7 @@ int handleSIMU(char buf[]);
int handleCONN(char buf[]);
int handlePOSI(char buf[]);
int handleCTRL(char buf[]);
int handleWYPT();
int handleWYPT(char buf[], int len);
int handleGETD(char *buf);
int handleDREF(char *buf);
int handleVIEW();
@@ -357,7 +357,7 @@ short handleInput(struct XPCMessage * theMessage)
}
else if (strncmp(theMessage->head,"WYPT",4)==0) // Header = WYPT (Waypoint Draw)
{
handleWYPT();
handleWYPT(theMessage->msg, theMessage->msglen);
}
else if (strncmp(theMessage->head,"GETD",4)==0) // Header = GETD (Data Request)
{
@@ -830,14 +830,35 @@ int handleCTRL(char buf[])
return 0;
}
int handleWYPT()
int handleWYPT(char buf[], int len)
{
char logmsg[100];
// UPDATE LOG
sprintf(logmsg,"[WYPT] Message Received (Conn %i)- WAYPOINT DRAWING FEATURE UNDER CONSTRUCTION", current_connection+1);
char logmsg[100];
sprintf(logmsg,"[WYPT] Message Received (Conn %i)", current_connection+1);
updateLog(logmsg, strlen(logmsg));
xpcWypt wypt = parseWYPT(buf);
if (wypt.op < 0)
{
sprintf(logmsg, "[WYPT] Failed to parse command. ERR:%i", wypt.op);
updateLog(logmsg, strlen(logmsg));
return -1;
}
switch (wypt.op)
{
case xpc_WYPT_ADD:
XPCAddWaypoints(wypt.points, wypt.numPoints);
break;
case xpc_WYPT_DEL:
XPCRemoveWaypoints(wypt.points, wypt.numPoints);
break;
case xpc_WYPT_CLR:
XPCClearWaypoints();
break;
default: //If parseWYPT is doing its job, we shouldn't ever hit this.
return -2;
}
return 0;
}

View File

@@ -113,7 +113,7 @@ static int RouteDrawCallback(XPLMDrawingPhase inPhase, int inIsBefore, void * in
{
g = &waypoints[i];
l = &localPoints[i];
XPLMWorldToLocal(g->lattitude, g->longitude, g->altitude,
XPLMWorldToLocal(g->latitude, g->longitude, g->altitude,
&l->x, &l->y, &l->z);
}
@@ -147,7 +147,7 @@ static int RouteDrawCallback(XPLMDrawingPhase inPhase, int inIsBefore, void * in
float xoff = (float)l->x - px;
float yoff = (float)l->y - py;
float zoff = (float)l->z - pz;
float d = sqrtf(xoff*xoff + zoff*zoff);
float d = sqrtf(xoff*xoff + yoff*yoff + zoff*zoff);
gl_drawCube((float)l->x, (float)l->y, (float)l->z, d);
}
return 1;
@@ -239,7 +239,7 @@ void XPCRemoveWaypoints(Waypoint points[], size_t numPoints)
for (size_t j = 0; j < numWaypoints; ++j)
{
Waypoint q = waypoints[j];
if (p.lattitude == q.lattitude &&
if (p.latitude == q.latitude &&
p.longitude == q.longitude &&
p.altitude == q.altitude)
{
@@ -255,7 +255,7 @@ void XPCRemoveWaypoints(Waypoint points[], size_t numPoints)
size_t copyCur = 0;
size_t count = delPointsCur;
delPointsCur = 0;
for (size_t i = 0; i < count; ++i)
for (size_t i = 0; i < numWaypoints; ++i)
{
if (i == delPoints[delPointsCur])
{

View File

@@ -2,13 +2,7 @@
#define xpcDrawing_h
#include <stdlib.h>
typedef struct
{
double lattitude;
double longitude;
double altitude;
} Waypoint;
#include "xplaneConnect.h"
void XPCClearMessage();