feat(vd960DBN): offlog TIME_ANCHOR 严格用平台下发 unix_ts

offlog_time_anchor 原丢弃传参内部重取 dev_time_now() (毫秒级误差),
改为 offlog_evt_ts() 直接写入平台下发值, 锚点事件与平台 ts 严格一致。
新增单测 test_time_anchor_exact, 7 例 ALL PASS
This commit is contained in:
wangfq
2026-08-04 18:10:18 +08:00
parent 2b1e888a73
commit 90755bf465
3 changed files with 30 additions and 4 deletions
@@ -212,11 +212,11 @@ static void offlog_write_raw(const OfflogEvt *e)
if (_count < OFFLOG_MAX_RECORDS) _count++; if (_count < OFFLOG_MAX_RECORDS) _count++;
} }
void offlog_evt(uint8_t type, const uint8_t *payload, uint8_t len) /* 内部: 支持外部指定 unix_ts (TIME_ANCHOR 用平台下发值, 严格一致) */
static void offlog_evt_ts(uint8_t type, const uint8_t *payload, uint8_t len, uint32_t unix_ts)
{ {
OfflogEvt e; OfflogEvt e;
uint32_t now = mstick(); uint32_t now = mstick();
uint32_t unix_ts = dev_time_now();
if (!_ready) return; if (!_ready) return;
@@ -237,6 +237,11 @@ void offlog_evt(uint8_t type, const uint8_t *payload, uint8_t len)
offlog_write_raw(&e); offlog_write_raw(&e);
} }
void offlog_evt(uint8_t type, const uint8_t *payload, uint8_t len)
{
offlog_evt_ts(type, payload, len, dev_time_now());
}
/*=========================================================================== /*===========================================================================
* 便捷事件包装 * 便捷事件包装
*===========================================================================*/ *===========================================================================*/
@@ -310,8 +315,7 @@ void offlog_coil(uint8_t sub, uint8_t ch, uint32_t value)
void offlog_time_anchor(uint32_t unix_ts) void offlog_time_anchor(uint32_t unix_ts)
{ {
(void)unix_ts; /* 值已过合法性门槛; offlog_evt 内经 dev_time_now() 重新取一致值 */ offlog_evt_ts(OFFLOG_EVT_TIME_ANCHOR, NULL, 0, unix_ts); /* 严格用平台下发值 */
offlog_evt(OFFLOG_EVT_TIME_ANCHOR, NULL, 0);
} }
/*=========================================================================== /*===========================================================================
+5
View File
@@ -711,10 +711,15 @@ TCP 超时要等 ~2 分钟才触发 `SINT_STAT_TIM_OUT`,
**附带收益**:栈上缓冲 2048→1024,每处省 1KB 栈(CH32V208 栈紧张,中断路径 832/1322 在回调/主循环调用)。 **附带收益**:栈上缓冲 2048→1024,每处省 1KB 栈(CH32V208 栈紧张,中断路径 832/1322 在回调/主循环调用)。
## 2026-08-04 — offlog: TIME_ANCHOR 严格使用平台下发 unix_ts
`offlog_time_anchor()` 原为丢弃传参、内部重取 `dev_time_now()`(毫秒级误差)。改为 `offlog_evt_ts()` 直接写入平台下发值,锚点事件与平台 ts **严格一致**。新增单测 `test_time_anchor_exact`(传 1800000000 验证写入值),7 例 ALL PASS。
## 修订记录 ## 修订记录
| 版本 | 时间 | 说明 | | 版本 | 时间 | 说明 |
|------|------|------| |------|------|------|
| V3.8 | 2026-08-04 | offlog: TIME_ANCHOR 严格用平台下发 unix_ts (offlog_evt_ts), 单测 7 例 |
| V3.7 | 2026-08-04 | tcp_json_srv 缓冲宏化: data_json[2048]→TCP_JSON_DATA_BUF_LEN(1024), 省栈1KB×3 | | V3.7 | 2026-08-04 | tcp_json_srv 缓冲宏化: data_json[2048]→TCP_JSON_DATA_BUF_LEN(1024), 省栈1KB×3 |
| V3.6 | 2026-08-04 | 脱机事件日志系统: W25Q32 256KB 环形(8064条) + BOOT/网络/事件/线圈/时钟锚点 8 类事件 + 掉电恢复 + gcc 单测 6 例 | | V3.6 | 2026-08-04 | 脱机事件日志系统: W25Q32 256KB 环形(8064条) + BOOT/网络/事件/线圈/时钟锚点 8 类事件 + 掉电恢复 + gcc 单测 6 例 |
| V3.5 | 2026-07-23 | 保活精简(去heartbeat+IWDG) + SocketSend故障恢复(3次失败重连+重建socket) | | V3.5 | 2026-07-23 | 保活精简(去heartbeat+IWDG) + SocketSend故障恢复(3次失败重连+重建socket) |
+17
View File
@@ -216,6 +216,22 @@ static void test_power_loss_mid_sector(void)
printf("PASS test_power_loss_mid_sector\n"); printf("PASS test_power_loss_mid_sector\n");
} }
/* 测试7: TIME_ANCHOR 严格使用平台下发 unix_ts (不走 dev_time_now) */
static void test_time_anchor_exact(void)
{
OfflogEvt e;
reset_flash();
offlog_init();
offlog_time_anchor(1800000000UL); /* 平台下发值, 与 mock dev_time_now() 不同 */
CHECK(offlog_count() == 1);
CHECK(offlog_read_idx(0, &e) == 0);
CHECK(e.type == OFFLOG_EVT_TIME_ANCHOR);
CHECK(e.unix_ts == 1800000000UL); /* 严格等于传参 */
CHECK(e.flags & OFFLOG_UNIX_VALID_FLAG);
printf("PASS test_time_anchor_exact\n");
}
int main(void) int main(void)
{ {
test_fresh_init(); test_fresh_init();
@@ -224,6 +240,7 @@ int main(void)
test_sector_switch(); test_sector_switch();
test_clear(); test_clear();
test_power_loss_mid_sector(); test_power_loss_mid_sector();
test_time_anchor_exact();
if (failures) { if (failures) {
printf("\n%d FAILURE(S)\n", failures); printf("\n%d FAILURE(S)\n", failures);