diff --git a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h index 38f705d..f11facf 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h +++ b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h @@ -181,7 +181,8 @@ typedef struct { /*--- 主动上报杂项计数 ---*/ uint32_t flow_count; // 车流量累计 uint32_t relay_count; // 继电器动作次数 - uint32_t passtime_start; // 进场/离开 时间戳(5ms tick) + uint32_t passtime_start; // 进场 时间戳(5ms tick) + uint32_t last_exit_tick; // 上次离场 时间戳(5ms tick), 用于车间距计算 uint32_t misc_value; // 当前要上报的杂项值 } Loop154_Unit; diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c index d1fb294..1d26040 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c @@ -313,6 +313,7 @@ void TMR15_GLOBAL_IRQHandler(void) unit->loop_stable = 0; unit->loop_ORG_CNT = 0; unit->loop_ORG_SUM = 0; + unit->last_exit_tick = g_loop_states.report_counter; #if USE_FLATNESS_EXIT unit->exit_state = 0; unit->max_slope = 0; @@ -518,11 +519,15 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->loop_freeze_cnt = 0; unit->loop_freeze_ref = 0; - /* 主动上报: 车流量+1, 继电器+1, 记录进场时间戳 */ + /* 主动上报: 车流量+1, 继电器+1, 车间距, 记录进场时间戳 */ unit->flow_count++; unit->relay_count++; + if (unit->last_exit_tick > 0) { + unit->misc_value = g_loop_states.report_counter - unit->last_exit_tick; + } else { + unit->misc_value = 0; // 首次检测, 车间距为0 + } unit->passtime_start = g_loop_states.report_counter; // 5ms tick - unit->misc_value = 0; // 车间距将在离开时计算 if (unit->hold_time > 0) { unit->loop_VD_HOLD = 1; } @@ -605,6 +610,7 @@ void vd1_task_per_channel(Loop154_Unit *unit) /* 主动上报: 计算通过时间 = 当前-进场时间戳 (5ms单位) */ unit->misc_value = g_loop_states.report_counter - unit->passtime_start; + unit->last_exit_tick = g_loop_states.report_counter; unit->relay_count++; // 离开时继电器翻转 } } else { @@ -636,6 +642,7 @@ void vd1_task_per_channel(Loop154_Unit *unit) /* 主动上报: 通过时间 + 继电器 */ unit->misc_value = g_loop_states.report_counter - unit->passtime_start; + unit->last_exit_tick = g_loop_states.report_counter; unit->relay_count++; } } else {