From d5ca5966f4b27d684ad81d0bfca9366b2ecde687 Mon Sep 17 00:00:00 2001 From: tanjianbin <632190820@qq.com> Date: Tue, 21 Apr 2026 11:11:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=8E=A5=E5=BE=85?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E9=80=BB=E8=BE=91=E5=B9=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=97=A8=E6=8E=A7=E5=B7=A5=E4=BD=9C=E6=B5=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 减少重置当前任务的动作集合,仅对显式导航/终止命令中断任务 - 修复接待任务中空位置导致任务异常的问题,增加参数校验与默认值处理 - 优化接待任务中位置匹配逻辑,忽略前后空格并修正状态处理流程 - 修复门控工作流执行时配置缺失的问题,添加服务器配置刷新机制 --- .../lzwcai_terminal_temi/MainActivity.kt | 47 +++++++++++++++++-- .../lzwcai_terminal_temi/MqttManager.kt | 9 ++-- .../lzwcai_terminal_temi/TaskController.kt | 30 ++++++++---- 3 files changed, 70 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/com/example/lzwcai_terminal_temi/MainActivity.kt b/app/src/main/java/com/example/lzwcai_terminal_temi/MainActivity.kt index 8fe638b..45475ef 100644 --- a/app/src/main/java/com/example/lzwcai_terminal_temi/MainActivity.kt +++ b/app/src/main/java/com/example/lzwcai_terminal_temi/MainActivity.kt @@ -99,6 +99,7 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG private var autoRechargeJob: Job? = null private var latestYaw: Float? = null private var receptionAnchorYaw: Float? = null + private var lastWorkflowConfigRefreshAt: Long = 0L private lateinit var telemetryManager: TelemetryManager private lateinit var taskController: TaskController private val robotEventHandler = RobotEventHandler() @@ -800,10 +801,19 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG private suspend fun executeDoorWorkflow(openDoor: Boolean): String? { val workflowIdKey = if (openDoor) HttpManager.PREF_KEY_OD_WFID else HttpManager.PREF_KEY_CD_WFID val workflowApiKey = if (openDoor) HttpManager.PREF_KEY_OD_WF_KEY else HttpManager.PREF_KEY_CD_WF_KEY - val workflowId = prefs.getString(workflowIdKey, "").orEmpty().trim() - val apiKey = prefs.getString(workflowApiKey, "").orEmpty().trim() + var workflowId = prefs.getString(workflowIdKey, "").orEmpty().trim() + var apiKey = prefs.getString(workflowApiKey, "").orEmpty().trim() if (workflowId.isEmpty() || apiKey.isEmpty()) { - Log.w("MainActivity", "Door workflow config missing: openDoor=$openDoor") + refreshWorkflowConfigsIfNeeded() + workflowId = prefs.getString(workflowIdKey, "").orEmpty().trim() + apiKey = prefs.getString(workflowApiKey, "").orEmpty().trim() + } + if (workflowId.isEmpty() || apiKey.isEmpty()) { + Log.w( + "MainActivity", + "Door workflow config missing after refresh: openDoor=$openDoor, " + + "workflowIdKey=$workflowIdKey, workflowApiKey=$workflowApiKey" + ) return null } return HttpManager.workflow_execute( @@ -814,6 +824,37 @@ class MainActivity : AppCompatActivity(), OnRobotReadyListener, TtsListener, OnG ) } + private suspend fun refreshWorkflowConfigsIfNeeded() { + val now = System.currentTimeMillis() + if (now - lastWorkflowConfigRefreshAt < 5000L) { + return + } + lastWorkflowConfigRefreshAt = now + val runtimeConfigs = HttpManager.fetchRuntimeConfigs(this@MainActivity) ?: return + val workflowKeys = listOf( + HttpManager.PREF_KEY_OD_WFID, + HttpManager.PREF_KEY_OD_WF_KEY, + HttpManager.PREF_KEY_CD_WFID, + HttpManager.PREF_KEY_CD_WF_KEY + ) + val editor = prefs.edit() + var changed = false + for (key in workflowKeys) { + val value = runtimeConfigs[key]?.trim().orEmpty() + if (value.isEmpty()) { + continue + } + if (prefs.getString(key, "").orEmpty() != value) { + editor.putString(key, value) + changed = true + } + } + if (changed) { + editor.apply() + Log.i("MainActivity", "Workflow configs refreshed from server.") + } + } + private fun isActivated(): Boolean { if (!::prefs.isInitialized) { return false diff --git a/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt b/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt index d3bae7a..fc6b58f 100644 --- a/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt +++ b/app/src/main/java/com/example/lzwcai_terminal_temi/MqttManager.kt @@ -313,7 +313,8 @@ class MqttManager( private fun handleJsonCommand(obj: JSONObject) { val action = obj.optString("action", obj.optString("cmd", obj.optString("type", ""))).lowercase() - val actionsResetTask = setOf("recharge", "goto", "notification", "reception", "patrol", "repose", "turn", "tilt", "terminate") + // Only interrupt current task for explicit navigation/termination commands. + val actionsResetTask = setOf("recharge", "goto", "terminate") if (action in actionsResetTask) { scope.launch(Dispatchers.Main) { onSetCurrentTask("") @@ -424,9 +425,9 @@ class MqttManager( } "reception" -> { speak("接到接待任务", "zh") - val location = obj.optString("location", "前台") - val text = obj.optString("text", "你是我要接待的贵宾吗?") - val destination = obj.optString("destination", "会议室") + val location = obj.optString("location", "前台").trim() + val text = obj.optString("text", "你是我要接待的贵宾吗?").trim() + val destination = obj.optString("destination", "会议室").trim() scope.launch(Dispatchers.Main) { onStartReceptionMode(location, text, destination) } diff --git a/app/src/main/java/com/example/lzwcai_terminal_temi/TaskController.kt b/app/src/main/java/com/example/lzwcai_terminal_temi/TaskController.kt index ed17fa1..34eb8dc 100644 --- a/app/src/main/java/com/example/lzwcai_terminal_temi/TaskController.kt +++ b/app/src/main/java/com/example/lzwcai_terminal_temi/TaskController.kt @@ -120,14 +120,21 @@ class TaskController( } fun startReceptionMode(location: String, text: String, destination: String) { + val targetLocation = location.trim() + val promptText = text.trim() + val targetDestination = destination.trim() + if (targetLocation.isEmpty()) { + setCurrentTask("") + return + } setCurrentTask("reception") - receptionLocation = location - receptionText = text - receptionDestination = destination + receptionLocation = targetLocation + receptionText = promptText.ifEmpty { "你是我要接待的贵宾吗?" } + receptionDestination = targetDestination isReceptionPromptVisible = false setReceptionButtonVisible(false) - if (getLastArrivalLocation() != location) { - navController.goTo(location, false) + if (getLastArrivalLocation()?.trim()?.equals(targetLocation, ignoreCase = true) != true) { + navController.goTo(targetLocation, false) } else { startTaskWaitTimeout() } @@ -177,9 +184,13 @@ class TaskController( speak("别妨碍我,我正在巡逻呢") return true } - if (currentTask == "reception" && - getLastArrivalLocation()?.equals(receptionLocation, ignoreCase = true) == true - ) { + if (currentTask == "reception") { + val isAtReceptionLocation = getLastArrivalLocation()?.trim() + ?.equals(receptionLocation, ignoreCase = true) == true + if (!isAtReceptionLocation) { + // Not at reception spot yet, let upper layer continue default behavior. + return false + } when (state) { DETECTED -> { startTaskWaitTimeout() @@ -194,8 +205,9 @@ class TaskController( setReceptionButtonVisible(false) } } + return true } - return currentTask == "reception" + return false } fun endNonSpecialTask(reason: String) {