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

Use int64_t for position array and timestamp values

Use an integer type to keep integrity of the data coming from the autopilot
parent e6dbfeff
...@@ -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 };
...@@ -33,8 +33,8 @@ VariableData droneVariableArray[] = { ...@@ -33,8 +33,8 @@ VariableData droneVariableArray[] = {
.typeName = "Position Array Type", .typeName = "Position Array Type",
.description = "Position Array", .description = "Position Array",
.value = &positionArray, .value = &positionArray,
.type = UA_TYPES_DOUBLE, .type = UA_TYPES_INT64,
.builtInType = UA_NS0ID_DOUBLE, .builtInType = UA_NS0ID_INT64,
.valueRank = UA_VALUERANK_ONE_DIMENSION, .valueRank = UA_VALUERANK_ONE_DIMENSION,
.arrayDimensionsSize = 1, .arrayDimensionsSize = 1,
.arrayDimensions = positionArrayDims, .arrayDimensions = positionArrayDims,
......
...@@ -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 {
......
...@@ -56,7 +56,7 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal, ...@@ -56,7 +56,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;
...@@ -66,9 +66,9 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal, ...@@ -66,9 +66,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]; //relative altitude s->z = (UA_Double)(positionArray[3] / 1000); //relative altitude
s->timestamp = positionArray[4]; s->timestamp = positionArray[4];
JS_SetOpaque(obj, s); JS_SetOpaque(obj, s);
free(positionArray); free(positionArray);
...@@ -88,7 +88,7 @@ static JSValue js_position_get(JSContext *ctx, JSValueConst thisVal, int magic) ...@@ -88,7 +88,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;
} }
...@@ -188,7 +188,7 @@ static JSValue js_drone_get(JSContext *ctx, JSValueConst thisVal, int magic) ...@@ -188,7 +188,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;
} }
...@@ -366,17 +366,17 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool ...@@ -366,17 +366,17 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool
{ {
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 (print) { if (print) {
......
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