diff --git a/apps/chrg/applications/utils/chrg_sink.c b/apps/chrg/applications/utils/chrg_sink.c index 9f89887..0912cc0 100644 --- a/apps/chrg/applications/utils/chrg_sink.c +++ b/apps/chrg/applications/utils/chrg_sink.c @@ -53,6 +53,8 @@ static rt_tick_t g_sink_unload_query_tick[TOTAL_SOU_CHS] = {0}; static rt_uint8_t g_sink_unload_confirm_count[TOTAL_SOU_CHS] = {0}; /* 记录各通道短路测试最近一次WORK_START的发送时间。 */ static rt_tick_t g_sink_short_start_tick[TOTAL_SOU_CHS] = {0}; +/* 锁存关机前的短路状态,防止关机过程中影子参数覆盖测试状态。 */ +static rt_bool_t g_sink_stop_from_short[TOTAL_SOU_CHS] = {RT_FALSE}; /* 只消费新的V_On电压采样,避免同一帧重复计入稳定确认。 */ static rt_uint32_t g_sink_von_voltage_seq[TOTAL_SOU_CHS] = {0}; /* 协议切换期间清零,避免旧电压样本累计成启动确认。 */ @@ -634,28 +636,40 @@ static int chrg_sink_work_low_aux_wait(eIDX_SOU_CH idx, 输入参数: idx:南向功率通道编号 pSW:当前通道控制结构体 输出参数: 清除运行、使能和在线标志,关闭北向继电器 返回说明: 0:关机成功 <0:停止命令提交失败 -其它说明: 先断开功率继电器并发送WORK_STOP,再关闭软件通道 +其它说明: 短路关机先退出短路再发送WORK_STOP,普通关机只发送WORK_STOP *****************************************************************/ static int chrg_sink_work_stop_prepare(eIDX_SOU_CH idx, struct chrg_switch_t *pSW) { - rt_uint16_t reg = REG_WORK; - rt_uint16_t value = WORK_STOP; + rt_uint16_t regs[2]; + rt_uint16_t values[2]; + rt_uint8_t count = 0U; + rt_bool_t was_short; if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) { return -1; } + was_short = (pSW->sink.test.test_mode_old == SINK_TEST_SHORT) || + (pSW->sink.test.test_mode == SINK_TEST_SHORT) || + g_sink_stop_from_short[idx]; + g_sink_stop_from_short[idx] = was_short; + if (was_short) { + regs[count] = ModbusRTU_ShortTest_CMD_MODE_FLAG; + values[count++] = ModbusRTU_DYNA_CMD_MODE_STOP; + } + regs[count] = REG_WORK; + values[count++] = WORK_STOP; g_sink_init_in_progress[idx] = RT_FALSE; g_sink_init_stage_submitted[idx] = RT_FALSE; if (chrg_sou_com_batch_cancel(idx) != 0) { return -1; } - if (chrg_sou_com_batch_submit(idx, ®, &value, 1U) != 0) { + if (chrg_sou_com_batch_submit(idx, regs, values, count) != 0) { return -1; } - /* 主动关机先停止电子负载。WORK_STOP收到匹配回码后,必须通过 - * 停止命令之后的新P1量测连续确认低电流,才允许断开功率继电器。 */ + /* 短路退出和WORK_STOP全部收到匹配回码后,必须通过停止命令之后的 + * 新P1量测连续确认低电流,才允许断开功率继电器。 */ chrg_sink_unload_confirm_reset(idx); pSW->sink.work_mode = SINK_WORK_STOP_WAIT; return 0; @@ -702,6 +716,10 @@ static int chrg_sink_work_stop_relay_wait(eIDX_SOU_CH idx, pNOR->enable[idx] = 0; g_sink_rel_main_closed[idx] = 0; g_sink_rel_main_ready[idx] = 0; + g_sink_short_start_tick[idx] = 0U; + g_sink_stop_from_short[idx] = RT_FALSE; + pSW->sink.test.test_mode = SINK_NO_TEST; + pSW->sink.test.test_mode_old = SINK_NO_TEST; chrg_nor_sw_rel((eIDX_NOR_CH)idx, 0); /* 主动停止已经完成,退出异步等待状态,禁止下一轮重复执行。 */