Rewrite reactor to source and register it properly to node object

This commit is contained in:
2025-07-21 12:44:07 +02:00
parent 73c2b654e1
commit b1719376cf
2 changed files with 16 additions and 12 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}