feat(dfu): add connection and MTU preflight checks

This commit is contained in:
2026-03-03 16:54:56 +01:00
parent 7a33e71410
commit fb85565854
4 changed files with 329 additions and 12 deletions

View File

@ -299,11 +299,20 @@ class BluetoothController {
Future<Result<void>> requestMtu(String deviceId,
{int mtu = defaultMtu}) async {
final result = await requestMtuAndGetValue(deviceId, mtu: mtu);
if (result.isErr()) {
return bail(result.unwrapErr());
}
return Ok(null);
}
Future<Result<int>> requestMtuAndGetValue(String deviceId,
{int mtu = defaultMtu}) async {
try {
final negotiatedMtu = await _ble.requestMtu(deviceId: deviceId, mtu: mtu);
log.info(
'MTU negotiated for $deviceId: requested $mtu, got $negotiatedMtu');
return Ok(null);
return Ok(negotiatedMtu);
} catch (e) {
return bail('Error requesting MTU $mtu for $deviceId: $e');
}