feat: 支持获取 maximumWrtieLength (#14)

This commit is contained in:
Mr剑侠客
2023-09-08 15:25:59 +08:00
committed by GitHub
parent 219bd73c33
commit 78bcb88563
28 changed files with 417 additions and 112 deletions

View File

@ -380,6 +380,33 @@ class MyCentralControllerHostApi {
}
}
Future<int> getMaximumWriteLength(int arg_myPeripheralKey, int arg_myTypeNumber) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.bluetooth_low_energy_darwin.MyCentralControllerHostApi.getMaximumWriteLength', codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_myPeripheralKey, arg_myTypeNumber]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as int?)!;
}
}
Future<void> discoverGATT(int arg_myPeripheralKey) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.bluetooth_low_energy_darwin.MyCentralControllerHostApi.discoverGATT', codec,

View File

@ -114,6 +114,22 @@ class MyCentralController extends CentralController
await _myApi.disconnect(myPeripheral.hashCode);
}
@override
Future<int> getMaximumWriteLength(
Peripheral peripheral, {
required GattCharacteristicWriteType type,
}) async {
await _throwWithoutState(CentralState.poweredOn);
final myPeripheral = peripheral as MyPeripheral;
final myTypeArgs = type.toMyArgs();
final myTypeNumber = myTypeArgs.index;
final maximumWriteLength = await _myApi.getMaximumWriteLength(
myPeripheral.hashCode,
myTypeNumber,
);
return maximumWriteLength;
}
@override
Future<void> discoverGATT(Peripheral peripheral) async {
await _throwWithoutState(CentralState.poweredOn);
@ -206,14 +222,14 @@ class MyCentralController extends CentralController
final myCharacteristic = characteristic as MyGattCharacteristic;
final myService = myCharacteristic.myService;
final myPeripheral = myService.myPeripheral;
final typeArgs = type.toMyArgs();
final typeNumber = typeArgs.index;
final myTypeArgs = type.toMyArgs();
final myTypeNumber = myTypeArgs.index;
await _myApi.writeCharacteristic(
myPeripheral.hashCode,
myService.hashCode,
myCharacteristic.hashCode,
value,
typeNumber,
myTypeNumber,
);
}