Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
qjs-wrapper
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
qjs-wrapper
Commits
37a13ee9
Commit
37a13ee9
authored
Jan 10, 2024
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if autopilot API is required
parent
1ab8f5a4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
168 additions
and
149 deletions
+168
-149
Makefile
Makefile
+6
-1
include/autopilot_API.h
include/autopilot_API.h
+3
-18
include/dronedge.h
include/dronedge.h
+0
-103
include/dronedge_protocol.h
include/dronedge_protocol.h
+35
-0
include/pubsub.h
include/pubsub.h
+3
-4
qjs_wrapper.c
qjs_wrapper.c
+121
-23
No files found.
Makefile
View file @
37a13ee9
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
...
...
include/autopilot_
wrapper
.h
→
include/autopilot_
API
.h
View file @
37a13ee9
#ifndef __AUTOPILOT_H__
#define __AUTOPILOT_H__
#ifndef __AUTOPILOT_
API_
H__
#define __AUTOPILOT_
API_
H__
#ifndef DLL_PUBLIC
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
#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
extern
"C"
{
#endif
...
...
@@ -59,4 +44,4 @@ DLL_PUBLIC void updateLogAndProjection(void);
}
#endif
#endif
/* __AUTOPILOT_H__ */
#endif
/* __AUTOPILOT_
_API_
H__ */
include/dronedge.h
deleted
100644 → 0
View file @
1ab8f5a4
#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__ */
include/dronedge_protocol.h
0 → 100644
View file @
37a13ee9
#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__ */
include/pubsub.h
View file @
37a13ee9
...
...
@@ -31,8 +31,6 @@ typedef struct {
UA_Float
climbRate
;
char
message
[
MAX_MESSAGE_SIZE
];
UA_UInt32
messageId
;
char
log
[
MAX_MESSAGE_SIZE
];
UA_UInt32
logId
;
}
JSDroneData
;
typedef
struct
{
...
...
@@ -81,8 +79,6 @@ int runPubsub(const UA_Logger *logger, UA_String *transportProfile,
UA_String
get_message
(
void
);
UA_String
get_log
(
void
);
UA_UInt16
get_drone_id
(
UA_UInt32
nb
);
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);
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__ */
qjs_wrapper.c
View file @
37a13ee9
#include <math.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
jsPositionClassId
;
...
...
@@ -33,12 +126,13 @@ static void js_position_finalizer(JSRuntime *rt, JSValue val)
js_free_rt
(
rt
,
s
);
}
#ifdef WITH_AUTOPILOT
static
JSValue
js_new_position
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
{
JSPositionData
*
s
;
JSValue
obj
;
UA_Int64
*
p
ositionArray
;
UA_Int64
*
newP
ositionArray
;
obj
=
JS_NewObjectClass
(
ctx
,
(
int
)
jsPositionClassId
);
if
(
JS_IsException
(
obj
))
return
obj
;
...
...
@@ -47,15 +141,16 @@ static JSValue js_new_position(JSContext *ctx, JSValueConst thisVal,
JS_FreeValue
(
ctx
,
obj
);
return
JS_EXCEPTION
;
}
p
ositionArray
=
getPositionArray
();
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
];
newP
ositionArray
=
getPositionArray
();
s
->
x
=
(
double
)
newPositionArray
[
LATITUDE
]
/
1e7
;
s
->
y
=
(
double
)
newPositionArray
[
LONGITUDE
]
/
1e7
;
s
->
z
=
(
UA_Double
)(
newPositionArray
[
REL_ALTITUDE
]
/
1000
);
s
->
timestamp
=
newPositionArray
[
TIMESTAMP
];
JS_SetOpaque
(
obj
,
s
);
free
(
p
ositionArray
);
free
(
newP
ositionArray
);
return
obj
;
}
#endif
static
JSValue
js_position_get
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
magic
)
{
...
...
@@ -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
)
{
JSDroneData
*
s
;
UA_Int64
*
p
ositionArray
;
UA_Float
*
s
peedArray
;
JSDroneData
*
s
;
UA_Int64
*
updatedP
ositionArray
;
UA_Float
*
updatedS
peedArray
;
for
(
UA_UInt32
i
=
0
;
i
<
nbDrone
+
nbSubscriber
;
i
++
)
{
s
=
(
JSDroneData
*
)
JS_GetOpaque
(
droneObjectIdList
[
i
],
jsDroneClassId
);
if
(
s
->
positionArrayId
==
id
)
{
p
ositionArray
=
(
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
];
updatedP
ositionArray
=
(
UA_Int64
*
)
var
->
value
.
data
;
s
->
latitude
=
(
double
)
updatedPositionArray
[
LATITUDE
]
/
1e7
;
s
->
longitude
=
(
double
)
updatedPositionArray
[
LONGITUDE
]
/
1e7
;
s
->
altitudeAbs
=
(
UA_Double
)(
updatedPositionArray
[
ABS_ALTITUDE
]
/
1000
);
s
->
altitudeRel
=
(
UA_Double
)(
updatedPositionArray
[
REL_ALTITUDE
]
/
1000
);
s
->
timestamp
=
updatedPositionArray
[
TIMESTAMP
];
if
(
print
)
{
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
}
return
;
}
else
if
(
s
->
speedArrayId
==
id
)
{
s
peedArray
=
(
UA_Float
*
)
var
->
value
.
data
;
s
->
yaw
=
speedArray
[
0
];
s
->
speed
=
speedArray
[
1
];
s
->
climbRate
=
speedArray
[
2
];
updatedS
peedArray
=
(
UA_Float
*
)
var
->
value
.
data
;
s
->
yaw
=
updatedSpeedArray
[
YAW
];
s
->
speed
=
updatedSpeedArray
[
SPEED
];
s
->
climbRate
=
updatedSpeedArray
[
CLIMB_RATE
];
if
(
print
)
{
UA_LOG_INFO
(
UA_Log_Stdout
,
UA_LOGCATEGORY_CLIENT
,
...
...
@@ -537,7 +632,7 @@ static JSValue js_stop_pubsub(JSContext *ctx, JSValueConst thisVal,
}
// Connexion management functions
#ifdef WITH_AUTOPILOT
static
JSValue
js_start
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
{
...
...
@@ -738,11 +833,14 @@ static JSValue js_updateLogAndProjection(JSContext *ctx, JSValueConst this_val,
updateLogAndProjection
();
return
JS_NewInt32
(
ctx
,
0
);
}
#endif
static
const
JSCFunctionListEntry
js_funcs
[]
=
{
JS_CFUNC_DEF
(
"setMessage"
,
1
,
js_drone_set_message
),
JS_CFUNC_DEF
(
"runPubsub"
,
6
,
js_run_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
(
"stop"
,
0
,
js_stop
),
JS_CFUNC_DEF
(
"reboot"
,
0
,
js_reboot
),
...
...
@@ -765,8 +863,8 @@ static const JSCFunctionListEntry js_funcs[] = {
JS_CFUNC_DEF
(
"gpsIsOk"
,
0
,
js_gpsIsOk
),
JS_CFUNC_DEF
(
"isLanding"
,
0
,
js_isLanding
),
JS_CFUNC_DEF
(
"healthAllOk"
,
0
,
js_healthAllOk
),
JS_CFUNC_DEF
(
"initPubsub"
,
2
,
js_init_pubsub
),
JS_CFUNC_DEF
(
"updateLogAndProjection"
,
0
,
js_updateLogAndProjection
),
#endif
};
static
int
js_init
(
JSContext
*
ctx
,
JSModuleDef
*
m
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment