Compare commits

..

10 Commits

5 changed files with 105 additions and 35 deletions

4
package-lock.json generated
View File

@@ -9,12 +9,12 @@
"version": "0.0.1",
"license": "SEE LICENSE",
"dependencies": {
"generalFunctions": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git"
"generalFunctions": "git+http://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#fix-missing-references"
}
},
"node_modules/generalFunctions": {
"version": "1.0.0",
"resolved": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#f13ee68938ea9d4b3a17ad90618c72634769c777",
"resolved": "git+http://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#3876f86530cc9c4c2ec65f305376923e6582eb85",
"license": "SEE LICENSE"
}
}

View File

@@ -22,6 +22,6 @@
}
},
"dependencies": {
"generalFunctions": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git"
"generalFunctions": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#fix-missing-references"
}
}

View File

@@ -1,8 +0,0 @@
class liquidFlowHandler {
constructor(config) {
this.config = config;
}
}
module.exports = { liquidFlowHandler };

View File

@@ -1,11 +1,11 @@
const Specific = require("./specificClass.js");
/**
* node class.js
*
* Encapsulates all node logic in a reusable class. In future updates we can split this into multiple generic classes and use the config to specifiy which ones to use.
* This allows us to keep the Node-RED node clean and focused on wiring up the UI and event handlers.
*/
const Specific = require("./specificClass.js");
class nodeClass {
/**
* Create a Node.
@@ -28,9 +28,8 @@ class nodeClass {
this._setupSpecificClass();
// Wire up event and lifecycle handlers
// this._registerChild();
this._startTickLoop();
// this._attachInputHandler();
this._attachInputHandler();
this._attachCloseHandler();
}
@@ -43,16 +42,16 @@ class nodeClass {
// Merge UI config over defaults
this.config = {
general: {
name: uiConfig.name,
name: uiConfig.name || this.name,
id: this.node.id, // node.id is for the child registration process
unit: uiConfig.unit, // add converter options later to convert to default units (need like a model that defines this which units we are going to use and then conver to those standards)
unit: null,
logging: {
enabled: uiConfig.enableLog,
logLevel: uiConfig.logLevel
}
},
functionality: {
positionVsParent: uiConfig.positionVsParent || 'atEquipment', // Default to 'atEquipment' if not specified
positionVsParent: uiConfig.positionVsParent || 'atEquipment' // Default to 'atEquipment' if not specified
}
};
}
@@ -68,20 +67,6 @@ class nodeClass {
this.node.source = this.source; // Store the source in the node instance for easy access
}
/**
* Register this node as a child upstream and downstream.
* Delayed to avoid Node-RED startup race conditions.
*/
_registerChild() {
setTimeout(() => {
this.node.send([
null,
null,
{ topic: 'registerChild', payload: this.config.general.id, positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' },
]);
}, 100);
}
/**
* Start the periodic tick loop.
*/
@@ -95,8 +80,8 @@ class nodeClass {
* Execute a single tick and send outputs.
*/
_tick() {
processMsg = null;
influxMsg = null;
let processMsg = this.source.getOutput();
let influxMsg = null;
// Send only updated outputs on ports 0 & 1
this.node.send([processMsg, influxMsg, null]);

93
src/specificClass.js Normal file
View File

@@ -0,0 +1,93 @@
const { childRegistrationUtils, logger } = require('generalFunctions');
class liquidFlowHandler {
constructor(config) {
this.config = config;
this.logger = new logger(this.config.general.logging.enabled, this.config.general.logging.logLevel, config.general.name);
this.reactors = [null, null];
this.pump = null;
this.flow = 0;
this.childRegistrationUtils = new childRegistrationUtils(this);
}
updateState(timeStamp) {
this.updatePumpFlow();
const effluent = this.reactors[1].getEffluent;
effluent.payload.F = this.flow;
effluent.payload.inlet = 1;
this.reactors[0].setInfluent = effluent;
}
updatePumpFlow() {
const measuredFlow = this.pump.measurements.type("flow").variant("measured").position("downstream").getCurrentValue();
if (!measuredFlow) {
this.logger.warn(`Invalid flow value provided: ${measuredFlow}`);
this.flow = 0;
return;
}
this.flow = measuredFlow;
}
getOutput() {
const mainEffluent = this.reactors[1].getEffluent;
const sideStream = structuredClone(mainEffluent);
const F_in = mainEffluent.payload.F;
mainEffluent.payload.F = Math.max(F_in - this.flow, 0);
sideStream.payload.F = F_in < this.flow ? F_in : 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;