feat: 移植腾讯云物联网开发平台 C SDK

This commit is contained in:
fancyxu
2022-07-01 11:06:09 +08:00
parent 2be1169b0b
commit 0acc079ed6
195 changed files with 36646 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_debug.h
* @brief iot debug & upload debug
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-05-28
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-05-28 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEBUG_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEBUG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "utils_log.h"
#include "qcloud_iot_config.h"
#include "qcloud_iot_platform.h"
#ifdef IOT_DEBUG
#define IOT_FUNC_ENTRY \
{ \
Log_d("FUNC_ENTRY: %s L#%d \n", __FUNCTION__, __LINE__); \
}
#define IOT_FUNC_EXIT \
{ \
Log_d("FUNC_EXIT: %s L#%d \n", __FUNCTION__, __LINE__); \
return; \
}
#define IOT_FUNC_EXIT_RC(x) \
{ \
Log_d("FUNC_EXIT: %s L#%d Return Code : %d \n", __FUNCTION__, __LINE__, x; \
return x; \
}
#else
#define IOT_FUNC_ENTRY
#define IOT_FUNC_EXIT \
{ \
return; \
}
#define IOT_FUNC_EXIT_RC(x) \
{ \
return x; \
}
#endif
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEBUG_H_

View File

@@ -0,0 +1,114 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_device.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-05-28
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-05-28 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEVICE_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEVICE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_config.h"
/**
* @brief MAX size of client ID.
*
*/
#define MAX_SIZE_OF_CLIENT_ID (80)
/**
* @brief MAX size of product ID.
*
*/
#define MAX_SIZE_OF_PRODUCT_ID (10)
/**
* @brief MAX size of product secret.
*
*/
#define MAX_SIZE_OF_PRODUCT_SECRET (32)
/**
* @brief MAX size of device name.
*
*/
#define MAX_SIZE_OF_DEVICE_NAME (48)
/**
* @brief MAX size of device secret.
*
*/
#define MAX_SIZE_OF_DEVICE_SECRET (64)
/**
* @brief MAX size of device cert file name.
*
*/
#define MAX_SIZE_OF_DEVICE_CERT_FILE_NAME (128)
/**
* @brief MAX size of device key file name.
*
*/
#define MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME (128)
/**
* @brief Max size of base64 encoded PSK = 64, after decode: 64/4*3 = 48.
*
*/
#define MAX_SIZE_OF_DECODE_PSK_LENGTH 48
/**
* @brief Device info needed to connect mqtt server.
*
*/
typedef struct {
char product_id[MAX_SIZE_OF_PRODUCT_ID + 1];
char device_name[MAX_SIZE_OF_DEVICE_NAME + 1];
char client_id[MAX_SIZE_OF_CLIENT_ID + 1];
#ifdef AUTH_MODE_CERT
char dev_cert_file_name[MAX_SIZE_OF_DEVICE_CERT_FILE_NAME + 1];
char dev_key_file_name[MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME + 1];
#else
char device_secret[MAX_SIZE_OF_DEVICE_SECRET + 1];
uint8_t device_secret_decode[MAX_SIZE_OF_DECODE_PSK_LENGTH];
size_t device_secret_decode_len;
#endif
#ifdef DEV_DYN_REG_ENABLED
char product_secret[MAX_SIZE_OF_PRODUCT_SECRET + 1];
#endif
} DeviceInfo;
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_DEVICE_H_

View File

@@ -0,0 +1,97 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_error.h
* @brief error code of sdk
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-05-28
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-05-28 <td>1.0 <td>fancyxu <td>first commit
* <tr><td>2021-07-08 <td>1.1 <td>fancyxu <td>fix code standard of IotReturnCode and QcloudIotClient
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_ERROR_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_ERROR_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IOT SDK return/error code.
* Enumeration of return code in QCloud IoT C-SDK.
* Values less than 0 are specific error codes
* Value of 0 is successful return
* Values greater than 0 are specific non-error return codes
*
*/
typedef enum {
QCLOUD_RET_SUCCESS = 0, /**< Successful return */
QCLOUD_ERR_FAILURE = -1, /**< Generic failure return */
QCLOUD_ERR_INVAL = -2, /**< Invalid parameter */
QCLOUD_ERR_DEV_INFO = -3, /**< Fail to get device info */
QCLOUD_ERR_MALLOC = -4, /**< Fail to malloc memory */
QCLOUD_RET_MQTT_ALREADY_CONNECTED = 4, /**< Already connected with MQTT server */
QCLOUD_RET_MQTT_CONNACK_CONNECTION_ACCEPTED = 3, /**< MQTT connection accepted by server */
QCLOUD_RET_MQTT_MANUALLY_DISCONNECTED = 2, /**< Manually disconnected with MQTT server */
QCLOUD_RET_MQTT_RECONNECTED = 1, /**< Reconnected with MQTT server successfully */
QCLOUD_ERR_MQTT_NO_CONN = -101, /**< Not connected with MQTT server */
QCLOUD_ERR_MQTT_ATTEMPTING_RECONNECT = -102, /**< Reconnecting with MQTT server */
QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT = -103, /**< MQTT reconnect timeout */
QCLOUD_ERR_MQTT_SUB = -104, /**< MQTT topic subscription fail */
QCLOUD_ERR_MQTT_NOTHING_TO_READ = -105, /**< MQTT nothing to read */
QCLOUD_ERR_MQTT_PACKET_READ = -106, /**< Something wrong when reading MQTT packet */
QCLOUD_ERR_MQTT_REQUEST_TIMEOUT = -107, /**< MQTT request timeout */
QCLOUD_ERR_RX_MESSAGE_INVAL = -108, /**< MQTT received invalid msg */
QCLOUD_ERR_BUF_TOO_SHORT = -109, /**< MQTT recv buffer not enough */
QCLOUD_ERR_MQTT_QOS_NOT_SUPPORT = -110, /**< MQTT QoS level not supported */
QCLOUD_ERR_MQTT_UNSUB_FAIL = -111, /**< MQTT unsubscribe failed */
QCLOUD_ERR_MAX_TOPIC_LENGTH = -112, /**< Topic length oversize */
QCLOUD_ERR_HTTP = -201, /**< HTTP unknown error */
QCLOUD_ERR_HTTP_AUTH = -202, /**< HTTP auth failed */
QCLOUD_ERR_HTTP_NOT_FOUND = -203, /**< HTTP 404 */
QCLOUD_ERR_HTTP_TIMEOUT = -204, /**< HTTP timeout */
QCLOUD_ERR_HTTP_PARSE = -205, /**< HTTP URL parse failed */
QCLOUD_ERR_JSON_PARSE = -300, /**< JSON parsing error */
QCLOUD_ERR_TCP_SOCKET_FAILED = -401, /**< TLS TCP socket connect fail */
QCLOUD_ERR_TCP_UNKNOWN_HOST = -402, /**< TCP unknown host (DNS fail) */
QCLOUD_ERR_TCP_CONNECT = -403, /**< TCP/UDP socket connect fail */
QCLOUD_ERR_TCP_READ_TIMEOUT = -404, /**< TCP read timeout */
QCLOUD_ERR_TCP_WRITE_TIMEOUT = -405, /**< TCP write timeout */
QCLOUD_ERR_TCP_READ_FAIL = -406, /**< TCP read error */
QCLOUD_ERR_TCP_WRITE_FAIL = -407, /**< TCP write error */
QCLOUD_ERR_TCP_PEER_SHUTDOWN = -408, /**< TCP server close connection */
QCLOUD_ERR_TCP_NOTHING_TO_READ = -409, /**< TCP socket nothing to read */
QCLOUD_ERR_SSL_INIT = -501, /**< TLS/SSL init fail */
QCLOUD_ERR_SSL_CERT = -502, /**< TLS/SSL certificate issue */
QCLOUD_ERR_SSL_CONNECT = -503, /**< TLS/SSL connect fail */
QCLOUD_ERR_SSL_CONNECT_TIMEOUT = -504, /**< TLS/SSL connect timeout */
QCLOUD_ERR_SSL_WRITE_TIMEOUT = -505, /**< TLS/SSL write timeout */
QCLOUD_ERR_SSL_WRITE = -506, /**< TLS/SSL write error */
QCLOUD_ERR_SSL_READ_TIMEOUT = -507, /**< TLS/SSL read timeout */
QCLOUD_ERR_SSL_READ = -508, /**< TLS/SSL read error */
QCLOUD_ERR_SSL_NOTHING_TO_READ = -509, /**< TLS/SSL nothing to read */
} IotReturnCode;
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_ERROR_H_

View File

@@ -0,0 +1,100 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_params_check.h
* @brief check params
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-05-28
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-05-28 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PARAMS_CHECK_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PARAMS_CHECK_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include "utils_log.h"
#define NUMBERIC_SANITY_CHECK(num, err) \
do { \
if (0 > (num)) { \
Log_e("Invalid argument, numeric 0"); \
return (err); \
} \
} while (0)
#define NUMBERIC_SANITY_CHECK_RTN(num) \
do { \
if (0 > (num)) { \
Log_e("Invalid argument, numeric 0"); \
return; \
} \
} while (0)
#define POINTER_SANITY_CHECK(ptr, err) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, ptr); \
return (err); \
} \
} while (0)
#define POINTER_SANITY_CHECK_RTN(ptr) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, ptr); \
return; \
} \
} while (0)
#define STRING_PTR_SANITY_CHECK(ptr, err) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, (ptr)); \
return (err); \
} \
if (0 == strlen((ptr))) { \
Log_e("Invalid argument, %s = '%s'", #ptr, (ptr)); \
return (err); \
} \
} while (0)
#define STRING_PTR_SANITY_CHECK_RTN(ptr) \
do { \
if (NULL == (ptr)) { \
Log_e("Invalid argument, %s = %p", #ptr, (ptr)); \
return; \
} \
if (0 == strlen((ptr))) { \
Log_e("Invalid argument, %s = '%s'", #ptr, (ptr)); \
return; \
} \
} while (0)
#define STRING_PTR_PRINT_SANITY_CHECK(s) ((s) ? (s) : "null")
#if defined(__cplusplus)
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PARAMS_CHECK_H_

View File

@@ -0,0 +1,451 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_platform.h
* @brief hal interface
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-05-28
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-05-28 <td>1.0 <td>fancyxu <td>first commit
* <tr><td>2021-07-09 <td>1.1 <td>fancyxu <td>support tls and change port to str format
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PLATFORM_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PLATFORM_H_
#if defined(__cplusplus)
extern "C" {
#endif
#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "qcloud_iot_device.h"
#include "qcloud_iot_common.h"
/**********************************************************************
* QCloud IoT C-SDK Hardware Abstraction Layer
* Platform/OS/IP stack/SSL dependant functions
* Check platform folder for reference implementation
* Require porting when adapt SDK to new platform/OS
*********************************************************************/
/**************************************************************************************
* os
**************************************************************************************/
/**
* @brief Mutex create.
*
* @return pointer to mutex
*/
void *HAL_MutexCreate(void);
/**
* @brief Mutex destroy.
*
* @param[in,out] mutex pointer to mutex
*/
void HAL_MutexDestroy(void *mutex);
/**
* @brief Mutex lock.
*
* @param[in,out] mutex pointer to mutex
*/
void HAL_MutexLock(void *mutex);
/**
* @brief Mutex try lock.
*
* @param[in,out] mutex pointer to mutex
* @return 0 for success
*/
int HAL_MutexTryLock(void *mutex);
/**
* @brief Mutex unlock.
*
* @param[in,out] mutex pointer to mutex
*/
void HAL_MutexUnlock(void *mutex);
/**
* @brief Malloc from heap.
*
* @param[in] size size to malloc
* @return pointer to buffer, NULL for failed.
*/
void *HAL_Malloc(size_t size);
/**
* @brief Free buffer malloced by HAL_Malloc.
*
* @param[in] ptr
*/
void HAL_Free(void *ptr);
/**
* @brief Printf with format.
*
* @param[in] fmt format
*/
void HAL_Printf(const char *fmt, ...);
/**
* @brief Snprintf with format.
*
* @param[out] str buffer to save
* @param[in] len buffer len
* @param[in] fmt format
* @return length of formatted string, >0 for success.
*/
int HAL_Snprintf(char *str, const int len, const char *fmt, ...);
/**
* @brief Sleep for ms.
*
* @param[in] ms ms to sleep
*/
void HAL_SleepMs(uint32_t ms);
#ifdef MULTITHREAD_ENABLED
/**
* @brief Theard entry function.
*
*/
typedef void (*ThreadRunFunc)(void *arg);
/**
* @brief Thread priority.
*
*/
typedef enum {
THREAD_PRIORITY_HIGH,
THREAD_PRIORITY_MIDDLE,
THREAD_PRIORITY_LOW,
} ThreadPriority;
/**
* @brief Thread params to create.
*
*/
typedef struct {
char *thread_name; /**< thread name */
void* thread_id; /**< thread handle */
ThreadRunFunc thread_func; /**< thread entry function */
void *user_arg; /**< thread entry arg */
ThreadPriority priority; /**< thread priority */
void *stack_base; /**< thread stack base */
uint32_t stack_size; /**< thread stack size */
} ThreadParams;
/**
* @brief platform-dependant thread create function
*
* @param[in,out] params params to create thread @see ThreadParams
* @return @see IotReturnCode
*/
int HAL_ThreadCreate(ThreadParams *params);
/**
* @brief platform-dependent thread destroy function.
*
*/
void HAL_ThreadDestroy(void *thread_id);
/**
* @brief platform-dependent semaphore create function.
*
* @return pointer to semaphore
*/
void *HAL_SemaphoreCreate(void);
/**
* @brief platform-dependent semaphore destory function.
*
* @param[in] sem pointer to semaphore
*/
void HAL_SemaphoreDestroy(void *sem);
/**
* @brief platform-dependent semaphore post function.
*
* @param[in] sem pointer to semaphore
*/
void HAL_SemaphorePost(void *sem);
/**
* @brief platform-dependent semaphore wait function.
*
* @param[in] sem pointer to semaphore
* @param[in] timeout_ms wait timeout
* @return @see IotReturnCode
*/
int HAL_SemaphoreWait(void *sem, uint32_t timeout_ms);
/**
* @brief platform-dependent mail queue init function.
*
* @param[in] pool pool using in mail queue
* @param[in] mail_size mail size
* @param[in] mail_count mail count
* @return pointer to mail queue
*/
void *HAL_MailQueueInit(void *pool, size_t mail_size, int mail_count);
/**
* @brief platform-dependent mail queue deinit function.
*
* @param[in] mail_q pointer to mail queue
*/
void HAL_MailQueueDeinit(void *mail_q);
/**
* @brief platform-dependent mail queue send function.
*
* @param[in] mail_q pointer to mail queue
* @param[in] buf data buf
* @param[in] size data size
* @return 0 for success
*/
int HAL_MailQueueSend(void *mail_q, const void *buf, size_t size);
/**
* @brief platform-dependent mail queue send function.
*
* @param[in] mail_q pointer to mail queue
* @param[out] buf data buf
* @param[in] size data size
* @param[in] timeout_ms
* @return 0 for success
*/
int HAL_MailQueueRecv(void *mail_q, void *buf, size_t *size, uint32_t timeout_ms);
#endif
/**
* @brief Functions for saving file into NVS(files/FLASH)
* @param[in] filename file path name
* @param[in] buf source need write buffer
* @param[in] write_len length of file to write
* @return length of data save when success, or 0 for failure
*/
size_t HAL_File_Write(const char *filename, const void *buf, size_t write_len, size_t offset);
/**
* @brief Functions for reading file from NVS(files/FLASH)
* @param[in] filename file path name
* @param[in] buf destination log buffer
* @param[in] read_len length to read
* @return length of data read when success, or 0 for failure
*/
size_t HAL_File_Read(const char *filename, void *buf, size_t read_len, size_t offset);
/**
* @brief Functions for deleting file in NVS(files/FLASH).
* @param[in] filename file path name
* @return 0 when success
*/
int HAL_File_Del(const char *filename);
/**
* @brief Functions for reading the size of file in NVS(files/FLASH).
* @param[in] filename file path name
* @return 0 when nothing exist
*/
size_t HAL_File_GetSize(const char *filename);
/**************************************************************************************
* device info
**************************************************************************************/
/**
* @brief Save device info
*
* @param[in] device_info @see DeviceInfo
* @return @see IotReturnCode
*/
int HAL_SetDevInfo(DeviceInfo *device_info);
/**
* @brief Get device info
*
* @param[in] device_info @see DeviceInfo
* @return @see IotReturnCode
*/
int HAL_GetDevInfo(DeviceInfo *device_info);
/**************************************************************************************
* timer
**************************************************************************************/
/**
* @brief time format string
*
* @return time format string, such as "2021-05-31 15:58:46"
*/
char *HAL_Timer_Current(void);
/**
* @brief Get utc time ms timestamp.
*
* @return timestamp
*/
uint64_t HAL_Timer_CurrentMs(void);
/**
* @brief Set system time using second timestamp
*
* @param[in] timestamp_ms
* @return 0 for success
*/
int HAL_Timer_SetSystimeMs(uint64_t timestamp_ms);
/**************************************************************************************
* network tcp
**************************************************************************************/
/**
* @brief TCP connect in linux
*
* @param[in] host host to connect
* @param[out] port port to connect
* @return socket fd
*/
int HAL_TCP_Connect(const char *host, const char *port);
/**
* @brief TCP disconnect
*
* @param[in] fd socket fd
* @return 0 for success
*/
int HAL_TCP_Disconnect(int fd);
/**
* @brief TCP write
*
* @param[in] fd socket fd
* @param[in] buf buf to write
* @param[in] len buf len
* @param[in] timeout_ms timeout
* @param[out] written_len data written length
* @return @see IotReturnCode
*/
int HAL_TCP_Write(int fd, const uint8_t *data, uint32_t len, uint32_t timeout_ms, size_t *written_len);
/**
* @brief TCP read.
*
* @param[in] fd socket fd
* @param[out] buf buffer to save read data
* @param[in] len buffer len
* @param[in] timeout_ms timeout
* @param[out] read_len length of data read
* @return @see IotReturnCode
*/
int HAL_TCP_Read(int fd, uint8_t *data, uint32_t len, uint32_t timeout_ms, size_t *read_len);
/**************************************************************************************
* AT module
**************************************************************************************/
#ifdef AT_MODULE_ENABLE
/**
* @brief Urc handler.
*
*/
typedef void (*OnUrcHandler)(const char *data, size_t data_len);
/**
* @brief Init at module.
*
* @return 0 for success
*/
int HAL_Module_Init(void);
/**
* @brief Deinit at module.
*
*/
void HAL_Module_Deinit(void);
/**
* @brief Send at cmd to at module and wait for resp.
*
* @param[in] at_cmd at cmd
* @param[in] at_expect expect resp
* @param[in] timeout_ms wait timeout
* @return 0 for success
*/
int HAL_Module_SendAtCmdWaitResp(const char *at_cmd, const char *at_expect, uint32_t timeout_ms);
/**
* @brief Send at cmd and waif for data.
*
* @param[in] at_cmd at cmd
* @param[in] at_expect expect resp
* @param[out] recv_buf recv data buffer
* @param[out] recv_len recv data length
* @param[in] timeout_ms wait timeout
* @return 0 for success
*/
int HAL_Module_SendAtCmdWaitRespWithData(const char *at_cmd, const char *at_expect, void *recv_buf, uint32_t *recv_len,
uint32_t timeout_ms);
/**
* @brief Send date to at module.
*
* @param[in] data data to send
* @param[in] data_len data length
* @return 0 for success
*/
int HAL_Module_SendAtData(const void *data, int data_len);
/**
* @brief Set urc.
*
* @param[in] urc irc string
* @param[in] urc_handler urc handler
* @return 0 for success
*/
int HAL_Module_SetUrc(const char *urc, OnUrcHandler urc_handler);
/**
* @brief connect network
*
* @return int 0 for success
*/
int HAL_Module_ConnectNetwork(void);
#endif
#if defined(__cplusplus)
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PLATFORM_H_

View File

@@ -0,0 +1,88 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2021 THL A29 Limited, a Tencent company.All rights reserved.
*
* Licensed under the MIT License(the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*
* @file qcloud_iot_timer.h
* @brief timer interface
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2022-04-07
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-04-07 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_TIMER_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_TIMER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "qcloud_iot_platform.h"
/**
* @brief Define timer.
*
*/
#define QcloudIotTimer uint64_t
/**
* @brief Return if timer expired.
*
* @param[in] timer @see QcloudIotTimer
* @return true expired
* @return false no expired
*/
bool IOT_Timer_Expired(QcloudIotTimer *timer);
/**
* @brief Countdown ms.
*
* @param[in,out] timer @see QcloudIotTimer
* @param[in] timeout_ms ms to count down
*/
void IOT_Timer_CountdownMs(QcloudIotTimer *timer, uint32_t timeout_ms);
/**
* @brief Countdown second
*
* @param[in,out] timer @see QcloudIotTimer
* @param[in] timeout second to count down
*/
void IOT_Timer_Countdown(QcloudIotTimer *timer, uint32_t timeout);
/**
* @brief QcloudIotTimer remain ms.
*
* @param[in] timer @see QcloudIotTimer
* @return ms
*/
uint64_t IOT_Timer_Remain(QcloudIotTimer *timer);
/**
* @brief Get current utf timestamp of second
*
* @return timestamp
*/
uint64_t IOT_Timer_CurrentSec(void);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_TIMER_H_