Commit 50ccbabe authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

Use int64_t for position array values

Use an integer type to keep integrity of the data coming for the autopilot
parent ea0066f2
......@@ -16,7 +16,7 @@ typedef struct {
struct messageNode *tail;
} MessageQueue;
UA_Double positionArray[POSITION_ARRAY_SIZE] = { 0 };
UA_Int64 positionArray[POSITION_ARRAY_SIZE] = { 0 };
UA_UInt32 positionArrayDims[] = {POSITION_ARRAY_SIZE};
UA_Double speedArray[SPEED_ARRAY_SIZE] = { 0 };
......
......@@ -25,7 +25,7 @@ typedef struct {
UA_Double longitude;
UA_Double altitudeAbs;
UA_Double altitudeRel;
UA_Double timestamp;
UA_Int64 timestamp;
UA_Float yaw;
UA_Float speed;
UA_Float climbRate;
......@@ -37,7 +37,7 @@ typedef struct {
UA_Double x;
UA_Double y;
UA_Double z;
UA_Double timestamp;
UA_Int64 timestamp;
} JSPositionData;
typedef struct {
......
......@@ -58,7 +58,7 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal,
{
JSPositionData *s;
JSValue obj;
UA_Double *positionArray;
UA_Int64 *positionArray;
obj = JS_NewObjectClass(ctx, (int) jsPositionClassId);
if (JS_IsException(obj))
return obj;
......@@ -68,9 +68,9 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal,
return JS_EXCEPTION;
}
positionArray = getPositionArray();
s->x = positionArray[0];
s->y = positionArray[1];
s->z = positionArray[3];
s->x = (double)positionArray[0] / 1e7;
s->y = (double)positionArray[1] / 1e7;
s->z = (UA_Double)(positionArray[3] / 1000);
s->timestamp = positionArray[4];
JS_SetOpaque(obj, s);
free(positionArray);
......@@ -90,7 +90,7 @@ static JSValue js_position_get(JSContext *ctx, JSValueConst thisVal, int magic)
case 2:
return JS_NewFloat64(ctx, s->z);
case 3:
return JS_NewFloat64(ctx, s->timestamp);
return JS_NewInt64(ctx, s->timestamp);
default:
return JS_EXCEPTION;
}
......@@ -190,7 +190,7 @@ static JSValue js_drone_get(JSContext *ctx, JSValueConst thisVal, int magic)
pthread_mutex_unlock(&mutex);
return res;
case 9:
return JS_NewFloat64(ctx, s->timestamp);
return JS_NewInt64(ctx, s->timestamp);
default:
return JS_EXCEPTION;
}
......@@ -368,17 +368,17 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var)
{
JSDroneData* s;
UA_String uaStr;
UA_Double* positionArray;
UA_Int64* positionArray;
UA_Float* speedArray;
for(UA_UInt32 i = 0; i < nbDrone + nbSubscriber; i++) {
s = (JSDroneData *) JS_GetOpaque(droneObjectIdList[i], jsDroneClassId);
if (s->positionArrayId == id) {
positionArray = (UA_Double*) var->value.data;
s->latitude = positionArray[0];
s->longitude = positionArray[1];
s->altitudeAbs = positionArray[2];
s->altitudeRel = positionArray[3];
positionArray = (UA_Int64*) var->value.data;
s->latitude = (double)positionArray[0] / 1e7;
s->longitude = (double)positionArray[1] / 1e7;
s->altitudeAbs = (UA_Double)(positionArray[2] / 1000);
s->altitudeRel = (UA_Double)(positionArray[3] / 1000);
s->timestamp = positionArray[4];
if (!isADrone) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment