Refactor nodeClass for to mostly allign with the standard EVOLV structure

This commit is contained in:
2025-07-04 12:06:58 +02:00
parent 1cda956d83
commit fee6881f1b

View File

@@ -15,6 +15,48 @@ class nodeClass {
this.RED = RED;
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;
switch (uiConfig.reactor_type) {
@@ -68,42 +110,8 @@ class nodeClass {
console.warn("Unknown reactor type: " + uiConfig.reactor_type);
}
const 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();
}
});
node.reactor = new_reactor; // protect from reassignment
}
}
module.exports = nodeClass;