2025-10-22 16:07:42 +02:00
|
|
|
const { childRegistrationUtils, logger, MeasurementContainer } = require('generalFunctions');
|
|
|
|
|
const EventEmitter = require('events');
|
|
|
|
|
|
|
|
|
|
class Settler {
|
|
|
|
|
constructor(config) {
|
|
|
|
|
this.config = config;
|
|
|
|
|
// EVOLV stuff
|
|
|
|
|
this.logger = new logger(this.config.general.logging.enabled, this.config.general.logging.logLevel, config.general.name);
|
|
|
|
|
this.emitter = new EventEmitter();
|
|
|
|
|
this.measurements = new MeasurementContainer();
|
|
|
|
|
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
|
2025-10-23 17:15:41 +02:00
|
|
|
|
|
|
|
|
this.upstreamReactor = null;
|
|
|
|
|
this.returnPump = null;
|
|
|
|
|
|
|
|
|
|
// state variables
|
|
|
|
|
this.F_in = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get getEffluent() {
|
|
|
|
|
return;
|
2025-10-22 16:07:42 +02:00
|
|
|
}
|
2025-10-22 16:22:33 +02:00
|
|
|
|
|
|
|
|
registerChild(child, softwareType) {
|
|
|
|
|
switch (softwareType) {
|
2025-10-23 17:15:41 +02:00
|
|
|
case "measurement":
|
|
|
|
|
this.logger.debug(`Registering measurement child...`);
|
|
|
|
|
this._connectMeasurement(child);
|
|
|
|
|
break;
|
|
|
|
|
case "reactor":
|
|
|
|
|
this.logger.debug(`Registering reactor child...`);
|
|
|
|
|
this._connectReactor(child);
|
|
|
|
|
break;
|
|
|
|
|
case "machine":
|
|
|
|
|
this.logger.debug(`Registering machine child...`);
|
|
|
|
|
this._connectMachine(child);
|
|
|
|
|
break;
|
2025-10-22 16:22:33 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
this.logger.error(`Unrecognized softwareType: ${softwareType}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-23 17:15:41 +02:00
|
|
|
|
|
|
|
|
_connectMeasurement(measurementChild) {
|
|
|
|
|
if (!measurementChild) {
|
|
|
|
|
this.logger.error("Invalid measurement provided.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const position = measurementChild.config.functionality.positionVsParent;
|
|
|
|
|
const measurementType = measurementChild.config.asset.type;
|
|
|
|
|
const eventName = `${measurementType}.measured.${position}`;
|
|
|
|
|
|
|
|
|
|
// Register event listener for measurement updates
|
|
|
|
|
measurementChild.measurements.emitter.on(eventName, (eventData) => {
|
|
|
|
|
this.logger.debug(`${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
|
|
|
|
|
|
|
|
|
|
// Store directly in parent's measurement container
|
|
|
|
|
this.measurements
|
|
|
|
|
.type(measurementType)
|
|
|
|
|
.variant("measured")
|
|
|
|
|
.position(position)
|
|
|
|
|
.value(eventData.value, eventData.timestamp, eventData.unit);
|
|
|
|
|
|
|
|
|
|
this._updateMeasurement(measurementType, eventData.value, position, eventData);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_connectReactor(reactorChild) {
|
|
|
|
|
if (!reactorChild) {
|
|
|
|
|
this.logger.error("Invalid reactor provided.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reactorChild.config.functionality.positionVsParent != "upstream") {
|
|
|
|
|
this.logger.warn("Reactor children of reactors should always be upstream.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.upstreamReactor = reactorChild;
|
|
|
|
|
|
|
|
|
|
reactorChild.emitter.on("stateChange", (eventData) => {
|
|
|
|
|
this.logger.debug(`State change of upstream reactor detected.`);
|
|
|
|
|
const effluent = this.upstreamReactor.getEffluent[0];
|
|
|
|
|
this.F_in = effluent.payload.F;
|
|
|
|
|
this.Cs_in = effluent.payload.C;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_connectMachine(machineChild) {
|
|
|
|
|
if (!machineChild) {
|
|
|
|
|
this.logger.error("Invalid rotating machine provided.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (machineChild.config.functionality.positionVsParent == "downstream") {
|
|
|
|
|
machineChild.upstreamReactor = this;
|
|
|
|
|
this.returnPump = machineChild;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-10-22 16:07:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { Settler };
|