- 新增time_manager模块用于统一管理时间同步状态 - 实现BLE时间同步GATT服务(time_sync_event和ble_time_sync_module) - 添加time_sync_protocol定义统一的协议帧格式 - 支持UTC时间戳、时区偏移和精度信息的时间同步 - 实现settings持久化存储时间校准数据 - 提供time_manager快照API供其他模块查询当前时间状态 - 增加对BLE/USB/手动三种同步源的支持和区分
38 lines
1.1 KiB
C
38 lines
1.1 KiB
C
#include "time_sync_event.h"
|
|
|
|
/* 统一输出来源字符串,便于日志快速确认是哪条链路在校时。 */
|
|
static const char *time_sync_source_name(enum time_sync_source source)
|
|
{
|
|
switch (source) {
|
|
case TIME_SYNC_SOURCE_NONE:
|
|
return "none";
|
|
case TIME_SYNC_SOURCE_BLE:
|
|
return "ble";
|
|
case TIME_SYNC_SOURCE_USB:
|
|
return "usb";
|
|
case TIME_SYNC_SOURCE_MANUAL:
|
|
return "manual";
|
|
default:
|
|
return "unknown";
|
|
}
|
|
}
|
|
|
|
/* 事件日志聚焦关键信息:来源、时区和 UTC 毫秒时间戳。 */
|
|
static void log_time_sync_event(const struct app_event_header *aeh)
|
|
{
|
|
const struct time_sync_event *event = cast_time_sync_event(aeh);
|
|
const struct time_sync_update *update = time_sync_event_get_update(event);
|
|
|
|
APP_EVENT_MANAGER_LOG(aeh,
|
|
"src=%s tz=%d utc_ms=%llu acc=%u",
|
|
time_sync_source_name(update->source),
|
|
update->timezone_min,
|
|
(unsigned long long)update->utc_ms,
|
|
update->accuracy_ms);
|
|
}
|
|
|
|
APP_EVENT_TYPE_DEFINE(time_sync_event,
|
|
log_time_sync_event,
|
|
NULL,
|
|
APP_EVENT_FLAGS_CREATE(APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|