Просмотр исходного кода

为防止预加热重复下发,这里做限制,当设备处于预加热的时候,下发开始预加热会失败

zhanghongyi 1 месяц назад
Родитель
Сommit
a65261ddae
4 измененных файлов с 53 добавлено и 12 удалено
  1. 2 1
      App/App/Inc/App_preheat.h
  2. 24 8
      App/App/Src/App_pc.c
  3. 17 0
      App/App/Src/App_preheat.c
  4. 10 3
      App/LVGL8v3/ui/Ui_temp_setting.c

+ 2 - 1
App/App/Inc/App_preheat.h

@@ -50,8 +50,9 @@ void App_preheat_task_create(void);
 
 /**
  * @brief  发送控制命令 (生产者接口: 屏端/上位机共用)
+ * @note   预热运行中再下发 START 会被拒绝 (互斥), 返回 pdFAIL
  * @param  cmd : 命令结构体指针
- * @return pdPASS 成功, pdFAIL 失败 (队列满或参数非法)
+ * @return pdPASS 成功, pdFAIL 失败 (队列满 / 参数非法 / 预热已在跑)
  */
 BaseType_t App_preheat_send_cmd(app_preheat_cmd_t *cmd);
 

+ 24 - 8
App/App/Src/App_pc.c

@@ -67,7 +67,9 @@ TaskHandle_t xPCTaskHandle = NULL;
  * @brief  处理 0x01 设置目标温度命令
  * @note   保存到 EEPROM 参数 (等效 UI Apply); 成功后自动启动预加热
  *         (APP_PREHEAT_CMD_START, 携带目标温度) 并切换屏幕到预加热页面。
- *         CPLD 失联 / BMC 未就绪 / 越界 / 写入失败都回 0x81 FAIL, 不触发预加热。
+ *         CPLD 失联 / BMC 未就绪 / 预热运行中 / 越界 / 写入失败都回 0x81 FAIL,
+ *         不触发预加热。预热运行中整条拒绝 ⇒ 目标温度也不写 EEPROM, 避免
+ *         把正在跑的这一轮目标值偷偷改掉。
  * @param  payload : 载荷指针 (长度 1, temp)
  * @param  plen    : 载荷长度
  * @return 无
@@ -90,6 +92,12 @@ static void App_Pc_HandleSetTarget(const uint8_t *payload, uint8_t plen)
     {
         LOG_PRINTF("[ERR] PC: set target rejected, BMC not ready\r\n");
     }
+    /* 预热互斥: 已在预热中不许再来一条 0x01 —— 它会连带重新 START,
+     * 把正在跑的目标温度换掉、并打断当前输出。与 0x07 的判据一致 */
+    else if (App_preheat_is_running())
+    {
+        LOG_PRINTF("[ERR] PC: set target rejected, preheat running\r\n");
+    }
     else if (plen >= 1)
     {
         uint8_t temp = payload[0];
@@ -99,18 +107,26 @@ static void App_Pc_HandleSetTarget(const uint8_t *payload, uint8_t plen)
             {
                 app_preheat_cmd_t cmd;
 
-                status = COM_PC_STATUS_OK;
-                LOG_PRINTF("[OK] PC: set target=%d, start preheat\r\n", (int)temp);
-
                 /* 自动启动预加热 (与 UI "Start preheating" 同路径) */
                 cmd.type   = APP_PREHEAT_CMD_START;
                 cmd.src    = APP_PREHEAT_SRC_UPPER;
                 cmd.target = (int16_t)temp;
-                App_preheat_send_cmd(&cmd);
 
-                /* 屏幕切到预加热页面 (线程安全: 投递到 LVGL 任务);
-                 * 页面已整体切换, 设置页显示无需另行刷新 */
-                Ui_preheat_enter_async();
+                /* 入队失败也要回 FAIL: 上面已判过"预热没在跑", 这里失败只剩
+                 * 队列满或两条 START 抢在任务处理前入队 (后者由任务侧拒) */
+                if (App_preheat_send_cmd(&cmd) == pdPASS)
+                {
+                    status = COM_PC_STATUS_OK;
+                    LOG_PRINTF("[OK] PC: set target=%d, start preheat\r\n", (int)temp);
+
+                    /* 屏幕切到预加热页面 (线程安全: 投递到 LVGL 任务);
+                     * 页面已整体切换, 设置页显示无需另行刷新 */
+                    Ui_preheat_enter_async();
+                }
+                else
+                {
+                    LOG_PRINTF("[ERR] PC: set target=%d, preheat start rejected\r\n", (int)temp);
+                }
             }
             else
             {

+ 17 - 0
App/App/Src/App_preheat.c

@@ -68,6 +68,15 @@ static int16_t  s_target = 0;
  */
 static void preheat_handle_start(const app_preheat_cmd_t *cmd)
 {
+    /* 互斥: 预热已在跑就拒绝。放行会把 s_target 换成新值, 等于中途偷改
+     * 目标温度, 还会再打一遍 pidControl_Stop 打断当前输出。
+     * 这一道兜的是"两条 START 都排在队列里、入队时都还没在跑"的窗口 */
+    if (s_state == PREHEAT_STATE_RUNNING)
+    {
+        LOG_PRINTF("[ERR] Preheat: start ignored, preheat running\r\n");
+        return;
+    }
+
     /* BMC 未就绪 (24 路全 0xFF, 如服务器还没开机完毕) 时不许预热。
      * UI 与上位机已各拦一道, 这里是兜底: 以后新加的入口也一并收住 */
     if (!Mid_Temp_IsBmcReady())
@@ -275,6 +284,14 @@ BaseType_t App_preheat_send_cmd(app_preheat_cmd_t *cmd)
         return pdFAIL;
     }
 
+    /* 预热互斥: 已在预热中再下发 START 直接回失败, 让调用方 (上位机应答 /
+     * 屏上按钮) 当场知道没受理, 不必等任务侧拒。任务侧还有一道同判据兜底 */
+    if ((cmd->type == APP_PREHEAT_CMD_START) && (s_state == PREHEAT_STATE_RUNNING))
+    {
+        LOG_PRINTF("[ERR] Preheat: start rejected, preheat running\r\n");
+        return pdFAIL;
+    }
+
     if (cmd->src == APP_PREHEAT_SRC_UPPER)
     {
         ret = xQueueSend(s_upper_q, cmd, 0);

+ 10 - 3
App/LVGL8v3/ui/Ui_temp_setting.c

@@ -268,16 +268,23 @@ static void ui_tset_msgbox_cb(lv_event_t * e)
     lv_obj_t * mbox = lv_event_get_current_target(e);
     if (lv_msgbox_get_active_btn(mbox) == 0)
     {
-        /* Yes: 通知预加热任务开始, 再进入预加热页面 */
+        /* Yes: 通知预加热任务开始, 再进入预加热页面。
+         * 预热已在跑时任务侧会拒 (互斥), 这里就不再切页 —— 否则屏幕会跳到
+         * 预热页而状态机其实没受理, 让人以为又开了一轮 */
         app_preheat_cmd_t cmd;
+        BaseType_t sent;
+
         cmd.type   = APP_PREHEAT_CMD_START;
         cmd.src    = APP_PREHEAT_SRC_UI;
         cmd.target = (int16_t)Com_parameter_get_target();
-        App_preheat_send_cmd(&cmd);
+        sent = App_preheat_send_cmd(&cmd);
 
         lv_msgbox_close(mbox);
         s_msgbox = NULL;
-        Ui_preheat_enter();
+        if (sent == pdPASS)
+        {
+            Ui_preheat_enter();
+        }
         return;
     }
     lv_msgbox_close(mbox);