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

Split ip and port parameters

parent 85268917
...@@ -20,7 +20,7 @@ extern "C" { ...@@ -20,7 +20,7 @@ extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
// Connexion management functions // Connexion management functions
int mavsdk_start(const char * url, const char * log_file, int timeout); int mavsdk_start(const char * ip, int port, const char * log_file, int timeout);
int mavsdk_stop(void); int mavsdk_stop(void);
int mavsdk_reboot(void); int mavsdk_reboot(void);
......
...@@ -92,7 +92,9 @@ static double toDeg(double angle) { ...@@ -92,7 +92,9 @@ static double toDeg(double angle) {
return 180 * angle / M_PI; return 180 * angle / M_PI;
} }
int mavsdk_start(const char * url, const char * log_file, int timeout) { int mavsdk_start(const char * ip, int port, const char * log_file, int timeout) {
char url[32];
sprintf(url, "udp://%s:%d", ip , port);
std::string connection_url(url); std::string connection_url(url);
ConnectionResult connection_result; ConnectionResult connection_result;
float abs_altitude; float abs_altitude;
......
...@@ -405,18 +405,21 @@ static JSValue js_stop_pubsub(JSContext *ctx, JSValueConst thisVal, ...@@ -405,18 +405,21 @@ static JSValue js_stop_pubsub(JSContext *ctx, JSValueConst thisVal,
static JSValue js_mavsdk_start(JSContext *ctx, JSValueConst thisVal, static JSValue js_mavsdk_start(JSContext *ctx, JSValueConst thisVal,
int argc, JSValueConst *argv) int argc, JSValueConst *argv)
{ {
const char *url; const char *ip;
const char *log_file; const char *log_file;
int port;
int timeout; int timeout;
int res; int res;
url = JS_ToCString(ctx, argv[0]); ip = JS_ToCString(ctx, argv[0]);
log_file = JS_ToCString(ctx, argv[1]); if (JS_ToInt32(ctx, &port, argv[1]))
if (JS_ToInt32(ctx, &timeout, argv[2])) return JS_EXCEPTION;
log_file = JS_ToCString(ctx, argv[2]);
if (JS_ToInt32(ctx, &timeout, argv[3]))
return JS_EXCEPTION; return JS_EXCEPTION;
res = mavsdk_start(url, log_file, timeout); res = mavsdk_start(ip, port, log_file, timeout);
JS_FreeCString(ctx, url); JS_FreeCString(ctx, ip);
JS_FreeCString(ctx, log_file); JS_FreeCString(ctx, log_file);
return JS_NewInt32(ctx, res); return JS_NewInt32(ctx, res);
...@@ -591,7 +594,7 @@ static const JSCFunctionListEntry js_mavsdk_funcs[] = { ...@@ -591,7 +594,7 @@ static const JSCFunctionListEntry js_mavsdk_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("start", 3, js_mavsdk_start ), JS_CFUNC_DEF("start", 4, js_mavsdk_start ),
JS_CFUNC_DEF("stop", 0, js_mavsdk_stop ), JS_CFUNC_DEF("stop", 0, js_mavsdk_stop ),
JS_CFUNC_DEF("reboot", 0, js_mavsdk_reboot ), JS_CFUNC_DEF("reboot", 0, js_mavsdk_reboot ),
JS_CFUNC_DEF("arm", 0, js_mavsdk_arm ), JS_CFUNC_DEF("arm", 0, js_mavsdk_arm ),
......
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