修复 CoW 导致 discoverGATT 失败的问题 (#38)

* 修复 CoW 导致 discoverGATT 失败的问题

* 修复 CoW 导致 discoverGATT 失败的问题
This commit is contained in:
iAMD
2024-01-16 17:59:47 +08:00
committed by GitHub
parent 41b09f3bf3
commit 6f0bc77ac9
8 changed files with 33 additions and 28 deletions

View File

@ -1,3 +1,7 @@
## 5.0.2
* Fix the issue that [discoverGATT failed caused by CoW](https://github.com/yanshouwang/bluetooth_low_energy/issues/36).
## 5.0.1 ## 5.0.1
* Fix the issue that [completion was called duplicately caused by CoW](https://github.com/yanshouwang/bluetooth_low_energy/issues/36). * Fix the issue that [completion was called duplicately caused by CoW](https://github.com/yanshouwang/bluetooth_low_energy/issues/36).

View File

@ -1029,6 +1029,18 @@ class _AdvertiserViewState extends State<AdvertiserView>
], ],
); );
await PeripheralManager.instance.addService(service); await PeripheralManager.instance.addService(service);
final batteryService = GattService(
uuid: UUID.short(0x180f),
characteristics: [
GattCharacteristic(
uuid: UUID.short(0x2A19),
properties: [GattCharacteristicProperty.read],
value: Uint8List.fromList([75]),
descriptors: [],
),
],
);
await PeripheralManager.instance.addService(batteryService);
final advertisement = Advertisement( final advertisement = Advertisement(
name: 'le12138', name: 'le12138',
manufacturerSpecificData: ManufacturerSpecificData( manufacturerSpecificData: ManufacturerSpecificData(

View File

@ -23,7 +23,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "5.0.1" version: "5.0.2"
bluetooth_low_energy_android: bluetooth_low_energy_android:
dependency: transitive dependency: transitive
description: description:
@ -36,10 +36,10 @@ packages:
dependency: transitive dependency: transitive
description: description:
name: bluetooth_low_energy_darwin name: bluetooth_low_energy_darwin
sha256: "8cbb1a9ac97a217f6f45dca58510df457e8b70f861c36d3bf8cf2640c669e1cd" sha256: "876fd1c7eadd5e4eea92257dd3d2ec31f3c0bb68f8e96c564ed28ecde7382bd1"
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "5.0.1" version: "5.0.2"
bluetooth_low_energy_linux: bluetooth_low_energy_linux:
dependency: transitive dependency: transitive
description: description:

View File

@ -1,6 +1,6 @@
name: bluetooth_low_energy name: bluetooth_low_energy
description: A Flutter plugin for controlling the bluetooth low energy, supports central and peripheral apis. description: A Flutter plugin for controlling the bluetooth low energy, supports central and peripheral apis.
version: 5.0.1 version: 5.0.2
homepage: https://github.com/yanshouwang/bluetooth_low_energy homepage: https://github.com/yanshouwang/bluetooth_low_energy
environment: environment:
@ -12,7 +12,7 @@ dependencies:
sdk: flutter sdk: flutter
bluetooth_low_energy_platform_interface: ^5.0.0 bluetooth_low_energy_platform_interface: ^5.0.0
bluetooth_low_energy_android: ^5.0.0 bluetooth_low_energy_android: ^5.0.0
bluetooth_low_energy_darwin: ^5.0.1 bluetooth_low_energy_darwin: ^5.0.2
bluetooth_low_energy_windows: ^5.0.0 bluetooth_low_energy_windows: ^5.0.0
bluetooth_low_energy_linux: ^5.0.0 bluetooth_low_energy_linux: ^5.0.0

View File

@ -1,3 +1,7 @@
## 5.0.2
* Fix the issue that [discoverGATT failed caused by CoW](https://github.com/yanshouwang/bluetooth_low_energy/issues/36).
## 5.0.1 ## 5.0.1
* Fix the issue that [completion was called duplicately caused by CoW](https://github.com/yanshouwang/bluetooth_low_energy/issues/36). * Fix the issue that [completion was called duplicately caused by CoW](https://github.com/yanshouwang/bluetooth_low_energy/issues/36).

View File

@ -384,16 +384,11 @@ class MyCentralManager: MyCentralManagerHostApi {
if error == nil { if error == nil {
let services = peripheral.services ?? [] let services = peripheral.services ?? []
let servicesArgs = services.map { service in service.toArgs() } let servicesArgs = services.map { service in service.toArgs() }
let elements = services.flatMap { service in let values = services.flatMap { service in
let hashCodeArgs = service.hash.toInt64() let hashCodeArgs = service.hash.toInt64()
return [hashCodeArgs: service] return [hashCodeArgs: service]
} }
var items = _services[uuidArgs] _services[uuidArgs] = Dictionary(uniqueKeysWithValues: values)
if items == nil {
_services[uuidArgs] = Dictionary(uniqueKeysWithValues: elements)
} else {
items!.merge(elements) { service1, service2 in service2 }
}
completion(.success(servicesArgs)) completion(.success(servicesArgs))
} else { } else {
completion(.failure(error!)) completion(.failure(error!))
@ -409,16 +404,11 @@ class MyCentralManager: MyCentralManagerHostApi {
if error == nil { if error == nil {
let characteristics = service.characteristics ?? [] let characteristics = service.characteristics ?? []
let characteristicsArgs = characteristics.map { characteristic in characteristic.toArgs() } let characteristicsArgs = characteristics.map { characteristic in characteristic.toArgs() }
let elements = characteristics.flatMap { characteristic in let values = characteristics.flatMap { characteristic in
let hashCodeArgs = characteristic.hash.toInt64() let hashCodeArgs = characteristic.hash.toInt64()
return [hashCodeArgs: characteristic] return [hashCodeArgs: characteristic]
} }
var items = _characteristics[uuidArgs] _characteristics[uuidArgs, default: [:]].merge(values) { value1, value2 in value2 }
if items == nil {
_characteristics[uuidArgs] = Dictionary(uniqueKeysWithValues: elements)
} else {
items!.merge(elements) { characteristic1, characteristic2 in characteristic2 }
}
completion(.success(characteristicsArgs)) completion(.success(characteristicsArgs))
} else { } else {
completion(.failure(error!)) completion(.failure(error!))
@ -434,16 +424,11 @@ class MyCentralManager: MyCentralManagerHostApi {
if error == nil { if error == nil {
let descriptors = characteristic.descriptors ?? [] let descriptors = characteristic.descriptors ?? []
let descriptorsArgs = descriptors.map { descriptor in descriptor.toArgs() } let descriptorsArgs = descriptors.map { descriptor in descriptor.toArgs() }
let elements = descriptors.flatMap { descriptor in let values = descriptors.flatMap { descriptor in
let hashCodeArgs = descriptor.hash.toInt64() let hashCodeArgs = descriptor.hash.toInt64()
return [hashCodeArgs: descriptor] return [hashCodeArgs: descriptor]
} }
var items = _descriptors[uuidArgs] _descriptors[uuidArgs, default: [:]].merge(values) { value1, value2 in value2 }
if items == nil {
_descriptors[uuidArgs] = Dictionary(uniqueKeysWithValues: elements)
} else {
items!.merge(elements) { descriptor1, descriptor2 in descriptor2 }
}
completion(.success(descriptorsArgs)) completion(.success(descriptorsArgs))
} else { } else {
completion(.failure(error!)) completion(.failure(error!))

View File

@ -15,7 +15,7 @@ packages:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "5.0.1" version: "5.0.2"
bluetooth_low_energy_platform_interface: bluetooth_low_energy_platform_interface:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -1,6 +1,6 @@
name: bluetooth_low_energy_darwin name: bluetooth_low_energy_darwin
description: iOS and macOS implementation of the bluetooth_low_energy plugin. description: iOS and macOS implementation of the bluetooth_low_energy plugin.
version: 5.0.1 version: 5.0.2
homepage: https://github.com/yanshouwang/bluetooth_low_energy homepage: https://github.com/yanshouwang/bluetooth_low_energy
environment: environment: