From 6c8d73dfd79395eca95b3e7d6817f759e015f071 Mon Sep 17 00:00:00 2001 From: Erik Johansson Date: Thu, 15 Nov 2018 22:25:28 +0100 Subject: [PATCH] Pretty print uuids in BluetoothCommunication --- .../bluetooth/BluetoothCommunication.java | 29 +++++++++++-------- .../core/bluetooth/BluetoothGattUuid.java | 4 +++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java index 6fe5d36d..0efd579a 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothCommunication.java @@ -266,7 +266,7 @@ public abstract class BluetoothCommunication { BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service) .getCharacteristic(characteristic); - Timber.d("Read characteristic %s", characteristic); + Timber.d("Read characteristic %s", BluetoothGattUuid.prettyPrint(characteristic)); bluetoothGatt.readCharacteristic(gattCharacteristic); } @@ -274,7 +274,7 @@ public abstract class BluetoothCommunication { BluetoothGattDescriptor gattDescriptor = bluetoothGatt.getService(service) .getCharacteristic(characteristic).getDescriptor(descriptor); - Timber.d("Read descriptor %s", descriptor); + Timber.d("Read descriptor %s", BluetoothGattUuid.prettyPrint(descriptor)); bluetoothGatt.readDescriptor(gattDescriptor); } @@ -285,7 +285,7 @@ public abstract class BluetoothCommunication { * @param characteristic the Bluetooth UUID characteristic */ protected void setIndicationOn(UUID service, UUID characteristic, UUID descriptor) { - Timber.d("Set indication on for %s", characteristic); + Timber.d("Set indication on for %s", BluetoothGattUuid.prettyPrint(characteristic)); try { BluetoothGattCharacteristic gattCharacteristic = @@ -310,7 +310,7 @@ public abstract class BluetoothCommunication { * @param characteristic the Bluetooth UUID characteristic */ protected void setNotificationOn(UUID service, UUID characteristic, UUID descriptor) { - Timber.d("Set notification on for %s", characteristic); + Timber.d("Set notification on for %s", BluetoothGattUuid.prettyPrint(characteristic)); try { BluetoothGattCharacteristic gattCharacteristic = @@ -335,7 +335,7 @@ public abstract class BluetoothCommunication { * @param characteristic the Bluetooth UUID characteristic */ protected void setNotificationOff(UUID service, UUID characteristic, UUID descriptor) { - Timber.d("Set notification off for %s", characteristic); + Timber.d("Set notification off for %s", BluetoothGattUuid.prettyPrint(characteristic)); BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service).getCharacteristic(characteristic); @@ -579,11 +579,12 @@ public abstract class BluetoothCommunication { descriptor.gattObject.setValue(descriptor.value); Timber.d("Write descriptor %s: %s (queue: %d %d)", - descriptor.gattObject.getUuid(), byteInHex(descriptor.gattObject.getValue()), + BluetoothGattUuid.prettyPrint(descriptor.gattObject.getUuid()), + byteInHex(descriptor.gattObject.getValue()), descriptorRequestQueue.size(), characteristicRequestQueue.size()); if (!bluetoothGatt.writeDescriptor(descriptor.gattObject)) { Timber.e("Failed to initiate write of descriptor %s", - descriptor.gattObject.getUuid()); + BluetoothGattUuid.prettyPrint(descriptor.gattObject.getUuid())); } openRequest = true; return; @@ -595,12 +596,13 @@ public abstract class BluetoothCommunication { characteristic.gattObject.setValue(characteristic.value); Timber.d("Write characteristic %s: %s (type: %d; queue: %d %d)", - characteristic.gattObject.getUuid(), byteInHex(characteristic.gattObject.getValue()), + BluetoothGattUuid.prettyPrint(characteristic.gattObject.getUuid()), + byteInHex(characteristic.gattObject.getValue()), characteristic.gattObject.getWriteType(), descriptorRequestQueue.size(), characteristicRequestQueue.size()); if (!bluetoothGatt.writeCharacteristic(characteristic.gattObject)) { Timber.e("Failed to initiate write of characteristic %s", - characteristic.gattObject.getUuid()); + BluetoothGattUuid.prettyPrint(characteristic.gattObject.getUuid())); } openRequest = true; return; @@ -732,7 +734,8 @@ public abstract class BluetoothCommunication { final BluetoothGattCharacteristic characteristic, final int status) { Timber.d("onCharacteristicRead %s (status=%d): %s", - characteristic.getUuid(), status, byteInHex(characteristic.getValue())); + BluetoothGattUuid.prettyPrint(characteristic.getUuid()), + status, byteInHex(characteristic.getValue())); handler.post(new Runnable() { @Override @@ -747,7 +750,8 @@ public abstract class BluetoothCommunication { public void onCharacteristicChanged(final BluetoothGatt gatt, final BluetoothGattCharacteristic characteristic) { Timber.d("onCharacteristicChanged %s: %s", - characteristic.getUuid(), byteInHex(characteristic.getValue())); + BluetoothGattUuid.prettyPrint(characteristic.getUuid()), + byteInHex(characteristic.getValue())); handler.post(new Runnable() { @Override @@ -762,7 +766,8 @@ public abstract class BluetoothCommunication { BluetoothGattDescriptor descriptor, int status) { Timber.d("onDescriptorRead %s (status=%d): %s", - descriptor.getUuid(), status, byteInHex(descriptor.getValue())); + BluetoothGattUuid.prettyPrint(descriptor.getUuid()), + status, byteInHex(descriptor.getValue())); postDelayedHandleRequests(); } diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java index 78cc7775..0c1f6e78 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/BluetoothGattUuid.java @@ -27,6 +27,10 @@ public class BluetoothGattUuid { } public static final String prettyPrint(UUID uuid) { + if (uuid == null) { + return "null"; + } + String str = uuid.toString(); if (str.endsWith(STANDARD_SUFFIX)) {