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

77 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html>
<title>Characterstic's ReadValue 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: 'body_sensor_location', mustDisconnect: true});
//Test 2
testCases.push({characteristic: 'gap.reconnection_address', mustDisconnect: false});
//Test 3
testCases.push({characteristic: 'serial_number_string', mustDisconnect: false});
//Test 4
testCases.push({characteristic: 0x00002a03, mustDisconnect: false});
//Test 5
testCases.push({characteristic: 0x00002a25, mustDisconnect: false});
//Test 6
testCases.push({characteristic: '00002a03-0000-1000-8000-00805f9b34fb', mustDisconnect: false});
//Test 7
testCases.push({characteristic: '00002a25-0000-1000-8000-00805f9b34fb', mustDisconnect: false});
//Test 8
testCases.push({characteristic: 'body_sensor_location', mustDisconnect: false});
//Test 9
testCases.push({characteristic: 0x00002a38, mustDisconnect: false});
//Test 10
testCases.push({characteristic: '00002a38-0000-1000-8000-00805f9b34fb', mustDisconnect: false});
//Test 11
testCases.push({characteristic: 'heart_rate_control_point', mustDisconnect: false});
function onButtonClick(testNumber) {
clear();
var bt_server;
log('Requesting Bluetooth Device...');
window.navigator.bluetooth.requestDevice({filters: [{services: ['heart_rate']}]})
.then(device => {
log('Connecting to GATTserver on device...');
return device.gatt.connect();
})
.then(server => {
bt_server = server;
log('Getting Primary Service "heart_rate"...');
return server.getPrimaryService('heart_rate');
})
.then(service => {
log('Getting Characteristic "' + testCases[testNumber].characteristic + '"...');
return service.getCharacteristic(testCases[testNumber].characteristic);
})
.then(characteristic => {
log('Characteristic found!');
if (testCases[testNumber].mustDisconnect) {
log('Disconnecting from server...');
bt_server.disconnect();
}
log('Reading the value of the Characteristic...');
return characteristic.readValue();
})
.then(value => {
log('> Characteristic value: ' + asciiToDecimal(value));
})
.catch(err => {
log(err);
});
}
populate(testCases);
</script>
</body>
</html>