From de8639010192bee9f87112eb52286a70e0e7f54a Mon Sep 17 00:00:00 2001 From: Nebojsa Cvetkovic Date: Wed, 6 Nov 2024 20:02:10 -0500 Subject: [PATCH] Rename instanceId to index --- .../FlutterBluePlusPlugin.java | 108 +++++------ ios/Classes/FlutterBluePlusPlugin.m | 168 +++++++++--------- lib/src/bluetooth_characteristic.dart | 42 ++--- lib/src/bluetooth_descriptor.dart | 24 +-- lib/src/bluetooth_events.dart | 20 +-- lib/src/bluetooth_msgs.dart | 162 ++++++++--------- lib/src/bluetooth_service.dart | 12 +- 7 files changed, 266 insertions(+), 270 deletions(-) diff --git a/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java b/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java index 4181e410..3be045cc 100644 --- a/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java +++ b/android/src/main/java/com/lib/flutter_blue_plus/FlutterBluePlusPlugin.java @@ -835,11 +835,11 @@ public void onMethodCall(@NonNull MethodCall call, HashMap data = call.arguments(); String remoteId = (String) data.get("remote_id"); String serviceUuid = (String) data.get("service_uuid"); - int serviceInstanceId = (int) data.get("service_instance_id"); + int serviceIndex = (int) data.get("service_index"); String secondaryServiceUuid = (String) data.get("secondary_service_uuid"); - Integer secondaryServiceInstanceId = (Integer) data.get("secondary_service_instance_id"); + Integer secondaryServiceIndex = (Integer) data.get("secondary_service_index"); String characteristicUuid = (String) data.get("characteristic_uuid"); - int characteristicInstanceId = (int) data.get("characteristic_instance_id"); + int characteristicIndex = (int) data.get("characteristic_index"); // check connection BluetoothGatt gatt = mConnectedDevices.get(remoteId); @@ -852,7 +852,7 @@ public void onMethodCall(@NonNull MethodCall call, waitIfBonding(); // find characteristic - ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceInstanceId, secondaryServiceUuid, secondaryServiceInstanceId, characteristicUuid, characteristicInstanceId); + ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceIndex, secondaryServiceUuid, secondaryServiceIndex, characteristicUuid, characteristicIndex); if (found.error != null) { result.error("readCharacteristic", found.error, null); break; @@ -884,11 +884,11 @@ public void onMethodCall(@NonNull MethodCall call, HashMap data = call.arguments(); String remoteId = (String) data.get("remote_id"); String serviceUuid = (String) data.get("service_uuid"); - int serviceInstanceId = (int) data.get("service_instance_id"); + int serviceIndex = (int) data.get("service_index"); String secondaryServiceUuid = (String) data.get("secondary_service_uuid"); - Integer secondaryServiceInstanceId = (Integer) data.get("secondary_service_instance_id"); + Integer secondaryServiceIndex = (Integer) data.get("secondary_service_index"); String characteristicUuid = (String) data.get("characteristic_uuid"); - int characteristicInstanceId = (int) data.get("characteristic_instance_id"); + int characteristicIndex = (int) data.get("characteristic_index"); String value = (String) data.get("value"); int writeTypeInt = (int) data.get("write_type"); boolean allowLongWrite = ((int) data.get("allow_long_write")) != 0; @@ -908,7 +908,7 @@ public void onMethodCall(@NonNull MethodCall call, waitIfBonding(); // find characteristic - ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceInstanceId, secondaryServiceUuid, secondaryServiceInstanceId, characteristicUuid, characteristicInstanceId); + ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceIndex, secondaryServiceUuid, secondaryServiceIndex, characteristicUuid, characteristicIndex); if (found.error != null) { result.error("writeCharacteristic", found.error, null); break; @@ -984,11 +984,11 @@ public void onMethodCall(@NonNull MethodCall call, HashMap data = call.arguments(); String remoteId = (String) data.get("remote_id"); String serviceUuid = (String) data.get("service_uuid"); - int serviceInstanceId = (int) data.get("service_instance_id"); + int serviceIndex = (int) data.get("service_index"); String secondaryServiceUuid = (String) data.get("secondary_service_uuid"); - Integer secondaryServiceInstanceId = (Integer) data.get("secondary_service_instance_id"); + Integer secondaryServiceIndex = (Integer) data.get("secondary_service_index"); String characteristicUuid = (String) data.get("characteristic_uuid"); - int characteristicInstanceId = (int) data.get("characteristic_instance_id"); + int characteristicIndex = (int) data.get("characteristic_index"); String descriptorUuid = (String) data.get("descriptor_uuid"); // check connection @@ -1002,7 +1002,7 @@ public void onMethodCall(@NonNull MethodCall call, waitIfBonding(); // find characteristic - ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceInstanceId, secondaryServiceUuid, secondaryServiceInstanceId, characteristicUuid, characteristicInstanceId); + ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceIndex, secondaryServiceUuid, secondaryServiceIndex, characteristicUuid, characteristicIndex); if (found.error != null) { result.error("readDescriptor", found.error, null); break; @@ -1034,11 +1034,11 @@ public void onMethodCall(@NonNull MethodCall call, HashMap data = call.arguments(); String remoteId = (String) data.get("remote_id"); String serviceUuid = (String) data.get("service_uuid"); - int serviceInstanceId = (int) data.get("service_instance_id"); + int serviceIndex = (int) data.get("service_index"); String secondaryServiceUuid = (String) data.get("secondary_service_uuid"); - Integer secondaryServiceInstanceId = (Integer) data.get("secondary_service_instance_id"); + Integer secondaryServiceIndex = (Integer) data.get("secondary_service_index"); String characteristicUuid = (String) data.get("characteristic_uuid"); - int characteristicInstanceId = (int) data.get("characteristic_instance_id"); + int characteristicIndex = (int) data.get("characteristic_index"); String descriptorUuid = (String) data.get("descriptor_uuid"); String value = (String) data.get("value"); @@ -1054,7 +1054,7 @@ public void onMethodCall(@NonNull MethodCall call, waitIfBonding(); // find characteristic - ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceInstanceId, secondaryServiceUuid, secondaryServiceInstanceId, characteristicUuid, characteristicInstanceId); + ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceIndex, secondaryServiceUuid, secondaryServiceIndex, characteristicUuid, characteristicIndex); if (found.error != null) { result.error("writeDescriptor", found.error, null); break; @@ -1118,11 +1118,11 @@ public void onMethodCall(@NonNull MethodCall call, HashMap data = call.arguments(); String remoteId = (String) data.get("remote_id"); String serviceUuid = (String) data.get("service_uuid"); - int serviceInstanceId = (int) data.get("service_instance_id"); + int serviceIndex = (int) data.get("service_index"); String secondaryServiceUuid = (String) data.get("secondary_service_uuid"); - Integer secondaryServiceInstanceId = (Integer) data.get("secondary_service_instance_id"); + Integer secondaryServiceIndex = (Integer) data.get("secondary_service_index"); String characteristicUuid = (String) data.get("characteristic_uuid"); - int characteristicInstanceId = (int) data.get("characteristic_instance_id"); + int characteristicIndex = (int) data.get("characteristic_index"); boolean forceIndications = (boolean) data.get("force_indications"); boolean enable = (boolean) data.get("enable"); @@ -1137,7 +1137,7 @@ public void onMethodCall(@NonNull MethodCall call, waitIfBonding(); // find characteristic - ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceInstanceId, secondaryServiceUuid, secondaryServiceInstanceId, characteristicUuid, characteristicInstanceId); + ChrFound found = locateCharacteristic(gatt, serviceUuid, serviceIndex, secondaryServiceUuid, secondaryServiceIndex, characteristicUuid, characteristicIndex); if (found.error != null) { result.error("setNotifyValue", found.error, null); break; @@ -1627,14 +1627,14 @@ public ChrFound(BluetoothGattCharacteristic characteristic, String error) { private ChrFound locateCharacteristic(BluetoothGatt gatt, String serviceId, - int serviceInstanceId, + int serviceIndex, String secondaryServiceId, - Integer secondaryServiceInstanceId, + Integer secondaryServiceIndex, String characteristicId, - int characteristicInstanceId) + int characteristicIndex) { // primary - BluetoothGattService primaryService = getServiceFromArray(serviceId, serviceInstanceId, gatt.getServices()); + BluetoothGattService primaryService = getServiceFromArray(serviceId, serviceIndex, gatt.getServices()); if(primaryService == null) { return new ChrFound(null, "service not found '" + serviceId + "'"); } @@ -1642,7 +1642,7 @@ private ChrFound locateCharacteristic(BluetoothGatt gatt, // secondary BluetoothGattService secondaryService = null; if(secondaryServiceId != null && secondaryServiceId.length() > 0) { - secondaryService = getServiceFromArray(secondaryServiceId, secondaryServiceInstanceId, primaryService.getIncludedServices()); + secondaryService = getServiceFromArray(secondaryServiceId, secondaryServiceIndex, primaryService.getIncludedServices()); if(secondaryService == null) { return new ChrFound(null, "secondaryService not found '" + secondaryServiceId + "'"); } @@ -1652,7 +1652,7 @@ private ChrFound locateCharacteristic(BluetoothGatt gatt, BluetoothGattService service = (secondaryService != null) ? secondaryService : primaryService; // characteristic - BluetoothGattCharacteristic characteristic = getCharacteristicFromArray(characteristicId, characteristicInstanceId, service.getCharacteristics()); + BluetoothGattCharacteristic characteristic = getCharacteristicFromArray(characteristicId, characteristicIndex, service.getCharacteristics()); if(characteristic == null) { return new ChrFound(null, "characteristic not found in service " + "(chr: '" + characteristicId + "' svc: '" + serviceId + "')"); @@ -1661,20 +1661,20 @@ private ChrFound locateCharacteristic(BluetoothGatt gatt, return new ChrFound(characteristic, null); } - private BluetoothGattService getServiceFromArray(String uuid, int instanceId, List array) + private BluetoothGattService getServiceFromArray(String uuid, int index, List array) { for (BluetoothGattService s : array) { - if (uuid128(s.getUuid()).equals(uuid128(uuid)) && s.getInstanceId() == instanceId) { + if (uuid128(s.getUuid()).equals(uuid128(uuid)) && s.getInstanceId() == index) { return s; } } return null; } - private BluetoothGattCharacteristic getCharacteristicFromArray(String uuid, int instanceId, List array) + private BluetoothGattCharacteristic getCharacteristicFromArray(String uuid, int index, List array) { for (BluetoothGattCharacteristic c : array) { - if (uuid128(c.getUuid()).equals(uuid128(uuid)) && c.getInstanceId() == instanceId) { + if (uuid128(c.getUuid()).equals(uuid128(uuid)) && c.getInstanceId() == index) { return c; } } @@ -2285,13 +2285,13 @@ public void onCharacteristicReceived(BluetoothGatt gatt, BluetoothGattCharacteri HashMap response = new HashMap<>(); response.put("remote_id", gatt.getDevice().getAddress()); response.put("service_uuid", uuidStr(pair.primary.getUuid())); - response.put("service_instance_id", pair.primary.getInstanceId()); + response.put("service_index", pair.primary.getInstanceId()); if (pair.secondary != null) { response.put("secondary_service_uuid", uuidStr(pair.secondary.getUuid())); - response.put("secondary_service_instance_id", pair.secondary.getInstanceId()); + response.put("secondary_service_index", pair.secondary.getInstanceId()); } response.put("characteristic_uuid", uuidStr(characteristic.getUuid())); - response.put("characteristic_instance_id", characteristic.getInstanceId()); + response.put("characteristic_index", characteristic.getInstanceId()); response.put("value", bytesToHex(value)); response.put("success", status == BluetoothGatt.GATT_SUCCESS ? 1 : 0); response.put("error_code", status); @@ -2341,11 +2341,11 @@ public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristi // for convenience String remoteId = gatt.getDevice().getAddress(); String serviceUuid = uuidStr(pair.primary.getUuid()); - int serviceInstanceId = pair.primary.getInstanceId(); + int serviceIndex = pair.primary.getInstanceId(); String secondaryServiceUuid = pair.secondary != null ? uuidStr(pair.secondary.getUuid()) : null; - Integer secondaryServiceInstanceId = pair.secondary != null ? pair.secondary.getInstanceId() : null; + Integer secondaryServiceIndex = pair.secondary != null ? pair.secondary.getInstanceId() : null; String characteristicUuid = uuidStr(characteristic.getUuid()); - int characteristicInstanceId = characteristic.getInstanceId(); + int characteristicIndex = characteristic.getInstanceId(); // what data did we write? String key = remoteId + ":" + serviceUuid + ":" + characteristicUuid; @@ -2356,13 +2356,13 @@ public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristi HashMap response = new HashMap<>(); response.put("remote_id", remoteId); response.put("service_uuid", serviceUuid); - response.put("service_instance_id", serviceInstanceId); + response.put("service_index", serviceIndex); if (secondaryServiceUuid != null) { response.put("secondary_service_uuid", secondaryServiceUuid); - response.put("secondary_service_instance_id", secondaryServiceInstanceId); + response.put("secondary_service_index", secondaryServiceIndex); } response.put("characteristic_uuid", characteristicUuid); - response.put("characteristic_instance_id", characteristicInstanceId); + response.put("characteristic_index", characteristicIndex); response.put("value", value); response.put("success", status == BluetoothGatt.GATT_SUCCESS ? 1 : 0); response.put("error_code", status); @@ -2387,13 +2387,13 @@ public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descrip HashMap response = new HashMap<>(); response.put("remote_id", gatt.getDevice().getAddress()); response.put("service_uuid", uuidStr(pair.primary.getUuid())); - response.put("service_instance_id", pair.primary.getInstanceId()); + response.put("service_index", pair.primary.getInstanceId()); if (pair.secondary != null) { response.put("secondary_service_uuid", uuidStr(pair.secondary.getUuid())); - response.put("secondary_service_instance_id", pair.secondary.getInstanceId()); + response.put("secondary_service_index", pair.secondary.getInstanceId()); } response.put("characteristic_uuid", uuidStr(descriptor.getCharacteristic().getUuid())); - response.put("characteristic_instance_id", descriptor.getCharacteristic().getInstanceId()); + response.put("characteristic_index", descriptor.getCharacteristic().getInstanceId()); response.put("descriptor_uuid", uuidStr(descriptor.getUuid())); response.put("value", bytesToHex(value)); response.put("success", status == BluetoothGatt.GATT_SUCCESS ? 1 : 0); @@ -2417,11 +2417,11 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri // for convenience String remoteId = gatt.getDevice().getAddress(); String serviceUuid = uuidStr(pair.primary.getUuid()); - int serviceInstanceId = pair.primary.getInstanceId(); + int serviceIndex = pair.primary.getInstanceId(); String secondaryServiceUuid = pair.secondary != null ? uuidStr(pair.secondary.getUuid()) : null; - Integer secondaryServiceInstanceId = pair.secondary != null ? pair.secondary.getInstanceId() : null; + Integer secondaryServiceIndex = pair.secondary != null ? pair.secondary.getInstanceId() : null; String characteristicUuid = uuidStr(descriptor.getCharacteristic().getUuid()); - int characteristicInstanceId = descriptor.getCharacteristic().getInstanceId(); + int characteristicIndex = descriptor.getCharacteristic().getInstanceId(); String descriptorUuid = uuidStr(descriptor.getUuid()); // what data did we write? @@ -2433,13 +2433,13 @@ public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descri HashMap response = new HashMap<>(); response.put("remote_id", remoteId); response.put("service_uuid", serviceUuid); - response.put("service_instance_id", serviceInstanceId); + response.put("service_index", serviceIndex); if (secondaryServiceUuid != null) { response.put("secondary_service_uuid", secondaryServiceUuid); - response.put("secondary_service_instance_id", secondaryServiceInstanceId); + response.put("secondary_service_index", secondaryServiceIndex); } response.put("characteristic_uuid", characteristicUuid); - response.put("characteristic_instance_id", characteristicInstanceId); + response.put("characteristic_index", characteristicIndex); response.put("descriptor_uuid", descriptorUuid); response.put("value", value); response.put("success", status == BluetoothGatt.GATT_SUCCESS ? 1 : 0); @@ -2638,7 +2638,7 @@ HashMap bmBluetoothService(BluetoothDevice device, BluetoothGatt HashMap map = new HashMap<>(); map.put("remote_id", device.getAddress()); map.put("service_uuid", uuidStr(service.getUuid())); - map.put("service_instance_id", service.getInstanceId()); + map.put("service_index", service.getInstanceId()); map.put("is_primary", service.getType() == BluetoothGattService.SERVICE_TYPE_PRIMARY ? 1 : 0); map.put("characteristics", characteristics); map.put("included_services", includedServices); @@ -2658,13 +2658,13 @@ HashMap bmBluetoothCharacteristic(BluetoothDevice device, Blueto HashMap map = new HashMap<>(); map.put("remote_id", device.getAddress()); map.put("service_uuid", uuidStr(pair.primary.getUuid())); - map.put("service_instance_id", pair.primary.getInstanceId()); + map.put("service_index", pair.primary.getInstanceId()); if (pair.secondary != null) { map.put("secondary_service_uuid", uuidStr(pair.secondary.getUuid())); - map.put("secondary_service_instance_id", pair.secondary.getInstanceId()); + map.put("secondary_service_index", pair.secondary.getInstanceId()); } map.put("characteristic_uuid", uuidStr(characteristic.getUuid())); - map.put("characteristic_instance_id", characteristic.getInstanceId()); + map.put("characteristic_index", characteristic.getInstanceId()); map.put("descriptors", descriptors); map.put("properties", bmCharacteristicProperties(characteristic.getProperties())); return map; @@ -2676,9 +2676,9 @@ HashMap bmBluetoothDescriptor(BluetoothDevice device, BluetoothG map.put("remote_id", device.getAddress()); map.put("descriptor_uuid", uuidStr(descriptor.getUuid())); map.put("characteristic_uuid", uuidStr(descriptor.getCharacteristic().getUuid())); - map.put("characteristic_instance_id", descriptor.getCharacteristic().getInstanceId()); + map.put("characteristic_index", descriptor.getCharacteristic().getInstanceId()); map.put("service_uuid", uuidStr(descriptor.getCharacteristic().getService().getUuid())); - map.put("service_instance_id", descriptor.getCharacteristic().getService().getInstanceId()); + map.put("service_index", descriptor.getCharacteristic().getService().getInstanceId()); return map; } diff --git a/ios/Classes/FlutterBluePlusPlugin.m b/ios/Classes/FlutterBluePlusPlugin.m index bfe090e8..f72afc45 100644 --- a/ios/Classes/FlutterBluePlusPlugin.m +++ b/ios/Classes/FlutterBluePlusPlugin.m @@ -458,11 +458,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSDictionary *args = (NSDictionary*)call.arguments; NSString *remoteId = args[@"remote_id"]; NSString *characteristicUuid = args[@"characteristic_uuid"]; - NSUInteger *characteristicInstanceId = [args[@"characteristic_instance_id"] unsignedIntegerValue]; + NSUInteger *characteristicIndex = [args[@"characteristic_index"] unsignedIntegerValue]; NSString *serviceUuid = args[@"service_uuid"]; - NSUInteger *serviceInstanceId = [args[@"service_instance_id"] unsignedIntegerValue]; + NSUInteger *serviceIndex = [args[@"service_index"] unsignedIntegerValue]; NSString *secondaryServiceUuid = args[@"secondary_service_uuid"]; - NSUInteger *secondaryServiceInstanceId = [args[@"secondary_service_instance_id"] unsignedIntegerValue]; + NSUInteger *secondaryServiceIndex = [args[@"secondary_service_index"] unsignedIntegerValue]; // Find peripheral CBPeripheral *peripheral = [self getConnectedPeripheral:remoteId]; @@ -475,12 +475,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Find characteristic NSError *error = nil; CBCharacteristic *characteristic = [self locateCharacteristic:characteristicUuid - characteristicInstanceId:characteristicInstanceId + characteristicIndex:characteristicIndex peripheral:peripheral - serviceId:serviceUuid - serviceInstanceId:serviceInstanceId - secondaryServiceId:secondaryServiceUuid - secondaryServiceInstanceId:secondaryServiceInstanceId + serviceId:serviceUuid + serviceIndex:serviceIndex + secondaryServiceId:secondaryServiceUuid + secondaryServiceIndex:secondaryServiceIndex error:&error]; if (characteristic == nil) { result([FlutterError errorWithCode:@"readCharacteristic" message:error.localizedDescription details:NULL]); @@ -505,11 +505,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSDictionary *args = (NSDictionary*)call.arguments; NSString *remoteId = args[@"remote_id"]; NSString *characteristicUuid = args[@"characteristic_uuid"]; - NSUInteger *characteristicInstanceId = [args[@"characteristic_instance_id"] unsignedIntegerValue]; + NSUInteger *characteristicIndex = [args[@"characteristic_index"] unsignedIntegerValue]; NSString *serviceUuid = args[@"service_uuid"]; - NSUInteger *serviceInstanceId = [args[@"service_instance_id"] unsignedIntegerValue]; + NSUInteger *serviceIndex = [args[@"service_index"] unsignedIntegerValue]; NSString *secondaryServiceUuid = args[@"secondary_service_uuid"]; - NSUInteger *secondaryServiceInstanceId = [args[@"secondary_service_instance_id"] unsignedIntegerValue]; + NSUInteger *secondaryServiceIndex = [args[@"secondary_service_index"] unsignedIntegerValue]; NSNumber *writeTypeNumber = args[@"write_type"]; NSNumber *allowLongWrite = args[@"allow_long_write"]; NSString *value = args[@"value"]; @@ -552,12 +552,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Find characteristic NSError *error = nil; CBCharacteristic *characteristic = [self locateCharacteristic:characteristicUuid - characteristicInstanceId:characteristicInstanceId + characteristicIndex:characteristicIndex peripheral:peripheral - serviceId:serviceUuid - serviceInstanceId:serviceInstanceId - secondaryServiceId:secondaryServiceUuid - secondaryServiceInstanceId:secondaryServiceInstanceId + serviceId:serviceUuid + serviceIndex:serviceIndex + secondaryServiceId:secondaryServiceUuid + secondaryServiceIndex:secondaryServiceIndex error:&error]; if (characteristic == nil) { result([FlutterError errorWithCode:@"writeCharacteristic" message:error.localizedDescription details:NULL]); @@ -600,9 +600,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSString *remoteId = args[@"remote_id"]; NSString *descriptorUuid = args[@"descriptor_uuid"]; NSString *serviceUuid = args[@"service_uuid"]; - NSUInteger *serviceInstanceId = [args[@"service_instance_id"] unsignedIntegerValue]; + NSUInteger *serviceIndex = [args[@"service_index"] unsignedIntegerValue]; NSString *secondaryServiceUuid = args[@"secondary_service_uuid"]; - NSUInteger *secondaryServiceInstanceId = [args[@"secondary_service_instance_id"] unsignedIntegerValue]; + NSUInteger *secondaryServiceIndex = [args[@"secondary_service_index"] unsignedIntegerValue]; NSString *characteristicUuid = args[@"characteristic_uuid"]; // Find peripheral @@ -615,13 +615,13 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Find characteristic NSError *error = nil; - CBCharacteristic *characteristic = [self locateCharacteristic:characteristicUuid - characteristicInstanceId:characteristicInstanceId + CBCharacteristic *characteristic = [self locateCharacteristic:characteristicUuid + characteristicIndex:characteristicIndex peripheral:peripheral - serviceId:serviceUuid - serviceInstanceId:serviceInstanceId - secondaryServiceId:secondaryServiceUuid - secondaryServiceInstanceId:secondaryServiceInstanceId + serviceId:serviceUuid + serviceIndex:serviceIndex + secondaryServiceId:secondaryServiceUuid + secondaryServiceIndex:secondaryServiceIndex error:&error]; if (characteristic == nil) { result([FlutterError errorWithCode:@"readDescriptor" message:error.localizedDescription details:NULL]); @@ -646,11 +646,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSString *remoteId = args[@"remote_id"]; NSString *descriptorUuid = args[@"descriptor_uuid"]; NSString *serviceUuid = args[@"service_uuid"]; - NSUInteger *serviceInstanceId = [args[@"service_instance_id"] unsignedIntegerValue]; + NSUInteger *serviceIndex = [args[@"service_index"] unsignedIntegerValue]; NSString *secondaryServiceUuid = args[@"secondary_service_uuid"]; - NSUInteger *secondaryServiceInstanceId = [args[@"secondary_service_instance_id"] unsignedIntegerValue]; + NSUInteger *secondaryServiceIndex = [args[@"secondary_service_index"] unsignedIntegerValue]; NSString *characteristicUuid = args[@"characteristic_uuid"]; - NSUInteger *characteristicInstanceId = [args[@"characteristic_instance_id"] unsignedIntegerValue]; + NSUInteger *characteristicIndex = [args[@"characteristic_index"] unsignedIntegerValue]; NSString *value = args[@"value"]; // Find peripheral @@ -674,12 +674,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Find characteristic NSError *error = nil; CBCharacteristic *characteristic = [self locateCharacteristic:characteristicUuid - characteristicInstanceId:characteristicInstanceId + characteristicIndex:characteristicIndex peripheral:peripheral - serviceId:serviceUuid - serviceInstanceId:serviceInstanceId - secondaryServiceId:secondaryServiceUuid - secondaryServiceInstanceId:secondaryServiceInstanceId + serviceId:serviceUuid + serviceIndex:serviceIndex + secondaryServiceId:secondaryServiceUuid + secondaryServiceIndex:secondaryServiceIndex error:&error]; if (characteristic == nil) { result([FlutterError errorWithCode:@"writeDescriptor" message:error.localizedDescription details:NULL]); @@ -708,11 +708,11 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result NSDictionary *args = (NSDictionary*)call.arguments; NSString *remoteId = args[@"remote_id"]; NSString *serviceUuid = args[@"service_uuid"]; - NSUInteger *serviceInstanceId = [args[@"service_instance_id"] unsignedIntegerValue]; + NSUInteger *serviceIndex = [args[@"service_index"] unsignedIntegerValue]; NSString *secondaryServiceUuid = args[@"secondary_service_uuid"]; - NSUInteger *secondaryServiceInstanceId = [args[@"secondary_service_instance_id"] unsignedIntegerValue]; + NSUInteger *secondaryServiceIndex = [args[@"secondary_service_index"] unsignedIntegerValue]; NSString *characteristicUuid = args[@"characteristic_uuid"]; - NSUInteger *characteristicInstanceId = [args[@"characteristic_instance_id"] unsignedIntegerValue]; + NSUInteger *characteristicIndex = [args[@"characteristic_index"] unsignedIntegerValue]; NSNumber *enable = args[@"enable"]; // Find peripheral @@ -726,12 +726,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Find characteristic NSError *error = nil; CBCharacteristic *characteristic = [self locateCharacteristic:characteristicUuid - characteristicInstanceId:characteristicInstanceId + characteristicIndex:characteristicIndex peripheral:peripheral - serviceId:serviceUuid - serviceInstanceId:serviceInstanceId - secondaryServiceId:secondaryServiceUuid - secondaryServiceInstanceId:secondaryServiceInstanceId + serviceId:serviceUuid + serviceIndex:serviceIndex + secondaryServiceId:secondaryServiceUuid + secondaryServiceIndex:secondaryServiceIndex error:&error]; if (characteristic == nil) { result([FlutterError errorWithCode:@"setNotifyValue" message:error.localizedDescription details:NULL]); @@ -854,17 +854,17 @@ - (CBPeripheral *)getConnectedPeripheral:(NSString *)remoteId return [self.connectedPeripherals objectForKey:remoteId]; } -- (CBCharacteristic *)locateCharacteristic:(NSString *)characteristicId - characteristicInstanceId:(NSUInteger *)characteristicInstanceId +- (CBCharacteristic *)locateCharacteristic:(NSString *)characteristicId + characteristicIndex:(NSUInteger *)characteristicIndex peripheral:(CBPeripheral *)peripheral - serviceId:(NSString *)serviceId - serviceInstanceId:(NSUInteger *)serviceInstanceId - secondaryServiceId:(NSString *)secondaryServiceId - secondaryServiceInstanceId:(NSUInteger *)secondaryServiceInstanceId + serviceId:(NSString *)serviceId + serviceIndex:(NSUInteger *)serviceIndex + secondaryServiceId:(NSString *)secondaryServiceId + secondaryServiceIndex:(NSUInteger *)secondaryServiceIndex error:(NSError **)error { // primary - CBService *primaryService = [self getServiceFromArray:serviceId instanceId:serviceInstanceId array:[peripheral services]]; + CBService *primaryService = [self getServiceFromArray:serviceId index:serviceIndex array:[peripheral services]]; if (primaryService == nil || [primaryService isPrimary] == false) { NSString* s = [NSString stringWithFormat:@"service not found '%@'", serviceId]; @@ -877,7 +877,7 @@ - (CBCharacteristic *)locateCharacteristic:(NSString *)characteristicId CBService *secondaryService; if (secondaryServiceId && (NSNull*) secondaryServiceId != [NSNull null] && secondaryServiceId.length) { - secondaryService = [self getServiceFromArray:secondaryServiceId instanceId:secondaryServiceInstanceId array:[primaryService includedServices]]; + secondaryService = [self getServiceFromArray:secondaryServiceId index:secondaryServiceIndex array:[primaryService includedServices]]; if (error && !secondaryService) { NSString* s = [NSString stringWithFormat:@"secondaryService not found '%@'", secondaryServiceId]; NSDictionary* d = @{NSLocalizedDescriptionKey : s}; @@ -890,7 +890,7 @@ - (CBCharacteristic *)locateCharacteristic:(NSString *)characteristicId CBService *service = (secondaryService != nil) ? secondaryService : primaryService; // characteristic - CBCharacteristic *characteristic = [self getCharacteristicFromArray:characteristicId instanceId:characteristicInstanceId array:[service characteristics]]; + CBCharacteristic *characteristic = [self getCharacteristicFromArray:characteristicId index:characteristicIndex array:[service characteristics]]; if (characteristic == nil) { NSString* format = @"characteristic not found in service (chr: '%@', svc: '%@')"; @@ -917,12 +917,12 @@ - (CBDescriptor *)locateDescriptor:(NSString *)descriptorId characteristic:(CBCh return descriptor; } -- (CBService *)getServiceFromArray:(NSString *)uuid instanceId:(NSUInteger *)instanceId array:(NSArray *)array +- (CBService *)getServiceFromArray:(NSString *)uuid index:(NSUInteger *)index array:(NSArray *)array { for (CBService *s in array) { - // Use hash as instanceId - if ([s.UUID isEqual:[CBUUID UUIDWithString:uuid]] && s.hash == instanceId) + // Use hash as index + if ([s.UUID isEqual:[CBUUID UUIDWithString:uuid]] && s.hash == index) { return s; } @@ -930,11 +930,11 @@ - (CBService *)getServiceFromArray:(NSString *)uuid instanceId:(NSUInteger *)ins return nil; } -- (CBCharacteristic *)getCharacteristicFromArray:(NSString *)uuid instanceId:(NSUInteger *)instanceId array:(NSArray *)array +- (CBCharacteristic *)getCharacteristicFromArray:(NSString *)uuid index:(NSUInteger *)index array:(NSArray *)array { for (CBCharacteristic *c in array) { - if ([c.UUID isEqual:[CBUUID UUIDWithString:uuid]] && c.hash == instanceId) + if ([c.UUID isEqual:[CBUUID UUIDWithString:uuid]] && c.hash == index) { return c; } @@ -1471,11 +1471,11 @@ - (void)peripheral:(CBPeripheral *)peripheral NSDictionary* result = @{ @"remote_id": [peripheral.identifier UUIDString], @"service_uuid": [pair.primary.UUID uuidStr], - @"service_instance_id": pair.primary.hash, + @"service_index": pair.primary.hash, @"secondary_service_uuid": pair.secondary ? [pair.secondary.UUID uuidStr] : [NSNull null], - @"secondary_service_instance_id": pair.secondary ? pair.secondary.hash : [NSNull null], + @"secondary_service_index": pair.secondary ? pair.secondary.hash : [NSNull null], @"characteristic_uuid": [characteristic.UUID uuidStr], - @"characteristic_instance_id": characteristic.hash, + @"characteristic_index": characteristic.hash, @"value": [self convertDataToHex:characteristic.value], @"success": error == nil ? @(1) : @(0), @"error_string": error ? [error localizedDescription] : @"success", @@ -1516,11 +1516,11 @@ - (void)peripheral:(CBPeripheral *)peripheral NSDictionary* result = @{ @"remote_id": remoteId, @"service_uuid": serviceUuid, - @"service_instance_id": pair.primary.hash, + @"service_index": pair.primary.hash, @"secondary_service_uuid": pair.secondary ? secondaryServiceUuid : [NSNull null], - @"secondary_service_instance_id": pair.secondary ? pair.secondary.hash : [NSNull null], + @"secondary_service_index": pair.secondary ? pair.secondary.hash : [NSNull null], @"characteristic_uuid": characteristicUuid, - @"characteristic_instance_id": characteristic.hash, + @"characteristic_index": characteristic.hash, @"value": value, @"success": @(error == nil), @"error_string": error ? [error localizedDescription] : @"success", @@ -1562,11 +1562,11 @@ - (void)peripheral:(CBPeripheral *)peripheral NSDictionary* result = @{ @"remote_id": [peripheral.identifier UUIDString], @"service_uuid": [pair.primary.UUID uuidStr], - @"service_instance_id": pair.primary.hash, + @"service_index": pair.primary.hash, @"secondary_service_uuid": pair.secondary ? [pair.secondary.UUID uuidStr] : [NSNull null], - @"secondary_service_instance_id": pair.secondary ? pair.secondary.hash : [NSNull null], + @"secondary_service_index": pair.secondary ? pair.secondary.hash : [NSNull null], @"characteristic_uuid": [characteristic.UUID uuidStr], - @"characteristic_instance_id": characteristic.hash, + @"characteristic_index": characteristic.hash, @"descriptor_uuid": CCCD, @"value": [self convertDataToHex:[NSData dataWithBytes:&value length:sizeof(value)]], @"success": @(error == nil), @@ -1600,11 +1600,11 @@ - (void)peripheral:(CBPeripheral *)peripheral NSDictionary* result = @{ @"remote_id": [peripheral.identifier UUIDString], @"service_uuid": [pair.primary.UUID uuidStr], - @"service_instance_id": pair.primary.hash, + @"service_index": pair.primary.hash, @"secondary_service_uuid": pair.secondary ? [pair.secondary.UUID uuidStr] : [NSNull null], - @"secondary_service_instance_id": pair.secondary ? pair.secondary.hash : [NSNull null], + @"secondary_service_index": pair.secondary ? pair.secondary.hash : [NSNull null], @"characteristic_uuid": [descriptor.characteristic.UUID uuidStr], - @"characteristic_instance_id": descriptor.characteristic.hash, + @"characteristic_index": descriptor.characteristic.hash, @"descriptor_uuid": [descriptor.UUID uuidStr], @"value": [self convertDataToHex:data], @"success": @(error == nil), @@ -1648,11 +1648,11 @@ - (void)peripheral:(CBPeripheral *)peripheral NSDictionary* result = @{ @"remote_id": remoteId, @"service_uuid": serviceUuid, - @"service_instance_id": pair.primary.hash, + @"service_index": pair.primary.hash, @"secondary_service_uuid": pair.secondary ? secondaryServiceUuid : [NSNull null], - @"secondary_service_instance_id": pair.secondary ? pair.secondary.hash : [NSNull null], + @"secondary_service_index": pair.secondary ? pair.secondary.hash : [NSNull null], @"characteristic_uuid": characteristicUuid, - @"characteristic_instance_id": descriptor.characteristic.hash, + @"characteristic_index": descriptor.characteristic.hash, @"descriptor_uuid": descriptorUuid, @"value": value, @"success": @(error == nil), @@ -1725,11 +1725,11 @@ - (void)peripheralIsReadyToSendWriteWithoutResponse:(CBPeripheral *)peripheral // See BmWriteCharacteristicRequest NSString *characteristicUuid = request[@"characteristic_uuid"]; - NSUInteger *characteristicInstanceId = [request[@"characteristic_instance_id"] unsignedIntegerValue]; + NSUInteger *characteristicIndex = [request[@"characteristic_index"] unsignedIntegerValue]; NSString *serviceUuid = request[@"service_uuid"]; - NSUInteger *serviceInstanceId = [request[@"service_instance_id"] unsignedIntegerValue]; + NSUInteger *serviceIndex = [request[@"service_index"] unsignedIntegerValue]; NSString *secondaryServiceUuid = request[@"secondary_service_uuid"]; - NSUInteger *secondaryServiceInstanceId = [request[@"secondary_service_instance_id"] unsignedIntegerValue]; + NSUInteger *secondaryServiceIndex = [request[@"secondary_service_index"] unsignedIntegerValue]; NSString *value = request[@"value"]; // Find characteristic @@ -1737,9 +1737,9 @@ - (void)peripheralIsReadyToSendWriteWithoutResponse:(CBPeripheral *)peripheral CBCharacteristic *characteristic = [self locateCharacteristic:characteristicUuid peripheral:peripheral serviceId:serviceUuid - serviceInstanceId:serviceInstanceId + serviceIndex:serviceIndex secondaryServiceId:secondaryServiceUuid - secondaryServiceInstanceId:secondaryServiceInstanceId + secondaryServiceIndex:secondaryServiceIndex error:&error]; if (characteristic == nil) { Log(LERROR, @"Error: peripheralIsReadyToSendWriteWithoutResponse: %@", [error localizedDescription]); @@ -1752,11 +1752,11 @@ - (void)peripheralIsReadyToSendWriteWithoutResponse:(CBPeripheral *)peripheral NSDictionary* result = @{ @"remote_id": [peripheral.identifier UUIDString], @"service_uuid": [pair.primary.UUID uuidStr], - @"service_instance_id": pair.primary.hash, + @"service_index": pair.primary.hash, @"secondary_service_uuid": pair.secondary ? [pair.secondary.UUID uuidStr] : [NSNull null], - @"secondary_service_instance_id": pair.secondary ? pair.secondary.hash : [NSNull null], + @"secondary_service_index": pair.secondary ? pair.secondary.hash : [NSNull null], @"characteristic_uuid": [characteristic.UUID uuidStr], - @"characteristic_instance_id": characteristic.hash, + @"characteristic_index": characteristic.hash, @"value": value, @"success": @(error == nil), @"error_string": error ? [error localizedDescription] : @"success", @@ -1909,7 +1909,7 @@ - (NSDictionary *)bmBluetoothService:(CBPeripheral *)peripheral service:(CBServi return @{ @"remote_id": [peripheral.identifier UUIDString], @"service_uuid": [service.UUID uuidStr], - @"service_instance_id": service.hash, + @"service_index": service.hash, @"characteristics": characteristicProtos, @"is_primary": @([service isPrimary]), @"included_services": includedServicesProtos, @@ -1927,11 +1927,11 @@ - (NSDictionary*)bmBluetoothCharacteristic:(CBPeripheral *)peripheral NSDictionary* desc = @{ @"remote_id": [peripheral.identifier UUIDString], @"service_uuid": [d.characteristic.service.UUID uuidStr], - @"service_instance_id": d.characteristic.service.hash, + @"service_index": d.characteristic.service.hash, @"secondary_service_uuid": [NSNull null], - @"secondary_service_instance_id": [NSNull null], + @"secondary_service_index": [NSNull null], @"characteristic_uuid": [d.characteristic.UUID uuidStr], - @"characteristic_instance_id": d.characteristic.hash, + @"characteristic_index": d.characteristic.hash, @"descriptor_uuid": [d.UUID uuidStr], }; @@ -1960,11 +1960,11 @@ - (NSDictionary*)bmBluetoothCharacteristic:(CBPeripheral *)peripheral return @{ @"remote_id": [peripheral.identifier UUIDString], @"service_uuid": [pair.primary.UUID uuidStr], - @"service_instance_id": pair.primary.hash, + @"service_index": pair.primary.hash, @"secondary_service_uuid": pair.secondary ? [pair.secondary.UUID uuidStr] : [NSNull null], - @"secondary_service_instance_id": pair.secondary ? pair.secondary.hash : [NSNull null], + @"secondary_service_index": pair.secondary ? pair.secondary.hash : [NSNull null], @"characteristic_uuid": [characteristic.UUID uuidStr], - @"characteristic_instance_id": characteristic.hash, + @"characteristic_index": characteristic.hash, @"descriptors": descriptors, @"properties": propsMap, }; diff --git a/lib/src/bluetooth_characteristic.dart b/lib/src/bluetooth_characteristic.dart index 206cb65a..46eb1c2d 100644 --- a/lib/src/bluetooth_characteristic.dart +++ b/lib/src/bluetooth_characteristic.dart @@ -9,30 +9,30 @@ final Guid cccdUuid = Guid("00002902-0000-1000-8000-00805f9b34fb"); class BluetoothCharacteristic { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; BluetoothCharacteristic({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, this.secondaryServiceUuid, - this.secondaryServiceInstanceId, + this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, }); BluetoothCharacteristic.fromProto(BmBluetoothCharacteristic p) : remoteId = p.remoteId, serviceUuid = p.serviceUuid, - serviceInstanceId = p.serviceInstanceId, + serviceIndex = p.serviceIndex, secondaryServiceUuid = p.secondaryServiceUuid, - secondaryServiceInstanceId = p.secondaryServiceInstanceId, + secondaryServiceIndex = p.secondaryServiceIndex, characteristicUuid = p.characteristicUuid, - characteristicInstanceId = p.characteristicInstanceId; + characteristicIndex = p.characteristicIndex; /// convenience accessor Guid get uuid => characteristicUuid; @@ -120,11 +120,11 @@ class BluetoothCharacteristic { var request = BmReadCharacteristicRequest( remoteId: remoteId, characteristicUuid: characteristicUuid, - characteristicInstanceId: characteristicInstanceId, + characteristicIndex: characteristicIndex, serviceUuid: serviceUuid, - serviceInstanceId: serviceInstanceId, + serviceIndex: serviceIndex, secondaryServiceUuid: secondaryServiceUuid, - secondaryServiceInstanceId: secondaryServiceInstanceId, + secondaryServiceIndex: secondaryServiceIndex, ); var responseStream = FlutterBluePlus._methodStream.stream @@ -194,11 +194,11 @@ class BluetoothCharacteristic { var request = BmWriteCharacteristicRequest( remoteId: remoteId, characteristicUuid: characteristicUuid, - characteristicInstanceId: characteristicInstanceId, + characteristicIndex: characteristicIndex, serviceUuid: serviceUuid, - serviceInstanceId: serviceInstanceId, + serviceIndex: serviceIndex, secondaryServiceUuid: secondaryServiceUuid, - secondaryServiceInstanceId: secondaryServiceInstanceId, + secondaryServiceIndex: secondaryServiceIndex, writeType: writeType, allowLongWrite: allowLongWrite, value: value, @@ -261,11 +261,11 @@ class BluetoothCharacteristic { var request = BmSetNotifyValueRequest( remoteId: remoteId, serviceUuid: serviceUuid, - serviceInstanceId: serviceInstanceId, + serviceIndex: serviceIndex, secondaryServiceUuid: secondaryServiceUuid, - secondaryServiceInstanceId: secondaryServiceInstanceId, + secondaryServiceIndex: secondaryServiceIndex, characteristicUuid: characteristicUuid, - characteristicInstanceId: characteristicInstanceId, + characteristicIndex: characteristicIndex, forceIndications: forceIndications, enable: notify, ); @@ -310,11 +310,11 @@ class BluetoothCharacteristic { BmBluetoothService? get _bmsvc { if (FlutterBluePlus._knownServices[remoteId] != null) { for (var s in FlutterBluePlus._knownServices[remoteId]!.services) { - if (s.serviceUuid == serviceUuid && s.serviceInstanceId == serviceInstanceId) { + if (s.serviceUuid == serviceUuid && s.serviceIndex == serviceIndex) { if (secondaryServiceUuid != null) { // search includedServices (i.e. secondary services) for (var s2 in s.includedServices) { - if (s2.serviceUuid == secondaryServiceUuid && s2.serviceInstanceId == secondaryServiceInstanceId) { + if (s2.serviceUuid == secondaryServiceUuid && s2.serviceIndex == secondaryServiceIndex) { return s2; } } @@ -331,7 +331,7 @@ class BluetoothCharacteristic { BmBluetoothCharacteristic? get _bmchr { if (_bmsvc != null) { for (var c in _bmsvc!.characteristics) { - if (c.characteristicUuid == uuid && c.characteristicInstanceId == characteristicInstanceId) { + if (c.characteristicUuid == uuid && c.characteristicIndex == characteristicIndex) { return c; } } diff --git a/lib/src/bluetooth_descriptor.dart b/lib/src/bluetooth_descriptor.dart index 2aa60986..743302bd 100644 --- a/lib/src/bluetooth_descriptor.dart +++ b/lib/src/bluetooth_descriptor.dart @@ -7,26 +7,26 @@ part of flutter_blue_plus; class BluetoothDescriptor { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final Guid descriptorUuid; BluetoothDescriptor({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.descriptorUuid, }); BluetoothDescriptor.fromProto(BmBluetoothDescriptor p) : remoteId = p.remoteId, serviceUuid = p.serviceUuid, - serviceInstanceId = p.serviceInstanceId, + serviceIndex = p.serviceIndex, characteristicUuid = p.characteristicUuid, - characteristicInstanceId = p.characteristicInstanceId, + characteristicIndex = p.characteristicIndex, descriptorUuid = p.descriptorUuid; /// convenience accessor @@ -92,11 +92,11 @@ class BluetoothDescriptor { var request = BmReadDescriptorRequest( remoteId: remoteId, serviceUuid: serviceUuid, - serviceInstanceId: serviceInstanceId, + serviceIndex: serviceIndex, secondaryServiceUuid: null, - secondaryServiceInstanceId: null, + secondaryServiceIndex: null, characteristicUuid: characteristicUuid, - characteristicInstanceId: characteristicInstanceId, + characteristicIndex: characteristicIndex, descriptorUuid: descriptorUuid, ); @@ -150,11 +150,11 @@ class BluetoothDescriptor { var request = BmWriteDescriptorRequest( remoteId: remoteId, serviceUuid: serviceUuid, - serviceInstanceId: serviceInstanceId, + serviceIndex: serviceIndex, secondaryServiceUuid: null, - secondaryServiceInstanceId: null, + secondaryServiceIndex: null, characteristicUuid: characteristicUuid, - characteristicInstanceId: characteristicInstanceId, + characteristicIndex: characteristicIndex, descriptorUuid: descriptorUuid, value: value, ); diff --git a/lib/src/bluetooth_events.dart b/lib/src/bluetooth_events.dart index 56253c52..58cf69d5 100644 --- a/lib/src/bluetooth_events.dart +++ b/lib/src/bluetooth_events.dart @@ -185,11 +185,11 @@ class OnCharacteristicReceivedEvent { BluetoothCharacteristic get characteristic => BluetoothCharacteristic( remoteId: _response.remoteId, characteristicUuid: _response.characteristicUuid, - characteristicInstanceId: _response.characteristicInstanceId, + characteristicIndex: _response.characteristicIndex, serviceUuid: _response.serviceUuid, - serviceInstanceId: _response.serviceInstanceId, + serviceIndex: _response.serviceIndex, secondaryServiceUuid: _response.secondaryServiceUuid, - secondaryServiceInstanceId: _response.secondaryServiceInstanceId); + secondaryServiceIndex: _response.secondaryServiceIndex); /// the new data List get value => _response.value; @@ -211,11 +211,11 @@ class OnCharacteristicWrittenEvent { BluetoothCharacteristic get characteristic => BluetoothCharacteristic( remoteId: _response.remoteId, characteristicUuid: _response.characteristicUuid, - characteristicInstanceId: _response.characteristicInstanceId, + characteristicIndex: _response.characteristicIndex, serviceUuid: _response.serviceUuid, - serviceInstanceId: _response.serviceInstanceId, + serviceIndex: _response.serviceIndex, secondaryServiceUuid: _response.secondaryServiceUuid, - secondaryServiceInstanceId: _response.secondaryServiceInstanceId); + secondaryServiceIndex: _response.secondaryServiceIndex); /// the new data List get value => _response.value; @@ -237,9 +237,9 @@ class OnDescriptorReadEvent { BluetoothDescriptor get descriptor => BluetoothDescriptor( remoteId: _response.remoteId, serviceUuid: _response.serviceUuid, - serviceInstanceId: _response.serviceInstanceId, + serviceIndex: _response.serviceIndex, characteristicUuid: _response.characteristicUuid, - characteristicInstanceId: _response.characteristicInstanceId, + characteristicIndex: _response.characteristicIndex, descriptorUuid: _response.descriptorUuid); /// the new data @@ -262,9 +262,9 @@ class OnDescriptorWrittenEvent { BluetoothDescriptor get descriptor => BluetoothDescriptor( remoteId: _response.remoteId, serviceUuid: _response.serviceUuid, - serviceInstanceId: _response.serviceInstanceId, + serviceIndex: _response.serviceIndex, characteristicUuid: _response.characteristicUuid, - characteristicInstanceId: _response.characteristicInstanceId, + characteristicIndex: _response.characteristicIndex, descriptorUuid: _response.descriptorUuid); /// the new data diff --git a/lib/src/bluetooth_msgs.dart b/lib/src/bluetooth_msgs.dart index 28fa2c45..595db57a 100644 --- a/lib/src/bluetooth_msgs.dart +++ b/lib/src/bluetooth_msgs.dart @@ -262,14 +262,14 @@ class BmNameChanged { class BmBluetoothService { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; bool isPrimary; List characteristics; List includedServices; BmBluetoothService({ required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.remoteId, required this.isPrimary, required this.characteristics, @@ -291,7 +291,7 @@ class BmBluetoothService { return BmBluetoothService( serviceUuid: Guid(json['service_uuid']), - serviceInstanceId: json['service_instance_id'], + serviceIndex: json['service_index'], remoteId: DeviceIdentifier(json['remote_id']), isPrimary: json['is_primary'] != 0, characteristics: chrs, @@ -303,22 +303,22 @@ class BmBluetoothService { class BmBluetoothCharacteristic { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; List descriptors; BmCharacteristicProperties properties; BmBluetoothCharacteristic({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.secondaryServiceUuid, - required this.secondaryServiceInstanceId, + required this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.descriptors, required this.properties, }); @@ -333,11 +333,11 @@ class BmBluetoothCharacteristic { return BmBluetoothCharacteristic( remoteId: DeviceIdentifier(json['remote_id']), serviceUuid: Guid(json['service_uuid']), - serviceInstanceId: json['service_instance_id'], + serviceIndex: json['service_index'], secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, - secondaryServiceInstanceId: json['secondary_service_instance_id'], + secondaryServiceIndex: json['secondary_service_index'], characteristicUuid: Guid(json['characteristic_uuid']), - characteristicInstanceId: json['characteristic_instance_id'], + characteristicIndex: json['characteristic_index'], descriptors: descs, properties: BmCharacteristicProperties.fromMap(json['properties']), ); @@ -347,17 +347,17 @@ class BmBluetoothCharacteristic { class BmBluetoothDescriptor { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final Guid descriptorUuid; BmBluetoothDescriptor({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.descriptorUuid, }); @@ -365,9 +365,9 @@ class BmBluetoothDescriptor { return BmBluetoothDescriptor( remoteId: DeviceIdentifier(json['remote_id']), serviceUuid: Guid(json['service_uuid']), - serviceInstanceId: json['service_instance_id'], + serviceIndex: json['service_index'], characteristicUuid: Guid(json['characteristic_uuid']), - characteristicInstanceId: json['characteristic_instance_id'], + characteristicIndex: json['characteristic_index'], descriptorUuid: Guid(json['descriptor_uuid']), ); } @@ -445,31 +445,31 @@ class BmDiscoverServicesResult { class BmReadCharacteristicRequest { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; BmReadCharacteristicRequest({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, this.secondaryServiceUuid, - this.secondaryServiceInstanceId, + this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, }); Map toMap() { final Map data = {}; data['remote_id'] = remoteId.str; data['service_uuid'] = serviceUuid.str; - data['service_instance_id'] = serviceInstanceId; + data['service_index'] = serviceIndex; data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['secondary_service_instance_id'] = secondaryServiceInstanceId; + data['secondary_service_index'] = secondaryServiceIndex; data['characteristic_uuid'] = characteristicUuid.str; - data['characteristic_instance_id'] = characteristicInstanceId; + data['characteristic_index'] = characteristicIndex; return data; } } @@ -477,11 +477,11 @@ class BmReadCharacteristicRequest { class BmCharacteristicData { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final List value; final bool success; final int errorCode; @@ -490,11 +490,11 @@ class BmCharacteristicData { BmCharacteristicData({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.secondaryServiceUuid, - required this.secondaryServiceInstanceId, + required this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.value, required this.success, required this.errorCode, @@ -505,11 +505,11 @@ class BmCharacteristicData { return BmCharacteristicData( remoteId: DeviceIdentifier(json['remote_id']), serviceUuid: Guid(json['service_uuid']), - serviceInstanceId: json['service_instance_id'], + serviceIndex: json['service_index'], secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, - secondaryServiceInstanceId: json['secondary_service_instance_id'], + secondaryServiceIndex: json['secondary_service_index'], characteristicUuid: Guid(json['characteristic_uuid']), - characteristicInstanceId: json['characteristic_instance_id'], + characteristicIndex: json['characteristic_index'], value: _hexDecode(json['value']), success: json['success'] != 0, errorCode: json['error_code'], @@ -521,21 +521,21 @@ class BmCharacteristicData { class BmReadDescriptorRequest { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final Guid descriptorUuid; BmReadDescriptorRequest({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.secondaryServiceUuid, - required this.secondaryServiceInstanceId, + required this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.descriptorUuid, }); @@ -543,11 +543,11 @@ class BmReadDescriptorRequest { final Map data = {}; data['remote_id'] = remoteId.str; data['service_uuid'] = serviceUuid.str; - data['service_instance_id'] = serviceInstanceId; + data['service_index'] = serviceIndex; data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['secondary_service_instance_id'] = secondaryServiceInstanceId; + data['secondary_service_index'] = secondaryServiceIndex; data['characteristic_uuid'] = characteristicUuid.str; - data['characteristic_instance_id'] = characteristicInstanceId; + data['characteristic_index'] = characteristicIndex; data['descriptor_uuid'] = descriptorUuid.str; return data; } @@ -561,11 +561,11 @@ enum BmWriteType { class BmWriteCharacteristicRequest { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final BmWriteType writeType; final bool allowLongWrite; final List value; @@ -573,11 +573,11 @@ class BmWriteCharacteristicRequest { BmWriteCharacteristicRequest({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.secondaryServiceUuid, - required this.secondaryServiceInstanceId, + required this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.writeType, required this.allowLongWrite, required this.value, @@ -587,11 +587,11 @@ class BmWriteCharacteristicRequest { final Map data = {}; data['remote_id'] = remoteId.str; data['service_uuid'] = serviceUuid.str; - data['service_instance_id'] = serviceInstanceId; + data['service_index'] = serviceIndex; data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['secondary_service_instance_id'] = secondaryServiceInstanceId; + data['secondary_service_index'] = secondaryServiceIndex; data['characteristic_uuid'] = characteristicUuid.str; - data['characteristic_instance_id'] = characteristicInstanceId; + data['characteristic_index'] = characteristicIndex; data['write_type'] = writeType.index; data['allow_long_write'] = allowLongWrite ? 1 : 0; data['value'] = _hexEncode(value); @@ -602,22 +602,22 @@ class BmWriteCharacteristicRequest { class BmWriteDescriptorRequest { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final Guid descriptorUuid; final List value; BmWriteDescriptorRequest({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.secondaryServiceUuid, - required this.secondaryServiceInstanceId, + required this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.descriptorUuid, required this.value, }); @@ -626,11 +626,11 @@ class BmWriteDescriptorRequest { final Map data = {}; data['remote_id'] = remoteId.str; data['service_uuid'] = serviceUuid.str; - data['service_instance_id'] = serviceInstanceId; + data['service_index'] = serviceIndex; data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['secondary_service_instance_id'] = secondaryServiceInstanceId; + data['secondary_service_index'] = secondaryServiceIndex; data['characteristic_uuid'] = characteristicUuid.str; - data['characteristic_instance_id'] = characteristicInstanceId; + data['characteristic_index'] = characteristicIndex; data['descriptor_uuid'] = descriptorUuid.str; data['value'] = _hexEncode(value); return data; @@ -640,11 +640,11 @@ class BmWriteDescriptorRequest { class BmDescriptorData { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final Guid descriptorUuid; final List value; final bool success; @@ -654,11 +654,11 @@ class BmDescriptorData { BmDescriptorData({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.secondaryServiceUuid, - required this.secondaryServiceInstanceId, + required this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.descriptorUuid, required this.value, required this.success, @@ -670,11 +670,11 @@ class BmDescriptorData { return BmDescriptorData( remoteId: DeviceIdentifier(json['remote_id']), serviceUuid: Guid(json['service_uuid']), - serviceInstanceId: json['service_instance_id'], + serviceIndex: json['service_index'], secondaryServiceUuid: json['secondary_service_uuid'] != null ? Guid(json['secondary_service_uuid']) : null, - secondaryServiceInstanceId: json['secondary_service_instance_id'], + secondaryServiceIndex: json['secondary_service_index'], characteristicUuid: Guid(json['characteristic_uuid']), - characteristicInstanceId: json['characteristic_instance_id'], + characteristicIndex: json['characteristic_index'], descriptorUuid: Guid(json['descriptor_uuid']), value: _hexDecode(json['value']), success: json['success'] != 0, @@ -687,22 +687,22 @@ class BmDescriptorData { class BmSetNotifyValueRequest { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final Guid? secondaryServiceUuid; - final int? secondaryServiceInstanceId; + final int? secondaryServiceIndex; final Guid characteristicUuid; - final int characteristicInstanceId; + final int characteristicIndex; final bool forceIndications; final bool enable; BmSetNotifyValueRequest({ required this.remoteId, required this.serviceUuid, - required this.serviceInstanceId, + required this.serviceIndex, required this.secondaryServiceUuid, - required this.secondaryServiceInstanceId, + required this.secondaryServiceIndex, required this.characteristicUuid, - required this.characteristicInstanceId, + required this.characteristicIndex, required this.forceIndications, required this.enable, }); @@ -711,11 +711,11 @@ class BmSetNotifyValueRequest { final Map data = {}; data['remote_id'] = remoteId.str; data['service_uuid'] = serviceUuid.str; - data['service_instance_id'] = serviceInstanceId; + data['service_index'] = serviceIndex; data['secondary_service_uuid'] = secondaryServiceUuid?.str; - data['secondary_service_instance_id'] = secondaryServiceInstanceId; + data['secondary_service_index'] = secondaryServiceIndex; data['characteristic_uuid'] = characteristicUuid.str; - data['characteristic_instance_id'] = characteristicInstanceId; + data['characteristic_index'] = characteristicIndex; data['force_indications'] = forceIndications; data['enable'] = enable; return data; diff --git a/lib/src/bluetooth_service.dart b/lib/src/bluetooth_service.dart index 567dd990..fafd874b 100644 --- a/lib/src/bluetooth_service.dart +++ b/lib/src/bluetooth_service.dart @@ -7,7 +7,7 @@ part of flutter_blue_plus; class BluetoothService { final DeviceIdentifier remoteId; final Guid serviceUuid; - final int serviceInstanceId; + final int serviceIndex; final bool isPrimary; final List characteristics; final List includedServices; @@ -18,14 +18,10 @@ class BluetoothService { BluetoothService.fromProto(BmBluetoothService p) : remoteId = p.remoteId, serviceUuid = p.serviceUuid, - serviceInstanceId = p.serviceInstanceId, + serviceIndex = p.serviceIndex, isPrimary = p.isPrimary, - characteristics = p.characteristics - .map((c) => BluetoothCharacteristic.fromProto(c)) - .toList(), - includedServices = p.includedServices - .map((s) => BluetoothService.fromProto(s)) - .toList(); + characteristics = p.characteristics.map((c) => BluetoothCharacteristic.fromProto(c)).toList(), + includedServices = p.includedServices.map((s) => BluetoothService.fromProto(s)).toList(); @override String toString() {