From 5c1a5a3be5b8bbba258d40d94e066f0fe26ec382 Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Tue, 16 Sep 2025 16:19:10 +0200
Subject: [PATCH] Refactor child attachement
---
src/specificClass.js | 68 +++++++++++++++++++++++++++++++++++++-------
1 file changed, 57 insertions(+), 11 deletions(-)
diff --git a/src/specificClass.js b/src/specificClass.js
index f039625..fb2a441 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -7,33 +7,79 @@ class liquidFlowHandler {
this.logger = new logger(this.config.general.logging.enabled, this.config.general.logging.logLevel, config.general.name);
this.reactors = [null, null];
- this.machines = {};
- this.debit = 0;
+ this.pump = null;
+ this.flow = 0;
this.childRegistrationUtils = new childRegistrationUtils(this);
}
updateState(timeStamp) {
+ this.getPumpFlow();
let effluent = this.reactors[1].getEffluent;
- effluent.payload.F = this.debit;
+ effluent.payload.F = this.flow;
this.reactors[0].setInfluent = effluent;
}
- handleChildChange() {
- return;
- }
-
- handlePressureChange(machine) {
- this.debit = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
+ getPumpFlow() {
+ this.flow = this.pump.measurements.type("flow").variant("predicted").position("atEquipment").getCurrentValue();
}
getOutput() {
let mainEffluent = this.reactors[1].getEffluent;
let sideStream = structuredClone(mainEffluent);
- mainEffluent.payload.F -= this.debit;
- sideStream.payload.F = this.debit;
+ mainEffluent.payload.F -= this.flow;
+ sideStream.payload.F = this.flow;
sideStream.payload.inlet = 1;
return {payload: [mainEffluent.payload, sideStream.payload]};
}
+
+ registerChild(child, softwareType) {
+ switch (softwareType) {
+ case "machine":
+ this.logger.debug(`Registering machine child.`);
+ this._connectMachine(child);
+ break;
+ case "reactor":
+ this.logger.debug(`Registering reactor child.`);
+ this._connectReactor(child);
+ break;
+
+ default:
+ this.logger.error(`Unrecognized softwareType: ${softwareType}`);
+ }
+ }
+
+ _connectMachine(machine) {
+ if (!machine) {
+ this.logger.warn("Invalid machine provided.");
+ return;
+ }
+
+ if (this.pump) {
+ this.logger.warn("Too many pumps provided.")
+ return;
+ }
+
+ this.pump = machine;
+ }
+
+ _connectReactor(reactor) {
+ const position = reactor.config.functionality.positionVsParent;
+
+ if (position == "downstream") {
+ this.reactors[0] = reactor;
+ }
+ if (position == "upstream") {
+ this.reactors[1] = reactor;
+ }
+
+ this.logger.debug("Attached reactor.")
+
+ reactor.emitter.on("stateChange", (data) => {
+ this.logger.debug(`State change of attached reactor detected.`);
+ this.updateState(data);
+ });
+ }
+
}
module.exports = liquidFlowHandler;
\ No newline at end of file