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 { ...@@ -16,7 +16,7 @@ typedef struct {
struct messageNode *tail; struct messageNode *tail;
} MessageQueue; } MessageQueue;
UA_Double positionArray[POSITION_ARRAY_SIZE] = { 0 }; UA_Int64 positionArray[POSITION_ARRAY_SIZE] = { 0 };
UA_UInt32 positionArrayDims[] = {POSITION_ARRAY_SIZE}; UA_UInt32 positionArrayDims[] = {POSITION_ARRAY_SIZE};
UA_Double speedArray[SPEED_ARRAY_SIZE] = { 0 }; UA_Double speedArray[SPEED_ARRAY_SIZE] = { 0 };
......
...@@ -25,7 +25,7 @@ typedef struct { ...@@ -25,7 +25,7 @@ typedef struct {
UA_Double longitude; UA_Double longitude;
UA_Double altitudeAbs; UA_Double altitudeAbs;
UA_Double altitudeRel; UA_Double altitudeRel;
UA_Double timestamp; UA_Int64 timestamp;
UA_Float yaw; UA_Float yaw;
UA_Float speed; UA_Float speed;
UA_Float climbRate; UA_Float climbRate;
...@@ -37,7 +37,7 @@ typedef struct { ...@@ -37,7 +37,7 @@ typedef struct {
UA_Double x; UA_Double x;
UA_Double y; UA_Double y;
UA_Double z; UA_Double z;
UA_Double timestamp; UA_Int64 timestamp;
} JSPositionData; } JSPositionData;
typedef struct { typedef struct {
......
...@@ -58,7 +58,7 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal, ...@@ -58,7 +58,7 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal,
{ {
JSPositionData *s; JSPositionData *s;
JSValue obj; JSValue obj;
UA_Double *positionArray; UA_Int64 *positionArray;
obj = JS_NewObjectClass(ctx, (int) jsPositionClassId); obj = JS_NewObjectClass(ctx, (int) jsPositionClassId);
if (JS_IsException(obj)) if (JS_IsException(obj))
return obj; return obj;
...@@ -68,9 +68,9 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal, ...@@ -68,9 +68,9 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal,
return JS_EXCEPTION; return JS_EXCEPTION;
} }
positionArray = getPositionArray(); positionArray = getPositionArray();
s->x = positionArray[0]; s->x = (double)positionArray[0] / 1e7;
s->y = positionArray[1]; s->y = (double)positionArray[1] / 1e7;
s->z = positionArray[3]; s->z = (UA_Double)(positionArray[3] / 1000);
s->timestamp = positionArray[4]; s->timestamp = positionArray[4];
JS_SetOpaque(obj, s); JS_SetOpaque(obj, s);
free(positionArray); free(positionArray);
...@@ -90,7 +90,7 @@ static JSValue js_position_get(JSContext *ctx, JSValueConst thisVal, int magic) ...@@ -90,7 +90,7 @@ static JSValue js_position_get(JSContext *ctx, JSValueConst thisVal, int magic)
case 2: case 2:
return JS_NewFloat64(ctx, s->z); return JS_NewFloat64(ctx, s->z);
case 3: case 3:
return JS_NewFloat64(ctx, s->timestamp); return JS_NewInt64(ctx, s->timestamp);
default: default:
return JS_EXCEPTION; return JS_EXCEPTION;
} }
...@@ -190,7 +190,7 @@ static JSValue js_drone_get(JSContext *ctx, JSValueConst thisVal, int magic) ...@@ -190,7 +190,7 @@ static JSValue js_drone_get(JSContext *ctx, JSValueConst thisVal, int magic)
pthread_mutex_unlock(&mutex); pthread_mutex_unlock(&mutex);
return res; return res;
case 9: case 9:
return JS_NewFloat64(ctx, s->timestamp); return JS_NewInt64(ctx, s->timestamp);
default: default:
return JS_EXCEPTION; return JS_EXCEPTION;
} }
...@@ -368,17 +368,17 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var) ...@@ -368,17 +368,17 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var)
{ {
JSDroneData* s; JSDroneData* s;
UA_String uaStr; UA_String uaStr;
UA_Double* positionArray; UA_Int64* positionArray;
UA_Float* speedArray; UA_Float* speedArray;
for(UA_UInt32 i = 0; i < nbDrone + nbSubscriber; i++) { for(UA_UInt32 i = 0; i < nbDrone + nbSubscriber; i++) {
s = (JSDroneData *) JS_GetOpaque(droneObjectIdList[i], jsDroneClassId); s = (JSDroneData *) JS_GetOpaque(droneObjectIdList[i], jsDroneClassId);
if (s->positionArrayId == id) { if (s->positionArrayId == id) {
positionArray = (UA_Double*) var->value.data; positionArray = (UA_Int64*) var->value.data;
s->latitude = positionArray[0]; s->latitude = (double)positionArray[0] / 1e7;
s->longitude = positionArray[1]; s->longitude = (double)positionArray[1] / 1e7;
s->altitudeAbs = positionArray[2]; s->altitudeAbs = (UA_Double)(positionArray[2] / 1000);
s->altitudeRel = positionArray[3]; s->altitudeRel = (UA_Double)(positionArray[3] / 1000);
s->timestamp = positionArray[4]; s->timestamp = positionArray[4];
if (!isADrone) { 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