-
Notifications
You must be signed in to change notification settings - Fork 0
/
payload-decoder.js
71 lines (60 loc) · 1.73 KB
/
payload-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
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
63
64
65
66
67
68
69
70
71
function Decoder(request) {
var data = JSON.parse(request.body);
var device = data.device;
var file = data.file;
var decoded = {};
if (file === "locations.qos") {
decoded.voltage = data.body.voltage;
decoded.motion = data.body.motion;
decoded.seconds = data.body.seconds;
} else if (file === "_session.qo") {
decoded.voltage = data.voltage;
}
if (("tower_lat" in data) && ("tower_lon" in data)) {
decoded.tower_location = "(" + data.tower_lat + "," + data.tower_lon + ")";
}
if (("where_lat" in data) && ("where_lon" in data)) {
decoded.device_location = "(" + data.where_lat + "," + data.where_lon + ")";
}
decoded.rssi = data.rssi;
decoded.bars = data.bars;
decoded.temp = data.temp;
decoded.orientation = data.orientation;
return [
{
device: device,
field: "TOWER_LOCATION",
value: decoded.tower_location
},
{
device: device,
field: "DEVICE_LOCATION",
value: decoded.device_location
},
{
device: device,
field: "RSSI",
value: decoded.rssi
},
{
device: device,
field: "BARS",
value: decoded.bars
},
{
device: device,
field: "VOLTAGE",
value: decoded.voltage
},
{
device: device,
field: "CARD_TEMPERATURE",
value: decoded.temp
},
{
device: device,
field: "ORIENTATION",
value: decoded.orientation
}
];
}