From 909e85d676810607de153860db55bb6f135d377e Mon Sep 17 00:00:00 2001 From: Fabian Christoffel Date: Tue, 20 Jun 2023 16:05:32 +0200 Subject: [PATCH] chore: print permissions characteristics --- .../sensortestingapp/ConnectionManager.kt | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/sensortestingapp/ConnectionManager.kt b/app/src/main/java/com/example/sensortestingapp/ConnectionManager.kt index c64c27e..9557c92 100644 --- a/app/src/main/java/com/example/sensortestingapp/ConnectionManager.kt +++ b/app/src/main/java/com/example/sensortestingapp/ConnectionManager.kt @@ -85,7 +85,14 @@ private fun BluetoothGatt.printGattTable() { val characteristicsTable = service.characteristics.joinToString( separator = "\n|--", prefix = "|--" - ) { it.uuid.toString() } + ) { + "${it.uuid.toString()} | " + + "readable: ${it.isReadable()}, " + + "writable: ${it.isWritable()}, " + + "writableWithoutResponse: ${it.isWritableWithoutResponse()}, " + + "notifiable: ${it.isNotifiable()}, " + + "indicatable: ${it.isIndicatable()}, " + } Log.i( "printGattTable", "\nService ${service.uuid}\nCharacteristics:\n$characteristicsTable" ) @@ -102,9 +109,14 @@ fun BluetoothGattCharacteristic.isWritable(): Boolean = fun BluetoothGattCharacteristic.isWritableWithoutResponse(): Boolean = containsProperty(BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) -fun BluetoothGattCharacteristic.containsProperty(property: Int): Boolean { - return properties and property != 0 -} +fun BluetoothGattCharacteristic.isIndicatable(): Boolean = + containsProperty(BluetoothGattCharacteristic.PROPERTY_INDICATE) + +fun BluetoothGattCharacteristic.isNotifiable(): Boolean = + containsProperty(BluetoothGattCharacteristic.PROPERTY_NOTIFY) + +fun BluetoothGattCharacteristic.containsProperty(property: Int): Boolean = + properties and property != 0 fun ByteArray.toHexString(): String = joinToString(separator = "", prefix = "0x") { String.format("%02X", it) }