diff options
author | Sven Gothel <[email protected]> | 2020-07-27 04:53:59 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-07-27 04:53:59 +0200 |
commit | b7d7d08c108fb3a1d17d3542dce1f942f6bb4059 (patch) | |
tree | 0a84ec673f836d5264f76f9b708563dd71012b91 /examples | |
parent | bc1cf2003cd624e1c859c0f421e432624077861b (diff) |
ScannerTinyB10: Wrap whole services/characteristic walk through block in a try - catch, avoiding retry on exception and fail once only.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/java/ScannerTinyB10.java | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/examples/java/ScannerTinyB10.java b/examples/java/ScannerTinyB10.java index c2194542..1ec6afc3 100644 --- a/examples/java/ScannerTinyB10.java +++ b/examples/java/ScannerTinyB10.java @@ -295,28 +295,28 @@ public class ScannerTinyB10 { println("Added GATTCharacteristicListener: "+addedCharacteristicListenerRes); } - int i=0, j=0; - for(final Iterator<BluetoothGattService> srvIter = primServices.iterator(); srvIter.hasNext(); i++) { - final BluetoothGattService primService = srvIter.next(); - printf(" [%02d] Service %s\n", i, primService.toString()); - printf(" [%02d] Service Characteristics\n", i); - final List<BluetoothGattCharacteristic> serviceCharacteristics = primService.getCharacteristics(); - for(final Iterator<BluetoothGattCharacteristic> charIter = serviceCharacteristics.iterator(); charIter.hasNext(); j++) { - final BluetoothGattCharacteristic serviceChar = charIter.next(); - printf(" [%02d.%02d] Decla: %s\n", i, j, serviceChar.toString()); - final List<String> properties = Arrays.asList(serviceChar.getFlags()); - if( properties.contains("read") ) { - try { + try { + int i=0, j=0; + for(final Iterator<BluetoothGattService> srvIter = primServices.iterator(); srvIter.hasNext(); i++) { + final BluetoothGattService primService = srvIter.next(); + printf(" [%02d] Service %s\n", i, primService.toString()); + printf(" [%02d] Service Characteristics\n", i); + final List<BluetoothGattCharacteristic> serviceCharacteristics = primService.getCharacteristics(); + for(final Iterator<BluetoothGattCharacteristic> charIter = serviceCharacteristics.iterator(); charIter.hasNext(); j++) { + final BluetoothGattCharacteristic serviceChar = charIter.next(); + printf(" [%02d.%02d] Decla: %s\n", i, j, serviceChar.toString()); + final List<String> properties = Arrays.asList(serviceChar.getFlags()); + if( properties.contains("read") ) { final byte[] value = serviceChar.readValue(); final String svalue = BluetoothUtils.decodeUTF8String(value, 0, value.length); printf(" [%02d.%02d] Value: %s ('%s')\n", i, j, BluetoothUtils.bytesHexString(value, true, true), svalue); - } catch( final Exception ex) { - println("Caught "+ex.getMessage()); - ex.printStackTrace(); } } } + } catch( final Exception ex) { + println("Caught "+ex.getMessage()); + ex.printStackTrace(); } // FIXME sleep 1s for potential callbacks .. try { |