From c2cd29db562e6e841b0392d8bb6617159c06aa20 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Fri, 5 Sep 2025 15:26:00 +0200 Subject: [PATCH] Update generalFunctions dependency and enhance reactor child registration logic --- package-lock.json | 2 +- src/nodeClass.js | 2 +- src/specificClass.js | 52 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2d885a7..a738306 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,7 +62,7 @@ }, "node_modules/generalFunctions": { "version": "1.0.0", - "resolved": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#50f99fa64286b35dbb6ba1b6918ebe1175756ebc", + "resolved": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#302e12238745766a679ef11ca6ed5f4ea1548f87", "license": "SEE LICENSE" }, "node_modules/javascript-natural-sort": { diff --git a/src/nodeClass.js b/src/nodeClass.js index 018610e..8955854 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -49,7 +49,7 @@ class nodeClass { this.source.setDispersion = msg; break; case 'registerChild': - // Register this node as a child of the parent node + // Register this node as a parent of the child node const childId = msg.payload; const childObj = this.RED.nodes.getNode(childId); this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent); diff --git a/src/specificClass.js b/src/specificClass.js index afa7446..fef1d3f 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -44,18 +44,6 @@ class Reactor { this.speedUpFactor = 60; // speed up factor for simulation, 60 means 1 minute per simulated second } - updateMeasurement(variant, subType, value, position) { - this.logger.debug(`---------------------- updating ${subType} ------------------ `); - switch (subType) { - case "temperature": - this.temperature = value; - break; - default: - this.logger.error(`Type '${subType}' not recognized for measured update.`); - return; - } - } - /** * Setter for influent data. * @param {object} input - Input object (msg) containing payload with inlet index, flow rate, and concentrations. @@ -109,6 +97,46 @@ class Reactor { } } + registerChild(child, softwareType) { + switch (softwareType) { + case "reactor": + this.logger.debug(`Registering reactor child.`); + this.connectReactor(child); + break; + + default: + this.logger.error(`Unrecognized softwareType: ${softwareType}`); + } + + } + + connectReactor(reactor) { + if (!reactor) { + this.logger.warn("Invalid reactor provided."); + return; + } + + this.upstreamReactor = reactor; + + reactor.emitter.on("stateChange", (data) => { + this.logger.debug(`State change of upstream reactor detected.`); + this.updateState(data); + }); + } + + + updateMeasurement(variant, subType, value, position) { + this.logger.debug(`---------------------- updating ${subType} ------------------ `); + switch (subType) { + case "temperature": + this.temperature = value; + break; + default: + this.logger.error(`Type '${subType}' not recognized for measured update.`); + return; + } + } + /** * Update the reactor state based on the new time. * @param {number} newTime - New time to update reactor state to, in milliseconds since epoch.