修复读取 CCCD 报错的问题,写入时更新特征值 (#50)
* 修复 CCCD 无法读取的问题 * 优化代码 * 调整部分必需参数为可空参数 * 调整接口 * 写入时更新特征值 * 调整接口 * 适配新接口 * 调整依赖项
This commit is contained in:
@ -1,3 +1,12 @@
|
||||
## 5.0.5
|
||||
|
||||
* Change flutter minimum version to 3.0.0.
|
||||
|
||||
## 5.0.4
|
||||
|
||||
* Update characteristic's value when write by centrals.
|
||||
* Implements new Api.
|
||||
|
||||
## 5.0.3
|
||||
|
||||
* Fix issues caused by CoW.
|
||||
|
@ -993,32 +993,32 @@ class _AdvertiserViewState extends State<AdvertiserView>
|
||||
GattCharacteristicProperty.write,
|
||||
GattCharacteristicProperty.writeWithoutResponse,
|
||||
],
|
||||
value: Uint8List.fromList([]),
|
||||
descriptors: [],
|
||||
),
|
||||
GattCharacteristic(
|
||||
uuid: UUID.short(202),
|
||||
properties: [
|
||||
GattCharacteristicProperty.notify,
|
||||
GattCharacteristicProperty.indicate,
|
||||
],
|
||||
value: Uint8List.fromList([]),
|
||||
descriptors: [],
|
||||
),
|
||||
GattCharacteristic(
|
||||
uuid: UUID.short(203),
|
||||
properties: [
|
||||
GattCharacteristicProperty.notify,
|
||||
GattCharacteristicProperty.indicate,
|
||||
],
|
||||
value: Uint8List.fromList([]),
|
||||
descriptors: [],
|
||||
),
|
||||
GattCharacteristic(
|
||||
uuid: UUID.short(204),
|
||||
properties: [
|
||||
GattCharacteristicProperty.read,
|
||||
GattCharacteristicProperty.write,
|
||||
GattCharacteristicProperty.writeWithoutResponse,
|
||||
GattCharacteristicProperty.notify,
|
||||
GattCharacteristicProperty.indicate,
|
||||
],
|
||||
value: Uint8List.fromList([]),
|
||||
value: value,
|
||||
descriptors: [],
|
||||
),
|
||||
],
|
||||
|
@ -15,15 +15,15 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "5.0.3"
|
||||
version: "5.0.5"
|
||||
bluetooth_low_energy_platform_interface:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: bluetooth_low_energy_platform_interface
|
||||
sha256: "54f92ab2d7746fb6f2b4a40a48cd7eb8e3bf772f3ee89e1979d4d7b741fb2a05"
|
||||
sha256: "5af74eb8f97a896dfdbcff2da284d4fe5b4e2e49ebb2f46f826ac1810f66e4d7"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
version: "5.0.2"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -312,4 +312,4 @@ packages:
|
||||
version: "3.0.2"
|
||||
sdks:
|
||||
dart: ">=3.2.0-194.0.dev <4.0.0"
|
||||
flutter: ">=3.3.0"
|
||||
flutter: ">=3.0.0"
|
||||
|
@ -203,17 +203,13 @@ extension MyGattDescriptorX on MyGattDescriptor {
|
||||
}
|
||||
|
||||
extension MyGattCharacteristicX on MyGattCharacteristic {
|
||||
MyGattCharacteristicArgs toArgs() {
|
||||
MyGattCharacteristicArgs toArgs(List<MyGattDescriptorArgs> descriptorsArgs) {
|
||||
final hashCodeArgs = hashCode;
|
||||
final uuidArgs = uuid.toArgs();
|
||||
final propertyNumbersArgs = properties.map((property) {
|
||||
final propertyArgs = property.toArgs();
|
||||
return propertyArgs.index;
|
||||
}).toList();
|
||||
final descriptorsArgs = descriptors
|
||||
.cast<MyGattDescriptor>()
|
||||
.map((descriptor) => descriptor.toArgs())
|
||||
.toList();
|
||||
return MyGattCharacteristicArgs(
|
||||
hashCodeArgs: hashCodeArgs,
|
||||
uuidArgs: uuidArgs,
|
||||
@ -224,13 +220,9 @@ extension MyGattCharacteristicX on MyGattCharacteristic {
|
||||
}
|
||||
|
||||
extension MyGattServiceX on MyGattService {
|
||||
MyGattServiceArgs toArgs() {
|
||||
MyGattServiceArgs toArgs(List<MyGattCharacteristicArgs> characteristicsArgs) {
|
||||
final hashCodeArgs = hashCode;
|
||||
final uuidArgs = uuid.toArgs();
|
||||
final characteristicsArgs = characteristics
|
||||
.cast<MyGattCharacteristic>()
|
||||
.map((characteristic) => characteristic.toArgs())
|
||||
.toList();
|
||||
return MyGattServiceArgs(
|
||||
hashCodeArgs: hashCodeArgs,
|
||||
uuidArgs: uuidArgs,
|
||||
|
@ -65,14 +65,22 @@ class MyPeripheralManager extends PeripheralManager
|
||||
if (service is! MyGattService) {
|
||||
throw TypeError();
|
||||
}
|
||||
final serviceArgs = service.toArgs();
|
||||
final hashCodeArgs = serviceArgs.hashCodeArgs;
|
||||
logger.info('addService: $hashCodeArgs');
|
||||
final characteristics = <int, MyGattCharacteristic>{};
|
||||
final characteristicsArgs = <MyGattCharacteristicArgs>[];
|
||||
for (var characteristic in service.characteristics) {
|
||||
final descriptorsArgs = <MyGattDescriptorArgs>[];
|
||||
for (var descriptor in characteristic.descriptors) {
|
||||
final descriptorArgs = descriptor.toArgs();
|
||||
descriptorsArgs.add(descriptorArgs);
|
||||
}
|
||||
final characteristicArgs = characteristic.toArgs(descriptorsArgs);
|
||||
characteristicsArgs.add(characteristicArgs);
|
||||
characteristics[characteristicArgs.hashCodeArgs] = characteristic;
|
||||
}
|
||||
final serviceArgs = service.toArgs(characteristicsArgs);
|
||||
logger.info('addService: $serviceArgs');
|
||||
await _api.addService(serviceArgs);
|
||||
_characteristics[hashCodeArgs] = {
|
||||
for (var characteristics in service.characteristics)
|
||||
characteristics.hashCode: characteristics
|
||||
};
|
||||
_characteristics[serviceArgs.hashCodeArgs] = characteristics;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -304,7 +312,8 @@ class MyPeripheralManager extends PeripheralManager
|
||||
MyGattCharacteristic characteristic,
|
||||
Uint8List value,
|
||||
) async {
|
||||
final trimmedValue = value.trimGATT();
|
||||
characteristic.value = value;
|
||||
final trimmedValue = characteristic.value;
|
||||
final eventArgs = GattCharacteristicWrittenEventArgs(
|
||||
central,
|
||||
characteristic,
|
||||
|
@ -1,16 +1,16 @@
|
||||
name: bluetooth_low_energy_darwin
|
||||
description: iOS and macOS implementation of the bluetooth_low_energy plugin.
|
||||
version: 5.0.3
|
||||
version: 5.0.5
|
||||
homepage: https://github.com/yanshouwang/bluetooth_low_energy
|
||||
|
||||
environment:
|
||||
sdk: ">=3.0.0 <4.0.0"
|
||||
flutter: ">=3.3.0"
|
||||
flutter: ">=3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
bluetooth_low_energy_platform_interface: ^5.0.0
|
||||
bluetooth_low_energy_platform_interface: ^5.0.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Reference in New Issue
Block a user