agent updates
This commit is contained in:
105
src/nodeClass.js
105
src/nodeClass.js
@@ -41,10 +41,13 @@ class nodeClass {
|
||||
* @param {object} uiConfig - Raw config from Node-RED UI.
|
||||
*/
|
||||
_loadConfig(uiConfig,node) {
|
||||
const cfgMgr = new configManager();
|
||||
this.defaultConfig = cfgMgr.getConfig(this.name);
|
||||
|
||||
// Merge UI config over defaults
|
||||
this.config = {
|
||||
general: {
|
||||
name: uiConfig.name || uiConfig.category || this.name,
|
||||
id: 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)
|
||||
logging: {
|
||||
@@ -53,16 +56,23 @@ class nodeClass {
|
||||
}
|
||||
},
|
||||
asset: {
|
||||
uuid: uiConfig.assetUuid, //need to add this later to the asset model
|
||||
tagCode: uiConfig.assetTagCode, //need to add this later to the asset model
|
||||
uuid: uiConfig.uuid,
|
||||
tagCode: uiConfig.assetTagCode,
|
||||
supplier: uiConfig.supplier,
|
||||
category: uiConfig.category, //add later to define as the software type
|
||||
type: uiConfig.assetType,
|
||||
model: uiConfig.model,
|
||||
unit: uiConfig.unit
|
||||
unit: uiConfig.unit,
|
||||
emptyWeightBucket: Number(uiConfig.emptyWeightBucket)
|
||||
},
|
||||
constraints: {
|
||||
samplingtime: Number(uiConfig.samplingtime),
|
||||
minVolume: Number(uiConfig.minvolume),
|
||||
maxWeight: Number(uiConfig.maxweight),
|
||||
},
|
||||
functionality: {
|
||||
positionVsParent: uiConfig.positionVsParent
|
||||
positionVsParent: uiConfig.positionVsParent || 'atEquipment',
|
||||
distance: uiConfig.hasDistance ? uiConfig.distance : undefined
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,6 +88,10 @@ class nodeClass {
|
||||
|
||||
this.source = new Specific(monsterConfig);
|
||||
|
||||
if (uiConfig?.aquon_sample_name) {
|
||||
this.source.aquonSampleName = uiConfig.aquon_sample_name;
|
||||
}
|
||||
|
||||
//store in node
|
||||
this.node.source = this.source; // Store the source in the node instance for easy access
|
||||
|
||||
@@ -111,7 +125,7 @@ try{
|
||||
|
||||
return status;
|
||||
} catch (error) {
|
||||
node.error("Error in updateNodeStatus: " + error);
|
||||
this.node.error("Error in updateNodeStatus: " + error);
|
||||
return { fill: "red", shape: "ring", text: "Status Error" };
|
||||
}
|
||||
}
|
||||
@@ -166,42 +180,53 @@ try{
|
||||
this.node.on('input', (msg, send, done) => {
|
||||
/* Update to complete event based node by putting the tick function after an input event */
|
||||
const m = this.source;
|
||||
switch(msg.topic) {
|
||||
case 'registerChild':
|
||||
// Register this node as a child of the parent node
|
||||
const childId = msg.payload;
|
||||
const childObj = this.RED.nodes.getNode(childId);
|
||||
m.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent);
|
||||
break;
|
||||
case 'setMode':
|
||||
m.setMode(msg.payload);
|
||||
break;
|
||||
case 'execSequence':
|
||||
const { source, action, parameter } = msg.payload;
|
||||
m.handleInput(source, action, parameter);
|
||||
break;
|
||||
case 'execMovement':
|
||||
const { source: mvSource, action: mvAction, setpoint } = msg.payload;
|
||||
m.handleInput(mvSource, mvAction, Number(setpoint));
|
||||
break;
|
||||
case 'flowMovement':
|
||||
const { source: fmSource, action: fmAction, setpoint: fmSetpoint } = msg.payload;
|
||||
m.handleInput(fmSource, fmAction, Number(fmSetpoint));
|
||||
|
||||
break;
|
||||
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() });
|
||||
break;
|
||||
case 'CoG':
|
||||
m.showCoG();
|
||||
send({ topic : "Showing CoG" , payload: m.showCoG() });
|
||||
break;
|
||||
try {
|
||||
switch(msg.topic) {
|
||||
case 'registerChild': {
|
||||
const childId = msg.payload;
|
||||
const childObj = this.RED.nodes.getNode(childId);
|
||||
if (childObj?.source) {
|
||||
m.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'setMode':
|
||||
m.setMode(msg.payload);
|
||||
break;
|
||||
case 'execSequence': {
|
||||
const { source, action, parameter } = msg.payload || {};
|
||||
m.handleInput(source, action, parameter);
|
||||
break;
|
||||
}
|
||||
case 'execMovement': {
|
||||
const { source: mvSource, action: mvAction, setpoint } = msg.payload || {};
|
||||
m.handleInput(mvSource, mvAction, Number(setpoint));
|
||||
break;
|
||||
}
|
||||
case 'flowMovement': {
|
||||
const { source: fmSource, action: fmAction, setpoint: fmSetpoint } = msg.payload || {};
|
||||
m.handleInput(fmSource, fmAction, Number(fmSetpoint));
|
||||
break;
|
||||
}
|
||||
case 'emergencystop': {
|
||||
const { source: esSource, action: esAction } = msg.payload || {};
|
||||
m.handleInput(esSource, esAction);
|
||||
break;
|
||||
}
|
||||
case 'showWorkingCurves':
|
||||
send({ topic : "Showing curve" , payload: m.showWorkingCurves() });
|
||||
break;
|
||||
case 'CoG':
|
||||
send({ topic : "Showing CoG" , payload: m.showCoG() });
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
this.node.error(`Error handling input (${msg?.topic}): ${error?.message || error}`);
|
||||
} finally {
|
||||
done();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user