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,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_