feat: 移植腾讯云物联网开发平台 C SDK
This commit is contained in:
@@ -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_
|
@@ -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_
|
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @file qcloud_iot_gateway_scene.h
|
||||
* @author {hubert} ({hubertxxu@tencent.com})
|
||||
* @brief
|
||||
* @version 1.0
|
||||
* @date 2022-06-15
|
||||
*
|
||||
* @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-06-15 1.0 hubertxxu first commit
|
||||
* </table>
|
||||
*/
|
||||
|
||||
#ifndef IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_GATEWAY_SCENE_H_
|
||||
#define IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_GATEWAY_SCENE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "qcloud_iot_common.h"
|
||||
|
||||
#define MAX_LENGTH_INNER_SCENE_ID (64)
|
||||
#define MAX_LENGTH_INNER_SCENE_NAME (64)
|
||||
#define MAX_LENGTH_INNER_SCENE_LIST (20)
|
||||
|
||||
/**
|
||||
* @brief callback of gateway scene
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
int (*gateway_scene_handles_callback)(UtilsJsonValue scene_id, UtilsJsonValue scene_name,
|
||||
UtilsJsonValue scene_update_time, UtilsJsonValue scene_handles,
|
||||
void *usr_data);
|
||||
int (*gateway_run_scene_callback)(UtilsJsonValue scene_id, void *usr_data);
|
||||
int (*gateway_delete_scene_callback)(UtilsJsonValue scene_id, void *usr_data);
|
||||
int (*gateway_reload_scene_reply_callback)(int result_code, UtilsJsonValue status, UtilsJsonValue scene_result,
|
||||
void *usr_data);
|
||||
} IoTGatewaySceneCallback;
|
||||
|
||||
/**
|
||||
* @brief gateway scene inner list
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
char inner_scene_id[MAX_LENGTH_INNER_SCENE_ID];
|
||||
char inner_scene_name[MAX_LENGTH_INNER_SCENE_NAME];
|
||||
} IoTGatewaySceneInnerList;
|
||||
|
||||
/**
|
||||
* @brief gateway scene init, register handler to server list.
|
||||
*
|
||||
* @param[in,out] client pointer to mqtt client
|
||||
* @param[in] callback @see IoTGatewaySceneCallback
|
||||
* @param[in] usr_data usr data used in callback
|
||||
* @return 0 for success, or err code (<0) @see IotReturnCode
|
||||
*/
|
||||
int IOT_GatewayScene_Init(void *client, IoTGatewaySceneCallback callback, void *usr_data);
|
||||
|
||||
/**
|
||||
* @brief Gateway scene deinit, unregister handler from server list.
|
||||
*
|
||||
* @param[in,out] client pointer to mqtt client
|
||||
*/
|
||||
void IOT_GatewayScene_Deinit(void *client);
|
||||
|
||||
/**
|
||||
* @brief reload gateway scene from cloud.
|
||||
*
|
||||
* @param[in,out] client pointer to mqtt client
|
||||
* @param[out] buf publish message buffer
|
||||
* @param[in] buf_len buffer len
|
||||
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
|
||||
*/
|
||||
int IOT_GatewayScene_Reload(void *client, char *buf, int buf_len);
|
||||
|
||||
/**
|
||||
* @brief report gateway local scene
|
||||
*
|
||||
* @param[in,out] client pointer to mqtt client
|
||||
* @param[out] buf publish message buffer
|
||||
* @param[in] buf_len buffer len
|
||||
* @param list local scene list
|
||||
* @param list_count local scene list count
|
||||
* @return packet id (>=0) when success, or err code (<0) @see IotReturnCode
|
||||
*/
|
||||
int IOT_GatewayScene_ReportInnerList(void *client, char *buf, int buf_len, IoTGatewaySceneInnerList *list,
|
||||
int list_count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // IOT_HUB_DEVICE_C_SDK_INCLUDE_SERVICES_EXPLORER_QCLOUD_IOT_GATEWAY_SCENE_H_
|
Reference in New Issue
Block a user