motion-master-client 0.0.245 → 0.0.247

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.
Files changed (104) hide show
  1. package/README.md +24 -18
  2. package/package.json +1 -1
  3. package/src/api.js +21 -5
  4. package/src/api.js.map +1 -1
  5. package/src/cli.js +47 -19
  6. package/src/cli.js.map +1 -1
  7. package/src/lib/cia402.js +11 -36
  8. package/src/lib/cia402.js.map +1 -1
  9. package/src/lib/config-file.js +4 -2
  10. package/src/lib/config-file.js.map +1 -1
  11. package/src/lib/data-monitoring.d.ts +4 -4
  12. package/src/lib/data-monitoring.js +8 -6
  13. package/src/lib/data-monitoring.js.map +1 -1
  14. package/src/lib/device-parameter.d.ts +5 -5
  15. package/src/lib/device-parameter.js +10 -44
  16. package/src/lib/device-parameter.js.map +1 -1
  17. package/src/lib/device.d.ts +4 -4
  18. package/src/lib/device.js +9 -7
  19. package/src/lib/device.js.map +1 -1
  20. package/src/lib/encoder.js +4 -1
  21. package/src/lib/encoder.js.map +1 -1
  22. package/src/lib/error-report.d.ts +4 -4
  23. package/src/lib/error-report.js +0 -1
  24. package/src/lib/error-report.js.map +1 -1
  25. package/src/lib/ethercat.js +119 -33
  26. package/src/lib/ethercat.js.map +1 -1
  27. package/src/lib/ethernet.d.ts +3 -3
  28. package/src/lib/ethernet.js +5 -5
  29. package/src/lib/ethernet.js.map +1 -1
  30. package/src/lib/fetch.d.ts +1 -1
  31. package/src/lib/fetch.js +7 -7
  32. package/src/lib/fetch.js.map +1 -1
  33. package/src/lib/firmware.js +3 -1
  34. package/src/lib/firmware.js.map +1 -1
  35. package/src/lib/homing.d.ts +1 -1
  36. package/src/lib/homing.js.map +1 -1
  37. package/src/lib/integro-encoder-calibration.js +11 -4
  38. package/src/lib/integro-encoder-calibration.js.map +1 -1
  39. package/src/lib/integro-variant.js.map +1 -1
  40. package/src/lib/is-online.js +2 -2
  41. package/src/lib/is-online.js.map +1 -1
  42. package/src/lib/logger.js +1 -1
  43. package/src/lib/mmcidb.js.map +1 -1
  44. package/src/lib/monitoring-config.d.ts +1 -1
  45. package/src/lib/monitoring-entry.d.ts +3 -3
  46. package/src/lib/motion-composer.d.ts +4 -4
  47. package/src/lib/motion-composer.js +3 -2
  48. package/src/lib/motion-composer.js.map +1 -1
  49. package/src/lib/motion-master-client.d.ts +10 -10
  50. package/src/lib/motion-master-client.js +15 -10
  51. package/src/lib/motion-master-client.js.map +1 -1
  52. package/src/lib/motion-master-pub-sub-client.d.ts +4 -4
  53. package/src/lib/motion-master-pub-sub-client.js +2 -2
  54. package/src/lib/motion-master-pub-sub-client.js.map +1 -1
  55. package/src/lib/motion-master-pub-sub-socket.d.ts +2 -2
  56. package/src/lib/motion-master-pub-sub-web-socket.d.ts +3 -3
  57. package/src/lib/motion-master-pub-sub-web-socket.js.map +1 -1
  58. package/src/lib/motion-master-pub-sub-worker-socket.d.ts +3 -3
  59. package/src/lib/motion-master-pub-sub-worker-socket.js +1 -1
  60. package/src/lib/motion-master-pub-sub-worker-socket.js.map +1 -1
  61. package/src/lib/motion-master-req-res-client.d.ts +291 -15
  62. package/src/lib/motion-master-req-res-client.js +491 -57
  63. package/src/lib/motion-master-req-res-client.js.map +1 -1
  64. package/src/lib/motion-master-req-res-socket.d.ts +2 -2
  65. package/src/lib/motion-master-req-res-web-socket.d.ts +3 -3
  66. package/src/lib/motion-master-req-res-web-socket.js +2 -2
  67. package/src/lib/motion-master-req-res-web-socket.js.map +1 -1
  68. package/src/lib/motion-master-req-res-worker-socket.d.ts +3 -3
  69. package/src/lib/motion-master-req-res-worker-socket.js.map +1 -1
  70. package/src/lib/online.d.ts +1 -1
  71. package/src/lib/online.js +3 -2
  72. package/src/lib/online.js.map +1 -1
  73. package/src/lib/operators.js.map +1 -1
  74. package/src/lib/options.js +5 -5
  75. package/src/lib/options.js.map +1 -1
  76. package/src/lib/os-command.d.ts +82 -22
  77. package/src/lib/os-command.js +95 -55
  78. package/src/lib/os-command.js.map +1 -1
  79. package/src/lib/parameter.d.ts +1 -1
  80. package/src/lib/parameter.js +6 -4
  81. package/src/lib/parameter.js.map +1 -1
  82. package/src/lib/product-id-range.js +5 -5
  83. package/src/lib/product-id-range.js.map +1 -1
  84. package/src/lib/product.js +256 -34
  85. package/src/lib/product.js.map +1 -1
  86. package/src/lib/request-status-resolver.d.ts +1 -1
  87. package/src/lib/request-status-resolver.js +8 -6
  88. package/src/lib/request-status-resolver.js.map +1 -1
  89. package/src/lib/sii.js +4 -11
  90. package/src/lib/sii.js.map +1 -1
  91. package/src/lib/smm-od-v1.json +1836 -0
  92. package/src/lib/smm.d.ts +63 -0
  93. package/src/lib/smm.js +177 -0
  94. package/src/lib/smm.js.map +1 -0
  95. package/src/lib/types.d.ts +8 -8
  96. package/src/lib/types.js +0 -4
  97. package/src/lib/types.js.map +1 -1
  98. package/src/lib/units.js +11 -23
  99. package/src/lib/units.js.map +1 -1
  100. package/src/lib/util.d.ts +3 -2
  101. package/src/lib/util.js +23 -11
  102. package/src/lib/util.js.map +1 -1
  103. package/src/lib/web-socket-connection-close-codes.js +2 -2
  104. package/src/lib/web-socket-connection-close-codes.js.map +1 -1
@@ -22,6 +22,7 @@ const integro_variant_1 = require("./integro-variant");
22
22
  const config_file_1 = require("./config-file");
23
23
  const product_1 = require("./product");
24
24
  const mmcidb_1 = require("./mmcidb");
25
+ const smm_1 = require("./smm");
25
26
  /**
26
27
  * This class contains methods for making requests to Motion Master using the injected request/response socket.
27
28
  *
@@ -289,9 +290,12 @@ class MotionMasterReqResClient {
289
290
  */
290
291
  getDeviceFile(props, requestTimeout, messageId) {
291
292
  return this.resolveDeviceAddress(props).pipe((0, operators_1.mergeMap)((deviceAddress) => {
292
- // @ts-ignore
293
- if ((props.name === 'SOMANET_CiA_402.xml' || props.name === 'SOMANET_CiA_402.xml.zip') && typeof window !== 'undefined' && window.indexedDB) {
294
- return this.getParameterValue(deviceAddress, 0x100A, 0x00).pipe((0, operators_1.mergeMap)((firmwareVersion) => {
293
+ if ((props.name === 'SOMANET_CiA_402.xml' || props.name === 'SOMANET_CiA_402.xml.zip') &&
294
+ // @ts-ignore
295
+ typeof window !== 'undefined' &&
296
+ // @ts-ignore
297
+ window.indexedDB) {
298
+ return this.getParameterValue(deviceAddress, 0x100a, 0x00).pipe((0, operators_1.mergeMap)((firmwareVersion) => {
295
299
  return (0, rxjs_1.from)(this.mmcidb.open()).pipe((0, operators_1.mergeMap)(() => this.mmcidb.getEsi(firmwareVersion)), (0, operators_1.mergeMap)((data) => {
296
300
  if (data) {
297
301
  const status = {
@@ -1184,7 +1188,7 @@ class MotionMasterReqResClient {
1184
1188
  * @throws errors if the device reference is invalid
1185
1189
  */
1186
1190
  resolveDevice(deviceRef, requestTimeout = 20000) {
1187
- const deviceRefObj = (typeof deviceRef === 'object') ? deviceRef : (0, device_1.makeDeviceRefObj)(deviceRef);
1191
+ const deviceRefObj = typeof deviceRef === 'object' ? deviceRef : (0, device_1.makeDeviceRefObj)(deviceRef);
1188
1192
  if (!(0, device_1.isValidDeviceRefObj)(deviceRefObj)) {
1189
1193
  return (0, rxjs_1.throwError)(() => new Error(`Device ref object is not valid ${JSON.stringify(deviceRefObj)}`));
1190
1194
  }
@@ -1214,7 +1218,7 @@ class MotionMasterReqResClient {
1214
1218
  * Refer to the description of this class for more information.
1215
1219
  */
1216
1220
  resolveDeviceAddress(deviceRef, requestTimeout = 60000) {
1217
- const deviceRefObj = (typeof deviceRef === 'object') ? deviceRef : (0, device_1.makeDeviceRefObj)(deviceRef);
1221
+ const deviceRefObj = typeof deviceRef === 'object' ? deviceRef : (0, device_1.makeDeviceRefObj)(deviceRef);
1218
1222
  // This avoids a circular call to getDevices() from resolveDevice().
1219
1223
  // If a device is referenced by its address, there's no need to resolve it by reading its .hardware_description file to determine the serial number.
1220
1224
  if (deviceRefObj.deviceAddress) {
@@ -1241,9 +1245,7 @@ class MotionMasterReqResClient {
1241
1245
  serialNumber = (0, hardware_description_1.getSerialNumberFromHardwareDescription)(hardwareDescription);
1242
1246
  }
1243
1247
  const id = serialNumber !== null && serialNumber !== void 0 ? serialNumber : (0, hardware_description_1.makeDeviceSerialNumberFromAddress)(device.deviceAddress);
1244
- const stackInfo = hardwareDescription
1245
- ? undefined
1246
- : yield (0, rxjs_1.lastValueFrom)(this.getStackInfo(deviceAddress));
1248
+ const stackInfo = hardwareDescription ? undefined : yield (0, rxjs_1.lastValueFrom)(this.getStackInfo(deviceAddress));
1247
1249
  let integroVariant = undefined;
1248
1250
  try {
1249
1251
  integroVariant = yield (0, rxjs_1.lastValueFrom)(this.getIntegroVariant(deviceAddress));
@@ -1295,7 +1297,8 @@ class MotionMasterReqResClient {
1295
1297
  let requestTimeout = 1000;
1296
1298
  let deviceRefObj;
1297
1299
  let messageId;
1298
- if (typeof b === 'number' && typeof c === 'number') { // index, subindex, e.g. 0x6060, 1
1300
+ if (typeof b === 'number' && typeof c === 'number') {
1301
+ // index, subindex, e.g. 0x6060, 1
1299
1302
  deviceRefObj = (0, device_1.makeDeviceRefObj)(a);
1300
1303
  index = b;
1301
1304
  subindex = c;
@@ -1309,7 +1312,8 @@ class MotionMasterReqResClient {
1309
1312
  messageId = f;
1310
1313
  }
1311
1314
  }
1312
- else if (typeof a === 'string') { // device parameter id, e.g. "0x2110:1A.8502-03-0001353-2115"
1315
+ else if (typeof a === 'string') {
1316
+ // device parameter id, e.g. "0x2110:1A.8502-03-0001353-2115"
1313
1317
  [deviceSerialNumber, index, subindex] = (0, device_parameter_1.splitDeviceParameterId)(a);
1314
1318
  deviceRefObj = (0, device_1.makeDeviceRefObj)(deviceSerialNumber);
1315
1319
  if (typeof b === 'boolean') {
@@ -1335,7 +1339,7 @@ class MotionMasterReqResClient {
1335
1339
  var _a;
1336
1340
  const collection = [];
1337
1341
  for (const [deviceAddress, index, subindex] of tuples) {
1338
- let item = collection.find(c => c.deviceAddress === deviceAddress);
1342
+ let item = collection.find((c) => c.deviceAddress === deviceAddress);
1339
1343
  if (!item) {
1340
1344
  item = { deviceAddress, parameters: [], sendProgress: false };
1341
1345
  collection.push(item);
@@ -1346,7 +1350,8 @@ class MotionMasterReqResClient {
1346
1350
  if (!(multiDeviceParameterValues === null || multiDeviceParameterValues === void 0 ? void 0 : multiDeviceParameterValues.collection)) {
1347
1351
  throw new Error(`Multi device parameter values collection is empty`);
1348
1352
  }
1349
- return multiDeviceParameterValues.collection.map(({ parameterValues, deviceAddress }) => {
1353
+ return multiDeviceParameterValues.collection
1354
+ .map(({ parameterValues, deviceAddress }) => {
1350
1355
  if (!parameterValues) {
1351
1356
  throw new Error(`No parameterValues for device ${deviceAddress}`);
1352
1357
  }
@@ -1358,7 +1363,8 @@ class MotionMasterReqResClient {
1358
1363
  }
1359
1364
  throw new Error(`No type value for parameter ${(0, parameter_1.makeParameterId)(value === null || value === void 0 ? void 0 : value.index, value === null || value === void 0 ? void 0 : value.subindex)}`);
1360
1365
  });
1361
- }).flat();
1366
+ })
1367
+ .flat();
1362
1368
  }));
1363
1369
  }));
1364
1370
  }
@@ -1371,14 +1377,14 @@ class MotionMasterReqResClient {
1371
1377
  }
1372
1378
  let refs;
1373
1379
  if ((0, types_1.isArrayOfDeviceSerialNumbers)(ids)) {
1374
- refs = ids.map(id => (0, device_parameter_1.splitDeviceParameterId)(id));
1380
+ refs = ids.map((id) => (0, device_parameter_1.splitDeviceParameterId)(id));
1375
1381
  }
1376
1382
  else {
1377
1383
  refs = ids;
1378
1384
  }
1379
1385
  return (0, rxjs_1.defer)(() => {
1380
1386
  return (0, rxjs_1.forkJoin)(refs.map(([deviceRef, index, subindex]) => {
1381
- return this.resolveDeviceAddress((0, device_1.makeDeviceRefObj)(deviceRef)).pipe((0, operators_1.map)((deviceAddress) => ([deviceAddress, index, subindex])));
1387
+ return this.resolveDeviceAddress((0, device_1.makeDeviceRefObj)(deviceRef)).pipe((0, operators_1.map)((deviceAddress) => [deviceAddress, index, subindex]));
1382
1388
  }));
1383
1389
  });
1384
1390
  }
@@ -1398,7 +1404,11 @@ class MotionMasterReqResClient {
1398
1404
  createSetParameterValueObservable(deviceRefObj, index, subindex, value, valueTypeKey, requestTimeout = 1000, messageId) {
1399
1405
  return (0, rxjs_1.defer)(() => {
1400
1406
  return this.resolveDeviceParameterTypeValueKey(deviceRefObj, index, subindex, valueTypeKey).pipe((0, operators_1.mergeMap)((valueTypeKey) => {
1401
- const parameterValue = { index, subindex, [valueTypeKey]: value };
1407
+ const parameterValue = {
1408
+ index,
1409
+ subindex,
1410
+ [valueTypeKey]: value,
1411
+ };
1402
1412
  return this.setDeviceParameterValues(Object.assign(Object.assign({}, deviceRefObj), { parameterValues: [parameterValue] }), requestTimeout, messageId).pipe((0, operators_1.map)(({ parameterValues }) => {
1403
1413
  var _a, _b, _c;
1404
1414
  const parameterValue = parameterValues === null || parameterValues === void 0 ? void 0 : parameterValues[0];
@@ -1427,7 +1437,8 @@ class MotionMasterReqResClient {
1427
1437
  let requestTimeout = 1000;
1428
1438
  let deviceRefObj;
1429
1439
  let messageId;
1430
- if (typeof b === 'number' && typeof c === 'number') { // index, subindex, e.g. 0x6060, 1
1440
+ if (typeof b === 'number' && typeof c === 'number') {
1441
+ // index, subindex, e.g. 0x6060, 1
1431
1442
  deviceRefObj = (0, device_1.makeDeviceRefObj)(a);
1432
1443
  index = b;
1433
1444
  subindex = c;
@@ -1440,7 +1451,8 @@ class MotionMasterReqResClient {
1440
1451
  }
1441
1452
  messageId = g;
1442
1453
  }
1443
- else if (typeof a === 'string') { // device parameter id, e.g. "0x2110:1A.8502-03-0001353-2115"
1454
+ else if (typeof a === 'string') {
1455
+ // device parameter id, e.g. "0x2110:1A.8502-03-0001353-2115"
1444
1456
  [deviceSerialNumber, index, subindex] = (0, device_parameter_1.splitDeviceParameterId)(a);
1445
1457
  deviceRefObj = (0, device_1.makeDeviceRefObj)(deviceSerialNumber);
1446
1458
  value = b;
@@ -1466,7 +1478,7 @@ class MotionMasterReqResClient {
1466
1478
  }
1467
1479
  let refs;
1468
1480
  if ((0, types_1.isObjectOfDeviceSerialNumberToValues)(ids)) {
1469
- refs = Object.entries(ids).map(([id, value]) => ([...(0, device_parameter_1.splitDeviceParameterId)(id), value]));
1481
+ refs = Object.entries(ids).map(([id, value]) => [...(0, device_parameter_1.splitDeviceParameterId)(id), value]);
1470
1482
  }
1471
1483
  else {
1472
1484
  refs = ids;
@@ -1475,13 +1487,19 @@ class MotionMasterReqResClient {
1475
1487
  return (0, rxjs_1.forkJoin)(refs.map(([deviceRef, index, subindex, value, typeValueKey]) => {
1476
1488
  const deviceRefObj = (0, device_1.makeDeviceRefObj)(deviceRef);
1477
1489
  return this.resolveDeviceAddress(deviceRefObj).pipe((0, operators_1.mergeMap)((deviceAddress) => {
1478
- return this.resolveDeviceParameterTypeValueKey(deviceRefObj, index, subindex, typeValueKey).pipe((0, operators_1.map)((typeValueKey) => ([deviceAddress, index, subindex, value, typeValueKey])));
1490
+ return this.resolveDeviceParameterTypeValueKey(deviceRefObj, index, subindex, typeValueKey).pipe((0, operators_1.map)((typeValueKey) => [
1491
+ deviceAddress,
1492
+ index,
1493
+ subindex,
1494
+ value,
1495
+ typeValueKey,
1496
+ ]));
1479
1497
  }));
1480
1498
  })).pipe((0, operators_1.mergeMap)((tuples) => {
1481
1499
  var _a;
1482
1500
  const collection = [];
1483
1501
  for (const [deviceAddress, index, subindex, value, typeValueKey] of tuples) {
1484
- let item = collection.find(c => c.deviceAddress === deviceAddress);
1502
+ let item = collection.find((c) => c.deviceAddress === deviceAddress);
1485
1503
  if (!item) {
1486
1504
  item = { deviceAddress, parameterValues: [] };
1487
1505
  collection.push(item);
@@ -1551,11 +1569,18 @@ class MotionMasterReqResClient {
1551
1569
  */
1552
1570
  getDeviceParameters(props, requestTimeout = 30000) {
1553
1571
  return this.resolveDevice(props).pipe((0, operators_1.mergeMap)((device) => {
1554
- return this.getDeviceParameterInfo({ deviceAddress: device.deviceAddress }, requestTimeout).pipe((0, operators_1.mergeMap)(deviceParameterInfoStatus => {
1572
+ return this.getDeviceParameterInfo({ deviceAddress: device.deviceAddress }, requestTimeout).pipe((0, operators_1.mergeMap)((deviceParameterInfoStatus) => {
1555
1573
  var _a;
1556
1574
  const { loadFromCache, sendProgress } = props;
1557
- const parameters = (_a = deviceParameterInfoStatus.parameters) === null || _a === void 0 ? void 0 : _a.map(p => { var _a, _b; return ({ index: (_a = p.index) !== null && _a !== void 0 ? _a : 0, subindex: (_b = p.subindex) !== null && _b !== void 0 ? _b : 0, loadFromCache }); });
1558
- return this.getDeviceParameterValues({ deviceAddress: device.deviceAddress, sendProgress, parameters }, requestTimeout).pipe((0, operators_1.map)(deviceParameterValuesStatus => {
1575
+ const parameters = (_a = deviceParameterInfoStatus.parameters) === null || _a === void 0 ? void 0 : _a.map((p) => {
1576
+ var _a, _b;
1577
+ return ({
1578
+ index: (_a = p.index) !== null && _a !== void 0 ? _a : 0,
1579
+ subindex: (_b = p.subindex) !== null && _b !== void 0 ? _b : 0,
1580
+ loadFromCache,
1581
+ });
1582
+ });
1583
+ return this.getDeviceParameterValues({ deviceAddress: device.deviceAddress, sendProgress, parameters }, requestTimeout).pipe((0, operators_1.map)((deviceParameterValuesStatus) => {
1559
1584
  var _a, _b;
1560
1585
  if (!deviceParameterValuesStatus.parameterValues) {
1561
1586
  throw new Error('Device parameter values is empty');
@@ -1565,7 +1590,8 @@ class MotionMasterReqResClient {
1565
1590
  const index = (_a = value.index) !== null && _a !== void 0 ? _a : 0;
1566
1591
  const subindex = (_b = value.subindex) !== null && _b !== void 0 ? _b : 0;
1567
1592
  const id = (0, device_parameter_1.makeDeviceParameterId)(device.id, index, subindex);
1568
- return (Object.assign(Object.assign(Object.assign({ id }, value), (_c = deviceParameterInfoStatus.parameters) === null || _c === void 0 ? void 0 : _c[i]), { index, subindex, value: (0, parameter_1.getParameterValue)(value) }));
1593
+ return Object.assign(Object.assign(Object.assign({ id }, value), (_c = deviceParameterInfoStatus.parameters) === null || _c === void 0 ? void 0 : _c[i]), { index,
1594
+ subindex, value: (0, parameter_1.getParameterValue)(value) });
1569
1595
  });
1570
1596
  const progress = sendProgress ? (_b = (_a = deviceParameterValuesStatus === null || deviceParameterValuesStatus === void 0 ? void 0 : deviceParameterValuesStatus.progress) === null || _a === void 0 ? void 0 : _a.percentage) !== null && _b !== void 0 ? _b : 0 : 100;
1571
1597
  return { parameters: deviceParameters, progress };
@@ -1682,7 +1708,8 @@ class MotionMasterReqResClient {
1682
1708
  * {@link https://www.synapticon.com/documentation/circulo/sw5.0/device_info/save_restore_config.html}
1683
1709
  */
1684
1710
  storeParameters(deviceRef, retryConfig = { count: 10, delay: 500 }) {
1685
- return this.setParameterValue(deviceRef, 0x1010, 1, 0x65766173).pipe(// "evas"
1711
+ return this.setParameterValue(deviceRef, 0x1010, 1, 0x65766173).pipe(
1712
+ // "evas"
1686
1713
  (0, operators_1.delay)(2000), (0, operators_1.mergeMap)(() => this.matchParameterValue(deviceRef, 0x1010, 1, 1).pipe((0, operators_1.retry)(retryConfig))));
1687
1714
  }
1688
1715
  /**
@@ -1707,7 +1734,8 @@ class MotionMasterReqResClient {
1707
1734
  * {@link https://www.synapticon.com/documentation/circulo/sw5.0/device_info/save_restore_config.html}
1708
1735
  */
1709
1736
  restoreDefaultParameters(deviceRef, type = types_1.RestoreDefaultParametersType.RESTORE_ALL_DEFAULT_PARAMETERS, retryConfig = { count: 10, delay: 500 }) {
1710
- return this.setParameterValue(deviceRef, 0x1011, type, 0x64616f6c).pipe(// "daol"
1737
+ return this.setParameterValue(deviceRef, 0x1011, type, 0x64616f6c).pipe(
1738
+ // "daol"
1711
1739
  (0, operators_1.delay)(2000), (0, operators_1.mergeMap)(() => this.matchParameterValue(deviceRef, 0x1011, type, 1).pipe((0, operators_1.retry)(retryConfig))));
1712
1740
  }
1713
1741
  /**
@@ -1787,10 +1815,10 @@ class MotionMasterReqResClient {
1787
1815
  throw new Error(`It is not possible to transition from state ${currentState} to state ${targetState}. The transition from the current ${currentState} state is automatic.`);
1788
1816
  }
1789
1817
  let controlword = yield this.upload(deviceRef, 0x6040, 0);
1790
- let transition = cia402_2.cia402Transitions.find(t => t.from === currentState && t.to === targetState);
1818
+ let transition = cia402_2.cia402Transitions.find((t) => t.from === currentState && t.to === targetState);
1791
1819
  // From SOD it's only possible to transition to RTSO.
1792
1820
  if (currentState === cia402_1.Cia402State.SWITCH_ON_DISABLED && targetState !== cia402_1.Cia402State.READY_TO_SWITCH_ON) {
1793
- transition = cia402_2.cia402Transitions.find(t => t.from === cia402_1.Cia402State.READY_TO_SWITCH_ON && t.to === targetState);
1821
+ transition = cia402_2.cia402Transitions.find((t) => t.from === cia402_1.Cia402State.READY_TO_SWITCH_ON && t.to === targetState);
1794
1822
  }
1795
1823
  if (!transition) {
1796
1824
  throw new Error(`It is not possible to transition from state ${currentState} to state ${targetState}.`);
@@ -1888,7 +1916,7 @@ class MotionMasterReqResClient {
1888
1916
  throw new Error(`Device ${deviceRef} is not in FAULT CiA402 state.`);
1889
1917
  }
1890
1918
  let controlword = yield this.upload(deviceRef, 0x6040, 0);
1891
- controlword = controlword & 0xFF7F; // set fault reset bit (7) to 0
1919
+ controlword = controlword & 0xff7f; // set fault reset bit (7) to 0
1892
1920
  yield this.download(deviceRef, 0x6040, 0, controlword);
1893
1921
  yield (0, util_1.resolveAfter)(10);
1894
1922
  controlword = (0, cia402_3.createControlwordCommand)(controlword, cia402_1.ControlwordCommand.FAULT_RESET); // set fault reset bit (7) to 1
@@ -1896,7 +1924,7 @@ class MotionMasterReqResClient {
1896
1924
  yield (0, util_1.resolveAfter)(10);
1897
1925
  currentState = yield (0, rxjs_1.lastValueFrom)(this.getCia402State(deviceRef));
1898
1926
  if (currentState === cia402_1.Cia402State.SWITCH_ON_DISABLED) {
1899
- controlword = controlword & 0xFF7F; // set fault reset bit (7) to 0
1927
+ controlword = controlword & 0xff7f; // set fault reset bit (7) to 0
1900
1928
  yield this.download(deviceRef, 0x6040, 0, controlword);
1901
1929
  }
1902
1930
  });
@@ -1924,9 +1952,10 @@ class MotionMasterReqResClient {
1924
1952
  const command = (0, cia402_3.createControlwordCommand)(controlword, cia402_1.ControlwordCommand.QUICK_STOP);
1925
1953
  yield this.download(deviceRef, 0x6040, 0, command);
1926
1954
  const modesOfOperationDisplay = yield this.upload(deviceRef, 0x6061, 0);
1927
- if (modesOfOperationDisplay === cia402_1.ModesOfOperation.CYCLIC_SYNC_TORQUE_MODE || modesOfOperationDisplay === cia402_1.ModesOfOperation.TORQUE_PROFILE_MODE) {
1955
+ if (modesOfOperationDisplay === cia402_1.ModesOfOperation.CYCLIC_SYNC_TORQUE_MODE ||
1956
+ modesOfOperationDisplay === cia402_1.ModesOfOperation.TORQUE_PROFILE_MODE) {
1928
1957
  yield this.download(deviceRef, 0x6071, 0, 0); // target torque
1929
- yield this.download(deviceRef, 0x60B2, 0, 0); // torque offset
1958
+ yield this.download(deviceRef, 0x60b2, 0, 0); // torque offset
1930
1959
  }
1931
1960
  });
1932
1961
  }
@@ -1940,8 +1969,8 @@ class MotionMasterReqResClient {
1940
1969
  const positionActualValue = yield this.upload(deviceRef, 0x6064, 0);
1941
1970
  yield this.downloadMany([
1942
1971
  [deviceRef, 0x6071, 0, 0],
1943
- [deviceRef, 0x607A, 0, positionActualValue],
1944
- [deviceRef, 0x60FF, 0, 0], // target velocity
1972
+ [deviceRef, 0x607a, 0, positionActualValue],
1973
+ [deviceRef, 0x60ff, 0, 0], // target velocity
1945
1974
  ]);
1946
1975
  });
1947
1976
  }
@@ -1967,7 +1996,7 @@ class MotionMasterReqResClient {
1967
1996
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
1968
1997
  let controlword = yield this.upload(deviceRef, 0x6040, 0);
1969
1998
  if ((controlword & 0x0010) > 0) {
1970
- controlword = controlword & 0xFFEF; // set new set-point bit to 0
1999
+ controlword = controlword & 0xffef; // set new set-point bit to 0
1971
2000
  yield this.download(deviceRef, 0x6040, 0, controlword);
1972
2001
  yield (0, util_1.resolveAfter)(30);
1973
2002
  }
@@ -2040,15 +2069,26 @@ class MotionMasterReqResClient {
2040
2069
  const getResponse$ = (0, rxjs_1.defer)(() => this.getParameterValue(deviceRef, 0x1023, 3).pipe((0, operators_1.map)((value) => (0, os_command_1.parseOsCommandResponse)(value, command)), (0, rxjs_1.tap)((r) => {
2041
2070
  r.fsBuffer = fsBuffer;
2042
2071
  response = r;
2043
- })));
2072
+ }) // A side effect (storing to a local variable) is required for the conditional in the repeat operator.
2073
+ ));
2044
2074
  if (osCommandMode === true) {
2045
2075
  osCommandMode = os_command_1.OsCommandMode.EXECUTE_THE_NEXT_COMMAND_IMMEDIATELY;
2046
2076
  }
2047
- return (0, rxjs_1.concat)((typeof osCommandMode === 'number') ? this.setOsCommandMode(deviceRef, osCommandMode) : rxjs_1.EMPTY, this.setParameterValue(deviceRef, 0x1023, 1, command), fsBufferContent instanceof Uint8Array ? this.setFile(deviceRef, 'fs-buffer', fsBufferContent, true, 20000) : rxjs_1.EMPTY, fsBufferContent === true ? this.getFile(deviceRef, 'fs-buffer', 20000).pipe((0, operators_1.map)((value) => fsBuffer = value)) : rxjs_1.EMPTY, getResponse$.pipe((0, operators_1.repeat)({
2048
- delay: () => (response && (response.request === 'succeeded' || response.request === 'failed'))
2077
+ return (0, rxjs_1.concat)(typeof osCommandMode === 'number' ? this.setOsCommandMode(deviceRef, osCommandMode) : rxjs_1.EMPTY, this.setParameterValue(deviceRef, 0x1023, 1, command), fsBufferContent instanceof Uint8Array
2078
+ ? this.setFile(deviceRef, 'fs-buffer', fsBufferContent, true, 20000)
2079
+ : rxjs_1.EMPTY, getResponse$.pipe((0, operators_1.repeat)({
2080
+ delay: () => response && (response.request === 'succeeded' || response.request === 'failed')
2049
2081
  ? rxjs_1.EMPTY
2050
2082
  : (0, rxjs_1.timer)(responsePollingInterval),
2051
- }))).pipe((0, operators_1.takeUntil)((0, rxjs_1.timer)(commandTimeout).pipe((0, operators_1.mergeMap)(() => (0, rxjs_1.throwError)(() => new Error(`A timeout has occurred for the OS command ${JSON.stringify(command)} on device ${deviceRef}.`))))), (0, operators_1.filter)(os_command_1.isOsCommandResponse), (0, os_command_1.mapOsCommandResponse)());
2083
+ }))).pipe((0, operators_1.takeUntil)((0, rxjs_1.timer)(commandTimeout).pipe((0, operators_1.mergeMap)(() => (0, rxjs_1.throwError)(() => new Error(`A timeout has occurred for the OS command ${JSON.stringify(command)} on device ${deviceRef}.`))))), (0, operators_1.filter)(os_command_1.isOsCommandResponse), (0, operators_1.mergeMap)((response) => {
2084
+ if (response.request === 'succeeded' && fsBufferContent === true) {
2085
+ return this.getFile(deviceRef, 'fs-buffer', 20000).pipe((0, operators_1.map)((value) => {
2086
+ response.fsBuffer = value;
2087
+ return response;
2088
+ }));
2089
+ }
2090
+ return (0, rxjs_1.of)(response);
2091
+ }), (0, os_command_1.mapOsCommandResponse)());
2052
2092
  }
2053
2093
  setOsCommandMode(deviceRef, value) {
2054
2094
  return this.setParameterValue(deviceRef, 0x1024, 0, value);
@@ -2085,7 +2125,7 @@ class MotionMasterReqResClient {
2085
2125
  }
2086
2126
  runOpenPhaseDetectionOsCommand(deviceRef, commandTimeout = 10000, responsePollingInterval = 1000, osCommandMode = false) {
2087
2127
  const command = (0, os_command_1.createOpenPhaseDetectionOsCommand)();
2088
- return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval, osCommandMode = false);
2128
+ return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval, (osCommandMode = false));
2089
2129
  }
2090
2130
  runPolePairDetectionOsCommand(deviceRef, commandTimeout = 60000, responsePollingInterval = 1000, osCommandMode = false) {
2091
2131
  const command = (0, os_command_1.createPolePairDetectionOsCommand)();
@@ -2139,7 +2179,8 @@ class MotionMasterReqResClient {
2139
2179
  */
2140
2180
  resetKublerEncoderMultiturnPosition(deviceRef) {
2141
2181
  return (0, rxjs_1.concat)(this.runKublerEncoderRegisterCommunicationOsCommand(deviceRef, 1, 0x56, 1, 4), // set to 0
2142
- this.runKublerEncoderRegisterCommunicationOsCommand(deviceRef, 1, 0x54, 1, 1));
2182
+ this.runKublerEncoderRegisterCommunicationOsCommand(deviceRef, 1, 0x54, 1, 1) // save value
2183
+ );
2143
2184
  }
2144
2185
  readOsCommandResponse(deviceRef) {
2145
2186
  return this.getParameterValue(deviceRef, 0x1023, 3).pipe((0, operators_1.map)((value) => (0, os_command_1.parseOsCommandResponse)(value)));
@@ -2147,7 +2188,7 @@ class MotionMasterReqResClient {
2147
2188
  runOsCommandAndWriteFsBuffer(deviceRef, command, content, commandTimeout = 30000, responsePollingInterval = 1000, osCommandMode = false) {
2148
2189
  return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval, osCommandMode, content);
2149
2190
  }
2150
- runOsCommandAndReadFsBuffer(deviceRef, command, commandTimeout, responsePollingInterval = 1000, osCommandMode = false) {
2191
+ runOsCommandAndReadFsBuffer(deviceRef, command, commandTimeout = 30000, responsePollingInterval = 1000, osCommandMode = false) {
2151
2192
  return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval, osCommandMode, true);
2152
2193
  }
2153
2194
  /**
@@ -2162,7 +2203,7 @@ class MotionMasterReqResClient {
2162
2203
  setHaltBit(deviceRef, value) {
2163
2204
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
2164
2205
  let controlword = yield this.upload(deviceRef, 0x6040, 0);
2165
- controlword = value ? (controlword | 0x0100) : (controlword & 0xFEFF);
2206
+ controlword = value ? controlword | 0x0100 : controlword & 0xfeff;
2166
2207
  yield this.download(deviceRef, 0x6040, 0, controlword);
2167
2208
  });
2168
2209
  }
@@ -2232,9 +2273,7 @@ class MotionMasterReqResClient {
2232
2273
  return (0, rxjs_1.defer)(() => this.deleteFile(deviceRef, file));
2233
2274
  }
2234
2275
  });
2235
- return fileDeletionObservables.length > 0
2236
- ? (0, rxjs_1.forkJoin)(fileDeletionObservables)
2237
- : (0, rxjs_1.of)(true); // continue even if there are no files to delete
2276
+ return fileDeletionObservables.length > 0 ? (0, rxjs_1.forkJoin)(fileDeletionObservables) : (0, rxjs_1.of)(true); // continue even if there are no files to delete
2238
2277
  }), (0, operators_1.mergeMap)(() => {
2239
2278
  if (installEmptyFirmware) {
2240
2279
  return this.startDeviceFirmwareInstallation(Object.assign(Object.assign({}, (0, device_1.makeDeviceRefObj)(deviceRef)), { firmwarePackageContent: new Uint8Array((0, base64_arraybuffer_1.decode)(device_1.emptyAppBase64)), skipSiiInstallation: true }), 120000);
@@ -2296,7 +2335,7 @@ class MotionMasterReqResClient {
2296
2335
  * Checks if the device has firmware by reading the Manufacturer Software Version parameter (0x100A:00).
2297
2336
  */
2298
2337
  hasFirmware(deviceRef) {
2299
- return this.getParameterValue(deviceRef, 0x100A, 0).pipe((0, operators_1.map)((value) => value ? true : false), (0, operators_1.catchError)(() => (0, rxjs_1.of)(false)));
2338
+ return this.getParameterValue(deviceRef, 0x100a, 0).pipe((0, operators_1.map)((value) => (value ? true : false)), (0, operators_1.catchError)(() => (0, rxjs_1.of)(false)));
2300
2339
  }
2301
2340
  /**
2302
2341
  * Reads the contents of configuration CSV files in the specified order and returns a list of unique configuration parameters.
@@ -2311,16 +2350,19 @@ class MotionMasterReqResClient {
2311
2350
  return this.getDecodedFile(deviceRef, name).pipe((0, operators_1.map)((content) => {
2312
2351
  const configFile = new config_file_1.ConfigFile(content); // Parse the content and create config parameters.
2313
2352
  return configFile.parameters;
2314
- }), (0, operators_1.catchError)(() => (0, rxjs_1.of)([])));
2353
+ }), (0, operators_1.catchError)(() => (0, rxjs_1.of)([])) // Handles potential errors, such as a missing file or failure to instantiate ConfigFile due to parsing issues.
2354
+ );
2315
2355
  }), (0, operators_1.toArray)(), // Collect all emitted parameters into a single array and emit them as a single emission after completion.
2316
2356
  (0, operators_1.map)((allParameters) => {
2317
2357
  const parameters = allParameters.flat(); // Flatten the array into a single list of parameters.
2318
2358
  // Filter out duplicate parameters by 'index' and 'subindex', keeping only the most recent one.
2319
- return Array.from(parameters.reduce((map, param) => {
2359
+ return Array.from(parameters
2360
+ .reduce((map, param) => {
2320
2361
  const key = (0, parameter_1.makeParameterId)(param.index, param.subindex);
2321
2362
  map.set(key, param); // Replace any existing entry with the same key.
2322
2363
  return map;
2323
- }, new Map()).values());
2364
+ }, new Map())
2365
+ .values());
2324
2366
  }));
2325
2367
  }
2326
2368
  /**
@@ -2405,21 +2447,21 @@ class MotionMasterReqResClient {
2405
2447
  uiFeaturesConfig.parameters = yield (0, rxjs_1.lastValueFrom)(this.getConfigFileParameters(deviceRef, ['.assembly_config']));
2406
2448
  // Parameters in the assembly configuration file are read-only.
2407
2449
  // Set write access to false to prevent modifications.
2408
- (_b = uiFeaturesConfig.parameters) === null || _b === void 0 ? void 0 : _b.map((parameter) => parameter.writeAccess = false);
2450
+ (_b = uiFeaturesConfig.parameters) === null || _b === void 0 ? void 0 : _b.map((parameter) => (parameter.writeAccess = false));
2409
2451
  // Check if the encoder configuration is disabled.
2410
2452
  // Encoder configuration is disabled if the parameters 0x2110 and 0x2112 are present in the assembly configuration file.
2411
- uiFeaturesConfig.encoderConfigurationDisabled = (_c = uiFeaturesConfig.parameters) === null || _c === void 0 ? void 0 : _c.some(parameter => parameter.index === 0x2110 || parameter.index === 0x2112);
2453
+ uiFeaturesConfig.encoderConfigurationDisabled = (_c = uiFeaturesConfig.parameters) === null || _c === void 0 ? void 0 : _c.some((parameter) => parameter.index === 0x2110 || parameter.index === 0x2112);
2412
2454
  // 0x607B: The position range limit is a special case. While the EtherCAT conformance test requires these parameters to be flagged as "rw",
2413
2455
  // users are not permitted to modify them because the firmware adjusts these values based on the encoder type and resolution.
2414
2456
  // To enforce this restriction, we set them as read-only here.
2415
2457
  (_d = uiFeaturesConfig.parameters) !== null && _d !== void 0 ? _d : (uiFeaturesConfig.parameters = []);
2416
2458
  for (let i = 1; i <= 2; i++) {
2417
- const parameter = uiFeaturesConfig.parameters.find((parameter) => parameter.index === 0x607B && parameter.subindex === i);
2459
+ const parameter = uiFeaturesConfig.parameters.find((parameter) => parameter.index === 0x607b && parameter.subindex === i);
2418
2460
  if (parameter) {
2419
2461
  parameter.writeAccess = false;
2420
2462
  }
2421
2463
  else {
2422
- uiFeaturesConfig.parameters.push({ index: 0x607B, subindex: i, writeAccess: false });
2464
+ uiFeaturesConfig.parameters.push({ index: 0x607b, subindex: i, writeAccess: false });
2423
2465
  }
2424
2466
  }
2425
2467
  return uiFeaturesConfig;
@@ -2448,9 +2490,10 @@ class MotionMasterReqResClient {
2448
2490
  updatePdoParameterGroupedValues(deviceRef, pdoGroupedValues, pdoIndex) {
2449
2491
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
2450
2492
  for (const [i, groupedValues] of pdoGroupedValues.entries()) {
2451
- let values = groupedValues.slice(1)
2493
+ let values = groupedValues
2494
+ .slice(1)
2452
2495
  .filter((value) => value !== 0)
2453
- .map((value) => typeof value === 'string' ? parseInt(value, 10) : value);
2496
+ .map((value) => (typeof value === 'string' ? parseInt(value, 10) : value));
2454
2497
  const n = values.length; // number of new mapped parameters
2455
2498
  values = values.concat(new Array(10 - n).fill(0));
2456
2499
  yield (0, rxjs_1.lastValueFrom)(this.setParameterValues([[deviceRef, pdoIndex + i, 0, 0]]));
@@ -2463,6 +2506,397 @@ class MotionMasterReqResClient {
2463
2506
  }
2464
2507
  });
2465
2508
  }
2509
+ /**
2510
+ * Reads the SMM parameter for a given device.
2511
+ *
2512
+ * @param deviceRef - The reference to the device to which the command will be sent.
2513
+ * @param index - The index of the SMM parameter to read.
2514
+ * @param subindex - The subindex of the SMM parameter to read. Defaults to 0.
2515
+ * @param commandTimeout - The timeout for the command in milliseconds. Defaults to 10,000 ms (10 seconds).
2516
+ * @param responsePollingInterval - The interval between polling attempts for a response in milliseconds. Defaults to 100 ms.
2517
+ *
2518
+ * @returns An observable that emits the response from the command once it is received.
2519
+ */
2520
+ readSmmParameter(deviceRef, index, subindex = 0, commandTimeout = 10000, responsePollingInterval = 100) {
2521
+ const command = (0, os_command_1.createSmmAcyclicHandlerReadSmmParameterOsCommand)(index, subindex);
2522
+ return this.runOsCommandAndReadFsBuffer(deviceRef, command, commandTimeout, responsePollingInterval, os_command_1.OsCommandMode.EXECUTE_THE_NEXT_COMMAND_IMMEDIATELY);
2523
+ }
2524
+ /**
2525
+ * Reads the SMM parameter value as a number.
2526
+ *
2527
+ * This method reads a parameter from a device and extracts its value based on the provided `dataViewExtractor`.
2528
+ * The default behavior is to extract a 32-bit integer in little-endian format.
2529
+ *
2530
+ * @param deviceRef - A reference to the device from which the SMM parameter is being read.
2531
+ * @param index - The index of the parameter to read.
2532
+ * @param subindex - The subindex of the parameter (default is 0).
2533
+ * @param dataViewExtractor - A function that extracts a number from the `DataView` (default is `view.getInt32(0, true)`).
2534
+ *
2535
+ * @returns An observable that emits the extracted number value.
2536
+ *
2537
+ * @throws {Error} If the response buffer is empty or invalid.
2538
+ */
2539
+ readSmmParameterNumberValue(deviceRef, index, subindex = 0, dataViewExtractor = (view) => view.getInt32(0, true)) {
2540
+ return this.readSmmParameter(deviceRef, index, subindex).pipe((0, operators_1.map)((response) => {
2541
+ if (!response.fsBuffer) {
2542
+ throw new Error('Reading SMM parameter failed. The response buffer is empty.');
2543
+ }
2544
+ const buffer = Uint8Array.from(response.fsBuffer);
2545
+ const view = new DataView(buffer.buffer);
2546
+ return dataViewExtractor(view);
2547
+ }));
2548
+ }
2549
+ /**
2550
+ * Reads the SMM parameter value as a string.
2551
+ *
2552
+ * This method reads a parameter from a device and decodes its value as a UTF-8 string from the response buffer.
2553
+ *
2554
+ * @param deviceRef - A reference to the device from which the SMM parameter is being read.
2555
+ * @param index - The index of the parameter to read.
2556
+ * @param subindex - The subindex of the parameter (default is 0).
2557
+ *
2558
+ * @returns An observable that emits the decoded string value.
2559
+ *
2560
+ * @throws {Error} If the response buffer is empty or invalid.
2561
+ */
2562
+ readSmmParameterStringValue(deviceRef, index, subindex = 0) {
2563
+ return this.readSmmParameter(deviceRef, index, subindex).pipe((0, operators_1.map)((response) => {
2564
+ if (!response.fsBuffer) {
2565
+ throw new Error('Reading SMM parameter failed. The response buffer is empty.');
2566
+ }
2567
+ const buffer = Uint8Array.from(response.fsBuffer);
2568
+ return new TextDecoder().decode(buffer);
2569
+ }));
2570
+ }
2571
+ /**
2572
+ * Reads the SMM parameter value as an array of numbers.
2573
+ *
2574
+ * This method reads a parameter from a device and returns the values as an array of numbers,
2575
+ * where each element corresponds to a byte from the response buffer.
2576
+ *
2577
+ * @param deviceRef - A reference to the device from which the SMM parameter is being read.
2578
+ * @param index - The index of the parameter to read.
2579
+ * @param subindex - The subindex of the parameter (default is 0).
2580
+ *
2581
+ * @returns An observable that emits an array of numbers, representing the byte values in the response buffer.
2582
+ *
2583
+ * @throws {Error} If the response buffer is empty or invalid.
2584
+ */
2585
+ readSmmParameterArrayValue(deviceRef, index, subindex = 0) {
2586
+ return this.readSmmParameter(deviceRef, index, subindex).pipe((0, operators_1.map)((response) => {
2587
+ if (!response.fsBuffer) {
2588
+ throw new Error('Reading SMM parameter failed. The response buffer is empty.');
2589
+ }
2590
+ const buffer = Uint8Array.from(response.fsBuffer);
2591
+ return Array.from(buffer);
2592
+ }));
2593
+ }
2594
+ /**
2595
+ * Reads the SMM firmware version from a device as an array of bytes.
2596
+ *
2597
+ * This method reads the firmware version (MCU Software Version 0x0001:00) of the device as an array of numbers.
2598
+ * The first byte represents the minor version, and the second byte represents the major version.
2599
+ *
2600
+ * @param deviceRef - A reference to the device from which the firmware version is being read.
2601
+ *
2602
+ * @returns An observable that emits an array of numbers, representing the byte values of the firmware version.
2603
+ */
2604
+ readSmmFirmareVersion(deviceRef) {
2605
+ return this.readSmmParameterArrayValue(deviceRef, 0x0001, 0);
2606
+ }
2607
+ /**
2608
+ * Reads the SMM firmware version from a device as a number.
2609
+ *
2610
+ * This function retrieves a specific parameter from the device's SMM memory
2611
+ * and interprets the result as a 16-bit version number.
2612
+ *
2613
+ * @param deviceRef - A reference to the target device.
2614
+ * @returns An `Observable<number>` emitting the firmware version, represented as an integer.
2615
+ */
2616
+ readSmmFirmareVersionAsNumber(deviceRef) {
2617
+ return this.readSmmParameterArrayValue(deviceRef, 0x0001, 0).pipe((0, operators_1.map)((bytes) => (bytes[1] << 8) | bytes[0]));
2618
+ }
2619
+ /**
2620
+ * Resolves the SMM parameter structure version for the specified device based on its firmware version.
2621
+ *
2622
+ * @param deviceRef - The reference to the target device.
2623
+ *
2624
+ * @returns An Observable that emits the appropriate SMM parameter structure version:
2625
+ * - 0x0041 for firmware versions below 2.3 (0x0203).
2626
+ * - 0x0203 for firmware versions 2.3 (0x0203) and above.
2627
+ *
2628
+ * @remarks
2629
+ * - The function first reads the firmware version of the device.
2630
+ * - Based on the firmware version, it returns the corresponding parameter structure version:
2631
+ * - If the firmware version is less than 0x0203, the parameter structure version is 0x0041.
2632
+ * - If the firmware version is 0x0203 or greater, the parameter structure version is 0x0203.
2633
+ */
2634
+ resolveSmmParameterStructureVersion(deviceRef) {
2635
+ return this.readSmmFirmareVersionAsNumber(deviceRef).pipe((0, operators_1.map)((version) => {
2636
+ if (version < 0x0203) {
2637
+ return 0x0041;
2638
+ }
2639
+ else {
2640
+ return 0x0203;
2641
+ }
2642
+ }));
2643
+ }
2644
+ /**
2645
+ * Reads the SMM serial number from a device.
2646
+ *
2647
+ * This method reads the serial number of the device as a string.
2648
+ * The serial number is retrieved from the device using the appropriate SMM parameter (0x0003:00).
2649
+ *
2650
+ * @param deviceRef - A reference to the device from which the serial number is being read.
2651
+ *
2652
+ * @returns An observable that emits the serial number as a string.
2653
+ */
2654
+ readSmmSerialNumber(deviceRef) {
2655
+ return this.readSmmParameterStringValue(deviceRef, 0x0003, 0);
2656
+ }
2657
+ /**
2658
+ * Reads the SMM temperature value from a device.
2659
+ *
2660
+ * This method reads the temperature of the device as a number. The temperature is retrieved from the device
2661
+ * using the appropriate SMM parameter (0x000a:00).
2662
+ *
2663
+ * @param deviceRef - A reference to the device from which the temperature is being read.
2664
+ *
2665
+ * @returns An observable that emits the temperature value as a number.
2666
+ */
2667
+ readSmmTemperature(deviceRef) {
2668
+ return this.readSmmParameterNumberValue(deviceRef, 0x000a, 0);
2669
+ }
2670
+ /**
2671
+ * Reads the SMM parameter check value from a device.
2672
+ *
2673
+ * This method reads the parameter check value from the device as a 16-bit unsigned integer. The value represents
2674
+ * the number of parameters available on the SMM and is retrieved from the device using the appropriate SMM parameter (0x000b:00).
2675
+ * and the custom data extraction function.
2676
+ *
2677
+ * @param deviceRef - A reference to the device from which the parameter check value is being read.
2678
+ *
2679
+ * @returns An observable that emits the parameter check value as a 16-bit unsigned integer, which represents
2680
+ * the number of parameters available on the SMM.
2681
+ */
2682
+ readSmmParameterCheck(deviceRef) {
2683
+ return this.readSmmParameterNumberValue(deviceRef, 0x000b, 0, (view) => view.getUint16(0, true));
2684
+ }
2685
+ /**
2686
+ * Reads the SMM maximum position discrepancy value from a device.
2687
+ *
2688
+ * This method reads the maximum position discrepancy value from the device as a 32-bit unsigned integer.
2689
+ * The value is retrieved from the device using the appropriate SMM parameter and the custom data extraction function.
2690
+ *
2691
+ * @param deviceRef - A reference to the device from which the maximum position discrepancy value is being read.
2692
+ *
2693
+ * @returns An observable that emits the maximum position discrepancy value as a 32-bit unsigned integer.
2694
+ */
2695
+ readSmmMaxPositionDiscrepancy(deviceRef) {
2696
+ return this.readSmmParameterNumberValue(deviceRef, 0x0011, 0, (view) => view.getUint32(0, true));
2697
+ }
2698
+ /**
2699
+ * Logs into the SMM for parameter download with the provided credentials.
2700
+ *
2701
+ * This function sends a login command to the device using the provided username and password. It returns an observable
2702
+ * that emits `true` if the login is successful and `false` otherwise. If the device is already logged in, the next login
2703
+ * attempt will fail unless the user logs out beforehand.
2704
+ *
2705
+ * @param deviceRef - The reference to the device to which the login command will be sent.
2706
+ * @param username - The optional username used for logging in to the SMM. If not provided, it will be treated as an empty string.
2707
+ * @param password - The password used for logging in to the SMM.
2708
+ *
2709
+ * @returns An observable that emits a boolean value indicating whether the login attempt succeeded.
2710
+ *
2711
+ * @remarks
2712
+ * If the device is already logged in, the next login attempt will fail unless the user logs out first.
2713
+ */
2714
+ loginToSmmForParameterDownload(deviceRef, username, password) {
2715
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.PARAMETER_DOWNLOAD_LOGIN);
2716
+ const content = (0, smm_1.packSmmCredentials)(username, password);
2717
+ return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2718
+ }
2719
+ /**
2720
+ * Logs into the SMM for software update with the provided credentials.
2721
+ *
2722
+ * This function sends a login command to the device using the provided username and password. It returns an observable
2723
+ * that emits `true` if the login is successful and `false` otherwise. If the device is already logged in, the next login
2724
+ * attempt will fail unless the user logs out beforehand.
2725
+ *
2726
+ * @param deviceRef - The reference to the device to which the login command will be sent.
2727
+ * @param username - The optional username used for logging in to the SMM. If not provided, it will be treated as an empty string.
2728
+ * @param password - The password used for logging in to the SMM.
2729
+ *
2730
+ * @returns An observable that emits a boolean value indicating whether the login attempt succeeded.
2731
+ *
2732
+ * @remarks
2733
+ * If the device is already logged in, the next login attempt will fail unless the user logs out first.
2734
+ */
2735
+ loginToSmmForSoftwareUpdate(deviceRef, username, password) {
2736
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.SOFTWARE_UPDATE_LOGIN);
2737
+ const content = (0, smm_1.packSmmCredentials)(username, password);
2738
+ return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2739
+ }
2740
+ /**
2741
+ * Logs out from the SMM.
2742
+ *
2743
+ * This function sends a logout command to the device and returns an observable that emits `true` if the logout
2744
+ * is successful and `false` otherwise. The command times out after 10 seconds if no response is received.
2745
+ *
2746
+ * @param deviceRef - The reference to the device to which the logout command will be sent.
2747
+ *
2748
+ * @returns An observable that emits a boolean value indicating whether the logout attempt succeeded.
2749
+ */
2750
+ logoutFromSmm(deviceRef) {
2751
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.LOGOUT);
2752
+ return this.runOsCommand(deviceRef, command, 10000, 100).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2753
+ }
2754
+ /**
2755
+ * Logs out from the SMM and then logs back in with the provided credentials for parameter download.
2756
+ *
2757
+ * This function first sends a logout command to the device, followed by a login command using the provided username
2758
+ * and password. It returns an observable that emits `true` if both the logout and login attempts are successful
2759
+ * and `false` otherwise. The login process is handled through the `loginToSmmForParameterDownload` function.
2760
+ *
2761
+ * @param deviceRef - The reference to the device to which the logout and login commands will be sent.
2762
+ * @param username - The username used for logging in to the SMM.
2763
+ * @param password - The password used for logging in to the SMM.
2764
+ *
2765
+ * @returns An observable that emits a boolean value indicating whether the relogin attempt succeeded.
2766
+ */
2767
+ reloginToSmmForParameterDownload(deviceRef, username, password) {
2768
+ return this.logoutFromSmm(deviceRef).pipe((0, operators_1.mergeMap)((succeeded) => succeeded ? this.loginToSmmForParameterDownload(deviceRef, username, password) : (0, rxjs_1.of)(false)));
2769
+ }
2770
+ /**
2771
+ * Changes the SMM password for the specified device.
2772
+ *
2773
+ * @param deviceRef - A reference to the target device.
2774
+ * @param oldPassword - The current SMM password.
2775
+ * @param newPassword - The new password to set for the SMM.
2776
+ * @returns An Observable that emits `true` if the password change and SMM restart succeed, otherwise `false`.
2777
+ *
2778
+ * @remarks
2779
+ * A prior successful login is required before changing the password.
2780
+ * The new password must be at least 4 characters long.
2781
+ *
2782
+ * This function sends an acyclic command to update the password. If successful, it triggers an SMM restart.
2783
+ */
2784
+ changeSmmPassword(deviceRef, oldPassword, newPassword) {
2785
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.CHANGE_PASSWORD);
2786
+ const content = (0, smm_1.packSmmChangePassword)(newPassword, oldPassword);
2787
+ return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'), (0, operators_1.mergeMap)((succeeded) => (succeeded ? this.triggerSmmRestart(deviceRef) : (0, rxjs_1.of)(false))));
2788
+ }
2789
+ /**
2790
+ * Triggers a restart for the specified device.
2791
+ *
2792
+ * This method sends a command to the device to trigger an SMM restart and waits for a response.
2793
+ * The method will return `true` if the restart was successful, otherwise `false`.
2794
+ *
2795
+ * @param deviceRef - The reference to the device to restart.
2796
+ * @param commandTimeout - The timeout in milliseconds for the command to complete. Default is 10000ms (10 seconds).
2797
+ * @param responsePollingInterval - The interval in milliseconds between polling for the response. Default is 100ms.
2798
+ *
2799
+ * @returns An Observable that emits `true` if the restart was successful, or `false` otherwise.
2800
+ */
2801
+ triggerSmmRestart(deviceRef, commandTimeout = 10000, responsePollingInterval = 100) {
2802
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.TRIGGER_RESTART);
2803
+ return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2804
+ }
2805
+ /**
2806
+ * Acknowledges an I/O failure on the specified device.
2807
+ *
2808
+ * This method sends a command to the device to acknowledge an I/O failure and waits for a response.
2809
+ * The method will return `true` if the acknowledgment was successful, otherwise `false`.
2810
+ *
2811
+ * @param deviceRef - The reference to the device to acknowledge the I/O failure on.
2812
+ * @param commandTimeout - The timeout in milliseconds for the command to complete. Default is 10000ms (10 seconds).
2813
+ * @param responsePollingInterval - The interval in milliseconds between polling for the response. Default is 100ms.
2814
+ *
2815
+ * @returns An Observable that emits `true` if the acknowledgment was successful, or `false` otherwise.
2816
+ */
2817
+ acknowledgeIoFailureOnSmm(deviceRef, commandTimeout = 10000, responsePollingInterval = 100) {
2818
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.IO_FAILURE_ACKNOWLEDGE);
2819
+ return this.runOsCommand(deviceRef, command, commandTimeout, responsePollingInterval).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2820
+ }
2821
+ configureSmmSoftwareUpdate(deviceRef, fileSize) {
2822
+ const command = (0, os_command_1.createSmmAcyclicHandlerConfigureSoftwareUpdateOsCommand)(fileSize);
2823
+ return this.runOsCommand(deviceRef, command, 10000, 100).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2824
+ }
2825
+ updateSmmSoftware(deviceRef, username, password, buffer, crc, chunkSize = 1000) {
2826
+ const fileSize = buffer.byteLength;
2827
+ const observables = [
2828
+ (0, rxjs_1.defer)(() => this.loginToSmmForSoftwareUpdate(deviceRef, username, password)),
2829
+ (0, rxjs_1.defer)(() => this.configureSmmSoftwareUpdate(deviceRef, fileSize)),
2830
+ ];
2831
+ const n = Math.ceil(fileSize / chunkSize);
2832
+ const transmitSoftwareCommand = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.TRANSMIT_SOFTWARE);
2833
+ for (let i = 0; i < n; i++) {
2834
+ const start = i * chunkSize;
2835
+ const end = start + chunkSize;
2836
+ const content = buffer.slice(start, end);
2837
+ observables.push((0, rxjs_1.defer)(() => this.runOsCommandAndWriteFsBuffer(deviceRef, transmitSoftwareCommand, content).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'))));
2838
+ }
2839
+ const packedCrc = (0, smm_1.packSmmSoftwareUpdateCrc)(crc);
2840
+ const finalizeSoftwareUpdateCommand = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.FINALIZE_SOFTWARE_UPDATE);
2841
+ observables.push((0, rxjs_1.defer)(() => this.runOsCommandAndWriteFsBuffer(deviceRef, finalizeSoftwareUpdateCommand, packedCrc).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'))), (0, rxjs_1.defer)(() => this.triggerSmmRestart(deviceRef)));
2842
+ return (0, rxjs_1.concat)(...observables);
2843
+ }
2844
+ /**
2845
+ * Transmits SMM parameters to the specified device.
2846
+ *
2847
+ * @param deviceRef - The reference to the target device.
2848
+ * @param values - An array of data values to transmit.
2849
+ * @param parameterStructureVersion - The version of the parameter structure (default: 0x0041).
2850
+ *
2851
+ * @returns An Observable that emits `true` if the operation succeeds, or `false` if it fails, the `values` array is empty.
2852
+ *
2853
+ * @remarks
2854
+ * - If the `values` array is empty, the function immediately returns `false`.
2855
+ * - The `version` is prepended to the values array before packing.
2856
+ * - The function constructs an OS command for transmitting the parameters and writes the packed buffer to the file system.
2857
+ */
2858
+ transmitSmmParameters(deviceRef, values, parameterStructureVersion = 0x0041) {
2859
+ if (values.length === 0) {
2860
+ return (0, rxjs_1.of)(false);
2861
+ }
2862
+ // usedParameterStructVersion: 1st byte is major version, 2nd byte is minor version (0x0028 -> 0.40)
2863
+ values.unshift(parameterStructureVersion);
2864
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.TRANSMIT_PARAMETERS);
2865
+ const { buffer: content } = (0, smm_1.packSmmParameterValues)(values);
2866
+ return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2867
+ }
2868
+ /**
2869
+ * Loads the SMM parameters for verification on the specified device.
2870
+ *
2871
+ * This method sends a command to the device to load the SMM parameters for verification and waits for the response.
2872
+ * The device returns a buffer with all bits inverted. The OS command will invert the bits and reconstruct the buffer
2873
+ * into valid parameter values, which are then returned in sequence within the OS command response.
2874
+ *
2875
+ * @param deviceRef - The reference to the device from which the parameters should be loaded.
2876
+ * @returns An Observable that emits the response from the device, containing the valid parameter values for verification
2877
+ * after the buffer is processed and reconstructed.
2878
+ *
2879
+ * @throws Will throw an error if the command fails or times out.
2880
+ */
2881
+ loadSmmParametersForVerification(deviceRef) {
2882
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.LOAD_PARAMETERS_FOR_VERIFICATION);
2883
+ return this.runOsCommandAndReadFsBuffer(deviceRef, command, 10000, 1000);
2884
+ }
2885
+ verifySmmParameters(deviceRef, parameters, groupOrdinal) {
2886
+ const values = parameters.map((p) => p.value);
2887
+ const { buffer: content } = (0, smm_1.calcSmmBitmask)(values, groupOrdinal);
2888
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.VERIFY_PARAMETERS);
2889
+ return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2890
+ }
2891
+ loadSmmValidationFile(deviceRef) {
2892
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.LOAD_VALIDATION_FILE);
2893
+ return this.runOsCommand(deviceRef, command, 5000, 100);
2894
+ }
2895
+ validateSmmConfiguration(deviceRef, report, date, username, password) {
2896
+ const { buffer: content } = (0, smm_1.packSmmValidationReport)(report, date, username, password);
2897
+ const command = (0, os_command_1.createSmmAcyclicHandlerOsCommand)(os_command_1.SmmAcyclicHandlerSubcommandId.VALIDATE_CONFIGURATION);
2898
+ return this.runOsCommandAndWriteFsBuffer(deviceRef, command, content).pipe((0, operators_1.last)(), (0, operators_1.map)((response) => response.request === 'succeeded'));
2899
+ }
2466
2900
  }
2467
2901
  exports.MotionMasterReqResClient = MotionMasterReqResClient;
2468
2902
  //# sourceMappingURL=motion-master-req-res-client.js.map