Browse Source

上传代码

weicu
liwei1dao 10 months ago
parent
commit
82e5368624
  1. 3
      local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt
  2. 4
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt
  3. 14
      local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleWakeupVoicesUpgradeSender.kt

3
local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt

@ -704,8 +704,7 @@ object AgentService : CoroutineScope {
_hasSpeechDetected.set(false)
restartIdleCheck()
restartIdleCheck()
}

4
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleService.kt

@ -980,10 +980,6 @@ object BleService {
Log.i(TAG, "收到通知特征数据(命令和控制)")
// 判断数据类型
when {
// 测试:唤醒词OTA升级通知 (0x20-0x2F开头)
data.isNotEmpty() && data[0] == BleConst.DEVICE_RESPONSE_HEADER && data[1] >= 0x20 -> {
wakeupVoicesUpgradeSender.processDeviceNotification(data)
}
// 设备响应 (0xBB开头)
data.isNotEmpty() && data[0] == BleConst.DEVICE_RESPONSE_HEADER -> {
commandSender.processDeviceResponse(data)

14
local_plugins/ble_service/android/src/main/kotlin/com/yunqiinnovation/ble_service/BleWakeupVoicesUpgradeSender.kt

@ -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")

Loading…
Cancel
Save