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