mirror of
https://github.com/servo/servo
synced 2026-04-28 02:19:14 +02:00
93 lines
3.5 KiB
HTML
93 lines
3.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<title>Characterstic's WriteValue Test Cases</title>
|
|
<body>
|
|
<div id="buttons"></div>
|
|
<pre id="log"></pre>
|
|
<script src="bluetooth_functions.js"></script>
|
|
<script>
|
|
var testCases = [];
|
|
//Test 1
|
|
testCases.push({characteristic: 0x2345, valueToWrite: [11], mustDisconnect: true});
|
|
//Test 2
|
|
testCases.push({characteristic: 0x2345, valueToWrite: new Array(513), mustDisconnect: false});
|
|
//Test 3
|
|
testCases.push({characteristic: 'gap.reconnection_address', valueToWrite: [1], mustDisconnect: false});
|
|
//Test 4
|
|
testCases.push({characteristic: 'serial_number_string', valueToWrite: [2], mustDisconnect: false});
|
|
//Test 5
|
|
testCases.push({characteristic: 0x00002a02, valueToWrite: [3], mustDisconnect: false});
|
|
//Test 6
|
|
testCases.push({characteristic: 0x00002a03, valueToWrite: [3], mustDisconnect: false});
|
|
//Test 7
|
|
testCases.push({characteristic: 0x00002a25, valueToWrite: [4], mustDisconnect: false});
|
|
//Test 8
|
|
testCases.push({characteristic: '00002a02-0000-1000-8000-00805f9b34fb', valueToWrite: [6], mustDisconnect: false});
|
|
//Test 9
|
|
testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', valueToWrite: [5], mustDisconnect: false});
|
|
//Test 10
|
|
testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', valueToWrite: [6], mustDisconnect: false});
|
|
//Test 11
|
|
testCases.push({characteristic: 0x2345, valueToWrite: [11]});
|
|
//Test 12
|
|
testCases.push({characteristic: '00002345-0000-1000-8000-00805f9b34fb', valueToWrite: [22], mustDisconnect: false});
|
|
|
|
function onButtonClick(testNumber) {
|
|
clear();
|
|
|
|
var bt_server;
|
|
|
|
log('Requesting Bluetooth Device...');
|
|
window.navigator.bluetooth.requestDevice({filters: [{services: [0x1234]}]})
|
|
.then(device => {
|
|
log('Connecting to GATT Server on device...');
|
|
return device.gatt.connect();
|
|
})
|
|
.then(server => {
|
|
bt_server = server;
|
|
|
|
log('Getting Primary Service...');
|
|
return server.getPrimaryService(0x1234);
|
|
})
|
|
.then(service => {
|
|
log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...');
|
|
return service.getCharacteristic(testCases[testNumber].characteristic);
|
|
})
|
|
.then(characteristic => {
|
|
log('Characteristic found!');
|
|
log('Reading the old value of the Characteristic...');
|
|
return characteristic.readValue();
|
|
})
|
|
.then(value => {
|
|
log('> Characteristic value: ' + asciiToDecimal(characteristic.value));
|
|
|
|
if (testCases[testNumber].mustDisconnect) {
|
|
log('Disconnecting from server...');
|
|
bt_server.disconnect();
|
|
}
|
|
|
|
if (testNumber !== 1) {
|
|
log('Writing the value of the Characteristic with: ' + testCases[testNumber].valueToWrite + '...');
|
|
} else {
|
|
log('Writing the value of the Characteristic with a 513 long array...');
|
|
}
|
|
|
|
return characteristic.writeValue(testCases[testNumber].valueToWrite);
|
|
})
|
|
.then(_ => {
|
|
log('Reading the new value of the Characteristic...');
|
|
return characteristic.readValue();
|
|
})
|
|
.then(value => {
|
|
log('> Characteristic value: ' + asciiToDecimal(value));
|
|
})
|
|
.catch(err => {
|
|
log(err);
|
|
});
|
|
}
|
|
|
|
populate(testCases);
|
|
</script>
|
|
</body>
|
|
</html>
|