@bldgblocks/node-red-contrib-control 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +202 -0
- package/nodes/average-block.js +43 -22
- package/nodes/changeover-block.js +119 -55
- package/nodes/delay-block.html +2 -2
- package/nodes/delay-block.js +47 -18
- package/nodes/enum-switch-block.js +36 -7
- package/nodes/global-getter.html +40 -43
- package/nodes/global-getter.js +67 -24
- package/nodes/global-setter.html +62 -12
- package/nodes/global-setter.js +150 -17
- package/nodes/hysteresis-block.js +67 -11
- package/nodes/max-block.js +37 -16
- package/nodes/min-block.js +36 -19
- package/nodes/minmax-block.js +43 -17
- package/nodes/on-change-block.js +34 -13
- package/nodes/pid-block.js +108 -44
- package/nodes/rate-of-change-block.js +43 -17
- package/nodes/string-builder-block.js +58 -25
- package/nodes/tstat-block.js +134 -60
- package/nodes/units-block.js +4 -3
- package/nodes/utils.js +17 -2
- package/package.json +2 -2
package/nodes/max-block.js
CHANGED
|
@@ -4,23 +4,18 @@ module.exports = function(RED) {
|
|
|
4
4
|
function MaxBlockNode(config) {
|
|
5
5
|
RED.nodes.createNode(this, config);
|
|
6
6
|
const node = this;
|
|
7
|
+
node.isBusy = false;
|
|
7
8
|
|
|
8
9
|
// Initialize runtime state
|
|
9
10
|
node.runtime = {
|
|
10
|
-
name: config.name
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// Evaluate typed-inputs
|
|
14
|
-
try {
|
|
15
|
-
node.runtime.max = parseFloat( RED.util.evaluateNodeProperty( config.max, config.maxType, node ));
|
|
16
|
-
} catch(err) {
|
|
17
|
-
node.status({ fill: "red", shape: "ring", text: "error evaluating properties" });
|
|
18
|
-
}
|
|
11
|
+
name: config.name,
|
|
12
|
+
max: parseFloat(config.max)
|
|
13
|
+
};
|
|
19
14
|
|
|
20
15
|
// Store last output value for status
|
|
21
16
|
let lastOutput = null;
|
|
22
17
|
|
|
23
|
-
node.on("input", function(msg, send, done) {
|
|
18
|
+
node.on("input", async function(msg, send, done) {
|
|
24
19
|
send = send || function() { node.send.apply(node, arguments); };
|
|
25
20
|
|
|
26
21
|
// Guard against invalid message
|
|
@@ -30,15 +25,41 @@ module.exports = function(RED) {
|
|
|
30
25
|
return;
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
// Evaluate
|
|
28
|
+
// Evaluate dynamic properties
|
|
34
29
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
|
|
31
|
+
// Check busy lock
|
|
32
|
+
if (node.isBusy) {
|
|
33
|
+
// Update status to let user know they are pushing too fast
|
|
34
|
+
node.status({ fill: "yellow", shape: "ring", text: "busy - dropped msg" });
|
|
35
|
+
if (done) done();
|
|
36
|
+
return;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
|
|
39
|
+
// Lock node during evaluation
|
|
40
|
+
node.isBusy = true;
|
|
41
|
+
|
|
42
|
+
// Begin evaluations
|
|
43
|
+
const evaluations = [];
|
|
44
|
+
|
|
45
|
+
evaluations.push(
|
|
46
|
+
utils.requiresEvaluation(config.maxType)
|
|
47
|
+
? utils.evaluateNodeProperty(config.max, config.maxType, node, msg)
|
|
48
|
+
.then(val => parseFloat(val))
|
|
49
|
+
: Promise.resolve(node.runtime.max),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const results = await Promise.all(evaluations);
|
|
53
|
+
|
|
54
|
+
// Update runtime with evaluated values
|
|
55
|
+
if (!isNaN(results[0])) node.runtime.max = results[0];
|
|
56
|
+
} catch (err) {
|
|
57
|
+
node.error(`Error evaluating properties: ${err.message}`);
|
|
58
|
+
if (done) done();
|
|
41
59
|
return;
|
|
60
|
+
} finally {
|
|
61
|
+
// Release, all synchronous from here on
|
|
62
|
+
node.isBusy = false;
|
|
42
63
|
}
|
|
43
64
|
|
|
44
65
|
// Validate values
|
package/nodes/min-block.js
CHANGED
|
@@ -4,23 +4,18 @@ module.exports = function(RED) {
|
|
|
4
4
|
function MinBlockNode(config) {
|
|
5
5
|
RED.nodes.createNode(this, config);
|
|
6
6
|
const node = this;
|
|
7
|
+
node.isBusy = false;
|
|
7
8
|
|
|
8
9
|
// Initialize runtime state
|
|
9
10
|
node.runtime = {
|
|
10
11
|
name: config.name,
|
|
12
|
+
min: parseFloat(config.min)
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
// Evaluate typed-inputs
|
|
14
|
-
try {
|
|
15
|
-
node.runtime.min = parseFloat(RED.util.evaluateNodeProperty( config.min, config.minType, node ));
|
|
16
|
-
} catch(err) {
|
|
17
|
-
node.status({ fill: "red", shape: "ring", text: "error evaluating properties" });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
15
|
// Store last output value for status
|
|
21
16
|
let lastOutput = null;
|
|
22
17
|
|
|
23
|
-
node.on("input", function(msg, send, done) {
|
|
18
|
+
node.on("input", async function(msg, send, done) {
|
|
24
19
|
send = send || function() { node.send.apply(node, arguments); };
|
|
25
20
|
|
|
26
21
|
// Guard against invalid message
|
|
@@ -30,15 +25,41 @@ module.exports = function(RED) {
|
|
|
30
25
|
return;
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
// Evaluate
|
|
28
|
+
// Evaluate dynamic properties
|
|
34
29
|
try {
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
|
|
31
|
+
// Check busy lock
|
|
32
|
+
if (node.isBusy) {
|
|
33
|
+
// Update status to let user know they are pushing too fast
|
|
34
|
+
node.status({ fill: "yellow", shape: "ring", text: "busy - dropped msg" });
|
|
35
|
+
if (done) done();
|
|
36
|
+
return;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
|
|
39
|
+
// Lock node during evaluation
|
|
40
|
+
node.isBusy = true;
|
|
41
|
+
|
|
42
|
+
// Begin evaluations
|
|
43
|
+
const evaluations = [];
|
|
44
|
+
|
|
45
|
+
evaluations.push(
|
|
46
|
+
utils.requiresEvaluation(config.minType)
|
|
47
|
+
? utils.evaluateNodeProperty(config.min, config.minType, node, msg)
|
|
48
|
+
.then(val => parseFloat(val))
|
|
49
|
+
: Promise.resolve(node.runtime.min),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const results = await Promise.all(evaluations);
|
|
53
|
+
|
|
54
|
+
// Update runtime with evaluated values
|
|
55
|
+
if (!isNaN(results[0])) node.runtime.min = results[0];
|
|
56
|
+
} catch (err) {
|
|
57
|
+
node.error(`Error evaluating properties: ${err.message}`);
|
|
58
|
+
if (done) done();
|
|
41
59
|
return;
|
|
60
|
+
} finally {
|
|
61
|
+
// Release, all synchronous from here on
|
|
62
|
+
node.isBusy = false;
|
|
42
63
|
}
|
|
43
64
|
|
|
44
65
|
// Validate
|
|
@@ -59,11 +80,7 @@ module.exports = function(RED) {
|
|
|
59
80
|
const minValue = parseFloat(msg.payload);
|
|
60
81
|
if (!isNaN(minValue) && minValue >= 0) {
|
|
61
82
|
node.runtime.min = minValue;
|
|
62
|
-
node.status({
|
|
63
|
-
fill: "green",
|
|
64
|
-
shape: "dot",
|
|
65
|
-
text: `min: ${minValue}`
|
|
66
|
-
});
|
|
83
|
+
node.status({ fill: "green", shape: "dot", text: `min: ${minValue}` });
|
|
67
84
|
} else {
|
|
68
85
|
node.status({ fill: "red", shape: "ring", text: "invalid min" });
|
|
69
86
|
}
|
package/nodes/minmax-block.js
CHANGED
|
@@ -4,24 +4,19 @@ module.exports = function(RED) {
|
|
|
4
4
|
function MinMaxBlockNode(config) {
|
|
5
5
|
RED.nodes.createNode(this, config);
|
|
6
6
|
const node = this;
|
|
7
|
+
node.isBusy = false;
|
|
7
8
|
|
|
8
9
|
// Initialize runtime state
|
|
9
10
|
node.runtime = {
|
|
10
11
|
name: config.name,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
node.runtime.min = parseFloat(RED.util.evaluateNodeProperty( config.min, config.minType, node ));
|
|
16
|
-
node.runtime.max = parseFloat(RED.util.evaluateNodeProperty( config.max, config.maxType, node ));
|
|
17
|
-
} catch (err) {
|
|
18
|
-
node.error(`Error evaluating properties: ${err.message}`);
|
|
19
|
-
}
|
|
12
|
+
min: parseFloat(config.min),
|
|
13
|
+
max: parseFloat(config.max)
|
|
14
|
+
};
|
|
20
15
|
|
|
21
16
|
// Store last output value for status
|
|
22
17
|
let lastOutput = null;
|
|
23
18
|
|
|
24
|
-
node.on("input", function(msg, send, done) {
|
|
19
|
+
node.on("input", async function(msg, send, done) {
|
|
25
20
|
send = send || function() { node.send.apply(node, arguments); };
|
|
26
21
|
|
|
27
22
|
// Guard against invalid message
|
|
@@ -31,21 +26,52 @@ module.exports = function(RED) {
|
|
|
31
26
|
return;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
//
|
|
29
|
+
// Evaluate dynamic properties
|
|
35
30
|
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
node.
|
|
31
|
+
|
|
32
|
+
// Check busy lock
|
|
33
|
+
if (node.isBusy) {
|
|
34
|
+
// Update status to let user know they are pushing too fast
|
|
35
|
+
node.status({ fill: "yellow", shape: "ring", text: "busy - dropped msg" });
|
|
36
|
+
if (done) done();
|
|
37
|
+
return;
|
|
41
38
|
}
|
|
39
|
+
|
|
40
|
+
// Lock node during evaluation
|
|
41
|
+
node.isBusy = true;
|
|
42
|
+
|
|
43
|
+
// Begin evaluations
|
|
44
|
+
const evaluations = [];
|
|
45
|
+
|
|
46
|
+
evaluations.push(
|
|
47
|
+
utils.requiresEvaluation(config.minType)
|
|
48
|
+
? utils.evaluateNodeProperty(config.min, config.minType, node, msg)
|
|
49
|
+
.then(val => parseFloat(val))
|
|
50
|
+
: Promise.resolve(node.runtime.min),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
evaluations.push(
|
|
54
|
+
utils.requiresEvaluation(config.maxType)
|
|
55
|
+
? utils.evaluateNodeProperty(config.max, config.maxType, node, msg)
|
|
56
|
+
.then(val => parseFloat(val))
|
|
57
|
+
: Promise.resolve(node.runtime.max),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const results = await Promise.all(evaluations);
|
|
61
|
+
|
|
62
|
+
// Update runtime with evaluated values
|
|
63
|
+
if (!isNaN(results[0])) node.runtime.min = results[0];
|
|
64
|
+
if (!isNaN(results[1])) node.runtime.max = results[1];
|
|
42
65
|
} catch (err) {
|
|
43
66
|
node.error(`Error evaluating properties: ${err.message}`);
|
|
44
67
|
if (done) done();
|
|
45
68
|
return;
|
|
69
|
+
} finally {
|
|
70
|
+
// Release, all synchronous from here on
|
|
71
|
+
node.isBusy = false;
|
|
46
72
|
}
|
|
47
73
|
|
|
48
|
-
// Validate min and max
|
|
74
|
+
// Validate min and max
|
|
49
75
|
if (isNaN(node.runtime.min) || isNaN(node.runtime.max) || node.runtime.min > node.runtime.max) {
|
|
50
76
|
node.status({ fill: "red", shape: "dot", text: `invalid min/max` });
|
|
51
77
|
if (done) done();
|
package/nodes/on-change-block.js
CHANGED
|
@@ -4,22 +4,17 @@ module.exports = function(RED) {
|
|
|
4
4
|
function OnChangeBlockNode(config) {
|
|
5
5
|
RED.nodes.createNode(this, config);
|
|
6
6
|
const node = this;
|
|
7
|
+
node.isBusy = false;
|
|
7
8
|
|
|
8
9
|
// Initialize runtime state
|
|
9
10
|
node.runtime = {
|
|
10
11
|
name: config.name,
|
|
11
12
|
lastValue: null,
|
|
12
|
-
blockTimer: null
|
|
13
|
+
blockTimer: null,
|
|
14
|
+
period: parseFloat(config.period),
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
node.runtime.period = parseFloat(RED.util.evaluateNodeProperty( config.period, config.periodType, node ));
|
|
18
|
-
} catch (err) {
|
|
19
|
-
node.status({ fill: "red", shape: "ring", text: "error evaluating properties" });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
node.on("input", function(msg, send, done) {
|
|
17
|
+
node.on("input", async function(msg, send, done) {
|
|
23
18
|
send = send || function() { node.send.apply(node, arguments); };
|
|
24
19
|
|
|
25
20
|
// Guard against invalid message
|
|
@@ -29,15 +24,41 @@ module.exports = function(RED) {
|
|
|
29
24
|
return;
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
// Evaluate
|
|
27
|
+
// Evaluate dynamic properties
|
|
33
28
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
|
|
30
|
+
// Check busy lock
|
|
31
|
+
if (node.isBusy) {
|
|
32
|
+
// Update status to let user know they are pushing too fast
|
|
33
|
+
node.status({ fill: "yellow", shape: "ring", text: "busy - dropped msg" });
|
|
34
|
+
if (done) done();
|
|
35
|
+
return;
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
// Lock node during evaluation
|
|
39
|
+
node.isBusy = true;
|
|
40
|
+
|
|
41
|
+
// Begin evaluations
|
|
42
|
+
const evaluations = [];
|
|
43
|
+
|
|
44
|
+
evaluations.push(
|
|
45
|
+
utils.requiresEvaluation(config.periodType)
|
|
46
|
+
? utils.evaluateNodeProperty(config.period, config.periodType, node, msg)
|
|
47
|
+
.then(val => parseFloat(val))
|
|
48
|
+
: Promise.resolve(node.runtime.period),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const results = await Promise.all(evaluations);
|
|
52
|
+
|
|
53
|
+
// Update runtime with evaluated values
|
|
54
|
+
if (!isNaN(results[0])) node.runtime.period = results[0];
|
|
37
55
|
} catch (err) {
|
|
38
|
-
node.
|
|
56
|
+
node.error(`Error evaluating properties: ${err.message}`);
|
|
39
57
|
if (done) done();
|
|
40
58
|
return;
|
|
59
|
+
} finally {
|
|
60
|
+
// Release, all synchronous from here on
|
|
61
|
+
node.isBusy = false;
|
|
41
62
|
}
|
|
42
63
|
|
|
43
64
|
// Acceptable fallbacks
|
package/nodes/pid-block.js
CHANGED
|
@@ -5,6 +5,7 @@ module.exports = function(RED) {
|
|
|
5
5
|
RED.nodes.createNode(this, config);
|
|
6
6
|
|
|
7
7
|
const node = this;
|
|
8
|
+
node.isBusy = false;
|
|
8
9
|
|
|
9
10
|
// Initialize runtime state
|
|
10
11
|
node.runtime = {
|
|
@@ -16,22 +17,17 @@ module.exports = function(RED) {
|
|
|
16
17
|
result: 0,
|
|
17
18
|
lastTime: Date.now(),
|
|
18
19
|
tuneMode: false,
|
|
19
|
-
tuneData: { oscillations: [], lastPeak: null, lastTrough: null, Ku: 0, Tu: 0 }
|
|
20
|
+
tuneData: { oscillations: [], lastPeak: null, lastTrough: null, Ku: 0, Tu: 0 },
|
|
21
|
+
kp: parseFloat(config.kp),
|
|
22
|
+
ki: parseFloat(config.ki),
|
|
23
|
+
kd: parseFloat(config.kd),
|
|
24
|
+
setpoint: parseFloat(config.setpoint),
|
|
25
|
+
deadband: parseFloat(config.deadband),
|
|
26
|
+
outMin: config.outMin ? parseFloat(config.outMin) : null,
|
|
27
|
+
outMax: config.outMax ? parseFloat(config.outMax) : null,
|
|
28
|
+
maxChange: parseFloat(config.maxChange),
|
|
29
|
+
run: !!config.run,
|
|
20
30
|
};
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
node.runtime.kp = parseFloat(RED.util.evaluateNodeProperty( config.kp, config.kpType, node ));
|
|
24
|
-
node.runtime.ki = parseFloat(RED.util.evaluateNodeProperty( config.ki, config.kiType, node ));
|
|
25
|
-
node.runtime.kd = parseFloat(RED.util.evaluateNodeProperty( config.kd, config.kdType, node ));
|
|
26
|
-
node.runtime.setpoint = parseFloat(RED.util.evaluateNodeProperty( config.setpoint, config.setpointType, node ));
|
|
27
|
-
node.runtime.deadband = parseFloat(RED.util.evaluateNodeProperty( config.deadband, config.deadbandType, node ));
|
|
28
|
-
node.runtime.outMin = parseFloat(RED.util.evaluateNodeProperty( config.outMin, config.outMinType, node ));
|
|
29
|
-
node.runtime.outMax = parseFloat(RED.util.evaluateNodeProperty( config.outMax, config.outMaxType, node ));
|
|
30
|
-
node.runtime.maxChange = parseFloat(RED.util.evaluateNodeProperty( config.maxChange, config.maxChangeType, node ));
|
|
31
|
-
node.runtime.run = RED.util.evaluateNodeProperty( config.run, config.runType, node ) === true;
|
|
32
|
-
} catch (err) {
|
|
33
|
-
node.error(`Error evaluating properties: ${err.message}`);
|
|
34
|
-
}
|
|
35
31
|
|
|
36
32
|
// Initialize internal variables
|
|
37
33
|
let storekp = parseFloat(config.kp) || 0;
|
|
@@ -49,7 +45,7 @@ module.exports = function(RED) {
|
|
|
49
45
|
let maxInt = kpkiConst === 0 ? 0 : (storeOutMax || Infinity) * kpkiConst;
|
|
50
46
|
let lastOutput = null;
|
|
51
47
|
|
|
52
|
-
node.on("input", function(msg, send, done) {
|
|
48
|
+
node.on("input", async function(msg, send, done) {
|
|
53
49
|
send = send || function() { node.send.apply(node, arguments); };
|
|
54
50
|
|
|
55
51
|
// Guard against invalid message
|
|
@@ -59,37 +55,105 @@ module.exports = function(RED) {
|
|
|
59
55
|
return;
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
// Evaluate
|
|
63
|
-
try {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
node.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
node.runtime.kd = parseFloat(RED.util.evaluateNodeProperty( config.kd, config.kdType, node, msg ));
|
|
72
|
-
}
|
|
73
|
-
if (utils.requiresEvaluation(config.setpointType)) {
|
|
74
|
-
node.runtime.setpoint = parseFloat(RED.util.evaluateNodeProperty( config.setpoint, config.setpointType, node, msg ));
|
|
75
|
-
}
|
|
76
|
-
if (utils.requiresEvaluation(config.deadbandType)) {
|
|
77
|
-
node.runtime.deadband = parseFloat(RED.util.evaluateNodeProperty( config.deadband, config.deadbandType, node, msg ));
|
|
78
|
-
}
|
|
79
|
-
if (utils.requiresEvaluation(config.outMinType)) {
|
|
80
|
-
node.runtime.outMin = parseFloat(RED.util.evaluateNodeProperty( config.outMin, config.outMinType, node, msg ));
|
|
81
|
-
}
|
|
82
|
-
if (utils.requiresEvaluation(config.outMaxType)) {
|
|
83
|
-
node.runtime.outMax = parseFloat(RED.util.evaluateNodeProperty( config.outMax, config.outMaxType, node, msg ));
|
|
84
|
-
}
|
|
85
|
-
if (utils.requiresEvaluation(config.maxChangeType)) {
|
|
86
|
-
node.runtime.maxChange = parseFloat(RED.util.evaluateNodeProperty( config.maxChange, config.maxChangeType, node, msg ));
|
|
87
|
-
}
|
|
88
|
-
if (utils.requiresEvaluation(config.runType)) {
|
|
89
|
-
node.runtime.run = RED.util.evaluateNodeProperty( config.run, config.runType, node, msg ) === true;
|
|
58
|
+
// Evaluate dynamic properties
|
|
59
|
+
try {
|
|
60
|
+
|
|
61
|
+
// Check busy lock
|
|
62
|
+
if (node.isBusy) {
|
|
63
|
+
// Update status to let user know they are pushing too fast
|
|
64
|
+
node.status({ fill: "yellow", shape: "ring", text: "busy - dropped msg" });
|
|
65
|
+
if (done) done();
|
|
66
|
+
return;
|
|
90
67
|
}
|
|
68
|
+
|
|
69
|
+
// Lock node during evaluation
|
|
70
|
+
node.isBusy = true;
|
|
71
|
+
|
|
72
|
+
// Begin evaluations
|
|
73
|
+
const evaluations = [];
|
|
74
|
+
|
|
75
|
+
evaluations.push(
|
|
76
|
+
utils.requiresEvaluation(config.kpType)
|
|
77
|
+
? utils.evaluateNodeProperty(config.kp, config.kpType, node, msg)
|
|
78
|
+
.then(val => parseFloat(val))
|
|
79
|
+
: Promise.resolve(node.runtime.kp),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
evaluations.push(
|
|
83
|
+
utils.requiresEvaluation(config.kiType)
|
|
84
|
+
? utils.evaluateNodeProperty(config.ki, config.kiType, node, msg)
|
|
85
|
+
.then(val => parseFloat(val))
|
|
86
|
+
: Promise.resolve(node.runtime.ki),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
evaluations.push(
|
|
90
|
+
utils.requiresEvaluation(config.kdType)
|
|
91
|
+
? utils.evaluateNodeProperty(config.kd, config.kdType, node, msg)
|
|
92
|
+
.then(val => parseFloat(val))
|
|
93
|
+
: Promise.resolve(node.runtime.kd),
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
evaluations.push(
|
|
97
|
+
utils.requiresEvaluation(config.setpointType)
|
|
98
|
+
? utils.evaluateNodeProperty(config.setpoint, config.setpointType, node, msg)
|
|
99
|
+
.then(val => parseFloat(val))
|
|
100
|
+
: Promise.resolve(node.runtime.setpoint),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
evaluations.push(
|
|
104
|
+
utils.requiresEvaluation(config.deadbandType)
|
|
105
|
+
? utils.evaluateNodeProperty(config.deadband, config.deadbandType, node, msg)
|
|
106
|
+
.then(val => parseFloat(val))
|
|
107
|
+
: Promise.resolve(node.runtime.deadband),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
evaluations.push(
|
|
111
|
+
utils.requiresEvaluation(config.outMinType)
|
|
112
|
+
? utils.evaluateNodeProperty(config.outMin, config.outMinType, node, msg)
|
|
113
|
+
.then(val => parseFloat(val))
|
|
114
|
+
: Promise.resolve(node.runtime.outMin),
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
evaluations.push(
|
|
118
|
+
utils.requiresEvaluation(config.outMaxType)
|
|
119
|
+
? utils.evaluateNodeProperty(config.outMax, config.outMaxType, node, msg)
|
|
120
|
+
.then(val => parseFloat(val))
|
|
121
|
+
: Promise.resolve(node.runtime.outMax),
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
evaluations.push(
|
|
125
|
+
utils.requiresEvaluation(config.maxChangeType)
|
|
126
|
+
? utils.evaluateNodeProperty(config.maxChange, config.maxChangeType, node, msg)
|
|
127
|
+
.then(val => parseFloat(val))
|
|
128
|
+
: Promise.resolve(node.runtime.maxChange),
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
evaluations.push(
|
|
132
|
+
utils.requiresEvaluation(config.runType)
|
|
133
|
+
? utils.evaluateNodeProperty(config.run, config.runType, node, msg)
|
|
134
|
+
.then(val => val === true)
|
|
135
|
+
: Promise.resolve(node.runtime.run),
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
const results = await Promise.all(evaluations);
|
|
139
|
+
|
|
140
|
+
// Update runtime with evaluated values
|
|
141
|
+
if (!isNaN(results[0])) node.runtime.kp = results[0];
|
|
142
|
+
if (!isNaN(results[1])) node.runtime.ki = results[1];
|
|
143
|
+
if (!isNaN(results[2])) node.runtime.kd = results[2];
|
|
144
|
+
if (!isNaN(results[3])) node.runtime.setpoint = results[3];
|
|
145
|
+
if (!isNaN(results[4])) node.runtime.deadband = results[4];
|
|
146
|
+
if (!isNaN(results[5])) node.runtime.outMin = results[5];
|
|
147
|
+
if (!isNaN(results[6])) node.runtime.outMax = results[6];
|
|
148
|
+
if (!isNaN(results[7])) node.runtime.maxChange = results[7];
|
|
149
|
+
if (results[8] != null) node.runtime.run = results[8];
|
|
91
150
|
} catch (err) {
|
|
92
151
|
node.error(`Error evaluating properties: ${err.message}`);
|
|
152
|
+
if (done) done();
|
|
153
|
+
return;
|
|
154
|
+
} finally {
|
|
155
|
+
// Release, all synchronous from here on
|
|
156
|
+
node.isBusy = false;
|
|
93
157
|
}
|
|
94
158
|
|
|
95
159
|
// Validate config
|
|
@@ -4,24 +4,19 @@ module.exports = function(RED) {
|
|
|
4
4
|
function RateOfChangeNode(config) {
|
|
5
5
|
RED.nodes.createNode(this, config);
|
|
6
6
|
const node = this;
|
|
7
|
+
node.isBusy = false;
|
|
7
8
|
|
|
8
9
|
// Initialize runtime state
|
|
9
10
|
node.runtime = {
|
|
10
11
|
maxSamples: parseInt(config.sampleSize),
|
|
11
12
|
samples: [], // Array of {timestamp: Date, value: number}
|
|
12
13
|
units: config.units || "minutes", // minutes, seconds, hours
|
|
13
|
-
lastRate: null
|
|
14
|
+
lastRate: null,
|
|
15
|
+
minValid: parseFloat(config.minValid),
|
|
16
|
+
maxValid: parseFloat(config.maxValid)
|
|
14
17
|
};
|
|
15
18
|
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
node.runtime.minValid = parseFloat(RED.util.evaluateNodeProperty( config.minValid, config.minValidType, node ));
|
|
19
|
-
node.runtime.maxValid = parseFloat(RED.util.evaluateNodeProperty( config.maxValid, config.maxValidType, node ));
|
|
20
|
-
} catch (err) {
|
|
21
|
-
node.error(`Error evaluating properties: ${err.message}`);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
node.on("input", function(msg, send, done) {
|
|
19
|
+
node.on("input", async function(msg, send, done) {
|
|
25
20
|
send = send || function() { node.send.apply(node, arguments); };
|
|
26
21
|
|
|
27
22
|
// Guard against invalid msg
|
|
@@ -31,18 +26,49 @@ module.exports = function(RED) {
|
|
|
31
26
|
return;
|
|
32
27
|
}
|
|
33
28
|
|
|
34
|
-
//
|
|
35
|
-
try {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
node.
|
|
29
|
+
// Evaluate dynamic properties
|
|
30
|
+
try {
|
|
31
|
+
|
|
32
|
+
// Check busy lock
|
|
33
|
+
if (node.isBusy) {
|
|
34
|
+
// Update status to let user know they are pushing too fast
|
|
35
|
+
node.status({ fill: "yellow", shape: "ring", text: "busy - dropped msg" });
|
|
36
|
+
if (done) done();
|
|
37
|
+
return;
|
|
41
38
|
}
|
|
39
|
+
|
|
40
|
+
// Lock node during evaluation
|
|
41
|
+
node.isBusy = true;
|
|
42
|
+
|
|
43
|
+
// Begin evaluations
|
|
44
|
+
const evaluations = [];
|
|
45
|
+
|
|
46
|
+
evaluations.push(
|
|
47
|
+
utils.requiresEvaluation(config.minValidType)
|
|
48
|
+
? utils.evaluateNodeProperty(config.minValid, config.minValidType, node, msg)
|
|
49
|
+
.then(val => parseFloat(val))
|
|
50
|
+
: Promise.resolve(node.runtime.minValid),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
evaluations.push(
|
|
54
|
+
utils.requiresEvaluation(config.maxValidType)
|
|
55
|
+
? utils.evaluateNodeProperty(config.maxValid, config.maxValidType, node, msg)
|
|
56
|
+
.then(val => parseFloat(val))
|
|
57
|
+
: Promise.resolve(node.runtime.maxValid),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const results = await Promise.all(evaluations);
|
|
61
|
+
|
|
62
|
+
// Update runtime with evaluated values
|
|
63
|
+
if (!isNaN(results[0])) node.runtime.minValid = results[0];
|
|
64
|
+
if (!isNaN(results[1])) node.runtime.maxValid = results[1];
|
|
42
65
|
} catch (err) {
|
|
43
66
|
node.error(`Error evaluating properties: ${err.message}`);
|
|
44
67
|
if (done) done();
|
|
45
68
|
return;
|
|
69
|
+
} finally {
|
|
70
|
+
// Release, all synchronous from here on
|
|
71
|
+
node.isBusy = false;
|
|
46
72
|
}
|
|
47
73
|
|
|
48
74
|
// Acceptable fallbacks
|