servo/tests/html/bluetooth/bluetooth_get_characteristic_test_cases.html
2016-09-26 20:02:42 +02:00

88 lines
5.4 KiB
HTML

<!DOCTYPE html>
<html>
<title>GetCharacteristic 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: 'not_a_characteristic_name', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 2
testCases.push({characteristic: 'battery_level', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 3
testCases.push({characteristic: '1234567891000-1000-8000-00805f9b34fb', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 4
testCases.push({characteristic: '11', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 5
testCases.push({characteristic: '12345678-1234-1234-1234-123456789abc', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 6
testCases.push({characteristic: '00000000-0000-0000-0000-000000000000', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 7
testCases.push({characteristic: 0x0000, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 8
testCases.push({characteristic: 0x000000000, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 9
testCases.push({characteristic: 0x2a19, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 10
testCases.push({characteristic: 0x12345678, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 11
testCases.push({characteristic: 0x00002a19, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 12
testCases.push({characteristic: 0x00002a03, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 13
testCases.push({characteristic: 0x00002a25, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 14
testCases.push({characteristic: 0x2a03, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 15
testCases.push({characteristic: 0x2a25, service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 16
testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
//Test 17
testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', service: 'battery_service', options: {filters: [{services: ['battery_service']}], optionalServices: ['cycling_power']} });
function onButtonClick(testNumber) {
clear();
log('Requesting Bluetooth Device...');
window.navigator.bluetooth.requestDevice(testCases[testNumber].options)
.then(device => {
log('Connecting to GATTserver on device...');
return device.gatt.connect();
})
.then(server => {
log('Getting Primary Service "' + testCases[testNumber].service + '"...');
return server.getPrimaryService(testCases[testNumber].service);
})
.then(service => {
log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...');
return service.getCharacteristic(testCases[testNumber].characteristic);
})
.then(characteristic => {
log('Characteristic found!');
log('> Characteristic service: ' + characteristic.service.uuid);
log('> Characteristic UUID: ' + characteristic.uuid);
log('> Broadcast: ' + characteristic.properties.broadcast);
log('> Read: ' + characteristic.properties.read);
log('> Write w/o response: ' + characteristic.properties.writeWithoutResponse);
log('> Write: ' + characteristic.properties.write);
log('> Notify: ' + characteristic.properties.notify);
log('> Indicate: ' + characteristic.properties.indicate);
log('> Signed Write: ' + characteristic.properties.authenticatedSignedWrites);
log('> Queued Write: ' + characteristic.properties.reliableWrite);
log('> Writable Auxiliaries: ' + characteristic.properties.writableAuxiliaries);
return characteristic.readValue();
})
.then(value => {
log('> Characteristic value: ' + asciiToDecimal(value));
})
.catch(err => {
log(err);
});
}
populate(testCases);
</script>
</body>
</html>