@ncd-io/node-red-enterprise-sensors 1.6.3 → 2.0.0

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,1342 @@
1
+ const { toMac, signInt, msbLsb } = require('../utils');
2
+
3
+ module.exports = (globalDevices, emitter) => {
4
+
5
+ const clear_globalDevices_stream = (deviceAddr) => {
6
+ if (Object.hasOwn(globalDevices, deviceAddr)) {
7
+ if (Object.hasOwn(globalDevices[deviceAddr], 'packet_stream_timeout')) {
8
+ clearTimeout(globalDevices[deviceAddr].packet_stream_timeout);
9
+ }
10
+ delete globalDevices[deviceAddr];
11
+ }
12
+ };
13
+
14
+ const init_globalDevices_stream = (deviceAddr, payload, expected_packets, parsed, msg_type) => {
15
+ globalDevices[deviceAddr] = {
16
+ data: {},
17
+ odr: msbLsb(payload[9], payload[10]),
18
+ mo: payload[8],
19
+ fsr: payload[11] >> 5,
20
+ hour: payload[12],
21
+ minute: payload[13],
22
+ temperature: msbLsb(payload[14], payload[15]) / 100,
23
+ expected_packets: expected_packets
24
+ };
25
+ globalDevices[deviceAddr].packet_stream_timeout = setTimeout(() => {
26
+ // Calling sibling function directly
27
+ parsed.sensor_data = concat_fft_data(deviceAddr, payload[8], msg_type);
28
+ parsed.sensor_data.error = 'Time Series Data Stream Timeout - incomplete data received';
29
+
30
+ emitter.emit('sensor_data', parsed);
31
+ emitter.emit('sensor_data-114', parsed);
32
+ emitter.emit('sensor_data' + '-' + deviceAddr, parsed);
33
+ }, 6000);
34
+ };
35
+
36
+ const concat_fft_data = (deviceAddr, mode, msg_type) => {
37
+ var raw_data = new Array();
38
+ for (const packet in globalDevices[deviceAddr].data) {
39
+ raw_data = raw_data.concat(globalDevices[deviceAddr].data[packet]);
40
+ }
41
+ var label = 0;
42
+ var fft_concat = { x: [], y: [], z: [] };
43
+
44
+ var en_axis_data = {};
45
+ en_axis_data.x_offset = 0;
46
+ en_axis_data.y_offset = 2;
47
+ en_axis_data.z_offset = 4;
48
+ en_axis_data.increment = 6;
49
+
50
+ var fsr_mult = .00006;
51
+ var fsr_text = "";
52
+
53
+ switch (globalDevices[deviceAddr].fsr) {
54
+ case 0: fsr_mult = 0.00006; break;
55
+ case 1: fsr_mult = 0.00012; break;
56
+ case 2: fsr_mult = 0.00024; break;
57
+ case 3: fsr_mult = 0.00049; break;
58
+ }
59
+ switch (globalDevices[deviceAddr].fsr) {
60
+ case 0: fsr_text = "2g"; break;
61
+ case 1: fsr_text = "4g"; break;
62
+ case 2: fsr_text = "8g"; break;
63
+ case 3: fsr_text = "16g"; break;
64
+ }
65
+
66
+ for (var i = 0; i < raw_data.length; i += en_axis_data.increment) {
67
+ label++;
68
+ if ('x_offset' in en_axis_data) {
69
+ fft_concat.x.push(parseFloat((signInt(((raw_data[i + en_axis_data.x_offset] << 8) + (raw_data[i + en_axis_data.x_offset + 1])), 16) * fsr_mult).toFixed(3)));
70
+ }
71
+ if ('y_offset' in en_axis_data) {
72
+ fft_concat.y.push(parseFloat((signInt(((raw_data[i + en_axis_data.y_offset] << 8) + (raw_data[i + en_axis_data.y_offset + 1])), 16) * fsr_mult).toFixed(3)));
73
+ }
74
+ if ('z_offset' in en_axis_data) {
75
+ fft_concat.z.push(parseFloat((signInt(((raw_data[i + en_axis_data.z_offset] << 8) + (raw_data[i + en_axis_data.z_offset + 1])), 16) * fsr_mult).toFixed(3)));
76
+ }
77
+ }
78
+ var fft_concat_obj = {
79
+ mode: mode,
80
+ msg_type: msg_type,
81
+ time_id: [
82
+ String(globalDevices[deviceAddr].hour).padStart(2, '0'),
83
+ String(globalDevices[deviceAddr].minute).padStart(2, '0'),
84
+ ].join(':'),
85
+ mac_address: deviceAddr,
86
+ fsr: fsr_text,
87
+ odr: globalDevices[deviceAddr].odr,
88
+ temperature: globalDevices[deviceAddr].temperature,
89
+ total_samples: label,
90
+ fft_confidence: ((Object.keys(globalDevices[deviceAddr].data).length / globalDevices[deviceAddr].expected_packets) * 100).toFixed(2) + '%',
91
+ data: fft_concat
92
+ };
93
+ return fft_concat_obj;
94
+ };
95
+ const get_write_buffer_size = (firmware) => {
96
+ return 41;
97
+ }
98
+ const get_config_map = (firmware) => {
99
+ console.log('Generating sync map for firmware version', firmware);
100
+
101
+ return {
102
+ "core_version": {
103
+ "read_index": 3,
104
+ "descriptions": {
105
+ "title": "Core Version",
106
+ "main_caption": "The version of the core communication stack."
107
+ },
108
+ "validator": {
109
+ "type": "uint8"
110
+ },
111
+ "tags": [
112
+ "system"
113
+ ]
114
+ },
115
+ "firmware_version": {
116
+ "read_index": 4,
117
+ "descriptions": {
118
+ "title": "Firmware Version",
119
+ "main_caption": "The application-specific firmware version."
120
+ },
121
+ "validator": {
122
+ "type": "uint8"
123
+ },
124
+ "tags": [
125
+ "system"
126
+ ]
127
+ },
128
+ "sensor_type": {
129
+ "read_index": 5,
130
+ "descriptions": {
131
+ "title": "Sensor Type",
132
+ "main_caption": "The hardware identifier for the specific sensor model."
133
+ },
134
+ "validator": {
135
+ "type": "uint16be"
136
+ },
137
+ "tags": [
138
+ "system"
139
+ ]
140
+ },
141
+ "tx_lifetime_counter": {
142
+ "read_index": 7,
143
+ "descriptions": {
144
+ "title": "Transmission Lifetime Counter",
145
+ "main_caption": "Total number of transmissions since the device was manufactured."
146
+ },
147
+ "validator": {
148
+ "type": "uint32be"
149
+ },
150
+ "tags": [
151
+ "diagnostics"
152
+ ]
153
+ },
154
+ "hardware_id": {
155
+ "read_index": 11,
156
+ "length": 3,
157
+ "descriptions": {
158
+ "title": "Hardware ID",
159
+ "main_caption": "A unique 3-byte hardware identifier."
160
+ },
161
+ "validator": {
162
+ "type": "buffer"
163
+ },
164
+ "tags": [
165
+ "system"
166
+ ]
167
+ },
168
+ "network_id": {
169
+ "read_index": 14,
170
+ "write_index": 3,
171
+ "length": 2,
172
+ "descriptions": {
173
+ "title": "Network ID",
174
+ "main_caption": ""
175
+ },
176
+ "default_value": "7fff",
177
+ "validator": {
178
+ "type": "hex",
179
+ "length": 4
180
+ },
181
+ "html_id": "pan_id",
182
+ "tags": [
183
+ "Communications"
184
+ ]
185
+ },
186
+ "destination_address": {
187
+ "read_index": 16,
188
+ "write_index": 5,
189
+ "length": 4,
190
+ "descriptions": {
191
+ "title": "Destination Address",
192
+ "main_caption": ""
193
+ },
194
+ "default_value": "0000ffff",
195
+ "validator": {
196
+ "type": "mac",
197
+ "length": 8
198
+ },
199
+ "html_id": "destination",
200
+ "tags": [
201
+ "Communications"
202
+ ]
203
+ },
204
+ "node_id": {
205
+ "read_index": 20,
206
+ "write_index": 9,
207
+ "descriptions": {
208
+ "title": "Node ID",
209
+ "main_caption": ""
210
+ },
211
+ "default_value": "0",
212
+ "validator": {
213
+ "type": "uint8",
214
+ "min": 0,
215
+ "max": 255,
216
+ "generated": true
217
+ },
218
+ "html_id": "node_id",
219
+ "tags": [
220
+ "generic"
221
+ ],
222
+ "tags": [
223
+ "Communications"
224
+ ]
225
+ },
226
+ "odr": {
227
+ "read_index": 21,
228
+ "write_index": 10,
229
+ "descriptions": {
230
+ "title": "Probe 1: Output Data Rate",
231
+ "main_caption": "<p>This would determine how many samples the output data has...</p>"
232
+ },
233
+ "default_value": 0,
234
+ "validator": {
235
+ "type": "uint8",
236
+ "min": 7,
237
+ "max": 15,
238
+ "generated": true
239
+ },
240
+ "options": {
241
+ "7": "100Hz",
242
+ "8": "200Hz",
243
+ "9": "400Hz",
244
+ "10": "800Hz",
245
+ "11": "1600Hz",
246
+ "12": "3200Hz",
247
+ "13": "6400Hz",
248
+ "14": "12800Hz",
249
+ "15": "25600Hz"
250
+ },
251
+ "tags": [
252
+ "Vibration Sampling"
253
+ ],
254
+ "html_id": "odr_p1_110"
255
+ },
256
+ "sampling_duration": {
257
+ "read_index": 22,
258
+ "write_index": 11,
259
+ "descriptions": {
260
+ "title": "Probe 1: Sampling Duration",
261
+ "main_caption": "<p>Set the amount of time which the samples are taken...</p>"
262
+ },
263
+ "default_value": 1,
264
+ "validator": {
265
+ "type": "uint8",
266
+ "min": 1,
267
+ "max": 100,
268
+ "generated": true
269
+ },
270
+ "tags": [
271
+ "Vibration Sampling"
272
+ ],
273
+ "html_id": "sampling_duration_p1_110"
274
+ },
275
+ "lpf_coefficient": {
276
+ "read_index": 23,
277
+ "write_index": 12,
278
+ "descriptions": {
279
+ "title": "Probe 1: Set Low Pass Filter",
280
+ "main_caption": "<p>This setting will set the LPF freq to ODR divided by Selected Value...</p>"
281
+ },
282
+ "default_value": 0,
283
+ "validator": {
284
+ "type": "uint8",
285
+ "min": 0,
286
+ "max": 9,
287
+ "generated": true
288
+ },
289
+ "options": {
290
+ "0": "4",
291
+ "1": "8",
292
+ "2": "16",
293
+ "3": "32",
294
+ "4": "64",
295
+ "5": "128",
296
+ "6": "256",
297
+ "7": "512",
298
+ "8": "1024",
299
+ "9": "2048"
300
+ },
301
+ "html_id": "low_pass_filter_p1_110"
302
+ },
303
+ "hpf_coefficient": {
304
+ "read_index": 24,
305
+ "write_index": 13,
306
+ "descriptions": {
307
+ "title": "Probe 1: Set High Pass Filter",
308
+ "main_caption": "<p>This setting will set the HPF freq to ODR divided by Selected Value...</p>"
309
+ },
310
+ "default_value": 0,
311
+ "validator": {
312
+ "type": "uint8",
313
+ "min": 0,
314
+ "max": 9,
315
+ "generated": true
316
+ },
317
+ "options": {
318
+ "0": "4",
319
+ "1": "8",
320
+ "2": "16",
321
+ "3": "32",
322
+ "4": "64",
323
+ "5": "128",
324
+ "6": "256",
325
+ "7": "512",
326
+ "8": "1024",
327
+ "9": "2048"
328
+ },
329
+ "html_id": "high_pass_filter_p1_110"
330
+ },
331
+ "full_scale_range": {
332
+ "read_index": 25,
333
+ "write_index": 14,
334
+ "descriptions": {
335
+ "title": "Full Scale Range",
336
+ "main_caption": "<p>Set how large of a range the device can measure acceleration in.</p>"
337
+ },
338
+ "default_value": 1,
339
+ "validator": {
340
+ "type": "uint8",
341
+ "min": 0,
342
+ "max": 5,
343
+ "generated": true
344
+ },
345
+ "options": {
346
+ "0": "+/- 2g",
347
+ "1": "+/- 4g",
348
+ "2": "+/- 8g",
349
+ "3": "+/- 16g",
350
+ "4": "+/- 32g",
351
+ "5": "+/- 64g"
352
+ },
353
+ "tags": [
354
+ "Vibration Sampling"
355
+ ],
356
+ "html_id": "full_scale_range_101"
357
+ },
358
+ "axes_enabled": {
359
+ "read_index": 26,
360
+ "write_index": 15,
361
+ "descriptions": {
362
+ "title": "Axes Enabled",
363
+ "main_caption": "New Command"
364
+ },
365
+ "validator": {
366
+ "type": "uint8"
367
+ },
368
+ "read_only": true,
369
+ },
370
+ "sampling_interval": {
371
+ "read_index": 27,
372
+ "write_index": 16,
373
+ "descriptions": {
374
+ "title": "Sampling Interval",
375
+ "main_caption": "<p>Set how often will the sensor transmit measurement data.</p>"
376
+ },
377
+ "default_value": 1,
378
+ "validator": {
379
+ "type": "uint8",
380
+ "min": 0,
381
+ "max": 8,
382
+ "generated": true
383
+ },
384
+ "options": {
385
+ "0": "5 Minutes",
386
+ "1": "10 Minutes",
387
+ "2": "15 Minutes",
388
+ "3": "20 Minutes",
389
+ "4": "30 Minutes",
390
+ "5": "60 Minutes",
391
+ "6": "120 Minutes",
392
+ "7": "180 Minutes",
393
+ "8": "1 Minute"
394
+ },
395
+ "tags": [
396
+ "Communications"
397
+ ],
398
+ "html_id": "sampling_interval_110"
399
+ },
400
+ "filter_status": {
401
+ "read_index": 28,
402
+ "write_index": 17,
403
+ "descriptions": {
404
+ "title": "Set Filtering",
405
+ "main_caption": "<p>Enable/Disable built-in filters</p>"
406
+ },
407
+ "default_value": 0,
408
+ "validator": {
409
+ "type": "uint8",
410
+ "min": 0,
411
+ "max": 1,
412
+ "generated": true
413
+ },
414
+ "options": {
415
+ "0": "Enabled",
416
+ "1": "Disabled"
417
+ },
418
+ "html_id": "enable_filtering_110"
419
+ },
420
+ "operation_mode": {
421
+ "read_index": 29,
422
+ "write_index": 18,
423
+ "descriptions": {
424
+ "title": "Mode",
425
+ "main_caption": "<p>• <strong>Processed:</strong> FFT is performed...</p>"
426
+ },
427
+ "default_value": 0,
428
+ "validator": {
429
+ "type": "uint8",
430
+ "min": 0,
431
+ "max": 3,
432
+ "generated": true
433
+ },
434
+ "options": {
435
+ "0": "Processed",
436
+ "1": "Raw",
437
+ "2": "Processed + Raw on demand",
438
+ "3": "Smart"
439
+ },
440
+ "html_id": "mode_110"
441
+ },
442
+ "measurement_mode": {
443
+ "read_index": 30,
444
+ "write_index": 19,
445
+ "descriptions": {
446
+ "title": "Measurement Mode",
447
+ "main_caption": "Changing this value does not do anything. Only give one option."
448
+ },
449
+ "validator": {
450
+ "type": "uint8"
451
+ },
452
+ "read_only": true
453
+ },
454
+ "on_request_timeout": {
455
+ "read_index": 31,
456
+ "write_index": 20,
457
+ "descriptions": {
458
+ "title": "Set On Request Timeout",
459
+ "main_caption": "<p>Set how long device will stay awake...</p>"
460
+ },
461
+ "default_value": 1,
462
+ "validator": {
463
+ "type": "uint8",
464
+ "min": 1,
465
+ "max": 10,
466
+ "generated": true
467
+ },
468
+ "depends_on": {
469
+ "operation_mode": [
470
+ 2,
471
+ 3
472
+ ]
473
+ },
474
+ "html_id": "on_request_timeout_80"
475
+ },
476
+ "deadband": {
477
+ "read_index": 32,
478
+ "write_index": 21,
479
+ "descriptions": {
480
+ "title": "Set Dead Band in mg",
481
+ "main_caption": "<p>Filters out acceleration values below the dead band threshold...</p>"
482
+ },
483
+ "default_value": 0,
484
+ "validator": {
485
+ "type": "uint8",
486
+ "min": 0,
487
+ "max": 255,
488
+ "generated": true
489
+ },
490
+ "html_id": "deadband_80"
491
+ },
492
+ "motion_detection_threshold": {
493
+ "read_index": 33,
494
+ "write_index": 22,
495
+ "descriptions": {
496
+ "title": "Probe 1: Set Acceleration Wake/Interrupt Threshold",
497
+ "main_caption": "<div><p>Set a breakpoint for sensor to wake up...</p></div>"
498
+ },
499
+ "default_value": 0,
500
+ "validator": {
501
+ "type": "uint8",
502
+ "min": 0,
503
+ "max": 40,
504
+ "generated": true
505
+ },
506
+ "html_id": "motion_detect_threshold_p1_110"
507
+ },
508
+ "led_acceleration_alert_threshold": {
509
+ "read_index": 34,
510
+ "write_index": 23,
511
+ "descriptions": {
512
+ "title": "LED Accelerometer Threshold",
513
+ "main_caption": "<div><p>Set the minimum acceleration value...</p></div>"
514
+ },
515
+ "default_value": 10,
516
+ "validator": {
517
+ "type": "uint8",
518
+ "min": 0,
519
+ "max": 255,
520
+ "generated": true
521
+ },
522
+ "depends_on": {
523
+ "led_alert_mode": 0
524
+ },
525
+ "html_id": "led_accelerometer_threshold_84"
526
+ },
527
+ "led_velocity_alert_threshold": {
528
+ "read_index": 35,
529
+ "write_index": 24,
530
+ "descriptions": {
531
+ "title": "LED Velocity Threshold",
532
+ "main_caption": "<div><p>Set the minimum velocity value...</p></div>"
533
+ },
534
+ "default_value": 10,
535
+ "validator": {
536
+ "type": "uint8",
537
+ "min": 0,
538
+ "max": 255,
539
+ "generated": true
540
+ },
541
+ "depends_on": {
542
+ "led_alert_mode": 1
543
+ },
544
+ "html_id": "led_velocity_threshold_84"
545
+ },
546
+ "smart_accelerometer_threshold": {
547
+ "read_index": 36,
548
+ "write_index": 25,
549
+ "descriptions": {
550
+ "title": "Probe 1: Set Smart Mode Threshold",
551
+ "main_caption": "<p>If RMS acceleration is above this in any axis...</p>"
552
+ },
553
+ "default_value": 1,
554
+ "validator": {
555
+ "type": "uint8",
556
+ "min": 1,
557
+ "max": 40
558
+ },
559
+ "depends_on": {
560
+ "operation_mode": 3
561
+ },
562
+ "html_id": "smart_threshold_110"
563
+ },
564
+ "led_alert_mode": {
565
+ "read_index": 37,
566
+ "write_index": 26,
567
+ "descriptions": {
568
+ "title": "LED Alert Mode",
569
+ "main_caption": "<p>Choose whether the LED indicator should be based on Acceleration or Velocity</p>"
570
+ },
571
+ "default_value": 0,
572
+ "validator": {
573
+ "type": "uint8",
574
+ "min": 0,
575
+ "max": 1,
576
+ "generated": true
577
+ },
578
+ "options": {
579
+ "0": "Acceleration",
580
+ "1": "Velocity"
581
+ },
582
+ "html_id": "led_alert_mode_84"
583
+ },
584
+ "raw_packet_length": {
585
+ "read_index": 38,
586
+ "write_index": 27,
587
+ "descriptions": {
588
+ "title": "Payload Length",
589
+ "main_caption": "<p>Set the size of the data payload...</p>",
590
+ "sub_caption": "<p class=\"caption\"><i>Note: For the 2.4GHz version you need to operate with a 55 Byte payload.</i></p>"
591
+ },
592
+ "default_value": 3,
593
+ "validator": {
594
+ "type": "uint8",
595
+ "min": 0,
596
+ "max": 3,
597
+ "generated": true
598
+ },
599
+ "options": {
600
+ "0": "55 Bytes",
601
+ "1": "100 Bytes",
602
+ "2": "150 Bytes",
603
+ "3": "180 Bytes"
604
+ },
605
+ "tags": [
606
+ "Communications"
607
+ ],
608
+ "html_id": "payload_length_80"
609
+ },
610
+ "auto_raw_interval": {
611
+ "read_index": 39,
612
+ "write_index": 28,
613
+ "descriptions": {
614
+ "title": "Set Auto Raw Interval",
615
+ "main_caption": "<p>Set the Auto Time Domain (Raw) data transmission Interval...</p>",
616
+ "sub_caption": "<p class=\"caption\"><i>Note: Auto Raw Transmission is disabled by default.</i></p>"
617
+ },
618
+ "default_value": 0,
619
+ "validator": {
620
+ "type": "uint8",
621
+ "min": 0,
622
+ "max": 255,
623
+ "generated": true
624
+ },
625
+ "depends_on": {
626
+ "operation_mode": 3
627
+ },
628
+ "tags": [
629
+ "Communications"
630
+ ],
631
+ "html_id": "auto_raw_interval_110"
632
+ },
633
+ "auto_raw_destination_address": {
634
+ "read_index": 40,
635
+ "write_index": 29,
636
+ "length": 4,
637
+ "descriptions": {
638
+ "title": "Set Auto Raw Destination Address",
639
+ "main_caption": "<p>Set the address where the Auto Time Domain (Raw) data will be transmitted...</p>",
640
+ "sub_caption": "<p class=\"caption\">Default value: 0000FFFF for Broadcast Mode</p>"
641
+ },
642
+ "default_value": "0000FFFF",
643
+ "validator": {
644
+ "type": "mac",
645
+ "length": 8,
646
+ "generated": true
647
+ },
648
+ "depends_on": {
649
+ "operation_mode": 3
650
+ },
651
+ "html_id": "auto_raw_destination_110"
652
+ },
653
+ "smart_mode_skip_count": {
654
+ "read_index": 44,
655
+ "write_index": 33,
656
+ "descriptions": {
657
+ "title": "Set Smart Mode Skip Interval",
658
+ "main_caption": "<p>Sensor will skip sending data this many times if vibration is below the smart threshold.</p>"
659
+ },
660
+ "default_value": 0,
661
+ "validator": {
662
+ "type": "uint8",
663
+ "min": 0,
664
+ "max": 255,
665
+ "generated": true
666
+ },
667
+ "depends_on": {
668
+ "operation_mode": 3
669
+ },
670
+ "html_id": "smart_interval_110"
671
+ },
672
+ "sync_interval": {
673
+ "read_index": 45,
674
+ "write_index": 34,
675
+ "descriptions": {
676
+ "title": "Set FLY Interval",
677
+ "main_caption": "<p>Set the interval at which the sensor will transmit FLY packets...</p>"
678
+ },
679
+ "default_value": 60,
680
+ "validator": {
681
+ "type": "uint16be",
682
+ "min": 0,
683
+ "max": 1440,
684
+ "generated": true
685
+ },
686
+ "options": {
687
+ "60": "1 Hour",
688
+ "120": "2 Hours",
689
+ "240": "4 Hours",
690
+ "480": "8 Hours",
691
+ "720": "12 Hours",
692
+ "1080": "18 Hours",
693
+ "1440": "24 Hours"
694
+ },
695
+ "tags": [
696
+ "Communications"
697
+ ],
698
+ "html_id": "fly_interval_110"
699
+ },
700
+ "rpm_compute_status": {
701
+ "read_index": 47,
702
+ "write_index": 36,
703
+ "descriptions": {
704
+ "title": "RPM Calculate Status",
705
+ "main_caption": "<p>Enable/Disable Revolutions Per Minute Calculate Status</p>"
706
+ },
707
+ "default_value": 0,
708
+ "validator": {
709
+ "type": "uint8",
710
+ "min": 0,
711
+ "max": 1,
712
+ "generated": true
713
+ },
714
+ "options": {
715
+ "0": "Disabled",
716
+ "1": "Enabled"
717
+ },
718
+ "html_id": "enable_rpm_calculate_status_110"
719
+ },
720
+ "max_raw_samples": {
721
+ "read_index": 48,
722
+ "write_index": 37,
723
+ "descriptions": {
724
+ "title": "Set Max Raw Sample",
725
+ "main_caption": "<p>Set the maximum number of samples...</p>"
726
+ },
727
+ "default_value": 0,
728
+ "validator": {
729
+ "type": "uint16be",
730
+ "min": 1024,
731
+ "max": 8100
732
+ },
733
+ "options": {
734
+ "1024": "1024 Samples",
735
+ "2048": "2048 Samples",
736
+ "4096": "4096 Samples",
737
+ "6400": "6400 Samples",
738
+ "8100": "8100 Samples"
739
+ },
740
+ "html_id": "max_raw_sample_110"
741
+ },
742
+ "motion_to_sampling_delay": {
743
+ "read_index": 50,
744
+ "write_index": 39,
745
+ "descriptions": {
746
+ "title": "Set Motion to Sampling Delay",
747
+ "main_caption": "<p>Once motion is detected, the sensor will wait...</p>"
748
+ },
749
+ "default_value": 100,
750
+ "validator": {
751
+ "type": "uint8",
752
+ "min": 0,
753
+ "max": 255,
754
+ "generated": true
755
+ },
756
+ "html_id": "motion_to_sampling_delay_110"
757
+ },
758
+ "max_motion_tx_per_interval": {
759
+ "read_index": 51,
760
+ "write_index": 40,
761
+ "descriptions": {
762
+ "title": "Set Max Number Motion Tx Per Interval",
763
+ "main_caption": "<p>Set Number of times it will send data due to motion triggers.</p>"
764
+ },
765
+ "default_value": 1,
766
+ "validator": {
767
+ "type": "uint8",
768
+ "min": 1,
769
+ "max": 255,
770
+ "generated": true
771
+ },
772
+ "html_id": "max_num_motion_tx_delay_110"
773
+ }
774
+ };
775
+ };
776
+
777
+ const sync_parse = (rep_buffer) => {
778
+ let response = {};
779
+
780
+ // Get the map based on the sensor type byte
781
+ const sync_map = get_config_map(rep_buffer[4]);
782
+
783
+ for (const [key, config] of Object.entries(sync_map)) {
784
+ // Destructure 'type' from inside 'validator' and rename 'read_index' to 'idx'
785
+ const { read_index: idx, length, validator: { type } = {} } = config;
786
+
787
+ // If for some reason a config doesn't have a validator/type, skip it
788
+ if (!type) continue;
789
+
790
+ switch (type) {
791
+ case 'uint8':
792
+ response[key] = rep_buffer[idx];
793
+ break;
794
+ case 'uint16be':
795
+ response[key] = rep_buffer.readUInt16BE(idx);
796
+ break;
797
+ case 'uint32be':
798
+ response[key] = rep_buffer.readUInt32BE(idx);
799
+ break;
800
+ case 'buffer':
801
+ response[key] = rep_buffer.subarray(idx, idx + length);
802
+ break;
803
+ case 'hex':
804
+ response[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
805
+ break;
806
+ case 'mac':
807
+ response[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
808
+ break;
809
+ }
810
+ }
811
+ if (Object.hasOwn(response, 'destination_address') && response.destination_address.toLowerCase() === '00000000') {
812
+ console.log('##############################');
813
+ console.log('#########Dest Override########');
814
+ console.log('##############################');
815
+ response.destination_address = "0000ffff";
816
+ response.auto_raw_destination_address = "0000ffff";
817
+ };
818
+ return response;
819
+ };
820
+
821
+ const parse_fly = (frame) => {
822
+ let frame_data = {};
823
+ switch (frame[16]) {
824
+ case 0:
825
+ frame_data.mode = "Processed";
826
+ break;
827
+ case 1:
828
+ frame_data.mode = "Raw";
829
+ break;
830
+ case 2:
831
+ frame_data.mode = "Processed + Raw on demand";
832
+ break;
833
+ case 3:
834
+ frame_data.mode = "Smart";
835
+ break;
836
+ }
837
+ switch (frame[17]) {
838
+ case 6:
839
+ frame_data.odr_1 = 50;
840
+ break;
841
+ case 7:
842
+ frame_data.odr_1 = 100;
843
+ break;
844
+ case 8:
845
+ frame_data.odr_1 = 200;
846
+ break;
847
+ case 9:
848
+ frame_data.odr_1 = 400;
849
+ break;
850
+ case 10:
851
+ frame_data.odr_1 = 800;
852
+ break;
853
+ case 11:
854
+ frame_data.odr_1 = 1600;
855
+ break;
856
+ case 12:
857
+ frame_data.odr_1 = 3200;
858
+ break;
859
+ case 13:
860
+ frame_data.odr_1 = 6400;
861
+ break;
862
+ case 14:
863
+ frame_data.odr_1 = 12800;
864
+ break;
865
+ case 15:
866
+ frame_data.odr_1 = 25600;
867
+ break;
868
+ }
869
+ frame_data.sampling_duration_1 = frame[18] * 50 + "ms";
870
+ switch (frame[19]) {
871
+ case 0:
872
+ frame_data.filter_status = "Disabled";
873
+ break;
874
+ case 1:
875
+ frame_data.filter_status = "Enabled";
876
+ break;
877
+ }
878
+ switch (frame[20]) {
879
+ case 0:
880
+ frame_data.lpf_coeff_1 = 4;
881
+ break;
882
+ case 1:
883
+ frame_data.lpf_coeff_1 = 8;
884
+ break;
885
+ case 2:
886
+ frame_data.lpf_coeff_1 = 16;
887
+ break;
888
+ case 2:
889
+ frame_data.lpf_coeff_1 = 32;
890
+ break;
891
+ case 4:
892
+ frame_data.lpf_coeff_1 = 64;
893
+ break;
894
+ case 5:
895
+ frame_data.lpf_coeff_1 = 128;
896
+ break;
897
+ case 6:
898
+ frame_data.lpf_coeff_1 = 256;
899
+ break;
900
+ case 7:
901
+ frame_data.lpf_coeff_1 = 512;
902
+ break;
903
+ case 8:
904
+ frame_data.lpf_coeff_1 = 1024;
905
+ break;
906
+ case 9:
907
+ frame_data.lpf_coeff_1 = 2048;
908
+ break;
909
+ }
910
+ frame_data.lpf_freq_1 = frame_data.odr_1 / frame_data.lpf_coeff_1;
911
+ switch (frame[21]) {
912
+ case 0:
913
+ frame_data.hpf_coeff_1 = 4;
914
+ break;
915
+ case 1:
916
+ frame_data.hpf_coeff_1 = 8;
917
+ break;
918
+ case 2:
919
+ frame_data.hpf_coeff_1 = 16;
920
+ break;
921
+ case 2:
922
+ frame_data.hpf_coeff_1 = 32;
923
+ break;
924
+ case 4:
925
+ frame_data.hpf_coeff_1 = 64;
926
+ break;
927
+ case 5:
928
+ frame_data.hpf_coeff_1 = 128;
929
+ break;
930
+ case 6:
931
+ frame_data.hpf_coeff_1 = 256;
932
+ break;
933
+ case 7:
934
+ frame_data.hpf_coeff_1 = 512;
935
+ break;
936
+ case 8:
937
+ frame_data.hpf_coeff_1 = 1024;
938
+ break;
939
+ case 9:
940
+ frame_data.hpf_coeff_1 = 2048;
941
+ break;
942
+ }
943
+ frame_data.hpf_freq_1 = frame_data.odr_1 / frame_data.hpf_coeff_1;
944
+ switch (frame[22]) {
945
+ case 0:
946
+ frame_data.sampling_interval = "5 Minutes";
947
+ frame_data.sampling_interval_number = 5;
948
+ break;
949
+ case 1:
950
+ frame_data.sampling_interval = "10 Minutes";
951
+ frame_data.sampling_interval_number = 10;
952
+ break;
953
+ case 2:
954
+ frame_data.sampling_interval = "15 Minutes";
955
+ frame_data.sampling_interval_number = 15;
956
+ break;
957
+ case 2:
958
+ frame_data.sampling_interval = "20 Minutes";
959
+ frame_data.sampling_interval_number = 20;
960
+ break;
961
+ case 4:
962
+ frame_data.sampling_interval = "30 Minutes";
963
+ frame_data.sampling_interval_number = 30;
964
+ break;
965
+ case 5:
966
+ frame_data.sampling_interval = "60 Minutes";
967
+ frame_data.sampling_interval_number = 60;
968
+ break;
969
+ case 6:
970
+ frame_data.sampling_interval = "120 Minutes";
971
+ frame_data.sampling_interval_number = 120;
972
+ break;
973
+ case 7:
974
+ frame_data.sampling_interval = "180 Minutes";
975
+ frame_data.sampling_interval_number = 180;
976
+ break;
977
+ case 8:
978
+ frame_data.sampling_interval = "1 Minute";
979
+ frame_data.sampling_interval_number = 1;
980
+ break;
981
+ }
982
+ frame_data.on_request_timeout = frame[23] + " Seconds";
983
+ frame_data.deadband = frame[24] + "mg";
984
+
985
+ switch (frame[25]) {
986
+ case 0:
987
+ frame_data.payload_length = "50 Bytes";
988
+ break;
989
+ case 1:
990
+ frame_data.payload_length = "100 Bytes";
991
+ break;
992
+ case 2:
993
+ frame_data.payload_length = "150 Bytes";
994
+ break;
995
+ case 3:
996
+ frame_data.payload_length = "180 Bytes";
997
+ break;
998
+ }
999
+ switch (frame[26]) {
1000
+ case 0:
1001
+ frame_data.fsr_text = "2g";
1002
+ break;
1003
+ case 1:
1004
+ frame_data.fsr_text = "4g";
1005
+ break;
1006
+ case 2:
1007
+ frame_data.fsr_text = "8g";
1008
+ break;
1009
+ case 3:
1010
+ frame_data.fsr_text = "16g";
1011
+ break;
1012
+ }
1013
+ frame_data.rpm_status = frame[27] ? 'Enabled' : 'Disabled';
1014
+ frame_data.auto_raw_interval = frame[32] * frame_data.sampling_interval_number || 'disabled';
1015
+ frame_data.auto_raw_interval = typeof frame_data.auto_raw_interval === 'number' ? frame_data.auto_raw_interval + 'min' : frame_data.auto_raw_interval;
1016
+ frame_data.smart_mode_threshold = frame[34] * 50;
1017
+ if (frame[2] > 6) { // for Firmware v7 and above
1018
+ frame_data.motion_to_delay = frame[41] * 50;
1019
+ return {
1020
+ 'firmware': frame[2],
1021
+ 'destination_address': toMac(frame.slice(12, 16)),
1022
+ 'mode': frame_data.mode,
1023
+ 'odr': frame_data.odr_1 + 'Hz',
1024
+ 'sampling_duration': frame_data.sampling_duration_1,
1025
+ 'filter_status': frame_data.filter_status,
1026
+ 'lpf_coeff': frame_data.lpf_coeff_1,
1027
+ 'lpf_freq': frame_data.lpf_freq_1 + 'Hz',
1028
+ 'hpf_coeff': frame_data.hpf_coeff_1,
1029
+ 'hpf_freq': frame_data.hpf_freq_1 + 'Hz',
1030
+ 'sampling_interval': frame_data.sampling_interval,
1031
+ 'on_request_timeout': frame_data.on_request_timeout,
1032
+ 'deadband': frame_data.deadband,
1033
+ 'payload_length': frame_data.payload_length,
1034
+ 'fsr': frame_data.fsr_text,
1035
+ 'rpm_compute_status': frame_data.rpm_status,
1036
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32)),
1037
+ 'auto_raw_interval': frame_data.auto_raw_interval,
1038
+ 'smart_mode_skip_count': frame[33],
1039
+ 'smart_mode_acc_threshold': frame_data.smart_mode_threshold + 'mg',
1040
+ 'uptime_counter': frame.slice(35, 39).reduce(msbLsb) + 'sec',
1041
+ 'max_tx_raw_samples': frame.slice(39, 41).reduce(msbLsb),
1042
+ 'motion_to_sampling_delay': frame_data.motion_to_delay + 'msec',
1043
+ 'max_num_of_motion_tx_per_interval': frame[42],
1044
+ 'hardware_id': frame.slice(43, 46),
1045
+ 'reserved': frame.slice(46, 50),
1046
+ 'tx_lifetime_counter': frame.slice(50, 54).reduce(msbLsb),
1047
+ 'machine_values': {
1048
+ 'firmware': frame[2],
1049
+ 'destination_address': toMac(frame.slice(12, 16), false),
1050
+ 'mode': frame[16],
1051
+ 'odr': frame[17],
1052
+ 'sampling_duration': frame[18],
1053
+ 'filter_status': frame[19],
1054
+ 'lpf_coeff': frame[20],
1055
+ 'hpf_coeff': frame[21],
1056
+ 'sampling_interval': frame[22],
1057
+ 'on_request_timeout': frame[23],
1058
+ 'deadband': frame[24],
1059
+ 'payload_length': frame[25],
1060
+ 'fsr': frame[26],
1061
+ 'rpm_compute_status': frame[27],
1062
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32), false),
1063
+ 'auto_raw_interval': frame[32],
1064
+ 'smart_mode_skip_count': frame[33],
1065
+ 'smart_mode_acc_threshold': frame[34],
1066
+ 'uptime_counter': frame.slice(35, 39),
1067
+ 'max_tx_raw_samples': frame.slice(39, 41),
1068
+ 'motion_to_sampling_delay': frame[41],
1069
+ 'max_num_of_motion_tx_per_interval': frame[42],
1070
+ 'hardware_id': frame.slice(43, 46),
1071
+ 'reserved': frame.slice(46, 50),
1072
+ 'tx_lifetime_counter': frame.slice(50, 54)
1073
+ }
1074
+ }
1075
+ } else if (frame[2] > 5) { // for Firmware v6
1076
+ frame_data.motion_to_delay = frame[41] * 50;
1077
+ return {
1078
+ 'firmware': frame[2],
1079
+ 'destination_address': toMac(frame.slice(12, 16)),
1080
+ 'mode': frame_data.mode,
1081
+ 'odr': frame_data.odr_1 + 'Hz',
1082
+ 'sampling_duration': frame_data.sampling_duration_1,
1083
+ 'filter_status': frame_data.filter_status,
1084
+ 'lpf_coeff': frame_data.lpf_coeff_1,
1085
+ 'lpf_freq': frame_data.lpf_freq_1 + 'Hz',
1086
+ 'hpf_coeff': frame_data.hpf_coeff_1,
1087
+ 'hpf_freq': frame_data.hpf_freq_1 + 'Hz',
1088
+ 'sampling_interval': frame_data.sampling_interval,
1089
+ 'on_request_timeout': frame_data.on_request_timeout,
1090
+ 'deadband': frame_data.deadband,
1091
+ 'payload_length': frame_data.payload_length,
1092
+ 'fsr': frame_data.fsr_text,
1093
+ 'rpm_compute_status': frame_data.rpm_status,
1094
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32)),
1095
+ 'auto_raw_interval': frame_data.auto_raw_interval,
1096
+ 'smart_mode_skip_count': frame[33],
1097
+ 'smart_mode_acc_threshold': frame_data.smart_mode_threshold + 'mg',
1098
+ 'uptime_counter': frame.slice(35, 39).reduce(msbLsb) + 'sec',
1099
+ 'max_tx_raw_samples': frame.slice(39, 41).reduce(msbLsb),
1100
+ 'machine_values': {
1101
+ 'firmware': frame[2],
1102
+ 'destination_address': toMac(frame.slice(12, 16), false),
1103
+ 'mode': frame[16],
1104
+ 'odr': frame[17],
1105
+ 'sampling_duration': frame[18],
1106
+ 'filter_status': frame[19],
1107
+ 'lpf_coeff': frame[20],
1108
+ 'hpf_coeff': frame[21],
1109
+ 'sampling_interval': frame[22],
1110
+ 'on_request_timeout': frame[23],
1111
+ 'deadband': frame[24],
1112
+ 'payload_length': frame[25],
1113
+ 'fsr': frame[26],
1114
+ 'rpm_compute_status': frame[27],
1115
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32), false),
1116
+ 'auto_raw_interval': frame[32],
1117
+ 'smart_mode_skip_count': frame[33],
1118
+ 'smart_mode_acc_threshold': frame[34],
1119
+ 'uptime_counter': frame.slice(35, 39),
1120
+ 'max_tx_raw_samples': frame.slice(39, 41)
1121
+ }
1122
+ }
1123
+ } else if (frame[2] > 4) { // for Firmware v5 and above
1124
+ return {
1125
+ 'firmware': frame[2],
1126
+ 'destination_address': toMac(frame.slice(12, 16)),
1127
+ 'mode': frame_data.mode,
1128
+ 'odr': frame_data.odr_1 + 'Hz',
1129
+ 'sampling_duration': frame_data.sampling_duration_1,
1130
+ 'filter_status': frame_data.filter_status,
1131
+ 'lpf_coeff': frame_data.lpf_coeff_1,
1132
+ 'lpf_freq': frame_data.lpf_freq_1 + 'Hz',
1133
+ 'hpf_coeff': frame_data.hpf_coeff_1,
1134
+ 'hpf_freq': frame_data.hpf_freq_1 + 'Hz',
1135
+ 'sampling_interval': frame_data.sampling_interval,
1136
+ 'on_request_timeout': frame_data.on_request_timeout,
1137
+ 'deadband': frame_data.deadband,
1138
+ 'payload_length': frame_data.payload_length,
1139
+ 'fsr': frame_data.fsr_text,
1140
+ 'rpm_compute_status': frame_data.rpm_status,
1141
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32)),
1142
+ 'auto_raw_interval': frame_data.auto_raw_interval,
1143
+ 'smart_mode_skip_count': frame[33],
1144
+ 'smart_mode_acc_threshold': frame_data.smart_mode_threshold + 'mg',
1145
+ 'uptime_counter': frame.slice(35, 39).reduce(msbLsb) + 'sec',
1146
+ 'max_tx_raw_samples': frame.slice(39, 41).reduce(msbLsb),
1147
+ 'hardware_id': frame.slice(41, 44),
1148
+ 'reserved': frame.slice(44, 48),
1149
+ 'tx_lifetime_counter': frame.slice(48, 52).reduce(msbLsb),
1150
+ 'machine_values': {
1151
+ 'firmware': frame[2],
1152
+ 'destination_address': toMac(frame.slice(12, 16), false),
1153
+ 'mode': frame[16],
1154
+ 'odr': frame[17],
1155
+ 'sampling_duration': frame[18],
1156
+ 'filter_status': frame[19],
1157
+ 'lpf_coeff': frame[20],
1158
+ 'hpf_coeff': frame[21],
1159
+ 'sampling_interval': frame[22],
1160
+ 'on_request_timeout': frame[23],
1161
+ 'deadband': frame[24],
1162
+ 'payload_length': frame[25],
1163
+ 'fsr': frame[26],
1164
+ 'rpm_compute_status': frame[27],
1165
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32), false),
1166
+ 'auto_raw_interval': frame[32],
1167
+ 'smart_mode_skip_count': frame[33],
1168
+ 'smart_mode_acc_threshold': frame[34],
1169
+ 'uptime_counter': frame.slice(35, 39),
1170
+ 'max_tx_raw_samples': frame.slice(39, 41),
1171
+ 'hardware_id': frame.slice(41, 44),
1172
+ 'reserved': frame.slice(44, 48),
1173
+ 'tx_lifetime_counter': frame.slice(48, 52)
1174
+ }
1175
+ }
1176
+ } else {
1177
+ return {
1178
+ 'firmware': frame[2],
1179
+ 'destination_address': toMac(frame.slice(12, 16)),
1180
+ 'mode': frame_data.mode,
1181
+ 'odr': frame_data.odr_1 + 'Hz',
1182
+ 'sampling_duration': frame_data.sampling_duration_1,
1183
+ 'filter_status': frame_data.filter_status,
1184
+ 'lpf_coeff': frame_data.lpf_coeff_1,
1185
+ 'lpf_freq': frame_data.lpf_freq_1 + 'Hz',
1186
+ 'hpf_coeff': frame_data.hpf_coeff_1,
1187
+ 'hpf_freq': frame_data.hpf_freq_1 + 'Hz',
1188
+ 'sampling_interval': frame_data.sampling_interval,
1189
+ 'on_request_timeout': frame_data.on_request_timeout,
1190
+ 'deadband': frame_data.deadband,
1191
+ 'payload_length': frame_data.payload_length,
1192
+ 'fsr': frame_data.fsr_text,
1193
+ 'rpm_compute_status': frame_data.rpm_status,
1194
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32)),
1195
+ 'auto_raw_interval': frame_data.auto_raw_interval,
1196
+ 'smart_mode_skip_count': frame[33],
1197
+ 'smart_mode_acc_threshold': frame_data.smart_mode_threshold + 'mg',
1198
+ 'uptime_counter': frame.slice(35, 39).reduce(msbLsb) + 'sec',
1199
+ 'hardware_id': frame.slice(39, 42),
1200
+ 'reserved': frame.slice(42, 46),
1201
+ 'tx_lifetime_counter': frame.slice(46, 50).reduce(msbLsb),
1202
+ 'machine_values': {
1203
+ 'firmware': frame[2],
1204
+ 'destination_address': toMac(frame.slice(12, 16), false),
1205
+ 'mode': frame[16],
1206
+ 'odr': frame[17],
1207
+ 'sampling_duration': frame[18],
1208
+ 'filter_status': frame[19],
1209
+ 'lpf_coeff': frame[20],
1210
+ 'hpf_coeff': frame[21],
1211
+ 'sampling_interval': frame[22],
1212
+ 'on_request_timeout': frame[23],
1213
+ 'deadband': frame[24],
1214
+ 'payload_length': frame[25],
1215
+ 'fsr': frame[26],
1216
+ 'rpm_compute_status': frame[27],
1217
+ 'auto_raw_destination_address': toMac(frame.slice(28, 32), false),
1218
+ 'auto_raw_interval': frame[32],
1219
+ 'smart_mode_skip_count': frame[33],
1220
+ 'smart_mode_acc_threshold': frame[34],
1221
+ 'uptime_counter': frame.slice(35, 39),
1222
+ 'hardware_id': frame.slice(39, 42),
1223
+ 'reserved': frame.slice(42, 46),
1224
+ 'tx_lifetime_counter': frame.slice(46, 50)
1225
+ }
1226
+ }
1227
+ }
1228
+ }
1229
+
1230
+ const parse = (payload, parsed, mac) => {
1231
+ if (payload[7] & 2) {
1232
+ console.log('Error found');
1233
+ parsed.data = { error: 'Error found, Sensor Probe may be unattached' };
1234
+ return parsed;
1235
+ }
1236
+ let msg_type = (payload[7] & 16) ? 'motion' : 'regular';
1237
+ if (payload[8] === 1) {
1238
+
1239
+ var deviceAddr = mac;
1240
+ var expected_packets = msbLsb(payload[16], payload[17]);
1241
+ var current_packet = msbLsb(payload[18], payload[19]);
1242
+ var sdata_start = 20;
1243
+
1244
+ if (globalDevices.hasOwnProperty(deviceAddr) || expected_packets == 1) {
1245
+ if (expected_packets != 1) {
1246
+ if (globalDevices[deviceAddr].last_packet_counter == current_packet) {
1247
+ console.log('Duplicated message');
1248
+ return;
1249
+ }
1250
+ if (current_packet == 1 || (globalDevices[deviceAddr].last_packet_counter > current_packet)) {
1251
+ console.log('Recovering bad packet');
1252
+ clear_globalDevices_stream(deviceAddr);
1253
+ init_globalDevices_stream(deviceAddr, payload, expected_packets, parsed, msg_type);
1254
+ globalDevices[deviceAddr].last_packet_counter = current_packet;
1255
+ globalDevices[deviceAddr].data[current_packet] = payload.slice(sdata_start);
1256
+ return;
1257
+ }
1258
+ else {
1259
+ globalDevices[deviceAddr].last_packet_counter = current_packet;
1260
+ globalDevices[deviceAddr].data[current_packet] = payload.slice(sdata_start);
1261
+ }
1262
+ }
1263
+ else {
1264
+ clear_globalDevices_stream(deviceAddr);
1265
+ init_globalDevices_stream(deviceAddr, payload, expected_packets, parsed, msg_type);
1266
+ globalDevices[deviceAddr].last_packet_counter = current_packet;
1267
+ globalDevices[deviceAddr].data[current_packet] = payload.slice(sdata_start);
1268
+ }
1269
+ }
1270
+ else {
1271
+ clear_globalDevices_stream(deviceAddr);
1272
+ init_globalDevices_stream(deviceAddr, payload, expected_packets, parsed, msg_type);
1273
+ globalDevices[deviceAddr].last_packet_counter = current_packet;
1274
+ globalDevices[deviceAddr].data[current_packet] = payload.slice(sdata_start);
1275
+ }
1276
+ if (current_packet == expected_packets) {
1277
+ sensor_data = concat_fft_data(deviceAddr, payload[8], msg_type);
1278
+ clear_globalDevices_stream(deviceAddr);
1279
+ return sensor_data;
1280
+ }
1281
+ else {
1282
+ return;
1283
+ }
1284
+ }
1285
+ else if (payload[8] === 0 || payload[8] === 2 || payload[8] === 3) {
1286
+ var odr;
1287
+ switch (payload[9]) {
1288
+ case 6: odr = "50Hz"; break;
1289
+ case 7: odr = "100Hz"; break;
1290
+ case 8: odr = "200Hz"; break;
1291
+ case 9: odr = "400Hz"; break;
1292
+ case 10: odr = "800Hz"; break;
1293
+ case 11: odr = "1600Hz"; break;
1294
+ case 12: odr = "3200Hz"; break;
1295
+ case 13: odr = "6400Hz"; break;
1296
+ case 14: odr = "12800Hz"; break;
1297
+ case 15: odr = "25600Hz"; break;
1298
+ }
1299
+ return {
1300
+ mode: payload[8],
1301
+ msg_type: msg_type,
1302
+ odr: odr,
1303
+ temperature: signInt(payload.slice(10, 12).reduce(msbLsb), 16) / 100,
1304
+ x_rms_ACC_G: payload.slice(12, 14).reduce(msbLsb) / 1000,
1305
+ x_max_ACC_G: payload.slice(14, 16).reduce(msbLsb) / 1000,
1306
+ x_velocity_mm_sec: payload.slice(16, 18).reduce(msbLsb) / 100,
1307
+ x_displacement_mm: payload.slice(18, 20).reduce(msbLsb) / 100,
1308
+ x_peak_one_Hz: payload.slice(20, 22).reduce(msbLsb),
1309
+ x_peak_two_Hz: payload.slice(22, 24).reduce(msbLsb),
1310
+ x_peak_three_Hz: payload.slice(24, 26).reduce(msbLsb),
1311
+ y_rms_ACC_G: payload.slice(26, 28).reduce(msbLsb) / 1000,
1312
+ y_max_ACC_G: payload.slice(28, 30).reduce(msbLsb) / 1000,
1313
+ y_velocity_mm_sec: payload.slice(30, 32).reduce(msbLsb) / 100,
1314
+ y_displacement_mm: payload.slice(32, 34).reduce(msbLsb) / 100,
1315
+ y_peak_one_Hz: payload.slice(34, 36).reduce(msbLsb),
1316
+ y_peak_two_Hz: payload.slice(36, 38).reduce(msbLsb),
1317
+ y_peak_three_Hz: payload.slice(38, 40).reduce(msbLsb),
1318
+ z_rms_ACC_G: payload.slice(40, 42).reduce(msbLsb) / 1000,
1319
+ z_max_ACC_G: payload.slice(42, 44).reduce(msbLsb) / 1000,
1320
+ z_velocity_mm_sec: payload.slice(44, 46).reduce(msbLsb) / 100,
1321
+ z_displacement_mm: payload.slice(46, 48).reduce(msbLsb) / 100,
1322
+ z_peak_one_Hz: payload.slice(48, 50).reduce(msbLsb),
1323
+ z_peak_two_Hz: payload.slice(50, 52).reduce(msbLsb),
1324
+ z_peak_three_Hz: payload.slice(52, 54).reduce(msbLsb),
1325
+ rpm: payload.slice(54, 56).reduce(msbLsb)
1326
+ };
1327
+ }
1328
+ };
1329
+
1330
+
1331
+ // Export the module with all the necessary functions and properties
1332
+ // that need to be called from outside the scrip
1333
+ return {
1334
+ type: 114,
1335
+ name: 'Standalone Smart Vibration Sensor v4',
1336
+ parse,
1337
+ get_write_buffer_size,
1338
+ get_config_map,
1339
+ sync_parse,
1340
+ parse_fly,
1341
+ };
1342
+ };