fix: check writeCharacteristic return value in sendOtaData

This commit is contained in:
eddy 2026-07-30 19:16:28 +02:00
commit 44297d30ad
2 changed files with 11 additions and 5 deletions

View file

@ -194,12 +194,12 @@ class BleRelayManager(
}
@SuppressLint("MissingPermission")
fun sendOtaData(data: ByteArray) {
val char = otaCharacteristic ?: return
val gatt = bluetoothGatt ?: return
fun sendOtaData(data: ByteArray): Boolean {
val char = otaCharacteristic ?: return false
val gatt = bluetoothGatt ?: return false
char.value = data
char.writeType = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
gatt.writeCharacteristic(char)
return gatt.writeCharacteristic(char)
}
@SuppressLint("MissingPermission")

View file

@ -105,7 +105,13 @@ class OtaManager(
var retries = 0
while (retries < MAX_RETRIES) {
relayManager.sendOtaData(packet.array())
val writeOk = relayManager.sendOtaData(packet.array())
if (!writeOk) {
Log.w(TAG, "writeCharacteristic returned false for chunk $seq, retrying")
retries++
delay(100)
continue
}
Log.d(TAG, "Sent chunk $seq/$totalChunks ($chunkSize bytes) attempt ${retries + 1}")
try {