Implement requestMtu in Linux (#22)

* Implement requestMtu in Linux

* Minor fixes

* Improve requestMtu
This commit is contained in:
Rohit Sangwan
2024-03-17 16:18:33 +05:30
committed by GitHub
parent 8108f9dfe4
commit fe0a654f36
5 changed files with 43 additions and 60 deletions
@@ -227,17 +227,16 @@ class UniversalBleLinux extends UniversalBlePlatform {
@override
Future<int> requestMtu(String deviceId, int expectedMtu) async {
// var device = _findDeviceById(deviceId);
// if (!device.connected) return 0;
// for (BlueZGattService service in device.gattServices) {
// for (BlueZGattCharacteristic characteristic in service.characteristics) {
// // The value provided by Bluez includes an extra 3 bytes from the GATT header, which needs to be removed.
// // requires `int? get mtu => _object.getUint16Property(_gattCharacteristicInterfaceName, 'MTU');` to add in bluez.dart
// return characteristic.mtu - 3;
// }
// }
// return 0;
throw UnimplementedError();
var device = _findDeviceById(deviceId);
if (!device.connected) throw Exception('Device not connected');
for (BlueZGattService service in device.gattServices) {
for (BlueZGattCharacteristic characteristic in service.characteristics) {
int? mtu = characteristic.mtu;
// The value provided by Bluez includes an extra 3 bytes from the GATT header, which needs to be removed.
if (mtu != null) return mtu - 3;
}
}
throw Exception('MTU not available');
}
@override