Split up services responses

This commit is contained in:
Jesse Hills 2022-09-28 17:02:22 +13:00
parent 40793909bf
commit 52b4ca279d
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
3 changed files with 147 additions and 90 deletions

View File

@ -47,7 +47,7 @@ service APIConnection {
rpc subscribe_bluetooth_le_advertisements (SubscribeBluetoothLEAdvertisementsRequest) returns (void) {}
rpc bluetooth_device_request(BluetoothDeviceRequest) returns (void) {}
rpc bluetooth_gatt_get_services(BluetoothGATTGetServicesRequest) returns (BluetoothGATTGetServicesResponse) {}
rpc bluetooth_gatt_get_services(BluetoothGATTGetServicesRequest) returns (void) {}
rpc bluetooth_gatt_read(BluetoothGATTReadRequest) returns (void) {}
rpc bluetooth_gatt_write(BluetoothGATTWriteRequest) returns (void) {}
rpc bluetooth_gatt_read_descriptor(BluetoothGATTReadDescriptorRequest) returns (void) {}
@ -1221,14 +1221,21 @@ message BluetoothGATTGetServicesResponse {
option (id) = 71;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_BLUETOOTH_PROXY";
option (no_delay) = true;
uint64 address = 1;
repeated BluetoothGATTService services = 2;
}
message BluetoothGATTReadRequest {
message BluetoothGATTGetServicesDoneResponse {
option (id) = 72;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_BLUETOOTH_PROXY";
uint64 address = 1;
}
message BluetoothGATTReadRequest {
option (id) = 73;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_BLUETOOTH_PROXY";
@ -1237,7 +1244,7 @@ message BluetoothGATTReadRequest {
}
message BluetoothGATTReadResponse {
option (id) = 73;
option (id) = 74;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_BLUETOOTH_PROXY";
@ -1249,7 +1256,7 @@ message BluetoothGATTReadResponse {
}
message BluetoothGATTWriteRequest {
option (id) = 74;
option (id) = 75;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_BLUETOOTH_PROXY";
@ -1261,7 +1268,7 @@ message BluetoothGATTWriteRequest {
}
message BluetoothGATTReadDescriptorRequest {
option (id) = 75;
option (id) = 76;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_BLUETOOTH_PROXY";
@ -1270,7 +1277,7 @@ message BluetoothGATTReadDescriptorRequest {
}
message BluetoothGATTWriteDescriptorRequest {
option (id) = 76;
option (id) = 77;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_BLUETOOTH_PROXY";
@ -1281,7 +1288,7 @@ message BluetoothGATTWriteDescriptorRequest {
}
message BluetoothGATTNotifyRequest {
option (id) = 77;
option (id) = 78;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_BLUETOOTH_PROXY";
@ -1291,7 +1298,7 @@ message BluetoothGATTNotifyRequest {
}
message BluetoothGATTNotifyDataResponse {
option (id) = 78;
option (id) = 79;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_BLUETOOTH_PROXY";
@ -1302,13 +1309,13 @@ message BluetoothGATTNotifyDataResponse {
}
message SubscribeBluetoothConnectionsFreeRequest {
option (id) = 79;
option (id) = 80;
option (source) = SOURCE_CLIENT;
option (ifdef) = "USE_BLUETOOTH_PROXY";
}
message BluetoothConnectionsFreeResponse {
option (id) = 80;
option (id) = 81;
option (source) = SOURCE_SERVER;
option (ifdef) = "USE_BLUETOOTH_PROXY";

File diff suppressed because one or more lines are too long

View File

@ -23,6 +23,7 @@ from .api_pb2 import ( # type: ignore
BluetoothDeviceConnectionResponse,
BluetoothDeviceRequest,
BluetoothGATTGetServicesRequest,
BluetoothGATTGetServicesDoneResponse,
BluetoothGATTGetServicesResponse,
BluetoothGATTNotifyDataResponse,
BluetoothGATTNotifyRequest,
@ -496,12 +497,20 @@ class APIClient:
async def bluetooth_gatt_get_services(self, address: int) -> BluetoothGATTServices:
self._check_authenticated()
def do_append(msg: message.Message) -> None:
return isinstance(msg, BluetoothGATTGetServicesResponse)
def do_stop(msg: message.Message) -> bool:
return isinstance(msg, BluetoothGATTGetServicesDoneResponse)
assert self._connection is not None
resp = await self._connection.send_message_await_response(
BluetoothGATTGetServicesRequest(address=address),
BluetoothGATTGetServicesResponse,
resp = await self._connection.send_message_await_response_complex(
BluetoothGATTGetServicesRequest(address=address), do_append, do_stop
)
return BluetoothGATTServices.from_pb(resp)
services = []
for msg in resp:
services.extend(BluetoothGATTServices.from_pb(msg).services)
return BluetoothGATTServices(address=address, services=services)
async def bluetooth_gatt_read(
self, address: int, characteristic_handle: int, timeout: float = 10.0