Merge pull request 'implement-reactor-child' (#2) from implement-reactor-child into main

Reviewed-on: p.vanderwilt/generalFunctions#2
This commit is contained in:
2025-09-03 10:18:21 +00:00

View File

@@ -85,12 +85,12 @@ class ChildRegistrationUtils {
case "actuator": case "actuator":
this.logger.debug(`Registering linear actuator child: ${id}`); this.logger.debug(`Registering linear actuator child: ${id}`);
this.connectActuator(child,positionVsParent); this.connectActuator(child, positionVsParent);
break; break;
case "reactor": case "reactor":
this.logger.debug(`Registering reactor child: ${id}`); this.logger.debug(`Registering reactor child: ${id}`);
this.connectReactor(child); this.connectReactor(child, positionVsParent);
break; break;
default: default:
@@ -228,18 +228,30 @@ class ChildRegistrationUtils {
//wanneer hij deze ontvangt is deltaP van een van de valves veranderd (kan ook zijn niet child zijn, maar dat maakt niet uit) //wanneer hij deze ontvangt is deltaP van een van de valves veranderd (kan ook zijn niet child zijn, maar dat maakt niet uit)
connectReactor(reactor) { connectReactor(reactor, positionVsParent) {
if (!reactor) { if (!reactor) {
this.logger.warn("Invalid reactor provided."); this.logger.warn("Invalid reactor provided.");
return; return;
} }
this.mainClass.upstreamReactor = reactor; // Add reactor to the main class
this.logger.info(`Reactor registered successfully.`); if (this.mainClass?.upstreamReactor){
this.mainClass.upstreamReactor = reactor; // Add reactor to the main class
this.logger.info(`Upstream reactor registered successfully.`);
} else if (this.mainClass?.reactors) {
if (positionVsParent == "downstream") {
this.mainClass.reactors[0] = reactor;
}
if (positionVsParent == "upstream") {
this.mainClass.reactors[1] = reactor;
}
this.logger.info(`Reactor registered successfully: ${this.mainClass.reactors}`);
} else {
this.logger.error(`Reactor not registered!`)
}
reactor.emitter.on("stateChange", (data) => { reactor.emitter.on("stateChange", (data) => {
this.mainClass.logger.debug(`State change of reactor detected: ${data}`); this.mainClass.logger.debug(`State change of upstream reactor detected.`);
this.mainClass.setInflux = data; this.mainClass.updateState(data);
this.mainClass.updateState(data.timestamp);
}); });
} }