@ncd-io/node-red-enterprise-sensors 2.0.3 → 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,472 @@
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 33;
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": 3,
145
+ "validator": {
146
+ "type": "uint32be"
147
+ },
148
+ "html_id": "delay"
149
+ },
150
+ "adc_pin_reading": {
151
+ "read_index": 25,
152
+ "validator": {
153
+ "type": "uint16be"
154
+ },
155
+ "tags": [
156
+ "diagnostics"
157
+ ]
158
+ },
159
+ "fsr": {
160
+ "read_index": 27,
161
+ "write_index": 14,
162
+ "descriptions": {
163
+ "title": "Set FSR",
164
+ "main_caption": ""
165
+ },
166
+ "default_value": 0,
167
+ "validator": {
168
+ "type": "uint8",
169
+ "min": 0,
170
+ "max": 5,
171
+ "generated": true
172
+ },
173
+ "options": {
174
+ "0": "6.114",
175
+ "1": "4.096",
176
+ "2": "2.048",
177
+ "3": "1.024",
178
+ "4": "0.512",
179
+ "5": "0.256"
180
+ },
181
+ "html_id": "fsr_420ma"
182
+ },
183
+ "calibration_one": {
184
+ "read_index": 28,
185
+ "write_index": 15,
186
+ "descriptions": {
187
+ "title": "Low Calibration Point",
188
+ "main_caption": ""
189
+ },
190
+ "default_value": 68805,
191
+ "validator": {
192
+ "type": "uint32be",
193
+ "min": 0,
194
+ "max": 4294967295
195
+ },
196
+ "html_id": "low_calibration_420ma"
197
+ },
198
+ "calibration_two": {
199
+ "read_index": 32,
200
+ "write_index": 19,
201
+ "descriptions": {
202
+ "title": "Mid Calibration Point",
203
+ "main_caption": ""
204
+ },
205
+ "default_value": 68724,
206
+ "validator": {
207
+ "type": "uint32be",
208
+ "min": 0,
209
+ "max": 4294967295
210
+ },
211
+ "html_id": "mid_calibration_420ma"
212
+ },
213
+ "calibration_three": {
214
+ "read_index": 36,
215
+ "write_index": 23,
216
+ "descriptions": {
217
+ "title": "High Calibration Point",
218
+ "main_caption": ""
219
+ },
220
+ "default_value": 68714,
221
+ "validator": {
222
+ "type": "uint32be",
223
+ "min": 0,
224
+ "max": 4294967295
225
+ },
226
+ "html_id": "high_calibration_420ma"
227
+ },
228
+ "boot_up_time": {
229
+ "read_index": 40,
230
+ "write_index": 27,
231
+ "descriptions": {
232
+ "title": "Sensor Boot Time",
233
+ "main_caption": ""
234
+ },
235
+ "default_value": 0,
236
+ "validator": {
237
+ "type": "uint8",
238
+ "min": 0,
239
+ "max": 255
240
+ },
241
+ "html_id": "sensor_boot_time_420ma"
242
+ },
243
+ "always_on": {
244
+ "read_index": 41,
245
+ "write_index": 28,
246
+ "descriptions": {
247
+ "title": "Set Sensor Always On",
248
+ "main_caption": "This command will keep the external power to the sensor always enabled."
249
+ },
250
+ "default_value": 0,
251
+ "validator": {
252
+ "type": "uint8",
253
+ "min": 0,
254
+ "max": 1,
255
+ "generated": true
256
+ },
257
+ "options": {
258
+ "0": "Disable",
259
+ "1": "Enable"
260
+ },
261
+ "html_id": "always_on_420ma"
262
+ },
263
+ "friction_noise_level": {
264
+ "read_index": 42,
265
+ "write_index": 29,
266
+ "descriptions": {
267
+ "title": "Set Friction Noise Level",
268
+ "main_caption": ""
269
+ },
270
+ "default_value": 35,
271
+ "validator": {
272
+ "type": "uint8",
273
+ "min": 1,
274
+ "max": 255
275
+ },
276
+ "html_id": "friction_level_105"
277
+ },
278
+ "faulty_noise_level": {
279
+ "read_index": 43,
280
+ "write_index": 30,
281
+ "descriptions": {
282
+ "title": "Set Faulty Noise Level",
283
+ "main_caption": ""
284
+ },
285
+ "default_value": 45,
286
+ "validator": {
287
+ "type": "uint8",
288
+ "min": 0,
289
+ "max": 255
290
+ },
291
+ "html_id": "faulty_level_105"
292
+ },
293
+ "lube_1_on_time": {
294
+ "read_index": 44,
295
+ "write_index": 31,
296
+ "descriptions": {
297
+ "title": "Set Lube On Time 1",
298
+ "main_caption": ""
299
+ },
300
+ "default_value": 10,
301
+ "validator": {
302
+ "type": "uint8",
303
+ "min": 0,
304
+ "max": 255
305
+ },
306
+ "html_id": "lube_on_time_1_105"
307
+ },
308
+ "lube_2_on_time": {
309
+ "read_index": 45,
310
+ "write_index": 32,
311
+ "descriptions": {
312
+ "title": "Set Lube On Time 2",
313
+ "main_caption": ""
314
+ },
315
+ "default_value": 10,
316
+ "validator": {
317
+ "type": "uint8",
318
+ "min": 0,
319
+ "max": 255
320
+ },
321
+ "html_id": "lube_on_time_2_105"
322
+ }
323
+ };
324
+ };
325
+
326
+ const sync_parse = (rep_buffer) => {
327
+ let response = {
328
+ 'human_readable': {},
329
+ 'machine_values': {}
330
+ };
331
+
332
+ // Get the map based on the sensor type byte
333
+ const sync_map = get_config_map(rep_buffer[4]);
334
+
335
+ for (const [key, config] of Object.entries(sync_map)) {
336
+ // Destructure 'type' from inside 'validator' and rename 'read_index' to 'idx'
337
+ const { read_index: idx, length, validator: { type } = {}, converter, options } = config;
338
+
339
+ // If for some reason a config doesn't have a validator/type, skip it
340
+ if (!type) continue;
341
+
342
+ switch (type) {
343
+ case 'uint8':
344
+ response.machine_values[key] = rep_buffer[idx];
345
+ break;
346
+ case 'uint16be':
347
+ response.machine_values[key] = rep_buffer.readUInt16BE(idx);
348
+ break;
349
+ case 'uint32be':
350
+ response.machine_values[key] = rep_buffer.readUInt32BE(idx);
351
+ break;
352
+ case 'buffer':
353
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length);
354
+ break;
355
+ case 'hex':
356
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
357
+ break;
358
+ case 'mac':
359
+ response.machine_values[key] = rep_buffer.subarray(idx, idx + length).toString('hex');
360
+ break;
361
+ }
362
+ let human_value = response.machine_values[key];
363
+ if(options && options[response.machine_values[key]]){
364
+ human_value = options[response.machine_values[key]];
365
+ }else{
366
+ if(converter && converter.multiplier){
367
+ human_value = human_value * converter.multiplier;
368
+ }
369
+ if(converter && converter.units){
370
+ human_value = human_value + converter.units;
371
+ }
372
+ }
373
+ response.human_readable[key] = human_value;
374
+ }
375
+ if (Object.hasOwn(response.machine_values, 'destination_address') && response.machine_values.destination_address.toLowerCase() === '00000000') {
376
+ console.log('##############################');
377
+ console.log('#########Dest Override########');
378
+ console.log('##############################');
379
+ response.destination_address = "0000ffff";
380
+ // response.auto_raw_destination_address = "0000ffff";
381
+ };
382
+ return response;
383
+ };
384
+
385
+ const parse_fly = (frame) => {
386
+ let firmware = frame[2];
387
+ if(firmware > 13){ // firmware 14 and above
388
+ let frame_data = {};
389
+ let auto_check_interval = frame.slice(20, 22).reduce(msbLsb);
390
+ if(!auto_check_interval){
391
+ frame_data.auto_check_interval = 'Disabled';
392
+ }else{
393
+ frame_data.auto_check_interval = auto_check_interval + " sec";
394
+ }
395
+ frame_data.always_on = frame[24]?"Enabled":"Disabled";
396
+ switch(frame[16]){
397
+ case 0:
398
+ frame_data.fsr = "+-6.114 V";
399
+ break;
400
+ case 1:
401
+ frame_data.fsr = "+-4.096 V";
402
+ break;
403
+ case 2:
404
+ frame_data.fsr = "+-2.048 V";
405
+ break;
406
+ case 3:
407
+ frame_data.fsr = "+-1.024 V";
408
+ break;
409
+ case 4:
410
+ frame_data.fsr = "+-0.512 V";
411
+ break;
412
+ case 5:
413
+ frame_data.fsr = "+-0.256 V";
414
+ break;
415
+ }
416
+ return {
417
+ 'firmware': frame[2],
418
+ 'fsr': frame_data.fsr,
419
+ 'boot_up_time': frame[17] + " sec",
420
+ 'adc_pin_reading': frame.slice(18, 20).reduce(msbLsb),
421
+ 'auto_check_interval': frame_data.auto_check_interval,
422
+ 'auto_check_threshold': frame.slice(22, 24).reduce(msbLsb),
423
+ 'always_on': frame_data.always_on,
424
+ 'calibration_one': frame.slice(25, 29).reduce(msbLsb),
425
+ 'calibration_two':frame.slice(29, 33).reduce(msbLsb),
426
+ 'calibration_three':frame.slice(33, 37).reduce(msbLsb),
427
+ 'hardware_id': frame.slice(37, 40),
428
+ 'report_rate': frame.slice(40, 44).reduce(msbLsb) + " sec",
429
+ 'tx_life_counter': frame.slice(44, 48).reduce(msbLsb),
430
+ 'machine_values': {
431
+ 'firmware': frame[2],
432
+ 'fsr': frame[16],
433
+ 'boot_up_time': frame[17],
434
+ 'adc_pin_reading': frame.slice(18, 20),
435
+ 'auto_check_interval': frame.slice(20, 22),
436
+ 'auto_check_percentage': frame.slice(22, 24),
437
+ 'always_on': frame[24],
438
+ 'calibration_one': frame.slice(25, 29),
439
+ 'calibration_two':frame.slice(29, 33),
440
+ 'calibration_three':frame.slice(33, 37),
441
+ 'hardware_id': frame.slice(37, 40),
442
+ 'report_rate': frame.slice(40, 44),
443
+ 'tx_life_counter': frame.slice(44, 48)
444
+ }
445
+ }
446
+ }
447
+ };
448
+
449
+ const parse = (d) => {
450
+ return {
451
+ c1_raw_adc: d.slice(0, 2).reduce(msbLsb),
452
+ c1_ma: d.slice(2, 4).reduce(msbLsb) / 100,
453
+ c1_db: d.slice(4, 6).reduce(msbLsb) / 100,
454
+ c2_raw_adc: d.slice(6, 8).reduce(msbLsb),
455
+ c2_ma: d.slice(8, 10).reduce(msbLsb) / 100,
456
+ c2_db: d.slice(10, 12).reduce(msbLsb) / 100
457
+ };
458
+ };
459
+
460
+ // --- 2. EXPORT THE MODULE ---
461
+ // Export the module with all the necessary functions and properties
462
+ // that need to be called from outside the scrip
463
+ return {
464
+ type: 106,
465
+ name: '2 Channel Automatic Luber With Ultrasound Vibration Sensor',
466
+ parse,
467
+ get_write_buffer_size,
468
+ get_config_map,
469
+ sync_parse,
470
+ parse_fly
471
+ };
472
+ };
@@ -419,8 +419,8 @@ module.exports = (globalDevices, emitter) => {
419
419
  "generated": true
420
420
  },
421
421
  "options": {
422
- "0": "Enabled",
423
- "1": "Disabled"
422
+ "0": "Disabled",
423
+ "1": "Enabled"
424
424
  },
425
425
  "html_id": "enable_filtering_110"
426
426
  },
@@ -513,44 +513,44 @@ module.exports = (globalDevices, emitter) => {
513
513
  },
514
514
  "html_id": "motion_detect_threshold_p1_110"
515
515
  },
516
- "led_acceleration_alert_threshold": {
517
- "read_index": 34,
518
- "write_index": 23,
519
- "descriptions": {
520
- "title": "LED Accelerometer Threshold",
521
- "main_caption": "<div><p>Set the minimum acceleration value...</p></div>"
522
- },
523
- "default_value": 10,
524
- "validator": {
525
- "type": "uint8",
526
- "min": 0,
527
- "max": 255,
528
- "generated": true
529
- },
530
- "depends_on": {
531
- "led_alert_mode": 0
532
- },
533
- "html_id": "led_accelerometer_threshold_84"
534
- },
535
- "led_velocity_alert_threshold": {
536
- "read_index": 35,
537
- "write_index": 24,
538
- "descriptions": {
539
- "title": "LED Velocity Threshold",
540
- "main_caption": "<div><p>Set the minimum velocity value...</p></div>"
541
- },
542
- "default_value": 10,
543
- "validator": {
544
- "type": "uint8",
545
- "min": 0,
546
- "max": 255,
547
- "generated": true
548
- },
549
- "depends_on": {
550
- "led_alert_mode": 1
551
- },
552
- "html_id": "led_velocity_threshold_84"
553
- },
516
+ // "led_acceleration_alert_threshold": {
517
+ // "read_index": 34,
518
+ // "write_index": 23,
519
+ // "descriptions": {
520
+ // "title": "LED Accelerometer Threshold",
521
+ // "main_caption": "<div><p>Set the minimum acceleration value...</p></div>"
522
+ // },
523
+ // "default_value": 10,
524
+ // "validator": {
525
+ // "type": "uint8",
526
+ // "min": 0,
527
+ // "max": 255,
528
+ // "generated": true
529
+ // },
530
+ // "depends_on": {
531
+ // "led_alert_mode": 0
532
+ // },
533
+ // "html_id": "led_accelerometer_threshold_84"
534
+ // },
535
+ // "led_velocity_alert_threshold": {
536
+ // "read_index": 35,
537
+ // "write_index": 24,
538
+ // "descriptions": {
539
+ // "title": "LED Velocity Threshold",
540
+ // "main_caption": "<div><p>Set the minimum velocity value...</p></div>"
541
+ // },
542
+ // "default_value": 10,
543
+ // "validator": {
544
+ // "type": "uint8",
545
+ // "min": 0,
546
+ // "max": 255,
547
+ // "generated": true
548
+ // },
549
+ // "depends_on": {
550
+ // "led_alert_mode": 1
551
+ // },
552
+ // "html_id": "led_velocity_threshold_84"
553
+ // },
554
554
  "smart_accelerometer_threshold": {
555
555
  "read_index": 36,
556
556
  "write_index": 25,
@@ -782,6 +782,21 @@ module.exports = (globalDevices, emitter) => {
782
782
  },
783
783
  "html_id": "max_num_motion_tx_delay_110",
784
784
  "old_fly_id": "max_num_of_motion_tx_per_interval"
785
+ },
786
+ "uptime_counter": {
787
+ "read_index": 52,
788
+ "descriptions": {
789
+ "title": "",
790
+ "main_caption": ""
791
+ },
792
+ "default_value": 1,
793
+ "validator": {
794
+ "type": "uint32be",
795
+ "min": 1,
796
+ "max": 4294967295,
797
+ "generated": true
798
+ },
799
+ "read_only": true
785
800
  }
786
801
  };
787
802
  };
@@ -529,8 +529,8 @@ module.exports = (globalDevices, emitter) => {
529
529
  "generated": true
530
530
  },
531
531
  "options": {
532
- "0": "Enabled",
533
- "1": "Disabled"
532
+ "0": "Disabled",
533
+ "1": "Enabled"
534
534
  },
535
535
  "html_id": "enable_filtering_110"
536
536
  },
@@ -877,6 +877,7 @@ module.exports = (globalDevices, emitter) => {
877
877
  "validator": {
878
878
  "type": "uint32be"
879
879
  },
880
+ "read_only": true,
880
881
  "tags": [
881
882
  "diagnostics"
882
883
  ]
@@ -890,6 +891,7 @@ module.exports = (globalDevices, emitter) => {
890
891
  "validator": {
891
892
  "type": "uint32be"
892
893
  },
894
+ "read_only": true,
893
895
  "tags": [
894
896
  "diagnostics"
895
897
  ]