-
Notifications
You must be signed in to change notification settings - Fork 0
/
adeunis-rf.js
62 lines (49 loc) · 2.15 KB
/
adeunis-rf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module.exports = function (RED) {
function AdeunisRF(config) {
RED.nodes.createNode(this, config);
var node = this;
this.on('input', function(msg) {
var ret = {};
status = msg.payload[0];
temp_is_present = status & 0x80;
acc_is_present = status & 0x40;
btn1_is_present = status & 0x20;
gps_is_present = status & 0x10;
up_is_present = status & 0x08;
down_is_present = status & 0x04;
batt_is_present = status & 0x02;
rssi_is_present = status & 0x01;
ret.temp = msg.payload[1]
ret.btn1 = btn1_is_present
// work on gps data
if (gps_is_present) {
shift = 8
ret.gps=true
ret.lat = ((msg.payload[2] & 0xF0 ) >> 4)*10 + (msg.payload[2] & 0x0F)
ret.lat += ((((msg.payload[3] & 0xF0 ) >> 4)*10 + (msg.payload[3] & 0x0F) +
(((msg.payload[4] & 0xF0) >> 4) / 10) +
((msg.payload[4] & 0x0F) / 100 ) +
((msg.payload[5] & 0xF0) >> 4) /1000)) /60
ret.lon = ((msg.payload[6] & 0xF0 ) >> 4)*100 + (msg.payload[6] & 0x0F )*10 + ((msg.payload[7] & 0xF0) >> 4) // degree
ret.lon += (((msg.payload[7] & 0x0F )* 10 + ((msg.payload[8] & 0xF0) >> 4) +
((msg.payload[8] & 0x0F) / 10) + ((msg.payload[9] & 0xF0) >> 4) / 100)) /60
ret.lat = ret.lat.toFixed(6)
ret.lon = ret.lon.toFixed(6)
} else {
shift = 0
ret.gps=false
}
ret.uplink = msg.payload[2+shift];
ret.down = msg.payload[3+shift];
ret.vbat = ((msg.payload[4+shift] << 8) + msg.payload[5+shift]) / 1000;
if (rssi_is_present) {
ret.rssi = msg.payload[6+shift] * -1
ret.snr = msg.payload[7+shift]
}
msg.raw = msg.payload;
msg.payload = ret;
node.send(msg);
});
}
RED.nodes.registerType("adeunis-rf", AdeunisRF);
}