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
recipe = slapos.recipe.cmmi
shared = true
configure-command = true
url = https://lab.nexedi.com/nexedi/qjs-wrapper/-/archive/v0.1/qjs-wrapper-v0.1.tar.gz
md5sum = 4f0eb6f3bc5719a8ec043ce4f4d20747
url = https://lab.nexedi.com/nexedi/qjs-wrapper/-/archive/v0.2/qjs-wrapper-v0.2.tar.gz
md5sum = fa78424e5314d6d3f76e9b0ec28f7878
environment =
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
......
......@@ -2,7 +2,7 @@
## 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
......@@ -18,6 +18,8 @@
* 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)
## How it works ##
......
......@@ -14,7 +14,7 @@
# not need these here).
[instance-profile]
filename = instance.cfg
md5sum = 99017d061d3be30746f6daef3a7bd8c4
md5sum = 9c754abbc80f795229c3e79a8ede534b
[cli]
filename = cli.js
......@@ -22,7 +22,7 @@ md5sum = 33271aeec124301604fdd406f0b339d1
[common]
filename = common.js
md5sum = bacc70f2683c279ba4e0751de616d4ff
md5sum = 1a43f5cf3db1256fee985f82d88930a0
[demo]
filename = demo.js
......@@ -34,4 +34,8 @@ md5sum = 175813fc8b2f19f91dae27ad4e14ab03
[pubsub]
filename = pubsub.js
md5sum = d949c9a6cdaaa94e7bdd22df5e52fbf4
md5sum = 1d1a2be301d74a619b63a33c4b4039da
[subscribe]
filename = subscribe.js
md5sum = 772e84f5584fc66c976778bbd8ae6a65
......@@ -162,7 +162,7 @@ export function startPubsub() {
droneDict[id].init(i);
}
pubsubWorker.postMessage({ action: "run" });
pubsubWorker.postMessage({ action: "run", publish: true });
pubsubRunning = true;
return droneDict;
}
......
......@@ -3,6 +3,7 @@ parts =
cli
demo
manual-flight
subscribe
eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory}
......@@ -33,11 +34,12 @@ init =
options['leader-id'] = options['slapparameter-dict'].get('leader_id', '1')
options['is-leader'] = 'true' if options['id'] == options['leader-id'] else 'false'
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', '')
[js-dynamic-template]
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
extra-context =
context =
......@@ -75,3 +77,10 @@ extra-context =
extra-context =
key id drone:id
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;
function handle_msg(e) {
switch(e.data.action) {
case "run":
runPubsub(IPV6, PORT, "eth0", {{ id }});
runPubsub(IPV6, PORT, "{{ net_if }}", {{ id }}, e.data.publish);
parent.postMessage({running: false});
parent.onmessage = null;
break;
......
......@@ -11,6 +11,7 @@ parts =
demo
manual-flight
pubsub
subscribe
slapos-cookbook
[download-file-base]
......@@ -37,3 +38,6 @@ output = ${buildout:directory}/template.cfg
[pubsub]
<= 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