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

software/js-drone: update default instance

Default software_type requests all required instances for the swarm.

See merge request nexedi/slapos!1264
parents e89e56bb 752cf414
...@@ -5,6 +5,7 @@ extends = ...@@ -5,6 +5,7 @@ extends =
../git/buildout.cfg ../git/buildout.cfg
../jsoncpp/buildout.cfg ../jsoncpp/buildout.cfg
../tinyxml2/buildout.cfg ../tinyxml2/buildout.cfg
../zlib/buildout.cfg
parts = parts =
mavsdk mavsdk
...@@ -41,7 +42,7 @@ configure-options = ...@@ -41,7 +42,7 @@ configure-options =
-DCMAKE_C_FLAGS="${:CMAKE_CFLAGS}" -DCMAKE_C_FLAGS="${:CMAKE_CFLAGS}"
-DCMAKE_CXX_FLAGS="${:CMAKE_CFLAGS}" -DCMAKE_CXX_FLAGS="${:CMAKE_CFLAGS}"
-DCMAKE_INSTALL_PREFIX=@@LOCATION@@ -DCMAKE_INSTALL_PREFIX=@@LOCATION@@
-DCMAKE_INSTALL_RPATH=${:CMAKE_LIBRARY_PATH} -DCMAKE_INSTALL_RPATH=${:CMAKE_LIBRARY_PATH}:@@LOCATION@@/lib
-DPKG_CONFIG_EXECUTABLE=${pkgconfig:location}/bin/pkg-config -DPKG_CONFIG_EXECUTABLE=${pkgconfig:location}/bin/pkg-config
-DSUPERBUILD=OFF -DSUPERBUILD=OFF
-Bbuild/default -Bbuild/default
...@@ -53,7 +54,7 @@ environment = ...@@ -53,7 +54,7 @@ environment =
CMAKE_LIBRARY_PATH=${:CMAKE_LIBRARY_PATH} CMAKE_LIBRARY_PATH=${:CMAKE_LIBRARY_PATH}
CMAKE_PROGRAM_PATH=${cmake:location}/bin CMAKE_PROGRAM_PATH=${cmake:location}/bin
PATH=${pkgconfig:location}/bin/:%(PATH)s PATH=${pkgconfig:location}/bin/:%(PATH)s
LDFLAGS=-L${jsoncpp:location}/lib -Wl,-rpath=${jsoncpp:location}/lib LDFLAGS=-L${curl:location}/lib -Wl,-rpath=${curl:location}/lib -L${jsoncpp:location}/lib -Wl,-rpath=${jsoncpp:location}/lib -L${tinyxml2:location}/lib -Wl,-rpath=${tinyxml2:location}/lib -L${zlib:location}/lib -Wl,-rpath=${zlib:location}/lib -Wl,-rpath=@@LOCATION@@/lib
CMAKE_CFLAGS=-I${tinyxml2:location}/include CMAKE_CFLAGS=-I${tinyxml2:location}/include
CMAKE_LIBRARY_PATH=${curl:location}/lib:${jsoncpp:location}/lib:${tinyxml2:location}/lib CMAKE_LIBRARY_PATH=${curl:location}/lib:${jsoncpp:location}/lib:${tinyxml2:location}/lib:${zlib:location}/lib
...@@ -8,10 +8,9 @@ parts = qjs-wrapper ...@@ -8,10 +8,9 @@ parts = qjs-wrapper
[qjs-wrapper] [qjs-wrapper]
recipe = slapos.recipe.cmmi recipe = slapos.recipe.cmmi
shared = true
configure-command = true configure-command = true
url = https://lab.nexedi.com/nexedi/qjs-wrapper/-/archive/v1.0/qjs-wrapper-v1.0.tar.gz url = https://lab.nexedi.com/nexedi/qjs-wrapper/-/archive/v1.2/qjs-wrapper-v1.2.tar.gz
md5sum = 0f1393fa15d46b2b551836197af9de46 md5sum = e335fc2251610c09dde3e74787317d98
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
......
...@@ -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 = 41f5acc071609a0c4b5ada295ede6bac md5sum = 82c476f22e6b55b674640abef959c3c2
[template-fluentd] [template-fluentd]
filename = instance-fluentd.cfg filename = instance-fluentd.cfg
......
...@@ -42,7 +42,7 @@ recipe = slapos.recipe.build ...@@ -42,7 +42,7 @@ recipe = slapos.recipe.build
slapparameter-dict = $${slap-configuration:configuration} slapparameter-dict = $${slap-configuration:configuration}
init = init =
import re import re
options['text'] = options['slapparameter-dict'].get('conf_text') or '' options['text'] = options['slapparameter-dict'].get('conf_text') or ' '
options['port-list'] = re.findall(r'<source>.*port (\d+).*<\/source>', options['text'], re.DOTALL) options['port-list'] = re.findall(r'<source>.*port (\d+).*<\/source>', options['text'], re.DOTALL)
[fluentd-agent-conf] [fluentd-agent-conf]
......
...@@ -2,26 +2,29 @@ ...@@ -2,26 +2,29 @@
## Presentation ## ## Presentation ##
* Deploy `user.js` script on a drone to fly it * Deploy `user.js` flight script on a drone swarm
* Compile all required libraries to run flight scripts * Compile all required libraries to run the flight script
## Parameters ## ## Parameters ##
* autopilot-ip: IPv4 address to identify the autpilot from the companion board * autopilot-ip: IPv4 address to identify the autopilot from the companion board
* id: User chosen ID for the drone (must be unique in a swarm, will be used as an identifier in multicast communications) * drone-guid-list: List of computer id on which flight script must be deployed
* is-a-simulation: Must be set to 'true' to automatically take off during simulation * is-a-simulation: Must be set to 'true' to automatically take off during simulation
* multicast-ipv6: IPv6 of the multicast group of the swarm * multicast-ip: IPv6 of the multicast group of the swarm
* net-if: Network interface used for multicast traffic * net-if: Network interface used for multicast traffic
* drone-id-list: List of the drone IDs of the swarm (recommended to add the current drone ID) * flight-script: URL of user's script to execute to fly drone swarm
* flight-script: User script to execute to fly drone swarm * subscriber-guid-list: List of computer id on which subscription script must be deployed
## How it works ## ## How it works ##
Run `quickjs binary location` `scripts location`/main.js `scripts location`/user.js For each computer listed in `drone-guid-list` and `subscriber-guid-list` a drone SR will be instanciated.
Each instance will return a `instance-path`. Under this path one will find `quickjs binary` in `bin` folder
and `scripts` in `etc` folder.
Run `quickjs binary location` `scripts location`/main.js `scripts location`/user.js .
...@@ -14,16 +14,24 @@ ...@@ -14,16 +14,24 @@
# not need these here). # not need these here).
[instance-profile] [instance-profile]
filename = instance.cfg filename = instance.cfg
md5sum = 7d4969239eb9d46bb44d57fc32b68c44 md5sum = 360b58007c25727b7bd8a9154d5cafd4
[instance-default]
filename = instance-default.cfg
md5sum = b26633b118cddd7c7b8dfd61b360999c
[instance-drone]
filename = instance-drone.cfg
md5sum = 1ff50063f5a54712a0bc0ff38fa74630
[main] [main]
filename = main.js filename = main.js
md5sum = 4b1b27ea3e06b8d40cbc33f0ec617601 md5sum = 2118d7908a909c585e03531147b1d540
[pubsub] [pubsub]
filename = pubsub.js filename = pubsub.js
md5sum = 4a0c63f9e088fa525a3699484d193c4d md5sum = 1555496ad591a31a845f33488d5c335d
[worker] [worker]
filename = worker.js filename = worker.js
md5sum = 5ed534e9ca56b9c0ee321b96b5d7c458 md5sum = 3893fb9228603e8c74f803476ec64dec
{% set autopilot_ip = slapparameter_dict.get('autopilotIp', '192.168.27.1') -%}
{% set flight_script = slapparameter_dict.get('flightScript', 'https://lab.nexedi.com/nexedi/flight-scripts/raw/master/default.js') -%}
{% set is_a_simulation = slapparameter_dict.get('isASimulation', False) -%}
{% set multicast_ip = slapparameter_dict.get('multicastIp', 'ff15::1111') -%}
{% set net_if = slapparameter_dict.get('netIf', 'eth0') -%}
{% set drone_guid_list = slapparameter_dict.get('droneGuidList', []) -%}
{% set subscriber_guid_list = slapparameter_dict.get('subscriberGuidList', []) -%}
{% set guid_list = drone_guid_list + subscriber_guid_list -%}
{% set nb_peer = len(guid_list) -%}
{% set drone_id_list = [] -%}
{% set subscriber_id_list = [] -%}
{% set part_list = ['publish-connection-information'] -%}
{% for id, guid in enumerate(guid_list) -%}
{% set request_drone_section_title = 'request-drone' ~ id -%}
{% do part_list.append(request_drone_section_title) %}
[{{ request_drone_section_title }}]
<= slap-connection
recipe = slapos.cookbook:request.serialised
name = Drone{{ id }}
software-url = $${:software-release-url}
software-type = drone
return = instance-path
sla-computer_guid = {{ guid }}
config-autopilotIp = {{ autopilot_ip }}
config-numberOfPeers = {{ dumps(nb_peer) }}
config-id = {{ dumps(id) }}
config-isASimulation = {{ dumps(is_a_simulation) }}
{% if guid in drone_guid_list -%}
{% do drone_id_list.append(id) %}
config-isADrone = {{ dumps(True) }}
config-flightScript = {{ flight_script }}
{% else -%}
{% do subscriber_id_list.append(id) %}
config-isADrone = {{ dumps(False) }}
config-flightScript = https://lab.nexedi.com/nexedi/flight-scripts/raw/master/subscribe.js
{% endif -%}
config-multicastIp = {{ multicast_ip }}
config-netIf = {{ net_if }}
{% endfor %}
[publish-connection-information]
recipe = slapos.cookbook:publish.serialised
drone-id-list = {{ dumps(drone_id_list) }}
subscriber-id-list = {{ dumps(subscriber_id_list) }}
[buildout]
parts =
{%- for part in part_list %}
{{ part }}
{%- endfor -%}
{
"$schema": "http://json-schema.org/draft-06/schema",
"type": "object",
"description": "Parameters to instantiate JS drone",
"additionalProperties": false,
"properties": {
"autopilotIp": {
"title": "IP address of the drone's autopilot",
"description": "IP used to create a connection with the autopilot.",
"type": "string"
},
"numberOfPeers": {
"title": "Number of Peers",
"description": "Number of drones and subscribers in the swarm",
"type": "integer"
},
"id": {
"title": "drone ID",
"description": "Drone unique identifier",
"type": "integer"
},
"isADrone": {
"title": "Set the requested instance as a drone",
"description": "The option used to determine if the instance is a drone. This affects the context of the user script (e.g. if it should be linked to an autopilot or publish its GPS coordinates)",
"type": "boolean"
},
"isASimulation": {
"title": "Set the flight as a simulation",
"description": "The option used to determine if the flight is real or if it is a simulation. This affects the context of the flight (e.g. if the take off is manual or automatic).",
"type": "boolean"
},
"multicastIp": {
"title": "IP of the multicast group",
"description": "IP address used to communicate with the other drones.",
"type": "string"
},
"netIf": {
"title": "Network interface",
"description": "Interface used for multicast traffic.",
"type": "string"
},
"flightScript": {
"title": "Script's URL of the flight",
"description": "URL of the script which will be executed for the flight. This URL must be publicly accesible so that all drones can fetch the script.",
"type": "string"
}
}
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Values returned by drone instantiation",
"additionalProperties": false,
"properties": {
"instance-path": {
"description": "Path of the directory where the quickjs binary and the flight scripts are located",
"type": "string"
}
},
"type": "object"
}
[buildout]
parts =
main
symlink-quickjs-binary
publish-connection-information
[directory]
recipe = slapos.cookbook:mkdirectory
home = $${buildout:directory}
bin = $${:home}/bin
etc = $${:home}/etc
var = $${:home}/var
log = $${:var}/log
[js-dynamic-template]
recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}.js
template = ${buildout:directory}/$${:_buildout_section_name_}.js
extra-context =
context =
import json_module json
raw qjs_wrapper ${qjs-wrapper:location}/lib/libqjswrapper.so
raw configuration {{ configuration }}
$${:extra-context}
[main]
<= js-dynamic-template
extra-context =
key log_dir directory:log
key pubsub_script pubsub:rendered
key worker_script worker:rendered
[pubsub]
<= js-dynamic-template
[worker]
<= js-dynamic-template
[symlink-quickjs-binary]
recipe = slapos.recipe.build
binary-path = ${quickjs:location}/bin/qjs
target = $${directory:bin}/qjs
init =
import os
if not os.path.exists(options['target']):
os.symlink(options['binary-path'], options['target'])
[publish-connection-information]
recipe = slapos.cookbook:publish.serialised
instance-path = $${directory:home}
...@@ -4,47 +4,47 @@ ...@@ -4,47 +4,47 @@
"description": "Parameters to instantiate JS drone", "description": "Parameters to instantiate JS drone",
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"autopilot-ip": { "autopilotIp": {
"title": "IP address of the drone's autopilot", "title": "IP address of the drone's autopilot",
"description": "IP used to create a connection with the autopilot.", "description": "IP used to create a connection with the autopilot.",
"type": "string", "type": "string",
"default": "192.168.27.1" "default": "192.168.27.1"
}, },
"id": { "droneGuidList": {
"title": "Drone ID", "title": "List of drones computer ID",
"description": "Unique identifier of the drone.", "description": "List of computer ID of drones in the swarm",
"type": "integer", "type": "array",
"default": 1 "default": []
}, },
"is-a-simulation": { "isASimulation": {
"title": "Set the flight as a simulation", "title": "Set the flight as a simulation",
"description": "The option used to determine if the flight is real or if it is a simulation. This affects the context of the flight (e.g. if the take off is manual or automatic).", "description": "The option used to determine if the flight is real or if it is a simulation. This affects the context of the flight (e.g. if the take off is manual or automatic).",
"type": "boolean", "type": "boolean",
"default": false "default": false
}, },
"multicast-ipv6": { "multicastIpv6": {
"title": "IP of the multicast group", "title": "IP of the multicast group",
"description": "IP address used to communicate with the other drones.", "description": "IP address used to communicate with the other drones.",
"type": "string", "type": "string",
"default": "ff15::1111" "default": "ff15::1111"
}, },
"net-if": { "netIf": {
"title": "Network interface", "title": "Network interface",
"description": "Interface used for multicast traffic.", "description": "Interface used for multicast traffic.",
"type": "string", "type": "string",
"default": "eth0" "default": "eth0"
}, },
"drone-id-list": { "flightScript": {
"title": "List of drones IDs", "title": "Script's URL of the flight",
"description": "List of identifiers of drones.", "description": "URL of the script which will be executed for the flight. This URL must be publicly accesible so that the drone can fetch the script.",
"type": "string",
"default": "https://lab.nexedi.com/nexedi/flight-scripts/raw/master/default.js"
},
"subscriberGuidList": {
"title": "List of subscribers computer ID",
"description": "List of computer ID of swarms subscribers",
"type": "array", "type": "array",
"default": [] "default": []
},
"flight-script": {
"title": "Script of the flight",
"description": "Script which will be executed for the flight",
"type": "string",
"textarea": true
} }
} }
} }
...@@ -2,6 +2,15 @@ ...@@ -2,6 +2,15 @@
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#",
"description": "Values returned by drone swarm (default) instantiation", "description": "Values returned by drone swarm (default) instantiation",
"additionalProperties": false, "additionalProperties": false,
"properties": {}, "properties": {
"drone-id-list": {
"description": "List of drones IDs",
"type": "array"
},
"subscriber-id-list": {
"description": "List of subscribers IDs",
"type": "array"
}
},
"type": "object" "type": "object"
} }
[buildout] [buildout]
parts = parts =
main switch-softwaretype
user
eggs-directory = ${buildout:eggs-directory} eggs-directory = ${buildout:eggs-directory}
develop-eggs-directory = ${buildout:develop-eggs-directory} develop-eggs-directory = ${buildout:develop-eggs-directory}
offline = true offline = true
[directory] [switch-softwaretype]
recipe = slapos.cookbook:mkdirectory recipe = slapos.cookbook:switch-softwaretype
home = $${buildout:directory} default = instance-default:output
etc = $${:home}/etc drone = instance-drone:output
var = $${:home}/var RootSoftwareInstance = $${:default}
log = $${:var}/log
[slap-configuration] [slap-configuration]
recipe = slapos.cookbook:slapconfiguration recipe = slapos.cookbook:slapconfiguration.serialised
computer = $${slap_connection:computer_id} computer = $${slap_connection:computer_id}
partition = $${slap_connection:partition_id} partition = $${slap_connection:partition_id}
url = $${slap_connection:server_url} url = $${slap_connection:server_url}
key = $${slap_connection:key_file} key = $${slap_connection:key_file}
cert = $${slap_connection:cert_file} cert = $${slap_connection:cert_file}
[drone] [dynamic-template-base]
recipe = slapos.recipe.build recipe = slapos.recipe.template:jinja2
slapparameter-dict = $${slap-configuration:configuration} url = ${buildout:directory}/$${:_buildout_section_name_}.cfg
init = output = $${buildout:directory}/$${:_buildout_section_name_}
options['autopilot-ip'] = options['slapparameter-dict'].get('autopilot-ip', '192.168.27.1')
options['id'] = options['slapparameter-dict'].get('id', 1)
options['is-a-simulation'] = options['slapparameter-dict'].get('is-a-simulation', 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', [])
options['is-a-drone'] = 'flight-script' in options['slapparameter-dict']
subscription_script = '''
me.onStart = function() {
me.f = me.fdopen(me.in, "r");
console.log("Use q to quit");
};
me.onUpdate= function(timestamp) { [instance-default]
while(me.f.getline() != "q") { <= dynamic-template-base
continue; extensions = jinja2.ext.do
} context =
try { key slapparameter_dict slap-configuration:configuration
me.f.close();;
} catch (error) {
console.error(error);
}
me.exit(0);
};
'''
options['flight-script'] = options['slapparameter-dict'].get('flight-script', subscription_script) [instance-drone]
<= dynamic-template-base
context =
key configuration drone-configuration:output
key user-script user:destination
[js-dynamic-template] [drone-configuration]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.template:jinja2
rendered = $${directory:etc}/$${:_buildout_section_name_}.js output = $${directory:etc}/configuration.json
template = ${buildout:directory}/$${:_buildout_section_name_}.js
extra-context =
context = context =
raw qjs_wrapper ${qjs-wrapper:location}/lib/libqjswrapper.so import json_module json
$${:extra-context} key slapparameter_dict slap-configuration:configuration
inline = {{ json_module.dumps(slapparameter_dict) }}
[main]
<= js-dynamic-template
extra-context =
key autopilot_ip drone:autopilot-ip
key id drone:id
key is_a_simulation drone:is-a-simulation
key is_a_drone drone:is-a-drone
key log_dir directory:log
key pubsub_script pubsub:rendered
key worker_script worker:rendered
[pubsub]
<= js-dynamic-template
extra-context =
key ipv6 drone:multicast-ipv6
key net_if drone:net-if
[user] [user]
recipe = slapos.recipe.template:jinja2 recipe = slapos.recipe.build:download
output = $${directory:etc}/user.js url = $${slap-configuration:configuration.flightScript}
context = destination = $${directory:etc}/user.js
key script drone:flight-script offline = false
inline = {{ script }}
[worker] [directory]
<= js-dynamic-template recipe = slapos.cookbook:mkdirectory
extra-context = home = $${buildout:directory}
key drone_id_list drone:drone-id-list etc = $${:home}/etc
key id drone:id
key is_a_drone drone:is-a-drone
/* global console */ /*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global arm, console, exit, open, scriptArgs, setTimeout, start, stop,
stopPubsub, takeOffAndWait, Worker*/
import { import {
arm, arm,
start, start,
stop, stop,
stopPubsub, stopPubsub,
takeOffAndWait takeOffAndWait
} from "{{ qjs_wrapper }}"; } from {{ json_module.dumps(qjs_wrapper) }};
import { setTimeout, Worker } from "os"; import { setTimeout, Worker } from "os";
import { exit } from "std"; import { open, exit } from "std";
(function (console, setTimeout, Worker) { (function (arm, console, exit, open, scriptArgs, setTimeout, start, stop,
stopPubsub, takeOffAndWait, Worker) {
"use strict"; "use strict";
const IP = "{{ autopilot_ip }}",
URL = "udp://" + IP + ":7909", var CONF_PATH = {{ json_module.dumps(configuration) }},
conf_file = open(CONF_PATH, "r"),
configuration = JSON.parse(conf_file.readAsString()),
URL = "udp://" + configuration.autopilotIp + ":7909",
LOG_FILE = "{{ log_dir }}/mavsdk-log", LOG_FILE = "{{ log_dir }}/mavsdk-log",
IS_A_DRONE = {{ 'true' if is_a_drone else 'false' }}, pubsubWorker,
SIMULATION = {{ 'true' if is_a_simulation else 'false' }}; worker,
user_script = scriptArgs[1],
FPS = 50, // Minimum sampling interval for open62541 monitored items
previous_timestamp,
can_update = false;
conf_file.close();
// Use a Worker to ensure the user script // Use a Worker to ensure the user script
// does not block the main script // does not block the main script
...@@ -23,17 +35,14 @@ import { exit } from "std"; ...@@ -23,17 +35,14 @@ import { exit } from "std";
// Create the update loop in the main script // Create the update loop in the main script
// to prevent it to finish (and so, exit the quickjs process) // to prevent it to finish (and so, exit the quickjs process)
var pubsubWorker, worker = new Worker("{{ worker_script }}");
worker = new Worker("{{ worker_script }}"),
user_script = scriptArgs[1],
// Use the same FPS than browser's requestAnimationFrame
FPS = 1000 / 60,
previous_timestamp,
can_update = false;
function connect() { function quit(is_a_drone, exit_code) {
console.log("Will connect to", URL); stopPubsub();
exitOnFail(start(URL, LOG_FILE, 60), "Failed to connect to " + URL); if (is_a_drone) {
stop();
}
exit(exit_code);
} }
function exitOnFail(ret, msg) { function exitOnFail(ret, msg) {
...@@ -43,25 +52,22 @@ import { exit } from "std"; ...@@ -43,25 +52,22 @@ import { exit } from "std";
} }
} }
function quit(is_a_drone, exit_code) { function connect() {
if (is_a_drone) { console.log("Will connect to", URL);
stop(); exitOnFail(start(URL, LOG_FILE, 60), "Failed to connect to " + URL);
}
stopPubsub();
exit(exit_code);
} }
if (IS_A_DRONE) { if (configuration.isADrone) {
console.log("Connecting to aupilot\n"); console.log("Connecting to aupilot\n");
connect(); connect();
} }
pubsubWorker = new Worker("{{ pubsub_script }}"); pubsubWorker = new Worker("{{ pubsub_script }}");
pubsubWorker.onmessage = function(e) { pubsubWorker.onmessage = function (e) {
if (!e.data.publishing) { if (!e.data.publishing) {
pubsubWorker.onmessage = null; pubsubWorker.onmessage = null;
} }
} };
worker.postMessage({type: "initPubsub"}); worker.postMessage({type: "initPubsub"});
...@@ -71,7 +77,7 @@ import { exit } from "std"; ...@@ -71,7 +77,7 @@ import { exit } from "std";
} }
function load() { function load() {
if (IS_A_DRONE && SIMULATION) { if (configuration.isADrone && configuration.isASimulation) {
takeOff(); takeOff();
} }
...@@ -88,7 +94,7 @@ import { exit } from "std"; ...@@ -88,7 +94,7 @@ import { exit } from "std";
} }
function loop() { function loop() {
let timestamp = Date.now(), var timestamp = Date.now(),
timeout; timeout;
if (can_update) { if (can_update) {
if (FPS <= (timestamp - previous_timestamp)) { if (FPS <= (timestamp - previous_timestamp)) {
...@@ -114,13 +120,13 @@ import { exit } from "std"; ...@@ -114,13 +120,13 @@ import { exit } from "std";
} }
worker.onmessage = function (e) { worker.onmessage = function (e) {
let type = e.data.type; var type = e.data.type;
if (type === 'initialized') { if (type === 'initialized') {
pubsubWorker.postMessage({ pubsubWorker.postMessage({
action: "run", action: "run",
id: {{ id }}, id: configuration.id,
interval: FPS, interval: FPS,
publish: IS_A_DRONE publish: configuration.isADrone
}); });
load(); load();
} else if (type === 'loaded') { } else if (type === 'loaded') {
...@@ -132,10 +138,11 @@ import { exit } from "std"; ...@@ -132,10 +138,11 @@ import { exit } from "std";
can_update = true; can_update = true;
} else if (type === 'exited') { } else if (type === 'exited') {
worker.onmessage = null; worker.onmessage = null;
quit(IS_A_DRONE, e.data.exit); quit(configuration.isADrone, e.data.exit);
} else { } else {
console.log('Unsupported message type', type); console.log('Unsupported message type', type);
quit(IS_A_DRONE, 1); quit(configuration.isADrone, 1);
} }
}; };
}(console, setTimeout, Worker)); }(arm, console, exit, open, scriptArgs, setTimeout, start, stop, stopPubsub,
takeOffAndWait, Worker));
import {runPubsub} from "{{ qjs_wrapper }}"; /*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, open, runPubsub, Worker*/
import {runPubsub} from {{ json_module.dumps(qjs_wrapper) }};
import {Worker} from "os"; import {Worker} from "os";
import {open} from "std";
const PORT = "4840"; (function (console, open, runPubsub, Worker) {
const IPV6 = "{{ ipv6 }}"; "use strict";
let parent = Worker.parent; var CONF_PATH = {{ json_module.dumps(configuration) }},
PORT = "4840",
parent = Worker.parent,
conf_file = open(CONF_PATH, "r"),
configuration = JSON.parse(conf_file.readAsString());
conf_file.close();
function handle_msg(e) { function handle_msg(e) {
switch(e.data.action) { switch (e.data.action) {
case "run": case "run":
runPubsub(IPV6, PORT, "{{ net_if }}", e.data.id, e.data.interval, e.data.publish); runPubsub(
configuration.multicastIp,
PORT,
configuration.netIf,
e.data.id,
e.data.interval,
e.data.publish
);
parent.postMessage({running: false}); parent.postMessage({running: false});
parent.onmessage = null; parent.onmessage = null;
break; break;
default: default:
console.log("Undefined action from parent: ", e.data.action); console.log("Undefined action from parent: ", e.data.action);
}
} }
}
parent.onmessage = handle_msg; parent.onmessage = handle_msg;
}(console, open, runPubsub, Worker));
\ No newline at end of file
...@@ -6,21 +6,34 @@ extends = ...@@ -6,21 +6,34 @@ extends =
parts = parts =
instance-profile instance-profile
instance-default
instance-drone
main main
pubsub pubsub
worker worker
slapos-cookbook slapos-cookbook
[download-file-base]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:filename}
destination = ${buildout:directory}/${:filename}
[instance-profile] [instance-profile]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:filename} url = ${:_profile_base_location_}/${:filename}
output = ${buildout:directory}/template.cfg output = ${buildout:directory}/template.cfg
[jinja-template-base]
recipe = slapos.recipe.template
url = ${:_profile_base_location_}/${:_buildout_section_name_}.cfg
output = ${buildout:directory}/${:_buildout_section_name_}.cfg
[instance-default]
<= jinja-template-base
[instance-drone]
<= jinja-template-base
[download-file-base]
recipe = slapos.recipe.build:download
url = ${:_profile_base_location_}/${:filename}
destination = ${buildout:directory}/${:filename}
[main] [main]
<= download-file-base <= download-file-base
......
{ {
"name": "JS Drone", "name": "JS Drone",
"description": "JS Drone", "description": "JS Drone",
"serialisation": "xml", "serialisation": "json-in-xml",
"software-type": { "software-type": {
"default": { "default": {
"title": "Default", "title": "Default",
"software-type": "default", "software-type": "default",
"description": "Default", "description": "Drone Swarm",
"request": "instance-input-schema.json", "request": "instance-input-schema.json",
"response": "instance-output-schema.json", "response": "instance-output-schema.json",
"index": 0 "index": 0
},
"drone": {
"title": "Drone",
"software-type": "drone",
"description": "Drone Instance",
"request": "instance-drone-input-schema.json",
"response": "instance-drone-output-schema.json",
"index": 1
} }
} }
} }
Tests for js-drone Software Release
##############################################################################
#
# Copyright (c) 2022 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from setuptools import setup, find_packages
version = '0.0.1.dev0'
name = 'slapos.test.js_drone'
with open("README.md") as f:
long_description = f.read()
setup(name=name,
version=version,
description="Test for SlapOS' js-drone",
long_description=long_description,
long_description_content_type='text/markdown',
maintainer="Nexedi",
maintainer_email="info@nexedi.com",
url="https://lab.nexedi.com/nexedi/slapos",
packages=find_packages(),
install_requires=[
'slapos.core',
'slapos.libnetworkcache',
'erp5.util'
],
zip_safe=True,
test_suite='test',
)
This diff is collapsed.
/* global console, std */ /*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global console, getAltitude, getAltitudeRel, getInitialAltitude, getLatitude,
getLongitude, getYaw, execUserScript, initPubsub, isInManualMode, landed,
loiter, setAirspeed, setAltitude, setManualControlInput, setMessage,
setTargetCoordinates, std, triggerParachute, Drone, Worker*/
import { import {
Drone, Drone,
triggerParachute, triggerParachute,
getAirspeed,
getAltitude, getAltitude,
getAltitudeRel, getAltitudeRel,
getClimbRate,
getInitialAltitude, getInitialAltitude,
getLatitude, getLatitude,
getLongitude, getLongitude,
...@@ -17,18 +23,22 @@ import { ...@@ -17,18 +23,22 @@ import {
setManualControlInput, setManualControlInput,
setMessage, setMessage,
setTargetCoordinates setTargetCoordinates
} from "{{ qjs_wrapper }}"; } from {{ json_module.dumps(qjs_wrapper) }};
import * as std from "std"; import * as std from "std";
import { Worker } from "os"; import { Worker } from "os";
(function (console, Worker) { (function (console, getAltitude, getAltitudeRel, getInitialAltitude,
getLatitude, getLongitude, getYaw, initPubsub, isInManualMode,
landed, loiter, setAirspeed, setAltitude, setManualControlInput,
setMessage, setTargetCoordinates, std, triggerParachute, Drone,
Worker) {
// Every script is evaluated per drone // Every script is evaluated per drone
"use strict"; "use strict";
const drone_dict = {},
drone_id_list = [{{ drone_id_list }}],
IS_A_DRONE = {{ 'true' if is_a_drone else 'false' }};
let parent = Worker.parent, var CONF_PATH = {{ json_module.dumps(configuration) }},
conf_file = std.open(CONF_PATH, "r"),
configuration = JSON.parse(conf_file.readAsString()),
parent = Worker.parent,
user_me = { user_me = {
//for debugging purpose //for debugging purpose
fdopen: std.fdopen, fdopen: std.fdopen,
...@@ -36,12 +46,12 @@ import { Worker } from "os"; ...@@ -36,12 +46,12 @@ import { Worker } from "os";
//required to fly //required to fly
triggerParachute: triggerParachute, triggerParachute: triggerParachute,
drone_dict: {}, drone_dict: {},
exit: function(exit_code) { exit: function (exit_code) {
parent.postMessage({type: "exited", exit: exit_code}); parent.postMessage({type: "exited", exit: exit_code});
parent.onmessage = null; parent.onmessage = null;
}, },
getAltitudeAbs: getAltitude, getAltitudeAbs: getAltitude,
getCurrentPosition: function() { getCurrentPosition: function () {
return { return {
x: getLatitude(), x: getLatitude(),
y: getLongitude(), y: getLongitude(),
...@@ -50,28 +60,30 @@ import { Worker } from "os"; ...@@ -50,28 +60,30 @@ import { Worker } from "os";
}, },
getInitialAltitude: getInitialAltitude, getInitialAltitude: getInitialAltitude,
getYaw: getYaw, getYaw: getYaw,
id: {{ id }}, getSpeed: getAirspeed,
getClimbRate: getClimbRate,
id: configuration.id,
landed: landed, landed: landed,
loiter: loiter, loiter: loiter,
sendMsg: function(msg, id = -1) { sendMsg: function (msg, id) {
if (id === undefined) { id = -1; }
setMessage(JSON.stringify({ content: msg, dest_id: id })); setMessage(JSON.stringify({ content: msg, dest_id: id }));
}, },
setAirspeed: setAirspeed, setAirspeed: setAirspeed,
setAltitude: setAltitude, setAltitude: setAltitude,
setTargetCoordinates: setTargetCoordinates setTargetCoordinates: setTargetCoordinates
}; };
conf_file.close();
function loadUserScript(path) { function loadUserScript(path) {
let script_content = std.loadFile(path); var script_content = std.loadFile(path);
if (script_content === null) { if (script_content === null) {
console.log("Failed to load user script " + path); console.log("Failed to load user script " + path);
std.exit(1); std.exit(1);
} }
try { try {
std.evalScript( std.evalScript(
"function execUserScript(from, me) {" + "function execUserScript(from, me) {" + script_content + "};"
script_content +
"};"
); );
} catch (e) { } catch (e) {
console.log("Failed to evaluate user script", e); console.log("Failed to evaluate user script", e);
...@@ -86,38 +98,32 @@ import { Worker } from "os"; ...@@ -86,38 +98,32 @@ import { Worker } from "os";
} }
function handleMainMessage(evt) { function handleMainMessage(evt) {
let type = evt.data.type, var type = evt.data.type, message, drone_id;
message,
drone_id;
if (type === "initPubsub") { if (type === "initPubsub") {
initPubsub(drone_id_list.length); initPubsub(configuration.numberOfPeers);
for (let i = 0; i < drone_id_list.length; i++) { for (drone_id = 0; drone_id < configuration.numberOfPeers; drone_id++) {
drone_id = drone_id_list[i];
user_me.drone_dict[drone_id] = new Drone(drone_id); user_me.drone_dict[drone_id] = new Drone(drone_id);
user_me.drone_dict[drone_id].init(i); user_me.drone_dict[drone_id].init(drone_id);
} }
parent.postMessage({type: "initialized"}); parent.postMessage({type: "initialized"});
} else if (type === "load") { } else if (type === "load") {
loadUserScript(evt.data.path); loadUserScript(evt.data.path);
parent.postMessage({type: "loaded"}); parent.postMessage({type: "loaded"});
} else if (type === "update") { } else if (type === "update") {
for (const [id, drone] of Object.entries(user_me.drone_dict)) { Object.entries(user_me.drone_dict).forEach(function ([id, drone]) {
message = drone.message message = drone.message;
if (message.length > 0) { if (user_me.id !== Number(id) && message.length > 0) {
message = JSON.parse(message); message = JSON.parse(message);
if (user_me.id === id) {
continue;
}
if (user_me.hasOwnProperty("onGetMsg") && if (user_me.hasOwnProperty("onGetMsg") &&
[-1, user_me.id].includes(message.dest_id)) { [-1, user_me.id].includes(message.dest_id)) {
user_me.onGetMsg(message.content); user_me.onGetMsg(message.content);
} }
} }
} });
// Call the drone onStart function // Call the drone onStart function
if (user_me.hasOwnProperty("onUpdate")) { if (user_me.hasOwnProperty("onUpdate")) {
if (IS_A_DRONE && isInManualMode()) { if (configuration.isADrone && isInManualMode()) {
setManualControlInput(); setManualControlInput();
} }
user_me.onUpdate(evt.data.timestamp); user_me.onUpdate(evt.data.timestamp);
...@@ -138,4 +144,7 @@ import { Worker } from "os"; ...@@ -138,4 +144,7 @@ import { Worker } from "os";
std.exit(1); std.exit(1);
} }
}; };
}(console, Worker)); }(console, getAltitude, getAltitudeRel, getInitialAltitude, getLatitude,
getLongitude, getYaw, initPubsub, isInManualMode, landed, loiter, setAirspeed,
setAltitude, setManualControlInput, setMessage, setTargetCoordinates, std,
triggerParachute, Drone, Worker));
...@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30 ...@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30
[template-mariadb.cfg] [template-mariadb.cfg]
_update_hash_filename_ = instance-mariadb.cfg.jinja2.in _update_hash_filename_ = instance-mariadb.cfg.jinja2.in
md5sum = bd5b0e72e8b5ddcd691e7f90a2947e50 md5sum = d1efa1148ef1d4fb3f2869f08ce85fd2
[template-my-cnf] [template-my-cnf]
_update_hash_filename_ = templates/my.cnf.in _update_hash_filename_ = templates/my.cnf.in
......
...@@ -209,7 +209,7 @@ wait-for-files = ...@@ -209,7 +209,7 @@ wait-for-files =
[{{ section('odbc-ini') }}] [{{ section('odbc-ini') }}]
recipe = slapos.recipe.template recipe = slapos.recipe.template
output = ${directory:etc}/odbc.ini output = ${directory:etc}/odbc.ini
inline = {{ dumps(slapparameter_dict.get('odbc-ini', '')) }} inline = {{ dumps(slapparameter_dict.get('odbc-ini', ' ')) }}
[{{ section('logrotate-entry-mariadb') }}] [{{ section('logrotate-entry-mariadb') }}]
< = logrotate-entry-base < = logrotate-entry-base
......
...@@ -252,6 +252,11 @@ setup = ${slapos-repository:location}/software/mosquitto/test/ ...@@ -252,6 +252,11 @@ setup = ${slapos-repository:location}/software/mosquitto/test/
egg = slapos.test.peertube egg = slapos.test.peertube
setup = ${slapos-repository:location}/software/peertube/test/ setup = ${slapos-repository:location}/software/peertube/test/
[slapos.test.js-drone-setup]
<= setup-develop-egg
egg = slapos.test.js_drone
setup = ${slapos-repository:location}/software/js-drone/test/
[slapos.core-repository] [slapos.core-repository]
<= git-clone-repository <= git-clone-repository
repository = https://lab.nexedi.com/nexedi/slapos.core.git repository = https://lab.nexedi.com/nexedi/slapos.core.git
...@@ -316,6 +321,7 @@ eggs += ...@@ -316,6 +321,7 @@ eggs +=
${slapos.test.html5as-setup:egg} ${slapos.test.html5as-setup:egg}
${slapos.test.htmlvalidatorserver-setup:egg} ${slapos.test.htmlvalidatorserver-setup:egg}
${slapos.test.hugo-setup:egg} ${slapos.test.hugo-setup:egg}
${slapos.test.js-drone-setup:egg}
${slapos.test.jscrawler-setup:egg} ${slapos.test.jscrawler-setup:egg}
${slapos.test.jstestnode-setup:egg} ${slapos.test.jstestnode-setup:egg}
${slapos.test.jupyter-setup:egg} ${slapos.test.jupyter-setup:egg}
...@@ -407,6 +413,7 @@ tests = ...@@ -407,6 +413,7 @@ tests =
html5as-base ${slapos.test.html5as-base-setup:setup} html5as-base ${slapos.test.html5as-base-setup:setup}
htmlvalidatorserver ${slapos.test.htmlvalidatorserver-setup:setup} htmlvalidatorserver ${slapos.test.htmlvalidatorserver-setup:setup}
hugo ${slapos.test.hugo-setup:setup} hugo ${slapos.test.hugo-setup:setup}
js-drone ${slapos.test.js-drone-setup:setup}
jscrawler ${slapos.test.jscrawler-setup:setup} jscrawler ${slapos.test.jscrawler-setup:setup}
jstestnode ${slapos.test.jstestnode-setup:setup} jstestnode ${slapos.test.jstestnode-setup:setup}
jupyter ${slapos.test.jupyter-setup:setup} jupyter ${slapos.test.jupyter-setup:setup}
......
...@@ -26,7 +26,7 @@ md5sum = d10b8e35b02b5391cf46bf0c7dbb1196 ...@@ -26,7 +26,7 @@ md5sum = d10b8e35b02b5391cf46bf0c7dbb1196
[template-mariadb] [template-mariadb]
filename = instance-mariadb.cfg.in filename = instance-mariadb.cfg.in
md5sum = cee995829fbd138a8c2c9209d72d01a0 md5sum = 93b2277185e4949a3d17be79d3710d2d
[template-kumofs] [template-kumofs]
filename = instance-kumofs.cfg.in filename = instance-kumofs.cfg.in
......
...@@ -193,7 +193,7 @@ environ = ...@@ -193,7 +193,7 @@ environ =
[{{ section('odbc-ini') }}] [{{ section('odbc-ini') }}]
recipe = slapos.recipe.template recipe = slapos.recipe.template
output = ${directory:etc}/odbc.ini output = ${directory:etc}/odbc.ini
inline = {{ dumps(slapparameter_dict.get('odbc-ini', '')) }} inline = {{ dumps(slapparameter_dict.get('odbc-ini', ' ')) }}
[{{ section('logrotate-entry-mariadb') }}] [{{ section('logrotate-entry-mariadb') }}]
< = logrotate-entry-base < = logrotate-entry-base
......
...@@ -297,7 +297,7 @@ slapos.libnetworkcache = 0.25 ...@@ -297,7 +297,7 @@ slapos.libnetworkcache = 0.25
slapos.rebootstrap = 4.5 slapos.rebootstrap = 4.5
slapos.recipe.build = 0.56 slapos.recipe.build = 0.56
slapos.recipe.cmmi = 0.19 slapos.recipe.cmmi = 0.19
slapos.recipe.template = 5.0 slapos.recipe.template = 5.1
slapos.toolbox = 0.129 slapos.toolbox = 0.129
smmap = 5.0.0 smmap = 5.0.0
sniffio = 1.3.0 sniffio = 1.3.0
......
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