feat(vd960Air): 方案 C MVP — 0x7F 帧解析 + 标准 JSON 上报(2026-08-31)

协议依据:《DLD960_IoT_MQTT协议》V1.13(4G 通道适配方案 C)

新增模块:
- frame_parser.lua: 0x7F 帧解析状态机(Lua 版 lup_feed_byte, XOR+SUM 校验)
- proto_conv.lua: 0xC0 传感帧 → loop_data + car_state/loop_state 沿检测(4 类线圈事件)
- evt_queue.lua: event_report 队列 + ACK 状态机(16深/5s×3/跨重连同 msg_id,对齐 DBN)
- clock.lua: report_config 时钟校准(协议 §2.3)
- app_iot.lua: initialize(extra_info imei/iccid + link)/ heartbeat / poll 驱动
- tools/sim_frame_test.py: 帧协议参考验证(56B 帧/4 路解析/沿检测/JSON 格式,全过)

改造:
- uart_app.lua: 0x7D 帧 → 0x7F 帧驱动;loop_data/event_report 组包 + link 注入
- mqtt_receiver.lua: 下行分发(ACK 路由 + 时钟校准)
- mqtt_main.lua: 连接成功 → initialize + 未决事件重发
- config.lua/main.lua: 方案 C 配置与入口

MVP 范围: 上行(initialize/loop_data/event_report/heartbeat)+ report_config;
下行命令转换与 0x7D 配置同步列入 P1。
This commit is contained in:
wangfq
2026-08-31 15:47:43 +08:00
parent 6d763f02fe
commit 3ad7ae8f09
11 changed files with 796 additions and 207 deletions
@@ -0,0 +1,44 @@
--[[
@module clock
@summary 设备时钟: 平台 report_config 校准后输出真实 Unix 秒
@version 0.1
@date 2026.08.31
@usage
对齐《DLD960_IoT_MQTT协议》§2.3 时钟同步语义:
- 未校准: 返回上电秒数(mstick()/1000,值很小,平台识别"未校准")
- 校准: base_unix + (now_ms - base_ms)/1000(真实 Unix 秒)
- 合法性门槛 ≥1600000000(2020-09 之后),非法值忽略
- 重启后需重新校准(无掉电保持)
]]
local clock = {}
local base_unix = 0
local base_ms = 0
-- 校准(平台 report_config 下发 ts 时调用)
-- @param unix_ts number: 平台下发的 Unix 秒
-- @param now_ms number: 当前 mstick()
function clock.sync(unix_ts, now_ms)
if not unix_ts or unix_ts < 1600000000 then
return -- 非法值忽略
end
base_unix = unix_ts
base_ms = now_ms or mstick()
end
-- 当前 Unix 秒(未校准返回上电秒数)
function clock.now(now_ms)
now_ms = now_ms or mstick()
if base_unix >= 1600000000 then
return base_unix + math.floor((now_ms - base_ms) / 1000)
end
return math.floor(now_ms / 1000)
end
-- 是否已校准
function clock.synced()
return base_unix >= 1600000000
end
return clock