|
|
|
@ -145,7 +145,7 @@ class BleWakeupVoicesUpgradeSender { |
|
|
|
// 初始化状态 |
|
|
|
otaBytes = bytes |
|
|
|
otaTotalPackets = ((bytes.size + MAX_DATA_PER_PACKET - 1) / MAX_DATA_PER_PACKET) |
|
|
|
currentSeq = 1 // 序号按文档使用1基准 |
|
|
|
currentSeq = 0 // 序号改为从0起步 |
|
|
|
handshakeAcked = false |
|
|
|
isUpgrading = true |
|
|
|
|
|
|
|
@ -248,18 +248,22 @@ class BleWakeupVoicesUpgradeSender { |
|
|
|
0x22 -> { |
|
|
|
// 数据包确认: 0xBB + 0x22 + 0x03 + OTA包序号(2Byte) + 0x01 + CRC 成功 |
|
|
|
// 数据包确认: 0xBB + 0x22 + 0x03 + OTA包序号(2Byte) + 0x00 + CRC 失败 |
|
|
|
if (data.size < 7) { |
|
|
|
Log.d(TAG, "liwei------------- 数据包确认: 消息异常 长度不够") |
|
|
|
return |
|
|
|
} |
|
|
|
val seqHi = data[3].toInt() and 0xFF |
|
|
|
val seqLo = data[4].toInt() and 0xFF |
|
|
|
val status = data[5].toInt() and 0xFF |
|
|
|
val ackSeq = (seqHi shl 8) or seqLo |
|
|
|
Log.d(TAG, "liwei------------- 数据包确认: seq=$ackSeq, status=$status") |
|
|
|
if (status == 0x01) { //成功 发送下一包 |
|
|
|
// 更新进度(1基准) |
|
|
|
val progress = ((ackSeq.coerceAtMost(otaTotalPackets)) * 100) / (otaTotalPackets.coerceAtLeast(1)) |
|
|
|
// 更新进度(0基准,显示为1..N) |
|
|
|
val progress = (((ackSeq + 1).coerceAtMost(otaTotalPackets)) * 100) / (otaTotalPackets.coerceAtLeast(1)) |
|
|
|
Log.i(TAG, "liwei------------- OTA进度: $progress%") |
|
|
|
callback?.notifyUpgradeProgressReceived(progress) |
|
|
|
// 继续发送下一包 |
|
|
|
if (ackSeq >= otaTotalPackets) { |
|
|
|
if (ackSeq >= otaTotalPackets - 1) { |
|
|
|
Log.i(TAG, "liwei------------- OTA完成,共发送${otaTotalPackets}包") |
|
|
|
callback?.notifyUpgradeProgressReceived(100) |
|
|
|
sendEndDataPacket() |
|
|
|
@ -520,7 +524,7 @@ class BleWakeupVoicesUpgradeSender { |
|
|
|
return |
|
|
|
} |
|
|
|
// 计算当前分片范围 |
|
|
|
val start = (currentSeq - 1) * MAX_DATA_PER_PACKET |
|
|
|
val start = currentSeq * MAX_DATA_PER_PACKET |
|
|
|
val end = minOf(start + MAX_DATA_PER_PACKET, bytes.size) |
|
|
|
if (start >= end) { |
|
|
|
Log.w(TAG, "没有更多数据可发送 start=$start end=$end") |
|
|
|
|