motion-master-client 0.0.55 → 0.0.56

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 (132) hide show
  1. package/.babelrc +3 -0
  2. package/.eslintrc.json +18 -0
  3. package/README.md +123 -123
  4. package/jest.config.ts +16 -0
  5. package/motion-master.proto +1861 -0
  6. package/package.json +6 -21
  7. package/project.json +45 -0
  8. package/src/{index.d.ts → index.ts} +26 -26
  9. package/src/lib/cia402.spec.ts +77 -0
  10. package/src/lib/cia402.ts +414 -0
  11. package/src/lib/config-file.spec.ts +114 -0
  12. package/src/lib/config-file.ts +63 -0
  13. package/src/lib/device-log-line.ts +5 -0
  14. package/src/lib/device-parameter.spec.ts +85 -0
  15. package/src/lib/device-parameter.ts +79 -0
  16. package/src/lib/device.ts +10 -0
  17. package/src/lib/hardware-description.spec.ts +253 -0
  18. package/src/lib/hardware-description.ts +129 -0
  19. package/src/lib/logger.ts +5 -0
  20. package/src/lib/monitoring-config.ts +6 -0
  21. package/src/lib/{monitoring-entry.d.ts → monitoring-entry.ts} +10 -9
  22. package/src/lib/motion-master-client.ts +266 -0
  23. package/src/lib/motion-master-pub-sub-client.ts +100 -0
  24. package/src/lib/motion-master-pub-sub-socket.ts +46 -0
  25. package/src/lib/motion-master-pub-sub-web-socket.ts +77 -0
  26. package/src/lib/motion-master-pub-sub-worker-socket.ts +57 -0
  27. package/src/lib/motion-master-req-res-client.spec.ts +740 -0
  28. package/src/lib/motion-master-req-res-client.ts +2211 -0
  29. package/src/lib/motion-master-req-res-socket.ts +68 -0
  30. package/src/lib/motion-master-req-res-web-socket.ts +123 -0
  31. package/src/lib/motion-master-req-res-worker-socket.ts +89 -0
  32. package/src/lib/motion-master.proto.d.ts +5183 -5083
  33. package/src/lib/motion-master.proto.js +53218 -52284
  34. package/src/lib/operators.ts +108 -0
  35. package/src/lib/options.ts +12 -0
  36. package/src/lib/parameter.spec.ts +160 -0
  37. package/src/lib/parameter.ts +170 -0
  38. package/src/lib/product-id-range.ts +8 -0
  39. package/src/lib/request-status-resolver.ts +403 -0
  40. package/src/lib/system-log-line.ts +9 -0
  41. package/src/lib/{types.d.ts → types.ts} +141 -209
  42. package/src/lib/urls.ts +6 -0
  43. package/src/lib/util.ts +332 -0
  44. package/src/lib/web-socket-connection-close-codes.ts +85 -0
  45. package/tsconfig.json +23 -0
  46. package/tsconfig.lib.json +10 -0
  47. package/tsconfig.spec.json +20 -0
  48. package/typedoc.json +10 -0
  49. package/src/index.js +0 -30
  50. package/src/index.js.map +0 -1
  51. package/src/lib/cia402.d.ts +0 -182
  52. package/src/lib/cia402.js +0 -392
  53. package/src/lib/cia402.js.map +0 -1
  54. package/src/lib/config-file.d.ts +0 -13
  55. package/src/lib/config-file.js +0 -50
  56. package/src/lib/config-file.js.map +0 -1
  57. package/src/lib/device-log-line.d.ts +0 -5
  58. package/src/lib/device-log-line.js +0 -3
  59. package/src/lib/device-log-line.js.map +0 -1
  60. package/src/lib/device-parameter.d.ts +0 -56
  61. package/src/lib/device-parameter.js +0 -39
  62. package/src/lib/device-parameter.js.map +0 -1
  63. package/src/lib/device.d.ts +0 -9
  64. package/src/lib/device.js +0 -3
  65. package/src/lib/device.js.map +0 -1
  66. package/src/lib/hardware-description.d.ts +0 -41
  67. package/src/lib/hardware-description.js +0 -94
  68. package/src/lib/hardware-description.js.map +0 -1
  69. package/src/lib/logger.d.ts +0 -1
  70. package/src/lib/logger.js +0 -8
  71. package/src/lib/logger.js.map +0 -1
  72. package/src/lib/monitoring-config.d.ts +0 -6
  73. package/src/lib/monitoring-config.js +0 -3
  74. package/src/lib/monitoring-config.js.map +0 -1
  75. package/src/lib/monitoring-entry.js +0 -3
  76. package/src/lib/monitoring-entry.js.map +0 -1
  77. package/src/lib/motion-master-client.d.ts +0 -56
  78. package/src/lib/motion-master-client.js +0 -167
  79. package/src/lib/motion-master-client.js.map +0 -1
  80. package/src/lib/motion-master-pub-sub-client.d.ts +0 -17
  81. package/src/lib/motion-master-pub-sub-client.js +0 -73
  82. package/src/lib/motion-master-pub-sub-client.js.map +0 -1
  83. package/src/lib/motion-master-pub-sub-socket.d.ts +0 -42
  84. package/src/lib/motion-master-pub-sub-socket.js +0 -3
  85. package/src/lib/motion-master-pub-sub-socket.js.map +0 -1
  86. package/src/lib/motion-master-pub-sub-web-socket.d.ts +0 -18
  87. package/src/lib/motion-master-pub-sub-web-socket.js +0 -66
  88. package/src/lib/motion-master-pub-sub-web-socket.js.map +0 -1
  89. package/src/lib/motion-master-pub-sub-worker-socket.d.ts +0 -18
  90. package/src/lib/motion-master-pub-sub-worker-socket.js +0 -48
  91. package/src/lib/motion-master-pub-sub-worker-socket.js.map +0 -1
  92. package/src/lib/motion-master-req-res-client.d.ts +0 -947
  93. package/src/lib/motion-master-req-res-client.js +0 -1735
  94. package/src/lib/motion-master-req-res-client.js.map +0 -1
  95. package/src/lib/motion-master-req-res-socket.d.ts +0 -60
  96. package/src/lib/motion-master-req-res-socket.js +0 -3
  97. package/src/lib/motion-master-req-res-socket.js.map +0 -1
  98. package/src/lib/motion-master-req-res-web-socket.d.ts +0 -28
  99. package/src/lib/motion-master-req-res-web-socket.js +0 -98
  100. package/src/lib/motion-master-req-res-web-socket.js.map +0 -1
  101. package/src/lib/motion-master-req-res-worker-socket.d.ts +0 -24
  102. package/src/lib/motion-master-req-res-worker-socket.js +0 -72
  103. package/src/lib/motion-master-req-res-worker-socket.js.map +0 -1
  104. package/src/lib/operators.d.ts +0 -20
  105. package/src/lib/operators.js +0 -84
  106. package/src/lib/operators.js.map +0 -1
  107. package/src/lib/options.d.ts +0 -10
  108. package/src/lib/options.js +0 -14
  109. package/src/lib/options.js.map +0 -1
  110. package/src/lib/parameter.d.ts +0 -72
  111. package/src/lib/parameter.js +0 -119
  112. package/src/lib/parameter.js.map +0 -1
  113. package/src/lib/product-id-range.d.ts +0 -7
  114. package/src/lib/product-id-range.js +0 -12
  115. package/src/lib/product-id-range.js.map +0 -1
  116. package/src/lib/request-status-resolver.d.ts +0 -4
  117. package/src/lib/request-status-resolver.js +0 -345
  118. package/src/lib/request-status-resolver.js.map +0 -1
  119. package/src/lib/system-log-line.d.ts +0 -9
  120. package/src/lib/system-log-line.js +0 -3
  121. package/src/lib/system-log-line.js.map +0 -1
  122. package/src/lib/types.js +0 -29
  123. package/src/lib/types.js.map +0 -1
  124. package/src/lib/urls.d.ts +0 -3
  125. package/src/lib/urls.js +0 -10
  126. package/src/lib/urls.js.map +0 -1
  127. package/src/lib/util.d.ts +0 -42
  128. package/src/lib/util.js +0 -327
  129. package/src/lib/util.js.map +0 -1
  130. package/src/lib/web-socket-connection-close-codes.d.ts +0 -8
  131. package/src/lib/web-socket-connection-close-codes.js +0 -89
  132. package/src/lib/web-socket-connection-close-codes.js.map +0 -1
@@ -0,0 +1,108 @@
1
+ import { pipe, filter, map, timeout, takeWhile, Observable, UnaryFunction, mergeMap, of } from 'rxjs';
2
+ import { getParameterValue } from './util';
3
+ import { requestStatusResolver } from './request-status-resolver';
4
+ import { IMotionMasterMessage, MotionMasterMessage, ParameterValueType, StatusKey } from './types';
5
+ import { DeviceParameter } from './device-parameter';
6
+ import { MotionMasterReqResClient } from './motion-master-req-res-client';
7
+ import { makeParameterId } from './parameter';
8
+
9
+ export function selectMotionMasterMessageStatusByMessageId<T>(key: StatusKey, id?: string) {
10
+ return pipe(
11
+ filter((message: IMotionMasterMessage) => message.id === id),
12
+ map((message) => {
13
+ // Handling the special case when Motion Master sends SystemEvent instead of e.g. DeviceParameterInfo status for
14
+ // GetDeviceParameterInfo request message. This typically happens when request contains an invalid device address.
15
+ if (message.status?.systemEvent && key !== 'systemEvent') {
16
+ if (message.status.systemEvent.error) {
17
+ throw new Error(`Error selecting message: ${message.status.systemEvent.error.message ?? ''}`);
18
+ } else {
19
+ throw new Error(`Error selecting message. Received System Event instead of "${key.toString()}": ${JSON.stringify(message)}`);
20
+ }
21
+ }
22
+ return message.status?.[key] as T;
23
+ }),
24
+ );
25
+ }
26
+
27
+ export function extendStatus<T>(data: { statusKey: StatusKey, messageId: string }) {
28
+ return pipe(
29
+ map((status: T) => {
30
+ const { statusKey, messageId } = data;
31
+ const request = requestStatusResolver[statusKey]?.<T>(status);
32
+ return { ...status, messageId, request };
33
+ }),
34
+ );
35
+ }
36
+
37
+ export function transformMotionMasterMessageToStatus<T>(statusKey: StatusKey, requestTimeout: number, messageId: string) {
38
+ if (typeof requestTimeout !== 'number') {
39
+ throw new Error(`Invalid requestTimeout=${requestTimeout} provided for ${statusKey}`);
40
+ }
41
+
42
+ return pipe(
43
+ selectMotionMasterMessageStatusByMessageId<T>(statusKey, messageId),
44
+ timeout(requestTimeout),
45
+ extendStatus({ statusKey, messageId }),
46
+ takeWhile((status) => status.request !== 'succeeded' && status.request !== 'failed', true),
47
+ );
48
+ }
49
+
50
+ export function selectMotionMasterMessageByTopic<T>(topic: string) {
51
+ return pipe(
52
+ filter(([t]: [string, T]) => t === topic),
53
+ map(([, data]) => data),
54
+ );
55
+ }
56
+
57
+ export function selectMotionMasterMessageStatusByKey<T>(key: keyof MotionMasterMessage.IStatus) {
58
+ return pipe(
59
+ filter((message: IMotionMasterMessage) => !!(message.status && message.status[key])),
60
+ map((message) => message.status?.[key] as T),
61
+ );
62
+ }
63
+
64
+ export function mapMonitoringParameterValuesStatusMessageToParameterValues()
65
+ : UnaryFunction<Observable<IMotionMasterMessage>, Observable<ParameterValueType[]>> {
66
+ return pipe(
67
+ map((message: IMotionMasterMessage) => {
68
+ if (message.status?.monitoringParameterValues) {
69
+ const { deviceParameterValues } = message.status.monitoringParameterValues;
70
+ if (deviceParameterValues?.parameterValues) {
71
+ return deviceParameterValues.parameterValues.map((parameterValue) => getParameterValue(parameterValue));
72
+ }
73
+ }
74
+ return [];
75
+ }),
76
+ );
77
+ }
78
+
79
+ export function mapMonitoringParameterValuesStatusMessageToDeviceParameters(request: MotionMasterReqResClient)
80
+ : UnaryFunction<Observable<IMotionMasterMessage>, Observable<DeviceParameter[]>> {
81
+ return pipe(
82
+ mergeMap((message: IMotionMasterMessage) => {
83
+ const parameterValues = message.status?.monitoringParameterValues?.deviceParameterValues?.parameterValues;
84
+
85
+ if (!parameterValues) {
86
+ return of([]);
87
+ }
88
+
89
+ const deviceAddress = message?.status?.monitoringParameterValues?.deviceParameterValues?.deviceAddress!;
90
+
91
+ return request.resolveDeviceParameterInfoMap(deviceAddress).pipe(
92
+ map((infoMap) => {
93
+ return parameterValues.map((parameter) => {
94
+ const index = parameter.index ?? 0x0000;
95
+ const subindex = parameter.subindex ?? 0x00;
96
+ const id = makeParameterId(index, subindex);
97
+
98
+ const infoParameter = infoMap.get(id);
99
+
100
+ const value = getParameterValue(parameter);
101
+
102
+ return { id, index, subindex, ...infoParameter, value } as DeviceParameter;
103
+ })
104
+ }),
105
+ );
106
+ }),
107
+ );
108
+ }
@@ -0,0 +1,12 @@
1
+ import { MotionMasterMessage } from './types';
2
+
3
+ export const parameterValueTypeOptions = {
4
+ 'intValue': 'intValue',
5
+ 'uintValue': 'uintValue',
6
+ 'floatValue': 'floatValue',
7
+ 'stringValue': 'stringValue',
8
+ 'rawValue': 'rawValue',
9
+ };
10
+
11
+ export const ethercatNetworkStateOptions = MotionMasterMessage.Status.EthercatNetworkState.State;
12
+ export const positionControllerTypeOptions = MotionMasterMessage.Request.ComputeAutoTuningGains.PositionParameters.ControllerType;
@@ -0,0 +1,160 @@
1
+ import { differenceParameters, intersectionParameters, makeParameterId, splitParameterId } from "./parameter";
2
+
3
+ describe('parameter', () => {
4
+
5
+ describe('makeParameterId', () => {
6
+
7
+ test.each<[[(number | null | undefined), (number | null | undefined)], string]>([
8
+ [[0x1234, 123], '0x1234:7B'],
9
+ [[23, 23], '0x0017:17'],
10
+ [[0, 0], '0x0000:00'],
11
+ [[0x2000, undefined], '0x2000:00'],
12
+ [[0x2003, null], '0x2003:00'],
13
+ [[0x10000, 3], '0x00010000:03'],
14
+ [[0x100F0, undefined], '0x000100F0:00'],
15
+ ])('should for tuple %j return "%s"', (tuple, expected) => {
16
+ const result = makeParameterId(tuple);
17
+
18
+ expect(result).toBe(expected);
19
+ });
20
+
21
+ test.each([
22
+ [{}, '0x0000:00'],
23
+ [{ index: 0x2004, subindex: 4 }, '0x2004:04'],
24
+ [{ index: 0x1024 }, '0x1024:00'],
25
+ ])('should for parameter %j return "%s"', (parameter, expected) => {
26
+ const result = makeParameterId(parameter);
27
+
28
+ expect(result).toBe(expected);
29
+ });
30
+
31
+ test.each([
32
+ [0x1234, 123, '0x1234:7B'],
33
+ [23, 23, '0x0017:17'],
34
+ [0, 0, '0x0000:00'],
35
+ [0x2000, undefined, '0x2000:00'],
36
+ [0x2003, null, '0x2003:00'],
37
+ [0x10000, 3, '0x00010000:03'],
38
+ [0x100F0, undefined, '0x000100F0:00'],
39
+ ])('should for index %d and subindex %d return "%s"', (index, subindex, expected) => {
40
+ const result = makeParameterId(index, subindex);
41
+
42
+ expect(result).toBe(expected);
43
+ });
44
+
45
+ it('should throw if index is less than 0', () => {
46
+ expect(() => {
47
+ makeParameterId(-123, 0);
48
+ }).toThrow();
49
+ });
50
+
51
+ it('should throw if subindex is less than 0', () => {
52
+ expect(() => {
53
+ makeParameterId(0x1024, -3);
54
+ }).toThrow();
55
+ });
56
+
57
+ });
58
+
59
+ describe('splitParameterId', () => {
60
+
61
+ test.each([
62
+ ['0x1234:7B', [4660, 123]],
63
+ ['0x000100F0:00', [65776, 0]],
64
+ ])('should for id "%s" return tuple %j', (id, expected) => {
65
+ const result = splitParameterId(id);
66
+
67
+ expect(result).toEqual(expected);
68
+ });
69
+
70
+ test.each([
71
+ ['0x12:7B'],
72
+ ['0x1234:F'],
73
+ ['0x1234:FG'],
74
+ ['0x1H34:FF'],
75
+ ])('should throw error for id "%s"', (id) => {
76
+ expect(() => splitParameterId(id)).toThrow();
77
+ });
78
+
79
+ });
80
+
81
+ describe('differenceParameters', () => {
82
+ it('should return an empty array if there are no differences', () => {
83
+ const parameters = differenceParameters(
84
+ [
85
+ { index: 0x2030, subindex: 1 },
86
+ { index: 0x2031, subindex: 1 },
87
+ ],
88
+ [
89
+ { index: 0x2030, subindex: 1 },
90
+ { index: 0x2031, subindex: 1 },
91
+ ],
92
+ );
93
+
94
+ expect(parameters).toEqual([]);
95
+ });
96
+
97
+ it('should return an array of differences', () => {
98
+ const parameters = differenceParameters(
99
+ [
100
+ { index: 0x2030, subindex: 1 },
101
+ { index: 0x2031, subindex: 1 },
102
+ { index: 0x6040, subindex: 0 },
103
+ { index: 0x6091, subindex: 0 },
104
+ ],
105
+ [
106
+ { index: 0x2031, subindex: 1 },
107
+ { index: 0x6040, subindex: 0 },
108
+ { index: 0x6041, subindex: 0 },
109
+ ],
110
+ );
111
+
112
+ expect(parameters).toEqual([
113
+ { index: 0x2030, subindex: 1 },
114
+ { index: 0x6091, subindex: 0 },
115
+ ]);
116
+ });
117
+ });
118
+
119
+ fdescribe('intersectionParameters', () => {
120
+ it('should return full array if there are no differences', () => {
121
+ const parameters = intersectionParameters(
122
+ [
123
+ { index: 0x2030, subindex: 1 },
124
+ { index: 0x2031, subindex: 1 },
125
+ ],
126
+ [
127
+ { index: 0x2030, subindex: 1 },
128
+ { index: 0x2031, subindex: 1 },
129
+ ],
130
+ );
131
+
132
+ expect(parameters).toEqual([
133
+ { index: 0x2030, subindex: 1 },
134
+ { index: 0x2031, subindex: 1 },
135
+ ]);
136
+ });
137
+
138
+ it('should return an array excluding differences', () => {
139
+ const parameters = intersectionParameters(
140
+ [
141
+ { index: 0x2031, subindex: 1 },
142
+ { index: 0x6040, subindex: 0 },
143
+ { index: 0x6041, subindex: 0 },
144
+ ],
145
+ [
146
+ { index: 0x2030, subindex: 1 },
147
+ { index: 0x2031, subindex: 1 },
148
+ { index: 0x6040, subindex: 0 },
149
+ { index: 0x6091, subindex: 0 },
150
+ ],
151
+ );
152
+
153
+ expect(parameters).toEqual([
154
+ { index: 0x2031, subindex: 1 },
155
+ { index: 0x6040, subindex: 0 },
156
+ ]);
157
+ });
158
+ });
159
+
160
+ });
@@ -0,0 +1,170 @@
1
+ import { MotionMasterMessage, ParameterTypeValueKey, ParameterValueType } from "./types";
2
+ import { differenceWith, intersectionWith, round } from "lodash";
3
+
4
+ export interface Parameter extends MotionMasterMessage.Status.DeviceParameterInfo.IParameter, MotionMasterMessage.Status.DeviceParameterValues.IParameterValue {
5
+ index: number;
6
+ subindex: number;
7
+ name: string;
8
+ value: ParameterValueType;
9
+ typeValueKey: ParameterTypeValueKey;
10
+ options?: { [key: string]: number };
11
+ }
12
+
13
+ export type ParameterIndexSubindex = Pick<Parameter, 'index' | 'subindex'>;
14
+
15
+ /**
16
+ * Make parameter id by providing a tuple of index and subindex.
17
+ *
18
+ * @param tuple - an array of index and subindex
19
+ * @throws {Error} if index or subindex are less than 0
20
+ * @returns combined index and subindex in uppercase hexadecimal format, e.g. "0x60FE:02"
21
+ */
22
+ export function makeParameterId(tuple: [(number | null | undefined), (number | null | undefined)]): string;
23
+
24
+ /**
25
+ * Make parameter id by providing an object which has index and subindex properties.
26
+ *
27
+ * @param parameter - an object with optional index and subindex properties
28
+ * @throws {Error} if index or subindex are less than 0
29
+ * @returns combined index and subindex in uppercase hexadecimal format, e.g. "0x60FE:02"
30
+ */
31
+ export function makeParameterId(parameter: { index?: (number | null), subindex?: (number | null) }): string;
32
+
33
+ /**
34
+ * Make parameter id by providing index and subindex.
35
+ *
36
+ * @param index - from 0x0000 to 0xFFFF for objects defined in ESI and >0xFFFF for custom object
37
+ * @param subindex - defaults to 0 if not provided
38
+ * @throws {Error} if index or subindex are less than 0
39
+ * @returns combined index and subindex in uppercase hexadecimal format, e.g. "0x60FE:02"
40
+ */
41
+ export function makeParameterId(index?: (number | null), subindex?: (number | null)): string;
42
+
43
+ /**
44
+ * Make parameter id by providing different arguments.
45
+ *
46
+ * The purpose of this declaration is to expose the signature of the implementation for {@link makeDeviceParameterId} function.
47
+ *
48
+ * @param a - number or an object with index and subindex or tuple of index and subindex
49
+ * @param b - optional subindex, defaults to 0 if not provided
50
+ * @throws {Error} if index or subindex are less than 0
51
+ * @returns combined index and subindex in uppercase hexadecimal format, e.g. "0x60FE:02"
52
+ */
53
+ export function makeParameterId(a?: (number | null) | { index?: (number | null), subindex?: (number | null) } | [(number | null | undefined), (number | null | undefined)], b?: (number | null)): string;
54
+
55
+ export function makeParameterId(a?: (number | null) | { index?: (number | null), subindex?: (number | null) } | [(number | null | undefined), (number | null | undefined)], b?: (number | null)): string {
56
+ let index = 0;
57
+ let subindex = 0;
58
+
59
+ if (Array.isArray(a)) {
60
+ if (a[0]) {
61
+ index = a[0];
62
+ }
63
+ if (a[1]) {
64
+ subindex = a[1];
65
+ }
66
+ } else if (typeof a === 'object') {
67
+ if (a?.index) {
68
+ index = a.index;
69
+ }
70
+ if (a?.subindex) {
71
+ subindex = a.subindex;
72
+ }
73
+ } else {
74
+ if (typeof a === 'number') {
75
+ index = a;
76
+ }
77
+ if (typeof b === 'number') {
78
+ subindex = b;
79
+ }
80
+ }
81
+
82
+ if (index < 0) {
83
+ throw new Error(`The provided index to makeParameterId must be greater than 0: ${index}`);
84
+ }
85
+
86
+ if (subindex < 0) {
87
+ throw new Error(`The provided subindex to makeParameterId must be greater than 0: ${subindex}`);
88
+ }
89
+
90
+ const indexMaxLength = index > 0xFFFF ? 8 : 4;
91
+ const x = index.toString(16).toUpperCase().padStart(indexMaxLength, '0');
92
+ const y = subindex.toString(16).toUpperCase().padStart(2, '0');
93
+
94
+ return `0x${x}:${y}`;
95
+ }
96
+
97
+ /**
98
+ * Example of parameter id is "0x2110:1A" where:
99
+ * - 0x2110 is object index in hexadecimal format
100
+ * - 1A is subindex in hexadecimal format
101
+ */
102
+ export const parameterIdRegExp = /^0x([0-9a-fA-F]{4,}):([0-9a-fA-F]{2})$/;
103
+
104
+ /**
105
+ * Split device parameter id into parts.
106
+ *
107
+ * @param id - parameter id like "0x2110:1A"
108
+ * @returns tuple of index and subindex
109
+ */
110
+ export function splitParameterId(id: string): [number, number] {
111
+ const match = id.match(parameterIdRegExp);
112
+
113
+ if (!match) {
114
+ throw new Error(`Parameter id "${id}" doesn't match the regular expression: ${parameterIdRegExp}`);
115
+ }
116
+
117
+ return [
118
+ parseInt(match[1], 16), // index
119
+ parseInt(match[2], 16), // subindex
120
+ ];
121
+ }
122
+
123
+ export function isParameterId(id: string): boolean {
124
+ return parameterIdRegExp.test(id);
125
+ }
126
+
127
+ export function parametersCompareFn(
128
+ a: Pick<Parameter, 'index' | 'subindex'>,
129
+ b: Pick<Parameter, 'index' | 'subindex'>,
130
+ ): number {
131
+ if (a.index > b.index) {
132
+ return 1;
133
+ } else if (a.index < b.index) {
134
+ return -1;
135
+ } else {
136
+ if (a.subindex > b.subindex) {
137
+ return 1;
138
+ } else if (a.subindex < b.subindex) {
139
+ return -1;
140
+ } else {
141
+ return 0;
142
+ }
143
+ }
144
+ }
145
+
146
+ export function differenceParameters<T extends Pick<Parameter, 'index' | 'subindex'>>(p1: T[], p2: T[]): T[] {
147
+ return differenceWith(p1, p2, (a, b) => a.index === b.index && a.subindex === b.subindex);
148
+ }
149
+
150
+ export function intersectionParameters<T extends Pick<Parameter, 'index' | 'subindex'>>(p1: T[], p2: T[]): T[] {
151
+ return intersectionWith(p1, p2, (a, b) => a.index === b.index && a.subindex === b.subindex);
152
+ }
153
+
154
+ export function intersectionParametersWithDifferentValues<T extends Pick<Parameter, 'index' | 'subindex' | 'value'>>(p1: T[], p2: T[], roundFloats = false): T[] {
155
+ return intersectionWith(p1, p2, (a, b) => {
156
+ if (a.index === b.index && a.subindex === b.subindex) {
157
+ // values that are very close but have a different number of decimal places are treated as not equal
158
+ if (roundFloats && typeof a.value === 'number' && typeof b.value === 'number') {
159
+ const v1 = round(a.value, 7);
160
+ const v2 = round(b.value, 7);
161
+ return v1 !== v2;
162
+ } else if (Array.isArray(a.value) && Array.isArray(b.value)) {
163
+ return JSON.stringify(a.value) !== JSON.stringify(b.value);
164
+ } else {
165
+ return a.value !== b.value;
166
+ }
167
+ }
168
+ return false;
169
+ });
170
+ }
@@ -0,0 +1,8 @@
1
+ // https://docs.google.com/spreadsheets/d/1XJX1eqGau1X3sse10fuF-tVVgosbxCo-3ioUUG2CDYQ
2
+ export const productIdRange = {
3
+ 'CIRCULO_SAFE_MOTION': [8600, 8699],
4
+ 'INTEGRO': [9000, 9499],
5
+ 'NODE': [9500, 9599],
6
+ 'NODE_SAFETY': [9600, 9998],
7
+ 'INTERNAL': [9999, 9999],
8
+ };