diff --git a/src/nodeClass.js b/src/nodeClass.js index 6c73b48..842c3a6 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -190,7 +190,7 @@ class nodeClass { } return status; } catch (error) { - node.error("Error in updateNodeStatus: " + error.message); + this.node.error("Error in updateNodeStatus: " + error.message); return { fill: "red", shape: "ring", text: "Status Error" }; } } @@ -246,32 +246,36 @@ class nodeClass { /* Update to complete event based node by putting the tick function after an input event */ const m = this.source; switch(msg.topic) { - case 'registerChild': + case 'registerChild': { // Register this node as a child of the parent node const childId = msg.payload; - const childObj = this.RED.nodes.getNode(childId); + const childObj = this.RED.nodes.getNode(childId); m.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent); break; + } case 'setMode': m.setMode(msg.payload); break; - case 'execSequence': + case 'execSequence': { const { source, action, parameter } = msg.payload; m.handleInput(source, action, parameter); break; - case 'execMovement': + } + case 'execMovement': { const { source: mvSource, action: mvAction, setpoint } = msg.payload; m.handleInput(mvSource, mvAction, Number(setpoint)); break; - case 'flowMovement': + } + case 'flowMovement': { const { source: fmSource, action: fmAction, setpoint: fmSetpoint } = msg.payload; m.handleInput(fmSource, fmAction, Number(fmSetpoint)); - break; - case 'emergencystop': + } + case 'emergencystop': { const { source: esSource, action: esAction } = msg.payload; m.handleInput(esSource, esAction); break; + } case 'showWorkingCurves': m.showWorkingCurves(); send({ topic : "Showing curve" , payload: m.showWorkingCurves() }); diff --git a/src/specificClass.js b/src/specificClass.js index b80f66b..2d7ce86 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -101,9 +101,11 @@ class Machine { //assume standard atm pressure is at sea level this.measurements.type('atmPressure').variant('measured').position('atEquipment').value(101325).unit('Pa'); //populate min and max - const flowunit = this.config.general.unit; - this.measurements.type('flow').variant('predicted').position('max').value(this.predictFlow.currentFxyYMax, Date.now() , flowunit) - this.measurements.type('flow').variant('predicted').position('min').value(this.predictFlow.currentFxyYMin).unit(this.config.general.unit); + if (this.predictFlow) { + const flowunit = this.config.general.unit; + this.measurements.type('flow').variant('predicted').position('max').value(this.predictFlow.currentFxyYMax, Date.now() , flowunit); + this.measurements.type('flow').variant('predicted').position('min').value(this.predictFlow.currentFxyYMin).unit(this.config.general.unit); + } } _updateState(){ @@ -143,48 +145,6 @@ class Machine { //rebuild to measurementype.variant no position and then switch based on values not strings or names. const eventName = `${measurementType}.measured.${position}`; - this.logger.debug(`Setting up listener for ${eventName} from child ${child.config.general.name}`); - // Register event listener for measurement updates - child.measurements.emitter.on(eventName, (eventData) => { - this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`); - - - this.logger.debug(` Emitting... ${eventName} with data:`); - // Store directly in parent's measurement container - this.measurements - .type(measurementType) - .variant("measured") - .position(position) - .value(eventData.value, eventData.timestamp, eventData.unit); - - // Call the appropriate handler - this._callMeasurementHandler(measurementType, eventData.value, position, eventData); - }); - } - } - -// Centralized handler dispatcher -_callMeasurementHandler(measurementType, value, position, context) { - switch (measurementType) { - case 'pressure': - this.updateMeasuredPressure(value, position, context); - break; - - case 'flow': - this.updateMeasuredFlow(value, position, context); - break; - - case 'temperature': - this.updateMeasuredTemperature(value, position, context); - break; - - default: - this.logger.warn(`No handler for measurement type: ${measurementType}`); - // Generic handler - just update position - this.updatePosition(); - break; - } -} this.logger.debug(`Setting up listener for ${eventName} from child ${measurementChild.config.general.name}`); // Register event listener for measurement updates measurementChild.measurements.emitter.on(eventName, (eventData) => { @@ -195,26 +155,36 @@ _callMeasurementHandler(measurementType, value, position, context) { .type(measurementType) .variant("measured") .position(position) - .value(eventData.value, eventData.timestamp, eventData.unit); - + .value(eventData.value, eventData.timestamp, eventData.unit); + // Call the appropriate handler - switch (measurementType) { - case 'pressure': - this.updateMeasuredPressure(eventData.value, position, eventData); - break; - - case 'flow': - this.updateMeasuredFlow(eventData.value, position, eventData); - break; - - default: - this.logger.warn(`No handler for measurement type: ${measurementType}`); - // Generic handler - just update position - this.updatePosition(); - } + this._callMeasurementHandler(measurementType, eventData.value, position, eventData); }); } + // Centralized handler dispatcher + _callMeasurementHandler(measurementType, value, position, context) { + switch (measurementType) { + case 'pressure': + this.updateMeasuredPressure(value, position, context); + break; + + case 'flow': + this.updateMeasuredFlow(value, position, context); + break; + + case 'temperature': + this.updateMeasuredTemperature(value, position, context); + break; + + default: + this.logger.warn(`No handler for measurement type: ${measurementType}`); + // Generic handler - just update position + this.updatePosition(); + break; + } + } + _connectReactor(reactorChild) { this.downstreamSink = reactorChild; // downstream from the pumps perpective } @@ -304,11 +274,12 @@ _callMeasurementHandler(measurementType, value, position, context) { case "exitmaintenance": return await this.executeSequence(parameter); - case "flowmovement": + case "flowmovement": { // Calculate the control value for a desired flow const pos = this.calcCtrl(parameter); // Move to the desired setpoint return await this.setpoint(pos); + } case "emergencystop": this.logger.warn(`Emergency stop activated by '${source}'.`);