-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttn_decoder.js
35 lines (30 loc) · 951 Bytes
/
ttn_decoder.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
function decodeUplink(input) {
var buffer = new ArrayBuffer(input.bytes.length);
var dataView = new DataView(buffer);
input.bytes.forEach(function (value, index) {
dataView.setUint8(index, value);
});
var latitude = dataView.getFloat32(0, true);
var longitude = dataView.getFloat32(4, true);
var altitude = dataView.getFloat32(8, true);
var hdop = dataView.getFloat32(12, true);
var sats = dataView.getUint32(16, true);
var time = dataView.getUint32(20, true);
var date = dataView.getUint32(24, true);
var battery = dataView.getUint16(28, true);
return {
data: {
bytes: input.bytes,
latitude: latitude,
longitude: longitude,
altitude: altitude,
hdop: hdop,
sats: sats,
time: time,
date: date,
battery: battery
},
warnings: [],
errors: []
};
}