@ncd-io/node-red-enterprise-sensors 0.1.23 → 1.0.1

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.
package/wireless.js CHANGED
@@ -3,7 +3,8 @@ const comms = require('ncd-red-comm');
3
3
  const sp = require('serialport');
4
4
  const Queue = require("promise-queue");
5
5
  const events = require("events");
6
-
6
+ const fs = require('fs');
7
+ const home_dir = require('os').homedir
7
8
  module.exports = function(RED) {
8
9
  var gateway_pool = {};
9
10
  function NcdGatewayConfig(config){
@@ -14,6 +15,8 @@ module.exports = function(RED) {
14
15
 
15
16
  this.listeners = [];
16
17
  this.sensor_pool = [];
18
+ // TODO sensor_list is a temporary property, should be combined with sensor_pool
19
+ this.sensor_list = {};
17
20
  this._emitter = new events.EventEmitter();
18
21
  this.on = (e,c) => this._emitter.on(e, c);
19
22
 
@@ -72,6 +75,67 @@ module.exports = function(RED) {
72
75
  node.gateway.digi.serial.reconnect();
73
76
  });
74
77
  }
78
+ // Event listener to make sure this only triggers once no matter how many gateway nodes there are
79
+ node.gateway.on('sensor_mode', (d) => {
80
+ if(d.mode == "FLY"){
81
+ if(Object.hasOwn(node.sensor_list, d.mac) && Object.hasOwn(node.sensor_list[d.mac], 'update_request')){
82
+ node.request_manifest(d.mac);
83
+ };
84
+ };
85
+ });
86
+ node.gateway.on('manifest_received', (manifest_data) => {
87
+ // read manifest length is 37. Could use the same event for both
88
+ if(Object.hasOwn(node.sensor_list, manifest_data.addr) && Object.hasOwn(node.sensor_list[manifest_data.addr], 'update_request')){
89
+ // TODO check manifest data and start update process
90
+ }
91
+ manifest_data.data = node._parse_manifest_read(manifest_data.data);
92
+ node._emitter.emit('send_manifest', manifest_data);
93
+ let firmware_data = node._compare_manifest(manifest_data);
94
+ if(!firmware_data){
95
+ delete node.sensor_list[manifest_data.addr].update_request;
96
+ return;
97
+ }
98
+
99
+ // TODO Right now assume everything is good
100
+ // node.gateway.firmware_set_to_ota_mode(manifest_data.addr);
101
+
102
+ setTimeout(() => {
103
+ var tout = setTimeout(() => {
104
+ console.log('Start OTA Timed Out');
105
+ }, 10000);
106
+
107
+ var promises = {};
108
+ promises.firmware_set_to_ota_mode = node.gateway.firmware_set_to_ota_mode(manifest_data.addr);
109
+ promises.finish = new Promise((fulfill, reject) => {
110
+ node.gateway.queue.add(() => {
111
+ return new Promise((f, r) => {
112
+ clearTimeout(tout);
113
+ // node.status(modes.FLY);
114
+ fulfill();
115
+ f();
116
+ });
117
+ });
118
+ });
119
+ for(var i in promises){
120
+ (function(name){
121
+ promises[name].then((f) => {
122
+ if(name != 'finish'){
123
+ console.log(name);
124
+ }
125
+ else{
126
+ // enter ota mode
127
+ node.gateway.digi.send.at_command("ID", [0x7a, 0xaa]).then().catch().then(() => {
128
+ node.start_firmware_update(manifest_data, firmware_data);
129
+ });
130
+ }
131
+ }).catch((err) => {
132
+ console.log(err);
133
+ // msg[name] = err;
134
+ });
135
+ })(i);
136
+ }
137
+ });
138
+ });
75
139
  }));
76
140
  });
77
141
  node.gateway.digi.serial.on('closed_comms', () => {
@@ -102,6 +166,81 @@ module.exports = function(RED) {
102
166
  });
103
167
  };
104
168
 
169
+ node.start_firmware_update = function(manifest_data, firmware_data){
170
+ return new Promise((top_fulfill, top_reject) => {
171
+ var success = {};
172
+
173
+ setTimeout(() => {
174
+ let chunk_size = 128;
175
+ let image_start = firmware_data.firmware.slice(1, 5).reduce(msbLsb)+6;
176
+
177
+ var promises = {};
178
+ promises.manifest = node.gateway.firmware_send_manifest(manifest_data.addr, firmware_data.firmware.slice(5, image_start-1));
179
+ firmware_data.firmware = firmware_data.firmware.slice(image_start+4);
180
+
181
+ var index = 0;
182
+ if(Object.hasOwn(node.sensor_list[manifest_data.addr], 'last_chunk_success')){
183
+ index = node.sensor_list[manifest_data.addr].last_chunk_success;
184
+ }
185
+ var temp_count = 0;
186
+ while(index*chunk_size < firmware_data.manifest.image_size){
187
+ let offset = index*chunk_size;
188
+ // console.log(index);
189
+ // let packet = [254, 59, 0, 0, 0];
190
+ let offset_bytes = int2Bytes(offset, 4);
191
+ let firmware_chunk = firmware_data.firmware.slice(index*chunk_size, index*chunk_size+chunk_size);
192
+ temp_count += 1;
193
+ // packet = packet.concat(offset_bytes, firmware_chunk);
194
+ promises[index] = node.gateway.firmware_send_chunk(manifest_data.addr, offset_bytes, firmware_chunk);
195
+ index++;
196
+ }
197
+
198
+ promises.reboot = node.gateway.config_reboot_sensor(manifest_data.addr);
199
+
200
+ for(var i in promises){
201
+ (function(name){
202
+ promises[name].then((f) => {
203
+ if(name == 'manifest'){
204
+ // delete node.sensor_list[manifest_data.addr].promises[name];
205
+ node.sensor_list[manifest_data.addr].test_check = {name: true};
206
+ node.sensor_list[manifest_data.addr].update_in_progress = true;
207
+ }else {
208
+ success[name] = true;
209
+ node.sensor_list[manifest_data.addr].test_check[name] = true;
210
+ node.sensor_list[manifest_data.addr].last_chunk_success = name;
211
+ // delete node.sensor_list[manifest_data.addr].promises[name];
212
+ }
213
+ }).catch((err) => {
214
+ if(name != 'reboot'){
215
+ node.gateway.clear_queue();
216
+ success[name] = err;
217
+ }else{
218
+ delete node.sensor_list[manifest_data.addr].last_chunk_success;
219
+ delete node.sensor_list[manifest_data.addr].update_request;
220
+ node._emitter.emit('send_firmware_stats', {state: success, addr: manifest_data.addr});
221
+ // #OTF
222
+ // node.send({topic: 'Config Results', payload: success, time: Date.now(), addr: manifest_data.addr});
223
+ top_fulfill(success);
224
+ }
225
+ node._emitter.emit('send_firmware_stats', {state: success, addr: manifest_data.addr});
226
+ node.resume_normal_operation();
227
+ });
228
+ })(i);
229
+ }
230
+ }, 1000);
231
+ });
232
+ }
233
+ node.resume_normal_operation = function(){
234
+ let pan_id = parseInt(config.pan_id, 16);
235
+ node.gateway.digi.send.at_command("ID", [pan_id >> 8, pan_id & 255]).then().catch().then(() => {
236
+ console.log('Set Pan ID to: '+pan_id);
237
+ });
238
+ }
239
+
240
+ node.request_manifest = function(sensor_addr){
241
+ // Request Manifest
242
+ node.gateway.firmware_request_manifest(sensor_addr);
243
+ };
105
244
 
106
245
  node.close_comms = function(){
107
246
  // node.gateway._emitter.removeAllListeners('sensor_data');
@@ -118,7 +257,55 @@ module.exports = function(RED) {
118
257
  // });
119
258
  }
120
259
  }
260
+ }
261
+ node._compare_manifest = function(sensor_manifest){
262
+ let firmware_dir = home_dir()+'/.node-red/node_modules/@ncd-io/node-red-enterprise-sensors/firmware_files';
263
+ let filename = '/' + sensor_manifest.data.device_type + '-' + sensor_manifest.data.hardware_id[0] + '_' + sensor_manifest.data.hardware_id[1] + '_' + sensor_manifest.data.hardware_id[2] + '.ncd';
264
+
265
+ try {
266
+ let firmware_file = fs.readFileSync(firmware_dir+filename,)
267
+ let stored_manifest = node._parse_manifest(firmware_file);
268
+ if(stored_manifest.firmware_version === sensor_manifest.data.firmware_version){
269
+ console.log('firmware versions SAME');
270
+ return false;
271
+ }
121
272
 
273
+ if(stored_manifest.max_image_size < sensor_manifest.data.image_size){
274
+ console.log('firmware image too large');
275
+ return false;
276
+ }
277
+ return {manifest: stored_manifest, firmware: firmware_file};
278
+ } catch(err){
279
+ console.log(err);
280
+ return err;
281
+ }
282
+ }
283
+ node._parse_manifest = function(bin_data){
284
+ return {
285
+ manifest_check: bin_data[0] == 0x01,
286
+ manifest_size: bin_data.slice(1, 5).reduce(msbLsb),
287
+ firmware_version: bin_data[5],
288
+ image_start_address: bin_data.slice(6, 10).reduce(msbLsb),
289
+ image_size: bin_data.slice(10, 14).reduce(msbLsb),
290
+ max_image_size: bin_data.slice(14, 18).reduce(msbLsb),
291
+ image_digest: bin_data.slice(18, 34),
292
+ device_type: bin_data.slice(34, 36).reduce(msbLsb),
293
+ hardware_id: bin_data.slice(36, 39),
294
+ reserve_bytes: bin_data.slice(39, 42)
295
+ }
296
+ };
297
+ node._parse_manifest_read = function(bin_data){
298
+ return {
299
+ // manifest_size: bin_data.slice(0,4).reduce(msbLsb),
300
+ firmware_version: bin_data[0],
301
+ image_start_address: bin_data.slice(1, 5).reduce(msbLsb),
302
+ image_size: bin_data.slice(5, 9).reduce(msbLsb),
303
+ max_image_size: bin_data.slice(9, 13).reduce(msbLsb),
304
+ image_digest: bin_data.slice(13, 29),
305
+ device_type: bin_data.slice(29, 31).reduce(msbLsb),
306
+ hardware_id: bin_data.slice(31, 34),
307
+ reserve_bytes: bin_data.slice(34, 37)
308
+ }
122
309
  }
123
310
  }
124
311
 
@@ -149,7 +336,17 @@ module.exports = function(RED) {
149
336
  node.set_status = function(){
150
337
  node.status(statuses[node._gateway_node.is_config]);
151
338
  };
152
-
339
+ node._gateway_node.on('send_manifest', (manifest_data) => {
340
+ node.send({
341
+ topic: 'sensor_manifest',
342
+ payload: {
343
+ addr: manifest_data.addr,
344
+ sensor_type: manifest_data.sensor_type,
345
+ manifest: manifest_data.data
346
+ },
347
+ time: Date.now()
348
+ });
349
+ });
153
350
  node.on('input', function(msg){
154
351
  switch(msg.topic){
155
352
  case "route_trace":
@@ -187,7 +384,133 @@ module.exports = function(RED) {
187
384
  // if(msg.topic == "fidelity_test"){
188
385
  // }
189
386
  });
387
+ node._gateway_node.on('send_firmware_stats', (data) => {
388
+ node.send({
389
+ topic: 'update_stats',
390
+ payload: data.state,
391
+ addr: data.addr,
392
+ time: Date.now()
393
+ });
394
+ });
395
+ node.on('input', function(msg){
396
+ switch(msg.topic){
397
+ case "route_trace":
398
+ var opts = {trace:1};
399
+ node.gateway.route_discover(msg.payload.address,opts).then().catch(console.log);
400
+ break;
401
+ case "link_test":
402
+ node.gateway.link_test(msg.payload.source_address,msg.payload.destination_address,msg.payload.options);
403
+ break;
404
+ case "fidelity_test":
405
+ break;
406
+ case "add_firmware_file":
407
+ // Parse Manifest to grab information and store it for later use
408
+ // msg.payload = [0x01, 0x00, ...]
409
+ let new_msg = {
410
+ topic: 'add_firmware_file_response',
411
+ payload: node._gateway_node._parse_manifest(msg.payload)
412
+ }
413
+ let firmware_dir = home_dir()+'/.node-red/node_modules/@ncd-io/node-red-enterprise-sensors/firmware_files';
414
+ if (!fs.existsSync(firmware_dir)) {
415
+ fs.mkdirSync(firmware_dir);
416
+ };
417
+ let filename = '/' + new_msg.payload.device_type + '-' + new_msg.payload.hardware_id[0] + '_' + new_msg.payload.hardware_id[1] + '_' + new_msg.payload.hardware_id[2] + '.ncd';
418
+ fs.writeFile(firmware_dir+filename, msg.payload, function(err){
419
+ if(err){
420
+ console.log(err);
421
+ };
422
+ console.log('Success');
423
+ });
424
+ node.send(new_msg);
425
+ break;
426
+ // case "get_firmware_file":
427
+ // Commented out as I'd rather use a flow to request the file. More robust. Maybe more complicated, wait for feedback.
428
+ // // This input makes a request to the specified url and downloads a firmware file at that location
429
+ // // msg.payload = "https://github.com/ncd-io/WiFi_MQTT_Temperature_Firmware/raw/main/v1.0.3/firmware.bin"
190
430
 
431
+ case "check_firmware_file":
432
+ // Read file that should be at location and spit out the binary
433
+ // Example msg.payload
434
+ // msg.payload = {
435
+ // device_type: 80,
436
+ // hardware_id: [88, 88, 88]
437
+ // }
438
+ break;
439
+ case "ota_firmware_update_single":
440
+ // msg.payload = {
441
+ // 'address': "00:13:a2:00:42:2c:d2:aa"
442
+ // }
443
+ if(!Object.hasOwn(node._gateway_node.sensor_list, msg.payload)){
444
+ node._gateway_node.sensor_list[msg.payload] = {};
445
+ };
446
+ if(!Object.hasOwn(node._gateway_node.sensor_list[msg.payload], 'update_request')){
447
+ node._gateway_node.sensor_list[msg.payload].update_request = true;
448
+ };
449
+ break;
450
+ case "ota_firmware_update_multiple":
451
+ // set the devices user wants to upload new firmware to
452
+ // msg.payload = {
453
+ // 'addresses': [
454
+ // "00:13:a2:00:42:2c:d2:aa",
455
+ // "00:13:a2:00:42:2c:d2:ab"
456
+ // ];
457
+ // }
458
+ // TODO unfinished
459
+ msg.payload.addresses.forEach((address) => {
460
+ if(!Object.hasOwn(node._gateway_node.sensor_list, msg.payload.address)){
461
+ node._gateway_node.sensor_list[address] = {};
462
+ };
463
+ if(!Object.hasOwn(node._gateway_node.sensor_list[msg.payload.address], 'update_request')){
464
+ node._gateway_node.sensor_list[address].update_request = true;
465
+ };
466
+ });
467
+ break;
468
+ case "get_manifest":
469
+ // Allows user to request manifest from one or more devices
470
+ // Primarily envisioned used for troubleshooting or engineer determination
471
+ // msg.payload = {
472
+ // 'addresses': [
473
+ // "00:13:a2:00:42:2c:d2:aa",
474
+ // "00:13:a2:00:42:2c:d2:ab"
475
+ // ];
476
+ // }
477
+ // OR
478
+ // msg.payload = {
479
+ // 'address': "00:13:a2:00:42:2c:d2:aa"
480
+ // }
481
+ break;
482
+ default:
483
+ const byteArrayToHexString = byteArray => Array.from(msg.payload.address, byte => ('0' + (byte & 0xFF).toString(16)).slice(-2)).join('');
484
+ node.gateway.control_send(msg.payload.address, msg.payload.data, msg.payload.options).then().catch(console.log);
485
+ }
486
+
487
+
488
+ // console.log("input triggered, topic:"+msg.topic);
489
+ // if(msg.topic == "transmit"){
490
+ // const byteArrayToHexString = byteArray => Array.from(msg.payload.address, byte => ('0' + (byte & 0xFF).toString(16)).slice(-2)).join('');
491
+ // node.gateway.control_send(msg.payload.address, msg.payload.data, msg.payload.options).then().catch(console.log);
492
+ // }
493
+ // if(msg.topic == "route_trace"){
494
+ // var opts = {trace:1};
495
+ // node.gateway.route_discover(msg.payload.address,opts).then().catch(console.log);
496
+ // }
497
+ // if(msg.topic == "link_test"){
498
+ // node.gateway.link_test(msg.payload.source_address,msg.payload.destination_address,msg.payload.options);
499
+ // }
500
+ // if(msg.topic == "fft_request"){
501
+
502
+ // }
503
+ // if(msg.topic == "fidelity_test"){
504
+ // }
505
+ });
506
+ node.gateway.on('ncd_error', (data) => {
507
+ node.send({
508
+ topic: 'ncd_error',
509
+ data: data,
510
+ payload: data.error,
511
+ time: Date.now()
512
+ });
513
+ });
191
514
  node.gateway.on('sensor_data', (d) => {
192
515
  node.set_status();
193
516
  node.send({topic: 'sensor_data', payload: d, time: Date.now()});
@@ -237,7 +560,7 @@ module.exports = function(RED) {
237
560
  this.config_gateway = this.config_gateway_node.gateway;
238
561
  dedicated_config = true;
239
562
  }
240
- this.queue = new Queue(1);
563
+ // this.queue = new Queue(1);
241
564
  var node = this;
242
565
  var modes = {
243
566
  PGM: {fill:"red",shape:"dot",text:"Config Mode"},
@@ -247,6 +570,7 @@ module.exports = function(RED) {
247
570
  RUN: {fill:"green",shape:"dot",text:"Running"},
248
571
  PUM: {fill:"yellow",shape:"ring",text:"Module was factory reset"},
249
572
  ACK: {fill:"green",shape:"ring",text:"Configuration Acknowledged"},
573
+ STREAM_ERR: {fill:"red",shape:"ring",text:"Multi-Packet Stream Error"},
250
574
  // FLY: {fill:"yellow",shape:"ring",text:"FLY notification received"},
251
575
  // OTN: {fill:"yellow",shape:"ring",text:"OTN Received, OTF Configuration Initiated"},
252
576
  // OFF: {fill:"green",shape:"dot",text:"OFF Recieved, OTF Configuration Completed"}
@@ -274,13 +598,13 @@ module.exports = function(RED) {
274
598
  }, 10000);
275
599
 
276
600
  var promises = {};
277
- // This command is used for OTF on types 53, 80,81,82,83,84, 101, 102 , 518,519
601
+ // This command is used for OTF on types 53, 80,81,82,83,84, 101, 102, 110, 111, 518, 519
278
602
  let original_otf_devices = [53, 80, 81, 82, 83, 84, 101, 102, 180, 181, 518, 519, 520];
279
603
  if(original_otf_devices.includes(sensor.type)){
280
- // This command is used for OTF on types 53, 80,81,82,83,84, 101, 102 , 518,519
604
+ // This command is used for OTF on types 53, 80, 81, 82, 83, 84, 101, 102, 110, 111, 518, 519
281
605
  promises.config_enter_otn_mode = node.config_gateway.config_enter_otn_mode(sensor.mac);
282
606
  }else{
283
- // This command is used for OTF on types not 53, 80,81,82,83,84, 101, 102 , 518,519
607
+ // This command is used for OTF on types not 53, 80, 81, 82, 83, 84, 101, 102, 110, 111, 518, 519
284
608
  promises.config_enter_otn_mode = node.config_gateway.config_enter_otn_mode_common(sensor.mac);
285
609
  }
286
610
  promises.finish = new Promise((fulfill, reject) => {
@@ -498,6 +822,21 @@ module.exports = function(RED) {
498
822
  }
499
823
  var interr = parseInt(config.activ_interr_x) | parseInt(config.activ_interr_y) | parseInt(config.activ_interr_z) | parseInt(config.activ_interr_op);
500
824
  promises.activity_interrupt = node.config_gateway.config_set_interrupt_24(mac, interr);
825
+ case 25:
826
+ if(config.impact_accel_active){
827
+ promises.impact_accel = node.config_gateway.config_set_acceleration_range_24(mac, parseInt(config.impact_accel));
828
+ }
829
+ if(config.impact_data_rate_active){
830
+ promises.impact_data_rate = node.config_gateway.config_set_data_rate_24(mac, parseInt(config.impact_data_rate));
831
+ }
832
+ if(config.impact_threshold_active){
833
+ promises.impact_threshold = node.config_gateway.config_set_threshold_24(mac, parseInt(config.impact_threshold));
834
+ }
835
+ if(config.impact_duration_active){
836
+ promises.impact_duration = node.config_gateway.config_set_duration_24(mac, parseInt(config.impact_duration));
837
+ }
838
+ var interr = parseInt(config.activ_interr_x) | parseInt(config.activ_interr_y) | parseInt(config.activ_interr_z) | parseInt(config.activ_interr_op);
839
+ promises.activity_interrupt = node.config_gateway.config_set_interrupt_24(mac, interr);
501
840
  case 35:
502
841
  if(config.counter_threshold_35_active){
503
842
  promises.config_set_counter_threshold_35 = node.config_gateway.config_set_counter_threshold_35(mac, parseInt(config.counter_threshold_35));
@@ -878,6 +1217,20 @@ module.exports = function(RED) {
878
1217
  // }
879
1218
  // promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
880
1219
  break;
1220
+ case 105:
1221
+ if(config.sensor_boot_time_420ma_active){
1222
+ promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
1223
+ }
1224
+ if(config.low_calibration_420ma_active){
1225
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
1226
+ }
1227
+ if(config.mid_calibration_420ma_active){
1228
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
1229
+ }
1230
+ if(config.high_calibration_420ma_active){
1231
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
1232
+ }
1233
+ break;
881
1234
  case 107:
882
1235
  if(config.sensor_boot_time_420ma_active){
883
1236
  promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
@@ -906,6 +1259,278 @@ module.exports = function(RED) {
906
1259
  promises.debounce_time_108 = node.config_gateway.config_set_debounce_time_108(mac, parseInt(config.debounce_time_108));
907
1260
  }
908
1261
  break;
1262
+ case 110:
1263
+ if(config.current_calibration_c1_80_active){
1264
+ promises.current_calibration_c1_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
1265
+ }
1266
+ if(config.output_data_rate_101_active){
1267
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
1268
+ }
1269
+ if(config.sampling_duration_101_active){
1270
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
1271
+ }
1272
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
1273
+ promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
1274
+ }
1275
+ if(config.sampling_interval_101_active){
1276
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
1277
+ }
1278
+ if(config.full_scale_range_101_active){
1279
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
1280
+ }
1281
+ if(config.mode_110_active){
1282
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_110));
1283
+ }
1284
+ if(config.filter_80_active){
1285
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
1286
+ }
1287
+ if(config.low_pass_filter_80_active){
1288
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
1289
+ }
1290
+ if(config.high_pass_filter_80_active){
1291
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
1292
+ }
1293
+ if(config.measurement_mode_80_active){
1294
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
1295
+ }
1296
+ if(config.on_request_timeout_80_active){
1297
+ promises.on_request_timeout = node.config_gateway.config_set_on_request_timeout_80(mac, parseInt(config.on_request_timeout_80));
1298
+ }
1299
+ if(config.deadband_80_active){
1300
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
1301
+ }
1302
+ if(config.payload_length_80_active){
1303
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
1304
+ }
1305
+ if(config.set_rtc_101){
1306
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
1307
+ }
1308
+ if(config.auto_raw_interval_110_active){
1309
+ promises.auto_raw_interval_110 = node.config_gateway.config_set_auto_raw_interval_110(mac, parseInt(config.auto_raw_interval_110));
1310
+ }
1311
+ if(config.auto_raw_destination_110_active){
1312
+ promises.auto_raw_destination_110 = node.config_gateway.config_set_auto_raw_destination_110(mac, parseInt(config.auto_raw_destination_110));
1313
+ }
1314
+ if(config.clear_probe_uptimers_110_active){
1315
+ promises.clear_probe_uptimers_110 = node.config_gateway.config_set_clear_probe_uptimers_110(mac, parseInt(config.clear_probe_uptimers_110));
1316
+ }
1317
+ if(config.smart_interval_110_active){
1318
+ promises.smart_interval_110 = node.config_gateway.config_set_smart_interval_110(mac, parseInt(config.smart_interval_110));
1319
+ }
1320
+ if(config.smart_threshold_110_active){
1321
+ promises.smart_threshold_110 = nocd.config_gateway.config_set_smart_threshold_110(mac, parseInt(config.smart_threshold_110));
1322
+ }
1323
+ break;
1324
+ case 111:
1325
+ if(config.current_calibration_c1_80_active){
1326
+ promises.current_calibration_c1_80_active = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
1327
+ }
1328
+ if(config.current_calibration_c2_80_active){
1329
+ promises.current_calibration_c2_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c2_80), 3);
1330
+ }
1331
+ if(config.output_data_rate_p1_81_active){
1332
+ promises.output_data_rate_p1_81 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_p1_81));
1333
+ }
1334
+ if(config.output_data_rate_p2_81_active){
1335
+ promises.output_data_rate_p2_81 = node.config_gateway.config_set_output_data_rate_p2_81(mac, parseInt(config.output_data_rate_p2_81));
1336
+ }
1337
+ if(config.sampling_duration_p1_81_active){
1338
+ promises.sampling_duration_p1_81 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_p1_81));
1339
+ }
1340
+ if(config.sampling_duration_p2_81_active){
1341
+ promises.sampling_duration_p2_81 = node.config_gateway.config_set_sampling_duration_p2_81(mac, parseInt(config.sampling_duration_p2_81));
1342
+ }
1343
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
1344
+ promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
1345
+ }
1346
+ if(config.sampling_interval_101_active){
1347
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
1348
+ }
1349
+ if(config.full_scale_range_101_active){
1350
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
1351
+ }
1352
+ if(config.mode_110_active){
1353
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_110));
1354
+ }
1355
+ if(config.filter_80_active){
1356
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
1357
+ }
1358
+ if(config.low_pass_filter_80_active){
1359
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
1360
+ }
1361
+ if(config.high_pass_filter_80_active){
1362
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
1363
+ }
1364
+ if(config.low_pass_filter_81_p2_active){
1365
+ promises.low_pass_filter_p2 = node.config_gateway.config_set_low_pass_filter_81_p2(mac, parseInt(config.low_pass_filter_81_p2));
1366
+ }
1367
+ if(config.high_pass_filter_81_p2_active){
1368
+ promises.high_pass_filter_p2 = node.config_gateway.config_set_high_pass_filter_81_p2(mac, parseInt(config.high_pass_filter_81_p2));
1369
+ }
1370
+ if(config.measurement_mode_80_active){
1371
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
1372
+ }
1373
+ if(config.on_request_timeout_80_active){
1374
+ promises.on_request_timeout = node.config_gateway.config_set_on_request_timeout_80(mac, parseInt(config.on_request_timeout_80));
1375
+ }
1376
+ if(config.deadband_80_active){
1377
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
1378
+ }
1379
+ if(config.payload_length_80_active){
1380
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
1381
+ }
1382
+ if(config.set_rtc_101){
1383
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
1384
+ }
1385
+ if(config.auto_raw_interval_110_active){
1386
+ promises.auto_raw_interval_110 = node.config_gateway.config_set_auto_raw_interval_110(mac, parseInt(config.auto_raw_interval_110));
1387
+ }
1388
+ if(config.auto_raw_destination_110_active){
1389
+ promises.auto_raw_destination_110 = node.config_gateway.config_set_auto_raw_destination_110(mac, parseInt(config.auto_raw_destination_110));
1390
+ }
1391
+ if(config.clear_probe_uptimers_110_active){
1392
+ promises.clear_probe_uptimers_110 = node.config_gateway.config_set_clear_probe_uptimers_110(mac, parseInt(config.clear_probe_uptimers_110));
1393
+ }
1394
+ if(config.smart_interval_110_active){
1395
+ promises.smart_interval_110 = node.config_gateway.config_set_smart_interval_110(mac, parseInt(config.smart_interval_110));
1396
+ }
1397
+ if(config.smart_threshold_110_active){
1398
+ promises.smart_threshold_110 = nocd.config_gateway.config_set_smart_threshold_110(mac, parseInt(config.smart_threshold_110));
1399
+ }
1400
+ break;
1401
+ case 112:
1402
+ if(config.current_calibration_82_active){
1403
+ promises.current_calibration_82 = node.config_gateway.config_set_current_calibration_82(mac, parseInt(config.current_calibration_82));
1404
+ }
1405
+ if(config.output_data_rate_101_active){
1406
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
1407
+ }
1408
+ if(config.sampling_duration_101_active){
1409
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
1410
+ }
1411
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
1412
+ promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
1413
+ }
1414
+ if(config.sampling_interval_101_active){
1415
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
1416
+ }
1417
+ if(config.full_scale_range_101_active){
1418
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
1419
+ }
1420
+ if(config.mode_110_active){
1421
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_110));
1422
+ }
1423
+ if(config.filter_80_active){
1424
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
1425
+ }
1426
+ if(config.low_pass_filter_80_active){
1427
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
1428
+ }
1429
+ if(config.high_pass_filter_80_active){
1430
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
1431
+ }
1432
+ if(config.measurement_mode_80_active){
1433
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
1434
+ }
1435
+ if(config.on_request_timeout_80_active){
1436
+ promises.on_request_timeout = node.config_gateway.config_set_on_request_timeout_80(mac, parseInt(config.on_request_timeout_80));
1437
+ }
1438
+ if(config.deadband_80_active){
1439
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
1440
+ }
1441
+ if(config.payload_length_80_active){
1442
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
1443
+ }
1444
+ if(config.set_rtc_101){
1445
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
1446
+ }
1447
+ if(config.auto_raw_interval_110_active){
1448
+ promises.auto_raw_interval_110 = node.config_gateway.config_set_auto_raw_interval_110(mac, parseInt(config.auto_raw_interval_110));
1449
+ }
1450
+ if(config.auto_raw_destination_110_active){
1451
+ promises.auto_raw_destination_110 = node.config_gateway.config_set_auto_raw_destination_110(mac, parseInt(config.auto_raw_destination_110));
1452
+ }
1453
+ if(config.clear_probe_uptimers_110_active){
1454
+ promises.clear_probe_uptimers_110 = node.config_gateway.config_set_clear_probe_uptimers_110(mac, parseInt(config.clear_probe_uptimers_110));
1455
+ }
1456
+ if(config.smart_interval_110_active){
1457
+ promises.smart_interval_110 = node.config_gateway.config_set_smart_interval_110(mac, parseInt(config.smart_interval_110));
1458
+ }
1459
+ if(config.smart_threshold_110_active){
1460
+ promises.smart_threshold_110 = nocd.config_gateway.config_set_smart_threshold_110(mac, parseInt(config.smart_threshold_110));
1461
+ }
1462
+ break;
1463
+ case 114:
1464
+ if(config.output_data_rate_101_active){
1465
+ promises.output_data_rate_101 = node.config_gateway.config_set_output_data_rate_101(mac, parseInt(config.output_data_rate_101));
1466
+ }
1467
+ if(config.sampling_duration_101_active){
1468
+ promises.sampling_duration_101 = node.config_gateway.config_set_sampling_duration_101(mac, parseInt(config.sampling_duration_101));
1469
+ }
1470
+ if(config.x_axis_101 || config.y_axis_101 || config.z_axis_101){
1471
+ promises.axis_enabled_101 = node.config_gateway.config_set_axis_enabled_101(mac, config.x_axis_101, config.y_axis_101, config.z_axis_101);
1472
+ }
1473
+ if(config.sampling_interval_101_active){
1474
+ promises.sampling_interval_101 = node.config_gateway.config_set_sampling_interval_101(mac, parseInt(config.sampling_interval_101));
1475
+ }
1476
+ if(config.full_scale_range_101_active){
1477
+ promises.full_scale_range_101 = node.config_gateway.config_set_full_scale_range_101(mac, parseInt(config.full_scale_range_101));
1478
+ }
1479
+ if(config.mode_110_active){
1480
+ promises.mode = node.config_gateway.config_set_operation_mode_80(mac, parseInt(config.mode_110));
1481
+ }
1482
+ if(config.filter_80_active){
1483
+ promises.filter = node.config_gateway.config_set_filters_80(mac, parseInt(config.filter_80));
1484
+ }
1485
+ if(config.low_pass_filter_80_active){
1486
+ promises.low_pass_filter = node.config_gateway.config_set_low_pass_filter_80(mac, parseInt(config.low_pass_filter_80));
1487
+ }
1488
+ if(config.high_pass_filter_80_active){
1489
+ promises.high_pass_filter = node.config_gateway.config_set_high_pass_filter_80(mac, parseInt(config.high_pass_filter_80));
1490
+ }
1491
+ if(config.measurement_mode_80_active){
1492
+ promises.measurement_mode = node.config_gateway.config_set_measurement_mode_80(mac, parseInt(config.measurement_mode_80));
1493
+ }
1494
+ if(config.on_request_timeout_80_active){
1495
+ promises.on_request_timeout = node.config_gateway.config_set_on_request_timeout_80(mac, parseInt(config.on_request_timeout_80));
1496
+ }
1497
+ if(config.deadband_80_active){
1498
+ promises.deadband = node.config_gateway.config_set_deadband_80(mac, parseInt(config.deadband_80));
1499
+ }
1500
+ if(config.led_alert_mode_84_active){
1501
+ promises.led_alert_mode_84 = node.config_gateway.config_set_led_alert_mode_84(mac, parseInt(config.led_alert_mode_84));
1502
+ }
1503
+ if(config.led_accelerometer_threshold_84_active){
1504
+ promises.led_accelerometer_threshold_84 = node.config_gateway.config_set_led_accelerometer_threshold_84(mac, parseInt(config.led_accelerometer_threshold_84));
1505
+ }
1506
+ if(config.led_velocity_threshold_84_active){
1507
+ promises.led_velocity_threshold_84 = node.config_gateway.config_set_led_velocity_threshold_84(mac, parseInt(config.led_velocity_threshold_84));
1508
+ }
1509
+ if(config.acceleration_interrupt_threshold_84_active){
1510
+ promises.acceleration_interrupt_threshold_84 = node.config_gateway.config_set_acceleration_interrupt_threshold_84(mac, parseInt(config.acceleration_interrupt_threshold_84));
1511
+ }
1512
+ if(config.payload_length_80_active){
1513
+ promises.payload_length_80 = node.config_gateway.config_set_payload_length_80(mac, parseInt(config.payload_length_80));
1514
+ }
1515
+ if(config.set_rtc_101){
1516
+ promises.set_rtc_101 = node.config_gateway.config_set_rtc_101(mac);
1517
+ }
1518
+ if(config.auto_raw_interval_110_active){
1519
+ promises.auto_raw_interval_110 = node.config_gateway.config_set_auto_raw_interval_110(mac, parseInt(config.auto_raw_interval_110));
1520
+ }
1521
+ if(config.auto_raw_destination_110_active){
1522
+ promises.auto_raw_destination_110 = node.config_gateway.config_set_auto_raw_destination_110(mac, parseInt(config.auto_raw_destination_110));
1523
+ }
1524
+ if(config.clear_probe_uptimers_110_active){
1525
+ promises.clear_probe_uptimers_110 = node.config_gateway.config_set_clear_probe_uptimers_110(mac, parseInt(config.clear_probe_uptimers_110));
1526
+ }
1527
+ if(config.smart_interval_110_active){
1528
+ promises.smart_interval_110 = node.config_gateway.config_set_smart_interval_110(mac, parseInt(config.smart_interval_110));
1529
+ }
1530
+ if(config.smart_threshold_110_active){
1531
+ promises.smart_threshold_110 = nocd.config_gateway.config_set_smart_threshold_110(mac, parseInt(config.smart_threshold_110));
1532
+ }
1533
+ break;
909
1534
  case 180:
910
1535
  if(config.current_calibration_c1_80_active){
911
1536
  promises.current_calibration_c1_80 = node.config_gateway.config_set_current_calibration_individual_80(mac, parseInt(config.current_calibration_c1_80), 1);
@@ -1185,6 +1810,20 @@ module.exports = function(RED) {
1185
1810
  promises.number_of_regs_to_rd_539 = node.config_gateway.config_set_number_of_regs_to_rd_539(mac, parseInt(config.number_of_regs_to_rd_539));
1186
1811
  }
1187
1812
  break;
1813
+ case 540:
1814
+ if(config.sensor_boot_time_420ma_active){
1815
+ promises.sensor_boot_time_420ma = node.config_gateway.config_set_sensor_boot_time_420ma(mac, parseInt(config.sensor_boot_time_420ma));
1816
+ }
1817
+ if(config.low_calibration_420ma_active){
1818
+ promises.low_calibration_420ma = node.config_gateway.config_set_low_calibration_420ma(mac, parseInt(config.low_calibration_420ma));
1819
+ }
1820
+ if(config.mid_calibration_420ma_active){
1821
+ promises.mid_calibration_420ma = node.config_gateway.config_set_mid_calibration_420ma(mac, parseInt(config.mid_calibration_420ma));
1822
+ }
1823
+ if(config.high_calibration_420ma_active){
1824
+ promises.high_calibration_420ma = node.config_gateway.config_set_high_calibration_420ma(mac, parseInt(config.high_calibration_420ma));
1825
+ }
1826
+ break;
1188
1827
  }
1189
1828
  }
1190
1829
  // These sensors listed in original_otf_devices use a different OTF code.
@@ -1600,3 +2239,4 @@ function toHex(n){return ('00' + n.toString(16)).substr(-2);}
1600
2239
  function toMac(arr){
1601
2240
  return arr.reduce((h,c,i) => {return ((i==1?toHex(h):h)+':'+toHex(c)).toUpperCase();});
1602
2241
  }
2242
+ function msbLsb(m,l){return (m<<8)+l;};