Refactor child attachement
This commit is contained in:
@@ -7,33 +7,79 @@ class liquidFlowHandler {
|
|||||||
|
|
||||||
this.logger = new logger(this.config.general.logging.enabled, this.config.general.logging.logLevel, config.general.name);
|
this.logger = new logger(this.config.general.logging.enabled, this.config.general.logging.logLevel, config.general.name);
|
||||||
this.reactors = [null, null];
|
this.reactors = [null, null];
|
||||||
this.machines = {};
|
this.pump = null;
|
||||||
this.debit = 0;
|
this.flow = 0;
|
||||||
this.childRegistrationUtils = new childRegistrationUtils(this);
|
this.childRegistrationUtils = new childRegistrationUtils(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateState(timeStamp) {
|
updateState(timeStamp) {
|
||||||
|
this.getPumpFlow();
|
||||||
let effluent = this.reactors[1].getEffluent;
|
let effluent = this.reactors[1].getEffluent;
|
||||||
effluent.payload.F = this.debit;
|
effluent.payload.F = this.flow;
|
||||||
this.reactors[0].setInfluent = effluent;
|
this.reactors[0].setInfluent = effluent;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChildChange() {
|
getPumpFlow() {
|
||||||
return;
|
this.flow = this.pump.measurements.type("flow").variant("predicted").position("atEquipment").getCurrentValue();
|
||||||
}
|
|
||||||
|
|
||||||
handlePressureChange(machine) {
|
|
||||||
this.debit = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getOutput() {
|
getOutput() {
|
||||||
let mainEffluent = this.reactors[1].getEffluent;
|
let mainEffluent = this.reactors[1].getEffluent;
|
||||||
let sideStream = structuredClone(mainEffluent);
|
let sideStream = structuredClone(mainEffluent);
|
||||||
mainEffluent.payload.F -= this.debit;
|
mainEffluent.payload.F -= this.flow;
|
||||||
sideStream.payload.F = this.debit;
|
sideStream.payload.F = this.flow;
|
||||||
sideStream.payload.inlet = 1;
|
sideStream.payload.inlet = 1;
|
||||||
return {payload: [mainEffluent.payload, sideStream.payload]};
|
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;
|
module.exports = liquidFlowHandler;
|
||||||
Reference in New Issue
Block a user