add new qloud-c-sdk component
This commit is contained in:
@@ -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_
|
@@ -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_
|
@@ -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_
|
@@ -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_
|
@@ -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_
|
Reference in New Issue
Block a user