Commit 886491d3 authored by legoc's avatar legoc
Browse files

Removed nomad positions addon and use zeromq directly

parent d4199401
......@@ -5,28 +5,6 @@
},
"targets": [
{
"target_name": "addonnomad3dposition",
'cflags_cc': [ '-std=c++17', '-fexceptions' ],
'conditions': [
['nomad=="true"', {
"sources": [
"nomad-positions/nomad-positions.cc",
],
"conditions": [
['OS=="mac"', {
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
},
}]
],
"libraries": [
"-lcameo-api-cpp -lzmq"
]
}]
]
},
{
"target_name": "addonnomad3dcollision",
'cflags_cc': [ '-std=c++17', '-fexceptions' ],
......
......@@ -51,11 +51,6 @@ class NomadServer {
return;
}
// Reset the addon.
await this.NomadPositions.reset(0);
console.log("Nomad positions reset")
// Get the current simulated server list.
this.resetServerIdMap();
this._currentServerId = this._controller.Server[0];
......@@ -63,10 +58,8 @@ class NomadServer {
async reset(nomadServerId) {
console.log("Resetting Nomad server to " + nomadServerId + "...")
// Reset the addon.
await this.NomadPositions.reset(nomadServerId);
// Set the simulated server id.
this.NomadPositions.reset(nomadServerId);
console.log("Reset Nomad server to " + nomadServerId)
}
......
......@@ -82,7 +82,7 @@ class Nomad3DController {
// Update if the value has changed.
// At first call, actual position is undefined so that the condition is evaluated to true.
if (this._actualPosition != position) {
console.info("Updating " + this.name + " to " + position + " at " + new Date().toISOString());
//console.info("Updating " + this.name + " to " + position + " at " + new Date().toISOString());
this._actualPosition = position;
this.component.axis.value = this._actualPosition;
......
......@@ -26,9 +26,6 @@ class Nomad3DPositions {
// Memorize the current nomad server id.
this._nomadServerId = nomadServerId;
// Reset Nomad.
return this._requester.request('ResetNomadPosition', this._nomadServerId);
}
getSimulatedServerIds() {
......
const config = require("../config");
const CameoServer = require("./cameo-server");
const zmq = require("zeromq");
/**
* Class managing the link with the addon.
* There is only one instance of the class.
*
*/
class NomadPositions {
constructor() {
this._addon = null;
}
// Get the list of instruments.
this._models = config.models;
init(localEndpoint, nomadEndpoint) {
// Get the addon.
this._addon = require('../../../build/Release/addonnomad3dposition');
// Create the subscriber to all the instruments.
this._subscriber = new zmq.Subscriber;
// Init with the endpoints.
this._addon.init([localEndpoint, nomadEndpoint, "nomad-3d-viewer"]);
// Positions of all the instruments.
this._positions = {};
}
getSimulatedServerIds() {
return this._addon.getSimulatedServerIds();
}
getPositions(nomadServerId) {
return this._addon.getPositions(nomadServerId);
async _positionsLoop() {
// Wait for a new message.
const [identity, type, message] = await this._subscriber.receive();
//console.log('Received positions', message.toString());
// Decode the message.
const instrumentPositions = JSON.parse(message.toString());
const instrument = instrumentPositions["instrument"];
const id = instrumentPositions["id"];
const positions = instrumentPositions["positions"];
if (!(instrument in this._positions)) {
this._positions[instrument] = {};
}
this._positions[instrument][id] = positions;
// Continue the loop.
setTimeout(() => {
this._positionsLoop();
});
}
pause(nomadServerId) {
return this._addon.pause(nomadServerId);
async init() {
// Subscribe to all the instruments.
for (let instrument in this._models) {
const endpoint = this._models[instrument]["endpoint"];
const server = new CameoServer(endpoint);
try {
const publisherProxyPort = await server.getPublisherProxyPort();
console.log('Instrument ' + instrument + ' at ' + endpoint + ' with publisher proxy port ' + publisherProxyPort);
let publisherEndpoint = endpoint.substring(0, endpoint.lastIndexOf(":") + 1);
publisherEndpoint += publisherProxyPort;
console.log('Connecting ' + publisherEndpoint);
this._subscriber.connect(publisherEndpoint);
const topic = 'publisher-55845880-56e9-4ad6-bea1-e84395c90b32-nomad3d_positions';
this._subscriber.subscribe(topic);
}
catch (error) {
console.log('Instrument ' + instrument + ' at ' + endpoint + ' unreachable');
}
}
// Start the message loop.
this._positionsLoop();
}
restart(nomadServerId) {
return this._addon.restart(nomadServerId);
async getSimulatedServerIds(instrument) {
const endpoint = this._models[instrument]["endpoint"];
const server = new CameoServer(endpoint);
let result = [];
try {
const apps = await server.getApplicationInfos();
for (let app of apps) {
if (app["name"] === 'nssim') {
result.push(app["id"]);
}
}
return result;
}
catch (error) {
console.log('Instrument ' + instrument + ' at ' + endpoint + ' unreachable');
}
}
reset(nomadServerId) {
return this._addon.reset(nomadServerId);
getPositions(instrument, nomadServerId) {
return this._positions[instrument][nomadServerId];
}
}
module.exports = new NomadPositions();
\ No newline at end of file
module.exports = NomadPositions;
\ No newline at end of file
const config = require("../config");
const CameoServer = require("./cameo-server");
const zmq = require("zeromq");
/**
*
*/
class NomadPositions2 {
constructor() {
// Get the list of instruments.
this._models = config.models;
// Create the subscriber to all the instruments.
this._subscriber = new zmq.Subscriber;
// Positions of all the instruments.
this._positions = {};
}
async _positionsLoop() {
// Wait for a new message.
const [identity, type, message] = await this._subscriber.receive();
// Decode the message.
const instrumentPositions = JSON.parse(message.toString());
const instrument = instrumentPositions["instrument"];
const id = instrumentPositions["id"];
const positions = instrumentPositions["positions"];
if (!(instrument in this._positions)) {
this._positions[instrument] = {};
}
this._positions[instrument][id] = positions;
// Continue the loop.
setTimeout(() => {
this._positionsLoop();
});
}
async init() {
// Subscribe to all the instruments.
for (let instrument in this._models) {
const endpoint = this._models[instrument]["endpoint"];
const server = new CameoServer(endpoint);
try {
const publisherProxyPort = await server.getPublisherProxyPort();
console.log('Instrument ' + instrument + ' at ' + endpoint + ' with publisher proxy port ' + publisherProxyPort);
let publisherEndpoint = endpoint.substring(0, endpoint.lastIndexOf(":") + 1);
publisherEndpoint += publisherProxyPort;
console.log('Connecting ' + publisherEndpoint);
this._subscriber.connect(publisherEndpoint);
const topic = 'publisher-55845880-56e9-4ad6-bea1-e84395c90b32-nomad3d_positions';
this._subscriber.subscribe(topic);
}
catch (error) {
console.log('Instrument ' + instrument + ' at ' + endpoint + ' unreachable');
}
}
// Start the message loop.
this._positionsLoop();
}
async getSimulatedServerIds(instrument) {
const endpoint = this._models[instrument]["endpoint"];
const server = new CameoServer(endpoint);
let result = [];
try {
const apps = await server.getApplicationInfos();
for (let app of apps) {
if (app["name"] === 'nssim') {
result.push(app["id"]);
}
}
return result;
}
catch (error) {
console.log('Instrument ' + instrument + ' at ' + endpoint + ' unreachable');
}
}
getPositions(instrument, nomadServerId) {
return this._positions[instrument][nomadServerId];
}
}
module.exports = NomadPositions2;
\ No newline at end of file
......@@ -3,8 +3,6 @@ class PositionsResponder {
constructor(responder, nomadPositions) {
// Register the handlers.
this.NomadPositions = require('./nomad-positions');
responder.onRequestAsync('GetSimulatedServerIds', (instrument) => {
return nomadPositions.getSimulatedServerIds(instrument);
});
......@@ -14,15 +12,13 @@ class PositionsResponder {
});
responder.onRequest('PausePositionsRequest', (nomadServerId) => {
return this.NomadPositions.pause(nomadServerId)
// To be implemented.
return {};
});
responder.onRequest('RestartPositionsRequest', (nomadServerId) => {
return this.NomadPositions.restart(nomadServerId)
});
responder.onRequest('ResetNomadPosition', (nomadServerId) => {
return this.NomadPositions.reset(nomadServerId)
// To be implemented.
return {};
});
}
......
......@@ -18,25 +18,22 @@ const WebSocket = require('ws');
const Responder = require('../../external/com/responder');
const config = require('../config');
const nomadPositions = require('../com/nomad-positions');
const AssetResponder = require("../com/asset-responder");
const PositionsResponder = require("../com/positions-responder");
const CollisionsResponder = require("../com/collisions-responder");
const NomadPositions2 = require('../com/nomad-positions2');
nomadPositions.init(config.endpoints.localEndpoint, config.endpoints.nomadEndpoint);
const NomadPositions = require('../com/nomad-positions');
const wss = new WebSocket.Server({ port: 8080 });
const responder = new Responder(wss);
const nomadPositions2 = new NomadPositions2();
const positionsResponder = new PositionsResponder(responder, nomadPositions2);
const nomadPositions = new NomadPositions();
const positionsResponder = new PositionsResponder(responder, nomadPositions);
const collisionsResponder = new CollisionsResponder(responder);
const assetResponder = new AssetResponder(responder);
nomadPositions2.init();
nomadPositions.init();
const app = express();
......
Supports Markdown
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