diff --git a/BLE/DLD110S_Peripheral_28K/APP/peripheral_main.c b/BLE/DLD110S_Peripheral_28K/APP/peripheral_main.c index 7b4f0e0..fcd2ae3 100644 --- a/BLE/DLD110S_Peripheral_28K/APP/peripheral_main.c +++ b/BLE/DLD110S_Peripheral_28K/APP/peripheral_main.c @@ -53,6 +53,7 @@ uint32_t g_sys_freq = 0; const uint8_t MAX_Store_Size = 80; uint8_t g_loop_power_up_state = 0; // 开机启动时线圈是否连接 +uint8_t g_disconnect_active = 0; // 当前线圈是否断开中 (1=断开) __IO uint32_t TimingDelayInc; /*=========================================================================== @@ -68,7 +69,7 @@ __IO uint32_t TimingDelayInc; #define ENTRY_CONFIRM 3 // 进入确认: 连续 N 次低于阈值才判有车 #define FREEZE_TIMEOUT 1000 // 基线冻结超时: ~8.7s, 持续偏高且稳定后强制更新 #define FREEZE_STABILITY_RATE 2 // 冻结稳定性窗口: 参考值 +-2% -#define USE_FLATNESS_EXIT 1 // 1=平坦性三条件离开, 0=简单滞回防抖 +// #define USE_FLATNESS_EXIT 1 // 1=平坦性三条件离开, 0=简单滞回防抖 #define WINDOW_ORIGIN 500 // 基线跟踪窗口 (500 窗 ~= 4.4s) #define STABLE_SAMPLES 128 // 稳定期样本数 (~1.1s) #define VARIATION_EVENT_TH 40 // BLE variation 事件阈值 (幅值基准 2^19, 对应旧代码的 5) @@ -311,7 +312,7 @@ void para_store_init(void) poll_sens_key(); g_loop_out_delay = g_loop_cng_unit.delay_time * 2; // 定时器以 50ms 为单位, 延时以100ms为单位 - g_hold_time = g_loop_cng_unit.exist_mode * 30 * 20; //50ms/per, 30s + g_hold_time = g_loop_cng_unit.exist_mode * 20 * 5; //50ms/per, period: 5s g_safe_max_cnt = g_loop_cng_unit.loopSafe_Timeout * 10 * (1000 / 50); g_freq_level = g_loop_cng_unit.loopFreq_Level - 1; g_function_mode = g_loop_cng_unit.direction_mode >> 4; @@ -487,6 +488,7 @@ void INIT_VD(void) loop1_FLAG_PLUSE_IN = 0; loop1_FLAG_CUT = 0; loop1_FLAG_HOLD_TIMEOUT = 0; + g_disconnect_active = 0; loop1_VD_HOLD = 0; Hold_CNT = 0; @@ -773,9 +775,16 @@ void cjq_srv(void){ return; } if(loop1_FLAG_CUT){ - /* 线圈断开后重连: 全复位, 重新自适应测量窗并重建基线 */ - g_loop_cut_last = 0; - INIT_VD(); + /* 线圈断开后重连: 不丢 VD_FLAG, CAPVD=0 直锁首个样本快速收敛 */ + g_disconnect_active = 0; + loop1_FLAG_CUT = 0; + loop1_CAPVD = 0; // 首个样本直锁, 跳过 IIR + loop1_ORG_CNT = 0; // 丢弃断开期间过期数据 + loop1_ORG_SUM = 0; + if(loop1_Origin == 0) { + /* Origin 意外丢失: 全复位 (不应发生, 做防御) */ + INIT_VD(); + } return; } if(!loop1_LOOP_OK0){ @@ -793,14 +802,15 @@ void cjq_srv(void){ }// end if loop1_LOOP_OK else{ loop1_FLAG_CUT = 1; - loop1_VD_FLAG = 0; + g_disconnect_active = 1; + // 不丢 VD_FLAG (保留有车状态, 重连后恢复) loop1_FLAG_IN = 0; loop1_FLAG_OUT = 0; loop1_FLAG_PLUSE = 0; loop1_FLAG_PLUSE_IN_F = 0; loop1_FLAG_PLUSE_IN = 0; - // 线圈断开: 继电器释放, 车辆状态清零 + // 线圈断开: 继电器释放 RLY1_OFF; RLY2_OFF; g_loop_acs_info.relay1_state = 0; g_loop_acs_info.relay2_state = 0; @@ -810,8 +820,8 @@ void cjq_srv(void){ g_loop_cut_last = loop1_FLAG_CUT; if(g_loop_power_up_state){ g_loop_cut_amount++; - if(g_loop_cut_amount >= 255){ - g_loop_cut_amount = 255; + if(g_loop_cut_amount > 3){ + g_loop_cut_amount = 3; } } } @@ -1021,23 +1031,22 @@ void TMR1_IRQHandler(void) TimingDelayInc++; u32CountWdt++; - /*--- LED: 稳定期 200ms 快闪; 线圈断开 150ms 快闪 ---*/ - if(loop1_FLAG_CUT == 0) + /*--- LED: 断开中 200ms 快闪; 稳定期 200ms 慢闪 ---*/ + if(g_disconnect_active || !g_loop_power_up_state) { - if(!g_loop_stable) + /* 线圈断开中 / 上电从未连接 → 200ms 快闪 (故障指示) */ + _counter1_init++; + if(_counter1_init >= 40) // 40: 200ms { - _counter1_init++; - if(_counter1_init >= 40) // 40: 200ms - { - _counter1_init = 0; - LEDA_ON_OFF(); - } + _counter1_init = 0; + LEDA_ON_OFF(); } } - else + else if(!g_loop_stable) { + /* 稳定期 → 200ms 慢闪 (自检中) */ _counter1_init++; - if(_counter1_init >= 30) // 30: 150ms + if(_counter1_init >= 40) // 40: 200ms { _counter1_init = 0; LEDA_ON_OFF();