-
Notifications
You must be signed in to change notification settings - Fork 1
/
vias_test.html
299 lines (269 loc) · 8.3 KB
/
vias_test.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> VIAS test </title>
<script src="vias.js"></script>
<script src="svr_config.js"></script>
<style>
.btn {
width:180px;
}
#idSpanDoorlock {
font-size:14px;
}
</style>
</head>
<body>
<button type="button" class="btn" id="idBtnConnect">Connect</button><br>
<button type="button" class="btn" id="idBtnDisconnect">Disconnect</button><br>
<br>
<button type="button" class="btn" id="idBtnGetSpeed">Get Speed</button><br>
<br>
<button type="button" class="btn" id="idBtnSubscribeSpeed">Subscribe Speed</button><br>
<button type="button" class="btn" id="idBtnUnsubscribeSpeed">Unsubscribe Speed</button><br>
<br>
<button type="button" class="btn" id="idBtnSubscribeRPM">Subscribe RPM</button><br>
<button type="button" class="btn" id="idBtnUnsubscribeRPM">Unsubscribe RPM</button><br>
<br>
<button type="button" class="btn" id="idBtnUnsubscribeAll">UnsubscribeAll</button><br>
<br>
<button type="button" class="btn" id="idBtnSetDoorlockTrue">Set Doorlock True</button><br>
<button type="button" class="btn" id="idBtnSetDoorlockFalse">Set Doorlock False</button><br>
<button type="button" class="btn" id="idBtnGetDoorlock">Get Doorlock</button><br>
<span id="idSpanDoorlock" >* Doorlock = Row2 Right Door's lock</span>
<br>
<br>
<button type="button" class="btn" id="idBtnAuthorize">Authorize</button><br>
<br>
<button type="button" class="btn" id="idBtnGetVss">getVss</button><br>
</body>
<script>
var VSS_SPEED = 'Signal.Drivetrain.Transmission.Speed';
var VSS_RPM = 'Signal.Drivetrain.InternalCombustionEngine.RPM';
var VSS_DOORLOCK = 'Signal.Cabin.Door.Row1.Right.IsLocked';
//var VSS_DOORLOCK = 'Signal.Cabin.Door.Row2.Right.IsLocked';
//var VISS_IP = 'wwwivi';
//var VISS_PORT='3000';
const viscOption = {
'host': VISS_IP,
'protocol': 'ws://',
'port': VISS_PORT
};
var subId_speed = null;
var subId_RPM = null;
var vias = new VISClient( viscOption );
var bConnected = false;
const connectCb = () => {
console.log(`Connect: Success`);
bConnected = true;
};
const connectErrCb = (_err) => {
//console.error(`Connect: Error : ${_err.number}`);
console.log('Connect: Error :' + _err.number );
bConnected = false;
};
// TODO: errorの返し方はどうする?
// このcallback は定義上は引数なし。
// disconnect 成功時のcallback. err というよりは msg を返したい
const disconnectCb = (_msg) => {
console.log(`Disconnect: Success` + _msg);
bConnected = false;
};
const disconnectErrCb = (_err) => {
console.error(`Disconnect: Error : ${_err.number}`);
};
function doConnect() {
if (bConnected) {
console.log("WebSocket already connected");
return;
}
vias.connect(connectCb, connectErrCb);
}
function doDisconnect() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
vias.disconnect(disconnectCb, disconnectErrCb);
}
function doGetSpeed() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
// get method test
vias.get(VSS_SPEED,
function(_val) {
console.log(`get speed:success: val= ${_val.value}, ts= ${_val.timestamp}`);
},
function(_err) {
console.error(`get speed:failure: err= ${_err.number}`);
});
}
function doSubscribe(_refval) {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
_refval.subId = vias.subscribe(_refval.path, _refval.sucCb, _refval.errCb);
}
function doSubscribeSpeed() {
var refval = {};
refval.path = VSS_SPEED;
refval.subId = subId_speed;
refval.sucCb = function(_val) { console.log(`subscribe speed: success: val= ${_val.value}, ts=${_val.timestamp}`); };
refval.errCb = function(_err) { console.error(`subscribe speed: failure: err= ${_err.number}`); };
doSubscribe(refval);
subId_speed = refval.subId;
}
function doSubscribeRPM() {
var refval = {};
refval.path = VSS_RPM;
refval.subId = subId_RPM;
refval.sucCb = function(_val) { console.log(`subscribe RPM: success: val= ${_val.value}, ts=${_val.timestamp}`); };
refval.errCb = function(_err) { console.error(`subscribe RPM: failure: err= ${_err.number}`); };
doSubscribe(refval);
subId_RPM = refval.subId;
}
function doUnsubscribe(_refval) {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
if (_refval.subId) {
vias.unsubscribe(_refval.subId,
_refval.sucCb, _refval.errCb);
}
}
function doUnsubscribeSpeed() {
var refval = {};
refval.subId = subId_speed;
refval.sucCb = function() {
console.log('unsubscribe:success');
subId_speed = null;
};
refval.errCb = function(_err) {
console.error(`unsubscribe:failure err=${_err.number}`);
};
doUnsubscribe(refval);
}
function doUnsubscribeRPM() {
var refval = {};
refval.subId = subId_RPM;
refval.sucCb = function() {
console.log('unsubscribe:success');
subId_RPM = null;
};
refval.errCb = function(_err) {
console.error(`unsubscribe:failure err=${_err.number}`);
};
doUnsubscribe(refval);
}
function doUnsubscribeAll() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
vias.unsubscribeAll(
function() {
console.log('unsubscribeAll:success');
},
function(_err) {
console.error(`unsubscribeAll:failure err=${_err.number}`);
}
);
}
function doGetDoorlock() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
// get method test
vias.get(VSS_DOORLOCK,
function(_val) {
console.log(`get doorlock:success: val= ${_val.value}, ts= ${_val.timestamp}`);
},
function(_err) {
console.error(`get doorlock:failure: err= ${_err.number}`);
});
}
function doSetDoorlockTrue() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
// set method test
vias.set(VSS_DOORLOCK, 'true',
function() {
console.log(`set doorlock:success`);
},
function(_err) {
console.error(`set doorlock:failure: err= ${_err.number}`);
});
}
function doSetDoorlockFalse() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
// set method test
vias.set(VSS_DOORLOCK, 'false',
function() {
console.log(`set doorlock:success`);
},
function(_err) {
console.error(`set doorlock:failure: err= ${_err.number}`);
});
}
function doAuthorize() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
// get method test
var userToken = 'token_valid'; // fake token for test
var deviceToken = 'token_valid'; // fake token for test
var tokens = {"authorization" : userToken,
"www-vehicle-device": deviceToken};
vias.authorize(tokens,
function(_ttl) {
console.log(`authorize :success: TTL= ${_ttl}`);
},
function(_err) {
console.error(`authorize :failure: err= ${_err.number}`);
});
}
function doGetVss() {
if (!bConnected) {
console.log("WebSocket not connected");
return;
}
// get method test
var path = 'Attribute.Body';
console.log('getVSS: path=' + path);
vias.getVss(path,
function(_vss) {
console.log(`getVSS :success: vss= ${_vss}`);
},
function(_err) {
console.error(`getVSS :failure: err= ${_err.number}`);
});
}
(function() {
document.getElementById('idBtnConnect').addEventListener('click', doConnect);
document.getElementById('idBtnDisconnect').addEventListener('click', doDisconnect);
document.getElementById('idBtnGetSpeed').addEventListener('click', doGetSpeed);
document.getElementById('idBtnSubscribeSpeed').addEventListener('click', doSubscribeSpeed);
document.getElementById('idBtnUnsubscribeSpeed').addEventListener('click', doUnsubscribeSpeed);
document.getElementById('idBtnSubscribeRPM').addEventListener('click', doSubscribeRPM);
document.getElementById('idBtnUnsubscribeRPM').addEventListener('click', doUnsubscribeRPM);
document.getElementById('idBtnUnsubscribeAll').addEventListener('click', doUnsubscribeAll);
document.getElementById('idBtnSetDoorlockTrue').addEventListener('click', doSetDoorlockTrue);
document.getElementById('idBtnSetDoorlockFalse').addEventListener('click', doSetDoorlockFalse);
document.getElementById('idBtnGetDoorlock').addEventListener('click', doGetDoorlock);
document.getElementById('idBtnAuthorize').addEventListener('click', doAuthorize);
document.getElementById('idBtnGetVss').addEventListener('click', doGetVss);
})();
</script>
</html>