4G_module/include/cmiot/cm_ntp.h

104 lines
3.5 KiB
C
Raw Permalink Normal View History

2024-09-02 17:54:29 +08:00
/**
* @file cm_ntp.h
* @brief NTP协议客户端接口
* @copyright Copyright © 2021 China Mobile IOT. All rights reserved.
* @author By wangk
* @date 2021/04/21
*
* @defgroup ntp ntp
* @ingroup DS
* @{
*/
#ifndef __CM_NTP_H__
#define __CM_NTP_H__
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/** NTP事件类型 */
typedef enum
{
CM_NTP_EVENT_SYNC_FAIL, /*!< NTP时间同步失败, 参数(event_param): NULL */
CM_NTP_EVENT_SYNC_OK, /*!< NTP时间同步成功, 参数(event_param): 获取到的NTP时间, ISO-8601时间格式字符串, 例如: 2021-04-21T17:10:08.868+08:00 */
CM_NTP_EVENT_SETTIME_FAIL, /*!< NTP时间同步成功但设置本地时间失败, 参数(event_param): 获取到的NTP时间, ISO-8601时间格式字符串, 例如: 2021-04-21T17:10:08.868+08:00 */
} cm_ntp_event_e;
/** NTP设置类型 */
typedef enum
{
CM_NTP_CFG_SERVER = 1, /*!< NTP服务器支持域名、ipv4地址、ipv6地址设置参数为字符串型最多128字节未设置时使用默认服务器 */
CM_NTP_CFG_PORT, /*!< NTP服务器端口号端口号为uint16_t型未设置时使用123端口 */
CM_NTP_CFG_TIMEOUT, /*!< NTP超时时间未设置时为3000毫秒支持设置范围1000~10000单位为毫秒 */
CM_NTP_CFG_DNS, /*!< NTP服务器为域名时DNS解析IP地址优先级优先级为uint32_t型0(默认)使用全局优先级。1v4优先。2v6优先 */
CM_NTP_CFG_SET_RTC, /*!< 是否将获取到的NTP时间设置到RTC设置参数为bool型0不同步至系统时间。1默认同步至系统时间 */
CM_NTP_CFG_CB, /*!< NTP服务回调函数设置回调函数类型见cm_ntp_event_cb */
CM_NTP_CFG_CB_PARAM, /*!< NTP服务回调函数中传递的用户参数指针 */
} cm_ntp_cfg_type_e;
/** NTP事件回调函数 */
typedef void (*cm_ntp_event_cb_t)(cm_ntp_event_e event, void *event_param, void *cb_param);
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/**
* @brief NTP服务设置参数
*
* @param [in] type
* @param [in] value
*
* @return
* = 0 - \n
* = -1 -
*
* @details NTP服务进行中不可设置
*/
int32_t cm_ntp_set_cfg(cm_ntp_cfg_type_e type, void *value);
/**
* @brief NTP时间同步
*
* @return
* = 0 - \n
* < 0 -
*
* @details NTP模块底层依赖asocketasync_dns和eloop模块
*/
int32_t cm_ntp_sync(void);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __CM_NTP_H__ */
/** @}*/