2025-06-25 17:26:13 +02:00
|
|
|
const nameOfNode = 'rotatingMachine';
|
2025-07-01 15:25:07 +02:00
|
|
|
const nodeClass = require('./src/nodeClass.js');
|
2025-06-25 17:26:13 +02:00
|
|
|
const { MenuManager, configManager } = require('generalFunctions');
|
2026-05-14 22:52:24 +02:00
|
|
|
const { buildQHCurve } = require('./src/display/workingCurves');
|
2025-05-14 10:07:27 +02:00
|
|
|
|
2025-06-25 17:26:13 +02:00
|
|
|
module.exports = function(RED) {
|
|
|
|
|
// 1) Register the node type and delegate to your class
|
|
|
|
|
RED.nodes.registerType(nameOfNode, function(config) {
|
|
|
|
|
RED.nodes.createNode(this, config);
|
2025-07-01 15:25:07 +02:00
|
|
|
this.nodeClass = new nodeClass(config, RED, this, nameOfNode);
|
2025-06-25 17:26:13 +02:00
|
|
|
});
|
2025-05-14 10:07:27 +02:00
|
|
|
|
2025-06-25 17:26:13 +02:00
|
|
|
// 2) Setup the dynamic menu & config endpoints
|
|
|
|
|
const menuMgr = new MenuManager();
|
|
|
|
|
const cfgMgr = new configManager();
|
2025-05-14 10:07:27 +02:00
|
|
|
|
2025-06-25 17:26:13 +02:00
|
|
|
// Serve /rotatingMachine/menu.js
|
|
|
|
|
RED.httpAdmin.get(`/${nameOfNode}/menu.js`, (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const script = menuMgr.createEndpoint(nameOfNode, ['asset','logger','position']);
|
|
|
|
|
res.type('application/javascript').send(script);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
res.status(500).send(`// Error generating menu: ${err.message}`);
|
2025-05-14 10:07:27 +02:00
|
|
|
}
|
2025-06-25 17:26:13 +02:00
|
|
|
});
|
2025-05-14 10:07:27 +02:00
|
|
|
|
2025-06-25 17:26:13 +02:00
|
|
|
// Serve /rotatingMachine/configData.js
|
|
|
|
|
RED.httpAdmin.get(`/${nameOfNode}/configData.js`, (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const script = cfgMgr.createEndpoint(nameOfNode);
|
|
|
|
|
res.type('application/javascript').send(script);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
res.status(500).send(`// Error generating configData: ${err.message}`);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-05-14 22:52:24 +02:00
|
|
|
|
|
|
|
|
// Q-H curve sampler — served on RED.httpNode (the dashboard/runtime
|
|
|
|
|
// router) so dashboard function nodes can fetch without admin auth.
|
|
|
|
|
// GET /rotatingMachine/:id/qh-curve?ctrl=<percent>
|
|
|
|
|
// Returns { ctrlPct, points: [{ Q (m³/h), H (m), dpPa }, ...] }
|
|
|
|
|
RED.httpNode.get(`/${nameOfNode}/:id/qh-curve`, (req, res) => {
|
|
|
|
|
const node = RED.nodes.getNode(req.params.id);
|
|
|
|
|
const source = node?.source;
|
|
|
|
|
if (!source) {
|
|
|
|
|
res.status(404).json({ error: `No rotatingMachine with id ${req.params.id}` });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const ctrl = Number(req.query.ctrl);
|
|
|
|
|
const result = buildQHCurve(source, Number.isFinite(ctrl) ? ctrl : source.state?.getCurrentPosition?.() ?? 0);
|
|
|
|
|
res.json(result);
|
|
|
|
|
});
|
2025-05-14 10:07:27 +02:00
|
|
|
};
|