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

Update API for multicopters

Update API to be convenient for both fix-wings and multicopters
parent 7165e6d6
...@@ -17,13 +17,13 @@ DLL_PUBLIC int reboot(void); ...@@ -17,13 +17,13 @@ DLL_PUBLIC int reboot(void);
// Flight state management functions // Flight state management functions
DLL_PUBLIC int arm(void); DLL_PUBLIC int arm(void);
DLL_PUBLIC int takeOff(void); DLL_PUBLIC int takeOff(void);
DLL_PUBLIC int takeOffAndWait(void); DLL_PUBLIC int land(void);
DLL_PUBLIC int triggerParachute(void);
// Flight management functions // Flight management functions
DLL_PUBLIC void loiter(double la, double lo, float a, float radius); DLL_PUBLIC void loiter(double latitude, double longitude, float altitude,
DLL_PUBLIC void setAirSpeed_async(float airspeed); float radius, float speed);
DLL_PUBLIC void setTargetCoordinates(double la, double lo, float a); DLL_PUBLIC void setTargetCoordinates(double latitude, double longitude,
float altitude, float speed);
// Information functions // Information functions
DLL_PUBLIC float getAltitude(void); DLL_PUBLIC float getAltitude(void);
...@@ -37,7 +37,7 @@ DLL_PUBLIC float getYaw(void); ...@@ -37,7 +37,7 @@ DLL_PUBLIC float getYaw(void);
DLL_PUBLIC float getSpeed(void); DLL_PUBLIC float getSpeed(void);
DLL_PUBLIC float getClimbRate(void); DLL_PUBLIC float getClimbRate(void);
DLL_PUBLIC int gpsIsOk(void); DLL_PUBLIC int gpsIsOk(void);
DLL_PUBLIC int healthAllOk(void); DLL_PUBLIC int isReadyToFly(void);
DLL_PUBLIC int isLanding(void); DLL_PUBLIC int isLanding(void);
DLL_PUBLIC void updateLogAndProjection(void); DLL_PUBLIC void updateLogAndProjection(void);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -394,7 +394,8 @@ static const JSCFunctionListEntry js_drone_proto_funcs[] = { ...@@ -394,7 +394,8 @@ static const JSCFunctionListEntry js_drone_proto_funcs[] = {
// pubsub functions // pubsub functions
UA_UInt16 get_drone_id(UA_UInt32 nb) { UA_UInt16 get_drone_id(UA_UInt32 nb) {
JSDroneData *s = (JSDroneData *) JS_GetOpaque(droneObjectIdList[nb], jsDroneClassId); JSDroneData *s =
(JSDroneData *) JS_GetOpaque(droneObjectIdList[nb], jsDroneClassId);
return s->id; return s->id;
} }
...@@ -411,10 +412,12 @@ VariableData pubsub_get_value(UA_String identifier) { ...@@ -411,10 +412,12 @@ VariableData pubsub_get_value(UA_String identifier) {
case UA_VALUERANK_SCALAR: case UA_VALUERANK_SCALAR:
switch(varDetails.type) { switch(varDetails.type) {
case UA_TYPES_STRING: case UA_TYPES_STRING:
*(UA_String*)varDetails.value = varDetails.getter.getString(); *(UA_String*)varDetails.value =
varDetails.getter.getString();
break; break;
default: default:
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "UA_TYPE not handled"); UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
"UA_TYPE not handled");
break; break;
} }
break; break;
...@@ -436,14 +439,16 @@ VariableData pubsub_get_value(UA_String identifier) { ...@@ -436,14 +439,16 @@ VariableData pubsub_get_value(UA_String identifier) {
ptrd += type.memSize; ptrd += type.memSize;
} }
if(retval != UA_STATUSCODE_GOOD) if(retval != UA_STATUSCODE_GOOD)
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Failed to update array"); UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
"Failed to update array");
} }
free(array); free(array);
break; break;
default: default:
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "UA_VALUERANK not handled"); UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
"UA_VALUERANK not handled");
break; break;
} }
} }
...@@ -452,8 +457,15 @@ VariableData pubsub_get_value(UA_String identifier) { ...@@ -452,8 +457,15 @@ VariableData pubsub_get_value(UA_String identifier) {
return varDetails; return varDetails;
} }
static JSDroneData* getJSDroneData(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic)
{
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT,
"Getting field %d of peer %d for node id %d", magic, nb, id);
return (JSDroneData *) JS_GetOpaque(droneObjectIdList[nb], jsDroneClassId);
}
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) {
JSDroneData *s = (JSDroneData *) JS_GetOpaque(droneObjectIdList[nb], jsDroneClassId); JSDroneData *s = getJSDroneData(id, nb, magic);
switch(magic) { switch(magic) {
case 0: case 0:
s->positionArrayId = id; s->positionArrayId = id;
...@@ -468,19 +480,21 @@ void init_drone_node_id(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic) { ...@@ -468,19 +480,21 @@ void init_drone_node_id(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic) {
s->logId = id; s->logId = id;
break; break;
default: default:
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Unknown variable id"); UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
"Unknown variable id");
break; break;
} }
} }
void init_subscriber_node_id(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic) { void init_subscriber_node_id(UA_UInt32 id, UA_UInt32 nb, UA_UInt32 magic) {
JSDroneData *s = (JSDroneData *) JS_GetOpaque(droneObjectIdList[nb], jsDroneClassId); JSDroneData *s = getJSDroneData(id, nb, magic);
switch(magic) { switch(magic) {
case 0: case 0:
s->messageId = id; s->messageId = id;
break; break;
default: default:
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "Unknown variable id"); UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
"Unknown variable id");
break; break;
} }
} }
...@@ -542,7 +556,8 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool ...@@ -542,7 +556,8 @@ static void pubsub_update_variables(UA_UInt32 id, const UA_DataValue *var, bool
return; return;
} }
} }
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, "NodeId not found"); UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT,
"NodeId %i not found", id);
} }
/* /*
...@@ -707,16 +722,10 @@ static JSValue js_takeOff(JSContext *ctx, JSValueConst thisVal, ...@@ -707,16 +722,10 @@ static JSValue js_takeOff(JSContext *ctx, JSValueConst thisVal,
return JS_NewInt32(ctx, takeOff()); return JS_NewInt32(ctx, takeOff());
} }
static JSValue js_takeOffAndWait(JSContext *ctx, JSValueConst thisVal, static JSValue js_land(JSContext *ctx, JSValueConst thisVal,
int argc, JSValueConst *argv)
{
return JS_NewInt32(ctx, takeOffAndWait());
}
static JSValue js_triggerParachute(JSContext *ctx, JSValueConst thisVal,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
return JS_NewInt32(ctx, triggerParachute()); return JS_NewInt32(ctx, land());
} }
// Flight management functions // Flight management functions
...@@ -724,33 +733,24 @@ static JSValue js_triggerParachute(JSContext *ctx, JSValueConst thisVal, ...@@ -724,33 +733,24 @@ static JSValue js_triggerParachute(JSContext *ctx, JSValueConst thisVal,
static JSValue js_loiter(JSContext *ctx, JSValueConst thisVal, static JSValue js_loiter(JSContext *ctx, JSValueConst thisVal,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
double la_arg_double; double latitude;
double lo_arg_double; double longitude;
double a_arg_double; double altitude;
double radius; double radius;
double speed;
if (JS_ToFloat64(ctx, &la_arg_double, argv[0])) if (JS_ToFloat64(ctx, &latitude, argv[0]))
return JS_EXCEPTION; return JS_EXCEPTION;
if (JS_ToFloat64(ctx, &lo_arg_double, argv[1])) if (JS_ToFloat64(ctx, &longitude, argv[1]))
return JS_EXCEPTION; return JS_EXCEPTION;
if (JS_ToFloat64(ctx, &a_arg_double, argv[2])) if (JS_ToFloat64(ctx, &altitude, argv[2]))
return JS_EXCEPTION; return JS_EXCEPTION;
if (JS_ToFloat64(ctx, &radius, argv[3])) if (JS_ToFloat64(ctx, &radius, argv[3]))
return JS_EXCEPTION; return JS_EXCEPTION;
if (JS_ToFloat64(ctx, &speed, argv[4]))
loiter(la_arg_double, lo_arg_double, (float)a_arg_double, (float)radius);
return JS_NewInt32(ctx, 0);
}
static JSValue js_setAirSpeed(JSContext *ctx, JSValueConst thisVal,
int argc, JSValueConst *argv)
{
double altitude;
if (JS_ToFloat64(ctx, &altitude, argv[0]))
return JS_EXCEPTION; return JS_EXCEPTION;
setAirSpeed_async((float)altitude); loiter(latitude, longitude, (float)altitude, (float)radius, (float)speed);
return JS_NewInt32(ctx, 0); return JS_NewInt32(ctx, 0);
} }
...@@ -758,18 +758,21 @@ static JSValue js_setTargetCoordinates(JSContext *ctx, ...@@ -758,18 +758,21 @@ static JSValue js_setTargetCoordinates(JSContext *ctx,
JSValueConst thisVal, JSValueConst thisVal,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
double la_arg_double; double latitude;
double lo_arg_double; double longitude;
double a_arg_double; double altitude;
double speed;
if (JS_ToFloat64(ctx, &la_arg_double, argv[0])) if (JS_ToFloat64(ctx, &latitude, argv[0]))
return JS_EXCEPTION;
if (JS_ToFloat64(ctx, &longitude, argv[1]))
return JS_EXCEPTION; return JS_EXCEPTION;
if (JS_ToFloat64(ctx, &lo_arg_double, argv[1])) if (JS_ToFloat64(ctx, &altitude, argv[2]))
return JS_EXCEPTION; return JS_EXCEPTION;
if (JS_ToFloat64(ctx, &a_arg_double, argv[2])) if (JS_ToFloat64(ctx, &speed, argv[3]))
return JS_EXCEPTION; return JS_EXCEPTION;
setTargetCoordinates(la_arg_double, lo_arg_double, (float)a_arg_double); setTargetCoordinates(latitude, longitude, (float)altitude, (float)speed);
return JS_NewInt32(ctx, 0); return JS_NewInt32(ctx, 0);
} }
...@@ -833,10 +836,10 @@ static JSValue js_gpsIsOk(JSContext *ctx, JSValueConst this_val, ...@@ -833,10 +836,10 @@ static JSValue js_gpsIsOk(JSContext *ctx, JSValueConst this_val,
return JS_NewBool(ctx, gpsIsOk()); return JS_NewBool(ctx, gpsIsOk());
} }
static JSValue js_healthAllOk(JSContext *ctx, JSValueConst this_val, static JSValue js_isReadyToFly(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
return JS_NewBool(ctx, healthAllOk()); return JS_NewBool(ctx, isReadyToFly());
} }
static JSValue js_isLanding(JSContext *ctx, JSValueConst this_val, static JSValue js_isLanding(JSContext *ctx, JSValueConst this_val,
...@@ -865,11 +868,9 @@ static const JSCFunctionListEntry js_funcs[] = { ...@@ -865,11 +868,9 @@ static const JSCFunctionListEntry js_funcs[] = {
JS_CFUNC_DEF("reboot", 0, js_reboot ), JS_CFUNC_DEF("reboot", 0, js_reboot ),
JS_CFUNC_DEF("arm", 0, js_arm ), JS_CFUNC_DEF("arm", 0, js_arm ),
JS_CFUNC_DEF("takeOff", 0, js_takeOff ), JS_CFUNC_DEF("takeOff", 0, js_takeOff ),
JS_CFUNC_DEF("takeOffAndWait", 0, js_takeOffAndWait ), JS_CFUNC_DEF("land", 0, js_land ),
JS_CFUNC_DEF("triggerParachute", 0, js_triggerParachute ), JS_CFUNC_DEF("loiter", 5, js_loiter ),
JS_CFUNC_DEF("loiter", 4, js_loiter ), JS_CFUNC_DEF("setTargetCoordinates", 4, js_setTargetCoordinates ),
JS_CFUNC_DEF("setAirSpeed", 1, js_setAirSpeed ),
JS_CFUNC_DEF("setTargetCoordinates", 3, js_setTargetCoordinates ),
JS_CFUNC_DEF("getPosition", 0, js_new_position ), JS_CFUNC_DEF("getPosition", 0, js_new_position ),
JS_CFUNC_DEF("getAltitude", 0, js_getAltitude ), JS_CFUNC_DEF("getAltitude", 0, js_getAltitude ),
JS_CFUNC_DEF("getInitialAltitude", 0, js_getInitialAltitude ), JS_CFUNC_DEF("getInitialAltitude", 0, js_getInitialAltitude ),
...@@ -877,11 +878,11 @@ static const JSCFunctionListEntry js_funcs[] = { ...@@ -877,11 +878,11 @@ static const JSCFunctionListEntry js_funcs[] = {
JS_CFUNC_DEF("getInitialLongitude", 0, js_getInitialLongitude ), JS_CFUNC_DEF("getInitialLongitude", 0, js_getInitialLongitude ),
JS_CFUNC_DEF("getTakeOffAltitude", 0, js_getTakeOffAltitude ), JS_CFUNC_DEF("getTakeOffAltitude", 0, js_getTakeOffAltitude ),
JS_CFUNC_DEF("getYaw", 0, js_getYaw ), JS_CFUNC_DEF("getYaw", 0, js_getYaw ),
JS_CFUNC_DEF("getAirspeed", 0, js_getSpeed ), JS_CFUNC_DEF("getSpeed", 0, js_getSpeed ),
JS_CFUNC_DEF("getClimbRate", 0, js_getClimbRate ), JS_CFUNC_DEF("getClimbRate", 0, js_getClimbRate ),
JS_CFUNC_DEF("gpsIsOk", 0, js_gpsIsOk ), JS_CFUNC_DEF("gpsIsOk", 0, js_gpsIsOk ),
JS_CFUNC_DEF("isReadyToFly", 0, js_isReadyToFly ),
JS_CFUNC_DEF("isLanding", 0, js_isLanding ), JS_CFUNC_DEF("isLanding", 0, js_isLanding ),
JS_CFUNC_DEF("healthAllOk", 0, js_healthAllOk ),
JS_CFUNC_DEF("updateLogAndProjection", 0, js_updateLogAndProjection ), JS_CFUNC_DEF("updateLogAndProjection", 0, js_updateLogAndProjection ),
#endif #endif
}; };
......
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