motion-master-client 0.0.3 → 0.0.6

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 (118) hide show
  1. package/README.md +123 -49
  2. package/package.json +21 -6
  3. package/src/{index.ts → index.d.ts} +23 -22
  4. package/src/index.js +27 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/cia402.d.ts +30 -0
  7. package/src/lib/cia402.js +112 -0
  8. package/src/lib/cia402.js.map +1 -0
  9. package/src/lib/device-log-line.d.ts +5 -0
  10. package/src/lib/device-log-line.js +3 -0
  11. package/src/lib/device-log-line.js.map +1 -0
  12. package/src/lib/{device-parameter.ts → device-parameter.d.ts} +56 -69
  13. package/src/lib/device-parameter.js +39 -0
  14. package/src/lib/device-parameter.js.map +1 -0
  15. package/src/lib/device.d.ts +8 -0
  16. package/src/lib/device.js +3 -0
  17. package/src/lib/device.js.map +1 -0
  18. package/src/lib/examples/get-firmware-version-for-all-devices.d.ts +1 -0
  19. package/src/lib/examples/get-firmware-version-for-all-devices.js +15 -0
  20. package/src/lib/examples/get-firmware-version-for-all-devices.js.map +1 -0
  21. package/src/lib/hardware-description.d.ts +37 -0
  22. package/src/lib/hardware-description.js +48 -0
  23. package/src/lib/hardware-description.js.map +1 -0
  24. package/src/lib/logger.d.ts +1 -0
  25. package/src/lib/logger.js +8 -0
  26. package/src/lib/logger.js.map +1 -0
  27. package/src/lib/monitoring-config.d.ts +6 -0
  28. package/src/lib/monitoring-config.js +3 -0
  29. package/src/lib/monitoring-config.js.map +1 -0
  30. package/src/lib/monitoring-entry.d.ts +9 -0
  31. package/src/lib/monitoring-entry.js +3 -0
  32. package/src/lib/monitoring-entry.js.map +1 -0
  33. package/src/lib/motion-master-client.d.ts +18 -0
  34. package/src/lib/motion-master-client.js +73 -0
  35. package/src/lib/motion-master-client.js.map +1 -0
  36. package/src/lib/motion-master-pub-sub-client.d.ts +16 -0
  37. package/src/lib/motion-master-pub-sub-client.js +68 -0
  38. package/src/lib/motion-master-pub-sub-client.js.map +1 -0
  39. package/src/lib/motion-master-pub-sub-socket.d.ts +28 -0
  40. package/src/lib/motion-master-pub-sub-socket.js +3 -0
  41. package/src/lib/motion-master-pub-sub-socket.js.map +1 -0
  42. package/src/lib/motion-master-pub-sub-web-socket.d.ts +13 -0
  43. package/src/lib/motion-master-pub-sub-web-socket.js +61 -0
  44. package/src/lib/motion-master-pub-sub-web-socket.js.map +1 -0
  45. package/src/lib/motion-master-pub-sub-worker-socket.d.ts +13 -0
  46. package/src/lib/motion-master-pub-sub-worker-socket.js +37 -0
  47. package/src/lib/motion-master-pub-sub-worker-socket.js.map +1 -0
  48. package/src/lib/motion-master-req-res-client.d.ts +956 -0
  49. package/src/lib/motion-master-req-res-client.js +1521 -0
  50. package/src/lib/motion-master-req-res-client.js.map +1 -0
  51. package/src/lib/motion-master-req-res-socket.d.ts +38 -0
  52. package/src/lib/motion-master-req-res-socket.js +3 -0
  53. package/src/lib/motion-master-req-res-socket.js.map +1 -0
  54. package/src/lib/motion-master-req-res-web-socket.d.ts +20 -0
  55. package/src/lib/motion-master-req-res-web-socket.js +100 -0
  56. package/src/lib/motion-master-req-res-web-socket.js.map +1 -0
  57. package/src/lib/motion-master-req-res-worker-socket.d.ts +15 -0
  58. package/src/lib/motion-master-req-res-worker-socket.js +53 -0
  59. package/src/lib/motion-master-req-res-worker-socket.js.map +1 -0
  60. package/src/lib/motion-master.proto.js +5 -3
  61. package/src/lib/operators.d.ts +21 -0
  62. package/src/lib/operators.js +71 -0
  63. package/src/lib/operators.js.map +1 -0
  64. package/src/lib/options.d.ts +34 -0
  65. package/src/lib/options.js +38 -0
  66. package/src/lib/options.js.map +1 -0
  67. package/src/lib/parameter.d.ts +65 -0
  68. package/src/lib/parameter.js +70 -0
  69. package/src/lib/parameter.js.map +1 -0
  70. package/src/lib/request-status-resolver.d.ts +4 -0
  71. package/src/lib/request-status-resolver.js +345 -0
  72. package/src/lib/request-status-resolver.js.map +1 -0
  73. package/src/lib/system-log-line.d.ts +8 -0
  74. package/src/lib/system-log-line.js +3 -0
  75. package/src/lib/system-log-line.js.map +1 -0
  76. package/src/lib/types.d.ts +50 -0
  77. package/src/lib/types.js +23 -0
  78. package/src/lib/types.js.map +1 -0
  79. package/src/lib/urls.d.ts +3 -0
  80. package/src/lib/urls.js +10 -0
  81. package/src/lib/urls.js.map +1 -0
  82. package/src/lib/util.d.ts +30 -0
  83. package/src/lib/util.js +279 -0
  84. package/src/lib/util.js.map +1 -0
  85. package/.babelrc +0 -3
  86. package/.eslintrc.json +0 -18
  87. package/jest.config.ts +0 -15
  88. package/motion-master.proto +0 -1822
  89. package/src/lib/device-log-line.ts +0 -5
  90. package/src/lib/device-parameter.spec.ts +0 -85
  91. package/src/lib/hardware-description.spec.ts +0 -223
  92. package/src/lib/hardware-description.ts +0 -79
  93. package/src/lib/logger.ts +0 -5
  94. package/src/lib/monitoring-config.ts +0 -6
  95. package/src/lib/monitoring-entry.ts +0 -11
  96. package/src/lib/motion-master-client.ts +0 -94
  97. package/src/lib/motion-master-pub-sub-client.ts +0 -94
  98. package/src/lib/motion-master-pub-sub-socket.ts +0 -33
  99. package/src/lib/motion-master-pub-sub-web-socket.ts +0 -71
  100. package/src/lib/motion-master-pub-sub-worker-socket.ts +0 -58
  101. package/src/lib/motion-master-req-res-client.spec.ts +0 -126
  102. package/src/lib/motion-master-req-res-client.ts +0 -1990
  103. package/src/lib/motion-master-req-res-socket.ts +0 -45
  104. package/src/lib/motion-master-req-res-web-socket.ts +0 -119
  105. package/src/lib/motion-master-req-res-worker-socket.ts +0 -63
  106. package/src/lib/operators.ts +0 -93
  107. package/src/lib/options.ts +0 -12
  108. package/src/lib/parameter.spec.ts +0 -81
  109. package/src/lib/parameter.ts +0 -119
  110. package/src/lib/request-status-resolver.ts +0 -380
  111. package/src/lib/system-log-line.ts +0 -8
  112. package/src/lib/types.ts +0 -58
  113. package/src/lib/urls.ts +0 -6
  114. package/src/lib/util.ts +0 -261
  115. package/tsconfig.json +0 -22
  116. package/tsconfig.lib.json +0 -10
  117. package/tsconfig.spec.json +0 -20
  118. package/typedoc.json +0 -10
package/src/lib/util.ts DELETED
@@ -1,261 +0,0 @@
1
- import { inRange } from "lodash";
2
- import { DeviceLogLine } from "./device-log-line";
3
- import { Parameter, ParameterIndexSubindex } from "./parameter";
4
- import { SystemLogLine } from "./system-log-line";
5
- import { DeviceRefObj, MotionMasterMessage, ParameterAddressValue, ParameterTypeValue, ParameterTypeValueKey, ParameterValueType, ValueType } from "./types";
6
-
7
- export function getParameterTypeValueDefault(key: ParameterTypeValueKey) {
8
- if (key === 'floatValue' || key === 'intValue' || key === 'uintValue') {
9
- return 0;
10
- } else if (key === 'rawValue') {
11
- return Uint8Array.from([]);
12
- } else if (key === 'stringValue') {
13
- return '';
14
- } else {
15
- return 0;
16
- }
17
- }
18
-
19
- export function getParameterTypeValue(parameter: MotionMasterMessage.Status.DeviceParameterValues.IParameterValue): ParameterTypeValueKey | undefined {
20
- return (MotionMasterMessage.Status.DeviceParameterValues.ParameterValue.create(parameter)).typeValue;
21
- }
22
-
23
- export function getParameterValue(parameter: MotionMasterMessage.Status.DeviceParameterValues.IParameterValue): ParameterValueType {
24
- const key = getParameterTypeValue(parameter);
25
- if (key && key in parameter) {
26
- return parameter[key] ?? getParameterTypeValueDefault(key);
27
- }
28
- return 0;
29
- }
30
-
31
- export function makeDeviceRefObj(deviceRef: number | string): DeviceRefObj {
32
- if (typeof deviceRef === 'number') {
33
- if (deviceRef <= 0xFFFF) {
34
- return { devicePosition: deviceRef };
35
- } else {
36
- return { deviceAddress: deviceRef };
37
- }
38
- } else {
39
- return { deviceSerialNumber: deviceRef };
40
- }
41
- }
42
-
43
- export function parseSystemLogLine(line: string): SystemLogLine | undefined {
44
- const re = /(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s\((.*)\)\s\[(.*)\]\s(.*:\d+)\s(.*)\|(.*)$/gm;
45
- const result = re.exec(line);
46
- if (result) {
47
- return {
48
- date: new Date(result[1]),
49
- uptime: result[2].trim(),
50
- id: result[3].trim(),
51
- file: result[4].trim(),
52
- level: result[5].trim(),
53
- message: result[6].trim(),
54
- };
55
- }
56
- return;
57
- }
58
-
59
- export function parseSystemLogContent(content: string): SystemLogLine[] {
60
- return content.split('\n')
61
- .map((v) => parseSystemLogLine(v))
62
- .filter((l): l is SystemLogLine => l !== undefined);
63
- }
64
-
65
- export function parseDeviceLog(line: string): DeviceLogLine | undefined {
66
- const re = /^(\d{2}:\d{2}:\d{2}\.\d+)\s(.*)\|(.*)$/gm;
67
- const result = re.exec(line);
68
- if (result) {
69
- return {
70
- time: result[1].trim(),
71
- level: result[2].trim(),
72
- message: result[3].trim(),
73
- };
74
- }
75
- return;
76
- }
77
-
78
- export function parseDeviceLogContent(content: string): DeviceLogLine[] {
79
- return content.split('\n')
80
- .map((v) => parseDeviceLog(v))
81
- .filter((l): l is DeviceLogLine => l !== undefined);
82
- }
83
-
84
- export function mapParameterTypeValueToObject(type: keyof ParameterTypeValue, value: number | string): ParameterTypeValue {
85
- const p: ParameterTypeValue = {};
86
- if (type === 'floatValue') {
87
- p['floatValue'] = typeof value === 'number' ? value : parseFloat(value);
88
- } else if (type === 'intValue') {
89
- p['intValue'] = typeof value === 'number' ? value : parseInt(value, 10);
90
- } else if (type === 'rawValue') {
91
- if (typeof value === 'number') {
92
- p['rawValue'] = Uint8Array.from([value]);
93
- } else {
94
- let bytes: number[] = [];
95
- if (value.startsWith('0x')) {
96
- bytes = value.slice(2).match(/.{1,2}/g)?.map((h) => parseInt(h, 16)) ?? [];
97
- } else {
98
- bytes = value.split(',').map((c) => c.trim()).map((c) => parseInt(c, 10));
99
- }
100
- p['rawValue'] = Uint8Array.from(bytes);
101
- }
102
- } else if (type === 'stringValue') {
103
- p['stringValue'] = typeof value === 'string' ? value : value.toString();
104
- } else if (type === 'uintValue') {
105
- p['uintValue'] = typeof value === 'number' ? value : parseInt(value, 10);
106
- }
107
- return p;
108
- }
109
-
110
- // Using bytes fixes: ERROR TypeError: Cannot freeze array buffer views with elements in NgRx
111
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
- export function createPlainObjectFromMotionMasterMessage(motionMasterMessage: MotionMasterMessage): any {
113
- return MotionMasterMessage.toObject(motionMasterMessage, {
114
- arrays: true, // populates empty arrays (repeated fields) even if defaults=false
115
- bytes: Array, // bytes as array of numbers
116
- defaults: true, // includes default values
117
- objects: true, // populates empty objects (map fields) even if defaults=false
118
- oneofs: true, // includes virtual oneof fields set to the present field's name
119
- });
120
- }
121
-
122
- export function decodeTextContent(content: Uint8Array): string {
123
- const decoder = new TextDecoder();
124
- const buffer = Uint8Array.from(content);
125
- return decoder.decode(buffer);
126
- }
127
-
128
- export function isRxPdoIndex(index: number): boolean {
129
- return inRange(index, 0x1600, 0x1800);
130
- }
131
-
132
- export function isTxPdoIndex(index: number): boolean {
133
- return inRange(index, 0x1A00, 0x1C00);
134
- }
135
-
136
- export function filterRxPdoParameters<T extends ParameterIndexSubindex>(parameters: T[], excludeSubIndex000 = false): T[] {
137
- return parameters.filter((p) => isRxPdoIndex(p.index) && (excludeSubIndex000 ? p.subindex > 0 : true)); // RxPDOs: Index area 0x1600 to 0x17FF
138
- }
139
-
140
- export function filterTxPdoParameters<T extends ParameterIndexSubindex>(parameters: T[], excludeSubIndex000 = false): T[] {
141
- return parameters.filter((p) => isTxPdoIndex(p.index) && (excludeSubIndex000 ? p.subindex > 0 : true)); // TxPDOs: Index area 0x1A00 to 0x1BFF
142
- }
143
-
144
- export function fillPdoParametersWithMappingEntries(parameters: Parameter[], entriesPerPdo = 10): Parameter[] {
145
- const output: Parameter[] = [];
146
- let i = 0;
147
- while (i < parameters.length) {
148
- if (parameters[i].subindex === 0) {
149
- let j = i;
150
- while (parameters[j] && (parameters[j].index === parameters[i].index)) {
151
- output.push(parameters[j]);
152
- j++;
153
- }
154
- let d = j - i;
155
- while (d <= entriesPerPdo) {
156
- output.push({
157
- index: parameters[i].index,
158
- subindex: d,
159
- name: parameters[i].name,
160
- uintValue: 0,
161
- value: 0,
162
- valueType: ValueType.UNSIGNED32,
163
- group: parameters[i].group,
164
- typeValue: "uintValue",
165
- readAccess: true,
166
- writeAccess: true,
167
- });
168
- d++;
169
- }
170
- i = j;
171
- } else {
172
- i++;
173
- }
174
- }
175
- return output;
176
- }
177
-
178
- export function mapParameterToPdoSubItemValue(parameter: Parameter): number {
179
- const { index, subindex } = parameter;
180
- if (parameter.valueType && parameter.valueType < ValueType.VISIBLE_STRING) {
181
- const buffer = new ArrayBuffer(4);
182
- const view = new DataView(buffer);
183
- const bitSize = mapValueTypeToBitSize(parameter.valueType);
184
- view.setUint16(0, index);
185
- view.setUint8(2, subindex);
186
- view.setUint8(3, bitSize);
187
- return view.getUint32(0);
188
- }
189
- return 0;
190
- }
191
-
192
- export function mapValueTypeToBitSize(valueType: ValueType): number {
193
- switch (valueType) {
194
- case ValueType.UNSPECIFIED:
195
- return 0;
196
- case ValueType.BOOLEAN:
197
- return 1;
198
- case ValueType.INTEGER8:
199
- case ValueType.UNSIGNED8:
200
- return 8;
201
- case ValueType.INTEGER16:
202
- case ValueType.UNSIGNED16:
203
- return 16;
204
- case ValueType.INTEGER32:
205
- case ValueType.UNSIGNED32:
206
- case ValueType.REAL32:
207
- return 32;
208
- }
209
- throw new Error(`Non-numeric value type "${valueType}" (data types with variable length) cannot be mapped to bit size. You will have to get this info from ESI.`);
210
- }
211
-
212
- export const valueTypeToParameterTypeValueKeyMap = new Map<ValueType, keyof Required<ParameterTypeValue>>([
213
- [ValueType.BOOLEAN, 'uintValue'],
214
- [ValueType.INTEGER8, 'intValue'],
215
- [ValueType.INTEGER16, 'intValue'],
216
- [ValueType.INTEGER32, 'intValue'],
217
- [ValueType.UNSIGNED8, 'uintValue'],
218
- [ValueType.UNSIGNED16, 'uintValue'],
219
- [ValueType.UNSIGNED32, 'uintValue'],
220
- [ValueType.REAL32, 'floatValue'],
221
- [ValueType.VISIBLE_STRING, 'stringValue'],
222
- [ValueType.OCTET_STRING, 'stringValue'],
223
- [ValueType.UNICODE_STRING, 'stringValue'],
224
- ]);
225
-
226
- export function createPdoParameterValues(parameters: Array<{ index: number, subindex: number, typeValue?: ParameterTypeValueKey }>, values: Array<ParameterValueType>) {
227
- const output = parameters.map((parameter, i, arr) => {
228
- const { index, subindex, typeValue } = parameter;
229
- let value = values[i];
230
- if (subindex === 0) {
231
- value = arr.reduce((n, p, j) => (p.index === index && p.subindex > 0 && values[j]) ? n + 1 : n, 0);
232
- }
233
- return [index, subindex, value, typeValue];
234
- }) as ParameterAddressValue[];
235
-
236
- for (let i = 0; i < output.length - 1; i++) {
237
- const [, subindex1, value1] = output[i];
238
- if (subindex1 > 0 && value1 === 0) {
239
- let j = i + 1;
240
- let [, subindex2, value2] = output[j];
241
- while (subindex2 > subindex1 && output[j]) {
242
- if (value2 > 0) {
243
- output[i][2] = value2;
244
- output[j][2] = 0;
245
- break;
246
- }
247
- if (output[++j]) {
248
- [, subindex2, value2] = output[j];
249
- }
250
- }
251
- }
252
- }
253
-
254
- return output;
255
- }
256
-
257
- export function resolveAfter(ms: number, value?: unknown) {
258
- return new Promise(function (resolve) {
259
- setTimeout(resolve.bind(null, value), ms);
260
- });
261
- }
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "files": [],
4
- "include": [],
5
- "references": [
6
- {
7
- "path": "./tsconfig.lib.json"
8
- },
9
- {
10
- "path": "./tsconfig.spec.json"
11
- }
12
- ],
13
- "compilerOptions": {
14
- "forceConsistentCasingInFileNames": true,
15
- "strict": true,
16
- "noImplicitOverride": true,
17
- "noPropertyAccessFromIndexSignature": true,
18
- "noImplicitReturns": true,
19
- "noFallthroughCasesInSwitch": true,
20
- "allowJs": true
21
- }
22
- }
package/tsconfig.lib.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "types": []
7
- },
8
- "include": ["src/**/*.ts"],
9
- "exclude": ["jest.config.ts", "**/*.spec.ts", "jest.config.ts"]
10
- }
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "types": ["jest", "node"]
7
- },
8
- "include": [
9
- "**/*.test.ts",
10
- "**/*.spec.ts",
11
- "**/*.test.tsx",
12
- "**/*.spec.tsx",
13
- "**/*.test.js",
14
- "**/*.spec.js",
15
- "**/*.test.jsx",
16
- "**/*.spec.jsx",
17
- "**/*.d.ts",
18
- "jest.config.ts"
19
- ]
20
- }
package/typedoc.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "entryPoints": [
3
- "./src/index.ts"
4
- ],
5
- "out": "../../docs/motion-master-client",
6
- "tsconfig": "./tsconfig.json",
7
- "exclude": [
8
- "**/*+(.spec|.e2e).ts"
9
- ]
10
- }