From 574395258f8af6d9442f003171ab2ef003ff789a Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Sat, 16 May 2026 14:31:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=A7=BB=E5=8A=A8=E9=9C=80?= =?UTF-8?q?=E6=B1=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/services/ble_manager.dart | 9 ++++++++- lib/modules/devices/views/devices_view.dart | 8 +++----- .../agent_service/AgentService.kt | 7 ++++++- .../yunqiinnovation/agent_service/StsAgent.kt | 15 ++++++++++++--- .../agent_service/AgentServiceImpl.swift | 3 ++- .../Sources/agent_service/StsAgent.swift | 18 +++++++++++++----- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/lib/data/services/ble_manager.dart b/lib/data/services/ble_manager.dart index c333607fd..61dac4a4c 100644 --- a/lib/data/services/ble_manager.dart +++ b/lib/data/services/ble_manager.dart @@ -977,7 +977,13 @@ class BleManager extends GetxService { ); stsCmei = matchedDevice.cmei; } catch (_) {} - Logger.i('BleManager', '当前设备 CMEI: $stsCmei (MAC=$mac)'); + // 当前连接设备的固件版本:原始为 "L1.L2.L3.R1.R2.R3",取左 3 段作为单一版本 + final rawFw = deviceInfo.value?.firmwareVersion ?? ''; + final fwParts = rawFw.split('.'); + final stsFirmwareVersion = + fwParts.length >= 3 ? fwParts.take(3).join('.') : rawFw; + Logger.i('BleManager', + '当前设备 CMEI: $stsCmei (MAC=$mac) firmware=$stsFirmwareVersion'); final config = { // STS 模式路由 @@ -990,6 +996,7 @@ class BleManager extends GetxService { 'stsDeviceSecret': stsDeviceSecret, 'stsCmei': stsCmei, 'stsMac': mac, + 'stsFirmwareVersion': stsFirmwareVersion, // 语音代理配置参数 'azureSpeechKey': azureSpeechKey, 'azureSpeechRegion': azureSpeechRegion, diff --git a/lib/modules/devices/views/devices_view.dart b/lib/modules/devices/views/devices_view.dart index 4e710fd13..c7a24538e 100644 --- a/lib/modules/devices/views/devices_view.dart +++ b/lib/modules/devices/views/devices_view.dart @@ -504,12 +504,10 @@ class DevicesView extends GetView { final info = bleManager.deviceInfo.value; final fwVersion = connected ? (info?.firmwareVersion ?? '') : ''; - // 固件版本格式:左 3 段 + 右 3 段,拼成 "0.0.1.0.0.1";按 6 段拆左右 + // 固件版本原始格式:左 3 段 + 右 3 段("0.0.1.0.0.1"),只展示左版本 final parts = fwVersion.split('.'); - final hasLeftRight = parts.length >= 6; - final fwDisplay = hasLeftRight - ? 'L ${parts.take(3).join('.')} · R ${parts.skip(3).take(3).join('.')}' - : fwVersion; + final fwDisplay = + parts.length >= 3 ? parts.take(3).join('.') : fwVersion; final hasFirmware = fwVersion.isNotEmpty; final hasLicense = device.license.isNotEmpty; final hasCmei = device.cmei.isNotEmpty; diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt index c335e5aaa..029bfa8c1 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt @@ -497,6 +497,7 @@ object AgentService : CoroutineScope { agentId = agentId, cmei = config["stsCmei"]?.toString() ?: "", mac = config["stsMac"]?.toString() ?: "", + firmwareVersion = config["stsFirmwareVersion"]?.toString() ?: "", ) stsAgent = StsAgent( context = context, @@ -632,7 +633,7 @@ object AgentService : CoroutineScope { config["mcpServer"]?.toString() ?: "", config["musicServiceType"]?.toString() ?: "" ) - // 更新 STS 模式参数(cmei / mac 等可能在首次初始化时尚未获取到) + // 更新 STS 模式参数(cmei / mac / firmwareVersion 等可能在首次初始化时尚未获取到) val newCmei = config["stsCmei"]?.toString() ?: "" if (newCmei.isNotEmpty()) { stsAgent?.updateCmei(newCmei) @@ -641,6 +642,10 @@ object AgentService : CoroutineScope { if (newMac.isNotEmpty()) { stsAgent?.updateMac(newMac) } + val newFirmwareVersion = config["stsFirmwareVersion"]?.toString() ?: "" + if (newFirmwareVersion.isNotEmpty()) { + stsAgent?.updateFirmwareVersion(newFirmwareVersion) + } } catch (e: Exception) { _log("ERROR", "[Agent] 应用配置更新失败: ${e.message}") } diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/StsAgent.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/StsAgent.kt index 6ff8eaea7..d3c279494 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/StsAgent.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/StsAgent.kt @@ -42,6 +42,7 @@ data class StsConfig( val agentId: String, val cmei: String = "", val mac: String = "", + val firmwareVersion: String = "", ) /** @@ -62,7 +63,7 @@ class StsAgent( override val coroutineContext = Dispatchers.IO + job init { - Log.i(TAG, "[YIDONG] StsAgent初始化: productId=${config.productId} deviceNo=${config.deviceNo} deviceId=${config.deviceId} agentId=${config.agentId} cmei=${config.cmei} mac=${config.mac} hasSecret=${config.deviceSecret.isNotEmpty()}") + Log.i(TAG, "[YIDONG] StsAgent初始化: productId=${config.productId} deviceNo=${config.deviceNo} deviceId=${config.deviceId} agentId=${config.agentId} cmei=${config.cmei} mac=${config.mac} firmwareVersion=${config.firmwareVersion} hasSecret=${config.deviceSecret.isNotEmpty()}") fetchCredentials() } @@ -82,6 +83,14 @@ class StsAgent( } } + /** 动态更新固件版本(设备连接后由 BLE 上报,首次初始化时通常尚未获取到) */ + fun updateFirmwareVersion(firmwareVersion: String) { + if (firmwareVersion.isNotEmpty() && firmwareVersion != config.firmwareVersion) { + config = config.copy(firmwareVersion = firmwareVersion) + Log.i(TAG, "[YIDONG] updateFirmwareVersion: firmwareVersion已更新为 $firmwareVersion") + } + } + // ── WebSocket ───────────────────────────────────────────────────────────── private val okHttpClient: OkHttpClient = buildTrustAllClient() private var webSocket: WebSocket? = null @@ -247,7 +256,7 @@ class StsAgent( return } prefs.edit().putLong("last_heartbeat_ts", now).apply() - Log.i(TAG, "[YIDONG] reportHeartbeat: 开始上报 deviceId=${config.deviceId} deviceNo=${config.deviceNo} cmei=${config.cmei} mac=${config.mac}") + Log.i(TAG, "[YIDONG] reportHeartbeat: 开始上报 deviceId=${config.deviceId} deviceNo=${config.deviceNo} cmei=${config.cmei} mac=${config.mac} firmwareVersion=${config.firmwareVersion}") launch { try { val netType = try { @@ -272,7 +281,7 @@ class StsAgent( put("netType", netType) put("platform", "") put("sdkVersion", "ai_http_1.0") - put("firmwareVersion", "1.0.0") + put("firmwareVersion", config.firmwareVersion) // 当前连接设备的固件版本(左 3 段) put("imei", "") put("cmei", config.cmei) // 优先使用 UserDevice 的 CMEI put("mac", config.mac) // 当前连接的 BLE 设备 MAC(由 Flutter 透传) diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift index 80af5c5b7..d6bfe9487 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift @@ -272,7 +272,8 @@ class AgentServiceImpl: NSObject { deviceSecret: config["stsDeviceSecret"] as? String ?? "", agentId: agentId, cmei: config["stsCmei"] as? String ?? "", - mac: config["stsMac"] as? String ?? "" + mac: config["stsMac"] as? String ?? "", + firmwareVersion: config["stsFirmwareVersion"] as? String ?? "" ) stsAgent = StsAgent( config: stsConfig, diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/StsAgent.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/StsAgent.swift index d5218631b..25427dde8 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/StsAgent.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/StsAgent.swift @@ -16,6 +16,7 @@ struct StsConfig { let agentId: String var cmei: String = "" var mac: String = "" + var firmwareVersion: String = "" } // MARK: - StsAgent @@ -88,9 +89,9 @@ class StsAgent: NSObject { super.init() let sessionConfig = URLSessionConfiguration.default urlSession = URLSession(configuration: sessionConfig, delegate: nil, delegateQueue: OperationQueue()) - os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ mac=%{public}@ hasSecret=%{public}@", + os_log("StsAgent 初始化: productId=%{public}@ deviceNo=%{public}@ deviceId=%{public}@ cmei=%{public}@ mac=%{public}@ firmwareVersion=%{public}@ hasSecret=%{public}@", log: logger, type: .info, - config.productId, config.deviceNo, config.deviceId, config.cmei, config.mac, + config.productId, config.deviceNo, config.deviceId, config.cmei, config.mac, config.firmwareVersion, config.deviceSecret.isEmpty ? "false" : "true") // 与 Android 行为对齐:凭证已有时立即尝试上报一次心跳(受 1 小时冷却保护) if !config.deviceSecret.isEmpty && !config.deviceId.isEmpty { @@ -113,6 +114,13 @@ class StsAgent: NSObject { os_log("updateMac: mac 已更新为 %{public}@", log: logger, type: .info, mac) } + /// 动态更新固件版本(设备连接后由 BLE 上报,首次初始化时通常尚未获取到) + func updateFirmwareVersion(_ firmwareVersion: String) { + guard !firmwareVersion.isEmpty, firmwareVersion != config.firmwareVersion else { return } + config.firmwareVersion = firmwareVersion + os_log("updateFirmwareVersion: firmwareVersion 已更新为 %{public}@", log: logger, type: .info, firmwareVersion) + } + // MARK: - 公共接口 func startCall() { @@ -241,8 +249,8 @@ class StsAgent: NSObject { return } defaults.set(now, forKey: HEARTBEAT_PREFS_KEY) - os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@ mac=%{public}@", - log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei, config.mac) + os_log("reportHeartbeat: 开始上报 deviceId=%{public}@ deviceNo=%{public}@ cmei=%{public}@ mac=%{public}@ firmwareVersion=%{public}@", + log: logger, type: .info, config.deviceId, config.deviceNo, config.cmei, config.mac, config.firmwareVersion) let urlStr = "https://ivs.chinamobiledevice.com:11443/v2/customer/device/report" guard let url = URL(string: urlStr) else { return } @@ -257,7 +265,7 @@ class StsAgent: NSObject { "netType": "WiFi", "platform": "", "sdkVersion": "ai_http_1.0", - "firmwareVersion": "1.0.0", + "firmwareVersion": config.firmwareVersion, "imei": "", "cmei": config.cmei, "mac": config.mac,