forked from jas-williams/CubeCell-Helium-Mapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decoder-for-datacake.js
39 lines (34 loc) · 1.02 KB
/
Decoder-for-datacake.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
function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
datacakeFields = [
{
field: "SATS",
value: bytes[9]
},
{
field: "SPEED",
value: (((bytes[8]))/1.609).toFixed(2)
},
{
field: "BATTERY",
value: (((bytes[10])*0.2)/10).toFixed(2)
},
];
var lat = ((bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3]) / 1E7;
var lon = ((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7]) / 1E7;
if ((lat < 90) && (lat > -90)) {
if ((lon < 90) && (lon > -90)) {
if ((lat !== 0) && (lon !==0)) {
datacakeFields.push({
field: "LOCATION",
value: "(" + lat + "," + lon + ")"
});
}
}
}
else {
console.log("No GPS Lock - Skipping Location")
}
return datacakeFields;
}