Loading android/pandora/server/src/Gatt.kt +23 −23 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun exchangeMTU( request: ExchangeMTURequest, responseObserver: StreamObserver<ExchangeMTUResponse> responseObserver: StreamObserver<ExchangeMTUResponse>, ) { grpcUnary<ExchangeMTUResponse>(mScope, responseObserver) { val mtu = request.mtu Loading @@ -85,7 +85,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun writeAttFromHandle( request: WriteRequest, responseObserver: StreamObserver<WriteResponse> responseObserver: StreamObserver<WriteResponse>, ) { grpcUnary<WriteResponse>(mScope, responseObserver) { Log.i(TAG, "writeAttFromHandle handle=${request.handle}") Loading @@ -108,7 +108,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { val valueWrote = gattInstance.writeCharacteristicBlocking( characteristic, request.value.toByteArray() request.value.toByteArray(), ) WriteResponse.newBuilder() .setHandle(valueWrote.handle) Loading @@ -120,7 +120,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun discoverServiceByUuid( request: DiscoverServiceByUuidRequest, responseObserver: StreamObserver<DiscoverServicesResponse> responseObserver: StreamObserver<DiscoverServicesResponse>, ) { grpcUnary<DiscoverServicesResponse>(mScope, responseObserver) { val gattInstance = GattInstance.get(request.connection.address) Loading @@ -140,7 +140,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun discoverServices( request: DiscoverServicesRequest, responseObserver: StreamObserver<DiscoverServicesResponse> responseObserver: StreamObserver<DiscoverServicesResponse>, ) { grpcUnary<DiscoverServicesResponse>(mScope, responseObserver) { Log.i(TAG, "discoverServices") Loading @@ -155,7 +155,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun discoverServicesSdp( request: DiscoverServicesSdpRequest, responseObserver: StreamObserver<DiscoverServicesSdpResponse> responseObserver: StreamObserver<DiscoverServicesSdpResponse>, ) { grpcUnary<DiscoverServicesSdpResponse>(mScope, responseObserver) { Log.i(TAG, "discoverServicesSdp") Loading @@ -178,7 +178,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun clearCache( request: ClearCacheRequest, responseObserver: StreamObserver<ClearCacheResponse> responseObserver: StreamObserver<ClearCacheResponse>, ) { grpcUnary<ClearCacheResponse>(mScope, responseObserver) { Log.i(TAG, "clearCache") Loading @@ -190,7 +190,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun readCharacteristicFromHandle( request: ReadCharacteristicRequest, responseObserver: StreamObserver<ReadCharacteristicResponse> responseObserver: StreamObserver<ReadCharacteristicResponse>, ) { grpcUnary<ReadCharacteristicResponse>(mScope, responseObserver) { Log.i(TAG, "readCharacteristicFromHandle handle=${request.handle}") Loading @@ -210,7 +210,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun readCharacteristicsFromUuid( request: ReadCharacteristicsFromUuidRequest, responseObserver: StreamObserver<ReadCharacteristicsFromUuidResponse> responseObserver: StreamObserver<ReadCharacteristicsFromUuidResponse>, ) { grpcUnary<ReadCharacteristicsFromUuidResponse>(mScope, responseObserver) { Log.i(TAG, "readCharacteristicsFromUuid uuid=${request.uuid}") Loading @@ -220,7 +220,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { gattInstance.readCharacteristicUuidBlocking( UUID.fromString(request.uuid), request.startHandle, request.endHandle request.endHandle, ) ReadCharacteristicsFromUuidResponse.newBuilder() .addAllCharacteristicsRead(generateReadValuesList(readValues)) Loading @@ -230,7 +230,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun readCharacteristicDescriptorFromHandle( request: ReadCharacteristicDescriptorRequest, responseObserver: StreamObserver<ReadCharacteristicDescriptorResponse> responseObserver: StreamObserver<ReadCharacteristicDescriptorResponse>, ) { grpcUnary<ReadCharacteristicDescriptorResponse>(mScope, responseObserver) { Log.i(TAG, "readCharacteristicDescriptorFromHandle handle=${request.handle}") Loading @@ -250,7 +250,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun registerService( request: RegisterServiceRequest, responseObserver: StreamObserver<RegisterServiceResponse> responseObserver: StreamObserver<RegisterServiceResponse>, ) { grpcUnary(mScope, responseObserver) { Log.i(TAG, "registerService") Loading @@ -261,14 +261,14 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { BluetoothGattCharacteristic( UUID.fromString(characteristic_params.uuid), characteristic_params.properties, characteristic_params.permissions characteristic_params.permissions, ) for (descriptor_params in characteristic_params.descriptorsList) { characteristic.addDescriptor( BluetoothGattDescriptor( UUID.fromString(descriptor_params.uuid), descriptor_params.properties, descriptor_params.permissions descriptor_params.permissions, ) ) } Loading @@ -282,7 +282,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { .setService( GattService.newBuilder() .setHandle(addedService.instanceId) .setType(addedService.type) .setServiceType(ServiceType.forNumber(addedService.type)) .setUuid(addedService.uuid.toString().uppercase()) .addAllIncludedServices(generateServicesList(service.includedServices, 1)) .addAllCharacteristics(generateCharacteristicsList(service.characteristics)) Loading @@ -294,7 +294,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun setCharacteristicNotificationFromHandle( request: SetCharacteristicNotificationFromHandleRequest, responseObserver: StreamObserver<SetCharacteristicNotificationFromHandleResponse> responseObserver: StreamObserver<SetCharacteristicNotificationFromHandleResponse>, ) { grpcUnary<SetCharacteristicNotificationFromHandleResponse>(mScope, responseObserver) { Log.i(TAG, "SetCharcteristicNotificationFromHandle") Loading @@ -308,7 +308,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { val valueWrote = gattInstance.writeDescriptorBlocking( descriptor, BluetoothGattDescriptor.ENABLE_INDICATION_VALUE BluetoothGattDescriptor.ENABLE_INDICATION_VALUE, ) SetCharacteristicNotificationFromHandleResponse.newBuilder() .setHandle(valueWrote.handle) Loading @@ -318,7 +318,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { val valueWrote = gattInstance.writeDescriptorBlocking( descriptor, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE, ) SetCharacteristicNotificationFromHandleResponse.newBuilder() .setHandle(valueWrote.handle) Loading @@ -330,7 +330,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun waitCharacteristicNotification( request: WaitCharacteristicNotificationRequest, responseObserver: StreamObserver<WaitCharacteristicNotificationResponse> responseObserver: StreamObserver<WaitCharacteristicNotificationResponse>, ) { grpcUnary<WaitCharacteristicNotificationResponse>(mScope, responseObserver) { val gattInstance = GattInstance.get(request.connection.address) Loading @@ -352,7 +352,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { */ private suspend fun getCharacteristicWithHandle( handle: Int, gattInstance: GattInstance gattInstance: GattInstance, ): BluetoothGattCharacteristic? { tryDiscoverServices(gattInstance) for (service: BluetoothGattService in gattInstance.mGatt.services.orEmpty()) { Loading @@ -371,7 +371,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { */ private suspend fun getDescriptorWithHandle( handle: Int, gattInstance: GattInstance gattInstance: GattInstance, ): BluetoothGattDescriptor? { tryDiscoverServices(gattInstance) for (service: BluetoothGattService in gattInstance.mGatt.services.orEmpty()) { Loading @@ -389,14 +389,14 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { /** Generates a list of GattService from a list of BluetoothGattService. */ private fun generateServicesList( servicesList: List<BluetoothGattService>, dpth: Int dpth: Int, ): ArrayList<GattService> { val newServicesList = arrayListOf<GattService>() for (service in servicesList) { val serviceBuilder = GattService.newBuilder() .setHandle(service.getInstanceId()) .setType(service.getType()) .setServiceType(ServiceType.forNumber(service.type)) .setUuid(service.getUuid().toString().uppercase()) .addAllIncludedServices( generateServicesList(service.getIncludedServices(), dpth + 1) Loading pandora/interfaces/pandora_experimental/gatt.proto +6 −1 Original line number Diff line number Diff line Loading @@ -85,10 +85,15 @@ enum EnableValue { ENABLE_INDICATION_VALUE = 1; } enum ServiceType { PRIMARY = 0x00; SECONDARY = 0x01; } // A message representing a GATT service. message GattService { uint32 handle = 1; uint32 type = 2; ServiceType service_type = 2; string uuid = 3; repeated GattService included_services = 4; repeated GattCharacteristic characteristics = 5; Loading pandora/server/bumble_experimental/gatt.py +6 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ import logging from bumble.att import Attribute from bumble.core import ProtocolError from bumble.device import Connection as BumbleConnection, Device, Peer from bumble.gatt import Characteristic, Descriptor, Service from bumble.gatt import Characteristic, Descriptor, Service, GATT_PRIMARY_SERVICE_ATTRIBUTE_TYPE from bumble.gatt_client import CharacteristicProxy, ServiceProxy from bumble.pandora import utils from pandora_experimental.gatt_grpc_aio import GATTServicer Loading @@ -42,6 +42,7 @@ from pandora_experimental.gatt_pb2 import ( IndicateOnCharacteristicResponse, NotifyOnCharacteristicRequest, NotifyOnCharacteristicResponse, PRIMARY as PRIMARY_SERVICE, ReadCharacteristicDescriptorRequest, ReadCharacteristicDescriptorResponse, ReadCharacteristicRequest, Loading @@ -50,6 +51,8 @@ from pandora_experimental.gatt_pb2 import ( ReadCharacteristicsFromUuidResponse, RegisterServiceRequest, RegisterServiceResponse, SECONDARY as SECONDARY_SERVICE, ServiceType, WriteRequest, WriteResponse, ) Loading Loading @@ -171,7 +174,8 @@ class GATTService(GATTServicer): return DiscoverServicesResponse(services=[ GattService( handle=service.handle, type=int.from_bytes(bytes(service.type), 'little'), service_type=PRIMARY_SERVICE if service.type == GATT_PRIMARY_SERVICE_ATTRIBUTE_TYPE else SECONDARY_SERVICE, uuid=service.uuid.to_hex_str('-'), # type: ignore characteristics=[ GattCharacteristic( Loading Loading
android/pandora/server/src/Gatt.kt +23 −23 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun exchangeMTU( request: ExchangeMTURequest, responseObserver: StreamObserver<ExchangeMTUResponse> responseObserver: StreamObserver<ExchangeMTUResponse>, ) { grpcUnary<ExchangeMTUResponse>(mScope, responseObserver) { val mtu = request.mtu Loading @@ -85,7 +85,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun writeAttFromHandle( request: WriteRequest, responseObserver: StreamObserver<WriteResponse> responseObserver: StreamObserver<WriteResponse>, ) { grpcUnary<WriteResponse>(mScope, responseObserver) { Log.i(TAG, "writeAttFromHandle handle=${request.handle}") Loading @@ -108,7 +108,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { val valueWrote = gattInstance.writeCharacteristicBlocking( characteristic, request.value.toByteArray() request.value.toByteArray(), ) WriteResponse.newBuilder() .setHandle(valueWrote.handle) Loading @@ -120,7 +120,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun discoverServiceByUuid( request: DiscoverServiceByUuidRequest, responseObserver: StreamObserver<DiscoverServicesResponse> responseObserver: StreamObserver<DiscoverServicesResponse>, ) { grpcUnary<DiscoverServicesResponse>(mScope, responseObserver) { val gattInstance = GattInstance.get(request.connection.address) Loading @@ -140,7 +140,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun discoverServices( request: DiscoverServicesRequest, responseObserver: StreamObserver<DiscoverServicesResponse> responseObserver: StreamObserver<DiscoverServicesResponse>, ) { grpcUnary<DiscoverServicesResponse>(mScope, responseObserver) { Log.i(TAG, "discoverServices") Loading @@ -155,7 +155,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun discoverServicesSdp( request: DiscoverServicesSdpRequest, responseObserver: StreamObserver<DiscoverServicesSdpResponse> responseObserver: StreamObserver<DiscoverServicesSdpResponse>, ) { grpcUnary<DiscoverServicesSdpResponse>(mScope, responseObserver) { Log.i(TAG, "discoverServicesSdp") Loading @@ -178,7 +178,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun clearCache( request: ClearCacheRequest, responseObserver: StreamObserver<ClearCacheResponse> responseObserver: StreamObserver<ClearCacheResponse>, ) { grpcUnary<ClearCacheResponse>(mScope, responseObserver) { Log.i(TAG, "clearCache") Loading @@ -190,7 +190,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun readCharacteristicFromHandle( request: ReadCharacteristicRequest, responseObserver: StreamObserver<ReadCharacteristicResponse> responseObserver: StreamObserver<ReadCharacteristicResponse>, ) { grpcUnary<ReadCharacteristicResponse>(mScope, responseObserver) { Log.i(TAG, "readCharacteristicFromHandle handle=${request.handle}") Loading @@ -210,7 +210,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun readCharacteristicsFromUuid( request: ReadCharacteristicsFromUuidRequest, responseObserver: StreamObserver<ReadCharacteristicsFromUuidResponse> responseObserver: StreamObserver<ReadCharacteristicsFromUuidResponse>, ) { grpcUnary<ReadCharacteristicsFromUuidResponse>(mScope, responseObserver) { Log.i(TAG, "readCharacteristicsFromUuid uuid=${request.uuid}") Loading @@ -220,7 +220,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { gattInstance.readCharacteristicUuidBlocking( UUID.fromString(request.uuid), request.startHandle, request.endHandle request.endHandle, ) ReadCharacteristicsFromUuidResponse.newBuilder() .addAllCharacteristicsRead(generateReadValuesList(readValues)) Loading @@ -230,7 +230,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun readCharacteristicDescriptorFromHandle( request: ReadCharacteristicDescriptorRequest, responseObserver: StreamObserver<ReadCharacteristicDescriptorResponse> responseObserver: StreamObserver<ReadCharacteristicDescriptorResponse>, ) { grpcUnary<ReadCharacteristicDescriptorResponse>(mScope, responseObserver) { Log.i(TAG, "readCharacteristicDescriptorFromHandle handle=${request.handle}") Loading @@ -250,7 +250,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun registerService( request: RegisterServiceRequest, responseObserver: StreamObserver<RegisterServiceResponse> responseObserver: StreamObserver<RegisterServiceResponse>, ) { grpcUnary(mScope, responseObserver) { Log.i(TAG, "registerService") Loading @@ -261,14 +261,14 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { BluetoothGattCharacteristic( UUID.fromString(characteristic_params.uuid), characteristic_params.properties, characteristic_params.permissions characteristic_params.permissions, ) for (descriptor_params in characteristic_params.descriptorsList) { characteristic.addDescriptor( BluetoothGattDescriptor( UUID.fromString(descriptor_params.uuid), descriptor_params.properties, descriptor_params.permissions descriptor_params.permissions, ) ) } Loading @@ -282,7 +282,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { .setService( GattService.newBuilder() .setHandle(addedService.instanceId) .setType(addedService.type) .setServiceType(ServiceType.forNumber(addedService.type)) .setUuid(addedService.uuid.toString().uppercase()) .addAllIncludedServices(generateServicesList(service.includedServices, 1)) .addAllCharacteristics(generateCharacteristicsList(service.characteristics)) Loading @@ -294,7 +294,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun setCharacteristicNotificationFromHandle( request: SetCharacteristicNotificationFromHandleRequest, responseObserver: StreamObserver<SetCharacteristicNotificationFromHandleResponse> responseObserver: StreamObserver<SetCharacteristicNotificationFromHandleResponse>, ) { grpcUnary<SetCharacteristicNotificationFromHandleResponse>(mScope, responseObserver) { Log.i(TAG, "SetCharcteristicNotificationFromHandle") Loading @@ -308,7 +308,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { val valueWrote = gattInstance.writeDescriptorBlocking( descriptor, BluetoothGattDescriptor.ENABLE_INDICATION_VALUE BluetoothGattDescriptor.ENABLE_INDICATION_VALUE, ) SetCharacteristicNotificationFromHandleResponse.newBuilder() .setHandle(valueWrote.handle) Loading @@ -318,7 +318,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { val valueWrote = gattInstance.writeDescriptorBlocking( descriptor, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE, ) SetCharacteristicNotificationFromHandleResponse.newBuilder() .setHandle(valueWrote.handle) Loading @@ -330,7 +330,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { override fun waitCharacteristicNotification( request: WaitCharacteristicNotificationRequest, responseObserver: StreamObserver<WaitCharacteristicNotificationResponse> responseObserver: StreamObserver<WaitCharacteristicNotificationResponse>, ) { grpcUnary<WaitCharacteristicNotificationResponse>(mScope, responseObserver) { val gattInstance = GattInstance.get(request.connection.address) Loading @@ -352,7 +352,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { */ private suspend fun getCharacteristicWithHandle( handle: Int, gattInstance: GattInstance gattInstance: GattInstance, ): BluetoothGattCharacteristic? { tryDiscoverServices(gattInstance) for (service: BluetoothGattService in gattInstance.mGatt.services.orEmpty()) { Loading @@ -371,7 +371,7 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { */ private suspend fun getDescriptorWithHandle( handle: Int, gattInstance: GattInstance gattInstance: GattInstance, ): BluetoothGattDescriptor? { tryDiscoverServices(gattInstance) for (service: BluetoothGattService in gattInstance.mGatt.services.orEmpty()) { Loading @@ -389,14 +389,14 @@ class Gatt(private val context: Context) : GATTImplBase(), Closeable { /** Generates a list of GattService from a list of BluetoothGattService. */ private fun generateServicesList( servicesList: List<BluetoothGattService>, dpth: Int dpth: Int, ): ArrayList<GattService> { val newServicesList = arrayListOf<GattService>() for (service in servicesList) { val serviceBuilder = GattService.newBuilder() .setHandle(service.getInstanceId()) .setType(service.getType()) .setServiceType(ServiceType.forNumber(service.type)) .setUuid(service.getUuid().toString().uppercase()) .addAllIncludedServices( generateServicesList(service.getIncludedServices(), dpth + 1) Loading
pandora/interfaces/pandora_experimental/gatt.proto +6 −1 Original line number Diff line number Diff line Loading @@ -85,10 +85,15 @@ enum EnableValue { ENABLE_INDICATION_VALUE = 1; } enum ServiceType { PRIMARY = 0x00; SECONDARY = 0x01; } // A message representing a GATT service. message GattService { uint32 handle = 1; uint32 type = 2; ServiceType service_type = 2; string uuid = 3; repeated GattService included_services = 4; repeated GattCharacteristic characteristics = 5; Loading
pandora/server/bumble_experimental/gatt.py +6 −2 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ import logging from bumble.att import Attribute from bumble.core import ProtocolError from bumble.device import Connection as BumbleConnection, Device, Peer from bumble.gatt import Characteristic, Descriptor, Service from bumble.gatt import Characteristic, Descriptor, Service, GATT_PRIMARY_SERVICE_ATTRIBUTE_TYPE from bumble.gatt_client import CharacteristicProxy, ServiceProxy from bumble.pandora import utils from pandora_experimental.gatt_grpc_aio import GATTServicer Loading @@ -42,6 +42,7 @@ from pandora_experimental.gatt_pb2 import ( IndicateOnCharacteristicResponse, NotifyOnCharacteristicRequest, NotifyOnCharacteristicResponse, PRIMARY as PRIMARY_SERVICE, ReadCharacteristicDescriptorRequest, ReadCharacteristicDescriptorResponse, ReadCharacteristicRequest, Loading @@ -50,6 +51,8 @@ from pandora_experimental.gatt_pb2 import ( ReadCharacteristicsFromUuidResponse, RegisterServiceRequest, RegisterServiceResponse, SECONDARY as SECONDARY_SERVICE, ServiceType, WriteRequest, WriteResponse, ) Loading Loading @@ -171,7 +174,8 @@ class GATTService(GATTServicer): return DiscoverServicesResponse(services=[ GattService( handle=service.handle, type=int.from_bytes(bytes(service.type), 'little'), service_type=PRIMARY_SERVICE if service.type == GATT_PRIMARY_SERVICE_ATTRIBUTE_TYPE else SECONDARY_SERVICE, uuid=service.uuid.to_hex_str('-'), # type: ignore characteristics=[ GattCharacteristic( Loading