add new qloud-c-sdk component

This commit is contained in:
mculover666
2022-03-25 10:06:56 +08:00
parent 565cd29e94
commit a3ac2e56d8
166 changed files with 35027 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,113 @@
/**
* @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>
/**
* @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,134 @@
/**
* @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_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_RET_SUCCESS = 0, /**< Successful return */
QCLOUD_ERR_FAILURE = -1001, /**< Generic failure return */
QCLOUD_ERR_INVAL = -1002, /**< Invalid parameter */
QCLOUD_ERR_DEV_INFO = -1003, /**< Fail to get device info */
QCLOUD_ERR_MALLOC = -1004, /**< Fail to malloc memory */
QCLOUD_ERR_HTTP_CLOSED = -3, /**< HTTP server close the connection */
QCLOUD_ERR_HTTP = -4, /**< HTTP unknown error */
QCLOUD_ERR_HTTP_PRTCL = -5, /**< HTTP protocol error */
QCLOUD_ERR_HTTP_UNRESOLVED_DNS = -6, /**< HTTP DNS resolve failed */
QCLOUD_ERR_HTTP_PARSE = -7, /**< HTTP URL parse failed */
QCLOUD_ERR_HTTP_CONN = -8, /**< HTTP connect failed */
QCLOUD_ERR_HTTP_AUTH = -9, /**< HTTP auth failed */
QCLOUD_ERR_HTTP_NOT_FOUND = -10, /**< HTTP 404 */
QCLOUD_ERR_HTTP_TIMEOUT = -11, /**< HTTP timeout */
QCLOUD_ERR_MQTT_PUSH_TO_LIST_FAILED = -102, /**< Fail to push node to MQTT waiting list */
QCLOUD_ERR_MQTT_NO_CONN = -103, /**< Not connected with MQTT server */
QCLOUD_ERR_MQTT_UNKNOWN = -104, /**< MQTT unknown error */
QCLOUD_ERR_MQTT_ATTEMPTING_RECONNECT = -105, /**< Reconnecting with MQTT server */
QCLOUD_ERR_MQTT_RECONNECT_TIMEOUT = -106, /**< MQTT reconnect timeout */
QCLOUD_ERR_MQTT_MAX_SUBSCRIPTIONS = -107, /**< MQTT topic subscription out of range */
QCLOUD_ERR_MQTT_SUB = -108, /**< MQTT topic subscription fail */
QCLOUD_ERR_MQTT_NOTHING_TO_READ = -109, /**< MQTT nothing to read */
QCLOUD_ERR_MQTT_PACKET_READ = -110, /**< Something wrong when reading MQTT packet */
QCLOUD_ERR_MQTT_REQUEST_TIMEOUT = -111, /**< MQTT request timeout */
QCLOUD_ERR_MQTT_CONNACK_UNKNOWN = -112, /**< MQTT connection refused: unknown error */
QCLOUD_ERR_MQTT_CONNACK_UNACCEPTABLE_PROTOCOL_VERSION =
-113, /**< MQTT connection refused: protocol version invalid */
QCLOUD_ERR_MQTT_CONNACK_IDENTIFIER_REJECTED = -114, /**< MQTT connection refused: identifier rejected */
QCLOUD_ERR_MQTT_CONNACK_SERVER_UNAVAILABLE = -115, /**< MQTT connection refused: service not available */
QCLOUD_ERR_MQTT_CONNACK_BAD_USERDATA = -116, /**< MQTT connection refused: bad user name or password */
QCLOUD_ERR_MQTT_CONNACK_NOT_AUTHORIZED = -117, /**< MQTT connection refused: not authorized */
QCLOUD_ERR_RX_MESSAGE_INVAL = -118, /**< MQTT received invalid msg */
QCLOUD_ERR_BUF_TOO_SHORT = -119, /**< MQTT recv buffer not enough */
QCLOUD_ERR_MQTT_QOS_NOT_SUPPORT = -120, /**< MQTT QoS level not supported */
QCLOUD_ERR_MQTT_UNSUB_FAIL = -121, /**< MQTT unsubscribe failed */
QCLOUD_ERR_JSON_PARSE = -132, /**< JSON parsing error */
QCLOUD_ERR_JSON_BUFFER_TRUNCATED = -133, /**< JSON buffer truncated */
QCLOUD_ERR_JSON_BUFFER_TOO_SMALL = -134, /**< JSON parsing buffer not enough */
QCLOUD_ERR_JSON = -135, /**< JSON generation error */
QCLOUD_ERR_MAX_JSON_TOKEN = -136, /**< JSON token out of range */
QCLOUD_ERR_MAX_APPENDING_REQUEST = -137, /**< appending request out of range */
QCLOUD_ERR_MAX_TOPIC_LENGTH = -138, /**< Topic length oversize */
QCLOUD_ERR_COAP_NULL = -150, /**< COAP null pointer */
QCLOUD_ERR_COAP_DATA_SIZE = -151, /**< COAP data size out of range */
QCLOUD_ERR_COAP_INTERNAL = -152, /**< COAP interval error */
QCLOUD_ERR_COAP_BADMSG = -153, /**< COAP bad msg */
QCLOUD_ERR_DTLS_PEER_CLOSE_NOTIFY = -160, /**< DTLS connection is closed */
QCLOUD_ERR_SHADOW_PROPERTY_EXIST = -201, /**< Shadow property already exist */
QCLOUD_ERR_SHADOW_NOT_PROPERTY_EXIST = -202, /**< Shadow property not exist */
QCLOUD_ERR_SHADOW_UPDATE_TIMEOUT = -203, /**< Shadow update timeout */
QCLOUD_ERR_SHADOW_UPDATE_REJECTED = -204, /**< Shadow update rejected by server */
QCLOUD_ERR_SHADOW_GET_TIMEOUT = -205, /**< Shadow get timeout */
QCLOUD_ERR_SHADOW_GET_REJECTED = -206, /**< Shadow get rejected by server */
QCLOUD_ERR_GATEWAY_CREATE_SESSION_FAIL = -221, /**< Gateway fail to create sub-device session */
QCLOUD_ERR_GATEWAY_SESSION_NO_EXIST = -222, /**< Gateway sub-device session not exist */
QCLOUD_ERR_GATEWAY_SESSION_TIMEOUT = -223, /**< Gateway sub-device session timeout */
QCLOUD_ERR_GATEWAY_SUBDEV_ONLINE = -224, /**< Gateway sub-device online */
QCLOUD_ERR_GATEWAY_SUBDEV_OFFLINE = -225, /**< Gateway sub-device offline */
QCLOUD_ERR_RRPC_REPLY_TIMEOUT = -230, /**< RRPC reply timeout */
QCLOUD_ERR_RRPC_REPLY_ERR = -231, /**< RRPC reply error */
QCLOUD_ERR_TCP_SOCKET_FAILED = -601, /**< TLS TCP socket connect fail */
QCLOUD_ERR_TCP_UNKNOWN_HOST = -602, /**< TCP unknown host (DNS fail) */
QCLOUD_ERR_TCP_CONNECT = -603, /**< TCP/UDP socket connect fail */
QCLOUD_ERR_TCP_READ_TIMEOUT = -604, /**< TCP read timeout */
QCLOUD_ERR_TCP_WRITE_TIMEOUT = -605, /**< TCP write timeout */
QCLOUD_ERR_TCP_READ_FAIL = -606, /**< TCP read error */
QCLOUD_ERR_TCP_WRITE_FAIL = -607, /**< TCP write error */
QCLOUD_ERR_TCP_PEER_SHUTDOWN = -608, /**< TCP server close connection */
QCLOUD_ERR_TCP_NOTHING_TO_READ = -609, /**< TCP socket nothing to read */
QCLOUD_ERR_SSL_INIT = -701, /**< TLS/SSL init fail */
QCLOUD_ERR_SSL_CERT = -702, /**< TLS/SSL certificate issue */
QCLOUD_ERR_SSL_CONNECT = -703, /**< TLS/SSL connect fail */
QCLOUD_ERR_SSL_CONNECT_TIMEOUT = -704, /**< TLS/SSL connect timeout */
QCLOUD_ERR_SSL_WRITE_TIMEOUT = -705, /**< TLS/SSL write timeout */
QCLOUD_ERR_SSL_WRITE = -706, /**< TLS/SSL write error */
QCLOUD_ERR_SSL_READ_TIMEOUT = -707, /**< TLS/SSL read timeout */
QCLOUD_ERR_SSL_READ = -708, /**< TLS/SSL read error */
QCLOUD_ERR_SSL_NOTHING_TO_READ = -709, /**< 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,423 @@
/**
* @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_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 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 */
uint16_t 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, 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, int timeout_ms);
#endif
/**
* @brief Functions for saving file into NVS(files/FLASH)
* @param[in] filename file path name
* @param[in] write_buffer source need write buffer
* @param[in] len length of file to save
* @return length of data save when success, or 0 for failure
*/
size_t HAL_File_Save(const char *filename, const char *write_buffer, size_t wLen);
/**
* @brief Functions for reading file from NVS(files/FLASH)
* @param[in] filename file path name
* @param[in] buf destination log buffer
* @param[in] len length of log to read
* @return length of data read when success, or 0 for failure
*/
size_t HAL_File_Read(const char *filename, char *buff, size_t read_len);
/**
* @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_Get_Size(const char *filename);
/**************************************************************************************
* device info
**************************************************************************************/
/**
* @brief Save device info.
*
* @param[in] dev_info device info to be saved
* @return @see IotReturnCode
*/
int HAL_SetDevInfo(void *dev_info);
/**
* @brief Get device info.
*
* @param[in] dev_info buffer to save device info
* @return @see IotReturnCode
*/
int HAL_GetDevInfo(void *dev_info);
/**************************************************************************************
* timer
**************************************************************************************/
/**
* @brief Define timer structure, platform dependant.
*
*/
typedef struct {
#if defined(__linux__) && defined(__GLIBC__)
struct timeval end_time;
#else
uintptr_t end_time;
#endif
} Timer;
/**
* @brief Return if timer expired.
*
* @param[in] timer @see Timer
* @return true expired
* @return false no expired
*/
bool HAL_Timer_Expired(Timer *timer);
/**
* @brief Countdown ms.
*
* @param[in,out] timer @see Timer
* @param[in] timeout_ms ms to count down
*/
void HAL_Timer_CountdownMs(Timer *timer, uint32_t timeout_ms);
/**
* @brief Countdown second
*
* @param[in,out] timer @see Timer
* @param[in] timeout second to count down
*/
void HAL_Timer_Countdown(Timer *timer, uint32_t timeout);
/**
* @brief Timer remain ms.
*
* @param[in] timer @see Timer
* @return ms
*/
uint32_t HAL_Timer_Remain(Timer *timer);
/**
* @brief time format string
*
* @return time format string, such as "2021-05-31 15:58:46"
*/
char *HAL_Timer_Current(void);
/**
* @brief Get current utf timestamp of second
*
* @return timestamp
*/
uint32_t HAL_Timer_CurrentSec(void);
/**
* @brief Get utc time ms timestamp.
*
* @return timestamp
*/
uint64_t HAL_Timer_CurrentMs(void);
/**
* @brief Set system time using ms timestamp
*
* @param[in] timestamp_sec timestamp to set
* @return 0 for success
*/
int HAL_Timer_SetSystimeSec(uint32_t timestamp_sec);
/**
* @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);
#if defined(__cplusplus)
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_COMMON_QCLOUD_IOT_PLATFORM_H_

View File

@@ -0,0 +1,63 @@
/**
* @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_config.h
* @brief sdk config define
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-06-01
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-06-01 <td>1.0 <td>fancyxu <td>first commit
* <tr><td>2021-07-12 <td>1.1 <td>fancyxu <td>rename AUTH_WITH_NOTLS to AUTH_WITH_NO_TLS
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_CONFIG_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
/* #undef AUTH_MODE_CERT */
#define AUTH_MODE_KEY
#define AUTH_WITH_NO_TLS
/* #undef GATEWAY_ENABLED */
/* #undef COAP_COMM_ENABLED */
/* #undef OTA_MQTT_CHANNEL */
/* #undef SYSTEM_COMM */
/* #undef DEV_DYN_REG_ENABLED */
/* #undef LOG_UPLOAD */
/* #undef IOT_DEBUG */
#define DEBUG_DEV_INFO_USED
/* #undef AT_TCP_ENABLED */
/* #undef AT_UART_RECV_IRQ */
/* #undef AT_OS_USED */
/* #undef AT_DEBUG */
/* #undef OTA_USE_HTTPS */
#define MULTITHREAD_ENABLED
/* #undef BROADCAST_ENABLED */
/* #undef RRPC_ENABLED */
/* #undef REMOTE_CONFIG_MQTT */
/* #undef LOG_UPLOAD_TYPE_JSON */
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_CONFIG_H_

View File

@@ -0,0 +1,87 @@
/**
* @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_host.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
* <tr><td>2021-07-12 <td>1.1 <td>fancyxu <td>change port to str format
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_HOST_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_HOST_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK APPID.
*
*/
#define QCLOUD_IOT_DEVICE_SDK_APPID "21010406"
#define QCLOUD_IOT_DEVICE_SDK_APPID_LEN (sizeof(QCLOUD_IOT_DEVICE_SDK_APPID) - 1)
/**
* @brief MQTT server domain.
*
*/
#define QCLOUD_IOT_MQTT_DIRECT_DOMAIN "iotcloud.tencentdevices.com"
#define MQTT_SERVER_PORT_TLS "8883"
#define MQTT_SERVER_PORT_NO_TLS "1883"
/**
* @brief Server domain for dynamic registering device.
*
*/
#define DYN_REG_SERVER_URL "ap-guangzhou.gateway.tencentdevices.com"
#define DYN_REG_URI_PATH "/device/register"
#define DYN_REG_SERVER_PORT "80"
#define DYN_REG_SERVER_PORT_TLS "443"
/**
* @brief URL for doing log upload.
*
*/
#define LOG_UPLOAD_SERVER_URL "ap-guangzhou.gateway.tencentdevices.com"
#define LOG_UPLOAD_URI_PATH "/device/reportlog"
#define LOG_UPLOAD_SERVER_PORT "80"
/**
* @brief (old)URL for doing log upload.
* Compatible with old versions, new users are recommended to use up
*
*/
#define LOG_UPLOAD_OLD_SERVER_URL "http://devicelog.iot.cloud.tencent.com/cgi-bin/report-log"
#define LOG_UPLOAD_OLD_SERVER_PORT "80"
/**
* @brief Max size of a host name.
*
*/
#define HOST_STR_LENGTH 64
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_HOST_H_

View File

@@ -0,0 +1,119 @@
/**
* @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_variables.h
* @brief variables can be set depend on user resource.
* @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_CONFIG_QCLOUD_IOT_VARIABLES_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_VARIABLES_H_
#ifdef __cplusplus
extern "C" {
#endif
// Variables are dependant on user situation (network status/device memory/application context). Adjust the default
// value to meet your requirement
/**
* @brief default MQTT timeout value when connect/pub/sub (unit: ms)
*
*/
#define QCLOUD_IOT_MQTT_COMMAND_TIMEOUT (5 * 1000)
/**
* @brief default MQTT timeout value when wait server ack
*
*/
#define QCLOUD_IOT_MQTT_WAIT_ACK_TIMEOUT (5 * 1000)
/**
* @brief default MQTT keep alive interval (unit: ms)
*
*/
#define QCLOUD_IOT_MQTT_KEEP_ALIVE_INTERNAL (240 * 1000)
/**
* @brief default MQTT Tx buffer size, MAX: 16*1024
*
*/
#define QCLOUD_IOT_MQTT_TX_BUF_LEN (4096)
/**
* @brief default MQTT Rx buffer size, MAX: 16*1024
*
*/
#define QCLOUD_IOT_MQTT_RX_BUF_LEN (4096)
/**
* @brief default MQTT timeout value when yield
*
*/
#define QCLOUD_IOT_MQTT_YIELD_TIMEOUT (500)
/**
* @brief MAX MQTT reconnect interval (unit: ms)
*
*/
#define MAX_RECONNECT_WAIT_INTERVAL (60 * 1000)
/**
* @brief MAX valid time when connect to MQTT server. 0: always valid.
* Use this only if the device has accurate UTC time. Otherwise, set to 0.
*
*/
#define MAX_ACCESS_EXPIRE_TIMEOUT (0)
// Log upload related params, which will affect the size of device memory/disk consumption Log upload related params,
// which will affect the size of device memory/disk consumption
/**
* @brief size of buffer for log upload
*
*/
#define LOG_UPLOAD_BUFFER_SIZE 5000
/**
* @brief Max size of one http log upload. Should not larger than 5000
*
*/
#define MAX_HTTP_LOG_POST_SIZE 5000
/**
* @brief MAX size for saving log into NVS (files/FLASH) after upload fail
*
*/
#define MAX_LOG_SAVE_SIZE (3 * LOG_UPLOAD_BUFFER_SIZE)
/**
* @brief interval of log upload (unit: ms) Decrease this value if LOG_UPLOAD_BUFFER_SIZE is small
*
*/
#define LOG_UPLOAD_INTERVAL_MS 1800000
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_CONFIG_QCLOUD_IOT_VARIABLES_H_

View File

@@ -0,0 +1,68 @@
/**
* @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_common.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-08-23
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-08-23 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_COMMON_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_COMMON_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK version info
*
*/
#define QCLOUD_IOT_DEVICE_SDK_VERSION "4.0.0"
// common header file
#include "qcloud_iot_debug.h"
#include "qcloud_iot_device.h"
#include "qcloud_iot_error.h"
#include "qcloud_iot_params_check.h"
#include "qcloud_iot_platform.h"
// config header file
#include "qcloud_iot_config.h"
#include "qcloud_iot_host.h"
#include "qcloud_iot_variables.h"
// service header file
#include "qcloud_iot_mqtt_client.h"
#include "qcloud_iot_system.h"
#include "qcloud_iot_ota.h"
#include "qcloud_iot_cos.h"
#include "qcloud_iot_http_client.h"
#include "qcloud_iot_log_upload.h"
#include "qcloud_iot_http_signed.h"
#include "qcloud_iot_dynreg.h"
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_COMMON_H_

View File

@@ -0,0 +1,50 @@
/**
* @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_explorer.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-08-23
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-08-23 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_EXPLORER_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_EXPLORER_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK version info
*
*/
#define QCLOUD_IOT_DEVICE_EXPLORER_SDK_VERSION "4.0.0"
// service header file
#include "qcloud_iot_data_template.h"
#include "qcloud_iot_file_manage.h"
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_EXPLORER_H_

View File

@@ -0,0 +1,50 @@
/**
* @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_hub.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
* <tr><td>2021-07-18 <td>1.1 <td>fancyxu <td>support broadcast
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_HUB_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_HUB_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief IoT C-SDK version info
*
*/
#define QCLOUD_IOT_DEVICE_HUB_SDK_VERSION "4.0.0"
// service header file
#include "qcloud_iot_broadcast.h"
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_QCLOUD_IOT_HUB_H_

View File

@@ -0,0 +1,90 @@
/**
* @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_cos.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-26
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-26 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_COS_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_COS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Cos download params.
*
*/
typedef struct {
const char *url; /**< cos url, user space */
uint32_t offset; /**< download offset */
uint32_t file_size; /**< download file size */
int is_fragmentation; /**< http fragmentation support */
int is_https_enabled; /**< TODO:https support */
} IotCosDownloadParams;
/**
* @brief Init cos download handle.
*
* @param[in] params @see IotCosDownloadParams
* @return pointer to cos download handle
*/
void *IOT_COS_DownloadInit(IotCosDownloadParams *params);
/**
* @brief Fetch data from cos.
*
* @param[in,out] handle pointer to cos download handle, @see HTTPCosDownloadHandle
* @param[out] buf buffer to store data
* @param[in] buf_len buffer length
* @param timeout_ms timeout for fetching
* @return >= 0 for recv data len. others @see IotReturnCode
*/
int IOT_COS_DownloadFetch(void *handle, uint8_t *buf, uint32_t buf_len, uint32_t timeout_ms);
/**
* @brief Is download finished.
*
* @param[in,out] handle pointer to cos download handle, @see HTTPCosDownloadHandle
* @return true for finished
*/
int IOT_COS_DownloadIsFinished(void *handle);
/**
* @brief Deinit cos download.
*
* @param[in,out] handle pointer to cos download handle, @see HTTPCosDownloadHandle
*/
void IOT_COS_DownloadDeinit(void *handle);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_COS_H_

View File

@@ -0,0 +1,52 @@
/**
* @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_cos.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-26
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-26 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_DYNREG_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_DYNREG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief dynreg device, get device secret or device cert file and private key file from iot platform
*
* @param[in] params @see DeviceInfo
* @return 0 is success other is failed
*/
int IOT_DynReg_Device(DeviceInfo *device_info);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_DYNREG_H_

View File

@@ -0,0 +1,157 @@
/**
* @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_http_client.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-25
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-25 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_CLIENT_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_CLIENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "qcloud_iot_common.h"
/**
* @brief HTTP write socket timeout.
*
*/
#define HTTP_WRITE_TIMEOUT_MS 5000
/**
* @brief HTTPs read tls timeout.
*
*/
#define HTTPS_READ_TIMEOUT_MS 2000
/**
* @brief Connect params set by user.
*
*/
typedef struct {
const char *url; /**< http header */
const char *port; /**< content length(optional) */
const char *ca_crt; /**< content type(optional) */
} IotHTTPConnectParams;
/**
* @brief Http method.
*
*/
typedef enum {
IOT_HTTP_METHOD_GET = 0,
IOT_HTTP_METHOD_POST,
IOT_HTTP_METHOD_PUT,
IOT_HTTP_METHOD_DELETE,
IOT_HTTP_METHOD_HEAD,
} IotHTTPMethod;
/**
* @brief Request params set by user.
* @ref https://datatracker.ietf.org/doc/html/rfc7231
*
*/
typedef struct {
const char *url; /**< request url */
IotHTTPMethod method; /**< request method */
char *header; /**< http header */
int content_length; /**< content length(optional) */
char *content_type; /**< content type(optional) */
char *content; /**< content (optional) */
} IotHTTPRequestParams;
/**
* @brief Malloc http client.
*
* @return pointer to http client
*/
void *IOT_HTTP_Init(void);
/**
* @brief Free http client.
*
*/
void IOT_HTTP_Deinit(void *client);
/**
* @brief Connect http server.
*
* @param[in,out] client pointer to http client
* @param[in] params params needed to connect http server, @see IotHTTPConnectParams
* @return 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Connect(void *client, IotHTTPConnectParams *params);
/**
* @brief Request http server.
*
* @param[in,out] client pointer to http client
* @param[in] params params needed to send request to http server, @see IotHTTPRequestParams
* @return 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Request(void *client, IotHTTPRequestParams *params);
/**
* @brief Send data to http server.
*
* @param[in,out] client pointer to http client
* @param[in] data data to send
* @param[out] data_len data len
* @return 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Send(void *client, uint8_t *data, int data_len);
/**
* @brief Recv data from http server.
*
* @param[in,out] client pointer to http client
* @param[out] buf buffer to store recv data
* @param[in] buf_len buffer len
* @param timeout_ms timeout for recv
* @return >= 0 for recv data len. others @see IotReturnCode
*/
int IOT_HTTP_Recv(void *client, uint8_t *buf, int buf_len, uint32_t timeout_ms);
/**
* @brief Check is recv finished.
*
* @param[in,out] client pointer to http client
* @return true for finished.
*/
int IOT_HTTP_IsRecvFinished(void *client);
/**
* @brief Disconnect http server.
*
* @param[in,out] client pointer to http client
*/
void IOT_HTTP_Disconnect(void *client);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_CLIENT_H_

View File

@@ -0,0 +1,61 @@
/**
* @file qcloud_iot_http_signed.h
* @author {hubert} ({hubertxxu@tencent.com})
* @brief
* @version 1.0
* @date 2022-01-17
*
* @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.
*
* @par Change Log:
* <table>
* Date Version Author Description
* 2022-01-17 1.0 hubertxxu first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_SIGNED_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_SIGNED_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "qcloud_iot_common.h"
typedef struct {
const char *host;
const char *uri;
char *secretkey;
uint32_t recv_timeout_ms;
bool need_recv;
} HttpSignedParams;
/**
* @brief post message and recv response
*
* @param params @see HttpSignedParams
* @param request_buf request buffer
* @param request_buf_len request buffer length
* @param response_buf response buffer if need recv
* @param response_buf_len response buffer length if need recv
* @return int 0 for success. others @see IotReturnCode
*/
int IOT_HTTP_Signed_Request(HttpSignedParams *params, const char *request_buf, size_t request_buf_len,
uint8_t *response_buf, int response_buf_len);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_HTTP_SIGNED_H_

View File

@@ -0,0 +1,119 @@
/**
* @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_log_upload.h
* @brief
* @author hubertxxu (hubertxxu@tencent.com)
* @version 1.0
* @date 2022-01-05
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2022-01-05 <td>1.0 <td>hubertxxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_LOG_UPLOAD_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_LOG_UPLOAD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
#include "utils_json.h"
#include "utils_hmac.h"
/**
* @brief user callback for saving/reading logs into/from NVS(files/FLASH) after
* upload fail/recover
*/
// callback for saving logs into NVS(files/FLASH) after upload fail
typedef size_t (*LogSaveFunc)(const char *filename, const char *msg, size_t wLen);
// callback for reading logs from NVS(files/FLASH) when upload ready
typedef size_t (*LogReadFunc)(const char *filename, char *buff, size_t rLen);
// callback for deleting logs in NVS(files/FLASH). return 0 when success
typedef int (*LogDelFunc)(const char *filename);
// callback for reading the size of logs in NVS(files/FLASH). return 0 when
// nothing exist
typedef size_t (*LogGetSizeFunc)(const char *filename);
/**
* @brief data structure to init feature of log upload
*/
typedef struct {
/* device info */
const char *product_id;
const char *device_name;
/* auth key, use device secret for PSK device and cert file path for cert device */
const char *sign_key;
/* http connect domain */
const char *host;
uint32_t log_buffer_size;
/* user callback saving/reading logs into/from NVS(files/FLASH) */
const char *save_log_filename;
LogSaveFunc save_func;
LogReadFunc read_func;
LogDelFunc del_func;
LogGetSizeFunc get_size_func;
} LogUploadInitParams;
#define DEFAULT_LOG_UPLOAD_INIT_PARAMS \
{ \
NULL, NULL, NULL, NULL, LOG_UPLOAD_BUFFER_SIZE, NULL, NULL, NULL, NULL, NULL \
}
/**
* @brief append need report log to log upload buffer
*
* @param[in] log_content data of need to report
*/
void IOT_Log_Upload_AppendToUploadBuffer(int log_level, const char *log_content);
/**
* @brief init log upload module
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Log_Upload(bool force_upload);
/**
* @brief init log upload previously
*
* @param[in] init_params @see LogUploadInitParams
* @return @see IotReturnCode
*/
int IOT_Log_Upload_InitPre(LogUploadInitParams *init_params);
/**
* @brief init log upload module
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Log_Upload_Init(void *client);
/**
* @brief stop log upload add release resources
*
* @return @see IotReturnCode
*/
int IOT_Log_Upload_Deinit(void);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_LOG_UPLOAD_H_

View File

@@ -0,0 +1,337 @@
/**
* @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_mqtt_client.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
* <tr><td>2021-07-07 <td>1.1 <td>fancyxu <td>support user host for unittest
* <tr><td>2021-07-08 <td>1.1 <td>fancyxu <td>fix code standard of IotReturnCode and QcloudIotClient
* <tr><td>2021-07-18 <td>1.1 <td>fancyxu <td>fix code standard of pClient
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_MQTT_CLIENT_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_MQTT_CLIENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Max size of a topic name
*
*/
#define MAX_SIZE_OF_CLOUD_TOPIC ((MAX_SIZE_OF_DEVICE_NAME) + (MAX_SIZE_OF_PRODUCT_ID) + 64 + 6)
/**
* @brief MQTT event type
*
*/
typedef enum {
MQTT_EVENT_UNDEF = 0, /**< MQTT undefined event */
MQTT_EVENT_DISCONNECT = 1, /**< MQTT disconnect */
MQTT_EVENT_RECONNECT = 2, /**< MQTT reconnect */
MQTT_EVENT_SUBSCRIBE_SUCCESS = 3, /**< MQTT subscribe success */
MQTT_EVENT_SUBSCRIBE_TIMEOUT = 4, /**< MQTT subscribe timeout */
MQTT_EVENT_SUBSCRIBE_NACK = 5, /**< MQTT subscribe fail */
MQTT_EVENT_UNSUBSCRIBE_SUCCESS = 6, /**< MQTT unsubscribe success */
MQTT_EVENT_UNSUBSCRIBE_TIMEOUT = 7, /**< MQTT unsubscribe timeout */
MQTT_EVENT_UNSUBSCRIBE_NACK = 8, /**< MQTT unsubscribe fail */
MQTT_EVENT_PUBLISH_SUCCESS = 9, /**< MQTT publish success */
MQTT_EVENT_PUBLISH_TIMEOUT = 10, /**< MQTT publish timeout */
MQTT_EVENT_PUBLISH_NACK = 11, /**< MQTT publish fail */
MQTT_EVENT_PUBLISH_RECEIVED = 12, /**< MQTT received msg from server */
MQTT_EVENT_CLIENT_DESTROY = 13, /**< MQTT client destroy */
MQTT_EVENT_UNSUBSCRIBE = 14, /**< MQTT unsubscribe */
MQTT_EVENT_GATEWAY_SEARCH = 15,
} MQTTEventType;
/**
* @brief MQTT event message
*
*/
typedef struct {
MQTTEventType event_type; /**< MQTT event type */
void *msg;
} MQTTEventMsg;
/**
* @brief Define MQTT callback when MQTT event happen
*
* @param[in,out] client pointer to mqtt client
* @param[in] context user callback context, @see MQTTEventHandler
* @param[in] msg the event message @see MQTTEventMsg
*/
typedef void (*MQTTEventHandleFun)(void *client, void *context, MQTTEventMsg *msg);
/* The structure of MQTT event handle */
/**
* @brief Define structure to handle mqtt event
*
*/
typedef struct {
MQTTEventHandleFun h_fp;
void *context;
} MQTTEventHandler;
/**
* @brief return next host ip
*/
typedef char *(*MQTTGetNextHostIp)(void);
/**
* @brief The structure of MQTT init parameters
*
*/
typedef struct {
DeviceInfo *device_info; /**< device info */
const char *host; /**< host for user, null for default using QCLOUD_IOT_MQTT_DIRECT_DOMAIN */
const char *backup_host; /**< backup host for user if host not connect will try use this */
uint32_t command_timeout; /**< timeout value (unit: ms) for MQTT connect/pub/sub/yield */
uint32_t keep_alive_interval_ms; /**< MQTT keep alive time interval in millisecond */
uint8_t clean_session; /**< flag of clean session, 1 clean, 0 not clean */
uint8_t auto_connect_enable; /**< flag of auto reconnection, 1 is enable and recommended */
uint8_t connect_when_construct; /**< 1 is enable when no using pre-process before connect */
uint8_t default_subscribe; /**< 1 is enable when clean session is 0, no subscribe packet send, only add subhandle */
MQTTGetNextHostIp get_next_host_ip; /**< get host ip*/
MQTTEventHandler event_handle; /**< event callback */
} MQTTInitParams;
/**
* Default MQTT init parameters
*/
#define DEFAULT_MQTT_INIT_PARAMS \
{ \
NULL, NULL, NULL, 5000, 240 * 1000, 1, 1, 1, 0, NULL, { 0 } \
}
/**
* @brief MQTT Quality of Service level
*
*/
typedef enum {
QOS0 = 0, /**< At most once delivery */
QOS1 = 1, /**< At least once delivery, PUBACK is required */
QOS2 = 2 /**< Exactly once delivery. NOT supported currently */
} QoS;
/**
* @brief MQTT message parameter for pub/sub
*
*/
typedef struct {
QoS qos; // MQTT QoS level
uint8_t retain; // RETAIN flag
uint8_t dup; // DUP flag
uint16_t packet_id; // MQTT Id
char *topic_name; // MQTT topic
int topic_len; // topic length
union {
uint8_t *payload; // MQTT msg payload
char *payload_str; // MQTT msg payload string
};
int payload_len; // MQTT length of msg payload
} MQTTMessage;
/**
* @brief Params needed to publish expcept topic name(as a paramter of function).
*
*/
typedef struct {
QoS qos; // MQTT QoS level
uint8_t retain; // RETAIN flag
uint8_t dup; // DUP flag
void *payload; // MQTT msg payload
int payload_len; // MQTT length of msg payload
} PublishParams;
/**
* @brief Default MQTT publish params
*
*/
#define DEFAULT_PUB_PARAMS \
{ \
QOS0, 0, 0, NULL, 0 \
}
/**
* @brief Define MQTT SUBSCRIBE callback when message arrived
*
* @param[in,out] client pointer to mqtt client
* @param[in] message publish message from server
* @param[in] usr_data user data of SubscribeParams, @see SubscribeParams
*/
typedef void (*OnMessageHandler)(void *client, const MQTTMessage *message, void *usr_data);
/**
* @brief Define MQTT SUBSCRIBE callback when event happened
*
* @param[in,out] client pointer to mqtt client
* @param[in] event_type @see MQTTEventType
* @param[in] usr_data user data of SubscribeParams, @see SubscribeParams
*
* @return none
*/
typedef void (*OnSubEventHandler)(void *client, MQTTEventType event_type, void *usr_data);
/**
* @brief Define structure to do MQTT subscription
*
*/
typedef struct {
QoS qos; /**< MQTT QoS level */
OnMessageHandler on_message_handler; /**< callback when message arrived */
OnSubEventHandler on_sub_event_handler; /**< callback when event happened */
void *user_data; /**< user context for callback */
void (*user_data_free)(void *); /**< user data free when sub handle remove */
} SubscribeParams;
/**
* Default MQTT subscribe parameters
*
*/
#define DEFAULT_SUB_PARAMS \
{ \
QOS0, NULL, NULL, NULL, NULL \
}
/**
* @brief Create MQTT client and connect to MQTT server.
*
* @param[in] params MQTT init parameters
* @return a valid MQTT client handle when success, or NULL otherwise
*/
void *IOT_MQTT_Construct(const MQTTInitParams *params);
/**
* @brief Connect Mqtt server if not connect.
*
* @param[in,out] client pointer to mqtt client pointer, should using the pointer of IOT_MQTT_Construct return.
* @return @see IotReturnCode
*/
int IOT_MQTT_Connect(void *client);
/**
* @brief Close connection and destroy MQTT client.
*
* @param client pointer to mqtt client pointer
* @return @see IotReturnCode
*/
int IOT_MQTT_Destroy(void **client);
/**
* @brief Check connection and keep alive state, read/handle MQTT packet in synchronized way.
*
* @param[in,out] client pointer to mqtt client
* @param[in] timeout_ms timeout value (unit: ms) for this operation
* @return QCLOUD_RET_SUCCESS when success, QCLOUD_ERR_MQTT_ATTEMPTING_RECONNECT when try reconnecting, others @see
* IotReturnCode
*/
int IOT_MQTT_Yield(void *client, uint32_t timeout_ms);
/**
* @brief Publish MQTT message.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_name topic to publish
* @param[in] params @see PublishParams
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_MQTT_Publish(void *client, const char *topic_name, const PublishParams *params);
/**
* @brief Subscribe MQTT topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @param[in] params @see SubscribeParams
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_MQTT_Subscribe(void *client, const char *topic_filter, const SubscribeParams *params);
/**
* @brief Unsubscribe MQTT topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to unsubscribe
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_MQTT_Unsubscribe(void *client, const char *topic_filter);
/**
* @brief Check if MQTT topic has been subscribed or not
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @return true already subscribed
* @return false not ready
*/
bool IOT_MQTT_IsSubReady(void *client, const char *topic_filter);
/**
* @brief Get user data in subscribe.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @return NULL or user data
*/
void *IOT_MQTT_GetSubUsrData(void *client, const char *topic_filter);
/**
* @brief Subscribe and wait sub ready.
*
* @param[in,out] client pointer to mqtt client
* @param[in] topic_filter topic filter to subscribe
* @param[in] params @see SubscribeParams
* @return @see IotReturnCode
*/
int IOT_MQTT_SubscribeSync(void *client, const char *topic_filter, const SubscribeParams *params);
/**
* @brief Check if MQTT is connected.
*
* @param[in,out] client pointer to mqtt client
* @return true connected
* @return false no connected
*/
bool IOT_MQTT_IsConnected(void *client);
/**
* @brief Get device info using to connect mqtt server.
*
* @param[in,out] client pointer to mqtt client
* @return @see DeviceInfo
*/
DeviceInfo *IOT_MQTT_GetDeviceInfo(void *client);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_MQTT_CLIENT_H_

View File

@@ -0,0 +1,113 @@
/**
* @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_ota.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-10-11
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-10-11 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_OTA_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_OTA_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
#include "utils_json.h"
/**
* @brief OTA report type.
*
*/
typedef enum {
IOT_OTA_REPORT_TYPE_DOWNLOADING = 0,
IOT_OTA_REPORT_TYPE_UPGRADE_BEGIN,
IOT_OTA_REPORT_TYPE_UPGRADE_SUCCESS,
IOT_OTA_REPORT_TYPE_DOWNLOAD_TIMEOUT,
IOT_OTA_REPORT_TYPE_FILE_NOT_EXIST,
IOT_OTA_REPORT_TYPE_AUTH_FAIL,
IOT_OTA_REPORT_TYPE_MD5_NOT_MATCH,
IOT_OTA_REPORT_TYPE_UPGRADE_FAIL,
} IotOTAReportType;
/**
* @brief Callback of OTA.
*
*/
typedef struct {
void (*update_firmware_callback)(UtilsJsonValue version, UtilsJsonValue url, UtilsJsonValue md5sum,
uint32_t file_size, void *usr_data);
void (*report_version_reply_callback)(int result_code, void *usr_data);
} IotOTAUpdateCallback;
/**
* @brief OTA init, subscribe update topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IotOTAUpdateCallback
* @param[in] usr_data usr data used in callback
* @return 0 for success, or err code (<0) @see IotReturnCode
*/
int IOT_OTA_Init(void *client, IotOTAUpdateCallback callback, void *usr_data);
/**
* @brief OTA deinit, unsubscribe update topic.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_OTA_Deinit(void *client);
/**
* @brief Report upgrade progress.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] report_type @see IotOTAReportType
* @param[in] progress progress using in IOT_OTA_REPORT_TYPE_DOWNLOADING
* @param[in] version update firmware version
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_OTA_ReportProgress(void *client, char *buf, int buf_len, IotOTAReportType report_type, int progress,
const char *version);
/**
* @brief Report current firmware version.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] version current firmware version
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_OTA_ReportVersion(void *client, char *buf, int buf_len, const char *version);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_OTA_H_

View File

@@ -0,0 +1,73 @@
/**
* @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_system.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-07-24
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-07-24 <td>1.0 <td>fancyxu <td>first commit
* <tr><td>2022-01-26 <td>1.1 <td>hubert <td>add serverip
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_SYSTEM_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_SYSTEM_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include "qcloud_iot_common.h"
#include "utils_json.h"
/**
* @brief Get time from system topic
*
* @param[in,out] client pointer to mqtt client
* @param[out] time time from system topic
* @return @see IotReturnCode
*/
int IOT_Sys_GetTime(void *client, uint32_t *time);
/**
* @brief Get ntp time and set to system.
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Sys_SyncNTPTime(void *client);
/**
* @brief Get serverip from system result topic
*
* @param[in,out] client pointer to mqtt client
* @param[out] server_ip serverip from system result topic
* @return @see IotReturnCode
*/
int IOT_Sys_GetServerIp(void *client, char *server_ip);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_COMMON_QCLOUD_IOT_SYSTEM_H_

View File

@@ -0,0 +1,214 @@
/**
* @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_data_template.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-08-23
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-08-23 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_DATA_TEMPLATE_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_DATA_TEMPLATE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Callback of property.
*
*/
typedef struct {
void (*method_control_callback)(UtilsJsonValue client_token, UtilsJsonValue params, void *usr_data);
void (*method_report_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
void (*method_get_status_reply_callback)(UtilsJsonValue client_token, int code, UtilsJsonValue reported,
UtilsJsonValue control, void *usr_data);
void (*method_report_info_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
void (*method_clear_control_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
} PropertyMessageCallback;
/**
* @brief Callback of event.
*
*/
typedef struct {
void (*method_event_reply_callback)(UtilsJsonValue client_token, int code, void *usr_data);
} EventMessageCallback;
/**
* @brief Callback of action.
*
*/
typedef struct {
void (*method_action_callback)(UtilsJsonValue client_token, UtilsJsonValue action_id, UtilsJsonValue params,
void *usr_data);
} ActionMessageCallback;
/**
* @brief Callback of data template(including property/event/action).
*
*/
typedef struct {
PropertyMessageCallback property_callback;
EventMessageCallback event_callback;
ActionMessageCallback action_callback;
} IotDataTemplateCallback;
#define DEFAULT_DATA_TEMPLATE_CALLBACK \
{ \
{NULL, NULL, NULL, NULL, NULL}, {NULL}, {NULL}, \
}
/**
* @brief Type of event.
*
*/
typedef enum {
IOT_DATA_TEMPLATE_EVENT_TYPE_INFO = 0,
IOT_DATA_TEMPLATE_EVENT_TYPE_ALERT,
IOT_DATA_TEMPLATE_EVENT_TYPE_FAULT,
} IotDataTemplateEventType;
/**
* @brief Post data.
*
*/
typedef struct {
const char * event_id; /**< event id defined in data template */
IotDataTemplateEventType type; /**< event type defined in data template */
const char * params; /**< property json defined in data template */
} IotDataTemplateEventData;
/**
* @brief Action reply.
*
*/
typedef struct {
UtilsJsonValue client_token;
int code;
const char * response; /**< property json defined in data template */
} IotDataTemplateActionReply;
/**
* @brief Check and subscribe data template topic.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IotDataTemplateCallback
* @param[in] usr_data usr data used in callback
* @return 0 for success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_Init(void *client, IotDataTemplateCallback callback, void *usr_data);
/**
* @brief Unsubscribe data template topic.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_DataTemplate_Deinit(void *client);
/**
* @brief Report property.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] params params constructed with property
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyReport(void *client, char *buf, int buf_len, const char *params);
/**
* @brief Get control message offline.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyGetStatus(void *client, char *buf, int buf_len);
/**
* @brief Report device info.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] params params constructed with device info
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyReportInfo(void *client, char *buf, int buf_len, const char *params);
/**
* @brief Clear control message offline.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyClearControl(void *client, char *buf, int buf_len);
/**
* @brief Reply control message.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] code 0 for success
* @param[in] client_token client token of control message
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_PropertyControlReply(void *client, char *buf, int buf_len, int code, UtilsJsonValue client_token);
/**
* @brief Post event.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] data @see IotDataTemplateEventData
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_EventPost(void *client, char *buf, int buf_len, IotDataTemplateEventData data);
/**
* @brief Reply action message.
*
* @param[in,out] client pointer to mqtt client
* @param[in] buf buffer for message
* @param[in] buf_len buffer length
* @param[in] reply @see IotDataTemplateActionReply
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_DataTemplate_ActionReply(void *client, char *buf, int buf_len, IotDataTemplateActionReply reply);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_DATA_TEMPLATE_H_

View File

@@ -0,0 +1,179 @@
/**
* @copyright
*
* Tencent is pleased to support the open source community by making IoT Hub available.
* Copyright(C) 2018 - 2022 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_file_manage.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2022-01-11
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2022-01-11 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_FILE_MANAGE_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_FILE_MANAGE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Define of max size using in file manage.
*
*/
#define MAX_SIZE_OF_FILE_MANAGE_FILE_NAME 64
#define MAX_SIZE_OF_FILE_MANAGE_FILE_TYPE 10
#define MAX_SIZE_OF_FILE_MANAGE_FILE_VERSION 64
/**
* @brief FileManage report type.
*
*/
typedef enum {
// file update
IOT_FILE_MANAGE_REPORT_TYPE_DOWNLOADING = 0,
IOT_FILE_MANAGE_REPORT_TYPE_UPGRADE_BEGIN,
IOT_FILE_MANAGE_REPORT_TYPE_UPGRADE_SUCCESS,
IOT_FILE_MANAGE_REPORT_TYPE_DOWNLOAD_TIMEOUT,
IOT_FILE_MANAGE_REPORT_TYPE_FILE_NOT_EXIST,
IOT_FILE_MANAGE_REPORT_TYPE_AUTH_FAIL,
IOT_FILE_MANAGE_REPORT_TYPE_MD5_NOT_MATCH,
IOT_FILE_MANAGE_REPORT_TYPE_UPGRADE_FAIL,
IOT_FILE_MANAGE_REPORT_TYPE_SPACE_NOT_ENOUGH,
// file delete
IOT_FILE_MANAGE_REPORT_TYPE_DEL_SUCCESS,
IOT_FILE_MANAGE_REPORT_TYPE_DEL_FAIL,
// file post
IOT_FILE_MANAGE_REPORT_TYPE_POST_SUCCESS,
IOT_FILE_MANAGE_REPORT_TYPE_POST_FAIL,
} IotFileManageReportType;
/**
* @brief FileManage file type. @see sg_file_manage_file_type_str
*
*/
typedef enum {
IOT_FILE_MANAGE_FILE_TYPE_UNKOWN = -1,
IOT_FILE_MANAGE_FILE_TYPE_FILE = 0,
IOT_FILE_MANAGE_FILE_TYPE_AUDIO,
IOT_FILE_MANAGE_FILE_TYPE_VOICE,
IOT_FILE_MANAGE_FILE_TYPE_VIDEO,
} IotFileManageFileType;
/**
* @brief File info.
*
*/
typedef struct {
char file_name[MAX_SIZE_OF_FILE_MANAGE_FILE_NAME];
char file_version[MAX_SIZE_OF_FILE_MANAGE_FILE_VERSION];
IotFileManageFileType file_type;
} IotFileManageFileInfo;
/**
* @brief Callback of FileManage.
*
*/
typedef struct {
void (*update_file_callback)(UtilsJsonValue file_name, UtilsJsonValue file_type, UtilsJsonValue version,
UtilsJsonValue url, UtilsJsonValue md5sum, uint32_t file_size, void *usr_data);
void (*del_file_callback)(UtilsJsonValue file_name, UtilsJsonValue file_type, UtilsJsonValue version,
void *usr_data);
void (*report_file_version_reponse_callback)(UtilsJsonValue file_list, int result_code, void *usr_data);
void (*request_file_url_response_callback)(UtilsJsonValue url, UtilsJsonValue file_token, int result_code,
void *usr_data);
} IotFileManageCallback;
/**
* @brief File manage init, register handler to server list.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback @see IotFileManageCallback
* @param[in] usr_data usr data used in callback
* @return 0 for success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_Init(void *client, IotFileManageCallback callback, void *usr_data);
/**
* @brief File manage deinit, unregister handler from server list.
*
* @param[in,out] client pointer to mqtt client
*/
void IOT_FileManage_Deinit(void *client);
/**
* @brief Report file manage message.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] report_type @see IotFileManageReportType
* @param[in] progress progress using in IOT_FILE_MANAGE_REPORT_TYPE_DOWNLOADING
* @param[in] file_name_or_token token using in post event;file name using in other event
* @param[in] version file version
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_Report(void *client, char *buf, int buf_len, IotFileManageReportType report_type, int progress,
const char *file_name_or_token, const char *version);
/**
* @brief Report file list to server mqtt topic.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] file_list file list of @see IotFileManageFileInfo; file name which is "\0" means invalid.
* @param[in] max_num max num of file list.
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_ReportFileList(void *client, char *buf, int buf_len, const IotFileManageFileInfo file_list[],
int max_num);
/**
* @brief Request url to upload.
*
* @param[in,out] client pointer to mqtt client
* @param[out] buf publish message buffer
* @param[in] buf_len buffer len
* @param[in] file_info file to upload, @see IotFileManageFileInfo
* @param[in] request_id user defined, to keep unique.
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
*/
int IOT_FileManage_PostRequest(void *client, char *buf, int buf_len, const IotFileManageFileInfo *file_info,
int request_id);
/**
* @brief Get file type according to string. @see sg_file_manage_file_type_str.
*
* @param[in] file_type file type string
* @param[in] len string length
* @return @see IotFileManageFileType
*/
IotFileManageFileType IOT_FileManage_GetFileType(const char *file_type, int len);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_FILE_MANAGE_H_

View File

@@ -0,0 +1,70 @@
/**
* @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_broadcast.h
* @brief
* @author fancyxu (fancyxu@tencent.com)
* @version 1.0
* @date 2021-07-18
*
* @par Change Log:
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2021-07-18 <td>1.0 <td>fancyxu <td>first commit
* </table>
*/
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_HUB_QCLOUD_IOT_BROADCAST_H_
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_HUB_QCLOUD_IOT_BROADCAST_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "qcloud_iot_common.h"
/**
* @brief Callback when broadcast message arrived.
*
*/
typedef void (*OnBroadcastArrivedCallback)(void *client, const char *msg, int msg_len, void *usr_data);
/**
* @brief Subscribe broadcast topic with callback.
*
* @param[in,out] client pointer to mqtt client
* @param[in] callback callback to handle message
* @param[in] usr_data usr data using in callback
* @return @see IotReturnCode
*/
int IOT_Broadcast_Init(void *client, OnBroadcastArrivedCallback callback, void *usr_data);
/**
* @brief Unsubscribe broadcast topic.
*
* @param[in,out] client pointer to mqtt client
* @return @see IotReturnCode
*/
int IOT_Broadcast_Deinit(void *client);
#ifdef __cplusplus
}
#endif
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_HUB_QCLOUD_IOT_BROADCAST_H_