feat(iot_mqtt): 快速上报增加 car_state 翻转沿触发

- Step2: 任一通道 |variation|>=阈值 或 car_state 翻转沿, 均进入 300ms 快速档
  (高灵敏度档小车 variation 可能不过阈值, 但 Loop 已判翻转, 事件不应慢发)
- 修复首版两坑: if(fast_mode=0) 单等号致沿检测死代码;
  快照刷新移到间隔门控之后, 防止沿被门控吞掉后退化为空闲慢发
- gcc 隔离单测: buggy 沿后延迟 950ms vs fixed 250ms, 出车沿/负向variation回归通过
- devlog 补 2026-07-15 条目
This commit is contained in:
wangfq
2026-07-15 09:34:04 +08:00
parent 964d619f10
commit dc7dd1cb26
2 changed files with 47 additions and 2 deletions
@@ -381,6 +381,7 @@ static void iot_process_recv(void) {
* Step 3 — 间隔门控: 时间到了才从缓存发布
*===========================================================================*/
void iot_mqtt_publish_sensor(void) {
static uint8_t _last_car_state[4] = {0};
if (g_iot_state != IOT_STATE_READY) return;
if (!g_report_cfg.enable) return;
@@ -405,7 +406,7 @@ void iot_mqtt_publish_sensor(void) {
/* 尚无缓存数据 → 不发 */
if (!_cached_sr_valid) return;
/*--- Step 2: 判断是否进入变化态 (任一通道 diff >= 10) ---*/
/*--- Step 2: 判断是否进入变化态 (任一通道 |variation|>=阈值, 或 car_state 翻转沿) ---*/
uint32_t interval_ms;
uint8_t fast_mode = 0;
@@ -419,6 +420,12 @@ void iot_mqtt_publish_sensor(void) {
fast_mode = 1;
break;
}
/* car_state 翻转沿(进车/出车) 同样触发快速上报
注: 能走到这里 fast_mode 必为 0 (置 1 即 break), 无需再判 */
if (_last_car_state[i] != _cached_sr.coils[i].car_state) {
fast_mode = 1;
break;
}
}
}
@@ -436,11 +443,21 @@ void iot_mqtt_publish_sensor(void) {
uint32_t now = mstick();
if (_last_publish_ms != 0
&& (now - _last_publish_ms) < interval_ms) {
return; // 未到间隔
return; // 未到间隔; _last_car_state 不刷新, 翻转沿保持"待发", 持续顶住 fast_mode
}
_last_publish_ms = now;
}
/* 确定发布 → 刷新 car_state 快照。必须放在门控之后:
若放门控前, 沿被门控吞掉时快照已刷新, 下一轮检测不到翻转,
事件退化为空闲间隔上报, 快速上报失效 */
{
uint8_t i;
for (i = 0; i < _cached_sr.coil_count; i++) {
_last_car_state[i] = _cached_sr.coils[i].car_state;
}
}
/*--- Step 4: 构建 JSON → 发布 (字段与 V1.02 协议一致) ---*/
static char data_json[1024];
static char payload[1400];