@machinemetrics/io-adapter-lib 2.32.0
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/.circleci/config.yml +141 -0
- package/.eslintrc.json +36 -0
- package/.gitattributes +12 -0
- package/CHANGELOG.md +544 -0
- package/README.md +2 -0
- package/index.js +17 -0
- package/lib/config/adapterConfig.js +535 -0
- package/lib/config/common/allowDenyList.js +58 -0
- package/lib/config/common/jsonPath.js +44 -0
- package/lib/config/common/labjackU3T4Common.js +227 -0
- package/lib/config/common/validations.js +142 -0
- package/lib/config/configError.js +32 -0
- package/lib/config/device/adam-6052Config.js +103 -0
- package/lib/config/device/brotherHTTPConfig.js +215 -0
- package/lib/config/device/ethernetIPConfig.js +191 -0
- package/lib/config/device/ifmIotConfig.js +245 -0
- package/lib/config/device/jsonHttpConfig.js +76 -0
- package/lib/config/device/labjackT4Config.js +39 -0
- package/lib/config/device/labjackT7Config.js +192 -0
- package/lib/config/device/labjackU3Config.js +32 -0
- package/lib/config/device/modbusTcpConfig.js +336 -0
- package/lib/config/device/mqttBaseConfig.js +70 -0
- package/lib/config/device/mqttConfig.js +113 -0
- package/lib/config/device/mqttLincolnConfig.js +62 -0
- package/lib/config/device/mtconnectAdapterConfig.js +42 -0
- package/lib/config/device/mtconnectBaseConfig.js +136 -0
- package/lib/config/device/mtconnectConfig.js +52 -0
- package/lib/config/device/mtconnectHaasConfig.js +15 -0
- package/lib/config/device/nullConfig.js +81 -0
- package/lib/config/device/opcuaConfig.js +205 -0
- package/lib/config/device/pcccConfig.js +88 -0
- package/lib/config/engineConfigV1.js +382 -0
- package/lib/config/engineConfigV2.js +106 -0
- package/lib/config/generator/counterGenConfig.js +15 -0
- package/lib/config/generator/cronGenConfig.js +33 -0
- package/lib/config/generator/dateTimeGenConfig.js +33 -0
- package/lib/config/index.js +339 -0
- package/lib/config/transformConfigUtil.js +296 -0
- package/lib/engine/dataOutput.js +357 -0
- package/lib/engine/deviceOutput.js +186 -0
- package/lib/engine/engineV1.js +480 -0
- package/lib/engine/engineV2.js +719 -0
- package/lib/engine/index.js +34 -0
- package/lib/engine/transformBuilderV1.js +111 -0
- package/lib/engine/transformBuilderV2.js +74 -0
- package/lib/expressionService.js +330 -0
- package/lib/math.js +142 -0
- package/lib/transform/accumulate.js +98 -0
- package/lib/transform/average.js +56 -0
- package/lib/transform/debounce.js +152 -0
- package/lib/transform/downsample.js +69 -0
- package/lib/transform/edge.js +34 -0
- package/lib/transform/expression.js +91 -0
- package/lib/transform/fallingEdge.js +70 -0
- package/lib/transform/fromBuffer.js +89 -0
- package/lib/transform/hash.js +41 -0
- package/lib/transform/ignoreValue.js +118 -0
- package/lib/transform/index.js +93 -0
- package/lib/transform/invert.js +25 -0
- package/lib/transform/latch.js +99 -0
- package/lib/transform/latchValue.js +115 -0
- package/lib/transform/logicAnd.js +67 -0
- package/lib/transform/logicOr.js +67 -0
- package/lib/transform/map.js +115 -0
- package/lib/transform/max.js +57 -0
- package/lib/transform/maxLength.js +39 -0
- package/lib/transform/min.js +57 -0
- package/lib/transform/minDelta.js +40 -0
- package/lib/transform/offDelay.js +89 -0
- package/lib/transform/onDelay.js +89 -0
- package/lib/transform/patternEscape.js +24 -0
- package/lib/transform/patternMatch.js +194 -0
- package/lib/transform/patternReplace.js +170 -0
- package/lib/transform/patternTest.js +85 -0
- package/lib/transform/rateOfChange.js +56 -0
- package/lib/transform/reject.js +115 -0
- package/lib/transform/resample.js +96 -0
- package/lib/transform/risingEdge.js +90 -0
- package/lib/transform/risingEdgeCounter.js +179 -0
- package/lib/transform/sampleInterval.js +12 -0
- package/lib/transform/source.js +116 -0
- package/lib/transform/state.js +201 -0
- package/lib/transform/threshold.js +52 -0
- package/lib/transform/toBuffer.js +159 -0
- package/lib/transform/toggle.js +118 -0
- package/lib/transform/transformState.js +193 -0
- package/lib/transform/trim.js +27 -0
- package/lib/transform/util/chainSource.js +96 -0
- package/lib/transform/util/ringBuffer.js +34 -0
- package/lib/transform/valueChange.js +34 -0
- package/lib/transform/valueDecrease.js +38 -0
- package/lib/transform/valueIncrease.js +38 -0
- package/lib/transform/valueIncreaseDiff.js +66 -0
- package/lib/transform/whenUnavailable.js +73 -0
- package/lib/transform/windowCount.js +86 -0
- package/lib/util/fileUtil.js +44 -0
- package/package.json +38 -0
- package/test/.eslintrc.json +15 -0
- package/test/chainedTransform.test.js +88 -0
- package/test/conditions.test.js +118 -0
- package/test/config/ab-pccc.test.js +41 -0
- package/test/config/adam-6052.test.js +16 -0
- package/test/config/adapter.test.js +109 -0
- package/test/config/brother-http.test.js +19 -0
- package/test/config/ethernet-ip.test.js +19 -0
- package/test/config/ifm-iot.test.js +20 -0
- package/test/config/json-http.test.js +47 -0
- package/test/config/labjack-t4.test.js +78 -0
- package/test/config/labjack-t7.test.js +18 -0
- package/test/config/labjack-u3.test.js +17 -0
- package/test/config/modbusTcp.test.js +87 -0
- package/test/config/mqtt.test.js +19 -0
- package/test/config/mqttLincoln.test.js +29 -0
- package/test/config/mtconnect.test.js +63 -0
- package/test/config/mtconnectAdapter.test.js +124 -0
- package/test/config/mtconnectHaas.test.js +15 -0
- package/test/config/null.test.js +16 -0
- package/test/config/opcua.test.js +97 -0
- package/test/config-tests.js +102 -0
- package/test/configFiles/conditions.yml +37 -0
- package/test/configFiles/data-items-legacy.yml +24 -0
- package/test/configFiles/data-items-shorthand.yml +14 -0
- package/test/configFiles/data-items.yml +12 -0
- package/test/configFiles/device/ab-pccc-default.yml +3 -0
- package/test/configFiles/device/ab-pccc-full.yml +13 -0
- package/test/configFiles/device/adam-6052-default.yml +2 -0
- package/test/configFiles/device/brother-http-default.yml +3 -0
- package/test/configFiles/device/ethernet-ip-default.yml +2 -0
- package/test/configFiles/device/ifm-iot-default.yml +2 -0
- package/test/configFiles/device/json-http-bad-prop.yml +13 -0
- package/test/configFiles/device/json-http-bad-prop2.yml +13 -0
- package/test/configFiles/device/json-http-default.yml +3 -0
- package/test/configFiles/device/json-http-std.yml +13 -0
- package/test/configFiles/device/labjack-t4-condition-exprs.yaml +46 -0
- package/test/configFiles/device/labjack-t4-default.yml +3 -0
- package/test/configFiles/device/labjack-t4-pins-alt.yaml +41 -0
- package/test/configFiles/device/labjack-t4-pins.yaml +40 -0
- package/test/configFiles/device/labjack-t4-v1.yaml +29 -0
- package/test/configFiles/device/labjack-t7-default.yml +2 -0
- package/test/configFiles/device/labjack-u3-default.yml +2 -0
- package/test/configFiles/device/modbus-partial.yml +4 -0
- package/test/configFiles/device/modbus-std-extended.yaml +23 -0
- package/test/configFiles/device/modbus-std.yaml +34 -0
- package/test/configFiles/device/modbus-tcp-default.yml +3 -0
- package/test/configFiles/device/mqtt-default.yml +2 -0
- package/test/configFiles/device/mqtt-lincoln-default.yml +3 -0
- package/test/configFiles/device/mqtt-lincoln-full.yml +7 -0
- package/test/configFiles/device/mtconnect-adapter-default.yml +3 -0
- package/test/configFiles/device/mtconnect-adapter-keys.yaml +18 -0
- package/test/configFiles/device/mtconnect-complex-keys.yaml +17 -0
- package/test/configFiles/device/mtconnect-default.yml +3 -0
- package/test/configFiles/device/mtconnect-duplicate-allow-keys.yaml +10 -0
- package/test/configFiles/device/mtconnect-duplicate-declare-keys.yaml +8 -0
- package/test/configFiles/device/mtconnect-duplicate-deny-keys.yaml +10 -0
- package/test/configFiles/device/mtconnect-haas-default.yml +3 -0
- package/test/configFiles/device/mtconnect-std.yaml +18 -0
- package/test/configFiles/device/null-default.yml +1 -0
- package/test/configFiles/device/opcua-bad-tag.yml +18 -0
- package/test/configFiles/device/opcua-bad-tag2.yml +18 -0
- package/test/configFiles/device/opcua-default.yml +3 -0
- package/test/configFiles/device/opcua-std.yml +18 -0
- package/test/configFiles/dump-test.yml +11 -0
- package/test/configFiles/expressionCond.yml +46 -0
- package/test/configFiles/min-config-t4.yaml +4 -0
- package/test/configFiles/min-config-u3.yaml +3 -0
- package/test/configFiles/missing-device.yaml +2 -0
- package/test/configFiles/parse-error1.yml +9 -0
- package/test/configFiles/parse-error2.yml +9 -0
- package/test/configFiles/repro/buffer-convert-repro.yml +15 -0
- package/test/configFiles/repro/chained-delay-timing-repro.yml +13 -0
- package/test/configFiles/repro/count-init-repro.yml +45 -0
- package/test/configFiles/repro/cycle-break-repro.yml +44 -0
- package/test/configFiles/repro/debounce-repro.yml +46 -0
- package/test/configFiles/repro/diff-count-repro.yml +34 -0
- package/test/configFiles/repro/engine-hang-repro.yml +9 -0
- package/test/configFiles/repro/latch-apm-repro.yml +26 -0
- package/test/configFiles/repro/lockout-count-repro.yml +33 -0
- package/test/configFiles/repro/program-extract-repro.yml +38 -0
- package/test/configFiles/repro/state-latch-repro.yml +47 -0
- package/test/configFiles/repro/ternary-repro.yml +26 -0
- package/test/configFiles/transform/debounce.yml +12 -0
- package/test/configFiles/transform/expression.yml +34 -0
- package/test/configFiles/transform/ignoreValue.yml +31 -0
- package/test/configFiles/transform/latch.yml +11 -0
- package/test/configFiles/transform/latchValue.yml +31 -0
- package/test/configFiles/transform/logicAnd.yml +14 -0
- package/test/configFiles/transform/logicOr.yml +14 -0
- package/test/configFiles/transform/map.yml +19 -0
- package/test/configFiles/transform/maxLength.yml +13 -0
- package/test/configFiles/transform/offDelay.yml +12 -0
- package/test/configFiles/transform/pattern-escape.yml +10 -0
- package/test/configFiles/transform/pattern-match.yml +57 -0
- package/test/configFiles/transform/pattern-replace.yml +34 -0
- package/test/configFiles/transform/pattern-test.yml +25 -0
- package/test/configFiles/transform/reject.yml +24 -0
- package/test/configFiles/transform/risingEdgeCounter.yml +36 -0
- package/test/configFiles/transform/source.yml +20 -0
- package/test/configFiles/transform/state.yml +56 -0
- package/test/configFiles/transform/toggle.yml +19 -0
- package/test/configFiles/transform/whenUnavailable.yml +19 -0
- package/test/dataFiles/noisy-pulse.txt +11330 -0
- package/test/dataItems.test.js +140 -0
- package/test/engine-v1-tests.js +418 -0
- package/test/engine-v2-tests.js +284 -0
- package/test/expression-tests.js +171 -0
- package/test/expressionService.test.js +154 -0
- package/test/expressionServiceCondition.test.js +130 -0
- package/test/repro/buffer-convert-repro.test.js +38 -0
- package/test/repro/chained-delay-timing-repro.test.js +34 -0
- package/test/repro/count-init-repro.test.js +46 -0
- package/test/repro/cylce-break-repro.test.js +57 -0
- package/test/repro/debounce-repro.test.js +65 -0
- package/test/repro/diff-count-repro.test.js +79 -0
- package/test/repro/engine-hang-repro.test.js +38 -0
- package/test/repro/latch-apm-repro.test.js +119 -0
- package/test/repro/lockout-count-repro.test.js +84 -0
- package/test/repro/program-extract-repro.test.js +40 -0
- package/test/repro/state-latch-repro.test.js +63 -0
- package/test/repro/ternary-repro.test.js +43 -0
- package/test/transform/accumulte.test.js +18 -0
- package/test/transform/average.test.js +22 -0
- package/test/transform/debounce.test.js +70 -0
- package/test/transform/downsample.test.js +30 -0
- package/test/transform/edge.test.js +27 -0
- package/test/transform/expression.test.js +189 -0
- package/test/transform/fallingEdge.test.js +59 -0
- package/test/transform/fromBuffer.test.js +60 -0
- package/test/transform/hash.test.js +34 -0
- package/test/transform/ignoreValue.test.js +123 -0
- package/test/transform/invert.test.js +26 -0
- package/test/transform/latch.test.js +33 -0
- package/test/transform/latchValue.test.js +126 -0
- package/test/transform/logicAnd.test.js +80 -0
- package/test/transform/logicOr.test.js +80 -0
- package/test/transform/map.test.js +42 -0
- package/test/transform/max.test.js +30 -0
- package/test/transform/maxLength.test.js +32 -0
- package/test/transform/min.test.js +30 -0
- package/test/transform/minDelta.test.js +14 -0
- package/test/transform/offDelay.test.js +123 -0
- package/test/transform/onDelay.test.js +105 -0
- package/test/transform/patternEscape.test.js +18 -0
- package/test/transform/patternMatch.test.js +177 -0
- package/test/transform/patternReplace.test.js +95 -0
- package/test/transform/patternTest.test.js +105 -0
- package/test/transform/rateOfChange.test.js +34 -0
- package/test/transform/reject.test.js +56 -0
- package/test/transform/resample.test.js +193 -0
- package/test/transform/risingEdge.test.js +60 -0
- package/test/transform/risingEdgeCounter.test.js +227 -0
- package/test/transform/sampleInterval.test.js +22 -0
- package/test/transform/source.test.js +137 -0
- package/test/transform/state.test.js +248 -0
- package/test/transform/threshold.test.js +78 -0
- package/test/transform/toBuffer.test.js +60 -0
- package/test/transform/toggle.test.js +92 -0
- package/test/transform/trim.test.js +30 -0
- package/test/transform/valueChange.test.js +14 -0
- package/test/transform/valueDecrease.test.js +32 -0
- package/test/transform/valueIncrease.test.js +32 -0
- package/test/transform/valueIncreaseDiff.test.js +32 -0
- package/test/transform/whenUnavailable.test.js +93 -0
- package/test/transform/windowCount.test.js +26 -0
- package/test/util/testUtils.js +405 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const ConfigError = require('../configError');
|
|
5
|
+
|
|
6
|
+
class MqttBaseConfig {
|
|
7
|
+
constructor(expressionService) {
|
|
8
|
+
this.expressionService = expressionService;
|
|
9
|
+
|
|
10
|
+
_.each(this.getIdentifiers(expressionService.config), name => this.expressionService.addName(name));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getIdentifiers() {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
parse(config = {}) {
|
|
18
|
+
this.endpoint = this.checkEndpoint(config);
|
|
19
|
+
this.telemetryRate = this.checkTelemetryRate(config);
|
|
20
|
+
|
|
21
|
+
this.username = this.checkUsername(config);
|
|
22
|
+
this.password = this.checkPassword(config);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
checkEndpoint(defn) {
|
|
26
|
+
const endpoint = defn.endpoint;
|
|
27
|
+
if (_.isEmpty(endpoint)) {
|
|
28
|
+
throw new ConfigError('An MQTT endpoint must be specified').atPath('endpoint');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return endpoint;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
checkTelemetryRate(defn) {
|
|
35
|
+
const rate = _.get(defn, 'telemetry-rate', 1);
|
|
36
|
+
if (!_.isNumber(rate) || rate <= 0) {
|
|
37
|
+
throw new ConfigError('telemetry-rate must be >= 0').atPath('telemetry-rate');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return rate;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
checkUsername(defn) {
|
|
44
|
+
const username = defn.username;
|
|
45
|
+
if (_.isEmpty(username)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!_.isString(username) && !_.isNumber(username)) {
|
|
50
|
+
throw new ConfigError('Username must be a string').atPath('username');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return String(username);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
checkPassword(defn) {
|
|
57
|
+
const password = defn.password;
|
|
58
|
+
if (_.isEmpty(password)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!_.isString(password) && !_.isNumber(password)) {
|
|
63
|
+
throw new ConfigError('Password must be a string').atPath('password');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return String(password);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = MqttBaseConfig;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const ConfigError = require('../configError');
|
|
5
|
+
const MqttBaseConfig = require('./mqttBaseConfig');
|
|
6
|
+
const validations = require('../common/validations');
|
|
7
|
+
const { checkJsonPropPath } = require('../common/jsonPath');
|
|
8
|
+
|
|
9
|
+
class MqttConfig extends MqttBaseConfig {
|
|
10
|
+
// eslint-disable-next-line no-useless-constructor
|
|
11
|
+
constructor(expressionService) {
|
|
12
|
+
super(expressionService);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
getIdentifiers(config = {}) {
|
|
16
|
+
const keys = [];
|
|
17
|
+
_.each(config.topics, (val) => {
|
|
18
|
+
if (_.isString(val)) {
|
|
19
|
+
keys.push(val);
|
|
20
|
+
} else if (_.isObject(val?.json)) {
|
|
21
|
+
keys.push(...Object.keys(val.json));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return _.map(keys, (name) => {
|
|
26
|
+
return {
|
|
27
|
+
name,
|
|
28
|
+
channel: 'device',
|
|
29
|
+
defaultValue: 0,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
device() {
|
|
35
|
+
return 'mqtt';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
parse(config = {}) {
|
|
39
|
+
this.endpoint = this.checkEndpoint(config);
|
|
40
|
+
this.telemetryRate = this.checkTelemetryRate(config);
|
|
41
|
+
|
|
42
|
+
this.username = this.checkUsername(config);
|
|
43
|
+
this.password = this.checkPassword(config);
|
|
44
|
+
|
|
45
|
+
this.topics = this.loadTopics(config.topics);
|
|
46
|
+
this.reset = validations.checkReset(config);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
loadTopics(topics = {}) {
|
|
50
|
+
return _(topics).map((defn, topic) => {
|
|
51
|
+
let subSection = '';
|
|
52
|
+
try {
|
|
53
|
+
if (_.isString(defn)) {
|
|
54
|
+
defn = { type: 'raw', key: defn };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!_.isObject(defn)) {
|
|
58
|
+
throw new ConfigError('Unexpected topic structure');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const type = this.checkType(defn);
|
|
62
|
+
if (type === 'raw') {
|
|
63
|
+
// Simple raw topic value
|
|
64
|
+
return {
|
|
65
|
+
topic,
|
|
66
|
+
type: 'raw',
|
|
67
|
+
key: defn.key,
|
|
68
|
+
};
|
|
69
|
+
} else if (type === 'json') {
|
|
70
|
+
subSection = 'json';
|
|
71
|
+
this.checkJson(defn);
|
|
72
|
+
|
|
73
|
+
// JSON prop collection
|
|
74
|
+
return {
|
|
75
|
+
topic,
|
|
76
|
+
type: 'json',
|
|
77
|
+
json: defn.json,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
throw new ConfigError('Unexpected topic type');
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (error instanceof ConfigError) {
|
|
84
|
+
let section = `topics.${topic}`;
|
|
85
|
+
if (subSection) {
|
|
86
|
+
section += `.${subSection}`;
|
|
87
|
+
}
|
|
88
|
+
error.atSection(section);
|
|
89
|
+
}
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}).keyBy('topic').value();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
checkType(defn) {
|
|
96
|
+
const type = defn.type ?? 'json';
|
|
97
|
+
if (!_.includes(['raw', 'json'], type)) {
|
|
98
|
+
throw new ConfigError('Type must be one of [raw, json]').atAttribute('type');
|
|
99
|
+
}
|
|
100
|
+
return type;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
checkJson(defn) {
|
|
104
|
+
const json = defn.json;
|
|
105
|
+
if (!_.isObject(json)) {
|
|
106
|
+
throw new ConfigError('JSON block must be collection of prop names and JSON paths').atAttribute('json');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_.each(json, (prop, key) => checkJsonPropPath(prop, key));
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
module.exports = MqttConfig;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const ConfigError = require('../configError');
|
|
5
|
+
const MqttBaseConfig = require('./mqttBaseConfig');
|
|
6
|
+
|
|
7
|
+
const fixedKeys = [
|
|
8
|
+
// telemetry
|
|
9
|
+
'current', 'voltage', 'wire_speed', 'motor_current', 'true_energy', 'weld_record',
|
|
10
|
+
// summary
|
|
11
|
+
'summary_avg_current', 'summary_avg_voltage', 'summary_avg_wire_speed', 'summary_avg_motor_current',
|
|
12
|
+
'summary_avg_gas_flow', 'consumable_density', 'consumable_diameter', 'summary_duration',
|
|
13
|
+
// derived
|
|
14
|
+
'execution', 'weldcount', 'consumable_rate', 'control_board_serial', 'observed_serials',
|
|
15
|
+
'summary_wire_length', 'summary_wire_mass',
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
class MqttLincolnConfig extends MqttBaseConfig {
|
|
19
|
+
// eslint-disable-next-line no-useless-constructor
|
|
20
|
+
constructor(expressionService) {
|
|
21
|
+
super(expressionService);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getIdentifiers() {
|
|
25
|
+
return _.map(fixedKeys, (name) => {
|
|
26
|
+
return {
|
|
27
|
+
name,
|
|
28
|
+
channel: 'device',
|
|
29
|
+
defaultValue: 0,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
parse(config = {}) {
|
|
35
|
+
this.endpoint = this.checkEndpoint(config);
|
|
36
|
+
this.telemetryRate = this.checkTelemetryRate(config);
|
|
37
|
+
this.serial = this.checkSerial(config);
|
|
38
|
+
this.username = this.checkUsername(config);
|
|
39
|
+
this.password = this.checkPassword(config);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
postParse(config) {
|
|
43
|
+
_.each(fixedKeys, (key) => {
|
|
44
|
+
config.adapter.loadDataItem(key, key);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
checkSerial(defn) {
|
|
49
|
+
const serial = defn.serial;
|
|
50
|
+
if (_.isNil(serial)) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!_.isString(serial) && !_.isNumber(serial)) {
|
|
55
|
+
throw new ConfigError('Invalid serial').atPath('serial');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return String(serial);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = MqttLincolnConfig;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MTConnectBaseConfig = require('./mtconnectBaseConfig');
|
|
4
|
+
const ConfigError = require('../configError');
|
|
5
|
+
|
|
6
|
+
class MTConnectAdapterConfig extends MTConnectBaseConfig {
|
|
7
|
+
parse(config = {}) {
|
|
8
|
+
super.parse(config);
|
|
9
|
+
|
|
10
|
+
if (config.device !== this.device()) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
this.parseEndpoint(config.endpoint);
|
|
15
|
+
// TODO: Chase down local address translation
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
device() {
|
|
19
|
+
return 'mtconnect-adapter';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
parseEndpoint(endpoint) {
|
|
23
|
+
if (!endpoint) {
|
|
24
|
+
throw new ConfigError('No endpoint defined').atAttribute('endpoint');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (endpoint.match(/^local\s+/)) {
|
|
28
|
+
this.localAddress = endpoint.replace(/^local\s+/, '');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!endpoint.match(/^[\w.]+(:\d+)?$/)) {
|
|
33
|
+
throw new ConfigError('Invalid endpoint').atAttribute('endpoint');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const [host, port] = endpoint.split(':');
|
|
37
|
+
this.host = host;
|
|
38
|
+
this.port = port || 7878;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = MTConnectAdapterConfig;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const AllowDenyList = require('../common/allowDenyList');
|
|
5
|
+
const ConfigError = require('../configError');
|
|
6
|
+
const validations = require('../common/validations');
|
|
7
|
+
|
|
8
|
+
const allowDeny = new AllowDenyList();
|
|
9
|
+
|
|
10
|
+
class MTConnectBaseConfig {
|
|
11
|
+
constructor(expressionService) {
|
|
12
|
+
this.expressionService = expressionService;
|
|
13
|
+
|
|
14
|
+
_.each(this.getIdentifiers(expressionService.config), name => this.expressionService.addName(name));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getIdentifiers(config = {}) {
|
|
18
|
+
return _.map(config['declare-keys'], (name) => {
|
|
19
|
+
if (_.isObject(name)) {
|
|
20
|
+
name = _.first(_.keys(name));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
channel: 'device',
|
|
26
|
+
defaultValue: 0,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
parse(config = {}) {
|
|
32
|
+
if (config.device !== this.device()) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.mtconnectPassthrough = this.parsePassthrough(config);
|
|
37
|
+
this.allowKeyPatterns = allowDeny.parseWildcardKeyList(config['allow-keys'], 'allow-keys');
|
|
38
|
+
this.denyKeyPatterns = allowDeny.parseWildcardKeyList(config['deny-keys'], 'deny-keys');
|
|
39
|
+
this.keys = this.parseDeclaredKeysList(config);
|
|
40
|
+
this.enforceAvailCheck = validations.checkBoolean(config, 'enforce-avail-check', { defaultValue: true });
|
|
41
|
+
|
|
42
|
+
this.sourceKeys = _(this.keys).map('source').uniq().value();
|
|
43
|
+
|
|
44
|
+
this.aliasMap = this.createAliasMap(this.keys);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
mtconnectKeys() {
|
|
48
|
+
return this.keys;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
parsePassthrough(config) {
|
|
52
|
+
if (_.isUndefined(config['mtconnect-passthrough'])) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return !!config['mtconnect-passthrough'];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
parseDeclaredKeysList(config) {
|
|
59
|
+
let attribute = 'declare-keys';
|
|
60
|
+
if (!config[attribute] && config.keys) {
|
|
61
|
+
attribute = 'keys';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const keys = config[attribute];
|
|
65
|
+
if (_.isEmpty(keys)) {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
if (!_.isArray(keys)) {
|
|
69
|
+
throw new ConfigError('list expected').atAttribute(attribute);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const parsedKeys = _(keys).map((key) => {
|
|
73
|
+
if (_.isObject(key)) {
|
|
74
|
+
const name = _.first(_.keys(key));
|
|
75
|
+
const body = key[name];
|
|
76
|
+
if (_.isObject(body)) {
|
|
77
|
+
let sourceName = name;
|
|
78
|
+
if (_.has(body, 'key')) {
|
|
79
|
+
sourceName = body.key;
|
|
80
|
+
}
|
|
81
|
+
const type = body.type ?? 'value';
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
name,
|
|
85
|
+
source: sourceName,
|
|
86
|
+
type,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
name,
|
|
92
|
+
source: body,
|
|
93
|
+
type: 'value',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
name: key,
|
|
99
|
+
source: key,
|
|
100
|
+
type: 'value',
|
|
101
|
+
};
|
|
102
|
+
}).value();
|
|
103
|
+
|
|
104
|
+
// Check for duplicate key names
|
|
105
|
+
const keyNames = _.map(parsedKeys, 'name');
|
|
106
|
+
const duplicates = _(keyNames)
|
|
107
|
+
.groupBy()
|
|
108
|
+
.pickBy(x => x.length > 1)
|
|
109
|
+
.keys()
|
|
110
|
+
.value();
|
|
111
|
+
|
|
112
|
+
if (duplicates.length > 0) {
|
|
113
|
+
throw new ConfigError(`duplicate key names found: ${duplicates.join(', ')}`).atAttribute(attribute);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return _.keyBy(parsedKeys, 'name');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
createAliasMap(keys) {
|
|
120
|
+
const aliasMap = {};
|
|
121
|
+
const sourceKeys = _(keys).map('source').uniq().value();
|
|
122
|
+
|
|
123
|
+
const aliasNames = _.uniq(_.map(_.filter(keys, k => k.name !== k.source), 'name'));
|
|
124
|
+
_.each(sourceKeys, (sourceKey) => {
|
|
125
|
+
aliasMap[sourceKey] = [];
|
|
126
|
+
});
|
|
127
|
+
_.each(aliasNames, (alias) => {
|
|
128
|
+
const key = keys[alias];
|
|
129
|
+
aliasMap[key.source].push(alias);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return aliasMap;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = MTConnectBaseConfig;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const MTConnectBaseConfig = require('./mtconnectBaseConfig');
|
|
4
|
+
const ConfigError = require('../configError');
|
|
5
|
+
|
|
6
|
+
class MTConnectConfig extends MTConnectBaseConfig {
|
|
7
|
+
constructor(expressionService) {
|
|
8
|
+
super(expressionService);
|
|
9
|
+
this.defaultPort = '5000';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
parse(config = {}) {
|
|
13
|
+
super.parse(config);
|
|
14
|
+
|
|
15
|
+
if (config.device !== this.device()) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.endpoint = this.parseEndpoint(config.endpoint);
|
|
20
|
+
this.verboseScanning = !!config['verbose-scanning'];
|
|
21
|
+
this.haasMode = !!config['haas-mode'];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
device() {
|
|
25
|
+
return 'mtconnect';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
parseEndpoint(endpointString) {
|
|
29
|
+
if (!endpointString) {
|
|
30
|
+
throw new ConfigError('No endpoint defined').atAttribute('endpoint');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// HTTP/S URLs are returned directly
|
|
34
|
+
if (endpointString.match(/^https?:\/\//)) {
|
|
35
|
+
return endpointString;
|
|
36
|
+
} else if (endpointString.match(/^\w+:\/\//)) {
|
|
37
|
+
throw new ConfigError('Unexpected endpoint protocol').atAttribute('endpoint');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let endpoint = endpointString;
|
|
41
|
+
// If no port is provided, specify 5000 by default
|
|
42
|
+
if (!endpointString.match(/:\d+/)) {
|
|
43
|
+
const [baseEndpoint, ...path] = endpointString.split('/');
|
|
44
|
+
endpoint = `${baseEndpoint}:${this.defaultPort}/${path.join('/')}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Assume HTTP protocol by default
|
|
48
|
+
return `http://${endpoint}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = MTConnectConfig;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const MTConnectConfig = require('./mtconnectConfig');
|
|
2
|
+
|
|
3
|
+
class MTConnectHaas extends MTConnectConfig {
|
|
4
|
+
constructor(expressionService) {
|
|
5
|
+
super(expressionService);
|
|
6
|
+
this.defaultPort = '8082';
|
|
7
|
+
this.haasMode = 1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
device() {
|
|
11
|
+
return 'mtconnect-haas';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = MTConnectHaas;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
const ConfigError = require('../configError');
|
|
5
|
+
|
|
6
|
+
class NullConfig {
|
|
7
|
+
constructor(expressionService) {
|
|
8
|
+
this.expressionService = expressionService;
|
|
9
|
+
|
|
10
|
+
_.each(this.getIdentifiers(expressionService.config), name => this.expressionService.addName(name));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getIdentifiers(config = {}) {
|
|
14
|
+
return _.map(config['declare-keys'], (name) => {
|
|
15
|
+
if (_.isObject(name)) {
|
|
16
|
+
name = _.first(_.keys(name));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
name,
|
|
21
|
+
channel: 'device',
|
|
22
|
+
defaultValue: 0,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
parse(config = {}) {
|
|
28
|
+
if (config.device !== 'local') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.keys = this.parseDeclaredKeysList(config);
|
|
33
|
+
this.sourceKeys = _(this.keys).map('source').uniq().value();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
parseDeclaredKeysList(config) {
|
|
37
|
+
let attribute = 'declare-keys';
|
|
38
|
+
if (!config[attribute] && config.keys) {
|
|
39
|
+
attribute = 'keys';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const keys = config[attribute];
|
|
43
|
+
if (_.isEmpty(keys)) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
if (!_.isArray(keys)) {
|
|
47
|
+
throw new ConfigError('list expected').atAttribute(attribute);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return _(keys).map((key) => {
|
|
51
|
+
if (_.isObject(key)) {
|
|
52
|
+
const name = _.first(_.keys(key));
|
|
53
|
+
const body = key[name];
|
|
54
|
+
if (_.isObject(body)) {
|
|
55
|
+
const sourceName = body.key;
|
|
56
|
+
const type = body.type;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
name,
|
|
60
|
+
source: sourceName,
|
|
61
|
+
type,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
name,
|
|
67
|
+
source: name,
|
|
68
|
+
type: body,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
name: key,
|
|
74
|
+
source: key,
|
|
75
|
+
type: 'value',
|
|
76
|
+
};
|
|
77
|
+
}).keyBy('name').value();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = NullConfig;
|