This commit is contained in:
znetsixe
2026-02-23 13:17:39 +01:00
parent ee38c8b581
commit f8012c8bad
2 changed files with 36 additions and 44 deletions

View File

@@ -80,7 +80,7 @@ class nodeClass {
const availableMachines = Object.values(mg.machines || {}).filter((machine) => { const availableMachines = Object.values(mg.machines || {}).filter((machine) => {
// Safety check: ensure machine and machine.state exist // Safety check: ensure machine and machine.state exist
if (!machine || !machine.state || typeof machine.state.getCurrentState !== 'function') { if (!machine || !machine.state || typeof machine.state.getCurrentState !== 'function') {
console.warn(`Machine missing or invalid:`, machine?.config?.general?.id || 'unknown'); mg.logger?.warn(`Machine missing or invalid: ${machine?.config?.general?.id || 'unknown'}`);
return false; return false;
} }
@@ -195,67 +195,52 @@ class nodeClass {
this.node.on( this.node.on(
"input", "input",
async (msg, send, done) => { async (msg, send, done) => {
const mg = this.source; const mg = this.source;
const RED = this.RED; const RED = this.RED;
try {
switch (msg.topic) { switch (msg.topic) {
case "registerChild": case "registerChild": {
//console.log(`Registering child in mgc: ${msg.payload}`); const childId = msg.payload;
const childId = msg.payload; const childObj = RED.nodes.getNode(childId);
const childObj = RED.nodes.getNode(childId); if (!childObj || !childObj.source) {
mg.logger.warn(`registerChild skipped: missing child/source for id=${childId}`);
// Debug: Check what we're getting break;
//console.log(`Child object:`, childObj ? 'found' : 'NOT FOUND'); }
//console.log(`Child source:`, childObj?.source ? 'exists' : 'MISSING'); mg.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
if (childObj?.source) { break;
//console.log(`Child source type:`, childObj.source.constructor.name); }
//console.log(`Child has state:`, !!childObj.source.state);
}
mg.childRegistrationUtils.registerChild(
childObj.source,
msg.positionVsParent
);
// Debug: Check machines after registration
//console.log(`Total machines after registration:`, Object.keys(mg.machines || {}).length);
break;
case "setMode": case "setMode":
const mode = msg.payload; mg.setMode(msg.payload);
mg.setMode(mode);
break; break;
case "setScaling": case "setScaling":
const scaling = msg.payload; mg.setScaling(msg.payload);
mg.setScaling(scaling);
break; break;
case "Qd": {
case "Qd":
const Qd = parseFloat(msg.payload); const Qd = parseFloat(msg.payload);
const sourceQd = "parent"; const sourceQd = "parent";
if (isNaN(Qd)) { if (isNaN(Qd)) {
return mg.logger.error(`Invalid demand value: ${Qd}`); mg.logger.error(`Invalid demand value: ${msg.payload}`);
break;
} }
try { try {
await mg.handleInput(sourceQd, Qd); await mg.handleInput(sourceQd, Qd);
msg.topic = mg.config.general.name; msg.topic = mg.config.general.name;
msg.payload = "done"; msg.payload = "done";
send(msg); send(msg);
} catch (e) { } catch (error) {
console.log(e); mg.logger.error(`Failed to process Qd: ${error.message}`);
} }
break; break;
}
default: default:
// Handle unknown topics if needed
mg.logger.warn(`Unknown topic: ${msg.topic}`); mg.logger.warn(`Unknown topic: ${msg.topic}`);
break; break;
} }
done(); } catch (error) {
mg.logger.error(`Input handler failure: ${error.message}`);
} }
if (typeof done === 'function') done();
}
); );
} }
@@ -266,7 +251,7 @@ class nodeClass {
this.node.on("close", (done) => { this.node.on("close", (done) => {
clearInterval(this._tickInterval); clearInterval(this._tickInterval);
clearInterval(this._statusInterval); clearInterval(this._statusInterval);
done(); if (typeof done === 'function') done();
}); });
} }
} }

View File

@@ -2,6 +2,10 @@
const EventEmitter = require("events"); const EventEmitter = require("events");
const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils} = require('generalFunctions'); const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils} = require('generalFunctions');
/**
* Machine group controller domain model.
* Aggregates multiple rotating machines and coordinates group-level optimization/control.
*/
class MachineGroup { class MachineGroup {
constructor(machineGroupConfig = {}) { constructor(machineGroupConfig = {}) {
@@ -50,7 +54,8 @@ class MachineGroup {
registerChild(child,softwareType) { registerChild(child,softwareType) {
this.logger.debug('Setting up childs specific for this class'); this.logger.debug('Setting up childs specific for this class');
const position = child.config.general.positionVsParent; // Prefer functionality-scoped position metadata; keep general fallback for legacy nodes.
const position = child.config?.functionality?.positionVsParent || child.config?.general?.positionVsParent;
if(softwareType == "machine"){ if(softwareType == "machine"){
// Check if the machine is already registered // Check if the machine is already registered
@@ -1396,6 +1401,8 @@ async function makeMachines(){
} }
makeMachines(); if (require.main === module) {
makeMachines();
}
//*/ //*/