Refactor nodeClass for to mostly allign with the standard EVOLV structure
This commit is contained in:
@@ -15,6 +15,48 @@ class nodeClass {
|
|||||||
this.RED = RED;
|
this.RED = RED;
|
||||||
this.name = nameOfNode;
|
this.name = nameOfNode;
|
||||||
|
|
||||||
|
this._setupClass(uiConfig, this.node);
|
||||||
|
|
||||||
|
this._attachInputHandler();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_attachInputHandler() { // Handle input messages
|
||||||
|
this.node.on('input', function(msg, send, done) {
|
||||||
|
let toggleUpdate = false;
|
||||||
|
|
||||||
|
switch (msg.topic) {
|
||||||
|
case "clock":
|
||||||
|
toggleUpdate = true;
|
||||||
|
break;
|
||||||
|
case "Fluent":
|
||||||
|
this.reactor.setInfluent = msg;
|
||||||
|
if (msg.payload.inlet == 0) {
|
||||||
|
toggleUpdate = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "OTR":
|
||||||
|
this.reactor.setOTR = msg;
|
||||||
|
break;
|
||||||
|
case "Dispersion":
|
||||||
|
this.reactor.setDispersion = msg;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.log("Unknown topic: " + msg.topic);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toggleUpdate) {
|
||||||
|
this.reactor.updateState(msg.timestamp);
|
||||||
|
send(this.reactor.getEffluent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_setupClass(uiConfig, node) {
|
||||||
let new_reactor;
|
let new_reactor;
|
||||||
|
|
||||||
switch (uiConfig.reactor_type) {
|
switch (uiConfig.reactor_type) {
|
||||||
@@ -68,42 +110,8 @@ class nodeClass {
|
|||||||
console.warn("Unknown reactor type: " + uiConfig.reactor_type);
|
console.warn("Unknown reactor type: " + uiConfig.reactor_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
const reactor = new_reactor; // protect from reassignment
|
node.reactor = new_reactor; // protect from reassignment
|
||||||
|
|
||||||
this.node.on('input', function(msg, send, done) {
|
|
||||||
let toggleUpdate = false;
|
|
||||||
|
|
||||||
switch (msg.topic) {
|
|
||||||
case "clock":
|
|
||||||
toggleUpdate = true;
|
|
||||||
break;
|
|
||||||
case "Fluent":
|
|
||||||
reactor.setInfluent = msg;
|
|
||||||
if (msg.payload.inlet == 0) {
|
|
||||||
toggleUpdate = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "OTR":
|
|
||||||
reactor.setOTR = msg;
|
|
||||||
break;
|
|
||||||
case "Dispersion":
|
|
||||||
reactor.setDispersion = msg;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
console.log("Unknown topic: " + msg.topic);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (toggleUpdate) {
|
|
||||||
reactor.updateState(msg.timestamp);
|
|
||||||
send(reactor.getEffluent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done) {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = nodeClass;
|
module.exports = nodeClass;
|
||||||
Reference in New Issue
Block a user