From b1719376cffcd0e32d96dae20e438262b528851d Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Mon, 21 Jul 2025 12:44:07 +0200
Subject: [PATCH] Rewrite reactor to source and register it properly to node
object
---
src/nodeClass.js | 25 ++++++++++++++-----------
src/specificClass.js | 3 ++-
2 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/src/nodeClass.js b/src/nodeClass.js
index 94b3965..989b806 100644
--- a/src/nodeClass.js
+++ b/src/nodeClass.js
@@ -14,12 +14,13 @@ class nodeClass {
this.node = nodeInstance;
this.RED = RED;
this.name = nameOfNode;
+ this.source = null;
this._loadConfig(uiConfig)
- this._registerChild();
this._setupClass();
this._attachInputHandler();
+ this._registerChild();
}
/**
@@ -32,27 +33,28 @@ class nodeClass {
switch (msg.topic) {
case "clock":
toggleUpdate = true;
- this.reactor.updateState(msg.timestamp);
- send([this.reactor.getEffluent, null, null]);
+ this.source.updateState(msg.timestamp);
+ send([this.source.getEffluent, null, null]);
send([msg, null, null])
break;
case "Fluent":
- this.reactor.setInfluent = msg;
+ this.source.setInfluent = msg;
break;
case "OTR":
- this.reactor.setOTR = msg;
+ this.source.setOTR = msg;
break;
case "Temperature":
- this.reactor.setTemperature = msg;
+ this.source.setTemperature = msg;
break;
case "Dispersion":
- this.reactor.setDispersion = msg;
+ this.source.setDispersion = msg;
break;
case 'registerChild':
// Register this node as a child of the parent node
const childId = msg.payload;
const childObj = this.RED.nodes.getNode(childId);
- this.reactor.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
+ console.log(childObj.source);
+ this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
break;
default:
console.log("Unknown topic: " + msg.topic);
@@ -76,7 +78,7 @@ class nodeClass {
unit: null
},
functionality: {
- softwareType: null // should be set in config manager
+ softwareType: "reactor" // should be set in config manager
},
reactor_type: uiConfig.reactor_type,
volume: parseFloat(uiConfig.volume),
@@ -112,7 +114,7 @@ class nodeClass {
this.node.send([
null,
null,
- { topic: 'registerChild', payload: this.node.id, positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' },
+ { topic: 'registerChild', payload: this.node.id, positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' }
]);
}, 100);
}
@@ -134,7 +136,8 @@ class nodeClass {
console.warn("Unknown reactor type: " + uiConfig.reactor_type);
}
- this.reactor = new_reactor; // protect from reassignment
+ this.source = new_reactor; // protect from reassignment
+ this.node.source = this.source;
}
}
diff --git a/src/specificClass.js b/src/specificClass.js
index 474ebf7..99ed988 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -20,6 +20,7 @@ class Reactor {
* @param {object} config - Configuration object containing reactor parameters.
*/
constructor(config) {
+ this.config = config;
// EVOLV stuff
this.logger = new logger(undefined, undefined, config.general.name);
this.emitter = new EventEmitter();
@@ -122,7 +123,7 @@ class Reactor {
n += 1;
}
this.currentTime += n_iter * this.timeStep * day2ms / this.speedUpFactor;
- this.emitter.emit("stateChanges", this.getEffluent);
+ this.emitter.emit("stateChange", this.getEffluent);
}
}
}