-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarm.html
246 lines (202 loc) · 10.1 KB
/
alarm.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title>CrossCONNECT Access Point API Example</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="lib/highlight/vs.css">
<script src="lib/common.js"></script>
<script src="lib/autobahn.js"></script>
<script src="lib/chart.js"></script>
<script src="lib/linq.js"></script>
<script src="lib/jquery-2.1.1.js"></script>
<script src="lib/highlight/highlight.pack.js"></script>
<script src="lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript">
$(function() {
var connection;
console.log('Autobahn version: ' + autobahn.version);
function addAlarm(entrance, alarm) {
// Add alarm to the table
var row = $('<tr>');
row.append($('<td>').text(alarm.id));
row.append($('<td>').text(alarm.deviceType));
row.append($('<td>').text(alarm.deviceId));
row.append($('<td>').text(entrance == null ? '-' : entrance.id));
row.append($('<td>').text(entrance == null ? '-' : entrance.name));
row.append($('<td>').text(alarm.direction));
row.append($('<td>').text(alarm.side));
$('#alarmTable tbody').prepend(row);
}
function openConnection(host) {
var entrances;
// Find the entrance to which a device belongs
var findEntrance = function(deviceType, deviceId) {
return Enumerable.From(entrances).Where(function(e) {
return Enumerable.From(e.devices).Any(function(d) {
return d.type == deviceType && d.id == deviceId;
});
}).FirstOrDefault();
};
// Create autobahn websocket connection
connection = new autobahn.Connection({
url: 'ws://' + host + ':9000/',
realm: 'ccap'
});
connection.onopen = function(session) {
// Hide error
showError(null);
// Set prefix
session.prefix('api', 'com.crosspoint.accesspoint');
// Get the counters
session.call('api:getentrances', []).then(
function(res) {
var kwargs = res.kwargs;
// Get all the entrances
entrances = Enumerable.From(kwargs.entrance).Select(function(e) {
// Get the devices
var devices = Enumerable.From(e.devices[0].device).Select(function(d) {
console.log('Entrance device: ', d);
return {
id: d.deviceId,
type: d.deviceType,
};
}).ToArray();
// Return entrance configuration
return {
id: e.id,
name: e.name,
devices: devices
};
}).ToArray();
console.log('Entrance definition: ', entrances);
},
function(err) {
showError(err.error.toString());
});
// Register to AM tag detected events
session.subscribe('api:tagdetectedam', function (args, kwargs) {
// Get the entrance
var entrance = findEntrance(kwargs.deviceType, kwargs.deviceId);
console.log('Alarm (AM) on entrance: ', entrance, kwargs);
// Add the alarm
addAlarm(entrance, kwargs);
}).catch(function(err) {
showError(err.error.toString());
});
// Register to RF tag detected events
session.subscribe('api:tagdetectedrf', function (args, kwargs) {
// Get the entrance
var entrance = findEntrance(kwargs.deviceType, kwargs.deviceId);
console.log('Alarm (RF) on entrance: ', entrance, kwargs);
// Add the alarm
addAlarm(entrance, kwargs);
}).catch(function(err) {
showError(err.error.toString());
});
};
connection.onclose = function(reason, details) {
var error = 'Autobahn connection closed. Reason: ' + reason;
if (details.message != null) {
error += details.message;
}
showError(error);
};
// Open the connection
connection.open();
}
$('#btnConnect').click(function(e) {
// Hide error
showError();
// Get host
var host = $('#inputAddress').val();
if (!host) {
showError('Invalid hostname or ip-address');
}
// Open connection
openConnection(host);
e.preventDefault();
e.stopPropagation();
});
// Show source code
showFunctionSource(openConnection, '#srcCode');
});
</script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<div class="navbar-brand">
CCAP API Example
</div>
</div>
<div class="navbar-header navbar-right">
<div class="navbar-image">
<img src="img/cross-point-logo.png">
</div>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="alert alert-danger" id="alertError">
<span class="glyphicon glyphicon-exclamation-sign"></span>
<span class="text">
Enter the CCAP IP hostname or ip-address in the input form and press connect.
</span>
</div>
<h3>
Input data
</h3>
<div class="input-group col-sm-6">
<input type="text" class="form-control" placeholder="Ccap IP or hostname" id="inputAddress" value="">
<span class="input-group-btn">
<button class="btn btn-primary" id="btnConnect">Connect</button>
</span>
</div>
<h3>
Description
</h3>
<p>
This example requests the entrance definition from the CrossCONNECT Access Point with the call <strong>com.crosspoint.accesspoint.getentrances</strong>.
</p>
<p>
Also the events are registered for the <strong>com.crosspoint.accesspoint.tagdetectedrf</strong> and <strong>com.crosspoint.accesspoint.tagdetectedam</strong> events. When this event is raised the entrance is determined and the information is added to the alarm table.
</p>
<p>
Enter the ip-address or hostname of your Access Point in the top bar and press connect to run the example.
</p>
<h3>
Alarm table
</h3>
<table id="alarmTable" class="table table-striped">
<thead>
<tr>
<th>Id</th>
<th>Device Type</th>
<th>Device Id</th>
<th>Entrance Id</th>
<th>Entrance Name</th>
<th>Direction</th>
<th>Side</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<h3>
Source Code
</h3>
<pre>
<code class="javascript" id="srcCode"></code>
</pre>
</div>
</div>
</div>
</body>
</html>