@ncd-io/node-red-enterprise-sensors 2.0.1 → 2.0.3

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,931 @@
1
+ const { toMac, signInt, msbLsb } = require('../utils');
2
+
3
+ // --- 1. DEFINE LOCAL FUNCTIONS ---
4
+ // These are defined as local variables so they can call each other easily.
5
+ module.exports = (globalDevices) => {
6
+
7
+ const get_write_buffer_size = (firmware) => {
8
+ return 90;
9
+ };
10
+
11
+ const get_config_map = (firmware) => {
12
+ console.log('Generating sync map for firmware version', firmware);
13
+
14
+ return {
15
+ "core_version": {
16
+ "read_index": 3,
17
+ "descriptions": {
18
+ "title": "Core Version",
19
+ "main_caption": "The version of the core communication stack."
20
+ },
21
+ "validator": {
22
+ "type": "uint8"
23
+ },
24
+ "tags": [
25
+ "system"
26
+ ]
27
+ },
28
+ "firmware_version": {
29
+ "read_index": 4,
30
+ "descriptions": {
31
+ "title": "Firmware Version",
32
+ "main_caption": "The application-specific firmware version."
33
+ },
34
+ "validator": {
35
+ "type": "uint8"
36
+ },
37
+ "tags": [
38
+ "system"
39
+ ]
40
+ },
41
+ "sensor_type": {
42
+ "read_index": 5,
43
+ "descriptions": {
44
+ "title": "Sensor Type",
45
+ "main_caption": "The hardware identifier for the specific sensor model."
46
+ },
47
+ "validator": {
48
+ "type": "uint16be"
49
+ },
50
+ "tags": [
51
+ "system"
52
+ ]
53
+ },
54
+ "tx_lifetime_counter": {
55
+ "read_index": 7,
56
+ "descriptions": {
57
+ "title": "Sampling Interval",
58
+ "main_caption": "Set how often will the sensor transmit measurement data. Note: For this sensor, this value functions as the sampling interval rather than a traditional delay.",
59
+ "sub_caption": "Default value: 20 milliseconds."
60
+ },
61
+ "validator": {
62
+ "type": "uint32be"
63
+ },
64
+ "tags": [
65
+ "diagnostics"
66
+ ]
67
+ },
68
+ "hardware_id": {
69
+ "read_index": 11,
70
+ "length": 3,
71
+ "descriptions": {
72
+ "title": "Hardware ID",
73
+ "main_caption": "A unique 3-byte hardware identifier."
74
+ },
75
+ "validator": {
76
+ "type": "buffer"
77
+ },
78
+ "tags": [
79
+ "system"
80
+ ]
81
+ },
82
+ "network_id": {
83
+ "read_index": 14,
84
+ "write_index": 3,
85
+ "length": 2,
86
+ "descriptions": {
87
+ "title": "Network ID",
88
+ "main_caption": ""
89
+ },
90
+ "default_value": "7fff",
91
+ "validator": {
92
+ "type": "hex",
93
+ "length": 4
94
+ },
95
+ "html_id": "pan_id",
96
+ "tags": [
97
+ "communications"
98
+ ]
99
+ },
100
+ "destination_address": {
101
+ "read_index": 16,
102
+ "write_index": 5,
103
+ "length": 4,
104
+ "descriptions": {
105
+ "title": "Destination Address",
106
+ "main_caption": ""
107
+ },
108
+ "default_value": "0000ffff",
109
+ "validator": {
110
+ "type": "mac",
111
+ "length": 8
112
+ },
113
+ "html_id": "destination",
114
+ "tags": [
115
+ "communications"
116
+ ]
117
+ },
118
+ "node_id": {
119
+ "read_index": 20,
120
+ "write_index": 9,
121
+ "descriptions": {
122
+ "title": "Node ID",
123
+ "main_caption": ""
124
+ },
125
+ "default_value": "0",
126
+ "validator": {
127
+ "type": "uint8",
128
+ "min": 0,
129
+ "max": 255,
130
+ "generated": true
131
+ },
132
+ "html_id": "node_id",
133
+ "tags": [
134
+ "generic"
135
+ ]
136
+ },
137
+ "report_rate": {
138
+ "read_index": 21,
139
+ "write_index": 10,
140
+ "descriptions": {
141
+ "title": "Delay",
142
+ "main_caption": ""
143
+ },
144
+ "default_value": "600",
145
+ "validator": {
146
+ "type": "uint32be",
147
+ "min": 0,
148
+ "max": 65535,
149
+ "generated": true
150
+ },
151
+ "html_id": "delay",
152
+ "tags": [
153
+ "generic"
154
+ ]
155
+ },
156
+ "register_to_read": {
157
+ "read_index": 25,
158
+ "write_index": 14,
159
+ "descriptions": {
160
+ "title": "Set Read Registers",
161
+ "main_caption": "Set the total number of registers to read on interval in the Register Reads field. Set the individual Registers to read below in the correspond Register field.",
162
+ },
163
+ "default_value": 1,
164
+ "validator": {
165
+ "type": "uint8",
166
+ "min": 0,
167
+ "max": 32,
168
+ "generated": true
169
+ },
170
+ "options": {
171
+ "0": "0",
172
+ "1": "1",
173
+ "2": "2",
174
+ "3": "3",
175
+ "4": "4",
176
+ "5": "5",
177
+ "6": "6",
178
+ "7": "7",
179
+ "8": "8",
180
+ "9": "9",
181
+ "10": "10",
182
+ "11": "11",
183
+ "12": "12",
184
+ "13": "13",
185
+ "14": "14",
186
+ "15": "15",
187
+ "16": "16",
188
+ "17": "17",
189
+ "18": "18",
190
+ "19": "19",
191
+ "20": "20",
192
+ "21": "21",
193
+ "22": "22",
194
+ "23": "23",
195
+ "24": "24",
196
+ "25": "25",
197
+ "26": "26",
198
+ "27": "27",
199
+ "28": "28",
200
+ "29": "29",
201
+ "30": "30",
202
+ "31": "31",
203
+ "32": "32"
204
+ },
205
+ "tags": [
206
+ "Communications"
207
+ ],
208
+ "html_id": "number_of_regs_to_rd_539"
209
+ },
210
+ "modbus_register_1": {
211
+ "read_index": 26,
212
+ "write_index": 15,
213
+ "descriptions": {
214
+ "title": "Register 1:",
215
+ "main_caption": "",
216
+ },
217
+ "default_value": 10,
218
+ "validator": {
219
+ "type": "uint16be",
220
+ "min": 0,
221
+ "max": 65000,
222
+ "generated": true
223
+ },
224
+ "html_id": "register_value_1_539"
225
+ },
226
+ "modbus_register_2": {
227
+ "read_index": 28,
228
+ "write_index": 17,
229
+ "descriptions": {
230
+ "title": "Register 2:",
231
+ "main_caption": "",
232
+ },
233
+ "default_value": 10,
234
+ "validator": {
235
+ "type": "uint16be",
236
+ "min": 0,
237
+ "max": 65000,
238
+ "generated": true
239
+ },
240
+ "html_id": "register_value_2_539"
241
+ },
242
+ "modbus_register_3": {
243
+ "read_index": 30,
244
+ "write_index": 19,
245
+ "descriptions": {
246
+ "title": "Register 3:",
247
+ "main_caption": "",
248
+ },
249
+ "default_value": 10,
250
+ "validator": {
251
+ "type": "uint16be",
252
+ "min": 0,
253
+ "max": 65000,
254
+ "generated": true
255
+ },
256
+ "html_id": "register_value_3_539"
257
+ },
258
+ "modbus_register_4": {
259
+ "read_index": 32,
260
+ "write_index": 21,
261
+ "descriptions": {
262
+ "title": "Register 4:",
263
+ "main_caption": "",
264
+ },
265
+ "default_value": 10,
266
+ "validator": {
267
+ "type": "uint16be",
268
+ "min": 0,
269
+ "max": 65000,
270
+ "generated": true
271
+ },
272
+ "html_id": "register_value_4_539"
273
+ },
274
+ "modbus_register_5": {
275
+ "read_index": 34,
276
+ "write_index": 23,
277
+ "descriptions": {
278
+ "title": "Register 5:",
279
+ "main_caption": "",
280
+ },
281
+ "default_value": 10,
282
+ "validator": {
283
+ "type": "uint16be",
284
+ "min": 0,
285
+ "max": 65000,
286
+ "generated": true
287
+ },
288
+ "html_id": "register_value_5_539"
289
+ },
290
+ "modbus_register_6": {
291
+ "read_index": 36,
292
+ "write_index": 25,
293
+ "descriptions": {
294
+ "title": "Register 6:",
295
+ "main_caption": "",
296
+ },
297
+ "default_value": 10,
298
+ "validator": {
299
+ "type": "uint16be",
300
+ "min": 0,
301
+ "max": 65000,
302
+ "generated": true
303
+ },
304
+ "html_id": "register_value_6_539"
305
+ },
306
+ "modbus_register_7": {
307
+ "read_index": 38,
308
+ "write_index": 27,
309
+ "descriptions": {
310
+ "title": "Register 7:",
311
+ "main_caption": "",
312
+ },
313
+ "default_value": 10,
314
+ "validator": {
315
+ "type": "uint16be",
316
+ "min": 0,
317
+ "max": 65000,
318
+ "generated": true
319
+ },
320
+ "html_id": "register_value_7_539"
321
+ },
322
+ "modbus_register_8": {
323
+ "read_index": 40,
324
+ "write_index": 29,
325
+ "descriptions": {
326
+ "title": "Register 8:",
327
+ "main_caption": "",
328
+ },
329
+ "default_value": 10,
330
+ "validator": {
331
+ "type": "uint16be",
332
+ "min": 0,
333
+ "max": 65000,
334
+ "generated": true
335
+ },
336
+ "html_id": "register_value_8_539"
337
+ },
338
+ "modbus_register_9": {
339
+ "read_index": 42,
340
+ "write_index": 31,
341
+ "descriptions": {
342
+ "title": "Register 9:",
343
+ "main_caption": "",
344
+ },
345
+ "default_value": 10,
346
+ "validator": {
347
+ "type": "uint16be",
348
+ "min": 0,
349
+ "max": 65000,
350
+ "generated": true
351
+ },
352
+ "html_id": "register_value_9_539"
353
+ },
354
+ "modbus_register_10": {
355
+ "read_index": 44,
356
+ "write_index": 33,
357
+ "descriptions": {
358
+ "title": "Register 10:",
359
+ "main_caption": "",
360
+ },
361
+ "default_value": 10,
362
+ "validator": {
363
+ "type": "uint16be",
364
+ "min": 0,
365
+ "max": 65000,
366
+ "generated": true
367
+ },
368
+ "html_id": "register_value_10_539"
369
+ },
370
+ "modbus_register_11": {
371
+ "read_index": 46,
372
+ "write_index": 35,
373
+ "descriptions": {
374
+ "title": "Register 11:",
375
+ "main_caption": "",
376
+ },
377
+ "default_value": 10,
378
+ "validator": {
379
+ "type": "uint16be",
380
+ "min": 0,
381
+ "max": 65000,
382
+ "generated": true
383
+ },
384
+ "html_id": "register_value_11_539"
385
+ },
386
+ "modbus_register_12": {
387
+ "read_index": 48,
388
+ "write_index": 37,
389
+ "descriptions": {
390
+ "title": "Register 12:",
391
+ "main_caption": "",
392
+ },
393
+ "default_value": 10,
394
+ "validator": {
395
+ "type": "uint16be",
396
+ "min": 0,
397
+ "max": 65000,
398
+ "generated": true
399
+ },
400
+ "html_id": "register_value_12_539"
401
+ },
402
+ "modbus_register_13": {
403
+ "read_index": 50,
404
+ "write_index": 39,
405
+ "descriptions": {
406
+ "title": "Register 13:",
407
+ "main_caption": "",
408
+ },
409
+ "default_value": 10,
410
+ "validator": {
411
+ "type": "uint16be",
412
+ "min": 0,
413
+ "max": 65000,
414
+ "generated": true
415
+ },
416
+ "html_id": "register_value_13_539"
417
+ },
418
+ "modbus_register_14": {
419
+ "read_index": 52,
420
+ "write_index": 41,
421
+ "descriptions": {
422
+ "title": "Register 14:",
423
+ "main_caption": "",
424
+ },
425
+ "default_value": 10,
426
+ "validator": {
427
+ "type": "uint16be",
428
+ "min": 0,
429
+ "max": 65000,
430
+ "generated": true
431
+ },
432
+ "html_id": "register_value_14_539"
433
+ },
434
+ "modbus_register_15": {
435
+ "read_index": 54,
436
+ "write_index": 43,
437
+ "descriptions": {
438
+ "title": "Register 15:",
439
+ "main_caption": "",
440
+ },
441
+ "default_value": 10,
442
+ "validator": {
443
+ "type": "uint16be",
444
+ "min": 0,
445
+ "max": 65000,
446
+ "generated": true
447
+ },
448
+ "html_id": "register_value_15_539"
449
+ },
450
+ "modbus_register_16": {
451
+ "read_index": 56,
452
+ "write_index": 45,
453
+ "descriptions": {
454
+ "title": "Register 16:",
455
+ "main_caption": "",
456
+ },
457
+ "default_value": 10,
458
+ "validator": {
459
+ "type": "uint16be",
460
+ "min": 0,
461
+ "max": 65000,
462
+ "generated": true
463
+ },
464
+ "html_id": "register_value_16_539"
465
+ },
466
+ "modbus_register_17": {
467
+ "read_index": 58,
468
+ "write_index": 47,
469
+ "descriptions": {
470
+ "title": "Register 17:",
471
+ "main_caption": "",
472
+ },
473
+ "default_value": 10,
474
+ "validator": {
475
+ "type": "uint16be",
476
+ "min": 0,
477
+ "max": 65000,
478
+ "generated": true
479
+ },
480
+ "html_id": "register_value_17_539"
481
+ },
482
+ "modbus_register_18": {
483
+ "read_index": 60,
484
+ "write_index": 49,
485
+ "descriptions": {
486
+ "title": "Register 18:",
487
+ "main_caption": "",
488
+ },
489
+ "default_value": 10,
490
+ "validator": {
491
+ "type": "uint16be",
492
+ "min": 0,
493
+ "max": 65000,
494
+ "generated": true
495
+ },
496
+ "html_id": "register_value_18_539"
497
+ },
498
+ "modbus_register_19": {
499
+ "read_index": 62,
500
+ "write_index": 51,
501
+ "descriptions": {
502
+ "title": "Register 19:",
503
+ "main_caption": "",
504
+ },
505
+ "default_value": 10,
506
+ "validator": {
507
+ "type": "uint16be",
508
+ "min": 0,
509
+ "max": 65000,
510
+ "generated": true
511
+ },
512
+ "html_id": "register_value_19_539"
513
+ },
514
+ "modbus_register_20": {
515
+ "read_index": 64,
516
+ "write_index": 53,
517
+ "descriptions": {
518
+ "title": "Register 20:",
519
+ "main_caption": "",
520
+ },
521
+ "default_value": 10,
522
+ "validator": {
523
+ "type": "uint16be",
524
+ "min": 0,
525
+ "max": 65000,
526
+ "generated": true
527
+ },
528
+ "html_id": "register_value_20_539"
529
+ },
530
+ "modbus_register_21": {
531
+ "read_index": 66,
532
+ "write_index": 55,
533
+ "descriptions": {
534
+ "title": "Register 21:",
535
+ "main_caption": "",
536
+ },
537
+ "default_value": 10,
538
+ "validator": {
539
+ "type": "uint16be",
540
+ "min": 0,
541
+ "max": 65000,
542
+ "generated": true
543
+ },
544
+ "html_id": "register_value_21_539"
545
+ },
546
+ "modbus_register_22": {
547
+ "read_index": 68,
548
+ "write_index": 57,
549
+ "descriptions": {
550
+ "title": "Register 22:",
551
+ "main_caption": "",
552
+ },
553
+ "default_value": 10,
554
+ "validator": {
555
+ "type": "uint16be",
556
+ "min": 0,
557
+ "max": 65000,
558
+ "generated": true
559
+ },
560
+ "html_id": "register_value_22_539"
561
+ },
562
+ "modbus_register_23": {
563
+ "read_index": 70,
564
+ "write_index": 59,
565
+ "descriptions": {
566
+ "title": "Register 23:",
567
+ "main_caption": "",
568
+ },
569
+ "default_value": 10,
570
+ "validator": {
571
+ "type": "uint16be",
572
+ "min": 0,
573
+ "max": 65000,
574
+ "generated": true
575
+ },
576
+ "html_id": "register_value_23_539"
577
+ },
578
+ "modbus_register_24": {
579
+ "read_index": 72,
580
+ "write_index": 61,
581
+ "descriptions": {
582
+ "title": "Register 24:",
583
+ "main_caption": "",
584
+ },
585
+ "default_value": 10,
586
+ "validator": {
587
+ "type": "uint16be",
588
+ "min": 0,
589
+ "max": 65000,
590
+ "generated": true
591
+ },
592
+ "html_id": "register_value_24_539"
593
+ },
594
+ "modbus_register_25": {
595
+ "read_index": 74,
596
+ "write_index": 63,
597
+ "descriptions": {
598
+ "title": "Register 25:",
599
+ "main_caption": "",
600
+ },
601
+ "default_value": 10,
602
+ "validator": {
603
+ "type": "uint16be",
604
+ "min": 0,
605
+ "max": 65000,
606
+ "generated": true
607
+ },
608
+ "html_id": "register_value_25_539"
609
+ },
610
+ "modbus_register_26": {
611
+ "read_index": 76,
612
+ "write_index": 65,
613
+ "descriptions": {
614
+ "title": "Register 26:",
615
+ "main_caption": "",
616
+ },
617
+ "default_value": 10,
618
+ "validator": {
619
+ "type": "uint16be",
620
+ "min": 0,
621
+ "max": 65000,
622
+ "generated": true
623
+ },
624
+ "html_id": "register_value_26_539"
625
+ },
626
+ "modbus_register_27": {
627
+ "read_index": 78,
628
+ "write_index": 67,
629
+ "descriptions": {
630
+ "title": "Register 27:",
631
+ "main_caption": "",
632
+ },
633
+ "default_value": 10,
634
+ "validator": {
635
+ "type": "uint16be",
636
+ "min": 0,
637
+ "max": 65000,
638
+ "generated": true
639
+ },
640
+ "html_id": "register_value_27_539"
641
+ },
642
+ "modbus_register_28": {
643
+ "read_index": 80,
644
+ "write_index": 69,
645
+ "descriptions": {
646
+ "title": "Register 28:",
647
+ "main_caption": "",
648
+ },
649
+ "default_value": 10,
650
+ "validator": {
651
+ "type": "uint16be",
652
+ "min": 0,
653
+ "max": 65000,
654
+ "generated": true
655
+ },
656
+ "html_id": "register_value_28_539"
657
+ },
658
+ "modbus_register_29": {
659
+ "read_index": 82,
660
+ "write_index": 71,
661
+ "descriptions": {
662
+ "title": "Register 29:",
663
+ "main_caption": "",
664
+ },
665
+ "default_value": 10,
666
+ "validator": {
667
+ "type": "uint16be",
668
+ "min": 0,
669
+ "max": 65000,
670
+ "generated": true
671
+ },
672
+ "html_id": "register_value_29_539"
673
+ },
674
+ "modbus_register_30": {
675
+ "read_index": 84,
676
+ "write_index": 73,
677
+ "descriptions": {
678
+ "title": "Register 30:",
679
+ "main_caption": "",
680
+ },
681
+ "default_value": 10,
682
+ "validator": {
683
+ "type": "uint16be",
684
+ "min": 0,
685
+ "max": 65000,
686
+ "generated": true
687
+ },
688
+ "html_id": "register_value_30_539"
689
+ },
690
+ "modbus_register_31": {
691
+ "read_index": 86,
692
+ "write_index": 75,
693
+ "descriptions": {
694
+ "title": "Register 31:",
695
+ "main_caption": "",
696
+ },
697
+ "default_value": 10,
698
+ "validator": {
699
+ "type": "uint16be",
700
+ "min": 0,
701
+ "max": 65000,
702
+ "generated": true
703
+ },
704
+ "html_id": "register_value_31_539"
705
+ },
706
+ "modbus_register_32": {
707
+ "read_index": 88,
708
+ "write_index": 77,
709
+ "descriptions": {
710
+ "title": "Register 32:",
711
+ "main_caption": "",
712
+ },
713
+ "default_value": 10,
714
+ "validator": {
715
+ "type": "uint16be",
716
+ "min": 0,
717
+ "max": 65000,
718
+ "generated": true
719
+ },
720
+ "html_id": "register_value_32_539"
721
+ },
722
+ "baud_rate": {
723
+ "read_index": 90,
724
+ "write_index": 79,
725
+ "descriptions": {
726
+ "title": "Set Baud Rate",
727
+ "main_caption": ""
728
+ },
729
+ "default_value": "9600",
730
+ "validator": {
731
+ "type": "uint32be",
732
+ "min": 0,
733
+ "max": 115200,
734
+ "generated": true
735
+ },
736
+ "options": {
737
+ "9600": "9600",
738
+ "19200": "19200",
739
+ "38400": "38400",
740
+ "57600": "57600",
741
+ "115200": "115200"
742
+ },
743
+ "html_id": "baudrate_539"
744
+ },
745
+ "bootup_time": {
746
+ "read_index": 94,
747
+ "write_index": 83,
748
+ "descriptions": {
749
+ "title": "Set Bootup Time",
750
+ "main_caption": "",
751
+ },
752
+ "default_value": 10,
753
+ "validator": {
754
+ "type": "uint8",
755
+ "min": 0,
756
+ "max": 255,
757
+ "generated": true
758
+ },
759
+ "html_id": "bootup_time_539"
760
+ },
761
+ "slave_address": {
762
+ "read_index": 95,
763
+ "write_index": 84,
764
+ "descriptions": {
765
+ "title": "Set Slave ID",
766
+ "main_caption": "",
767
+ },
768
+ "default_value": 10,
769
+ "validator": {
770
+ "type": "uint8",
771
+ "min": 0,
772
+ "max": 255,
773
+ "generated": true
774
+ },
775
+ "html_id": "sensor_add_539"
776
+ },
777
+ "response_timeout": {
778
+ "read_index": 96,
779
+ "write_index": 85,
780
+ "descriptions": {
781
+ "title": "Set Rx Timeout",
782
+ "main_caption": "",
783
+ },
784
+ "default_value": 10,
785
+ "validator": {
786
+ "type": "uint16be",
787
+ "min": 0,
788
+ "max": 65000,
789
+ "generated": true
790
+ },
791
+ "html_id": "rx_timeout_539"
792
+ },
793
+ "sub_device_type": {
794
+ "read_index": 98,
795
+ "write_index": 87,
796
+ "descriptions": {
797
+ "title": "Set Sub Device Type",
798
+ "main_caption": "",
799
+ },
800
+ "default_value": 10,
801
+ "validator": {
802
+ "type": "uint8",
803
+ "min": 0,
804
+ "max": 255,
805
+ "generated": true
806
+ },
807
+ "html_id": "sub_device_type_539"
808
+ },
809
+ "read_retries": {
810
+ "read_index": 99,
811
+ "write_index": 88,
812
+ "descriptions": {
813
+ "title": "Set Number of Read Retries",
814
+ "main_caption": "Range: 1 to 3.",
815
+ },
816
+ "default_value": 1,
817
+ "validator": {
818
+ "type": "uint8",
819
+ "min": 0,
820
+ "max": 3,
821
+ "generated": true
822
+ },
823
+ "html_id": "number_of_read_retries_539"
824
+ },
825
+ "modbus_command": {
826
+ "read_index": 100,
827
+ "write_index": 89,
828
+ "descriptions": {
829
+ "title": "Set Read Parameter",
830
+ "main_caption": "",
831
+ },
832
+ "default_value": 3,
833
+ "validator": {
834
+ "type": "uint8",
835
+ "min": 3,
836
+ "max": 4,
837
+ "generated": true
838
+ },
839
+ "html_id": "read_parameter_539"
840
+ },
841
+ };
842
+ };
843
+
844
+ const sync_parse = (rep_buffer) => {
845
+ let response = {
846
+ 'human_readable': {},
847
+ 'machine_values': {}
848
+ };
849
+
850
+ // Get the map based on the sensor type byte
851
+ const sync_map = get_config_map(rep_buffer[4]);
852
+
853
+ for (const [key, config] of Object.entries(sync_map)) {
854
+ // Destructure 'type' from inside 'validator' and rename 'read_index' to 'idx'
855
+ const { read_index: idx, length, validator: { type } = {}, converter, options } = config;
856
+
857
+ // If for some reason a config doesn't have a validator/type, skip it
858
+ if (!type) continue;
859
+
860
+ switch (type) {
861
+ case 'uint8':
862
+ response.machine_values[key] = rep_buffer[idx];
863
+ break;
864
+ case 'uint16be':
865
+ response.machine_values[key] = rep_buffer.readUInt16BE(idx);
866
+ break;
867
+ case 'uint32be':
868
+ response.machine_values[key] = rep_buffer.readUInt32BE(idx);
869
+ break;
870
+ case 'buffer':
871
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length);
872
+ break;
873
+ case 'hex':
874
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
875
+ break;
876
+ case 'mac':
877
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
878
+ break;
879
+ }
880
+ let human_value = response.machine_values[key];
881
+ if(options && options[response.machine_values[key]]){
882
+ human_value = options[response.machine_values[key]];
883
+ }else{
884
+ if(converter && converter.multiplier){
885
+ human_value = human_value * converter.multiplier;
886
+ }
887
+ if(converter && converter.units){
888
+ human_value = human_value + converter.units;
889
+ }
890
+ }
891
+ response.human_readable[key] = human_value;
892
+ }
893
+ if (Object.hasOwn(response.machine_values, 'destination_address') && response.machine_values.destination_address.toLowerCase() === '00000000') {
894
+ console.log('##############################');
895
+ console.log('#########Dest Override########');
896
+ console.log('##############################');
897
+ response.destination_address = "0000ffff";
898
+ //response.auto_raw_destination_address = "0000ffff";
899
+ };
900
+ return response;
901
+ };
902
+
903
+ const parse = (d) => {
904
+ return {
905
+ subdevice_type: d[0],
906
+ number_of_registers: d[1],
907
+ status_24_31: d[2],
908
+ status_16_23: d[3],
909
+ status_8_15: d[4],
910
+ status_0_7: d[5],
911
+ // TODO we can automatically determine how many registers are here based on the number_of_registers and create data objects appropriately
912
+ // r1: d.slice(2,4),
913
+ // r2: d.slice(4,6),
914
+ // r3: d.slice(6,8),
915
+ // r4: d.slice(8,10),
916
+ data: d.slice(6)
917
+ };
918
+ };
919
+
920
+ // --- 2. EXPORT THE MODULE ---
921
+ // Export the module with all the necessary functions and properties
922
+ // that need to be called from outside the scrip
923
+ return {
924
+ type: 539,
925
+ name: 'RS485 Modbus Wireless Converter',
926
+ parse,
927
+ get_write_buffer_size,
928
+ get_config_map,
929
+ sync_parse
930
+ };
931
+ };