-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgps.js
47 lines (36 loc) · 1.17 KB
/
gps.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
function Decoder(bytes, port) {
var params = {
"bytes": bytes
};
if (port == 136) {
if ((bytes[0] & 0x8) === 0) {
params.gnss_fix = true;
} else {
params.gnss_fix = false;
}
// Mask off enf of temp byte, RFU
temp = bytes[2] & 0x7f;
acc = bytes[10] >> 5;
acc = Math.pow(2, parseInt(acc) + 2);
// Mask off end of accuracy byte, so lon doesn't get affected
bytes[10] &= 0x1f;
if ((bytes[10] & (1 << 4)) !== 0) {
bytes[10] |= 0xe0;
}
// Mask off end of lat byte, RFU
bytes[6] &= 0x0f;
lat = ((bytes[6] << 24 | bytes[5] << 16) | bytes[4] << 8 ) | bytes[3];
lon = ((bytes[10] << 24 | bytes[9] << 16) | bytes[8] << 8 ) | bytes[7];
battery = bytes[1];
capacity = battery >> 4;
voltage = battery & 0x0f;
params.latitude = lat/1000000;
params.longitude = lon/1000000;
params.accuracy = acc;
params.temperature = temp - 32;
params.capacity = (capacity / 15) * 100;
params.voltage = (25 + voltage)/10;
params.port=port;
return params;
}
}