-
Notifications
You must be signed in to change notification settings - Fork 5
/
peripherals.html
114 lines (114 loc) · 5.87 KB
/
peripherals.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<html>
<head>
<title>BLE Device Log</title>
<meta charset="UTF-8">
<script src="http://gatd.eecs.umich.edu/bower_components/socket.io-client/dist/socket.io.min.js"></script>
<script src="http://gatd.eecs.umich.edu/bower_components/jquery/dist/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.4.0/bootstrap-table.min.js"></script>
<script src="json/gatt.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.4.0/bootstrap-table.min.css" rel="stylesheet" type="text/css">
<style>
html { height:100%; margin:0;}
body { font-family:'Helvetica Neue'; font-weight:200; font-size:small; height:100%; overflow:hidden;}
table { font-family:'Helvetica Neue'; font-weight:200; font-size:small; cursor:pointer; }
ul {padding-left:15px; margin-bottom:0;}
b {font-weight: 500;}
</style>
</head>
<body>
<div style="height:90%; padding:1%;">
<div id="toolbar" class="btn-group"><button type="button" class="btn btn-default disabled" id="count"># Peripherals</button></div>
<table id="table" data-sort-name="TIME" data-sort-order="desc" data-search="true" data-toolbar="#toolbar">
<thead>
<tr>
<th data-field="uuid" data-sortable="true">ADDRESS</th>
<th data-field="NAME" data-sortable="true">DEVICE</th>
<th data-field="TIME" data-sortable="true">TIME</th>
<th data-field="LOC" data-sortable="true">LOCATION</th>
<th data-field="ADV" data-sortable="true">ADVERTISEMENT</th>
<th data-field="SERV" data-sortable="true">SERVICES</th>
</tr>
</thead>
</table>
</div>
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header" style="font-weight:bold;"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button><br /></div>
<div class="modal-body"></div>
<div class="modal-footer"><button type="button" class="btn btn-primary" data-dismiss="modal">Close</button></div>
</div>
</div>
</div>
<script>
data = []; t_end = 0; loc = {"281473061251561":"BBB Atrium","281473061252076":"BBB 2nd Floor"};
$(function () { $('#table').bootstrapTable({ data: data }); });
stringify = function (arr) {
str = '';
for (i = 0; i < arr.length; i++) str+=String.fromCharCode(arr[i]);
return str;
}
onload = function() {
socket = io.connect('gatd.eecs.umich.edu:8084/stream');
socket.on('connect', function (dat) {
socket.emit('query', {'profile_id':'SgYPCHTR5a','time': {'$gt': 1423958400},'_speedup': 100000000.0,'TYPE':'ble-device'});
});
socket.on('data', function (dat) {
// if (typeof dat["services"] != 'undefined') {
if (dat.time > t_end) {
// console.log(dat);
t_end = dat.time;
dat.TIME = new Date(parseInt(dat["time"])).toLocaleString('en-US', { hour12: false });
dat.NAME = dat.advertisement.localName;
dat.ADV = "<ul>";
for (n in dat.advertisement) {
if (n=="manufacturerData" && dat.advertisement[n].type=="Buffer") {
hex = (dat.advertisement[n].data.map(function (x) {return x.toString(16);})).join("");
str = stringify(dat.advertisement[n].data);
dat.ADV += "<li><b>" + n + "</b> : \"" + hex + "\"</li>";
}
else dat.ADV += "<li><b>" + n + "</b> : " + JSON.stringify(dat.advertisement[n],null,4) + "</li>";
}
dat.ADV += "</ul>"
// JSON.stringify(dat.advertisement,null,2);
serv = "<ul>";
for (n in dat.services) {
service = dat.services[n];
serv += "<li>" + (service.name || service.uuid) + "<ul>";
for (m in service.characteristics) {
serv += "<li>" + (service.characteristics[m].name || service.characteristics[m].uuid) + "</li>";
if (service.characteristics[m].uuid=="2a00" && !dat.NAME) dat.NAME = service.characteristics[m].stringValue;
}
serv += "</ul></li>";
}
for (n in dat.advertisement.serviceUuids) {
service = dat.advertisement.serviceUuids[n];
serv += "<li>" + ((typeof services[service])!="undefined" ? services[service].name : service) + "</li>";
if (!dat.NAME) dat.NAME = known[service];
}
for (n in dat.advertisement.serviceData) {
service = dat.advertisement.serviceData[n];
serv += "<li>" + ((typeof services[service.uuid])!="undefined" ? services[service.uuid].name : service.uuid) + "</li>";
}
serv += "</ul>";
dat.SERV = serv;
dat.LOC = dat.location || loc[dat.address] || "BBB 2909";
for (n in data) if(data[n].uuid===dat.uuid) data.splice(n,1);
data.unshift(dat);
$('#table').bootstrapTable('load', data );
$('#count').html(data.length + " Peripherals")
}
// }
$("tr").click(function(){
index = $(this).attr("data-index");
obj = data[index]; delete obj.TIME; delete obj.NAME; delete obj.ADV; delete obj.SERV; delete obj.LOC;
$(".modal-body").html("<pre>"+JSON.stringify(obj,null,4)+"</pre>");
$("#modal").modal('show');
});
});
}
</script>
</body>
</html>