feat: 添加时间同步管理功能
- 新增time_manager模块用于统一管理时间同步状态 - 实现BLE时间同步GATT服务(time_sync_event和ble_time_sync_module) - 添加time_sync_protocol定义统一的协议帧格式 - 支持UTC时间戳、时区偏移和精度信息的时间同步 - 实现settings持久化存储时间校准数据 - 提供time_manager快照API供其他模块查询当前时间状态 - 增加对BLE/USB/手动三种同步源的支持和区分
This commit is contained in:
33
inc/time_sync_protocol.h
Normal file
33
inc/time_sync_protocol.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef TIME_SYNC_PROTOCOL_H__
|
||||
#define TIME_SYNC_PROTOCOL_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <zephyr/sys/util.h>
|
||||
|
||||
/*
|
||||
* 统一定义时间同步协议帧格式,方便 BLE/USB 两条链路共享:
|
||||
*
|
||||
* byte 0 : version
|
||||
* byte 1 : flags
|
||||
* byte 2-3 : timezone_min (little-endian, int16)
|
||||
* byte 4-11: utc_ms (little-endian, uint64)
|
||||
* byte 12-15: accuracy_ms (little-endian, uint32)
|
||||
*/
|
||||
#define TIME_SYNC_PROTOCOL_VERSION 1U
|
||||
#define TIME_SYNC_PROTOCOL_PAYLOAD_SIZE 16U
|
||||
|
||||
#define TIME_SYNC_PROTOCOL_OFFSET_VERSION 0U
|
||||
#define TIME_SYNC_PROTOCOL_OFFSET_FLAGS 1U
|
||||
#define TIME_SYNC_PROTOCOL_OFFSET_TIMEZONE 2U
|
||||
#define TIME_SYNC_PROTOCOL_OFFSET_UTC_MS 4U
|
||||
#define TIME_SYNC_PROTOCOL_OFFSET_ACCURACY_MS 12U
|
||||
|
||||
/*
|
||||
* 预留 flags 字段:
|
||||
* - 当前版本只要求时区字段有效;
|
||||
* - 后续如果要加 DST、闰秒或来源质量扩展,可以继续复用这个字节。
|
||||
*/
|
||||
#define TIME_SYNC_PROTOCOL_FLAG_TIMEZONE_VALID BIT(0)
|
||||
|
||||
#endif /* TIME_SYNC_PROTOCOL_H__ */
|
||||
Reference in New Issue
Block a user