Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
0
Merge Requests
0
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
Léo-Paul Géneau
slapos
Commits
fa8c3c27
Commit
fa8c3c27
authored
May 31, 2023
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
software/js-drone: handle SIGTERM
parent
16d3c1ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
26 deletions
+50
-26
software/js-drone/buildout.hash.cfg
software/js-drone/buildout.hash.cfg
+2
-2
software/js-drone/main.js
software/js-drone/main.js
+15
-5
software/js-drone/worker.js
software/js-drone/worker.js
+33
-19
No files found.
software/js-drone/buildout.hash.cfg
View file @
fa8c3c27
...
...
@@ -26,7 +26,7 @@ md5sum = b1910416ffa6f2b6a84fd13cca6109ce
[main]
filename = main.js
md5sum = 8
1e692d3edcfe666bb4d7505b3375d8d
md5sum = 8
bc77ebd49e8e6fe060de507bccc44d5
[pubsub]
filename = pubsub.js
...
...
@@ -34,4 +34,4 @@ md5sum = 1555496ad591a31a845f33488d5c335d
[worker]
filename = worker.js
md5sum =
33f09ad15e70230054f00778e6f53f38
md5sum =
ccbdd75b2a58e8d92d7cb990f2565b37
software/js-drone/main.js
View file @
fa8c3c27
...
...
@@ -8,8 +8,8 @@ import {
stopPubsub
,
takeOffAndWait
}
from
{{
json_module
.
dumps
(
qjs_wrapper
)
}};
import
{
setTimeout
,
Worker
}
from
"
os
"
;
import
{
open
,
exit
}
from
"
std
"
;
import
{
Worker
,
SIGTERM
,
setTimeout
,
signal
}
from
"
os
"
;
import
{
exit
,
open
}
from
"
std
"
;
(
function
(
arm
,
console
,
exit
,
open
,
scriptArgs
,
setTimeout
,
start
,
stop
,
stopPubsub
,
takeOffAndWait
,
Worker
)
{
...
...
@@ -37,6 +37,7 @@ import { open, exit } from "std";
worker
=
new
Worker
(
"
{{ worker_script }}
"
);
function
quit
(
is_a_drone
,
exit_code
)
{
worker
.
onmessage
=
null
;
stopPubsub
();
if
(
is_a_drone
)
{
stop
();
...
...
@@ -44,10 +45,19 @@ import { open, exit } from "std";
exit
(
exit_code
);
}
function
exitWorker
(
exit_code
)
{
worker
.
postMessage
({
type
:
"
exit
"
,
code
:
exit_code
});
}
signal
(
SIGTERM
,
exitWorker
.
bind
(
null
,
0
));
function
exitOnFail
(
ret
,
msg
)
{
if
(
ret
)
{
console
.
log
(
msg
);
quit
(
1
);
exitWorker
(
1
);
}
}
...
...
@@ -87,7 +97,7 @@ import { open, exit } from "std";
// First argument must provide the user script path
if
(
user_script
===
undefined
)
{
console
.
log
(
'
Please provide the user_script path.
'
);
quit
(
1
);
exitWorker
(
1
);
}
worker
.
postMessage
({
...
...
@@ -144,7 +154,7 @@ import { open, exit } from "std";
quit
(
configuration
.
isADrone
,
e
.
data
.
exit
);
}
else
{
console
.
log
(
'
Unsupported message type
'
,
type
);
quit
(
configuration
.
isADrone
,
!
configuration
.
isASimulation
,
1
);
exitWorker
(
1
);
}
};
}(
arm
,
console
,
exit
,
open
,
scriptArgs
,
setTimeout
,
start
,
stop
,
stopPubsub
,
...
...
software/js-drone/worker.js
View file @
fa8c3c27
...
...
@@ -30,10 +30,10 @@ import {
setReadHandler
,
waitpid
}
from
"
os
"
;
import
{
evalScript
,
exit
,
fdopen
,
loadFile
,
open
}
from
"
std
"
;
import
{
evalScript
,
fdopen
,
loadFile
,
open
}
from
"
std
"
;
(
function
(
Drone
,
SIGTERM
,
WNOHANG
,
Worker
,
close
,
console
,
evalScript
,
exec
,
exit
,
fdopen
,
getAltitude
,
getAltitudeRel
,
getInitialAltitude
,
fdopen
,
getAltitude
,
getAltitudeRel
,
getInitialAltitude
,
getLatitude
,
getLongitude
,
getYaw
,
initPubsub
,
kill
,
loadFile
,
loiter
,
open
,
pipe
,
setAirspeed
,
setMessage
,
setReadHandler
,
setTargetCoordinates
,
triggerParachute
,
waitpid
)
{
...
...
@@ -55,13 +55,7 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
//required to fly
triggerParachute
:
triggerParachute
,
drone_dict
:
{},
exit
:
function
(
exit_code
)
{
parent
.
postMessage
({
type
:
"
exited
"
,
exit
:
exit_code
});
parent
.
onmessage
=
null
;
if
(
user_me
.
hasOwnProperty
(
"
onWebSocketMessage
"
))
{
stopGwsocket
();
}
},
exit
:
exitWorker
,
getAltitudeAbs
:
getAltitude
,
getCurrentPosition
:
function
()
{
return
{
...
...
@@ -89,7 +83,15 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
};
conf_file
.
close
();
function
readMessage
(
rd
)
{
function
exitWorker
(
exit_code
)
{
if
(
user_me
.
hasOwnProperty
(
"
onWebSocketMessage
"
))
{
stopGwsocket
();
}
parent
.
postMessage
({
type
:
"
exited
"
,
exit
:
exit_code
});
parent
.
onmessage
=
null
;
}
function
readMessage
(
rd
)
{
function
read4
()
{
var
b1
,
b2
,
b3
,
b4
;
b1
=
rd
.
getByte
();
...
...
@@ -175,7 +177,7 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
var
script_content
=
loadFile
(
path
);
if
(
script_content
===
null
)
{
console
.
log
(
"
Failed to load user script
"
+
path
);
exit
(
1
);
exit
Worker
(
1
);
}
try
{
evalScript
(
...
...
@@ -183,7 +185,7 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
);
}
catch
(
e
)
{
console
.
log
(
"
Failed to evaluate user script
"
,
e
);
exit
(
1
);
exit
Worker
(
1
);
}
execUserScript
(
null
,
user_me
);
...
...
@@ -200,7 +202,9 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
function
handleMainMessage
(
evt
)
{
var
type
=
evt
.
data
.
type
,
message
,
peer_id
;
if
(
type
===
"
initPubsub
"
)
{
switch
(
type
)
{
case
"
initPubsub
"
:
initPubsub
(
configuration
.
numberOfDrone
,
configuration
.
numberOfSubscriber
);
for
(
peer_id
=
0
;
peer_id
<
configuration
.
numberOfDrone
+
configuration
.
numberOfSubscriber
;
peer_id
++
)
{
peer_dict
[
peer_id
]
=
new
Drone
(
peer_id
);
...
...
@@ -210,10 +214,14 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
}
}
parent
.
postMessage
({
type
:
"
initialized
"
});
}
else
if
(
type
===
"
load
"
)
{
break
;
case
"
load
"
:
loadUserScript
(
evt
.
data
.
path
);
parent
.
postMessage
({
type
:
"
loaded
"
});
}
else
if
(
type
===
"
update
"
)
{
break
;
case
"
update
"
:
Object
.
entries
(
peer_dict
).
forEach
(
function
([
id
,
peer
])
{
message
=
peer
.
message
;
if
(
user_me
.
id
!==
Number
(
id
)
&&
message
.
length
>
0
)
{
...
...
@@ -231,9 +239,15 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
user_me
.
onUpdate
(
evt
.
data
.
timestamp
);
}
parent
.
postMessage
({
type
:
"
updated
"
});
}
else
{
break
;
case
"
exit
"
:
exitWorker
(
evt
.
data
.
code
);
break
;
default
:
throw
new
Error
(
"
Unsupported message type
"
,
type
);
}
}
;
}
parent
.
onmessage
=
function
(
evt
)
{
...
...
@@ -243,11 +257,11 @@ import { evalScript, exit, fdopen, loadFile, open } from "std";
// Catch all potential bug to exit the main process
// if it occurs
console
.
log
(
error
);
exit
(
1
);
exit
Worker
(
1
);
}
};
}(
Drone
,
SIGTERM
,
WNOHANG
,
Worker
,
close
,
console
,
evalScript
,
exec
,
exit
,
fdopen
,
getAltitude
,
getAltitudeRel
,
getInitialAltitude
,
fdopen
,
getAltitude
,
getAltitudeRel
,
getInitialAltitude
,
getLatitude
,
getLongitude
,
getYaw
,
initPubsub
,
kill
,
loadFile
,
loiter
,
open
,
pipe
,
setAirspeed
,
setMessage
,
setReadHandler
,
setTargetCoordinates
,
triggerParachute
,
waitpid
));
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