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
fdde4519
Commit
fdde4519
authored
Aug 30, 2023
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add position class
Return a position object instead of using various getters.
parent
906bf07f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
22 deletions
+74
-22
include/pubsub.h
include/pubsub.h
+6
-0
qjs_wrapper.c
qjs_wrapper.c
+68
-22
No files found.
include/pubsub.h
View file @
fdde4519
...
...
@@ -32,6 +32,12 @@ typedef struct {
UA_UInt32
messageId
;
}
JSDroneData
;
typedef
struct
{
UA_Double
x
;
UA_Double
y
;
UA_Double
z
;
}
JSPositionData
;
typedef
struct
{
char
*
name
;
char
*
typeName
;
...
...
qjs_wrapper.c
View file @
fdde4519
...
...
@@ -10,6 +10,7 @@
# define ANSI_COLOR_RESET "\x1b[0m"
static
JSClassID
jsDroneClassId
;
static
JSClassID
jsPositionClassId
;
static
UA_Boolean
pubsubShouldRun
=
true
;
static
UA_Boolean
pubsubExited
=
true
;
...
...
@@ -42,6 +43,65 @@ const char *logCategoryNames[10] =
{
"network"
,
"channel"
,
"session"
,
"server"
,
"client"
,
"userland"
,
"securitypolicy"
,
"eventloop"
,
"pubsub"
,
"discovery"
};
// Position class functions
static
void
js_position_finalizer
(
JSRuntime
*
rt
,
JSValue
val
)
{
JSPositionData
*
s
=
(
JSPositionData
*
)
JS_GetOpaque
(
val
,
jsPositionClassId
);
js_free_rt
(
rt
,
s
);
}
static
JSValue
js_new_position
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
{
JSPositionData
*
s
;
JSValue
obj
;
UA_Double
*
positionArray
;
obj
=
JS_NewObjectClass
(
ctx
,
(
int
)
jsPositionClassId
);
if
(
JS_IsException
(
obj
))
return
obj
;
s
=
(
JSPositionData
*
)
js_mallocz
(
ctx
,
sizeof
(
*
s
));
if
(
!
s
)
{
JS_FreeValue
(
ctx
,
obj
);
return
JS_EXCEPTION
;
}
positionArray
=
getPositionArray
();
s
->
x
=
positionArray
[
0
];
s
->
y
=
positionArray
[
1
];
s
->
z
=
positionArray
[
3
];
//relative altitude
JS_SetOpaque
(
obj
,
s
);
free
(
positionArray
);
return
obj
;
}
static
JSValue
js_position_get
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
magic
)
{
JSPositionData
*
s
=
(
JSPositionData
*
)
JS_GetOpaque2
(
ctx
,
thisVal
,
jsPositionClassId
);
if
(
!
s
)
return
JS_EXCEPTION
;
switch
(
magic
)
{
case
0
:
return
JS_NewFloat64
(
ctx
,
s
->
x
);
case
1
:
return
JS_NewFloat64
(
ctx
,
s
->
y
);
case
2
:
return
JS_NewFloat64
(
ctx
,
s
->
z
);
default:
return
JS_EXCEPTION
;
}
}
static
JSClassDef
jsPositionClass
=
{
"Position"
,
.
finalizer
=
js_position_finalizer
,
};
static
const
JSCFunctionListEntry
js_position_proto_funcs
[]
=
{
JS_CGETSET_MAGIC_DEF
(
"x"
,
js_position_get
,
NULL
,
0
),
JS_CGETSET_MAGIC_DEF
(
"y"
,
js_position_get
,
NULL
,
1
),
JS_CGETSET_MAGIC_DEF
(
"z"
,
js_position_get
,
NULL
,
2
),
};
// Drone class functions
static
void
js_drone_finalizer
(
JSRuntime
*
rt
,
JSValue
val
)
...
...
@@ -626,12 +686,6 @@ static JSValue js_getAltitude(JSContext *ctx, JSValueConst thisVal,
return
JS_NewFloat64
(
ctx
,
getAltitude
());
}
static
JSValue
js_getAltitudeRel
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
{
return
JS_NewFloat64
(
ctx
,
getAltitudeRel
());
}
static
JSValue
js_getInitialAltitude
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
...
...
@@ -653,18 +707,6 @@ static JSValue js_getInitialLongitude(JSContext *ctx,
return
JS_NewFloat64
(
ctx
,
getInitialLongitude
());
}
static
JSValue
js_getLatitude
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
{
return
JS_NewFloat64
(
ctx
,
getLatitude
());
}
static
JSValue
js_getLongitude
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
{
return
JS_NewFloat64
(
ctx
,
getLongitude
());
}
static
JSValue
js_getTakeOffAltitude
(
JSContext
*
ctx
,
JSValueConst
thisVal
,
int
argc
,
JSValueConst
*
argv
)
...
...
@@ -716,13 +758,11 @@ static const JSCFunctionListEntry js_funcs[] = {
JS_CFUNC_DEF
(
"loiter"
,
4
,
js_loiter
),
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
(
"getAltitude"
,
0
,
js_getAltitude
),
JS_CFUNC_DEF
(
"getAltitudeRel"
,
0
,
js_getAltitudeRel
),
JS_CFUNC_DEF
(
"getInitialAltitude"
,
0
,
js_getInitialAltitude
),
JS_CFUNC_DEF
(
"getInitialLatitude"
,
0
,
js_getInitialLatitude
),
JS_CFUNC_DEF
(
"getInitialLongitude"
,
0
,
js_getInitialLongitude
),
JS_CFUNC_DEF
(
"getLatitude"
,
0
,
js_getLatitude
),
JS_CFUNC_DEF
(
"getLongitude"
,
0
,
js_getLongitude
),
JS_CFUNC_DEF
(
"getTakeOffAltitude"
,
0
,
js_getTakeOffAltitude
),
JS_CFUNC_DEF
(
"getYaw"
,
0
,
js_getYaw
),
JS_CFUNC_DEF
(
"getAirspeed"
,
0
,
js_getSpeed
),
...
...
@@ -735,19 +775,25 @@ static const JSCFunctionListEntry js_funcs[] = {
static
int
js_init
(
JSContext
*
ctx
,
JSModuleDef
*
m
)
{
JSValue
droneProto
,
droneClass
;
JSValue
droneProto
,
droneClass
,
positionProto
;
JS_NewClassID
(
&
jsDroneClassId
);
JS_NewClassID
(
&
jsPositionClassId
);
JS_NewClass
(
JS_GetRuntime
(
ctx
),
jsDroneClassId
,
&
jsDroneClass
);
JS_NewClass
(
JS_GetRuntime
(
ctx
),
jsPositionClassId
,
&
jsPositionClass
);
droneProto
=
JS_NewObject
(
ctx
);
JS_SetPropertyFunctionList
(
ctx
,
droneProto
,
js_drone_proto_funcs
,
countof
(
js_drone_proto_funcs
));
positionProto
=
JS_NewObject
(
ctx
);
JS_SetPropertyFunctionList
(
ctx
,
positionProto
,
js_position_proto_funcs
,
countof
(
js_position_proto_funcs
));
droneClass
=
JS_NewCFunction2
(
ctx
,
js_drone_ctor
,
"Drone"
,
1
,
JS_CFUNC_constructor
,
0
);
JS_SetConstructor
(
ctx
,
droneClass
,
droneProto
);
JS_SetClassProto
(
ctx
,
jsDroneClassId
,
droneProto
);
JS_SetClassProto
(
ctx
,
jsPositionClassId
,
positionProto
);
JS_SetModuleExport
(
ctx
,
m
,
"Drone"
,
droneClass
);
...
...
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