@catchpower/device-config-interaction 0.0.13

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.
@@ -0,0 +1,1018 @@
1
+ import * as i0 from '@angular/core';
2
+ import { Injectable, NgModule } from '@angular/core';
3
+ import * as axios from 'axios';
4
+ import * as i2 from '@angular/forms';
5
+ import { Validators, UntypedFormGroup, UntypedFormControl } from '@angular/forms';
6
+
7
+ class CpDevicesListService {
8
+ //constructor() {}
9
+ async getDevicesList(_url, auth, listVersion = '-1') {
10
+ //console.log('getDevicesList function TRIGGERED ', _url);
11
+ const headers = {
12
+ Authorization: 'Basic ' + btoa(auth),
13
+ 'list-version': listVersion,
14
+ };
15
+ const response = await axios.default
16
+ .request({
17
+ method: 'get',
18
+ url: _url,
19
+ headers: headers,
20
+ })
21
+ .then((res) => {
22
+ if (res.status == 200) {
23
+ //console.log( 'get DL function SUCCESS ', JSON.stringify(res));
24
+ return res.data;
25
+ }
26
+ else {
27
+ return new Error('ERROR getting Devices List. ' + JSON.stringify(res));
28
+ }
29
+ }, (error) => {
30
+ return new Error('ERROR getting Devices List. ' + JSON.stringify(error));
31
+ });
32
+ return response;
33
+ }
34
+ getValueFromObj(element, name) {
35
+ let value = null;
36
+ let notInOther = true;
37
+ element.otherData.forEach((other) => {
38
+ if (other.name == name) {
39
+ value = other.value;
40
+ notInOther = false;
41
+ }
42
+ });
43
+ if (notInOther) {
44
+ element.rawData.forEach((raw) => {
45
+ if (raw.name == name) {
46
+ value = raw.value;
47
+ }
48
+ });
49
+ }
50
+ return value;
51
+ }
52
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CpDevicesListService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
53
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CpDevicesListService, providedIn: 'root' }); }
54
+ }
55
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CpDevicesListService, decorators: [{
56
+ type: Injectable,
57
+ args: [{
58
+ providedIn: 'root',
59
+ }]
60
+ }] });
61
+
62
+ class DatasetProcessingService {
63
+ //constructor() {}
64
+ /*
65
+ * For use with DataView
66
+ *
67
+ */
68
+ getValuefromBuffer(obj, buffer) {
69
+ let value = 0;
70
+ if (obj.signed) {
71
+ switch (obj.length) {
72
+ case 8:
73
+ value = buffer.getInt8(obj.position);
74
+ break;
75
+ case 16:
76
+ value = buffer.getInt16(obj.position, obj.little);
77
+ break;
78
+ case 32:
79
+ value = buffer.getInt32(obj.position, obj.little);
80
+ break;
81
+ }
82
+ }
83
+ else {
84
+ switch (obj.length) {
85
+ case 8:
86
+ value = buffer.getUint8(obj.position);
87
+ break;
88
+ case 16:
89
+ value = buffer.getUint16(obj.position, obj.little);
90
+ break;
91
+ case 32:
92
+ value = buffer.getUint32(obj.position, obj.little);
93
+ break;
94
+ }
95
+ }
96
+ return value;
97
+ }
98
+ /*
99
+ * For use with DataView
100
+ *
101
+ *
102
+ */
103
+ writeValueToBuffer(obj, value, buffer) {
104
+ if (obj.signed) {
105
+ switch (obj.length) {
106
+ case 8:
107
+ buffer.setInt8(obj.position, value);
108
+ break;
109
+ case 16:
110
+ buffer.setInt16(obj.position, value, obj.little);
111
+ break;
112
+ case 32:
113
+ buffer.setInt32(obj.position, value, obj.little);
114
+ break;
115
+ }
116
+ }
117
+ else {
118
+ switch (obj.length) {
119
+ case 8:
120
+ buffer.setUint8(obj.position, value);
121
+ break;
122
+ case 16:
123
+ buffer.setUint16(obj.position, value, obj.little);
124
+ break;
125
+ case 32:
126
+ buffer.setUint32(obj.position, value, obj.little);
127
+ break;
128
+ }
129
+ }
130
+ }
131
+ runProcess(process, rawData, otherData) {
132
+ const values = this.getChunkValues(process.data, rawData, otherData);
133
+ //console.log('process values ', values);
134
+ let pVal = 0;
135
+ switch (process.type) {
136
+ case 'ass':
137
+ pVal = this.assembleProcess(values);
138
+ process.value = pVal;
139
+ return;
140
+ case 'com':
141
+ pVal = this.compareProcess(values, process);
142
+ process.value = pVal;
143
+ return;
144
+ case 'cal':
145
+ pVal = this.calculateProcess(values);
146
+ process.value = pVal;
147
+ return;
148
+ case 'tfm':
149
+ pVal = this.tfmProcess(values);
150
+ process.value = pVal;
151
+ return;
152
+ case 'cdt':
153
+ pVal = this.cdtProcess(values);
154
+ process.value = pVal;
155
+ return;
156
+ case 'itd':
157
+ pVal = this.itdProcess(values);
158
+ process.value = pVal;
159
+ return;
160
+ case 'its':
161
+ pVal = this.itsProcess(values);
162
+ process.value = pVal;
163
+ return;
164
+ case 'bsv':
165
+ pVal = this.bsvProcess(values);
166
+ process.value = pVal;
167
+ return;
168
+ case 'vfa':
169
+ pVal = this.vfaProcess(values, process);
170
+ process.value = pVal;
171
+ return;
172
+ case 'cts':
173
+ pVal = this.ctsProcess(values);
174
+ process.value = pVal;
175
+ return;
176
+ }
177
+ }
178
+ assembleProcess(values) {
179
+ let result = '';
180
+ values.forEach((v) => {
181
+ result += v;
182
+ });
183
+ return result;
184
+ }
185
+ disassembleProcess(string, values) {
186
+ const result = {};
187
+ let i = 0;
188
+ let length = 0;
189
+ values.forEach((val) => {
190
+ if (Object.prototype.hasOwnProperty.call(val, 'strLength')) {
191
+ length = val.strLength;
192
+ }
193
+ else {
194
+ const str = val.value;
195
+ length = str.length;
196
+ }
197
+ if (val.fromData == 'raw') {
198
+ result[val.value] = Number(string.substring(i, i + length));
199
+ }
200
+ i = i + length;
201
+ });
202
+ //console.log('Disassemble Result ', JSON.stringify(result));
203
+ return result;
204
+ }
205
+ compareProcess(values, process) {
206
+ const result = this.compareValues(values[0], values[1], values[2]);
207
+ let text = 'N/A';
208
+ if ('comTxt' in process) {
209
+ if (process.comTxt !== undefined) {
210
+ if (result) {
211
+ text = process.comTxt[0];
212
+ }
213
+ else {
214
+ return process.comTxt[1];
215
+ }
216
+ }
217
+ }
218
+ return text;
219
+ }
220
+ compareValues(v1, op, v2) {
221
+ switch (op) {
222
+ case '<':
223
+ return v1 < v2;
224
+ case '<=':
225
+ return v1 <= v2;
226
+ case '==':
227
+ return v1 == v2;
228
+ case '>=':
229
+ return v1 >= v2;
230
+ case '>':
231
+ return v1 > v2;
232
+ default:
233
+ return false;
234
+ }
235
+ }
236
+ calculateProcess(values) {
237
+ return this.calculateValues(values[0], values[1], values[2]);
238
+ }
239
+ calculateValues(v1, op, v2) {
240
+ switch (op) {
241
+ case '+':
242
+ return v1 + v2;
243
+ case '-':
244
+ return v1 - v2;
245
+ case '/':
246
+ return v1 / v2;
247
+ case '*':
248
+ return v1 * v2;
249
+ default:
250
+ return 0;
251
+ }
252
+ }
253
+ tfmProcess(values) {
254
+ const hours = Math.floor((values[0] * 60) / 3600);
255
+ const mins = Math.floor((values[0] * 60 - hours * 3600) / 60);
256
+ return this.displayTime(hours, mins);
257
+ }
258
+ cdtProcess(values) {
259
+ const hours = parseInt(values[0].substring(11, 13));
260
+ const mins = parseInt(values[0].substring(14, 16));
261
+ return this.displayTime(hours, mins);
262
+ }
263
+ //New process to pick value from array based on interger value
264
+ vfaProcess(values, process) {
265
+ const value = values[0];
266
+ if (process.valuesList !== undefined) {
267
+ if (value < process.valuesList.length) {
268
+ return process.valuesList[value];
269
+ }
270
+ else {
271
+ return 'nip';
272
+ }
273
+ }
274
+ else {
275
+ return 'n/a';
276
+ }
277
+ }
278
+ itdProcess(values) {
279
+ let hours = Math.floor((values[0] * 60) / 3600);
280
+ //console.log("hours ", hours);
281
+ const mins = Math.floor((values[0] * 60 - hours * 3600) / 60);
282
+ //console.log("mins ", mins);
283
+ let h;
284
+ let m;
285
+ if (hours > 23) {
286
+ hours = hours - 24;
287
+ }
288
+ if (hours < 10) {
289
+ h = '0' + hours;
290
+ }
291
+ else {
292
+ h = hours;
293
+ }
294
+ if (mins < 10) {
295
+ m = '0' + mins;
296
+ }
297
+ else {
298
+ m = mins;
299
+ }
300
+ const string = '0000-00-00T' + h + ':' + m;
301
+ //console.log("$%^&&^%%$$%^&&&^%%%%^^^&&&^^%^%%%^^^& dt string ", string);
302
+ return string;
303
+ }
304
+ dtiProcess(string, values) {
305
+ //console.log("dtiProcess inputs string: ", string, " Values: ", values);
306
+ const result = {};
307
+ let h;
308
+ let m;
309
+ values.forEach((val) => {
310
+ // h = Number(string.substr(11, 2));
311
+ // m = Number(string.substr(14, 2));
312
+ h = Number(string.substring(11, 13));
313
+ m = Number(string.substring(14, 16));
314
+ result[val.value] = h * 60 + m;
315
+ });
316
+ //console.log("date to integer Result ", JSON.stringify(result));
317
+ return result;
318
+ }
319
+ itsProcess(values) {
320
+ //console.log('itsProcess values', JSON.stringify(values));
321
+ const str = values[0].toString();
322
+ return str;
323
+ }
324
+ stiProcess(string, values) {
325
+ const result = {};
326
+ values.forEach((val) => {
327
+ result[val.value] = Number(string);
328
+ });
329
+ //console.log("string to integer Result ", JSON.stringify(result));
330
+ return result;
331
+ }
332
+ bsvProcess(values) {
333
+ const startValue = values[0];
334
+ const pos1 = values[1];
335
+ const pos2 = pos1 + 1;
336
+ const binaryStr = parseInt(startValue, 10)
337
+ .toString(2)
338
+ .padStart(4, '0');
339
+ return binaryStr.substring(pos1, pos2);
340
+ }
341
+ bsvRevert(string, values, bssObj) {
342
+ if (Object.prototype.hasOwnProperty.call(bssObj, values[0].value)) {
343
+ bssObj[values[0].value] = this.replaceCharAt(bssObj[values[0].value], values[1].value, string);
344
+ }
345
+ else {
346
+ bssObj[values[0].value] = '0000';
347
+ bssObj[values[0].value] = this.replaceCharAt(bssObj[values[0].value], values[1].value, string);
348
+ }
349
+ return bssObj;
350
+ }
351
+ stcProcess(value) {
352
+ const initArray = value.split('');
353
+ const resultArray = [];
354
+ initArray.forEach((v) => {
355
+ resultArray.push(v.charCodeAt(0));
356
+ });
357
+ return resultArray;
358
+ }
359
+ ctsProcess(values) {
360
+ // let result: string = "";
361
+ const ary = [];
362
+ values.forEach((v) => {
363
+ if (v >= 0) {
364
+ ary.push(v);
365
+ }
366
+ else {
367
+ ary.push(0);
368
+ }
369
+ });
370
+ //console.log("CTS PROCESS INPUT VALUES ", values);
371
+ let str = String.fromCharCode(...ary);
372
+ // eslint-disable-next-line no-control-regex
373
+ str = str.replace(/[\u0000]/g, '');
374
+ //str = str.replace(/[^\x20-\x7E]/g, "");
375
+ return str;
376
+ }
377
+ ctsRevert(otherObj, results) {
378
+ const valAry = this.stcProcess(otherObj.value);
379
+ //console.log("VAL ARRAY", valAry);
380
+ //console.log("PROCESS DATA", JSON.stringify(otherObj.processData));
381
+ let progress = 0;
382
+ otherObj.processData[0].data.forEach((process) => {
383
+ const res = {};
384
+ if (valAry.length >= progress) {
385
+ res[process.value] = valAry[progress];
386
+ }
387
+ else {
388
+ res[process.value] = 0;
389
+ }
390
+ results = Object.assign(results, res);
391
+ ++progress;
392
+ });
393
+ return results;
394
+ }
395
+ binaryStrToDecimal(str) {
396
+ return parseInt(str, 2);
397
+ }
398
+ replaceCharAt(string, index, char) {
399
+ return (string.substring(0, index) + char + string.substring(index + char.length));
400
+ //return string.substr(0, index) + char + string.substr(index + char.length);
401
+ }
402
+ writeFormValuesToRawObj(formValues, rawObj) {
403
+ // rawObj.forEach((raw) => {
404
+ // if (formValues.hasOwnProperty(raw.name)) {
405
+ // raw.value = Math.round(formValues[raw.name] / raw.multi);
406
+ // }
407
+ // });
408
+ for (let i = 0; i < rawObj.length; i++) {
409
+ if (Object.prototype.hasOwnProperty.call(formValues, rawObj[i].name)) {
410
+ rawObj[i].value = Math.round(formValues[rawObj[i].name] / rawObj[i].multi);
411
+ }
412
+ }
413
+ return rawObj;
414
+ }
415
+ getPwd(rawValues) {
416
+ const pwdArray = [];
417
+ let i;
418
+ let name;
419
+ for (i = 0; i < 16; i++) {
420
+ if (i < 10) {
421
+ name = 'pass_0' + i;
422
+ }
423
+ else {
424
+ name = 'pass_' + i;
425
+ }
426
+ rawValues.forEach((v) => {
427
+ if (v.name == name) {
428
+ pwdArray.push(v.value);
429
+ }
430
+ });
431
+ }
432
+ return pwdArray;
433
+ }
434
+ strToPwd(string) {
435
+ const pwdArray = [];
436
+ let i;
437
+ if (string == null) {
438
+ string = '';
439
+ }
440
+ for (i = 0; i < 16; i++) {
441
+ if (i < string.length) {
442
+ pwdArray.push(string.charCodeAt(i));
443
+ }
444
+ else {
445
+ pwdArray.push(0);
446
+ }
447
+ }
448
+ return pwdArray;
449
+ }
450
+ chkPwd(arr1, arr2) {
451
+ if (!Array.isArray(arr1) ||
452
+ !Array.isArray(arr2) ||
453
+ arr1.length !== arr2.length)
454
+ return false;
455
+ for (let i = 0; i < arr1.length; i++) {
456
+ if (arr1[i] !== arr2[i])
457
+ return false;
458
+ }
459
+ return true;
460
+ }
461
+ writePwdToConfig(passArray, rawObj) {
462
+ let i;
463
+ let name;
464
+ //console.log("Before write password ", JSON.stringify(rawObj));
465
+ for (i = 0; i < 16; i++) {
466
+ if (i < 10) {
467
+ name = 'pass_0' + i;
468
+ }
469
+ else {
470
+ name = 'pass_' + i;
471
+ }
472
+ rawObj.forEach((v) => {
473
+ if (v.name == name) {
474
+ v.value = passArray[i];
475
+ }
476
+ });
477
+ }
478
+ //console.log("After write password ", JSON.stringify(rawObj));
479
+ return rawObj;
480
+ }
481
+ displayTime(hours, mins) {
482
+ //console.log("hours = ", hours, " mins = ", mins);
483
+ let m = mins;
484
+ let p = 'am';
485
+ if (mins < 10) {
486
+ m = '0' + mins;
487
+ }
488
+ if (hours > 11) {
489
+ p = 'pm';
490
+ }
491
+ if (hours == 0) {
492
+ hours = 12;
493
+ }
494
+ if (hours > 12) {
495
+ hours -= 12;
496
+ }
497
+ return hours + ':' + m + ' ' + p;
498
+ }
499
+ getChunkValues(processData, rawData, otherData) {
500
+ // console.log(
501
+ // 'GET CHUNK VALUES ',
502
+ // JSON.stringify(rawData),
503
+ // ' ',
504
+ // JSON.stringify(otherData)
505
+ // );
506
+ let v;
507
+ const values = [];
508
+ processData.forEach((chunk) => {
509
+ //console.log('Process Raw chunk ', JSON.stringify(chunk));
510
+ switch (chunk.fromData) {
511
+ case 'raw':
512
+ rawData.forEach((rd) => {
513
+ if (rd.name == chunk.value) {
514
+ //console.log('RAW chunk name: ', rd.name);
515
+ v = rd.value;
516
+ }
517
+ });
518
+ break;
519
+ case 'other':
520
+ otherData.forEach((od) => {
521
+ if (od.name == chunk.value) {
522
+ v = od.value;
523
+ }
524
+ });
525
+ break;
526
+ case 'no':
527
+ v = chunk.value;
528
+ break;
529
+ }
530
+ if (typeof chunk.strLength === 'undefined') {
531
+ values.push(v);
532
+ }
533
+ else {
534
+ const pad = v.toString().padStart(chunk.strLength, '0');
535
+ values.push(pad);
536
+ }
537
+ });
538
+ return values;
539
+ }
540
+ uint8ArrayToArray(uint8) {
541
+ return Array.from(uint8);
542
+ }
543
+ arrayToUint8Array(array) {
544
+ return Uint8Array.from(array);
545
+ }
546
+ isUint8Array(v) {
547
+ const isStr = Object.prototype.toString;
548
+ return isStr.call(v) === '[object Uint8Array]';
549
+ }
550
+ processRaw(input, configObj) {
551
+ let buffer;
552
+ if (this.isUint8Array(input)) {
553
+ buffer = input;
554
+ }
555
+ else {
556
+ buffer = this.arrayToUint8Array(input);
557
+ }
558
+ const rawDataBuffer = new DataView(buffer.buffer, 0, 254);
559
+ //console.log('PROCESS RAW CONFIG ', rawDataBuffer);
560
+ configObj.rawData.forEach((datapoint) => {
561
+ datapoint.value =
562
+ this.getValuefromBuffer(datapoint.buffer, rawDataBuffer) *
563
+ datapoint.multi;
564
+ });
565
+ }
566
+ processOther(configObj) {
567
+ configObj.otherData.forEach((dataPoint) => {
568
+ dataPoint.processData.forEach((process) => {
569
+ this.runProcess(process, configObj.rawData, configObj.otherData);
570
+ dataPoint.value = process.value;
571
+ });
572
+ });
573
+ }
574
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatasetProcessingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
575
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatasetProcessingService, providedIn: 'root' }); }
576
+ }
577
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DatasetProcessingService, decorators: [{
578
+ type: Injectable,
579
+ args: [{
580
+ providedIn: 'root',
581
+ }]
582
+ }] });
583
+
584
+ class CrcCheckService {
585
+ constructor() {
586
+ // checksum arrays
587
+ this.auchCRCHi = [
588
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
589
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40,
590
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
591
+ 0x00, 0xc1, 0x81, 0x40, 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41,
592
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
593
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40,
594
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40,
595
+ 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40,
596
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
597
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40,
598
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
599
+ 0x00, 0xc1, 0x81, 0x40, 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41,
600
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
601
+ 0x00, 0xc1, 0x81, 0x40, 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41,
602
+ 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41,
603
+ 0x00, 0xc1, 0x81, 0x40, 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41,
604
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
605
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40,
606
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
607
+ 0x00, 0xc1, 0x81, 0x40, 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41,
608
+ 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, 0x01, 0xc0, 0x80, 0x41,
609
+ 0x00, 0xc1, 0x81, 0x40,
610
+ ];
611
+ this.auchCRCLo = [
612
+ 0x00, 0xc0, 0xc1, 0x01, 0xc3, 0x03, 0x02, 0xc2, 0xc6, 0x06, 0x07, 0xc7,
613
+ 0x05, 0xc5, 0xc4, 0x04, 0xcc, 0x0c, 0x0d, 0xcd, 0x0f, 0xcf, 0xce, 0x0e,
614
+ 0x0a, 0xca, 0xcb, 0x0b, 0xc9, 0x09, 0x08, 0xc8, 0xd8, 0x18, 0x19, 0xd9,
615
+ 0x1b, 0xdb, 0xda, 0x1a, 0x1e, 0xde, 0xdf, 0x1f, 0xdd, 0x1d, 0x1c, 0xdc,
616
+ 0x14, 0xd4, 0xd5, 0x15, 0xd7, 0x17, 0x16, 0xd6, 0xd2, 0x12, 0x13, 0xd3,
617
+ 0x11, 0xd1, 0xd0, 0x10, 0xf0, 0x30, 0x31, 0xf1, 0x33, 0xf3, 0xf2, 0x32,
618
+ 0x36, 0xf6, 0xf7, 0x37, 0xf5, 0x35, 0x34, 0xf4, 0x3c, 0xfc, 0xfd, 0x3d,
619
+ 0xff, 0x3f, 0x3e, 0xfe, 0xfa, 0x3a, 0x3b, 0xfb, 0x39, 0xf9, 0xf8, 0x38,
620
+ 0x28, 0xe8, 0xe9, 0x29, 0xeb, 0x2b, 0x2a, 0xea, 0xee, 0x2e, 0x2f, 0xef,
621
+ 0x2d, 0xed, 0xec, 0x2c, 0xe4, 0x24, 0x25, 0xe5, 0x27, 0xe7, 0xe6, 0x26,
622
+ 0x22, 0xe2, 0xe3, 0x23, 0xe1, 0x21, 0x20, 0xe0, 0xa0, 0x60, 0x61, 0xa1,
623
+ 0x63, 0xa3, 0xa2, 0x62, 0x66, 0xa6, 0xa7, 0x67, 0xa5, 0x65, 0x64, 0xa4,
624
+ 0x6c, 0xac, 0xad, 0x6d, 0xaf, 0x6f, 0x6e, 0xae, 0xaa, 0x6a, 0x6b, 0xab,
625
+ 0x69, 0xa9, 0xa8, 0x68, 0x78, 0xb8, 0xb9, 0x79, 0xbb, 0x7b, 0x7a, 0xba,
626
+ 0xbe, 0x7e, 0x7f, 0xbf, 0x7d, 0xbd, 0xbc, 0x7c, 0xb4, 0x74, 0x75, 0xb5,
627
+ 0x77, 0xb7, 0xb6, 0x76, 0x72, 0xb2, 0xb3, 0x73, 0xb1, 0x71, 0x70, 0xb0,
628
+ 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, 0x96, 0x56, 0x57, 0x97,
629
+ 0x55, 0x95, 0x94, 0x54, 0x9c, 0x5c, 0x5d, 0x9d, 0x5f, 0x9f, 0x9e, 0x5e,
630
+ 0x5a, 0x9a, 0x9b, 0x5b, 0x99, 0x59, 0x58, 0x98, 0x88, 0x48, 0x49, 0x89,
631
+ 0x4b, 0x8b, 0x8a, 0x4a, 0x4e, 0x8e, 0x8f, 0x4f, 0x8d, 0x4d, 0x4c, 0x8c,
632
+ 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83,
633
+ 0x41, 0x81, 0x80, 0x40,
634
+ ];
635
+ }
636
+ //constructor() {}
637
+ _buildCRC(puchMsg, usDataLen, startIndex = 0) {
638
+ console.log('Start of CRC check generation.');
639
+ let uchCRCHi = 0xff; /* high byte of CRC initialized */
640
+ let uchCRCLo = 0xff; /* low byte of CRC initialized */
641
+ let uIndex; /* will index into CRC lookup table */
642
+ let bufferIndex = startIndex;
643
+ while (usDataLen--) {
644
+ uIndex = uchCRCLo ^ puchMsg[bufferIndex]; /* calculate the CRC */
645
+ bufferIndex++;
646
+ uchCRCLo = uchCRCHi ^ this.auchCRCHi[uIndex];
647
+ uchCRCHi = this.auchCRCLo[uIndex];
648
+ }
649
+ return [uchCRCHi, uchCRCLo];
650
+ }
651
+ /**
652
+ *
653
+ * @param sentValuePair
654
+ * @param receivedValuePair
655
+ * @returns
656
+ */
657
+ saveCheck(sentValuePair, receivedValuePair) {
658
+ console.log('CRC save check sent ', sentValuePair, ' recieved ', receivedValuePair);
659
+ if (sentValuePair[0] === receivedValuePair[0] &&
660
+ sentValuePair[1] === receivedValuePair[1]) {
661
+ console.log('CRC compare check TRUE');
662
+ return true;
663
+ }
664
+ else {
665
+ console.log('CRC compare check FALSE');
666
+ return false;
667
+ }
668
+ }
669
+ async writeCrcToCommand(commandData) {
670
+ console.log('WRITE CRC TO COMMAND TRIGGERED ');
671
+ const checkSum = this._buildCRC(commandData.byteData, commandData.byteData.length - 2);
672
+ console.log('###### ####### CRC16 values ', checkSum);
673
+ commandData.byteData[253] = checkSum[0];
674
+ commandData.byteData[254] = checkSum[1];
675
+ return commandData;
676
+ }
677
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CrcCheckService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
678
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CrcCheckService, providedIn: 'root' }); }
679
+ }
680
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CrcCheckService, decorators: [{
681
+ type: Injectable,
682
+ args: [{
683
+ providedIn: 'root',
684
+ }]
685
+ }] });
686
+
687
+ class CommandService {
688
+ constructor(dps, crcService) {
689
+ this.dps = dps;
690
+ this.crcService = crcService;
691
+ }
692
+ /**
693
+ * For Bluetooth command send
694
+ * @param currentDevice
695
+ * @param command
696
+ * @param rawDataObj
697
+ * @returns
698
+ */
699
+ async createCommandData(currentDevice, command, rawDataObj) {
700
+ let opCode = 0;
701
+ const comandBuffer = new ArrayBuffer(currentDevice.write.bufferSize);
702
+ currentDevice.commands.forEach((commandObj) => {
703
+ //console.log('Command Name', commandObj.name);
704
+ if (command == commandObj.name) {
705
+ opCode = parseInt(commandObj.opCode);
706
+ }
707
+ });
708
+ //console.log('########### $$$$$$$$$$$$ Op Code ', opCode);
709
+ if (rawDataObj !== undefined) {
710
+ //console.log('create Command Data, Raw Data Object is present.');
711
+ const dataView = new DataView(comandBuffer);
712
+ rawDataObj.forEach((raw) => {
713
+ this.dps.writeValueToBuffer(raw.buffer, raw.value, dataView);
714
+ });
715
+ }
716
+ let commandData = {
717
+ opCode: opCode,
718
+ service: currentDevice.write.service,
719
+ characteristic: currentDevice.write.characteristic,
720
+ byteData: new Uint8Array(comandBuffer),
721
+ };
722
+ commandData.byteData[0] = commandData.opCode;
723
+ commandData = await this.crcService.writeCrcToCommand(commandData);
724
+ return commandData;
725
+ }
726
+ async createCommandDataForApi(currentDevice, command, rawDataObj) {
727
+ let raw = undefined;
728
+ if (rawDataObj !== undefined) {
729
+ raw = rawDataObj;
730
+ }
731
+ const commandBt = this.createCommandData(currentDevice, command, raw);
732
+ const send = {
733
+ serialNumber: currentDevice.serial.toString(),
734
+ data: this.dps.uint8ArrayToArray((await commandBt).byteData),
735
+ };
736
+ //console.log(JSON.stringify(send));
737
+ return send;
738
+ }
739
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CommandService, deps: [{ token: DatasetProcessingService }, { token: CrcCheckService }], target: i0.ɵɵFactoryTarget.Injectable }); }
740
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CommandService, providedIn: 'root' }); }
741
+ }
742
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CommandService, decorators: [{
743
+ type: Injectable,
744
+ args: [{
745
+ providedIn: 'root',
746
+ }]
747
+ }], ctorParameters: function () { return [{ type: DatasetProcessingService }, { type: CrcCheckService }]; } });
748
+
749
+ class DeviceConfigDatasetService {
750
+ constructor(dps, formBuilder) {
751
+ this.dps = dps;
752
+ this.formBuilder = formBuilder;
753
+ }
754
+ processConfig(buffer, config) {
755
+ this.dps.processRaw(buffer, config);
756
+ this.dps.processOther(config);
757
+ this.processForm(config);
758
+ return config;
759
+ }
760
+ processForm(config) {
761
+ //console.log("Starting to process form data");
762
+ config.formData.forEach((formSection) => {
763
+ formSection.dataObjs.forEach((formControl) => {
764
+ config.rawData.forEach((dp) => {
765
+ if (formControl.dataId == dp.name) {
766
+ formControl.value = dp.value;
767
+ }
768
+ });
769
+ config.otherData.forEach((dp) => {
770
+ if (formControl.dataId == dp.name) {
771
+ formControl.value = dp.value;
772
+ }
773
+ });
774
+ });
775
+ });
776
+ }
777
+ processResultsToFormData(formResults, config) {
778
+ for (let i = 0; i < config.formData.length; i++) {
779
+ for (let x = 0; x < config.formData[i].dataObjs.length; x++) {
780
+ if (Object.prototype.hasOwnProperty.call(formResults, config.formData[i].dataObjs[x].dataId)) {
781
+ config.formData[i].dataObjs[x].value =
782
+ formResults[config.formData[i].dataObjs[x].dataId];
783
+ }
784
+ if (Object.prototype.hasOwnProperty.call(config.formData[i].dataObjs[x], 'autoInput')) {
785
+ if (config.formData[i].dataObjs[x].autoInput == true) {
786
+ //console.log("auto date condition met");
787
+ config.formData[i].dataObjs[x].value = this.currentDateTimeStr();
788
+ }
789
+ }
790
+ }
791
+ }
792
+ //console.log("formdata object updated", JSON.stringify(config.formData));
793
+ return config;
794
+ }
795
+ currentDateTimeStr() {
796
+ const date = new Date();
797
+ const str = date.getFullYear() +
798
+ '-' +
799
+ (date.getMonth() + 1).toString().padStart(2, '0') +
800
+ '-' +
801
+ date.getDate().toString().padStart(2, '0') +
802
+ 'T' +
803
+ date.getHours().toString().padStart(2, '0') +
804
+ ':' +
805
+ date.getMinutes().toString().padStart(2, '0');
806
+ return str;
807
+ }
808
+ extractBackToRaw(config) {
809
+ const otherToProcess = {};
810
+ let valuesToRaw = {};
811
+ let bss = {};
812
+ if (Object.prototype.hasOwnProperty.call(config, 'formData')) {
813
+ for (let i = 0; i < config.formData.length; i++) {
814
+ for (let x = 0; x < config.formData[i].dataObjs.length; x++) {
815
+ let isRawData = false;
816
+ for (let z = 0; z < config.rawData.length; z++) {
817
+ if (config.rawData[z].name == config.formData[i].dataObjs[x].dataId) {
818
+ valuesToRaw[config.formData[i].dataObjs[x].dataId] =
819
+ config.formData[i].dataObjs[x].value;
820
+ isRawData = true;
821
+ }
822
+ }
823
+ if (isRawData == false) {
824
+ otherToProcess[config.formData[i].dataObjs[x].dataId] =
825
+ config.formData[i].dataObjs[x].value;
826
+ }
827
+ }
828
+ }
829
+ }
830
+ else {
831
+ config.otherData.forEach((otherObj) => {
832
+ otherToProcess[otherObj.name] = otherObj.value;
833
+ });
834
+ }
835
+ //console.log('Other to Process ', JSON.stringify(otherToProcess));
836
+ config.otherData.forEach((otherObj) => {
837
+ const value = otherToProcess[otherObj.name];
838
+ // console.log(
839
+ // 'EXTRACT BACK TO RAW ',
840
+ // ' ',
841
+ // otherObj.name,
842
+ // ' ',
843
+ // JSON.stringify(value)
844
+ // );
845
+ otherObj.processData.forEach((pdo) => {
846
+ switch (pdo.type) {
847
+ case 'ass':
848
+ valuesToRaw = Object.assign(valuesToRaw, this.dps.disassembleProcess(value, pdo.data));
849
+ return;
850
+ case 'itd':
851
+ valuesToRaw = Object.assign(valuesToRaw, this.dps.dtiProcess(value, pdo.data));
852
+ return;
853
+ case 'its':
854
+ valuesToRaw = Object.assign(valuesToRaw, this.dps.stiProcess(value, pdo.data));
855
+ return;
856
+ case 'bsv':
857
+ bss = this.dps.bsvRevert(value, pdo.data, bss);
858
+ return;
859
+ }
860
+ });
861
+ });
862
+ if (Object.keys(bss).length > 0) {
863
+ for (const str in bss) {
864
+ valuesToRaw[str] = this.dps.binaryStrToDecimal(bss[str]);
865
+ }
866
+ }
867
+ config.rawData = this.dps.writeFormValuesToRawObj(valuesToRaw, config.rawData);
868
+ //console.log("rawData Obj ", JSON.stringify(config.rawData));
869
+ return config;
870
+ }
871
+ generateValidationRules(formField) {
872
+ const validators = [];
873
+ if (formField.required == true) {
874
+ validators.push(Validators.required);
875
+ }
876
+ if (Object.prototype.hasOwnProperty.call(formField, 'min')) {
877
+ if (formField.min !== undefined)
878
+ validators.push(Validators.min(formField.min));
879
+ }
880
+ if (Object.prototype.hasOwnProperty.call(formField, 'max')) {
881
+ if (formField.max !== undefined)
882
+ validators.push(Validators.max(formField.max));
883
+ }
884
+ if (Object.prototype.hasOwnProperty.call(formField, 'minLength')) {
885
+ if (formField.minLength !== undefined)
886
+ validators.push(Validators.minLength(formField.minLength));
887
+ }
888
+ if (Object.prototype.hasOwnProperty.call(formField, 'maxLength')) {
889
+ if (formField.maxLength !== undefined)
890
+ validators.push(Validators.maxLength(formField.maxLength));
891
+ }
892
+ if (Object.prototype.hasOwnProperty.call(formField, 'rex')) {
893
+ if (formField.rex !== undefined)
894
+ validators.push(Validators.pattern(formField.rex));
895
+ }
896
+ return validators;
897
+ }
898
+ generateFormGroup(config, blackList) {
899
+ //console.log('Generate form group TRIGGERED');
900
+ const configForm = new UntypedFormGroup({});
901
+ for (let i = 0; i < config.formData.length; i++) {
902
+ //console.log("FORM SECTION ", JSON.stringify(config.formData[i]));
903
+ for (let x = 0; x < config.formData[i].dataObjs.length; x++) {
904
+ if (!blackList.includes(config.formData[i].title)) {
905
+ let fieldDisable = false;
906
+ const validators = this.generateValidationRules(config.formData[i].dataObjs[x]);
907
+ if (!config.formData[i].dataObjs[x].active) {
908
+ fieldDisable = true;
909
+ }
910
+ //console.log('ADD CONTROL');
911
+ configForm.addControl(config.formData[i].dataObjs[x].dataId, new UntypedFormControl({
912
+ value: config.formData[i].dataObjs[x].value,
913
+ disabled: fieldDisable,
914
+ }, validators));
915
+ }
916
+ }
917
+ }
918
+ //console.log('END OF GENERATE FORMGROUP');
919
+ return configForm;
920
+ }
921
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DeviceConfigDatasetService, deps: [{ token: DatasetProcessingService }, { token: i2.UntypedFormBuilder }], target: i0.ɵɵFactoryTarget.Injectable }); }
922
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DeviceConfigDatasetService, providedIn: 'root' }); }
923
+ }
924
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DeviceConfigDatasetService, decorators: [{
925
+ type: Injectable,
926
+ args: [{
927
+ providedIn: 'root',
928
+ }]
929
+ }], ctorParameters: function () { return [{ type: DatasetProcessingService }, { type: i2.UntypedFormBuilder }]; } });
930
+
931
+ class DeviceLiveDatasetService {
932
+ constructor(dps) {
933
+ this.dps = dps;
934
+ }
935
+ processDisplay(buffer, display) {
936
+ this.dps.processRaw(buffer, display);
937
+ this.dps.processOther(display);
938
+ this.processLayout(display);
939
+ return display;
940
+ }
941
+ processLayout(display) {
942
+ display.layout.forEach((section) => {
943
+ section.rows.forEach((row) => {
944
+ row.cols.forEach((col) => {
945
+ let wv = '';
946
+ if (typeof col.refData !== 'undefined') {
947
+ display.rawData.forEach((raw) => {
948
+ if (raw.name == col.refData) {
949
+ if (typeof col.round !== 'undefined') {
950
+ wv = raw.value.toFixed(col.round);
951
+ }
952
+ else {
953
+ wv = raw.value;
954
+ }
955
+ }
956
+ });
957
+ display.otherData.forEach((other) => {
958
+ if (other.name == col.refData) {
959
+ wv = other.value;
960
+ }
961
+ });
962
+ if (typeof col.prepend !== 'undefined') {
963
+ wv = col.prepend + wv;
964
+ }
965
+ if (typeof col.append !== 'undefined') {
966
+ wv = wv + col.append;
967
+ }
968
+ col.value = wv;
969
+ }
970
+ });
971
+ });
972
+ });
973
+ }
974
+ async rssiData(device, rssiSignal) {
975
+ const result = { deviceName: 'N/A', rssi: 'N/A' };
976
+ if (device != null) {
977
+ result.deviceName = device.name;
978
+ const rssi = await rssiSignal();
979
+ if (rssi <= 0) {
980
+ result.rssi = rssi.toString() + ' dBa';
981
+ }
982
+ }
983
+ return result;
984
+ }
985
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DeviceLiveDatasetService, deps: [{ token: DatasetProcessingService }], target: i0.ɵɵFactoryTarget.Injectable }); }
986
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DeviceLiveDatasetService, providedIn: 'root' }); }
987
+ }
988
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DeviceLiveDatasetService, decorators: [{
989
+ type: Injectable,
990
+ args: [{
991
+ providedIn: 'root',
992
+ }]
993
+ }], ctorParameters: function () { return [{ type: DatasetProcessingService }]; } });
994
+
995
+ class CpDevicesListModule {
996
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CpDevicesListModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
997
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: CpDevicesListModule }); }
998
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CpDevicesListModule }); }
999
+ }
1000
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CpDevicesListModule, decorators: [{
1001
+ type: NgModule,
1002
+ args: [{
1003
+ declarations: [],
1004
+ imports: [],
1005
+ exports: [],
1006
+ }]
1007
+ }] });
1008
+
1009
+ /*
1010
+ * Public API Surface of device-config-interaction
1011
+ */
1012
+
1013
+ /**
1014
+ * Generated bundle index. Do not edit.
1015
+ */
1016
+
1017
+ export { CommandService, CpDevicesListModule, CpDevicesListService, CrcCheckService, DatasetProcessingService, DeviceConfigDatasetService, DeviceLiveDatasetService };
1018
+ //# sourceMappingURL=catchpower-device-config-interaction.mjs.map