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 {
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 };
......@@ -33,8 +33,8 @@ VariableData droneVariableArray[] = {
.typeName = "Position Array Type",
.description = "Position Array",
.value = &positionArray,
.type = UA_TYPES_DOUBLE,
.builtInType = UA_NS0ID_DOUBLE,
.type = UA_TYPES_INT64,
.builtInType = UA_NS0ID_INT64,
.valueRank = UA_VALUERANK_ONE_DIMENSION,
.arrayDimensionsSize = 1,
.arrayDimensions = positionArrayDims,
......
......@@ -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 {
......
......@@ -56,7 +56,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;
......@@ -66,9 +66,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]; //relative altitude
s->x = (double)positionArray[0] / 1e7;
s->y = (double)positionArray[1] / 1e7;
s->z = (UA_Double)(positionArray[3] / 1000); //relative altitude
s->timestamp = positionArray[4];
JS_SetOpaque(obj, s);
free(positionArray);
......@@ -88,7 +88,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;
}
......@@ -188,7 +188,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;
}
......@@ -366,17 +366,17 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool
{
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 (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