@machinemetrics/io-adapter-lib 2.36.0 → 2.37.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/CHANGELOG.md +3 -0
- package/lib/config/device/brotherHTTPConfig.js +47 -6
- package/lib/config/index.js +2 -0
- package/package.json +1 -1
- package/test/config/brother-ftp.test.js +63 -0
- package/test/config/brother-http.test.js +2 -0
- package/test/configFiles/device/brother-ftp-bad-cnc.yml +3 -0
- package/test/configFiles/device/brother-ftp-bad-mode.yml +3 -0
- package/test/configFiles/device/brother-ftp-bad-path.yml +3 -0
- package/test/configFiles/device/brother-ftp-cnc-legacy.yml +3 -0
- package/test/configFiles/device/brother-ftp-minimal.yml +2 -0
- package/test/configFiles/device/brother-ftp-paths.yml +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -16,7 +16,10 @@ class BrotherHTTPConfig {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const mode = expressionService.config['collection-mode'];
|
|
19
|
-
const
|
|
19
|
+
const deviceName = expressionService.config.device;
|
|
20
|
+
const defaultMode = deviceName === 'brother-ftp'
|
|
21
|
+
? this.DataCollectionModes.FTP
|
|
22
|
+
: this.DataCollectionModes.MIXED;
|
|
20
23
|
if (mode === undefined) this.dataCollectionMode = defaultMode;
|
|
21
24
|
else if (mode.toLowerCase() === 'http') this.dataCollectionMode = this.DataCollectionModes.HTTP;
|
|
22
25
|
else if (mode.toLowerCase() === 'ftp') this.dataCollectionMode = this.DataCollectionModes.FTP;
|
|
@@ -141,15 +144,23 @@ class BrotherHTTPConfig {
|
|
|
141
144
|
|
|
142
145
|
/** Configuration indicates how to collect data:
|
|
143
146
|
* HTTP only,
|
|
144
|
-
* FTP only (default),
|
|
147
|
+
* FTP only (default for device brother-ftp),
|
|
145
148
|
* HTTP + FTP for program headers
|
|
146
149
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
const isBrotherFtp = config.device === 'brother-ftp';
|
|
151
|
+
let mode = config['collection-mode'];
|
|
152
|
+
if (mode === undefined || mode === null || mode === '') {
|
|
153
|
+
mode = isBrotherFtp ? 'ftp' : '';
|
|
154
|
+
}
|
|
155
|
+
if (!_.isString(mode)) {
|
|
156
|
+
throw new ConfigError('collection-mode must be a string').atAttribute('collection-mode');
|
|
157
|
+
}
|
|
158
|
+
mode = mode.toLowerCase();
|
|
159
|
+
if (isBrotherFtp && mode !== 'ftp') {
|
|
160
|
+
throw new ConfigError('device brother-ftp requires collection-mode ftp').atAttribute('collection-mode');
|
|
150
161
|
}
|
|
151
162
|
if (!_.includes(['http', 'ftp', 'mixed'], mode)) {
|
|
152
|
-
throw new ConfigError('collection-mode must be one of: {http, ftp, mixed}').atAttribute('
|
|
163
|
+
throw new ConfigError('collection-mode must be one of: {http, ftp, mixed}').atAttribute('collection-mode');
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
let keysThatAlreadyExist = '';
|
|
@@ -191,6 +202,36 @@ class BrotherHTTPConfig {
|
|
|
191
202
|
throw new ConfigError(`The value of macros key ${key} must be a valid integer`).atAttribute(key);
|
|
192
203
|
}
|
|
193
204
|
});
|
|
205
|
+
|
|
206
|
+
this.assignOptionalRelativePath(config, 'memory-path', 'memoryPath');
|
|
207
|
+
this.assignOptionalRelativePath(config, 'production-path', 'productionPath');
|
|
208
|
+
this.assignOptionalRelativePath(config, 'panel-path', 'panelPath');
|
|
209
|
+
this.assignOptionalRelativePath(config, 'position-path', 'positionPath');
|
|
210
|
+
this.assignOptionalRelativePath(config, 'work-counter-path', 'workCounterPath');
|
|
211
|
+
this.assignOptionalRelativePath(config, 'alarm-path', 'alarmPath');
|
|
212
|
+
this.assignOptionalRelativePath(config, 'macro-path', 'macroPath');
|
|
213
|
+
|
|
214
|
+
if (_.has(config, 'cnc-version')) {
|
|
215
|
+
const cncVersion = config['cnc-version'];
|
|
216
|
+
if (cncVersion !== 'legacy' && cncVersion !== 'd00') {
|
|
217
|
+
throw new ConfigError('cnc-version must be one of: legacy, d00').atAttribute('cnc-version');
|
|
218
|
+
}
|
|
219
|
+
this.cncVersion = cncVersion;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
assignOptionalRelativePath(config, yamlKey, propertyName) {
|
|
224
|
+
if (!_.has(config, yamlKey)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const value = config[yamlKey];
|
|
228
|
+
if (!_.isString(value) || value.trim() === '') {
|
|
229
|
+
throw new ConfigError(`${yamlKey} must be a non-empty string`).atAttribute(yamlKey);
|
|
230
|
+
}
|
|
231
|
+
if (value.includes('..')) {
|
|
232
|
+
throw new ConfigError(`${yamlKey} must not contain '..'`).atAttribute(yamlKey);
|
|
233
|
+
}
|
|
234
|
+
this[propertyName] = value;
|
|
194
235
|
}
|
|
195
236
|
|
|
196
237
|
checkScanInterval(config) {
|
package/lib/config/index.js
CHANGED
|
@@ -204,6 +204,7 @@ class Config {
|
|
|
204
204
|
return new OPCUAConfig(expressionService);
|
|
205
205
|
case 'brother':
|
|
206
206
|
case 'brother-http':
|
|
207
|
+
case 'brother-ftp':
|
|
207
208
|
return new BrotherHTTPConfig(expressionService);
|
|
208
209
|
case 'adam-6052':
|
|
209
210
|
return new AdamConfig(expressionService);
|
|
@@ -315,6 +316,7 @@ class Config {
|
|
|
315
316
|
'opc-ua',
|
|
316
317
|
'brother',
|
|
317
318
|
'brother-http',
|
|
319
|
+
'brother-ftp',
|
|
318
320
|
'adam-6052',
|
|
319
321
|
'mtconnect',
|
|
320
322
|
'mtconnect-haas',
|
package/package.json
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const expect = require('chai').expect;
|
|
4
|
+
const ConfigError = require('../../lib/config/configError');
|
|
5
|
+
const testUtils = require('../util/testUtils');
|
|
6
|
+
|
|
7
|
+
describe('Brother FTP device config', function () {
|
|
8
|
+
it('accepts brother-ftp without collection-mode (defaults to ftp)', async function () {
|
|
9
|
+
const cfg = await testUtils.loadConfig('device/brother-ftp-minimal.yml');
|
|
10
|
+
expect(cfg.deviceName).to.eq('brother-ftp');
|
|
11
|
+
expect(cfg.device.dataCollectionMode).to.eq(cfg.device.DataCollectionModes.FTP);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('passes through optional FTP paths and cnc-version', async function () {
|
|
15
|
+
const cfg = await testUtils.loadConfig('device/brother-ftp-paths.yml');
|
|
16
|
+
expect(cfg.device.cncVersion).to.eq('d00');
|
|
17
|
+
expect(cfg.device.memoryPath).to.eq('_DAT/MEM.NC');
|
|
18
|
+
expect(cfg.device.productionPath).to.eq('_PRD/PRDD2.NC');
|
|
19
|
+
expect(cfg.device.panelPath).to.eq('_DAT/PANEL.NC');
|
|
20
|
+
expect(cfg.device.positionPath).to.eq('_DAT/PDSP.NC');
|
|
21
|
+
expect(cfg.device.workCounterPath).to.eq('_DAT/WKCNTR.NC');
|
|
22
|
+
expect(cfg.device.alarmPath).to.eq('_DAT/ALARM.NC');
|
|
23
|
+
expect(cfg.device.macroPath).to.eq('_DAT/MCRNI1.NC');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('does not set path properties when keys are omitted', async function () {
|
|
27
|
+
const cfg = await testUtils.loadConfig('device/brother-ftp-minimal.yml');
|
|
28
|
+
expect(cfg.device.memoryPath).to.eq(undefined);
|
|
29
|
+
expect(cfg.device.cncVersion).to.eq(undefined);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('accepts cnc-version legacy', async function () {
|
|
33
|
+
const cfg = await testUtils.loadConfig('device/brother-ftp-cnc-legacy.yml');
|
|
34
|
+
expect(cfg.device.cncVersion).to.eq('legacy');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('rejects invalid cnc-version', async function () {
|
|
38
|
+
try {
|
|
39
|
+
await testUtils.loadConfig('device/brother-ftp-bad-cnc.yml');
|
|
40
|
+
expect.fail('Expected ConfigError');
|
|
41
|
+
} catch (err) {
|
|
42
|
+
expect(err).to.be.instanceof(ConfigError);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('rejects paths containing ..', async function () {
|
|
47
|
+
try {
|
|
48
|
+
await testUtils.loadConfig('device/brother-ftp-bad-path.yml');
|
|
49
|
+
expect.fail('Expected ConfigError');
|
|
50
|
+
} catch (err) {
|
|
51
|
+
expect(err).to.be.instanceof(ConfigError);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('rejects brother-ftp with non-ftp collection-mode', async function () {
|
|
56
|
+
try {
|
|
57
|
+
await testUtils.loadConfig('device/brother-ftp-bad-mode.yml');
|
|
58
|
+
expect.fail('Expected ConfigError');
|
|
59
|
+
} catch (err) {
|
|
60
|
+
expect(err).to.be.instanceof(ConfigError);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -15,5 +15,7 @@ describe('Brother HTTP config tests', function () {
|
|
|
15
15
|
expect(defaultConfig.device.port).to.eq(21);
|
|
16
16
|
expect(defaultConfig.device.scanInterval).to.eq(1000);
|
|
17
17
|
expect(defaultConfig.device.httpInterval).to.eq(50);
|
|
18
|
+
expect(defaultConfig.device.memoryPath).to.eq(undefined);
|
|
19
|
+
expect(defaultConfig.device.cncVersion).to.eq(undefined);
|
|
18
20
|
});
|
|
19
21
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
device: brother-ftp
|
|
2
|
+
endpoint: 192.168.1.50
|
|
3
|
+
collection-mode: ftp
|
|
4
|
+
cnc-version: d00
|
|
5
|
+
memory-path: _DAT/MEM.NC
|
|
6
|
+
production-path: _PRD/PRDD2.NC
|
|
7
|
+
panel-path: _DAT/PANEL.NC
|
|
8
|
+
position-path: _DAT/PDSP.NC
|
|
9
|
+
work-counter-path: _DAT/WKCNTR.NC
|
|
10
|
+
alarm-path: _DAT/ALARM.NC
|
|
11
|
+
macro-path: _DAT/MCRNI1.NC
|