Added sanitizing of input for handleInput for rotating machine
This commit is contained in:
@@ -199,6 +199,11 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
async handleInput(source, action, parameter) {
|
async handleInput(source, action, parameter) {
|
||||||
|
|
||||||
|
//sanitize input
|
||||||
|
if( typeof action !== 'string'){this.logger.error(`Action must be string`); return;}
|
||||||
|
//convert to lower case to avoid to many mistakes in commands
|
||||||
|
action = action.toLowerCase();
|
||||||
|
|
||||||
if (!this.isValidSourceForMode(source, this.currentMode)) {
|
if (!this.isValidSourceForMode(source, this.currentMode)) {
|
||||||
let warningTxt = `Source '${source}' is not valid for mode '${this.currentMode}'.`;
|
let warningTxt = `Source '${source}' is not valid for mode '${this.currentMode}'.`;
|
||||||
this.logger.warn(warningTxt);
|
this.logger.warn(warningTxt);
|
||||||
@@ -209,23 +214,24 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case "execSequence":
|
|
||||||
|
case "execsequence":
|
||||||
return await this.executeSequence(parameter);
|
return await this.executeSequence(parameter);
|
||||||
|
|
||||||
case "execMovement":
|
case "execmovement":
|
||||||
return await this.setpoint(parameter);
|
return await this.setpoint(parameter);
|
||||||
|
|
||||||
case "flowMovement":
|
case "flowmovement":
|
||||||
// Calculate the control value for a desired flow
|
// Calculate the control value for a desired flow
|
||||||
const pos = this.calcCtrl(parameter);
|
const pos = this.calcCtrl(parameter);
|
||||||
// Move to the desired setpoint
|
// Move to the desired setpoint
|
||||||
return await this.setpoint(pos);
|
return await this.setpoint(pos);
|
||||||
|
|
||||||
case "emergencyStop":
|
case "emergencystop":
|
||||||
this.logger.warn(`Emergency stop activated by '${source}'.`);
|
this.logger.warn(`Emergency stop activated by '${source}'.`);
|
||||||
return await this.executeSequence("emergencyStop");
|
return await this.executeSequence("emergencyStop");
|
||||||
|
|
||||||
case "statusCheck":
|
case "statuscheck":
|
||||||
this.logger.info(`Status Check: Mode = '${this.currentMode}', Source = '${source}'.`);
|
this.logger.info(`Status Check: Mode = '${this.currentMode}', Source = '${source}'.`);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -704,23 +710,12 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
|
|
||||||
// Improved output object generation
|
// Improved output object generation
|
||||||
const output = {};
|
const output = {};
|
||||||
//build the output object
|
|
||||||
this.measurements.getTypes().forEach(type => {
|
|
||||||
this.measurements.getVariants(type).forEach(variant => {
|
|
||||||
|
|
||||||
const downstreamVal = this.measurements.type(type).variant(variant).position("downstream").getCurrentValue();
|
Object.entries(this.measurements.measurements).forEach(([type, variants]) => {
|
||||||
const upstreamVal = this.measurements.type(type).variant(variant).position("upstream").getCurrentValue();
|
Object.entries(variants).forEach(([variant, positions]) => {
|
||||||
|
Object.entries(positions).forEach(([position, measurement]) => {
|
||||||
if (downstreamVal != null) {
|
output[`${type}.${variant}.${position}`] = measurement.getCurrentValue();
|
||||||
output[`downstream_${variant}_${type}`] = downstreamVal;
|
});
|
||||||
}
|
|
||||||
if (upstreamVal != null) {
|
|
||||||
output[`upstream_${variant}_${type}`] = upstreamVal;
|
|
||||||
}
|
|
||||||
if (downstreamVal != null && upstreamVal != null) {
|
|
||||||
const diffVal = this.measurements.type(type).variant(variant).difference().value;
|
|
||||||
output[`differential_${variant}_${type}`] = diffVal;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -733,6 +728,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
|
|||||||
output["cog"] = this.cog; // flow / power efficiency
|
output["cog"] = this.cog; // flow / power efficiency
|
||||||
output["NCog"] = this.NCog; // normalized cog
|
output["NCog"] = this.NCog; // normalized cog
|
||||||
output["NCogPercent"] = Math.round(this.NCog * 100 * 100) / 100 ;
|
output["NCogPercent"] = Math.round(this.NCog * 100 * 100) / 100 ;
|
||||||
|
output["maintenanceTime"] = this.state.getMaintenanceTimeHours();
|
||||||
|
|
||||||
if(this.flowDrift != null){
|
if(this.flowDrift != null){
|
||||||
const flowDrift = this.flowDrift;
|
const flowDrift = this.flowDrift;
|
||||||
|
|||||||
Reference in New Issue
Block a user