diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d25179..2e58365 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.6 +* Fix a Windows issue where characteristics of certain services would not be discovered +* Improve readme + ## 0.9.5 * Windows support has graduated from beta to stable * Support filtering by manufacturer data diff --git a/pubspec.yaml b/pubspec.yaml index cf81314..11d2529 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: universal_ble description: A cross-platform (Android/iOS/macOS/Windows/Linux/Web) Bluetooth Low Energy (BLE) plugin for Flutter -version: 0.9.5 +version: 0.9.6 homepage: https://navideck.com repository: https://github.com/Navideck/universal_ble issue_tracker: https://github.com/Navideck/universal_ble/issues diff --git a/windows/src/universal_ble_plugin.cpp b/windows/src/universal_ble_plugin.cpp index 7f568a2..0b5db1d 100644 --- a/windows/src/universal_ble_plugin.cpp +++ b/windows/src/universal_ble_plugin.cpp @@ -1084,70 +1084,56 @@ namespace universal_ble } } - winrt::fire_and_forget UniversalBlePlugin::DiscoverServicesAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, std::function reply)> result) + void UniversalBlePlugin::DiscoverServicesAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, std::function reply)> result) { try { - auto deviceId = _mac_address_to_str(bluetoothDeviceAgent.device.BluetoothAddress()); - auto serviceResult = co_await bluetoothDeviceAgent.device.GetGattServicesAsync(); - if (serviceResult.Status() != GattCommunicationStatus::Success) - { - result(FlutterError("DiscoverServiceError: No services found for device")); - co_return; - } - auto services = serviceResult.Services(); auto universalServices = flutter::EncodableList(); - for (auto service : serviceResult.Services()) + for (auto &service : bluetoothDeviceAgent.gatt_map_) { - auto characteristicResult = co_await service.GetCharacteristicsAsync(); flutter::EncodableList universalCharacteristics; - if (characteristicResult.Status() == GattCommunicationStatus::Success) + for (auto characteristicsMap : service.second.characteristics) { - for (auto c : characteristicResult.Characteristics()) + auto &c = characteristicsMap.second.obj; + flutter::EncodableList properties = flutter::EncodableList(); + auto propertiesValue = c.CharacteristicProperties(); + if ((propertiesValue & GattCharacteristicProperties::Broadcast) != GattCharacteristicProperties::None) { - flutter::EncodableList properties = flutter::EncodableList(); - auto propertiesValue = c.CharacteristicProperties(); - if ((propertiesValue & GattCharacteristicProperties::Broadcast) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::broadcast)); - } - if ((propertiesValue & GattCharacteristicProperties::Read) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::read)); - } - if ((propertiesValue & GattCharacteristicProperties::Write) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::write)); - } - if ((propertiesValue & GattCharacteristicProperties::WriteWithoutResponse) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::writeWithoutResponse)); - } - if ((propertiesValue & GattCharacteristicProperties::Notify) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::notify)); - } - if ((propertiesValue & GattCharacteristicProperties::Indicate) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::indicate)); - } - if ((propertiesValue & GattCharacteristicProperties::AuthenticatedSignedWrites) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::authenticatedSignedWrites)); - } - if ((propertiesValue & GattCharacteristicProperties::ExtendedProperties) != GattCharacteristicProperties::None) - { - properties.push_back(static_cast(CharacteristicProperty::extendedProperties)); - } - universalCharacteristics.push_back( - flutter::CustomEncodableValue(UniversalBleCharacteristic(to_uuidstr(c.Uuid()), properties))); + properties.push_back(static_cast(CharacteristicProperty::broadcast)); } + if ((propertiesValue & GattCharacteristicProperties::Read) != GattCharacteristicProperties::None) + { + properties.push_back(static_cast(CharacteristicProperty::read)); + } + if ((propertiesValue & GattCharacteristicProperties::Write) != GattCharacteristicProperties::None) + { + properties.push_back(static_cast(CharacteristicProperty::write)); + } + if ((propertiesValue & GattCharacteristicProperties::WriteWithoutResponse) != GattCharacteristicProperties::None) + { + properties.push_back(static_cast(CharacteristicProperty::writeWithoutResponse)); + } + if ((propertiesValue & GattCharacteristicProperties::Notify) != GattCharacteristicProperties::None) + { + properties.push_back(static_cast(CharacteristicProperty::notify)); + } + if ((propertiesValue & GattCharacteristicProperties::Indicate) != GattCharacteristicProperties::None) + { + properties.push_back(static_cast(CharacteristicProperty::indicate)); + } + if ((propertiesValue & GattCharacteristicProperties::AuthenticatedSignedWrites) != GattCharacteristicProperties::None) + { + properties.push_back(static_cast(CharacteristicProperty::authenticatedSignedWrites)); + } + if ((propertiesValue & GattCharacteristicProperties::ExtendedProperties) != GattCharacteristicProperties::None) + { + properties.push_back(static_cast(CharacteristicProperty::extendedProperties)); + } + universalCharacteristics.push_back( + flutter::CustomEncodableValue(UniversalBleCharacteristic(to_uuidstr(c.Uuid()), properties))); } - else - { - std::cout << "Failed to get characteristics for service: " << to_uuidstr(service.Uuid()) << ", With Status: " << GattCommunicationStatusToString(characteristicResult.Status()) << std::endl; - } - auto universalBleService = UniversalBleService(to_uuidstr(service.Uuid())); + + auto universalBleService = UniversalBleService(to_uuidstr(service.second.obj.Uuid())); universalBleService.set_characteristics(universalCharacteristics); universalServices.push_back(flutter::CustomEncodableValue(universalBleService)); } diff --git a/windows/src/universal_ble_plugin.h b/windows/src/universal_ble_plugin.h index 3070c75..50e62eb 100644 --- a/windows/src/universal_ble_plugin.h +++ b/windows/src/universal_ble_plugin.h @@ -111,7 +111,7 @@ namespace universal_ble winrt::fire_and_forget ConnectAsync(uint64_t bluetoothAddress); void BluetoothLEDevice_ConnectionStatusChanged(BluetoothLEDevice sender, IInspectable args); void CleanConnection(uint64_t bluetoothAddress); - winrt::fire_and_forget DiscoverServicesAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, std::function reply)>); + void DiscoverServicesAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, std::function reply)>); winrt::fire_and_forget SetNotifiableAsync(BluetoothDeviceAgent &bluetoothDeviceAgent, const std::string &service, const std::string &characteristic, GattClientCharacteristicConfigurationDescriptorValue descriptorValue); void GattCharacteristic_ValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args);