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

software/js-drone: add subscribe script

parent a41296a7
...@@ -10,8 +10,8 @@ parts = qjs-wrapper ...@@ -10,8 +10,8 @@ parts = qjs-wrapper
recipe = slapos.recipe.cmmi recipe = slapos.recipe.cmmi
shared = true shared = true
configure-command = true configure-command = true
url = https://lab.nexedi.com/nexedi/qjs-wrapper/-/archive/v0.1/qjs-wrapper-v0.1.tar.gz url = https://lab.nexedi.com/nexedi/qjs-wrapper/-/archive/v0.2/qjs-wrapper-v0.2.tar.gz
md5sum = 4f0eb6f3bc5719a8ec043ce4f4d20747 md5sum = fa78424e5314d6d3f76e9b0ec28f7878
environment = environment =
C_INCLUDE_PATH=include:${open62541:location}/include:${open62541:location}/deps:${open62541:location}/src/pubsub:${quickjs:location}/include C_INCLUDE_PATH=include:${open62541:location}/include:${open62541:location}/deps:${open62541:location}/src/pubsub:${quickjs:location}/include
CPLUS_INCLUDE_PATH=include:${mavsdk:location}/include:${mavsdk:location}/include/mavsdk CPLUS_INCLUDE_PATH=include:${mavsdk:location}/include:${mavsdk:location}/include/mavsdk
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## Presentation ## ## Presentation ##
* Deploy 3 different scripts (`cli.js`, `demo.js` and `manual-flight.js`) on a drone to fly it * Deploy 4 different scripts (`cli.js`, `demo.js`, `manual-flight.js` and `subscribe.js`) on a drone to fly it
* Compile all required libraries to run flight scripts * Compile all required libraries to run flight scripts
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
* multicast-ipv6: IPv6 of the multicast group of the swarm * multicast-ipv6: IPv6 of the multicast group of the swarm
* net-if: Network interface used for multicast traffic
* drone-id-list: Comma seperated list of the drone IDs of the swarm (recommanded to add the current drone ID) * drone-id-list: Comma seperated list of the drone IDs of the swarm (recommanded to add the current drone ID)
## How it works ## ## How it works ##
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
# not need these here). # not need these here).
[instance-profile] [instance-profile]
filename = instance.cfg filename = instance.cfg
md5sum = 99017d061d3be30746f6daef3a7bd8c4 md5sum = 9c754abbc80f795229c3e79a8ede534b
[cli] [cli]
filename = cli.js filename = cli.js
...@@ -22,7 +22,7 @@ md5sum = 33271aeec124301604fdd406f0b339d1 ...@@ -22,7 +22,7 @@ md5sum = 33271aeec124301604fdd406f0b339d1
[common] [common]
filename = common.js filename = common.js
md5sum = bacc70f2683c279ba4e0751de616d4ff md5sum = 1a43f5cf3db1256fee985f82d88930a0
[demo] [demo]
filename = demo.js filename = demo.js
...@@ -34,4 +34,8 @@ md5sum = 175813fc8b2f19f91dae27ad4e14ab03 ...@@ -34,4 +34,8 @@ md5sum = 175813fc8b2f19f91dae27ad4e14ab03
[pubsub] [pubsub]
filename = pubsub.js filename = pubsub.js
md5sum = d949c9a6cdaaa94e7bdd22df5e52fbf4 md5sum = 1d1a2be301d74a619b63a33c4b4039da
[subscribe]
filename = subscribe.js
md5sum = 772e84f5584fc66c976778bbd8ae6a65
...@@ -162,7 +162,7 @@ export function startPubsub() { ...@@ -162,7 +162,7 @@ export function startPubsub() {
droneDict[id].init(i); droneDict[id].init(i);
} }
pubsubWorker.postMessage({ action: "run" }); pubsubWorker.postMessage({ action: "run", publish: true });
pubsubRunning = true; pubsubRunning = true;
return droneDict; return droneDict;
} }
......
...@@ -3,6 +3,7 @@ parts = ...@@ -3,6 +3,7 @@ parts =
cli cli
demo demo
manual-flight manual-flight
subscribe
eggs-directory = ${buildout:eggs-directory} eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory} develop-eggs-directory = ${buildout:develop-eggs-directory}
...@@ -33,11 +34,12 @@ init = ...@@ -33,11 +34,12 @@ init =
options['leader-id'] = options['slapparameter-dict'].get('leader_id', '1') options['leader-id'] = options['slapparameter-dict'].get('leader_id', '1')
options['is-leader'] = 'true' if options['id'] == options['leader-id'] else 'false' options['is-leader'] = 'true' if options['id'] == options['leader-id'] else 'false'
options['multicast-ipv6'] = options['slapparameter-dict'].get('multicast_ip', 'ff15::1111') options['multicast-ipv6'] = options['slapparameter-dict'].get('multicast_ip', 'ff15::1111')
options['net-if'] = options['slapparameter-dict'].get('net_if', 'eth0')
options['drone-id-list'] = options['slapparameter-dict'].get('drone_id_list', '') options['drone-id-list'] = options['slapparameter-dict'].get('drone_id_list', '')
[js-dynamic-template] [js-dynamic-template]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_} rendered = $${directory:etc}/$${:_buildout_section_name_}.js
template = ${buildout:directory}/$${:_buildout_section_name_}.js template = ${buildout:directory}/$${:_buildout_section_name_}.js
extra-context = extra-context =
context = context =
...@@ -75,3 +77,10 @@ extra-context = ...@@ -75,3 +77,10 @@ extra-context =
extra-context = extra-context =
key id drone:id key id drone:id
key ipv6 drone:multicast-ipv6 key ipv6 drone:multicast-ipv6
key net_if drone:net-if
[subscribe]
<= js-dynamic-template
extra-context =
key drone_id_list drone:drone-id-list
key pubsub_script pubsub:rendered
...@@ -9,7 +9,7 @@ var parent = Worker.parent; ...@@ -9,7 +9,7 @@ var parent = Worker.parent;
function handle_msg(e) { function handle_msg(e) {
switch(e.data.action) { switch(e.data.action) {
case "run": case "run":
runPubsub(IPV6, PORT, "eth0", {{ id }}); runPubsub(IPV6, PORT, "{{ net_if }}", {{ id }}, e.data.publish);
parent.postMessage({running: false}); parent.postMessage({running: false});
parent.onmessage = null; parent.onmessage = null;
break; break;
......
...@@ -11,6 +11,7 @@ parts = ...@@ -11,6 +11,7 @@ parts =
demo demo
manual-flight manual-flight
pubsub pubsub
subscribe
slapos-cookbook slapos-cookbook
[download-file-base] [download-file-base]
...@@ -37,3 +38,6 @@ output = ${buildout:directory}/template.cfg ...@@ -37,3 +38,6 @@ output = ${buildout:directory}/template.cfg
[pubsub] [pubsub]
<= download-file-base <= download-file-base
[subscribe]
<= download-file-base
/*jslint-disable*/
{% set comma_separated_drone_id_list = ', '.join(drone_id_list.split()) -%}
/*jslint-enable*/
import {
initPubsub,
stopPubsub,
Drone
} from "{{ qjs_wrapper }}"; //jslint-quiet
import {Worker} from "os";
/*jslint-disable*/
import * as std from "std";
/*jslint-enable*/
const droneIdList = [{{ comma_separated_drone_id_list }}];
const droneDict = {};
var pubsubWorker = new Worker("{{ pubsub_script }}");
pubsubWorker.onmessage = function(e) {
if (!e.data.publishing)
pubsubWorker.onmessage = null;
}
initPubsub(droneIdList.length);
for (let i = 0; i < droneIdList.length; i++) {
let id = droneIdList[i]
droneDict[id] = new Drone(id);
droneDict[id].init(i);
}
pubsubWorker.postMessage({ action: "run", publish: false });
const f = std.fdopen(std.in, "r");
console.log("Use q to quit");
while (f.getline() != "q") {
continue;
}
stopPubsub();
f.close();
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