diff --git a/settler.html b/settler.html
index 429f818..09ebea5 100644
--- a/settler.html
+++ b/settler.html
@@ -1,86 +1,86 @@
\ No newline at end of file
diff --git a/settler.js b/settler.js
index 06f81a1..12fbb6b 100644
--- a/settler.js
+++ b/settler.js
@@ -4,23 +4,23 @@ const { MenuManager } = require('generalFunctions');
module.exports = function (RED) {
- // Register the node type
- RED.nodes.registerType(nameOfNode, function (config) {
- // Initialize the Node-RED node first
- RED.nodes.createNode(this, config);
- // Then create your custom class and attach it
- this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
- });
+ // Register the node type
+ RED.nodes.registerType(nameOfNode, function (config) {
+ // Initialize the Node-RED node first
+ RED.nodes.createNode(this, config);
+ // Then create your custom class and attach it
+ this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
+ });
- const menuMgr = new MenuManager();
+ const menuMgr = new MenuManager();
- // Serve /settler/menu.js
- RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
- try {
- const script = menuMgr.createEndpoint(nameOfNode, ['logger', 'position']);
- res.type('application/javascript').send(script);
- } catch (err) {
- res.status(500).send(`// Error generating menu: ${err.message}`);
- }
- });
+ // Serve /settler/menu.js
+ RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
+ try {
+ const script = menuMgr.createEndpoint(nameOfNode, ['logger', 'position']);
+ res.type('application/javascript').send(script);
+ } catch (err) {
+ res.status(500).send(`// Error generating menu: ${err.message}`);
+ }
+ });
};
\ No newline at end of file
diff --git a/src/nodeClass.js b/src/nodeClass.js
index 2d16352..702b430 100644
--- a/src/nodeClass.js
+++ b/src/nodeClass.js
@@ -2,113 +2,113 @@ const { Settler } = require('./specificClass.js');
class nodeClass {
- /**
- * Node-RED node class for settler.
- * @param {object} uiConfig - Node-RED node configuration
- * @param {object} RED - Node-RED runtime API
- * @param {object} nodeInstance - Node-RED node instance
- * @param {string} nameOfNode - Name of the node
- */
- constructor(uiConfig, RED, nodeInstance, nameOfNode) {
- // Preserve RED reference for HTTP endpoints if needed
- this.node = nodeInstance;
- this.RED = RED;
- this.name = nameOfNode;
- this.source = null;
+ /**
+ * Node-RED node class for settler.
+ * @param {object} uiConfig - Node-RED node configuration
+ * @param {object} RED - Node-RED runtime API
+ * @param {object} nodeInstance - Node-RED node instance
+ * @param {string} nameOfNode - Name of the node
+ */
+ constructor(uiConfig, RED, nodeInstance, nameOfNode) {
+ // Preserve RED reference for HTTP endpoints if needed
+ this.node = nodeInstance;
+ this.RED = RED;
+ this.name = nameOfNode;
+ this.source = null;
- this._loadConfig(uiConfig)
- this._setupClass();
+ this._loadConfig(uiConfig)
+ this._setupClass();
- this._attachInputHandler();
- this._registerChild();
- this._startTickLoop();
- this._attachCloseHandler();
- }
+ this._attachInputHandler();
+ this._registerChild();
+ this._startTickLoop();
+ this._attachCloseHandler();
+ }
- /**
- * Handle node-red input messages
- */
- _attachInputHandler() {
- this.node.on('input', (msg, send, done) => {
+ /**
+ * Handle node-red input messages
+ */
+ _attachInputHandler() {
+ this.node.on('input', (msg, send, done) => {
- switch (msg.topic) {
- case 'registerChild':
- // Register this node as a parent of the child node
- const childId = msg.payload;
- const childObj = this.RED.nodes.getNode(childId);
- this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
- break;
- default:
- console.log("Unknown topic: " + msg.topic);
- }
+ switch (msg.topic) {
+ case 'registerChild':
+ // Register this node as a parent of the child node
+ const childId = msg.payload;
+ const childObj = this.RED.nodes.getNode(childId);
+ this.source.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
+ break;
+ default:
+ console.log("Unknown topic: " + msg.topic);
+ }
- if (done) {
- done();
- }
- });
- }
+ if (done) {
+ done();
+ }
+ });
+ }
- /**
- * Parse node configuration
- * @param {object} uiConfig Config set in UI in node-red
- */
- _loadConfig(uiConfig) {
- this.config = {
- general: {
- name: uiConfig.name || this.name,
- id: this.node.id,
- unit: null,
- logging: {
- enabled: uiConfig.enableLog,
- logLevel: uiConfig.logLevel
- }
- },
- functionality: {
- positionVsParent: uiConfig.positionVsParent || 'atEquipment', // Default to 'atEquipment' if not specified
- softwareType: "settler" // should be set in config manager
- }
+ /**
+ * Parse node configuration
+ * @param {object} uiConfig Config set in UI in node-red
+ */
+ _loadConfig(uiConfig) {
+ this.config = {
+ general: {
+ name: uiConfig.name || this.name,
+ id: this.node.id,
+ unit: null,
+ logging: {
+ enabled: uiConfig.enableLog,
+ logLevel: uiConfig.logLevel
}
+ },
+ functionality: {
+ positionVsParent: uiConfig.positionVsParent || 'atEquipment', // Default to 'atEquipment' if not specified
+ softwareType: "settler" // should be set in config manager
+ }
}
+ }
- /**
- * 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.node.id, positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' }
- ]);
- }, 100);
- }
+ /**
+ * 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.node.id, positionVsParent: this.config?.functionality?.positionVsParent || 'atEquipment' }
+ ]);
+ }, 100);
+ }
- /**
- * Setup settler class
- */
- _setupClass() {
+ /**
+ * Setup settler class
+ */
+ _setupClass() {
- this.source = new Settler(this.config); // protect from reassignment
- this.node.source = this.source;
- }
+ this.source = new Settler(this.config); // protect from reassignment
+ this.node.source = this.source;
+ }
- _startTickLoop() {
- setTimeout(() => {
- this._tickInterval = setInterval(() => this._tick(), 1000);
- }, 1000);
- }
+ _startTickLoop() {
+ setTimeout(() => {
+ this._tickInterval = setInterval(() => this._tick(), 1000);
+ }, 1000);
+ }
- _tick(){
- this.node.send([null, null, null]);
- }
+ _tick(){
+ this.node.send([null, null, null]);
+ }
- _attachCloseHandler() {
- this.node.on('close', (done) => {
- clearInterval(this._tickInterval);
- done();
- });
- }
+ _attachCloseHandler() {
+ this.node.on('close', (done) => {
+ clearInterval(this._tickInterval);
+ done();
+ });
+ }
}
module.exports = nodeClass;
\ No newline at end of file
diff --git a/src/specificClass.js b/src/specificClass.js
index 32589f9..bc98902 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -10,6 +10,14 @@ class Settler {
this.measurements = new MeasurementContainer();
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
}
+
+ registerChild(child, softwareType) {
+ switch (softwareType) {
+
+ default:
+ this.logger.error(`Unrecognized softwareType: ${softwareType}`);
+ }
+ }
}
module.exports = { Settler };
\ No newline at end of file