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

Check if autopilot API is required

parent 1ab8f5a4
CFLAGS=-std=c99 -D_POSIX_C_SOURCE=200809L -pipe -Wall -Wextra -Wpedantic -Werror -Wno-overlength-strings -Wno-unused-parameter -Wc++-compat -Wformat -Wformat-security -Wformat-nonliteral -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wuninitialized -Winit-self -Wcast-qual -Wstrict-overflow -Wnested-externs -Wmultichar -Wundef -fno-strict-aliasing -fexceptions -fstack-protector-strong -fstack-clash-protection -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-math-errno -O3 -flto -fno-fat-lto-objects -Wshadow -Wconversion -fvisibility=hidden CFLAGS=-std=c99 -D_POSIX_C_SOURCE=200809L -pipe -Wall -Wextra -Wpedantic -Werror -Wno-overlength-strings -Wno-unused-parameter -Wc++-compat -Wformat -Wformat-security -Wformat-nonliteral -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wuninitialized -Winit-self -Wcast-qual -Wstrict-overflow -Wnested-externs -Wmultichar -Wundef -fno-strict-aliasing -fexceptions -fstack-protector-strong -fstack-clash-protection -ffunction-sections -fdata-sections -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-math-errno -O3 -flto -fno-fat-lto-objects -Wshadow -Wconversion -fvisibility=hidden
LIBS=-lautopilotwrapper -lopen62541 LIBS=-lopen62541
ifeq ($(WITH_AUTOPILOT),y)
LIBS+= -lautopilotwrapper
CFLAGS+= -DWITH_AUTOPILOT
endif
LIB_NAME := libqjswrapper.so LIB_NAME := libqjswrapper.so
......
#ifndef __AUTOPILOT_H__ #ifndef __AUTOPILOT_API_H__
#define __AUTOPILOT_H__ #define __AUTOPILOT_API_H__
#ifndef DLL_PUBLIC #ifndef DLL_PUBLIC
#define DLL_PUBLIC __attribute__ ((visibility ("default"))) #define DLL_PUBLIC __attribute__ ((visibility ("default")))
#endif #endif
/*
* 0. latitude (double, degrees)
* 1. longitude (double, degrees)
* 2. absolute altitude (double, meters)
* 3. relative altitude (double, meters)
* 4. timestamp (double, milliseconds)
*/
#define POSITION_ARRAY_SIZE 5
/*
* 0. yaw angle (float, degrees)
* 1. air speed (float, m/s)
* 2. climb rate (float, m/s)
*/
#define SPEED_ARRAY_SIZE 3
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -59,4 +44,4 @@ DLL_PUBLIC void updateLogAndProjection(void); ...@@ -59,4 +44,4 @@ DLL_PUBLIC void updateLogAndProjection(void);
} }
#endif #endif
#endif /* __AUTOPILOT_H__ */ #endif /* __AUTOPILOT__API_H__ */
#ifndef __DRONEDGE_H__
#define __DRONEDGE_H__
#include <open62541/server.h>
#include "autopilot_wrapper.h"
#include "pubsub.h"
#define DRONE_VARIABLE_NB 4
#define SUBSCRIBER_VARIABLE_NB 1
struct messageNode {
char *message;
struct messageNode *next;
};
typedef struct {
struct messageNode *head;
struct messageNode *tail;
} MessageQueue;
UA_Int64 positionArray[POSITION_ARRAY_SIZE] = { 0 };
UA_UInt32 positionArrayDims[] = {POSITION_ARRAY_SIZE};
UA_Double speedArray[SPEED_ARRAY_SIZE] = { 0 };
UA_UInt32 speedArrayDims[] = {SPEED_ARRAY_SIZE};
UA_String initial_ua_string = {
.length = 0,
.data = NULL,
};
VariableData droneVariableArray[] = {
{
.name = "positionArray",
.typeName = "Position Array Type",
.description = "Position Array",
.value = &positionArray,
.type = UA_TYPES_INT64,
.builtInType = UA_NS0ID_INT64,
.valueRank = UA_VALUERANK_ONE_DIMENSION,
.arrayDimensionsSize = 1,
.arrayDimensions = positionArrayDims,
.getter.getArray = getPositionArray,
},
{
.name = "speedArray",
.typeName = "Speed Array Type",
.description = "Speed Array",
.value = &speedArray,
.type = UA_TYPES_FLOAT,
.builtInType = UA_NS0ID_FLOAT,
.valueRank = UA_VALUERANK_ONE_DIMENSION,
.arrayDimensionsSize = 1,
.arrayDimensions = speedArrayDims,
.getter.getArray = getSpeedArray,
},
{
.name = "message",
.description = "Message to send to the other drones",
.value = &initial_ua_string,
.type = UA_TYPES_STRING,
.builtInType = UA_NS0ID_STRING,
.valueRank = UA_VALUERANK_SCALAR,
.arrayDimensionsSize = 0,
.arrayDimensions = NULL,
.getter.getString = get_message,
},
{
.name = "log",
.description = "Message to send to the other drones",
.value = &initial_ua_string,
.type = UA_TYPES_STRING,
.builtInType = UA_NS0ID_STRING,
.valueRank = UA_VALUERANK_SCALAR,
.arrayDimensionsSize = 0,
.arrayDimensions = NULL,
.getter.getString = get_log,
},
};
VariableStruct droneVariables = {
.nbVariable = DRONE_VARIABLE_NB,
.variableArray = droneVariableArray,
};
VariableData subscriberVariableArray[] = {
{
.name = "message",
.description = "Message to send to the other drones",
.value = &initial_ua_string,
.type = UA_TYPES_STRING,
.builtInType = UA_NS0ID_STRING,
.valueRank = UA_VALUERANK_SCALAR,
.arrayDimensionsSize = 0,
.arrayDimensions = NULL,
.getter.getString = get_message,
},
};
VariableStruct subscriberVariables = {
.nbVariable = SUBSCRIBER_VARIABLE_NB,
.variableArray = subscriberVariableArray,
};
#endif /* __DRONEDGE_H__ */
#ifndef __DRONEDGE_PROTOCOL_H__
#define __DRONEDGE_PROTOCOL_H__
#define POSITION_ARRAY_SIZE 5
#define SPEED_ARRAY_SIZE 3
/*
* 0. latitude (double, degrees)
* 1. longitude (double, degrees)
* 2. absolute altitude (double, meters)
* 3. relative altitude (double, meters)
* 4. timestamp (double, milliseconds)
*/
typedef enum
{
LATITUDE = 0x0,
LONGITUDE,
ABS_ALTITUDE,
REL_ALTITUDE,
TIMESTAMP,
} POSITION_ENUM;
/*
* 0. yaw angle (float, degrees)
* 1. air speed (float, m/s)
* 2. climb rate (float, m/s)
*/
typedef enum
{
YAW = 0x0,
SPEED,
CLIMB_RATE,
} SPEED_ENUM;
#endif /* __DRONEDGE_PROTOCOL_H__ */
...@@ -31,8 +31,6 @@ typedef struct { ...@@ -31,8 +31,6 @@ typedef struct {
UA_Float climbRate; UA_Float climbRate;
char message[MAX_MESSAGE_SIZE]; char message[MAX_MESSAGE_SIZE];
UA_UInt32 messageId; UA_UInt32 messageId;
char log[MAX_MESSAGE_SIZE];
UA_UInt32 logId;
} JSDroneData; } JSDroneData;
typedef struct { typedef struct {
...@@ -81,8 +79,6 @@ int runPubsub(const UA_Logger *logger, UA_String *transportProfile, ...@@ -81,8 +79,6 @@ int runPubsub(const UA_Logger *logger, UA_String *transportProfile,
UA_String get_message(void); UA_String get_message(void);
UA_String get_log(void);
UA_UInt16 get_drone_id(UA_UInt32 nb); UA_UInt16 get_drone_id(UA_UInt32 nb);
void init_drone_node_id(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic); void init_drone_node_id(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic);
...@@ -93,4 +89,7 @@ VariableData pubsub_get_value(UA_String identifier); ...@@ -93,4 +89,7 @@ VariableData pubsub_get_value(UA_String identifier);
DLL_PUBLIC JSModuleDef *js_init_module(JSContext *ctx, const char *module_name); DLL_PUBLIC JSModuleDef *js_init_module(JSContext *ctx, const char *module_name);
void Subscriber_log(void *context, UA_LogLevel level, UA_LogCategory category,
const char *msg, va_list args);
#endif /* __PUBSUB_H__ */ #endif /* __PUBSUB_H__ */
#include <math.h> #include <math.h>
#include <pthread.h> #include <pthread.h>
#include "dronedge.h" #include <open62541/server.h>
#include "dronedge_protocol.h"
#include "pubsub.h"
#ifdef WITH_AUTOPILOT
#include "autopilot_API.h"
#endif
#define DRONE_VARIABLE_NB 3
#define SUBSCRIBER_VARIABLE_NB 1
struct strNode {
char *str;
struct strNode *next;
};
typedef struct {
struct strNode *head;
struct strNode *tail;
} StrQueue;
UA_Int64 positionArray[POSITION_ARRAY_SIZE] = { 0 };
UA_UInt32 positionArrayDims[] = {POSITION_ARRAY_SIZE};
UA_Double speedArray[SPEED_ARRAY_SIZE] = { 0 };
UA_UInt32 speedArrayDims[] = {SPEED_ARRAY_SIZE};
UA_String message = {
.length = 0,
.data = NULL,
};
VariableData droneVariableArray[] = {
{
.name = "positionArray",
.typeName = "Position Array Type",
.description = "Position Array",
.value = &positionArray,
.type = UA_TYPES_INT64,
.builtInType = UA_NS0ID_INT64,
.valueRank = UA_VALUERANK_ONE_DIMENSION,
.arrayDimensionsSize = 1,
.arrayDimensions = positionArrayDims,
#ifdef WITH_AUTOPILOT
.getter.getArray = (void * (*)(void))getPositionArray,
#endif
},
{
.name = "speedArray",
.typeName = "Speed Array Type",
.description = "Speed Array",
.value = &speedArray,
.type = UA_TYPES_FLOAT,
.builtInType = UA_NS0ID_FLOAT,
.valueRank = UA_VALUERANK_ONE_DIMENSION,
.arrayDimensionsSize = 1,
.arrayDimensions = speedArrayDims,
#ifdef WITH_AUTOPILOT
.getter.getArray = (void * (*)(void))getSpeedArray,
#endif
},
{
.name = "message",
.description = "Message to send to the other drones",
.value = &message,
.type = UA_TYPES_STRING,
.builtInType = UA_NS0ID_STRING,
.valueRank = UA_VALUERANK_SCALAR,
.arrayDimensionsSize = 0,
.arrayDimensions = NULL,
.getter.getString = get_message,
},
};
VariableStruct droneVariables = {
.nbVariable = DRONE_VARIABLE_NB,
.variableArray = droneVariableArray,
};
VariableData subscriberVariableArray[] = {
{
.name = "message",
.description = "Message to send to the other drones",
.value = &message,
.type = UA_TYPES_STRING,
.builtInType = UA_NS0ID_STRING,
.valueRank = UA_VALUERANK_SCALAR,
.arrayDimensionsSize = 0,
.arrayDimensions = NULL,
.getter.getString = get_message,
},
};
VariableStruct subscriberVariables = {
.nbVariable = SUBSCRIBER_VARIABLE_NB,
.variableArray = subscriberVariableArray,
};
static JSClassID jsDroneClassId; static JSClassID jsDroneClassId;
static JSClassID jsPositionClassId; static JSClassID jsPositionClassId;
...@@ -33,12 +126,13 @@ static void js_position_finalizer(JSRuntime *rt, JSValue val) ...@@ -33,12 +126,13 @@ static void js_position_finalizer(JSRuntime *rt, JSValue val)
js_free_rt(rt, s); js_free_rt(rt, s);
} }
#ifdef WITH_AUTOPILOT
static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal, static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
JSPositionData *s; JSPositionData *s;
JSValue obj; JSValue obj;
UA_Int64 *positionArray; UA_Int64 *newPositionArray;
obj = JS_NewObjectClass(ctx, (int) jsPositionClassId); obj = JS_NewObjectClass(ctx, (int) jsPositionClassId);
if (JS_IsException(obj)) if (JS_IsException(obj))
return obj; return obj;
...@@ -47,15 +141,16 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal, ...@@ -47,15 +141,16 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal,
JS_FreeValue(ctx, obj); JS_FreeValue(ctx, obj);
return JS_EXCEPTION; return JS_EXCEPTION;
} }
positionArray = getPositionArray(); newPositionArray = getPositionArray();
s->x = (double)positionArray[0] / 1e7; s->x = (double)newPositionArray[LATITUDE] / 1e7;
s->y = (double)positionArray[1] / 1e7; s->y = (double)newPositionArray[LONGITUDE] / 1e7;
s->z = (UA_Double)(positionArray[3] / 1000); //relative altitude s->z = (UA_Double)(newPositionArray[REL_ALTITUDE] / 1000);
s->timestamp = positionArray[4]; s->timestamp = newPositionArray[TIMESTAMP];
JS_SetOpaque(obj, s); JS_SetOpaque(obj, s);
free(positionArray); free(newPositionArray);
return obj; return obj;
} }
#endif
static JSValue js_position_get(JSContext *ctx, JSValueConst thisVal, int magic) static JSValue js_position_get(JSContext *ctx, JSValueConst thisVal, int magic)
{ {
...@@ -381,19 +476,19 @@ static void setDroneDataStr(void *data, char *str) ...@@ -381,19 +476,19 @@ static void setDroneDataStr(void *data, char *str)
static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool print) static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool print)
{ {
JSDroneData* s; JSDroneData* s;
UA_Int64* positionArray; UA_Int64* updatedPositionArray;
UA_Float* speedArray; UA_Float* updatedSpeedArray;
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_Int64*) var->value.data; updatedPositionArray = (UA_Int64*) var->value.data;
s->latitude = (double)positionArray[0] / 1e7; s->latitude = (double)updatedPositionArray[LATITUDE] / 1e7;
s->longitude = (double)positionArray[1] / 1e7; s->longitude = (double)updatedPositionArray[LONGITUDE] / 1e7;
s->altitudeAbs = (UA_Double)(positionArray[2] / 1000); s->altitudeAbs = (UA_Double)(updatedPositionArray[ABS_ALTITUDE] / 1000);
s->altitudeRel = (UA_Double)(positionArray[3] / 1000); s->altitudeRel = (UA_Double)(updatedPositionArray[REL_ALTITUDE] / 1000);
s->timestamp = positionArray[4]; s->timestamp = updatedPositionArray[TIMESTAMP];
if (print) { if (print) {
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT,
...@@ -402,10 +497,10 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool ...@@ -402,10 +497,10 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool
} }
return; return;
} else if (s->speedArrayId == id) { } else if (s->speedArrayId == id) {
speedArray = (UA_Float*) var->value.data; updatedSpeedArray = (UA_Float*) var->value.data;
s->yaw = speedArray[0]; s->yaw = updatedSpeedArray[YAW];
s->speed = speedArray[1]; s->speed = updatedSpeedArray[SPEED];
s->climbRate = speedArray[2]; s->climbRate = updatedSpeedArray[CLIMB_RATE];
if (print) { if (print) {
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT,
...@@ -537,7 +632,7 @@ static JSValue js_stop_pubsub(JSContext *ctx, JSValueConst thisVal, ...@@ -537,7 +632,7 @@ static JSValue js_stop_pubsub(JSContext *ctx, JSValueConst thisVal,
} }
// Connexion management functions // Connexion management functions
#ifdef WITH_AUTOPILOT
static JSValue js_start(JSContext *ctx, JSValueConst thisVal, static JSValue js_start(JSContext *ctx, JSValueConst thisVal,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
...@@ -738,11 +833,14 @@ static JSValue js_updateLogAndProjection(JSContext *ctx, JSValueConst this_val, ...@@ -738,11 +833,14 @@ static JSValue js_updateLogAndProjection(JSContext *ctx, JSValueConst this_val,
updateLogAndProjection(); updateLogAndProjection();
return JS_NewInt32(ctx, 0); return JS_NewInt32(ctx, 0);
} }
#endif
static const JSCFunctionListEntry js_funcs[] = { static const JSCFunctionListEntry js_funcs[] = {
JS_CFUNC_DEF("setMessage", 1, js_drone_set_message ), JS_CFUNC_DEF("setMessage", 1, js_drone_set_message ),
JS_CFUNC_DEF("runPubsub", 6, js_run_pubsub ), JS_CFUNC_DEF("runPubsub", 6, js_run_pubsub ),
JS_CFUNC_DEF("stopPubsub", 0, js_stop_pubsub ), JS_CFUNC_DEF("stopPubsub", 0, js_stop_pubsub ),
JS_CFUNC_DEF("initPubsub", 2, js_init_pubsub ),
#ifdef WITH_AUTOPILOT
JS_CFUNC_DEF("start", 6, js_start ), JS_CFUNC_DEF("start", 6, js_start ),
JS_CFUNC_DEF("stop", 0, js_stop ), JS_CFUNC_DEF("stop", 0, js_stop ),
JS_CFUNC_DEF("reboot", 0, js_reboot ), JS_CFUNC_DEF("reboot", 0, js_reboot ),
...@@ -765,8 +863,8 @@ static const JSCFunctionListEntry js_funcs[] = { ...@@ -765,8 +863,8 @@ static const JSCFunctionListEntry js_funcs[] = {
JS_CFUNC_DEF("gpsIsOk", 0, js_gpsIsOk ), JS_CFUNC_DEF("gpsIsOk", 0, js_gpsIsOk ),
JS_CFUNC_DEF("isLanding", 0, js_isLanding ), JS_CFUNC_DEF("isLanding", 0, js_isLanding ),
JS_CFUNC_DEF("healthAllOk", 0, js_healthAllOk ), JS_CFUNC_DEF("healthAllOk", 0, js_healthAllOk ),
JS_CFUNC_DEF("initPubsub", 2, js_init_pubsub ),
JS_CFUNC_DEF("updateLogAndProjection", 0, js_updateLogAndProjection ), JS_CFUNC_DEF("updateLogAndProjection", 0, js_updateLogAndProjection ),
#endif
}; };
static int js_init(JSContext *ctx, JSModuleDef *m) static int js_init(JSContext *ctx, JSModuleDef *m)
......
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