@synapticon/motion-master-client 2.2.2 → 6.0.0-alpha.22
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 +21 -0
- package/dist/client.d.ts +20 -0
- package/dist/client.js +37 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +8 -0
- package/dist/generated/Api.d.ts +991 -0
- package/dist/generated/Api.js +614 -0
- package/dist/generated/data-contracts.d.ts +644 -0
- package/dist/generated/data-contracts.js +12 -0
- package/dist/generated/http-client.d.ts +60 -0
- package/dist/generated/http-client.js +171 -0
- package/dist/hex.d.ts +2 -0
- package/dist/hex.js +20 -0
- package/dist/index.d.ts +10 -7
- package/dist/index.js +16 -22
- package/dist/mmpd.d.ts +54 -0
- package/dist/mmpd.js +323 -0
- package/dist/sdo.d.ts +15 -0
- package/dist/sdo.js +212 -0
- package/dist/somanet.d.ts +5 -0
- package/dist/somanet.js +15 -0
- package/dist/web-socket-connection.d.ts +69 -0
- package/dist/web-socket-connection.js +206 -0
- package/package.json +29 -39
- package/.vscode/launch.json +0 -23
- package/README.md +0 -118
- package/box.config.json +0 -7
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -1433
- package/dist/cli.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/motion-master-client-web-socket-connection.d.ts +0 -43
- package/dist/motion-master-client-web-socket-connection.d.ts.map +0 -1
- package/dist/motion-master-client-web-socket-connection.js +0 -91
- package/dist/motion-master-client-web-socket-connection.js.map +0 -1
- package/dist/motion-master-client.d.ts +0 -105
- package/dist/motion-master-client.d.ts.map +0 -1
- package/dist/motion-master-client.js +0 -348
- package/dist/motion-master-client.js.map +0 -1
- package/dist/motion-master-notification-subscribe-data.d.ts +0 -8
- package/dist/motion-master-notification-subscribe-data.d.ts.map +0 -1
- package/dist/motion-master-notification-subscribe-data.js +0 -3
- package/dist/motion-master-notification-subscribe-data.js.map +0 -1
- package/dist/motion-master-notification-web-socket-connection.d.ts +0 -56
- package/dist/motion-master-notification-web-socket-connection.d.ts.map +0 -1
- package/dist/motion-master-notification-web-socket-connection.js +0 -115
- package/dist/motion-master-notification-web-socket-connection.js.map +0 -1
- package/dist/motion-master-notification.d.ts +0 -31
- package/dist/motion-master-notification.d.ts.map +0 -1
- package/dist/motion-master-notification.js +0 -44
- package/dist/motion-master-notification.js.map +0 -1
- package/dist/util.d.ts +0 -16
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -24
- package/dist/util.js.map +0 -1
- package/licenses.format.json +0 -4
- package/motion-master-client.config.json +0 -7
- package/smm_data_dic.json +0 -1213
- package/src/cli.ts +0 -1361
- package/src/index.ts +0 -7
- package/src/motion-master-client-web-socket-connection.ts +0 -104
- package/src/motion-master-client.ts +0 -468
- package/src/motion-master-notification-subscribe-data.ts +0 -7
- package/src/motion-master-notification-web-socket-connection.ts +0 -143
- package/src/motion-master-notification.ts +0 -51
- package/src/util.ts +0 -22
- package/test.sh +0 -122
- package/tsconfig.json +0 -63
- package/tslint.json +0 -118
package/src/cli.ts
DELETED
|
@@ -1,1361 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import program, { Command } from 'commander';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { interval } from 'rxjs';
|
|
6
|
-
import { first, map, timeout } from 'rxjs/operators';
|
|
7
|
-
import { StringDecoder } from 'string_decoder';
|
|
8
|
-
import util from 'util';
|
|
9
|
-
import { v4 } from 'uuid';
|
|
10
|
-
import YAML from 'yaml';
|
|
11
|
-
import zmq from 'zeromq';
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
ComputeAutoTuningGainsType,
|
|
15
|
-
DeviceAddressType,
|
|
16
|
-
MotionMasterClient,
|
|
17
|
-
RequestType,
|
|
18
|
-
SignalGeneratorType,
|
|
19
|
-
StatusType,
|
|
20
|
-
} from './motion-master-client';
|
|
21
|
-
import { MotionMasterNotification } from './motion-master-notification';
|
|
22
|
-
import {
|
|
23
|
-
decodeMotionMasterMessage,
|
|
24
|
-
encodeMotionMasterMessage,
|
|
25
|
-
MotionMasterMessage,
|
|
26
|
-
} from './util';
|
|
27
|
-
|
|
28
|
-
type OutputFormat = 'inspect' | 'json' | 'yaml';
|
|
29
|
-
|
|
30
|
-
enum ExitStatus {
|
|
31
|
-
SUCCESS,
|
|
32
|
-
UNCAUGHT_EXCEPTION,
|
|
33
|
-
UNHANDLED_REJECTION,
|
|
34
|
-
TIMEOUT,
|
|
35
|
-
INCORRECT_PARAMETER_FORMAT,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// tslint:disable: no-var-requires
|
|
39
|
-
const debug = require('debug')('motion-master-client');
|
|
40
|
-
const version = require('../package.json')['version'];
|
|
41
|
-
// tslint:enable-next-line: no-var-requires
|
|
42
|
-
|
|
43
|
-
process.on('uncaughtException', (err) => {
|
|
44
|
-
console.error('Caught exception: ' + err);
|
|
45
|
-
process.exit(ExitStatus.UNCAUGHT_EXCEPTION);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
process.on('unhandledRejection', (reason) => {
|
|
49
|
-
console.error('Unhandled rejection reason: ', reason);
|
|
50
|
-
process.exit(ExitStatus.UNHANDLED_REJECTION);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const inspectOptions: util.InspectOptions = {
|
|
54
|
-
showHidden: false,
|
|
55
|
-
depth: null,
|
|
56
|
-
colors: true,
|
|
57
|
-
maxArrayLength: null,
|
|
58
|
-
compact: false,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// map to cache device parameter info per device
|
|
62
|
-
const deviceParameterInfoMap: Map<number, MotionMasterMessage.Status.IDeviceParameterInfo | null | undefined> = new Map();
|
|
63
|
-
|
|
64
|
-
const motionMasterClient = new MotionMasterClient();
|
|
65
|
-
const motionMasterNotification = new MotionMasterNotification();
|
|
66
|
-
|
|
67
|
-
const config = {
|
|
68
|
-
pingSystemInterval: 150, // ping Motion Master at regular intervals
|
|
69
|
-
motionMasterHeartbeatTimeoutDue: 1000, // exit process when Motion Master doesn't send a heartbeat message in time specified
|
|
70
|
-
serverEndpoint: 'tcp://127.0.0.1:62524', // request and receive status messages (response)
|
|
71
|
-
notificationEndpoint: 'tcp://127.0.0.1:62525', // subscribe to a topic and receive published status messages (heartbeat and monitoring)
|
|
72
|
-
identity: v4(), // ZeroMQ DEALER socket identity
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
// program and commands
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
program
|
|
80
|
-
.version(version)
|
|
81
|
-
.option('-c, --config <path>', 'path to JSON config file to read and replace the default values with')
|
|
82
|
-
.option('-d, --device-address <address>', 'device address (uint32) generated by Motion Master - takes precedence over device position', parseOptionValueAsInt)
|
|
83
|
-
.option('-f, --output-format <json|yaml>', 'if left unspecified the output format is the default colored message inspect')
|
|
84
|
-
.option('-p, --device-position <position>', 'used when device address is not specified', parseOptionValueAsInt, 0);
|
|
85
|
-
|
|
86
|
-
program
|
|
87
|
-
.command('request <type> [args...]')
|
|
88
|
-
.option('-i, --interval <value>', 'sending interval in microseconds', parseOptionValueAsInt, 1 * 1000 * 1000)
|
|
89
|
-
.on('--help', () => {
|
|
90
|
-
const types = Object.keys(MotionMasterMessage.Request).slice(8).map((type) => type.charAt(0).toLowerCase() + type.slice(1));
|
|
91
|
-
console.log('');
|
|
92
|
-
console.log('Request <type>s:');
|
|
93
|
-
console.log(' ' + types.join('\n '));
|
|
94
|
-
})
|
|
95
|
-
.action(requestAction);
|
|
96
|
-
|
|
97
|
-
program
|
|
98
|
-
.command('upload [params...]')
|
|
99
|
-
.option('-s, --send-progress')
|
|
100
|
-
.action(uploadAction);
|
|
101
|
-
|
|
102
|
-
program
|
|
103
|
-
.command('download [paramValues...]')
|
|
104
|
-
.action(downloadAction);
|
|
105
|
-
|
|
106
|
-
program
|
|
107
|
-
.command('getDeviceFileContent <filename>')
|
|
108
|
-
.action(getDeviceFileContentAction);
|
|
109
|
-
|
|
110
|
-
program
|
|
111
|
-
.command('getDeviceLogContent')
|
|
112
|
-
.action(getDeviceLogContentAction);
|
|
113
|
-
|
|
114
|
-
program
|
|
115
|
-
.command('getCoggingTorqueDataContent')
|
|
116
|
-
.action(getCoggingTorqueDataContent);
|
|
117
|
-
|
|
118
|
-
program
|
|
119
|
-
.command('startCoggingTorqueRecording')
|
|
120
|
-
.option('-s, --skip-auto-tuning')
|
|
121
|
-
.action(startCoggingTorqueRecordingAction);
|
|
122
|
-
|
|
123
|
-
program
|
|
124
|
-
.command('startOffsetDetection')
|
|
125
|
-
.action(startOffsetDetectionAction);
|
|
126
|
-
|
|
127
|
-
program
|
|
128
|
-
.command('startPlantIdentification <durationSeconds> <torqueAmplitude> <startFrequency> <endFrequency> <cutoffFrequency>')
|
|
129
|
-
.action(startPlantIdentificationAction);
|
|
130
|
-
|
|
131
|
-
program
|
|
132
|
-
.command('startSystemIdentification <durationSeconds> <torqueAmplitude> <startFrequency> <endFrequency>')
|
|
133
|
-
.action(startSystemIdentificationAction);
|
|
134
|
-
|
|
135
|
-
program
|
|
136
|
-
.command('startCirculoEncoderNarrowAngleCalibrationProcedure <encoderOrdinal>')
|
|
137
|
-
.action(startCirculoEncoderNarrowAngleCalibrationProcedureAction);
|
|
138
|
-
|
|
139
|
-
program
|
|
140
|
-
.command('monitor <topic> [params...]')
|
|
141
|
-
.option('-i, --interval <value>', 'sending interval in microseconds', parseOptionValueAsInt, 1 * 1000 * 1000)
|
|
142
|
-
.action(monitorAction);
|
|
143
|
-
|
|
144
|
-
// parse command line arguments and execute the command action
|
|
145
|
-
program.parse(process.argv);
|
|
146
|
-
|
|
147
|
-
//
|
|
148
|
-
// command action functions
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
async function requestAction(type: RequestType, args: string[], cmd: Command) {
|
|
152
|
-
connectToMotionMaster(cmd.parent);
|
|
153
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
154
|
-
|
|
155
|
-
const messageId = v4();
|
|
156
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
157
|
-
|
|
158
|
-
switch (type) {
|
|
159
|
-
case 'pingSystem': {
|
|
160
|
-
motionMasterClient.requestPingSystem(messageId);
|
|
161
|
-
|
|
162
|
-
process.exit(ExitStatus.SUCCESS);
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
case 'getSystemVersion': {
|
|
166
|
-
exitOnMessageReceived(messageId);
|
|
167
|
-
|
|
168
|
-
motionMasterClient.requestGetSystemVersion(messageId);
|
|
169
|
-
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case 'getDeviceInfo': {
|
|
173
|
-
exitOnMessageReceived(messageId);
|
|
174
|
-
|
|
175
|
-
motionMasterClient.requestGetDeviceInfo(messageId);
|
|
176
|
-
|
|
177
|
-
break;
|
|
178
|
-
}
|
|
179
|
-
case 'getDeviceParameterInfo': {
|
|
180
|
-
exitOnMessageReceived(messageId);
|
|
181
|
-
|
|
182
|
-
motionMasterClient.requestGetDeviceParameterInfo(deviceAddress, messageId);
|
|
183
|
-
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
case 'getDeviceParameterValues': {
|
|
187
|
-
exitOnMessageReceived(messageId);
|
|
188
|
-
|
|
189
|
-
const parameters: MotionMasterMessage.Request.GetDeviceParameterValues.IParameter[] = args.map(paramToIndexSubindex);
|
|
190
|
-
validateParameters(parameters);
|
|
191
|
-
motionMasterClient.requestGetDeviceParameterValues(deviceAddress, parameters, false, messageId);
|
|
192
|
-
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
case 'getMultiDeviceParameterValues': {
|
|
196
|
-
throw new Error(`Request "${type}" is not yet implemented`);
|
|
197
|
-
}
|
|
198
|
-
case 'setDeviceParameterValues': {
|
|
199
|
-
exitOnMessageReceived(messageId);
|
|
200
|
-
|
|
201
|
-
const deviceParameterInfo = await getDeviceParameterInfoAsync(deviceAddress);
|
|
202
|
-
const parameterValues = args.map((paramValue) => paramToIndexSubIndexValue(paramValue, deviceParameterInfo));
|
|
203
|
-
motionMasterClient.requestSetDeviceParameterValues(deviceAddress, parameterValues, messageId);
|
|
204
|
-
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
case 'setMultiDeviceParameterValues': {
|
|
208
|
-
throw new Error(`Request "${type}" is not yet implemented`);
|
|
209
|
-
}
|
|
210
|
-
case 'getDeviceFileList': {
|
|
211
|
-
exitOnMessageReceived(messageId);
|
|
212
|
-
|
|
213
|
-
motionMasterClient.requestGetDeviceFileList(deviceAddress, messageId);
|
|
214
|
-
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
case 'getDeviceFile': {
|
|
218
|
-
exitOnMessageReceived(messageId);
|
|
219
|
-
|
|
220
|
-
const name = args[0];
|
|
221
|
-
motionMasterClient.requestGetDeviceFile(deviceAddress, name, messageId);
|
|
222
|
-
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
case 'setDeviceFile': {
|
|
226
|
-
exitOnMessageReceived(messageId);
|
|
227
|
-
|
|
228
|
-
const filepath = args[0];
|
|
229
|
-
const name = path.basename(filepath);
|
|
230
|
-
const content = fs.readFileSync(filepath);
|
|
231
|
-
const overwrite = true;
|
|
232
|
-
motionMasterClient.requestSetDeviceFile(deviceAddress, name, content, overwrite, messageId);
|
|
233
|
-
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
case 'deleteDeviceFile': {
|
|
237
|
-
exitOnMessageReceived(messageId);
|
|
238
|
-
|
|
239
|
-
const name = args[0];
|
|
240
|
-
motionMasterClient.requestDeleteDeviceFile(deviceAddress, name, messageId);
|
|
241
|
-
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
case 'resetDeviceFault': {
|
|
245
|
-
exitOnMessageReceived(messageId);
|
|
246
|
-
|
|
247
|
-
motionMasterClient.requestResetDeviceFault(deviceAddress, messageId);
|
|
248
|
-
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
case 'stopDevice': {
|
|
252
|
-
motionMasterClient.requestStopDevice(deviceAddress, messageId);
|
|
253
|
-
|
|
254
|
-
process.exit(ExitStatus.SUCCESS);
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
case 'startDeviceFirmwareInstallation': {
|
|
258
|
-
exitOnMessageReceived(messageId, 120000, MotionMasterMessage.Status.DeviceFirmwareInstallation.Success.Code.DONE);
|
|
259
|
-
|
|
260
|
-
const filepath = args[0];
|
|
261
|
-
const firmwarePackageContent = fs.readFileSync(filepath);
|
|
262
|
-
|
|
263
|
-
const skipSiiInstallation = parseInt(args[1], 10) !== 0;
|
|
264
|
-
|
|
265
|
-
motionMasterClient.requestStartDeviceFirmwareInstallation(deviceAddress, firmwarePackageContent, skipSiiInstallation, messageId);
|
|
266
|
-
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
case 'getDeviceLog': {
|
|
270
|
-
exitOnMessageReceived(messageId);
|
|
271
|
-
|
|
272
|
-
const getDeviceLog: MotionMasterMessage.Request.IGetDeviceLog = { deviceAddress };
|
|
273
|
-
|
|
274
|
-
motionMasterClient.sendRequest({ getDeviceLog }, messageId);
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
case 'startCoggingTorqueRecording': {
|
|
278
|
-
exitOnMessageReceived(messageId, 300000, MotionMasterMessage.Status.CoggingTorqueRecording.Success.Code.DONE);
|
|
279
|
-
|
|
280
|
-
const skipAutoTuning = parseInt(args[0], 10) !== 0;
|
|
281
|
-
|
|
282
|
-
motionMasterClient.requestStartCoggingTorqueRecording(deviceAddress, skipAutoTuning, messageId);
|
|
283
|
-
|
|
284
|
-
break;
|
|
285
|
-
}
|
|
286
|
-
case 'getCoggingTorqueData': {
|
|
287
|
-
exitOnMessageReceived(messageId);
|
|
288
|
-
|
|
289
|
-
motionMasterClient.requestGetCoggingTorqueData(deviceAddress, messageId);
|
|
290
|
-
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
case 'startOffsetDetection': {
|
|
294
|
-
exitOnMessageReceived(messageId, 180000, MotionMasterMessage.Status.OffsetDetection.Success.Code.DONE);
|
|
295
|
-
|
|
296
|
-
motionMasterClient.requestStartOffsetDetection(deviceAddress, messageId);
|
|
297
|
-
|
|
298
|
-
break;
|
|
299
|
-
}
|
|
300
|
-
case 'startPlantIdentification': {
|
|
301
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.PlantIdentification.Success.Code.DONE);
|
|
302
|
-
|
|
303
|
-
const durationSeconds = parseFloat(args[0]);
|
|
304
|
-
const torqueAmplitude = parseInt(args[1], 10);
|
|
305
|
-
const startFrequency = parseInt(args[2], 10);
|
|
306
|
-
const endFrequency = parseInt(args[3], 10);
|
|
307
|
-
const cutoffFrequency = parseInt(args[4], 10);
|
|
308
|
-
|
|
309
|
-
motionMasterClient.requestStartPlantIdentification(deviceAddress, durationSeconds, torqueAmplitude, startFrequency, endFrequency, cutoffFrequency, messageId);
|
|
310
|
-
|
|
311
|
-
break;
|
|
312
|
-
}
|
|
313
|
-
case 'startSystemIdentification': {
|
|
314
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.SystemIdentification.Success.Code.DONE);
|
|
315
|
-
|
|
316
|
-
const durationSeconds = parseFloat(args[0]);
|
|
317
|
-
const torqueAmplitude = parseInt(args[1], 10);
|
|
318
|
-
const startFrequency = parseFloat(args[2]);
|
|
319
|
-
const endFrequency = parseFloat(args[3]);
|
|
320
|
-
|
|
321
|
-
motionMasterClient.requestStartSystemIdentification(deviceAddress, durationSeconds, torqueAmplitude, startFrequency, endFrequency, messageId);
|
|
322
|
-
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
case 'computeAutoTuningGains': {
|
|
326
|
-
const computeAutoTuningGainsType = args[0] as ComputeAutoTuningGainsType;
|
|
327
|
-
switch (computeAutoTuningGainsType) {
|
|
328
|
-
case 'positionParameters': {
|
|
329
|
-
exitOnMessageReceived(messageId, 10000, MotionMasterMessage.Status.AutoTuning.Success.Code.POSITION_DONE);
|
|
330
|
-
|
|
331
|
-
const controllerType = parseInt(args[1], 10);
|
|
332
|
-
const settlingTime = parseFloat(args[2]);
|
|
333
|
-
const positionDamping = parseFloat(args[3]);
|
|
334
|
-
const alphaMult = parseInt(args[4], 10);
|
|
335
|
-
const order = parseInt(args[5], 10);
|
|
336
|
-
const lb = parseFloat(args[6]);
|
|
337
|
-
const ub = parseFloat(args[7]);
|
|
338
|
-
|
|
339
|
-
const computeAutoTuningGains: MotionMasterMessage.Request.IComputeAutoTuningGains = {
|
|
340
|
-
deviceAddress,
|
|
341
|
-
positionParameters: {
|
|
342
|
-
controllerType,
|
|
343
|
-
settlingTime,
|
|
344
|
-
positionDamping,
|
|
345
|
-
alphaMult,
|
|
346
|
-
order,
|
|
347
|
-
lb,
|
|
348
|
-
ub,
|
|
349
|
-
},
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
motionMasterClient.sendRequest({ computeAutoTuningGains }, messageId);
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
case 'velocityParameters': {
|
|
356
|
-
exitOnMessageReceived(messageId, 10000, MotionMasterMessage.Status.AutoTuning.Success.Code.VELOCITY_DONE);
|
|
357
|
-
|
|
358
|
-
const velocityLoopBandwidth = parseFloat(args[1]);
|
|
359
|
-
const velocityDamping = parseFloat(args[2]);
|
|
360
|
-
|
|
361
|
-
const computeAutoTuningGains: MotionMasterMessage.Request.IComputeAutoTuningGains = {
|
|
362
|
-
deviceAddress,
|
|
363
|
-
velocityParameters: {
|
|
364
|
-
velocityLoopBandwidth,
|
|
365
|
-
velocityDamping,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
motionMasterClient.sendRequest({ computeAutoTuningGains }, messageId);
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
default: {
|
|
373
|
-
throw new Error(`Unknown compute auto-tuning gains type: ${computeAutoTuningGainsType}`);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
break;
|
|
377
|
-
}
|
|
378
|
-
case 'setMotionControllerParameters': {
|
|
379
|
-
const target = parseInt(args[0], 10);
|
|
380
|
-
|
|
381
|
-
const setMotionControllerParameters: MotionMasterMessage.Request.ISetMotionControllerParameters = {
|
|
382
|
-
deviceAddress,
|
|
383
|
-
target,
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
motionMasterClient.sendRequest({ setMotionControllerParameters }, messageId);
|
|
387
|
-
process.exit(ExitStatus.SUCCESS);
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
case 'enableMotionController': {
|
|
391
|
-
exitOnMessageReceived(messageId);
|
|
392
|
-
|
|
393
|
-
const controllerType = parseInt(args[0], 10);
|
|
394
|
-
const filter = parseInt(args[1], 10) !== 0;
|
|
395
|
-
|
|
396
|
-
motionMasterClient.requestEnableMotionController(deviceAddress, controllerType, filter, messageId);
|
|
397
|
-
|
|
398
|
-
break;
|
|
399
|
-
}
|
|
400
|
-
case 'disableMotionController': {
|
|
401
|
-
motionMasterClient.requestDisableMotionController(deviceAddress, messageId);
|
|
402
|
-
process.exit(ExitStatus.SUCCESS);
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
case 'setSignalGeneratorParameters': {
|
|
406
|
-
const signalGeneratorType = args[0] as SignalGeneratorType;
|
|
407
|
-
|
|
408
|
-
const setSignalGeneratorParameters: MotionMasterMessage.Request.ISetSignalGeneratorParameters = { deviceAddress };
|
|
409
|
-
|
|
410
|
-
switch (signalGeneratorType) {
|
|
411
|
-
case 'positionStepResponse': {
|
|
412
|
-
const target = parseInt(args[1], 10);
|
|
413
|
-
const sustainTime = parseInt(args[2], 10);
|
|
414
|
-
|
|
415
|
-
setSignalGeneratorParameters.positionStepResponse = {
|
|
416
|
-
target,
|
|
417
|
-
sustainTime,
|
|
418
|
-
};
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
case 'positionAdvancedStepResponse': {
|
|
422
|
-
const target = parseInt(args[1], 10);
|
|
423
|
-
const sustainTime = parseInt(args[2], 10);
|
|
424
|
-
const repeat = parseInt(args[3], 10) !== 0;
|
|
425
|
-
|
|
426
|
-
setSignalGeneratorParameters.positionAdvancedStepResponse = {
|
|
427
|
-
target,
|
|
428
|
-
sustainTime,
|
|
429
|
-
repeat,
|
|
430
|
-
};
|
|
431
|
-
break;
|
|
432
|
-
}
|
|
433
|
-
case 'positionRamp': {
|
|
434
|
-
const target = parseInt(args[1], 10);
|
|
435
|
-
const profileVelocity = parseInt(args[2], 10);
|
|
436
|
-
const profileAcceleration = parseInt(args[3], 10);
|
|
437
|
-
const profileDeceleration = parseInt(args[4], 10);
|
|
438
|
-
const sustainTime = parseInt(args[5], 10);
|
|
439
|
-
|
|
440
|
-
setSignalGeneratorParameters.positionRamp = {
|
|
441
|
-
target,
|
|
442
|
-
profileVelocity,
|
|
443
|
-
profileAcceleration,
|
|
444
|
-
profileDeceleration,
|
|
445
|
-
sustainTime,
|
|
446
|
-
};
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
case 'positionTrapezoidal': {
|
|
450
|
-
const target = parseInt(args[1], 10);
|
|
451
|
-
const profileVelocity = parseInt(args[2], 10);
|
|
452
|
-
const profileAcceleration = parseInt(args[3], 10);
|
|
453
|
-
const profileDeceleration = parseInt(args[4], 10);
|
|
454
|
-
const sustainTime = parseInt(args[5], 10);
|
|
455
|
-
const repeat = parseInt(args[6], 10) !== 0;
|
|
456
|
-
|
|
457
|
-
setSignalGeneratorParameters.positionTrapezoidal = {
|
|
458
|
-
target,
|
|
459
|
-
profileVelocity,
|
|
460
|
-
profileAcceleration,
|
|
461
|
-
profileDeceleration,
|
|
462
|
-
sustainTime,
|
|
463
|
-
repeat,
|
|
464
|
-
};
|
|
465
|
-
break;
|
|
466
|
-
}
|
|
467
|
-
case 'positionBidirectional': {
|
|
468
|
-
const target = parseInt(args[1], 10);
|
|
469
|
-
const profileVelocity = parseInt(args[2], 10);
|
|
470
|
-
const profileAcceleration = parseInt(args[3], 10);
|
|
471
|
-
const profileDeceleration = parseInt(args[4], 10);
|
|
472
|
-
const sustainTime = parseInt(args[5], 10);
|
|
473
|
-
const repeat = parseInt(args[6], 10) !== 0;
|
|
474
|
-
|
|
475
|
-
setSignalGeneratorParameters.positionBidirectional = {
|
|
476
|
-
target,
|
|
477
|
-
profileVelocity,
|
|
478
|
-
profileAcceleration,
|
|
479
|
-
profileDeceleration,
|
|
480
|
-
sustainTime,
|
|
481
|
-
repeat,
|
|
482
|
-
};
|
|
483
|
-
break;
|
|
484
|
-
}
|
|
485
|
-
case 'positionSineWave': {
|
|
486
|
-
const amplitude = parseInt(args[1], 10);
|
|
487
|
-
const frequency = parseFloat(args[2]);
|
|
488
|
-
const repeat = parseInt(args[3], 10) !== 0;
|
|
489
|
-
|
|
490
|
-
setSignalGeneratorParameters.positionSineWave = {
|
|
491
|
-
amplitude,
|
|
492
|
-
frequency,
|
|
493
|
-
repeat,
|
|
494
|
-
};
|
|
495
|
-
break;
|
|
496
|
-
}
|
|
497
|
-
case 'velocityStepResponse': {
|
|
498
|
-
const target = parseInt(args[1], 10);
|
|
499
|
-
const sustainTime = parseInt(args[2], 10);
|
|
500
|
-
|
|
501
|
-
setSignalGeneratorParameters.velocityStepResponse = {
|
|
502
|
-
target,
|
|
503
|
-
sustainTime,
|
|
504
|
-
};
|
|
505
|
-
break;
|
|
506
|
-
}
|
|
507
|
-
case 'velocityAdvancedStepResponse': {
|
|
508
|
-
const target = parseInt(args[1], 10);
|
|
509
|
-
const sustainTime = parseInt(args[2], 10);
|
|
510
|
-
const repeat = parseInt(args[3], 10) !== 0;
|
|
511
|
-
|
|
512
|
-
setSignalGeneratorParameters.velocityAdvancedStepResponse = {
|
|
513
|
-
target,
|
|
514
|
-
sustainTime,
|
|
515
|
-
repeat,
|
|
516
|
-
};
|
|
517
|
-
break;
|
|
518
|
-
}
|
|
519
|
-
case 'velocityRamp': {
|
|
520
|
-
const target = parseInt(args[1], 10);
|
|
521
|
-
const profileAcceleration = parseInt(args[2], 10);
|
|
522
|
-
const profileDeceleration = parseInt(args[3], 10);
|
|
523
|
-
const sustainTime = parseInt(args[4], 10);
|
|
524
|
-
|
|
525
|
-
setSignalGeneratorParameters.velocityRamp = {
|
|
526
|
-
target,
|
|
527
|
-
profileAcceleration,
|
|
528
|
-
profileDeceleration,
|
|
529
|
-
sustainTime,
|
|
530
|
-
};
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
case 'velocityTrapezoidal': {
|
|
534
|
-
const target = parseInt(args[1], 10);
|
|
535
|
-
const profileAcceleration = parseInt(args[2], 10);
|
|
536
|
-
const profileDeceleration = parseInt(args[3], 10);
|
|
537
|
-
const sustainTime = parseInt(args[4], 10);
|
|
538
|
-
const repeat = parseInt(args[5], 10) !== 0;
|
|
539
|
-
|
|
540
|
-
setSignalGeneratorParameters.velocityTrapezoidal = {
|
|
541
|
-
target,
|
|
542
|
-
profileAcceleration,
|
|
543
|
-
profileDeceleration,
|
|
544
|
-
sustainTime,
|
|
545
|
-
repeat,
|
|
546
|
-
};
|
|
547
|
-
break;
|
|
548
|
-
}
|
|
549
|
-
case 'velocityBidirectional': {
|
|
550
|
-
const target = parseInt(args[1], 10);
|
|
551
|
-
const profileAcceleration = parseInt(args[2], 10);
|
|
552
|
-
const profileDeceleration = parseInt(args[3], 10);
|
|
553
|
-
const sustainTime = parseInt(args[4], 10);
|
|
554
|
-
const repeat = parseInt(args[5], 10) !== 0;
|
|
555
|
-
|
|
556
|
-
setSignalGeneratorParameters.velocityBidirectional = {
|
|
557
|
-
target,
|
|
558
|
-
profileAcceleration,
|
|
559
|
-
profileDeceleration,
|
|
560
|
-
sustainTime,
|
|
561
|
-
repeat,
|
|
562
|
-
};
|
|
563
|
-
break;
|
|
564
|
-
}
|
|
565
|
-
case 'velocitySineWave': {
|
|
566
|
-
const amplitude = parseInt(args[1], 10);
|
|
567
|
-
const frequency = parseFloat(args[2]);
|
|
568
|
-
const repeat = parseInt(args[3], 10) !== 0;
|
|
569
|
-
|
|
570
|
-
setSignalGeneratorParameters.velocitySineWave = {
|
|
571
|
-
amplitude,
|
|
572
|
-
frequency,
|
|
573
|
-
repeat,
|
|
574
|
-
};
|
|
575
|
-
break;
|
|
576
|
-
}
|
|
577
|
-
case 'torqueStepResponse': {
|
|
578
|
-
const target = parseInt(args[1], 10);
|
|
579
|
-
const sustainTime = parseInt(args[2], 10);
|
|
580
|
-
|
|
581
|
-
setSignalGeneratorParameters.torqueStepResponse = {
|
|
582
|
-
target,
|
|
583
|
-
sustainTime,
|
|
584
|
-
};
|
|
585
|
-
break;
|
|
586
|
-
}
|
|
587
|
-
case 'torqueAdvancedStepResponse': {
|
|
588
|
-
const target = parseInt(args[1], 10);
|
|
589
|
-
const sustainTime = parseInt(args[2], 10);
|
|
590
|
-
const repeat = parseInt(args[3], 10) !== 0;
|
|
591
|
-
|
|
592
|
-
setSignalGeneratorParameters.torqueAdvancedStepResponse = {
|
|
593
|
-
target,
|
|
594
|
-
sustainTime,
|
|
595
|
-
repeat,
|
|
596
|
-
};
|
|
597
|
-
break;
|
|
598
|
-
}
|
|
599
|
-
case 'torqueRamp': {
|
|
600
|
-
const target = parseInt(args[1], 10);
|
|
601
|
-
const torqueSlope = parseInt(args[2], 10);
|
|
602
|
-
const sustainTime = parseInt(args[3], 10);
|
|
603
|
-
|
|
604
|
-
setSignalGeneratorParameters.torqueRamp = {
|
|
605
|
-
target,
|
|
606
|
-
torqueSlope,
|
|
607
|
-
sustainTime,
|
|
608
|
-
};
|
|
609
|
-
break;
|
|
610
|
-
}
|
|
611
|
-
case 'torqueTrapezoidal': {
|
|
612
|
-
const target = parseInt(args[1], 10);
|
|
613
|
-
const torqueSlope = parseInt(args[2], 10);
|
|
614
|
-
const sustainTime = parseInt(args[3], 10);
|
|
615
|
-
const repeat = parseInt(args[4], 10) !== 0;
|
|
616
|
-
|
|
617
|
-
setSignalGeneratorParameters.torqueTrapezoidal = {
|
|
618
|
-
target,
|
|
619
|
-
torqueSlope,
|
|
620
|
-
sustainTime,
|
|
621
|
-
repeat,
|
|
622
|
-
};
|
|
623
|
-
break;
|
|
624
|
-
}
|
|
625
|
-
case 'torqueBidirectional': {
|
|
626
|
-
const target = parseInt(args[1], 10);
|
|
627
|
-
const torqueSlope = parseInt(args[2], 10);
|
|
628
|
-
const sustainTime = parseInt(args[3], 10);
|
|
629
|
-
const repeat = parseInt(args[4], 10) !== 0;
|
|
630
|
-
|
|
631
|
-
setSignalGeneratorParameters.torqueBidirectional = {
|
|
632
|
-
target,
|
|
633
|
-
torqueSlope,
|
|
634
|
-
sustainTime,
|
|
635
|
-
repeat,
|
|
636
|
-
};
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
case 'torqueSineWave': {
|
|
640
|
-
const amplitude = parseInt(args[1], 10);
|
|
641
|
-
const frequency = parseFloat(args[2]);
|
|
642
|
-
const repeat = parseInt(args[3], 10) !== 0;
|
|
643
|
-
|
|
644
|
-
setSignalGeneratorParameters.torqueSineWave = {
|
|
645
|
-
amplitude,
|
|
646
|
-
frequency,
|
|
647
|
-
repeat,
|
|
648
|
-
};
|
|
649
|
-
break;
|
|
650
|
-
}
|
|
651
|
-
default: {
|
|
652
|
-
throw new Error(`Unknown set signal generator parameters type: ${signalGeneratorType}`);
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
motionMasterClient.sendRequest({ setSignalGeneratorParameters }, messageId);
|
|
657
|
-
process.exit(ExitStatus.SUCCESS);
|
|
658
|
-
break;
|
|
659
|
-
}
|
|
660
|
-
case 'startSignalGenerator': {
|
|
661
|
-
exitOnMessageReceived(messageId, 2147483647, MotionMasterMessage.Status.SignalGenerator.Success.Code.DONE);
|
|
662
|
-
|
|
663
|
-
motionMasterClient.requestStartSignalGenerator(deviceAddress, messageId);
|
|
664
|
-
|
|
665
|
-
break;
|
|
666
|
-
}
|
|
667
|
-
case 'stopSignalGenerator': {
|
|
668
|
-
motionMasterClient.requestStopSignalGenerator(deviceAddress, messageId);
|
|
669
|
-
process.exit(ExitStatus.SUCCESS);
|
|
670
|
-
break;
|
|
671
|
-
}
|
|
672
|
-
case 'startMonitoringDeviceParameterValues': {
|
|
673
|
-
const parameters = args.slice(1).map(paramToIndexSubindex) as MotionMasterMessage.Request.GetDeviceParameterValues.IParameter[];
|
|
674
|
-
validateParameters(parameters);
|
|
675
|
-
const getDeviceParameterValues = { deviceAddress, parameters };
|
|
676
|
-
const topic = args[0];
|
|
677
|
-
|
|
678
|
-
requestStartMonitoringDeviceParameterValues({ getDeviceParameterValues, interval: cmd.interval, topic });
|
|
679
|
-
break;
|
|
680
|
-
}
|
|
681
|
-
case 'stopMonitoringDeviceParameterValues': {
|
|
682
|
-
const startMonitoringRequestId = args[0];
|
|
683
|
-
|
|
684
|
-
motionMasterClient.requestStopMonitoringDeviceParameterValues(startMonitoringRequestId, messageId);
|
|
685
|
-
|
|
686
|
-
process.exit(ExitStatus.SUCCESS);
|
|
687
|
-
break;
|
|
688
|
-
}
|
|
689
|
-
case 'getEthercatNetworkState': {
|
|
690
|
-
exitOnMessageReceived(messageId);
|
|
691
|
-
|
|
692
|
-
motionMasterClient.requestGetEthercatNetworkState(deviceAddress, messageId);
|
|
693
|
-
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
case 'setEthercatNetworkState': {
|
|
697
|
-
exitOnMessageReceived(messageId);
|
|
698
|
-
|
|
699
|
-
const state = parseInt(args[0], 10);
|
|
700
|
-
motionMasterClient.requestSetEthercatNetworkState(deviceAddress, state, messageId);
|
|
701
|
-
|
|
702
|
-
break;
|
|
703
|
-
}
|
|
704
|
-
case 'startNarrowAngleCalibration': {
|
|
705
|
-
exitOnMessageReceived(messageId, 180000, MotionMasterMessage.Status.NarrowAngleCalibration.Success.Code.DONE);
|
|
706
|
-
|
|
707
|
-
motionMasterClient.requestStartNarrowAngleCalibration(deviceAddress);
|
|
708
|
-
|
|
709
|
-
break;
|
|
710
|
-
}
|
|
711
|
-
case 'setSystemClientTimeout': {
|
|
712
|
-
const timeoutMs = parseInt(args[0], 10);
|
|
713
|
-
motionMasterClient.requestSetSystemClientTimeout(timeoutMs, messageId);
|
|
714
|
-
|
|
715
|
-
process.exit(ExitStatus.SUCCESS);
|
|
716
|
-
break;
|
|
717
|
-
}
|
|
718
|
-
case 'getCirculoEncoderMagnetDistance': {
|
|
719
|
-
exitOnMessageReceived(messageId);
|
|
720
|
-
|
|
721
|
-
const encoderOrdinal = parseInt(args[0], 10);
|
|
722
|
-
const ringRevision = parseInt(args[1], 10);
|
|
723
|
-
motionMasterClient.requestGetCirculoEncoderMagnetDistance(deviceAddress, encoderOrdinal, ringRevision, messageId);
|
|
724
|
-
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
case 'startCirculoEncoderNarrowAngleCalibrationProcedure': {
|
|
728
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.CirculoEncoderNarrowAngleCalibrationProcedure.Success.Code.DONE);
|
|
729
|
-
|
|
730
|
-
const encoderOrdinal = parseInt(args[0], 10);
|
|
731
|
-
motionMasterClient.requestStartCirculoEncoderNarrowAngleCalibrationProcedure(deviceAddress, encoderOrdinal, messageId);
|
|
732
|
-
|
|
733
|
-
break;
|
|
734
|
-
}
|
|
735
|
-
case 'getDeviceCia402State': {
|
|
736
|
-
exitOnMessageReceived(messageId);
|
|
737
|
-
|
|
738
|
-
motionMasterClient.requestGetDeviceCia402State(deviceAddress, messageId);
|
|
739
|
-
|
|
740
|
-
break;
|
|
741
|
-
}
|
|
742
|
-
case 'setDeviceCia402State': {
|
|
743
|
-
exitOnMessageReceived(messageId);
|
|
744
|
-
|
|
745
|
-
const state = parseInt(args[0], 10);
|
|
746
|
-
motionMasterClient.requestSetDeviceCia402State(deviceAddress, state, messageId);
|
|
747
|
-
|
|
748
|
-
break;
|
|
749
|
-
}
|
|
750
|
-
case 'getSystemLog': {
|
|
751
|
-
exitOnMessageReceived(messageId);
|
|
752
|
-
|
|
753
|
-
motionMasterClient.requestGetSystemLog(messageId);
|
|
754
|
-
|
|
755
|
-
break;
|
|
756
|
-
}
|
|
757
|
-
case 'startDeviceSiiRestore': {
|
|
758
|
-
exitOnMessageReceived(messageId, 120000, MotionMasterMessage.Status.DeviceSiiRestore.Success.Code.DONE);
|
|
759
|
-
|
|
760
|
-
const devicePosition = parseInt(args[0], 10);
|
|
761
|
-
|
|
762
|
-
const filepath = args[1];
|
|
763
|
-
const firmwarePackageContent = fs.readFileSync(filepath);
|
|
764
|
-
|
|
765
|
-
motionMasterClient.requestStartDeviceSiiRestore(devicePosition, firmwarePackageContent, messageId);
|
|
766
|
-
|
|
767
|
-
break;
|
|
768
|
-
}
|
|
769
|
-
case 'startOpenLoopFieldControl': {
|
|
770
|
-
exitOnMessageReceived(messageId, 2147483647, MotionMasterMessage.Status.OpenLoopFieldControl.Success.Code.DONE);
|
|
771
|
-
|
|
772
|
-
const properties: MotionMasterMessage.Request.IStartOpenLoopFieldControl = {
|
|
773
|
-
deviceAddress,
|
|
774
|
-
angle: parseInt(args[0], 10),
|
|
775
|
-
velocity: parseInt(args[1], 10),
|
|
776
|
-
acceleration: parseInt(args[2], 10),
|
|
777
|
-
torque: parseInt(args[3], 10),
|
|
778
|
-
torqueSpeed: parseInt(args[4], 10),
|
|
779
|
-
};
|
|
780
|
-
|
|
781
|
-
motionMasterClient.requestStartOpenLoopFieldControl(properties, messageId);
|
|
782
|
-
|
|
783
|
-
break;
|
|
784
|
-
}
|
|
785
|
-
case 'computeFullAutoTuningGains': {
|
|
786
|
-
const tuningType = parseInt(args[0], 10); // POSITION (0), VELOCITY (1)
|
|
787
|
-
const controllerType = args[1] // UNSPECIFIED (0), PI_P (1), P_PI (2)
|
|
788
|
-
? parseInt(args[1], 10)
|
|
789
|
-
: MotionMasterMessage.Request.ComputeFullAutoTuningGains.ControllerType.UNSPECIFIED;
|
|
790
|
-
|
|
791
|
-
switch (tuningType) {
|
|
792
|
-
case 0: {
|
|
793
|
-
exitOnMessageReceived(messageId, 10000, MotionMasterMessage.Status.FullAutoTuning.Success.Code.POSITION_DONE);
|
|
794
|
-
|
|
795
|
-
motionMasterClient.requestComputeFullAutoTuningGains(deviceAddress, tuningType, controllerType, messageId);
|
|
796
|
-
|
|
797
|
-
break;
|
|
798
|
-
}
|
|
799
|
-
case 1: {
|
|
800
|
-
exitOnMessageReceived(messageId, 10000, MotionMasterMessage.Status.FullAutoTuning.Success.Code.VELOCITY_DONE);
|
|
801
|
-
|
|
802
|
-
motionMasterClient.requestComputeFullAutoTuningGains(deviceAddress, tuningType, controllerType, messageId);
|
|
803
|
-
|
|
804
|
-
break;
|
|
805
|
-
}
|
|
806
|
-
default: {
|
|
807
|
-
throw new Error(`Unknown compute auto-tuning gains type: ${tuningType}`);
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
break;
|
|
811
|
-
}
|
|
812
|
-
case 'startFullAutoTuning': {
|
|
813
|
-
const tuningType = parseInt(args[0], 10); // POSITION (0), VELOCITY (1)
|
|
814
|
-
const controllerType = args[1] // UNSPECIFIED (0), PI_P (1), P_PI (2)
|
|
815
|
-
? parseInt(args[1], 10)
|
|
816
|
-
: MotionMasterMessage.Request.StartFullAutoTuning.ControllerType.UNSPECIFIED;
|
|
817
|
-
|
|
818
|
-
switch (tuningType) {
|
|
819
|
-
case 0: {
|
|
820
|
-
exitOnMessageReceived(messageId, 10000, MotionMasterMessage.Status.FullAutoTuning.Success.Code.POSITION_DONE);
|
|
821
|
-
|
|
822
|
-
motionMasterClient.requestStartFullAutoTuning(deviceAddress, tuningType, controllerType, messageId);
|
|
823
|
-
|
|
824
|
-
break;
|
|
825
|
-
}
|
|
826
|
-
case 1: {
|
|
827
|
-
exitOnMessageReceived(messageId, 10000, MotionMasterMessage.Status.FullAutoTuning.Success.Code.VELOCITY_DONE);
|
|
828
|
-
|
|
829
|
-
motionMasterClient.requestStartFullAutoTuning(deviceAddress, tuningType, controllerType, messageId);
|
|
830
|
-
|
|
831
|
-
break;
|
|
832
|
-
}
|
|
833
|
-
default: {
|
|
834
|
-
throw new Error(`Unknown start auto-tuning type: ${tuningType}`);
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
break;
|
|
838
|
-
}
|
|
839
|
-
case 'stopFullAutoTuning': {
|
|
840
|
-
motionMasterClient.requestStopFullAutoTuning(deviceAddress, messageId);
|
|
841
|
-
|
|
842
|
-
break;
|
|
843
|
-
}
|
|
844
|
-
case 'startCirculoEncoderConfiguration': {
|
|
845
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.CirculoEncoderConfiguration.Success.Code.DONE);
|
|
846
|
-
|
|
847
|
-
const encoderOrdinal = parseInt(args[0], 10);
|
|
848
|
-
|
|
849
|
-
motionMasterClient.requestStartCirculoEncoderConfiguration(deviceAddress, encoderOrdinal, messageId);
|
|
850
|
-
|
|
851
|
-
break;
|
|
852
|
-
}
|
|
853
|
-
case 'startOsCommand': {
|
|
854
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.OsCommand.Success.Code.DONE);
|
|
855
|
-
|
|
856
|
-
const timeoutMs = parseInt(args[0], 10);
|
|
857
|
-
|
|
858
|
-
const filepath = args[1];
|
|
859
|
-
const command = fs.readFileSync(filepath);
|
|
860
|
-
|
|
861
|
-
motionMasterClient.requestStartOsCommand(deviceAddress, timeoutMs, command, messageId);
|
|
862
|
-
|
|
863
|
-
break;
|
|
864
|
-
}
|
|
865
|
-
default: {
|
|
866
|
-
throw new Error(`Request "${type}" doesn\'t exist`);
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
async function uploadAction(params: string[], cmd: Command) {
|
|
872
|
-
connectToMotionMaster(cmd.parent);
|
|
873
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
874
|
-
const sendProgress = cmd.sendProgress;
|
|
875
|
-
|
|
876
|
-
const messageId = v4();
|
|
877
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
878
|
-
exitOnMessageReceived(messageId);
|
|
879
|
-
|
|
880
|
-
const parameters: MotionMasterMessage.Request.GetDeviceParameterValues.IParameter[] = params.map(paramToIndexSubindex);
|
|
881
|
-
validateParameters(parameters);
|
|
882
|
-
const getDeviceParameterValues: MotionMasterMessage.Request.IGetDeviceParameterValues = { deviceAddress, parameters, sendProgress };
|
|
883
|
-
|
|
884
|
-
motionMasterClient.sendRequest({ getDeviceParameterValues }, messageId);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
async function downloadAction(paramValues: string[], cmd: Command) {
|
|
888
|
-
connectToMotionMaster(cmd.parent);
|
|
889
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
890
|
-
|
|
891
|
-
const messageId = v4();
|
|
892
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
893
|
-
exitOnMessageReceived(messageId);
|
|
894
|
-
|
|
895
|
-
const deviceParameterInfo = await getDeviceParameterInfoAsync(deviceAddress);
|
|
896
|
-
const parameterValues = paramValues.map((paramValue) => paramToIndexSubIndexValue(paramValue, deviceParameterInfo));
|
|
897
|
-
const setDeviceParameterValues: MotionMasterMessage.Request.ISetDeviceParameterValues = { deviceAddress, parameterValues };
|
|
898
|
-
|
|
899
|
-
motionMasterClient.sendRequest({ setDeviceParameterValues }, messageId);
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
async function getDeviceFileContentAction(name: string, cmd: Command) {
|
|
903
|
-
connectToMotionMaster(cmd.parent);
|
|
904
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
905
|
-
|
|
906
|
-
const messageId = v4();
|
|
907
|
-
|
|
908
|
-
motionMasterClient.selectMessage(messageId).pipe(
|
|
909
|
-
first(),
|
|
910
|
-
).subscribe((message) => {
|
|
911
|
-
if (message && message.status && message.status.deviceFile) {
|
|
912
|
-
const error = message.status.deviceFile.error;
|
|
913
|
-
if (error) {
|
|
914
|
-
throw new Error(`${error.code}: ${error.message}`);
|
|
915
|
-
} else {
|
|
916
|
-
const content = message.status.deviceFile.content;
|
|
917
|
-
if (content) {
|
|
918
|
-
const contentDecoded = new StringDecoder('utf-8').write(Buffer.from(content));
|
|
919
|
-
console.log(contentDecoded);
|
|
920
|
-
process.exit(ExitStatus.SUCCESS);
|
|
921
|
-
} else {
|
|
922
|
-
throw new Error('Device file content is empty');
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
} else {
|
|
926
|
-
throw new Error('The received message is not "deviceFile"');
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
const getDeviceFile: MotionMasterMessage.Request.IGetDeviceFile = { deviceAddress, name };
|
|
931
|
-
|
|
932
|
-
motionMasterClient.sendRequest({ getDeviceFile }, messageId);
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
async function getDeviceLogContentAction(cmd: Command) {
|
|
936
|
-
connectToMotionMaster(cmd.parent);
|
|
937
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
938
|
-
|
|
939
|
-
const messageId = v4();
|
|
940
|
-
|
|
941
|
-
motionMasterClient.selectMessage(messageId).pipe(
|
|
942
|
-
first(),
|
|
943
|
-
).subscribe((message) => {
|
|
944
|
-
if (message && message.status && message.status.deviceLog) {
|
|
945
|
-
const error = message.status.deviceLog.error;
|
|
946
|
-
if (error) {
|
|
947
|
-
throw new Error(`${error.code}: ${error.message}`);
|
|
948
|
-
} else {
|
|
949
|
-
const content = message.status.deviceLog.content;
|
|
950
|
-
if (content) {
|
|
951
|
-
const contentDecoded = new StringDecoder('utf-8').write(Buffer.from(content));
|
|
952
|
-
console.log(contentDecoded);
|
|
953
|
-
process.exit(ExitStatus.SUCCESS);
|
|
954
|
-
} else {
|
|
955
|
-
throw new Error('Device log content is empty');
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
} else {
|
|
959
|
-
throw new Error('The received message is not "deviceLog"');
|
|
960
|
-
}
|
|
961
|
-
});
|
|
962
|
-
|
|
963
|
-
const getDeviceLog: MotionMasterMessage.Request.IGetDeviceLog = { deviceAddress };
|
|
964
|
-
|
|
965
|
-
motionMasterClient.sendRequest({ getDeviceLog }, messageId);
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
async function getCoggingTorqueDataContent(cmd: Command) {
|
|
969
|
-
connectToMotionMaster(cmd.parent);
|
|
970
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
971
|
-
|
|
972
|
-
const messageId = v4();
|
|
973
|
-
|
|
974
|
-
motionMasterClient.selectMessage(messageId).pipe(
|
|
975
|
-
first(),
|
|
976
|
-
).subscribe((message) => {
|
|
977
|
-
if (message && message.status && message.status.coggingTorqueData) {
|
|
978
|
-
const error = message.status.coggingTorqueData.error;
|
|
979
|
-
if (error) {
|
|
980
|
-
throw new Error(`${error.code}: ${error.message}`);
|
|
981
|
-
} else {
|
|
982
|
-
const table = message.status.coggingTorqueData.table;
|
|
983
|
-
if (table && table.data) {
|
|
984
|
-
console.log(table.data.join(', '));
|
|
985
|
-
process.exit(ExitStatus.SUCCESS);
|
|
986
|
-
} else {
|
|
987
|
-
throw new Error('Cogging torque table content data is empty');
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
} else {
|
|
991
|
-
throw new Error('The received message is not "coggingTorqueData"');
|
|
992
|
-
}
|
|
993
|
-
});
|
|
994
|
-
|
|
995
|
-
const getCoggingTorqueData: MotionMasterMessage.Request.IGetCoggingTorqueData = { deviceAddress };
|
|
996
|
-
|
|
997
|
-
motionMasterClient.sendRequest({ getCoggingTorqueData }, messageId);
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
async function startOffsetDetectionAction(cmd: Command) {
|
|
1001
|
-
connectToMotionMaster(cmd.parent);
|
|
1002
|
-
|
|
1003
|
-
const messageId = v4();
|
|
1004
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
1005
|
-
exitOnMessageReceived(messageId, 180000, MotionMasterMessage.Status.OffsetDetection.Success.Code.DONE);
|
|
1006
|
-
|
|
1007
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
1008
|
-
const startOffsetDetection: MotionMasterMessage.Request.IStartOffsetDetection = { deviceAddress };
|
|
1009
|
-
|
|
1010
|
-
motionMasterClient.sendRequest({ startOffsetDetection }, messageId);
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
async function startCoggingTorqueRecordingAction(cmd: Command) {
|
|
1014
|
-
connectToMotionMaster(cmd.parent);
|
|
1015
|
-
|
|
1016
|
-
const messageId = v4();
|
|
1017
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
1018
|
-
exitOnMessageReceived(messageId, 300000, MotionMasterMessage.Status.CoggingTorqueRecording.Success.Code.DONE);
|
|
1019
|
-
|
|
1020
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
1021
|
-
const skipAutoTuning = cmd.skipAutoTuning;
|
|
1022
|
-
const startCoggingTorqueRecording: MotionMasterMessage.Request.IStartCoggingTorqueRecording = { deviceAddress, skipAutoTuning };
|
|
1023
|
-
|
|
1024
|
-
motionMasterClient.sendRequest({ startCoggingTorqueRecording }, messageId);
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
async function startPlantIdentificationAction(
|
|
1028
|
-
durationSeconds: any,
|
|
1029
|
-
torqueAmplitude: any,
|
|
1030
|
-
startFrequency: any,
|
|
1031
|
-
endFrequency: any,
|
|
1032
|
-
cutoffFrequency: any,
|
|
1033
|
-
cmd: Command,
|
|
1034
|
-
) {
|
|
1035
|
-
connectToMotionMaster(cmd.parent);
|
|
1036
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
1037
|
-
|
|
1038
|
-
const messageId = v4();
|
|
1039
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
1040
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.PlantIdentification.Success.Code.DONE);
|
|
1041
|
-
|
|
1042
|
-
durationSeconds = parseFloat(durationSeconds);
|
|
1043
|
-
torqueAmplitude = parseInt(torqueAmplitude, 10);
|
|
1044
|
-
startFrequency = parseInt(startFrequency, 10);
|
|
1045
|
-
endFrequency = parseInt(endFrequency, 10);
|
|
1046
|
-
cutoffFrequency = parseInt(cutoffFrequency, 10);
|
|
1047
|
-
|
|
1048
|
-
const startPlantIdentification: MotionMasterMessage.Request.IStartPlantIdentification = {
|
|
1049
|
-
deviceAddress,
|
|
1050
|
-
durationSeconds,
|
|
1051
|
-
torqueAmplitude,
|
|
1052
|
-
startFrequency,
|
|
1053
|
-
endFrequency,
|
|
1054
|
-
cutoffFrequency,
|
|
1055
|
-
};
|
|
1056
|
-
|
|
1057
|
-
motionMasterClient.sendRequest({ startPlantIdentification }, messageId);
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
async function startSystemIdentificationAction(
|
|
1061
|
-
durationSeconds: any,
|
|
1062
|
-
torqueAmplitude: any,
|
|
1063
|
-
startFrequency: any,
|
|
1064
|
-
endFrequency: any,
|
|
1065
|
-
cmd: Command,
|
|
1066
|
-
) {
|
|
1067
|
-
connectToMotionMaster(cmd.parent);
|
|
1068
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
1069
|
-
|
|
1070
|
-
const messageId = v4();
|
|
1071
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
1072
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.SystemIdentification.Success.Code.DONE);
|
|
1073
|
-
|
|
1074
|
-
durationSeconds = parseFloat(durationSeconds);
|
|
1075
|
-
torqueAmplitude = parseInt(torqueAmplitude, 10);
|
|
1076
|
-
startFrequency = parseFloat(startFrequency);
|
|
1077
|
-
endFrequency = parseFloat(endFrequency);
|
|
1078
|
-
|
|
1079
|
-
const startSystemIdentification: MotionMasterMessage.Request.IStartSystemIdentification = {
|
|
1080
|
-
deviceAddress,
|
|
1081
|
-
durationSeconds,
|
|
1082
|
-
torqueAmplitude,
|
|
1083
|
-
startFrequency,
|
|
1084
|
-
endFrequency,
|
|
1085
|
-
};
|
|
1086
|
-
|
|
1087
|
-
motionMasterClient.sendRequest({ startSystemIdentification }, messageId);
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
async function startCirculoEncoderNarrowAngleCalibrationProcedureAction(
|
|
1091
|
-
encoderOrdinal: any,
|
|
1092
|
-
cmd: Command,
|
|
1093
|
-
) {
|
|
1094
|
-
connectToMotionMaster(cmd.parent);
|
|
1095
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
1096
|
-
|
|
1097
|
-
const messageId = v4();
|
|
1098
|
-
printOnMessageReceived(messageId, cmd.parent.outputFormat as OutputFormat);
|
|
1099
|
-
exitOnMessageReceived(messageId, 60000, MotionMasterMessage.Status.CirculoEncoderNarrowAngleCalibrationProcedure.Success.Code.DONE);
|
|
1100
|
-
|
|
1101
|
-
encoderOrdinal = parseInt(encoderOrdinal, 10);
|
|
1102
|
-
|
|
1103
|
-
const startCirculoEncoderNarrowAngleCalibrationProcedure: MotionMasterMessage.Request.IStartCirculoEncoderNarrowAngleCalibrationProcedure = {
|
|
1104
|
-
deviceAddress,
|
|
1105
|
-
encoderOrdinal,
|
|
1106
|
-
};
|
|
1107
|
-
|
|
1108
|
-
motionMasterClient.sendRequest({ startCirculoEncoderNarrowAngleCalibrationProcedure }, messageId);
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
async function monitorAction(topic: string, params: string[], cmd: Command) {
|
|
1112
|
-
connectToMotionMaster(cmd.parent);
|
|
1113
|
-
const deviceAddress = await getCommandDeviceAddressAsync(cmd.parent);
|
|
1114
|
-
|
|
1115
|
-
const parameters = params.map(paramToIndexSubindex);
|
|
1116
|
-
const getDeviceParameterValues = { deviceAddress, parameters };
|
|
1117
|
-
|
|
1118
|
-
requestStartMonitoringDeviceParameterValues({ getDeviceParameterValues, interval: cmd.interval, topic });
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
//
|
|
1122
|
-
// helper functions
|
|
1123
|
-
//
|
|
1124
|
-
|
|
1125
|
-
function connectToMotionMaster(cmd: Command) {
|
|
1126
|
-
|
|
1127
|
-
if (cmd.config) {
|
|
1128
|
-
const contents = fs.readFileSync(cmd.config, { encoding: 'utf8' });
|
|
1129
|
-
const json = JSON.parse(contents);
|
|
1130
|
-
Object.assign(config, json);
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
// ping Motion Master in regular intervals
|
|
1134
|
-
const pingSystemInterval = interval(config.pingSystemInterval);
|
|
1135
|
-
pingSystemInterval.subscribe(() => motionMasterClient.sendRequest({ pingSystem: {} }));
|
|
1136
|
-
|
|
1137
|
-
// connect to server endpoint
|
|
1138
|
-
const serverSocket = zmq.socket('dealer');
|
|
1139
|
-
debug(`Using identity for ZeroMQ DEALER socket: ${config.identity}`);
|
|
1140
|
-
serverSocket.identity = config.identity;
|
|
1141
|
-
serverSocket.connect(config.serverEndpoint);
|
|
1142
|
-
debug(`Connected to ZeroMQ DEALER socket server endpoint: ${config.serverEndpoint}`);
|
|
1143
|
-
|
|
1144
|
-
// feed data coming from Motion Master to MotionMasterClient
|
|
1145
|
-
serverSocket.on('message', (data) => {
|
|
1146
|
-
motionMasterClient.input$.next(decodeMotionMasterMessage(data));
|
|
1147
|
-
});
|
|
1148
|
-
|
|
1149
|
-
// send data fed from MotionMasterClient to Motion Master
|
|
1150
|
-
motionMasterClient.output$.subscribe((message) => {
|
|
1151
|
-
// log outgoing messages and skip ping messages
|
|
1152
|
-
if (!(message && message.request && message.request.pingSystem)) {
|
|
1153
|
-
debug(
|
|
1154
|
-
util.inspect(message, inspectOptions),
|
|
1155
|
-
);
|
|
1156
|
-
}
|
|
1157
|
-
serverSocket.send(Buffer.from(encodeMotionMasterMessage(message)));
|
|
1158
|
-
});
|
|
1159
|
-
|
|
1160
|
-
// connnect to notification endpoint
|
|
1161
|
-
const notificationSocket = zmq.socket('sub').connect(config.notificationEndpoint);
|
|
1162
|
-
debug(`Connected to ZeroMQ SUB socket notification endpoint: ${config.notificationEndpoint}`);
|
|
1163
|
-
|
|
1164
|
-
// subscribe to all topics
|
|
1165
|
-
notificationSocket.subscribe('');
|
|
1166
|
-
|
|
1167
|
-
// exit process when a heartbeat message is not received for more than the time specified
|
|
1168
|
-
motionMasterClient.selectMessageStatus('systemPong').pipe(
|
|
1169
|
-
timeout(config.motionMasterHeartbeatTimeoutDue),
|
|
1170
|
-
).subscribe({
|
|
1171
|
-
error: (err) => {
|
|
1172
|
-
console.error(`${err.name}: Heartbeat message not received for more than ${config.motionMasterHeartbeatTimeoutDue} ms. Check if Motion Master process is running.`);
|
|
1173
|
-
process.exit(ExitStatus.TIMEOUT);
|
|
1174
|
-
},
|
|
1175
|
-
});
|
|
1176
|
-
|
|
1177
|
-
// feed notification data coming from Motion Master to MotionMasterNotification
|
|
1178
|
-
notificationSocket.on('message', (topic: Uint8Array, message: Uint8Array) => {
|
|
1179
|
-
motionMasterNotification.input$.next({ topic: topic.toString(), messages: [decodeMotionMasterMessage(message)] });
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
function requestStartMonitoringDeviceParameterValues(startMonitoringDeviceParameterValues: MotionMasterMessage.Request.IStartMonitoringDeviceParameterValues) {
|
|
1184
|
-
const messageId = v4();
|
|
1185
|
-
|
|
1186
|
-
motionMasterNotification.selectMessagesByTopic(startMonitoringDeviceParameterValues.topic || '').subscribe((messages) => {
|
|
1187
|
-
const timestamp = Date.now();
|
|
1188
|
-
const topic = startMonitoringDeviceParameterValues.topic;
|
|
1189
|
-
console.log(
|
|
1190
|
-
util.inspect({ timestamp, topic, messages }, inspectOptions),
|
|
1191
|
-
);
|
|
1192
|
-
});
|
|
1193
|
-
|
|
1194
|
-
motionMasterClient.sendRequest({ startMonitoringDeviceParameterValues }, messageId);
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
async function getDeviceParameterInfoAsync(deviceAddress: DeviceAddressType) {
|
|
1198
|
-
if (!deviceAddress) {
|
|
1199
|
-
return null;
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
if (deviceParameterInfoMap.has(deviceAddress)) {
|
|
1203
|
-
return deviceParameterInfoMap.get(deviceAddress); // retrieve from cache
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
const getDeviceParameterInfo = { deviceAddress };
|
|
1207
|
-
const messageId = v4();
|
|
1208
|
-
motionMasterClient.sendRequest({ getDeviceParameterInfo }, messageId);
|
|
1209
|
-
|
|
1210
|
-
const deviceParameterInfo = await motionMasterClient.selectMessage(messageId).pipe(
|
|
1211
|
-
first(),
|
|
1212
|
-
map((message) => message && message.status ? message.status.deviceParameterInfo : null),
|
|
1213
|
-
).toPromise();
|
|
1214
|
-
|
|
1215
|
-
deviceParameterInfoMap.set(deviceAddress, deviceParameterInfo); // cache
|
|
1216
|
-
|
|
1217
|
-
return deviceParameterInfo;
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
function paramToIndexSubindex(paramValue: string) {
|
|
1221
|
-
const [indexStr, subindexStr] = paramValue.split(':');
|
|
1222
|
-
const index = parseInt(indexStr, 16);
|
|
1223
|
-
const subindex = parseInt(subindexStr, 10) || 0;
|
|
1224
|
-
return { index, subindex };
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
function paramToIndexSubIndexValue(paramValue: string, deviceParameterInfo: MotionMasterMessage.Status.IDeviceParameterInfo | null | undefined) {
|
|
1228
|
-
const [param, value] = paramValue.split('=');
|
|
1229
|
-
const { index, subindex } = paramToIndexSubindex(param);
|
|
1230
|
-
|
|
1231
|
-
const parameterValue: MotionMasterMessage.Status.DeviceParameterValues.IParameterValue = { index, subindex };
|
|
1232
|
-
|
|
1233
|
-
if (deviceParameterInfo) {
|
|
1234
|
-
if (deviceParameterInfo.parameters) {
|
|
1235
|
-
const parameter = deviceParameterInfo.parameters.find((p) => p.index === index && p.subindex === subindex);
|
|
1236
|
-
if (parameter) {
|
|
1237
|
-
const VT = MotionMasterMessage.Status.DeviceParameterInfo.Parameter.ValueType;
|
|
1238
|
-
switch (parameter.valueType) {
|
|
1239
|
-
case VT.UNSPECIFIED:
|
|
1240
|
-
case VT.INTEGER8:
|
|
1241
|
-
case VT.INTEGER16:
|
|
1242
|
-
case VT.INTEGER32: {
|
|
1243
|
-
parameterValue.intValue = parseInt(value, 10);
|
|
1244
|
-
break;
|
|
1245
|
-
}
|
|
1246
|
-
case VT.BOOLEAN:
|
|
1247
|
-
case VT.UNSIGNED8:
|
|
1248
|
-
case VT.UNSIGNED16:
|
|
1249
|
-
case VT.UNSIGNED32: {
|
|
1250
|
-
parameterValue.uintValue = parseInt(value, 10);
|
|
1251
|
-
break;
|
|
1252
|
-
}
|
|
1253
|
-
case VT.REAL32: {
|
|
1254
|
-
parameterValue.floatValue = parseFloat(value);
|
|
1255
|
-
break;
|
|
1256
|
-
}
|
|
1257
|
-
case VT.VISIBLE_STRING:
|
|
1258
|
-
case VT.OCTET_STRING:
|
|
1259
|
-
case VT.UNICODE_STRING:
|
|
1260
|
-
case VT.TIME_OF_DAY: {
|
|
1261
|
-
parameterValue.stringValue = value;
|
|
1262
|
-
break;
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
return parameterValue;
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
function validateParameters(parameters: MotionMasterMessage.Request.GetDeviceParameterValues.IParameter[]) {
|
|
1273
|
-
let error = null;
|
|
1274
|
-
|
|
1275
|
-
if (parameters.some((p) => p.index === 0)) {
|
|
1276
|
-
error = new Error('Parameter with index 0 is requested.');
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
if (parameters.some((p) => isNaN(p.index as number) || isNaN(p.subindex as number))) {
|
|
1280
|
-
error = new Error('Parameter with unparsable index or subindex is requested.');
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
if (error) {
|
|
1284
|
-
error.message += '\nExample of correct formats: "0x2002 0x100A:0 0x2003:4".';
|
|
1285
|
-
console.error(`${error.name}: ${error.message}`);
|
|
1286
|
-
console.error(util.inspect(parameters, inspectOptions));
|
|
1287
|
-
process.exit(ExitStatus.INCORRECT_PARAMETER_FORMAT);
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
async function getCommandDeviceAddressAsync(cmd: Command): Promise<DeviceAddressType | null> {
|
|
1292
|
-
if (cmd.deviceAddress) {
|
|
1293
|
-
return cmd.deviceAddress;
|
|
1294
|
-
} else if (Number.isInteger(cmd.devicePosition)) {
|
|
1295
|
-
const device = await motionMasterClient.selectDeviceAtPosition(cmd.devicePosition).toPromise();
|
|
1296
|
-
if (device) {
|
|
1297
|
-
return device.deviceAddress;
|
|
1298
|
-
} else {
|
|
1299
|
-
console.warn(`WARNING: Cannot get device at position ${cmd.devicePosition} or device list is empty.`);
|
|
1300
|
-
return null;
|
|
1301
|
-
}
|
|
1302
|
-
} else {
|
|
1303
|
-
return null;
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
function exitOnMessageReceived(messageId: string, due = 10000, exitOnSuccessCode?: number) {
|
|
1308
|
-
motionMasterClient.selectMessage(messageId).pipe(
|
|
1309
|
-
first((message) => {
|
|
1310
|
-
if (exitOnSuccessCode === undefined) {
|
|
1311
|
-
return true;
|
|
1312
|
-
} else {
|
|
1313
|
-
if (message && message.status) {
|
|
1314
|
-
const key = Object.keys(message.status)[0] as StatusType;
|
|
1315
|
-
const status = message.status[key] as { success: any, error: any };
|
|
1316
|
-
if (status && ((status.success && status.success.code === exitOnSuccessCode) || status.error)) {
|
|
1317
|
-
return true;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
return false;
|
|
1321
|
-
}
|
|
1322
|
-
}),
|
|
1323
|
-
timeout(due),
|
|
1324
|
-
).subscribe({
|
|
1325
|
-
next: () => {
|
|
1326
|
-
debug(`Exit on message received ${messageId}`);
|
|
1327
|
-
process.exit(ExitStatus.SUCCESS);
|
|
1328
|
-
},
|
|
1329
|
-
error: (err) => {
|
|
1330
|
-
console.error(`${err.name}: Status message ${messageId} not received for more than ${due} ms.`);
|
|
1331
|
-
process.exit(ExitStatus.TIMEOUT);
|
|
1332
|
-
},
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
function printOnMessageReceived(messageId: string, outputFormat: OutputFormat = 'inspect') {
|
|
1337
|
-
motionMasterClient.selectMessage(messageId).subscribe((message) => {
|
|
1338
|
-
const timestamp = Date.now();
|
|
1339
|
-
const outputObj = { timestamp, message };
|
|
1340
|
-
|
|
1341
|
-
switch (outputFormat) {
|
|
1342
|
-
case 'json': {
|
|
1343
|
-
console.log(JSON.stringify(outputObj));
|
|
1344
|
-
break;
|
|
1345
|
-
}
|
|
1346
|
-
case 'yaml': {
|
|
1347
|
-
console.log(YAML.stringify(outputObj));
|
|
1348
|
-
break;
|
|
1349
|
-
}
|
|
1350
|
-
default: {
|
|
1351
|
-
console.log(
|
|
1352
|
-
util.inspect(outputObj, inspectOptions),
|
|
1353
|
-
);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
});
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
function parseOptionValueAsInt(value: string) {
|
|
1360
|
-
return parseInt(value, 10);
|
|
1361
|
-
}
|