feat: 主动上报时间量 — 补齐车间距时间 (gap time)

- Loop154_Unit 新增 last_exit_tick 字段,记录上次离场时间戳
- 进场: misc_value = 车间距 (report_counter - last_exit_tick), 首车为0
- 离场 (flatness/cnt_release): 记录 last_exit_tick, misc_value = 通过时间
- 有限存在超时: 也记录 last_exit_tick, 确保下一辆车车间距正确

四通道独立计算, 单位 5ms tick
This commit is contained in:
wangfq
2026-07-03 09:13:39 +08:00
parent 67a54bded3
commit 9fae087fed
2 changed files with 11 additions and 3 deletions

View File

@@ -181,7 +181,8 @@ typedef struct {
/*--- 主动上报杂项计数 ---*/ /*--- 主动上报杂项计数 ---*/
uint32_t flow_count; // 车流量累计 uint32_t flow_count; // 车流量累计
uint32_t relay_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; // 当前要上报的杂项值 uint32_t misc_value; // 当前要上报的杂项值
} Loop154_Unit; } Loop154_Unit;

View File

@@ -313,6 +313,7 @@ void TMR15_GLOBAL_IRQHandler(void)
unit->loop_stable = 0; unit->loop_stable = 0;
unit->loop_ORG_CNT = 0; unit->loop_ORG_CNT = 0;
unit->loop_ORG_SUM = 0; unit->loop_ORG_SUM = 0;
unit->last_exit_tick = g_loop_states.report_counter;
#if USE_FLATNESS_EXIT #if USE_FLATNESS_EXIT
unit->exit_state = 0; unit->exit_state = 0;
unit->max_slope = 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_cnt = 0;
unit->loop_freeze_ref = 0; unit->loop_freeze_ref = 0;
/* 主动上报: 车流量+1, 继电器+1, 记录进场时间戳 */ /* 主动上报: 车流量+1, 继电器+1, 车间距, 记录进场时间戳 */
unit->flow_count++; unit->flow_count++;
unit->relay_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->passtime_start = g_loop_states.report_counter; // 5ms tick
unit->misc_value = 0; // 车间距将在离开时计算
if (unit->hold_time > 0) { if (unit->hold_time > 0) {
unit->loop_VD_HOLD = 1; unit->loop_VD_HOLD = 1;
} }
@@ -605,6 +610,7 @@ void vd1_task_per_channel(Loop154_Unit *unit)
/* 主动上报: 计算通过时间 = 当前-进场时间戳 (5ms单位) */ /* 主动上报: 计算通过时间 = 当前-进场时间戳 (5ms单位) */
unit->misc_value = g_loop_states.report_counter - unit->passtime_start; unit->misc_value = g_loop_states.report_counter - unit->passtime_start;
unit->last_exit_tick = g_loop_states.report_counter;
unit->relay_count++; // 离开时继电器翻转 unit->relay_count++; // 离开时继电器翻转
} }
} else { } 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->misc_value = g_loop_states.report_counter - unit->passtime_start;
unit->last_exit_tick = g_loop_states.report_counter;
unit->relay_count++; unit->relay_count++;
} }
} else { } else {