-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelium_decoder
38 lines (33 loc) · 1.25 KB
/
Helium_decoder
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
function Decoder(bytes, port) {
var decoded = {};
switch (port){
case 1:
decoded.latitude = ((bytes[0]<<16)>>>0) + ((bytes[1]<<8)>>>0) + bytes[2];
decoded.latitude = (decoded.latitude / 16777215.0 * 180) - 90;
decoded.longitude = ((bytes[3]<<16)>>>0) + ((bytes[4]<<8)>>>0) + bytes[5];
decoded.longitude = (decoded.longitude / 16777215.0 * 360) - 180;
var altValue = ((bytes[6]<<8)>>>0) + bytes[7];
var sign = bytes[6] & (1 << 7);
if(sign) decoded.altitude = 0xFFFF0000 | altValue;
else decoded.altitude = altValue;
decoded.hdop = bytes[8] / 10.0;
decoded.sats = bytes[9];
break;
case 2:
decoded.WiFi_Name = String.fromCharCode.apply(null, bytes)
break;
case 3:
decoded.MAC = String.fromCharCode.apply(null, bytes)
break;
case 4:
decoded.encryption = String.fromCharCode.apply(null, bytes)
break;
case 5:
decoded.Rssi = String.fromCharCode.apply(null, bytes)
break;
case 6:
decoded.channel = String.fromCharCode.apply(null, bytes)
break;
}
return decoded;
}