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));
|