@ncd-io/node-red-enterprise-sensors 2.0.2 → 2.0.4

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,963 @@
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
+ "html_active_id": "number_of_regs_to_rd_539_active"
226
+ },
227
+ "modbus_register_2": {
228
+ "read_index": 28,
229
+ "write_index": 17,
230
+ "descriptions": {
231
+ "title": "Register 2:",
232
+ "main_caption": "",
233
+ },
234
+ "default_value": 10,
235
+ "validator": {
236
+ "type": "uint16be",
237
+ "min": 0,
238
+ "max": 65000,
239
+ "generated": true
240
+ },
241
+ "html_id": "register_value_2_539",
242
+ "html_active_id": "number_of_regs_to_rd_539_active"
243
+ },
244
+ "modbus_register_3": {
245
+ "read_index": 30,
246
+ "write_index": 19,
247
+ "descriptions": {
248
+ "title": "Register 3:",
249
+ "main_caption": "",
250
+ },
251
+ "default_value": 10,
252
+ "validator": {
253
+ "type": "uint16be",
254
+ "min": 0,
255
+ "max": 65000,
256
+ "generated": true
257
+ },
258
+ "html_id": "register_value_3_539",
259
+ "html_active_id": "number_of_regs_to_rd_539_active"
260
+ },
261
+ "modbus_register_4": {
262
+ "read_index": 32,
263
+ "write_index": 21,
264
+ "descriptions": {
265
+ "title": "Register 4:",
266
+ "main_caption": "",
267
+ },
268
+ "default_value": 10,
269
+ "validator": {
270
+ "type": "uint16be",
271
+ "min": 0,
272
+ "max": 65000,
273
+ "generated": true
274
+ },
275
+ "html_id": "register_value_4_539",
276
+ "html_active_id": "number_of_regs_to_rd_539_active"
277
+ },
278
+ "modbus_register_5": {
279
+ "read_index": 34,
280
+ "write_index": 23,
281
+ "descriptions": {
282
+ "title": "Register 5:",
283
+ "main_caption": "",
284
+ },
285
+ "default_value": 10,
286
+ "validator": {
287
+ "type": "uint16be",
288
+ "min": 0,
289
+ "max": 65000,
290
+ "generated": true
291
+ },
292
+ "html_id": "register_value_5_539",
293
+ "html_active_id": "number_of_regs_to_rd_539_active"
294
+ },
295
+ "modbus_register_6": {
296
+ "read_index": 36,
297
+ "write_index": 25,
298
+ "descriptions": {
299
+ "title": "Register 6:",
300
+ "main_caption": "",
301
+ },
302
+ "default_value": 10,
303
+ "validator": {
304
+ "type": "uint16be",
305
+ "min": 0,
306
+ "max": 65000,
307
+ "generated": true
308
+ },
309
+ "html_id": "register_value_6_539",
310
+ "html_active_id": "number_of_regs_to_rd_539_active"
311
+ },
312
+ "modbus_register_7": {
313
+ "read_index": 38,
314
+ "write_index": 27,
315
+ "descriptions": {
316
+ "title": "Register 7:",
317
+ "main_caption": "",
318
+ },
319
+ "default_value": 10,
320
+ "validator": {
321
+ "type": "uint16be",
322
+ "min": 0,
323
+ "max": 65000,
324
+ "generated": true
325
+ },
326
+ "html_id": "register_value_7_539",
327
+ "html_active_id": "number_of_regs_to_rd_539_active"
328
+ },
329
+ "modbus_register_8": {
330
+ "read_index": 40,
331
+ "write_index": 29,
332
+ "descriptions": {
333
+ "title": "Register 8:",
334
+ "main_caption": "",
335
+ },
336
+ "default_value": 10,
337
+ "validator": {
338
+ "type": "uint16be",
339
+ "min": 0,
340
+ "max": 65000,
341
+ "generated": true
342
+ },
343
+ "html_id": "register_value_8_539",
344
+ "html_active_id": "number_of_regs_to_rd_539_active"
345
+ },
346
+ "modbus_register_9": {
347
+ "read_index": 42,
348
+ "write_index": 31,
349
+ "descriptions": {
350
+ "title": "Register 9:",
351
+ "main_caption": "",
352
+ },
353
+ "default_value": 10,
354
+ "validator": {
355
+ "type": "uint16be",
356
+ "min": 0,
357
+ "max": 65000,
358
+ "generated": true
359
+ },
360
+ "html_id": "register_value_9_539",
361
+ "html_active_id": "number_of_regs_to_rd_539_active"
362
+ },
363
+ "modbus_register_10": {
364
+ "read_index": 44,
365
+ "write_index": 33,
366
+ "descriptions": {
367
+ "title": "Register 10:",
368
+ "main_caption": "",
369
+ },
370
+ "default_value": 10,
371
+ "validator": {
372
+ "type": "uint16be",
373
+ "min": 0,
374
+ "max": 65000,
375
+ "generated": true
376
+ },
377
+ "html_id": "register_value_10_539",
378
+ "html_active_id": "number_of_regs_to_rd_539_active"
379
+ },
380
+ "modbus_register_11": {
381
+ "read_index": 46,
382
+ "write_index": 35,
383
+ "descriptions": {
384
+ "title": "Register 11:",
385
+ "main_caption": "",
386
+ },
387
+ "default_value": 10,
388
+ "validator": {
389
+ "type": "uint16be",
390
+ "min": 0,
391
+ "max": 65000,
392
+ "generated": true
393
+ },
394
+ "html_id": "register_value_11_539",
395
+ "html_active_id": "number_of_regs_to_rd_539_active"
396
+ },
397
+ "modbus_register_12": {
398
+ "read_index": 48,
399
+ "write_index": 37,
400
+ "descriptions": {
401
+ "title": "Register 12:",
402
+ "main_caption": "",
403
+ },
404
+ "default_value": 10,
405
+ "validator": {
406
+ "type": "uint16be",
407
+ "min": 0,
408
+ "max": 65000,
409
+ "generated": true
410
+ },
411
+ "html_id": "register_value_12_539",
412
+ "html_active_id": "number_of_regs_to_rd_539_active"
413
+ },
414
+ "modbus_register_13": {
415
+ "read_index": 50,
416
+ "write_index": 39,
417
+ "descriptions": {
418
+ "title": "Register 13:",
419
+ "main_caption": "",
420
+ },
421
+ "default_value": 10,
422
+ "validator": {
423
+ "type": "uint16be",
424
+ "min": 0,
425
+ "max": 65000,
426
+ "generated": true
427
+ },
428
+ "html_id": "register_value_13_539",
429
+ "html_active_id": "number_of_regs_to_rd_539_active"
430
+ },
431
+ "modbus_register_14": {
432
+ "read_index": 52,
433
+ "write_index": 41,
434
+ "descriptions": {
435
+ "title": "Register 14:",
436
+ "main_caption": "",
437
+ },
438
+ "default_value": 10,
439
+ "validator": {
440
+ "type": "uint16be",
441
+ "min": 0,
442
+ "max": 65000,
443
+ "generated": true
444
+ },
445
+ "html_id": "register_value_14_539",
446
+ "html_active_id": "number_of_regs_to_rd_539_active"
447
+ },
448
+ "modbus_register_15": {
449
+ "read_index": 54,
450
+ "write_index": 43,
451
+ "descriptions": {
452
+ "title": "Register 15:",
453
+ "main_caption": "",
454
+ },
455
+ "default_value": 10,
456
+ "validator": {
457
+ "type": "uint16be",
458
+ "min": 0,
459
+ "max": 65000,
460
+ "generated": true
461
+ },
462
+ "html_id": "register_value_15_539",
463
+ "html_active_id": "number_of_regs_to_rd_539_active"
464
+ },
465
+ "modbus_register_16": {
466
+ "read_index": 56,
467
+ "write_index": 45,
468
+ "descriptions": {
469
+ "title": "Register 16:",
470
+ "main_caption": "",
471
+ },
472
+ "default_value": 10,
473
+ "validator": {
474
+ "type": "uint16be",
475
+ "min": 0,
476
+ "max": 65000,
477
+ "generated": true
478
+ },
479
+ "html_id": "register_value_16_539",
480
+ "html_active_id": "number_of_regs_to_rd_539_active"
481
+ },
482
+ "modbus_register_17": {
483
+ "read_index": 58,
484
+ "write_index": 47,
485
+ "descriptions": {
486
+ "title": "Register 17:",
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_17_539",
497
+ "html_active_id": "number_of_regs_to_rd_539_active"
498
+ },
499
+ "modbus_register_18": {
500
+ "read_index": 60,
501
+ "write_index": 49,
502
+ "descriptions": {
503
+ "title": "Register 18:",
504
+ "main_caption": "",
505
+ },
506
+ "default_value": 10,
507
+ "validator": {
508
+ "type": "uint16be",
509
+ "min": 0,
510
+ "max": 65000,
511
+ "generated": true
512
+ },
513
+ "html_id": "register_value_18_539",
514
+ "html_active_id": "number_of_regs_to_rd_539_active"
515
+ },
516
+ "modbus_register_19": {
517
+ "read_index": 62,
518
+ "write_index": 51,
519
+ "descriptions": {
520
+ "title": "Register 19:",
521
+ "main_caption": "",
522
+ },
523
+ "default_value": 10,
524
+ "validator": {
525
+ "type": "uint16be",
526
+ "min": 0,
527
+ "max": 65000,
528
+ "generated": true
529
+ },
530
+ "html_id": "register_value_19_539",
531
+ "html_active_id": "number_of_regs_to_rd_539_active"
532
+ },
533
+ "modbus_register_20": {
534
+ "read_index": 64,
535
+ "write_index": 53,
536
+ "descriptions": {
537
+ "title": "Register 20:",
538
+ "main_caption": "",
539
+ },
540
+ "default_value": 10,
541
+ "validator": {
542
+ "type": "uint16be",
543
+ "min": 0,
544
+ "max": 65000,
545
+ "generated": true
546
+ },
547
+ "html_id": "register_value_20_539",
548
+ "html_active_id": "number_of_regs_to_rd_539_active"
549
+ },
550
+ "modbus_register_21": {
551
+ "read_index": 66,
552
+ "write_index": 55,
553
+ "descriptions": {
554
+ "title": "Register 21:",
555
+ "main_caption": "",
556
+ },
557
+ "default_value": 10,
558
+ "validator": {
559
+ "type": "uint16be",
560
+ "min": 0,
561
+ "max": 65000,
562
+ "generated": true
563
+ },
564
+ "html_id": "register_value_21_539",
565
+ "html_active_id": "number_of_regs_to_rd_539_active"
566
+ },
567
+ "modbus_register_22": {
568
+ "read_index": 68,
569
+ "write_index": 57,
570
+ "descriptions": {
571
+ "title": "Register 22:",
572
+ "main_caption": "",
573
+ },
574
+ "default_value": 10,
575
+ "validator": {
576
+ "type": "uint16be",
577
+ "min": 0,
578
+ "max": 65000,
579
+ "generated": true
580
+ },
581
+ "html_id": "register_value_22_539",
582
+ "html_active_id": "number_of_regs_to_rd_539_active"
583
+ },
584
+ "modbus_register_23": {
585
+ "read_index": 70,
586
+ "write_index": 59,
587
+ "descriptions": {
588
+ "title": "Register 23:",
589
+ "main_caption": "",
590
+ },
591
+ "default_value": 10,
592
+ "validator": {
593
+ "type": "uint16be",
594
+ "min": 0,
595
+ "max": 65000,
596
+ "generated": true
597
+ },
598
+ "html_id": "register_value_23_539",
599
+ "html_active_id": "number_of_regs_to_rd_539_active"
600
+ },
601
+ "modbus_register_24": {
602
+ "read_index": 72,
603
+ "write_index": 61,
604
+ "descriptions": {
605
+ "title": "Register 24:",
606
+ "main_caption": "",
607
+ },
608
+ "default_value": 10,
609
+ "validator": {
610
+ "type": "uint16be",
611
+ "min": 0,
612
+ "max": 65000,
613
+ "generated": true
614
+ },
615
+ "html_id": "register_value_24_539",
616
+ "html_active_id": "number_of_regs_to_rd_539_active"
617
+ },
618
+ "modbus_register_25": {
619
+ "read_index": 74,
620
+ "write_index": 63,
621
+ "descriptions": {
622
+ "title": "Register 25:",
623
+ "main_caption": "",
624
+ },
625
+ "default_value": 10,
626
+ "validator": {
627
+ "type": "uint16be",
628
+ "min": 0,
629
+ "max": 65000,
630
+ "generated": true
631
+ },
632
+ "html_id": "register_value_25_539",
633
+ "html_active_id": "number_of_regs_to_rd_539_active"
634
+ },
635
+ "modbus_register_26": {
636
+ "read_index": 76,
637
+ "write_index": 65,
638
+ "descriptions": {
639
+ "title": "Register 26:",
640
+ "main_caption": "",
641
+ },
642
+ "default_value": 10,
643
+ "validator": {
644
+ "type": "uint16be",
645
+ "min": 0,
646
+ "max": 65000,
647
+ "generated": true
648
+ },
649
+ "html_id": "register_value_26_539",
650
+ "html_active_id": "number_of_regs_to_rd_539_active"
651
+ },
652
+ "modbus_register_27": {
653
+ "read_index": 78,
654
+ "write_index": 67,
655
+ "descriptions": {
656
+ "title": "Register 27:",
657
+ "main_caption": "",
658
+ },
659
+ "default_value": 10,
660
+ "validator": {
661
+ "type": "uint16be",
662
+ "min": 0,
663
+ "max": 65000,
664
+ "generated": true
665
+ },
666
+ "html_id": "register_value_27_539",
667
+ "html_active_id": "number_of_regs_to_rd_539_active"
668
+ },
669
+ "modbus_register_28": {
670
+ "read_index": 80,
671
+ "write_index": 69,
672
+ "descriptions": {
673
+ "title": "Register 28:",
674
+ "main_caption": "",
675
+ },
676
+ "default_value": 10,
677
+ "validator": {
678
+ "type": "uint16be",
679
+ "min": 0,
680
+ "max": 65000,
681
+ "generated": true
682
+ },
683
+ "html_id": "register_value_28_539",
684
+ "html_active_id": "number_of_regs_to_rd_539_active"
685
+ },
686
+ "modbus_register_29": {
687
+ "read_index": 82,
688
+ "write_index": 71,
689
+ "descriptions": {
690
+ "title": "Register 29:",
691
+ "main_caption": "",
692
+ },
693
+ "default_value": 10,
694
+ "validator": {
695
+ "type": "uint16be",
696
+ "min": 0,
697
+ "max": 65000,
698
+ "generated": true
699
+ },
700
+ "html_id": "register_value_29_539",
701
+ "html_active_id": "number_of_regs_to_rd_539_active"
702
+ },
703
+ "modbus_register_30": {
704
+ "read_index": 84,
705
+ "write_index": 73,
706
+ "descriptions": {
707
+ "title": "Register 30:",
708
+ "main_caption": "",
709
+ },
710
+ "default_value": 10,
711
+ "validator": {
712
+ "type": "uint16be",
713
+ "min": 0,
714
+ "max": 65000,
715
+ "generated": true
716
+ },
717
+ "html_id": "register_value_30_539",
718
+ "html_active_id": "number_of_regs_to_rd_539_active"
719
+ },
720
+ "modbus_register_31": {
721
+ "read_index": 86,
722
+ "write_index": 75,
723
+ "descriptions": {
724
+ "title": "Register 31:",
725
+ "main_caption": "",
726
+ },
727
+ "default_value": 10,
728
+ "validator": {
729
+ "type": "uint16be",
730
+ "min": 0,
731
+ "max": 65000,
732
+ "generated": true
733
+ },
734
+ "html_id": "register_value_31_539",
735
+ "html_active_id": "number_of_regs_to_rd_539_active"
736
+ },
737
+ "modbus_register_32": {
738
+ "read_index": 88,
739
+ "write_index": 77,
740
+ "descriptions": {
741
+ "title": "Register 32:",
742
+ "main_caption": "",
743
+ },
744
+ "default_value": 10,
745
+ "validator": {
746
+ "type": "uint16be",
747
+ "min": 0,
748
+ "max": 65000,
749
+ "generated": true
750
+ },
751
+ "html_id": "register_value_32_539",
752
+ "html_active_id": "number_of_regs_to_rd_539_active"
753
+ },
754
+ "baud_rate": {
755
+ "read_index": 90,
756
+ "write_index": 79,
757
+ "descriptions": {
758
+ "title": "Set Baud Rate",
759
+ "main_caption": ""
760
+ },
761
+ "default_value": "9600",
762
+ "validator": {
763
+ "type": "uint32be",
764
+ "min": 0,
765
+ "max": 115200,
766
+ "generated": true
767
+ },
768
+ "options": {
769
+ "9600": "9600",
770
+ "19200": "19200",
771
+ "38400": "38400",
772
+ "57600": "57600",
773
+ "115200": "115200"
774
+ },
775
+ "html_id": "baudrate_539"
776
+ },
777
+ "bootup_time": {
778
+ "read_index": 94,
779
+ "write_index": 83,
780
+ "descriptions": {
781
+ "title": "Set Bootup Time",
782
+ "main_caption": "",
783
+ },
784
+ "default_value": 10,
785
+ "validator": {
786
+ "type": "uint8",
787
+ "min": 0,
788
+ "max": 255,
789
+ "generated": true
790
+ },
791
+ "html_id": "bootup_time_539"
792
+ },
793
+ "slave_address": {
794
+ "read_index": 95,
795
+ "write_index": 84,
796
+ "descriptions": {
797
+ "title": "Set Slave ID",
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": "sensor_add_539"
808
+ },
809
+ "response_timeout": {
810
+ "read_index": 96,
811
+ "write_index": 85,
812
+ "descriptions": {
813
+ "title": "Set Rx Timeout",
814
+ "main_caption": "",
815
+ },
816
+ "default_value": 10,
817
+ "validator": {
818
+ "type": "uint16be",
819
+ "min": 0,
820
+ "max": 65000,
821
+ "generated": true
822
+ },
823
+ "html_id": "rx_timeout_539"
824
+ },
825
+ "sub_device_type": {
826
+ "read_index": 98,
827
+ "write_index": 87,
828
+ "descriptions": {
829
+ "title": "Set Sub Device Type",
830
+ "main_caption": "",
831
+ },
832
+ "default_value": 10,
833
+ "validator": {
834
+ "type": "uint8",
835
+ "min": 0,
836
+ "max": 255,
837
+ "generated": true
838
+ },
839
+ "html_id": "sub_device_type_539"
840
+ },
841
+ "read_retries": {
842
+ "read_index": 99,
843
+ "write_index": 88,
844
+ "descriptions": {
845
+ "title": "Set Number of Read Retries",
846
+ "main_caption": "Range: 1 to 3.",
847
+ },
848
+ "default_value": 1,
849
+ "validator": {
850
+ "type": "uint8",
851
+ "min": 0,
852
+ "max": 3,
853
+ "generated": true
854
+ },
855
+ "html_id": "number_of_read_retries_539"
856
+ },
857
+ "modbus_command": {
858
+ "read_index": 100,
859
+ "write_index": 89,
860
+ "descriptions": {
861
+ "title": "Set Read Parameter",
862
+ "main_caption": "",
863
+ },
864
+ "default_value": 3,
865
+ "validator": {
866
+ "type": "uint8",
867
+ "min": 3,
868
+ "max": 4,
869
+ "generated": true
870
+ },
871
+ "html_id": "read_parameter_539"
872
+ },
873
+ };
874
+ };
875
+
876
+ const sync_parse = (rep_buffer) => {
877
+ let response = {
878
+ 'human_readable': {},
879
+ 'machine_values': {}
880
+ };
881
+
882
+ // Get the map based on the sensor type byte
883
+ const sync_map = get_config_map(rep_buffer[4]);
884
+
885
+ for (const [key, config] of Object.entries(sync_map)) {
886
+ // Destructure 'type' from inside 'validator' and rename 'read_index' to 'idx'
887
+ const { read_index: idx, length, validator: { type } = {}, converter, options } = config;
888
+
889
+ // If for some reason a config doesn't have a validator/type, skip it
890
+ if (!type) continue;
891
+
892
+ switch (type) {
893
+ case 'uint8':
894
+ response.machine_values[key] = rep_buffer[idx];
895
+ break;
896
+ case 'uint16be':
897
+ response.machine_values[key] = rep_buffer.readUInt16BE(idx);
898
+ break;
899
+ case 'uint32be':
900
+ response.machine_values[key] = rep_buffer.readUInt32BE(idx);
901
+ break;
902
+ case 'buffer':
903
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length);
904
+ break;
905
+ case 'hex':
906
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
907
+ break;
908
+ case 'mac':
909
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
910
+ break;
911
+ }
912
+ let human_value = response.machine_values[key];
913
+ if(options && options[response.machine_values[key]]){
914
+ human_value = options[response.machine_values[key]];
915
+ }else{
916
+ if(converter && converter.multiplier){
917
+ human_value = human_value * converter.multiplier;
918
+ }
919
+ if(converter && converter.units){
920
+ human_value = human_value + converter.units;
921
+ }
922
+ }
923
+ response.human_readable[key] = human_value;
924
+ }
925
+ if (Object.hasOwn(response.machine_values, 'destination_address') && response.machine_values.destination_address.toLowerCase() === '00000000') {
926
+ console.log('##############################');
927
+ console.log('#########Dest Override########');
928
+ console.log('##############################');
929
+ response.destination_address = "0000ffff";
930
+ //response.auto_raw_destination_address = "0000ffff";
931
+ };
932
+ return response;
933
+ };
934
+
935
+ const parse = (d) => {
936
+ return {
937
+ subdevice_type: d[0],
938
+ number_of_registers: d[1],
939
+ status_24_31: d[2],
940
+ status_16_23: d[3],
941
+ status_8_15: d[4],
942
+ status_0_7: d[5],
943
+ // TODO we can automatically determine how many registers are here based on the number_of_registers and create data objects appropriately
944
+ // r1: d.slice(2,4),
945
+ // r2: d.slice(4,6),
946
+ // r3: d.slice(6,8),
947
+ // r4: d.slice(8,10),
948
+ data: d.slice(6)
949
+ };
950
+ };
951
+
952
+ // --- 2. EXPORT THE MODULE ---
953
+ // Export the module with all the necessary functions and properties
954
+ // that need to be called from outside the scrip
955
+ return {
956
+ type: 539,
957
+ name: 'RS485 Modbus Wireless Converter',
958
+ parse,
959
+ get_write_buffer_size,
960
+ get_config_map,
961
+ sync_parse
962
+ };
963
+ };