merge new qcloud sdk
1. qcloud has a great revolution, the protocol has been changed to implement data template, so the old TencentCloud_SDK developed by us will not work fine now(mqtt still works, but data template will not works fine for recently created product/devices). 2. I merge the official qlcoud sdk(include both the iot-hub and iot-explorer sdk) into the componet/conectivity to support new protocol of data template 3. iot-hub sdk, supply the fundamental iot protocol(like mqtt coap, etc.) iot-explorer sdk, supply the high level service like data template based on mqtt 4. To know how it works, see qcloud_iot_explorer_sdk_data_template、qcloud_iot_hub_sdk_mqtt example(keil project in board\TencentOS_tiny_EVB_MX_Plus\KEIL\qcloud_iot_explorer_sdk_data_template and board\TencentOS_tiny_EVB_MX_Plus\KEIL\qcloud_iot_hub_sdk_mqtt)
This commit is contained in:
17
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/config.h
vendored
Normal file
17
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/config.h
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/* #undef AUTH_MODE_CERT */
|
||||
#define AUTH_MODE_KEY
|
||||
/* #undef AUTH_WITH_NOTLS */
|
||||
/* #undef GATEWAY_ENABLED */
|
||||
/* #undef COAP_COMM_ENABLED */
|
||||
#define OTA_MQTT_CHANNEL
|
||||
/* #undef SYSTEM_COMM */
|
||||
#define EVENT_POST_ENABLED
|
||||
#define ACTION_ENABLED
|
||||
/* #undef DEV_DYN_REG_ENABLED */
|
||||
/* #undef LOG_UPLOAD */
|
||||
/* #undef IOT_DEBUG */
|
||||
/* #undef DEBUG_DEV_INFO_USED */
|
||||
/* #undef AT_TCP_ENABLED */
|
||||
/* #undef AT_UART_RECV_IRQ */
|
||||
/* #undef AT_OS_USED */
|
||||
/* #undef AT_DEBUG */
|
@@ -0,0 +1,526 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_DATA_TEMPLATE_H_
|
||||
#define QCLOUD_IOT_EXPORT_DATA_TEMPLATE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "qcloud_iot_export_mqtt.h"
|
||||
#include "qcloud_iot_export_method.h"
|
||||
|
||||
#define MAX_CONTORL_REPLY_STATUS_LEN 64 // max len of status within control reply msg
|
||||
|
||||
/**
|
||||
* @brief Data type of template
|
||||
*/
|
||||
|
||||
#define TYPE_TEMPLATE_INT JINT32
|
||||
#define TYPE_TEMPLATE_ENUM JINT32
|
||||
#define TYPE_TEMPLATE_FLOAT JFLOAT
|
||||
#define TYPE_TEMPLATE_BOOL JINT8
|
||||
#define TYPE_TEMPLATE_STRING JSTRING
|
||||
#define TYPE_TEMPLATE_TIME JUINT32
|
||||
#define TYPE_TEMPLATE_JOBJECT JOBJECT
|
||||
|
||||
typedef int32_t TYPE_DEF_TEMPLATE_INT;
|
||||
typedef int32_t TYPE_DEF_TEMPLATE_ENUM;
|
||||
typedef float TYPE_DEF_TEMPLATE_FLOAT;
|
||||
typedef char TYPE_DEF_TEMPLATE_BOOL;
|
||||
typedef char TYPE_DEF_TEMPLATE_STRING;
|
||||
typedef uint32_t TYPE_DEF_TEMPLATE_TIME;
|
||||
typedef void * TYPE_DEF_TEMPLATE_OBJECT;
|
||||
|
||||
#ifdef EVENT_POST_ENABLED //enable event function of data_template
|
||||
|
||||
#define TYPE_STR_INFO "info"
|
||||
#define TYPE_STR_ALERT "alert"
|
||||
#define TYPE_STR_FAULT "fault"
|
||||
|
||||
/*If defined,event's timesamp should be accurate UTC timestamp in millisecond */
|
||||
#define EVENT_TIMESTAMP_USED
|
||||
|
||||
#define FLAG_EVENT0 (1U<<0)
|
||||
#define FLAG_EVENT1 (1U<<1)
|
||||
#define FLAG_EVENT2 (1U<<2)
|
||||
#define FLAG_EVENT3 (1U<<3)
|
||||
#define FLAG_EVENT4 (1U<<4)
|
||||
#define FLAG_EVENT5 (1U<<5)
|
||||
#define FLAG_EVENT6 (1U<<6)
|
||||
#define FLAG_EVENT7 (1U<<7)
|
||||
#define FLAG_EVENT8 (1U<<8)
|
||||
#define FLAG_EVENT9 (1U<<9)
|
||||
|
||||
#define ALL_EVENTS_MASK (0xFFFFFFFF)
|
||||
|
||||
|
||||
typedef enum {
|
||||
eEVENT_INFO,
|
||||
eEVENT_ALERT,
|
||||
eEVENT_FAULT,
|
||||
}eEventType;
|
||||
|
||||
typedef struct _sEvent_{
|
||||
char *event_name; // event name
|
||||
char *type; // event type
|
||||
uint32_t timestamp; // event timestamp
|
||||
uint8_t eventDataNum; // number of event properties
|
||||
DeviceProperty *pEventData; // event properties
|
||||
} sEvent;
|
||||
|
||||
#endif
|
||||
|
||||
/* The structure of data_template init parameters */
|
||||
typedef struct {
|
||||
/* device info */
|
||||
char *product_id; // product ID
|
||||
char *device_name; // device name
|
||||
|
||||
#ifdef AUTH_MODE_CERT
|
||||
char *cert_file; // cert file path
|
||||
char *key_file; // key file path
|
||||
#else
|
||||
char *device_secret; // device secret
|
||||
#endif
|
||||
|
||||
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
|
||||
|
||||
MQTTEventHandler event_handle; // event callback
|
||||
|
||||
} TemplateInitParams;
|
||||
|
||||
#ifdef AUTH_MODE_CERT
|
||||
#define DEFAULT_TEMPLATE_INIT_PARAMS { NULL, NULL, NULL, NULL, 2000, 240 * 1000, 1, 1, {0}}
|
||||
#else
|
||||
#define DEFAULT_TEMPLATE_INIT_PARAMS { NULL, NULL, NULL, 2000, 240 * 1000, 1, 1, {0}}
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum _eReplyCode_{
|
||||
eDEAL_SUCCESS = 0,
|
||||
eDEAL_FAIL = -1,
|
||||
}eReplyCode;
|
||||
|
||||
/**
|
||||
* @brief control msg reply parameter
|
||||
*/
|
||||
typedef struct _sReplyPara {
|
||||
uint32_t timeout_ms; // request timeout time, unit:ms
|
||||
eReplyCode code; // reply code. 0:success, ~0:failed
|
||||
char status_msg[MAX_CONTORL_REPLY_STATUS_LEN]; // reply message
|
||||
|
||||
} sReplyPara;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Define property status in data template
|
||||
*/
|
||||
typedef enum _eDataState_{
|
||||
eNOCHANGE = 0,
|
||||
eCHANGED = 1,
|
||||
} eDataState;
|
||||
|
||||
/**
|
||||
* @brief Define data point in data template
|
||||
*/
|
||||
typedef struct {
|
||||
DeviceProperty data_property;
|
||||
eDataState state;
|
||||
} sDataPoint;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Create data_template client and connect to MQTT server
|
||||
*
|
||||
* @param pParams data_template init parameters
|
||||
*
|
||||
* @return a valid data_template client handle when success, or NULL otherwise
|
||||
*/
|
||||
void* IOT_Template_Construct(TemplateInitParams *pParams);
|
||||
|
||||
/**
|
||||
* @brief Publish MQTT message
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param topicName MQTT topic name
|
||||
* @param pParams publish parameters
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_Template_Publish(void *handle, char *topicName, PublishParams *pParams);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Subscribe MQTT message
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param topicFilter MQTT topic filter
|
||||
* @param pParams subscribe parameters
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_Template_Subscribe(void *handle, char *topicFilter, SubscribeParams *pParams);
|
||||
|
||||
/**
|
||||
* @brief Unsubscribe MQTT message
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param topicFilter MQTT topic filter
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_Template_Unsubscribe(void *handle, char *topicFilter);
|
||||
|
||||
/**
|
||||
* @brief Check if MQTT data_template is connected
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @return true= connected, false = unconnected
|
||||
*/
|
||||
bool IOT_Template_IsConnected(void *handle);
|
||||
|
||||
/**
|
||||
* @brief Close connection and destroy MQTT data_template client
|
||||
*
|
||||
* @param pClient pointer of handle to data_template client
|
||||
*
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_Destroy(void *handle);
|
||||
|
||||
/**
|
||||
* @brief Check connection and keep alive state, read/handle MQTT message in synchronized way
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param timeout_ms timeout value (unit: ms) for this operation
|
||||
*
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_Yield(void *handle, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Register device property
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param pProperty reference to device property
|
||||
* @param callback callback when property changes
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_Register_Property(void *handle, DeviceProperty *pProperty, OnPropRegCallback callback);
|
||||
|
||||
/**
|
||||
* @brief UnRegister device property
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param pProperty reference to device property
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_UnRegister_Property(void *handle, DeviceProperty *pProperty);
|
||||
|
||||
#ifdef ACTION_ENABLED
|
||||
int IOT_Template_Register_Action(void *handle, DeviceAction *pAction, OnActionHandleCallback callback);
|
||||
|
||||
int IOT_Template_UnRegister_Action(void *handle, DeviceAction *pAction);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Add reported fields array in JSON document, don't overwrite
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param jsonBuffer string buffer to store JSON document
|
||||
* @param sizeOfBuffer size of string buffer
|
||||
* @param count number of properties
|
||||
* @param pDeviceProperties array of properties
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_JSON_ConstructReportArray(void *handle, char *jsonBuffer, size_t sizeOfBuffer, uint8_t count, DeviceProperty *pDeviceProperties[]);
|
||||
|
||||
|
||||
/**
|
||||
* @brief report data_template data in asynchronized way
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param pJsonDoc source JSON document for report
|
||||
* @param sizeOfBuffer length of JSON document
|
||||
* @param callback callback when response arrive
|
||||
* @param userContext user data for callback
|
||||
* @param timeout_ms timeout value for this operation (unit: ms)
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_Report(void *handle, char *pJsonDoc, size_t sizeOfBuffer, OnReplyCallback callback, void *userContext, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief report data_template data in synchronized way
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param pJsonDoc source JSON document for report
|
||||
* @param sizeOfBuffer length of JSON document
|
||||
* @param timeout_ms timeout value for this operation (unit: ms)
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
|
||||
*/
|
||||
int IOT_Template_Report_Sync(void *handle, char *pJsonDoc, size_t sizeOfBuffer, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Get data_template state from server in asynchronized way.
|
||||
* Generally it's a way to sync data_template data during offline
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param callback callback when response arrive
|
||||
* @param userContext user data for callback
|
||||
* @param timeout_ms timeout value for this operation (unit: ms)
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_GetStatus(void *handle, OnReplyCallback callback, void *userContext, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Get Get data_template state from server in asynchronized way
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param timeout_ms timeout value for this operation (unit: ms)
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_GetStatus_sync(void *handle, uint32_t timeout_ms);
|
||||
|
||||
|
||||
/**
|
||||
* @brief clear the control msg when IOT_Template_GetStatus get control msg
|
||||
* @param pClient handle to data_template client
|
||||
* @param pClientToken correspond to the clientToken of control msg
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_ClearControl(void *handle, char *pClientToken, OnReplyCallback callback, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief reply to the control msg
|
||||
* @param pClient handle to data_template client
|
||||
* @param pJsonDoc data buffer for reply
|
||||
* @param sizeOfBuffer length of data buffer
|
||||
* @param replyPara reply info
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_ControlReply(void *handle, char *pJsonDoc, size_t sizeOfBuffer, sReplyPara *replyPara);
|
||||
|
||||
/**
|
||||
* @brief construct system information in json format
|
||||
* @param pClient handle to data_template client
|
||||
* @param jsonBuffer data buffer for construct
|
||||
* @param sizeOfBuffer length of data buffer
|
||||
* @param pPlatInfo pointer of platform info, compulsory
|
||||
* @param pSelfInfo pointer of self-define info, option
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
|
||||
*package format for system info report
|
||||
* {
|
||||
* "method": "report_info",
|
||||
* "clientToken": "client-token1618",
|
||||
* "params": {
|
||||
* "module_hardinfo": "esp8266", //if module used, compulsory
|
||||
* "module_softinfo": "APP_2.0.0", //compulsory
|
||||
* "fw_ver": "FW_1.0.0", //compulsory
|
||||
* "imei": "123456789", //option
|
||||
* "lat": "22.546015" //latitude,option
|
||||
* "lon": "113.941125", //longitude,option
|
||||
* "device_label": {
|
||||
* "append_info": "your self define info" //self-define information,option
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
int IOT_Template_JSON_ConstructSysInfo(void *handle, char *jsonBuffer, size_t sizeOfBuffer, DeviceProperty *pPlatInfo, DeviceProperty *pSelfInfo);
|
||||
|
||||
/**
|
||||
* @brief report system information in asynchronized way
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param pJsonDoc source JSON document for report
|
||||
* @param sizeOfBuffer length of JSON document
|
||||
* @param callback callback when response arrive
|
||||
* @param userContext user data for callback
|
||||
* @param timeout_ms timeout value for this operation (unit: ms)
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_Report_SysInfo(void *handle, char *pJsonDoc, size_t sizeOfBuffer, OnReplyCallback callback, void *userContext, uint32_t timeout_ms);
|
||||
|
||||
|
||||
/**
|
||||
* @brief report data_template data in synchronized way
|
||||
*
|
||||
* @param pClient handle to data_template client
|
||||
* @param pJsonDoc source JSON document for report
|
||||
* @param sizeOfBuffer length of JSON document
|
||||
* @param callback callback when response arrive
|
||||
* @param userContext user data for callback
|
||||
* @param timeout_ms timeout value for this operation (unit: ms)
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_Template_Report_SysInfo_Sync(void *handle, char *pJsonDoc, size_t sizeOfBuffer, uint32_t timeout_ms);
|
||||
|
||||
|
||||
#ifdef EVENT_POST_ENABLED
|
||||
/**
|
||||
* @brief callback of event reply
|
||||
*
|
||||
* @param client handle to data_template client
|
||||
* @param msg event reply msg
|
||||
*
|
||||
*/
|
||||
typedef void (*OnEventReplyCallback)(void *client, MQTTMessage *msg);
|
||||
|
||||
|
||||
/**
|
||||
* @brief set events flag when events occured
|
||||
*
|
||||
* @param client handle to data_template client
|
||||
* @param flag event flags for set. per bit of 32bits represent one event.
|
||||
*
|
||||
*/
|
||||
void IOT_Event_setFlag(void *client, uint32_t flag);
|
||||
|
||||
|
||||
/**
|
||||
* @brief clear events flag after events dealed
|
||||
*
|
||||
* @param client handle to data_template client
|
||||
* @param flag event flags for clear. per bit of 32bits represent one event.
|
||||
*
|
||||
*/
|
||||
void IOT_Event_clearFlag(void *client, uint32_t flag);
|
||||
|
||||
|
||||
/**
|
||||
* @brief get events flag setted
|
||||
*
|
||||
* @param client handle to data_template client
|
||||
* @return events flag status
|
||||
*
|
||||
*/
|
||||
uint32_t IOT_Event_getFlag(void *client);
|
||||
|
||||
/**
|
||||
* @brief init event function of data_template client
|
||||
*
|
||||
* @param c handle to data_template client
|
||||
*/
|
||||
int IOT_Event_Init(void *c);
|
||||
|
||||
|
||||
/**
|
||||
* @brief handle event wait for reply timeout
|
||||
*
|
||||
* @param client handle to data_template client
|
||||
*/
|
||||
void handle_template_expired_event(void *client);
|
||||
|
||||
|
||||
/**
|
||||
* @brief post event to cloud, SDK construct event json package
|
||||
* @param pClient handle to data_template client
|
||||
* @param pJsonDoc data buffer for event post
|
||||
* @param sizeOfBuffer length of data buffer
|
||||
* @param event_count event counts to post
|
||||
* @param pEventArry pointer of events array to post
|
||||
* @param replyCb callback when event reply received
|
||||
* @return @see IoT_Error_Code
|
||||
*/
|
||||
int IOT_Post_Event(void *pClient, char *pJsonDoc, size_t sizeOfBuffer, uint8_t event_count, sEvent *pEventArry[], OnEventReplyCallback replyCb);
|
||||
|
||||
/**
|
||||
* @brief post event to cloud, user input raw event data
|
||||
* @param pClient handle to data_template client
|
||||
* @param pJsonDoc data buffer for event post
|
||||
* @param sizeOfBuffer length of data buffer
|
||||
* @param pEventMsg user input event raw data in json format
|
||||
* event package format:
|
||||
* {"method": "event_post",
|
||||
* "clientToken": "123",
|
||||
* "version": "1.0",
|
||||
* "eventId": "PowerAlarm",
|
||||
* "type": "fatal",
|
||||
* "timestamp": 1212121221,
|
||||
* "params": {
|
||||
* "Voltage": 2.8,
|
||||
* "Percent": 20
|
||||
* }
|
||||
* }
|
||||
|
||||
* pEventMsg for example
|
||||
* single event:
|
||||
* {
|
||||
* "eventId": "PowerAlarm",
|
||||
* "type": "fatal",
|
||||
* "timestamp": 1212121221,
|
||||
* "params": {
|
||||
* "Voltage": 2.8,
|
||||
* "Percent": 20
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* multi event:
|
||||
* {
|
||||
* "eventId": "PowerAlarm",
|
||||
* "type": "fatal",
|
||||
* "timestamp": 1212121221,
|
||||
* "params": {
|
||||
* "Voltage": 2.8,
|
||||
* "Percent": 20
|
||||
* }
|
||||
* },
|
||||
* {
|
||||
* "name": "PowerAlarm",
|
||||
* "type": "fatal",
|
||||
* "timestamp": 1212121223,
|
||||
* "params": {
|
||||
* "Voltage": 2.1,
|
||||
* "Percent": 10
|
||||
* }
|
||||
* },
|
||||
* ....
|
||||
*
|
||||
* @param replyCb event callback when event reply received
|
||||
* @return @see IoT_Error_Code
|
||||
*/
|
||||
int IOT_Post_Event_Raw(void *pClient, char *pJsonDoc, size_t sizeOfBuffer, char *pEventMsg, OnEventReplyCallback replyCb);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ACTION_ENABLED
|
||||
/**
|
||||
* @brief reply to the action msg
|
||||
* @param pClient handle to data_template client
|
||||
* @param pClientToken correspond to the clientToken of action msg
|
||||
* @param pJsonDoc data buffer for reply
|
||||
* @param sizeOfBuffer length of data buffer
|
||||
* @param pAction pointer of action
|
||||
* @param replyPara action reply info
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
|
||||
int IOT_ACTION_REPLY(void *pClient, const char *pClientToken, char *pJsonDoc, size_t sizeOfBuffer, DeviceAction *pAction, sReplyPara *replyPara);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_TEMPLATE_H_ */
|
131
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_error.h
vendored
Normal file
131
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_error.h
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_ERROR_H_
|
||||
#define QCLOUD_IOT_EXPORT_ERROR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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_PROPERTY_EXIST = -201, // property already exist
|
||||
QCLOUD_ERR_NOT_PROPERTY_EXIST = -202, // property not exist
|
||||
QCLOUD_ERR_REPORT_TIMEOUT = -203, // update timeout
|
||||
QCLOUD_ERR_REPORT_REJECTED = -204, // update rejected by server
|
||||
QCLOUD_ERR_GET_TIMEOUT = -205, // get timeout
|
||||
QCLOUD_ERR_GET_REJECTED = -206, // get rejected by server
|
||||
|
||||
QCLOUD_ERR_ACTION_EXIST = -210, // acion already exist
|
||||
QCLOUD_ERR_NOT_ACTION_EXIST = -211, // acion not exist
|
||||
|
||||
|
||||
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_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
|
||||
} IoT_Return_Code;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_ERROR_H_ */
|
205
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_log.h
vendored
Normal file
205
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_log.h
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_LOG_H_
|
||||
#define QCLOUD_IOT_EXPORT_LOG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include "qcloud_iot_export_variables.h"
|
||||
|
||||
/**
|
||||
* SDK log print/upload level
|
||||
*/
|
||||
typedef enum {
|
||||
eLOG_DISABLE = 0,
|
||||
eLOG_ERROR = 1,
|
||||
eLOG_WARN = 2,
|
||||
eLOG_INFO = 3,
|
||||
eLOG_DEBUG = 4
|
||||
} LOG_LEVEL;
|
||||
|
||||
/**
|
||||
* log print level control, only print logs with level less or equal to this variable
|
||||
*/
|
||||
extern LOG_LEVEL g_log_print_level;
|
||||
|
||||
/**
|
||||
* log upload level control, only upload logs with level less or equal to this variable
|
||||
*/
|
||||
extern LOG_LEVEL g_log_upload_level;
|
||||
|
||||
/* user's self defined log handler callback */
|
||||
typedef bool (*LogMessageHandler)(const char* message);
|
||||
|
||||
/**
|
||||
* @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 *msg, size_t wLen);
|
||||
// callback for reading logs from NVS(files/FLASH) when upload ready
|
||||
typedef size_t (*LogReadFunc)(char *buff, size_t rLen);
|
||||
// callback for deleting logs in NVS(files/FLASH). return 0 when success
|
||||
typedef int (*LogDelFunc)();
|
||||
// callback for reading the size of logs in NVS(files/FLASH). return 0 when nothing exist
|
||||
typedef size_t (*LogGetSizeFunc)();
|
||||
|
||||
/**
|
||||
* @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;
|
||||
/* user callback saving/reading logs into/from NVS(files/FLASH) */
|
||||
LogSaveFunc save_func;
|
||||
LogReadFunc read_func;
|
||||
LogDelFunc del_func;
|
||||
LogGetSizeFunc get_size_func;
|
||||
} LogUploadInitParams;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the global log level of print
|
||||
*
|
||||
* @param level
|
||||
*/
|
||||
void IOT_Log_Set_Level(LOG_LEVEL level);
|
||||
|
||||
/**
|
||||
* @brief Get the global log level of print
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
LOG_LEVEL IOT_Log_Get_Level();
|
||||
|
||||
/**
|
||||
* @brief Set the global log level of upload
|
||||
*
|
||||
* @param level
|
||||
*/
|
||||
void IOT_Log_Set_Upload_Level(LOG_LEVEL level);
|
||||
|
||||
/**
|
||||
* @brief Get the global log level of upload
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
LOG_LEVEL IOT_Log_Get_Upload_Level();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set user callback to print log into whereever you want
|
||||
*
|
||||
* @param handler function pointer of callback
|
||||
*
|
||||
*/
|
||||
void IOT_Log_Set_MessageHandler(LogMessageHandler handler);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Init the resource for log upload
|
||||
*
|
||||
* @param init_params init parameter
|
||||
* @return QCLOUD_RET_SUCCESS when success, or error code when fail
|
||||
*
|
||||
*/
|
||||
int IOT_Log_Init_Uploader(LogUploadInitParams *init_params);
|
||||
|
||||
/**
|
||||
* @brief Stop log upload and release the resource
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void IOT_Log_Fini_Uploader(void);
|
||||
|
||||
/**
|
||||
* @brief Do one log upload
|
||||
*
|
||||
* @param force_upload true = upload log at once, false = upload in defined time interval
|
||||
* @return QCLOUD_RET_SUCCESS when success, or error code when fail
|
||||
*/
|
||||
int IOT_Log_Upload(bool force_upload);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generate log for print/upload, call LogMessageHandler if defined
|
||||
*
|
||||
* When LOG_UPLOAD is enabled, the log will be uploaded to cloud server
|
||||
*
|
||||
* @param file
|
||||
* @param func
|
||||
* @param line
|
||||
* @param level
|
||||
*/
|
||||
void IOT_Log_Gen(const char *file, const char *func, const int line, const int level, const char *fmt, ...);
|
||||
|
||||
/* Simple APIs for log generation in different level */
|
||||
#define Log_d(fmt, ...) IOT_Log_Gen(__FILE__, __FUNCTION__, __LINE__, eLOG_DEBUG, fmt, ##__VA_ARGS__)
|
||||
#define Log_i(fmt, ...) IOT_Log_Gen(__FILE__, __FUNCTION__, __LINE__, eLOG_INFO, fmt, ##__VA_ARGS__)
|
||||
#define Log_w(fmt, ...) IOT_Log_Gen(__FILE__, __FUNCTION__, __LINE__, eLOG_WARN, fmt, ##__VA_ARGS__)
|
||||
#define Log_e(fmt, ...) IOT_Log_Gen(__FILE__, __FUNCTION__, __LINE__, eLOG_ERROR, fmt, ##__VA_ARGS__)
|
||||
|
||||
/* Macro for debug mode */
|
||||
#ifdef IOT_DEBUG
|
||||
#define IOT_FUNC_ENTRY \
|
||||
{\
|
||||
printf("FUNC_ENTRY: %s L#%d \n", __FUNCTION__, __LINE__); \
|
||||
}
|
||||
#define IOT_FUNC_EXIT \
|
||||
{\
|
||||
printf("FUNC_EXIT: %s L#%d \n", __FUNCTION__, __LINE__); \
|
||||
return;\
|
||||
}
|
||||
#define IOT_FUNC_EXIT_RC(x) \
|
||||
{\
|
||||
printf("FUNC_EXIT: %s L#%d Return Code : %ld \n", __FUNCTION__, __LINE__, (long)(x)); \
|
||||
return x; \
|
||||
}
|
||||
#else
|
||||
#define IOT_FUNC_ENTRY
|
||||
#define IOT_FUNC_EXIT \
|
||||
{\
|
||||
return;\
|
||||
}
|
||||
#define IOT_FUNC_EXIT_RC(x) \
|
||||
{\
|
||||
return x; \
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Macro for interval debug */
|
||||
//#define LOG_UPLOAD_DEBUG
|
||||
#ifdef LOG_UPLOAD_DEBUG
|
||||
#define UPLOAD_DBG(fmt, ...) HAL_Printf(">>LOG-DBG>>%s(%d): " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
#else
|
||||
#define UPLOAD_DBG(...)
|
||||
#endif
|
||||
#define UPLOAD_ERR(fmt, ...) HAL_Printf(">>LOG-ERR>>%s(%d): " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__)
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_LOG_H_ */
|
117
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_method.h
vendored
Normal file
117
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_method.h
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_METHOD_H_
|
||||
#define QCLOUD_IOT_EXPORT_METHOD_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Type of request ACK
|
||||
*/
|
||||
typedef enum {
|
||||
ACK_NONE = -3, // request timeout
|
||||
ACK_TIMEOUT = -2, // request timeout
|
||||
ACK_REJECTED = -1, // request rejected
|
||||
ACK_ACCEPTED = 0 // request accepted
|
||||
} ReplyAck;
|
||||
|
||||
/**
|
||||
* @brief Type of interaction with server
|
||||
*/
|
||||
typedef enum {
|
||||
GET = 0, // Get data_template state from server
|
||||
REPORT = 1, // Report property to server
|
||||
RINFO = 2, // Report system information to server
|
||||
REPLY = 3, // Reply to control msg
|
||||
CLEAR = 4, // Clear control msg
|
||||
} Method;
|
||||
|
||||
/**
|
||||
* @brief JSON data type
|
||||
*/
|
||||
typedef enum {
|
||||
JINT32,
|
||||
JINT16,
|
||||
JINT8,
|
||||
JUINT32,
|
||||
JUINT16,
|
||||
JUINT8,
|
||||
JFLOAT,
|
||||
JDOUBLE,
|
||||
JBOOL,
|
||||
JSTRING,
|
||||
JOBJECT
|
||||
} JsonDataType;
|
||||
|
||||
/**
|
||||
* @brief Define a device property, as a JSON document node
|
||||
*/
|
||||
typedef struct _JSONNode {
|
||||
char *key; // Key of this JSON node
|
||||
void *data; // Value of this JSON node
|
||||
uint16_t data_buff_len; // data buff len, for string type value update
|
||||
JsonDataType type; // Data type of this JSON node
|
||||
} DeviceProperty;
|
||||
|
||||
/**
|
||||
* @brief Define a device action
|
||||
*/
|
||||
typedef struct {
|
||||
char *pActionId; // action id
|
||||
uint32_t timestamp; // action timestamp
|
||||
uint8_t input_num; // input num
|
||||
uint8_t output_num; // output mun
|
||||
DeviceProperty *pInput; // input
|
||||
DeviceProperty *pOutput; // output
|
||||
} DeviceAction;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Define MQTT data_template callback when request response arrived
|
||||
*
|
||||
* @param method type of request
|
||||
* @param requestAck response type
|
||||
* @param pJsonDocument JSON document from server
|
||||
* @param userContext User context
|
||||
*
|
||||
*/
|
||||
typedef void (*OnReplyCallback)(void *pClient, Method method, ReplyAck replyAck, const char *pJsonDocument, void *userContext);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Define callback when device property change
|
||||
*
|
||||
* @param pJsonValueBuffer property JSON buffer
|
||||
* @param valueLength property length
|
||||
* @param DeviceProperty reference to device property
|
||||
*/
|
||||
typedef void (*OnPropRegCallback)(void *pClient, const char *pJsonValueBuffer, uint32_t valueLength, DeviceProperty *pProperty);
|
||||
|
||||
/**
|
||||
* @brief action handle callback
|
||||
*
|
||||
* @param pAction action with input data
|
||||
*/
|
||||
typedef void (*OnActionHandleCallback)(void *pClient, const char *pClientToken, DeviceAction *pAction);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_SHADOW_H_ */
|
270
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_mqtt.h
vendored
Normal file
270
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_mqtt.h
vendored
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_MQTT_H_
|
||||
#define QCLOUD_IOT_EXPORT_MQTT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief MQTT Quality of Service level
|
||||
*
|
||||
* Check MQTT spec for QoS define
|
||||
*/
|
||||
typedef enum _QoS {
|
||||
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 retained; // RETAIN flag
|
||||
uint8_t dup; // DUP flag
|
||||
uint16_t id; // MQTT Id
|
||||
|
||||
const char *ptopic; // MQTT topic
|
||||
size_t topic_len; // topic length
|
||||
|
||||
void *payload; // MQTT msg payload
|
||||
size_t payload_len; // MQTT length of msg payload
|
||||
} MQTTMessage;
|
||||
|
||||
typedef MQTTMessage PublishParams;
|
||||
|
||||
#define DEFAULT_PUB_PARAMS {QOS0, 0, 0, 0, NULL, 0, NULL, 0}
|
||||
|
||||
typedef enum {
|
||||
|
||||
/* MQTT undefined event */
|
||||
MQTT_EVENT_UNDEF = 0,
|
||||
|
||||
/* MQTT disconnect */
|
||||
MQTT_EVENT_DISCONNECT = 1,
|
||||
|
||||
/* MQTT reconnect */
|
||||
MQTT_EVENT_RECONNECT = 2,
|
||||
|
||||
/* MQTT subscribe success */
|
||||
MQTT_EVENT_SUBCRIBE_SUCCESS = 3,
|
||||
|
||||
/* MQTT subscribe timeout */
|
||||
MQTT_EVENT_SUBCRIBE_TIMEOUT = 4,
|
||||
|
||||
/* MQTT subscribe fail */
|
||||
MQTT_EVENT_SUBCRIBE_NACK = 5,
|
||||
|
||||
/* MQTT unsubscribe success */
|
||||
MQTT_EVENT_UNSUBCRIBE_SUCCESS = 6,
|
||||
|
||||
/* MQTT unsubscribe timeout */
|
||||
MQTT_EVENT_UNSUBCRIBE_TIMEOUT = 7,
|
||||
|
||||
/* MQTT unsubscribe fail */
|
||||
MQTT_EVENT_UNSUBCRIBE_NACK = 8,
|
||||
|
||||
/* MQTT publish success */
|
||||
MQTT_EVENT_PUBLISH_SUCCESS = 9,
|
||||
|
||||
/* MQTT publish timeout */
|
||||
MQTT_EVENT_PUBLISH_TIMEOUT = 10,
|
||||
|
||||
/* MQTT publish fail */
|
||||
MQTT_EVENT_PUBLISH_NACK = 11,
|
||||
|
||||
/* MQTT received msg from server */
|
||||
MQTT_EVENT_PUBLISH_RECVEIVED = 12,
|
||||
|
||||
/* MQTT client destroy */
|
||||
MQTT_EVENT_CLIENT_DESTROY = 13,
|
||||
|
||||
/* MQTT unsubscribe */
|
||||
MQTT_EVENT_UNSUBSCRIBE = 14,
|
||||
|
||||
} MQTTEventType;
|
||||
|
||||
/**
|
||||
* @brief Define MQTT SUBSCRIBE callback when message arrived
|
||||
*/
|
||||
typedef void (*OnMessageHandler)(void *pClient, MQTTMessage *message, void *pUserData);
|
||||
|
||||
/**
|
||||
* @brief Define MQTT SUBSCRIBE callback when event happened
|
||||
*/
|
||||
typedef void (*OnSubEventHandler)(void *pClient, MQTTEventType event_type, void *pUserData);
|
||||
|
||||
/**
|
||||
* @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
|
||||
} SubscribeParams;
|
||||
|
||||
/**
|
||||
* Default MQTT subscription parameters
|
||||
*/
|
||||
#define DEFAULT_SUB_PARAMS {QOS0, NULL, NULL, NULL}
|
||||
|
||||
|
||||
typedef struct {
|
||||
/* MQTT event type */
|
||||
MQTTEventType event_type;
|
||||
|
||||
void *msg;
|
||||
} MQTTEventMsg;
|
||||
|
||||
/**
|
||||
* @brief Define MQTT callback when MQTT event happen
|
||||
*
|
||||
* @param pclient, the MQTT client
|
||||
* @param context, user callback context
|
||||
* @param msg, the event message.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
typedef void (*MQTTEventHandleFun)(void *pclient, void *context, MQTTEventMsg *msg);
|
||||
|
||||
|
||||
/* The structure of MQTT event handle */
|
||||
typedef struct {
|
||||
MQTTEventHandleFun h_fp;
|
||||
void *context;
|
||||
} MQTTEventHandler;
|
||||
|
||||
/* The structure of MQTT init parameters */
|
||||
typedef struct {
|
||||
/* device info */
|
||||
char *product_id; // product ID
|
||||
char *device_name; // device name
|
||||
|
||||
#ifdef AUTH_MODE_CERT
|
||||
char *cert_file; // cert file path
|
||||
char *key_file; // key file path
|
||||
#else
|
||||
char *device_secret; // device secret
|
||||
#endif
|
||||
|
||||
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
|
||||
|
||||
MQTTEventHandler event_handle; // event callback
|
||||
|
||||
} MQTTInitParams;
|
||||
|
||||
/**
|
||||
* Default MQTT init parameters
|
||||
*/
|
||||
#ifdef AUTH_MODE_CERT
|
||||
#define DEFAULT_MQTTINIT_PARAMS { NULL, NULL, NULL, NULL, 5000, 240 * 1000, 1, 1, {0}}
|
||||
#else
|
||||
#define DEFAULT_MQTTINIT_PARAMS { NULL, NULL, NULL, 5000, 240 * 1000, 1, 1, {0}}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Create MQTT client and connect to MQTT server
|
||||
*
|
||||
* @param pParams MQTT init parameters
|
||||
*
|
||||
* @return a valid MQTT client handle when success, or NULL otherwise
|
||||
*/
|
||||
void* IOT_MQTT_Construct(MQTTInitParams *pParams);
|
||||
|
||||
/**
|
||||
* @brief Close connection and destroy MQTT client
|
||||
*
|
||||
* @param pClient pointer of handle to MQTT client
|
||||
*
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int IOT_MQTT_Destroy(void **pClient);
|
||||
|
||||
/**
|
||||
* @brief Check connection and keep alive state, read/handle MQTT message in synchronized way
|
||||
*
|
||||
* @param pClient handle to MQTT client
|
||||
* @param timeout_ms timeout value (unit: ms) for this operation
|
||||
*
|
||||
* @return QCLOUD_RET_SUCCESS when success, QCLOUD_ERR_MQTT_ATTEMPTING_RECONNECT when try reconnecing, or err code for failure
|
||||
*/
|
||||
int IOT_MQTT_Yield(void *pClient, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Publish MQTT message
|
||||
*
|
||||
* @param pClient handle to MQTT client
|
||||
* @param topicName MQTT topic name
|
||||
* @param pParams publish parameters
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_MQTT_Publish(void *pClient, char *topicName, PublishParams *pParams);
|
||||
|
||||
/**
|
||||
* @brief Subscribe MQTT topic
|
||||
*
|
||||
* @param pClient handle to MQTT client
|
||||
* @param topicFilter MQTT topic filter
|
||||
* @param pParams subscribe parameters
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_MQTT_Subscribe(void *pClient, char *topicFilter, SubscribeParams *pParams);
|
||||
|
||||
/**
|
||||
* @brief Unsubscribe MQTT topic
|
||||
*
|
||||
* @param pClient handle to MQTT client
|
||||
* @param topicFilter MQTT topic filter
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_MQTT_Unsubscribe(void *pClient, char *topicFilter);
|
||||
|
||||
/**
|
||||
* @brief Check if MQTT is connected
|
||||
*
|
||||
* @param pClient handle to MQTT client
|
||||
* @return true= connected, false = unconnected
|
||||
*/
|
||||
bool IOT_MQTT_IsConnected(void *pClient);
|
||||
|
||||
/**
|
||||
* @brief Get error code of last IOT_MQTT_Construct operation
|
||||
*
|
||||
* @return error code of last IOT_MQTT_Construct operation
|
||||
*/
|
||||
int IOT_MQTT_GetErrCode(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_MQTT_H_ */
|
262
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_ota.h
vendored
Normal file
262
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/exports/qcloud_iot_export_ota.h
vendored
Normal file
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_OTA_H_
|
||||
#define QCLOUD_IOT_EXPORT_OTA_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "qcloud_iot_import.h"
|
||||
|
||||
|
||||
typedef enum {
|
||||
|
||||
IOT_OTA_ERR_FAIL = -1,
|
||||
IOT_OTA_ERR_INVALID_PARAM = -2,
|
||||
IOT_OTA_ERR_INVALID_STATE = -3,
|
||||
IOT_OTA_ERR_STR_TOO_LONG = -4,
|
||||
IOT_OTA_ERR_FETCH_FAILED = -5,
|
||||
IOT_OTA_ERR_FETCH_NOT_EXIST = -6,
|
||||
IOT_OTA_ERR_FETCH_AUTH_FAIL = -7,
|
||||
IOT_OTA_ERR_FETCH_TIMEOUT = -8,
|
||||
IOT_OTA_ERR_NOMEM = -9,
|
||||
IOT_OTA_ERR_OSC_FAILED = -10,
|
||||
IOT_OTA_ERR_REPORT_VERSION = -11,
|
||||
IOT_OTA_ERR_NONE = 0
|
||||
|
||||
} IOT_OTA_Error_Code;
|
||||
|
||||
|
||||
/* type of OTA state */
|
||||
typedef enum {
|
||||
IOT_OTAS_UNINITED = 0, /* un-inited */
|
||||
IOT_OTAS_INITED, /* inited */
|
||||
IOT_OTAS_FETCHING, /* fetching */
|
||||
IOT_OTAS_FETCHED, /* fetched */
|
||||
IOT_OTAS_DISCONNECTED /* disconnected */
|
||||
} IOT_OTA_State_Code;
|
||||
|
||||
|
||||
/* type of OTA progress */
|
||||
typedef enum {
|
||||
|
||||
/* firmware upgrade failed */
|
||||
IOT_OTAP_BURN_FAILED = -4,
|
||||
|
||||
/* firmware checksum failed */
|
||||
IOT_OTAP_CHECK_FALIED = -3,
|
||||
|
||||
/* firmware download failed */
|
||||
IOT_OTAP_FETCH_FAILED = -2,
|
||||
|
||||
/* init failed */
|
||||
IOT_OTAP_GENERAL_FAILED = -1,
|
||||
|
||||
|
||||
/* [0, 100], progress percentage */
|
||||
|
||||
/* minimal of progress percentage */
|
||||
IOT_OTAP_FETCH_PERCENTAGE_MIN = 0,
|
||||
|
||||
/* maximal of progress percentage */
|
||||
IOT_OTAP_FETCH_PERCENTAGE_MAX = 100
|
||||
|
||||
} IOT_OTA_Progress_Code;
|
||||
|
||||
|
||||
typedef enum {
|
||||
|
||||
IOT_OTAG_FETCHED_SIZE, /* Size of firmware fetched */
|
||||
IOT_OTAG_FILE_SIZE, /* Total size of firmware */
|
||||
IOT_OTAG_MD5SUM, /* firmware md5 checksum (string) */
|
||||
IOT_OTAG_VERSION, /* firmware version (string) */
|
||||
IOT_OTAG_CHECK_FIRMWARE /* check firmware */
|
||||
|
||||
} IOT_OTA_CmdType;
|
||||
|
||||
typedef enum {
|
||||
|
||||
IOT_OTAR_DOWNLOAD_TIMEOUT = -1,
|
||||
IOT_OTAR_FILE_NOT_EXIST = -2,
|
||||
IOT_OTAR_AUTH_FAIL = -3,
|
||||
IOT_OTAR_MD5_NOT_MATCH = -4,
|
||||
IOT_OTAR_UPGRADE_FAIL = -5,
|
||||
IOT_OTAR_NONE = 0,
|
||||
IOT_OTAR_DOWNLOAD_BEGIN = 1,
|
||||
IOT_OTAR_DOWNLOADING = 2,
|
||||
IOT_OTAR_UPGRADE_BEGIN = 3,
|
||||
IOT_OTAR_UPGRADE_SUCCESS = 4,
|
||||
|
||||
} IOT_OTAReportType;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Init OTA module and resources
|
||||
* MQTT/COAP Client should be constructed beforehand
|
||||
*
|
||||
* @param product_id: product Id
|
||||
* @param device_name: device name
|
||||
* @param ch_signal: channel: MQTT or COAP
|
||||
*
|
||||
* @return a valid OTA module handle when success, or NULL otherwise
|
||||
*/
|
||||
void *IOT_OTA_Init(const char *product_id, const char *device_name, void *ch_signal);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Destroy OTA module and resources
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
*
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_OTA_Destroy(void *handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Setup HTTP connection and prepare OTA download
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
* @param offset: offset of firmware downloaded
|
||||
* @param size: size of firmware
|
||||
*
|
||||
* @return QCLOUD_RET_SUCCESS when success, or err code for failure
|
||||
*/
|
||||
int IOT_OTA_StartDownload(void *handle, uint32_t offset, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Update MD5 of local firmware
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
* @param buff: buffer to firmware
|
||||
* @param size: size of buffer
|
||||
*
|
||||
*/
|
||||
void IOT_OTA_UpdateClientMd5(void *handle, char * buff, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Report local firmware version to server
|
||||
* NOTE: do this report before real download
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
* @param version: local firmware version string
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_OTA_ReportVersion(void *handle, const char *version);
|
||||
|
||||
/**
|
||||
* @brief Report upgrade begin to server
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_OTA_ReportUpgradeBegin(void *handle);
|
||||
|
||||
/**
|
||||
* @brief Report upgrade success to server
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
* @param version: version string of firmware to upgrade
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_OTA_ReportUpgradeSuccess(void *handle, const char *version);
|
||||
|
||||
/**
|
||||
* @brief Report upgrade fail to server
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
* @param version: version string of firmware to upgrade
|
||||
*
|
||||
* @return packet id (>=0) when success, or err code (<0) for failure
|
||||
*/
|
||||
int IOT_OTA_ReportUpgradeFail(void *handle, const char *version);
|
||||
|
||||
/**
|
||||
* @brief Check if firmware is fetching/downloading
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
*
|
||||
* @retval 1 : Yes.
|
||||
* @retval 0 : No.
|
||||
*/
|
||||
int IOT_OTA_IsFetching(void *handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Check if firmware fetching/downloading is finished
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
*
|
||||
* @retval 1 : Yes.
|
||||
* @retval 0 : No.
|
||||
*/
|
||||
int IOT_OTA_IsFetchFinish(void *handle);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Download firmware from HTTP server and save to buffer
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
* @param buf: buffer to store firmware
|
||||
* @param buf_len: length of buffer
|
||||
* @param timeout_s: timeout value in second
|
||||
*
|
||||
* @retval < 0 : error code
|
||||
* @retval 0 : no data is downloaded in this period and timeout happen
|
||||
* @retval (0, len] : size of the downloaded data
|
||||
*/
|
||||
int IOT_OTA_FetchYield(void *handle, char *buf, uint32_t buf_len, uint32_t timeout_s);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get OTA info (version, file_size, MD5, download state) from OTA module
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
* @param type: type of info to get, refer to IOT_OTA_CmdType
|
||||
* @param buf: buffer for the data
|
||||
* @param buf_len: length of buffer
|
||||
* @return
|
||||
NOTE:
|
||||
1) if type==IOT_OTAG_FETCHED_SIZE, 'buf' = uint32_t pointer, 'buf_len' = 4
|
||||
2) if type==IOT_OTAG_FILE_SIZE, 'buf' = uint32_t pointer, 'buf_len' = 4
|
||||
3) if type==IOT_OTAG_MD5SUM, 'buf' = char array buffer, 'buf_len = 33
|
||||
4) if type==IOT_OTAG_VERSION, 'buf'= char array buffer, 'buf_len = OTA_VERSION_LEN_MAX
|
||||
5) if type==IOT_OTAG_CHECK_FIRMWARE, 'buf' = uint32_t pointer, 'buf_len' = 4
|
||||
*
|
||||
* @retval 0 : success
|
||||
* @retval < 0 : error code for failure
|
||||
*/
|
||||
int IOT_OTA_Ioctl(void *handle, IOT_OTA_CmdType type, void *buf, size_t buf_len);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get error code of last operation
|
||||
*
|
||||
* @param handle: OTA module handle
|
||||
*
|
||||
* @return error code
|
||||
*/
|
||||
int IOT_OTA_GetLastError(void *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_OTA_H_ */
|
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_SYSTEM_H_
|
||||
#define QCLOUD_IOT_EXPORT_SYSTEM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get system timestamp from MQTT server
|
||||
*
|
||||
* @param pClient MQTTClient pointer
|
||||
* @param time timestamp value return from server
|
||||
* @return QCLOUD_RET_SUCCESS for success
|
||||
* otherwise, failure
|
||||
*/
|
||||
int IOT_Get_SysTime(void* pClient, long* time);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_COAP_H_ */
|
498
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/lite-list.h
vendored
Normal file
498
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/lite-list.h
vendored
Normal file
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2019 Tencent Group. All rights reserved.
|
||||
* License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Edit by shockcao@tencent.com 2018/3/15
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_LIST_H
|
||||
#define _LINUX_LIST_H
|
||||
|
||||
#define inline __inline
|
||||
|
||||
typedef struct list_head list_head_t;
|
||||
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
/*
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
static inline void INIT_LIST_HEAD(struct list_head *list)
|
||||
{
|
||||
list->next = list;
|
||||
list->prev = list;
|
||||
}
|
||||
|
||||
/*
|
||||
* Insert a new_ptr entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *new_ptr,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new_ptr;
|
||||
new_ptr->next = next;
|
||||
new_ptr->prev = prev;
|
||||
prev->next = new_ptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new_ptr entry
|
||||
* @new_ptr: new_ptr entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new_ptr entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new_ptr, struct list_head *head)
|
||||
{
|
||||
__list_add(new_ptr, head, head->next);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new_ptr entry
|
||||
* @new_ptr: new_ptr entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new_ptr entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *new_ptr, struct list_head *head)
|
||||
{
|
||||
__list_add(new_ptr, head->prev, head);
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head *prev, struct list_head *next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty() on entry does not return true after this, the entry is
|
||||
* in an undefined state.
|
||||
*/
|
||||
static inline void __list_del_entry(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_replace - replace old entry by new_ptr one
|
||||
* @old : the element to be replaced
|
||||
* @new_ptr : the new_ptr element to insert
|
||||
*
|
||||
* If @old was empty, it will be overwritten.
|
||||
*/
|
||||
static inline void list_replace(struct list_head *old,
|
||||
struct list_head *new_ptr)
|
||||
{
|
||||
new_ptr->next = old->next;
|
||||
new_ptr->next->prev = new_ptr;
|
||||
new_ptr->prev = old->prev;
|
||||
new_ptr->prev->next = new_ptr;
|
||||
}
|
||||
|
||||
static inline void list_replace_init(struct list_head *old,
|
||||
struct list_head *new_ptr)
|
||||
{
|
||||
list_replace(old, new_ptr);
|
||||
INIT_LIST_HEAD(old);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del_entry(entry);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del_entry(list);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del_entry(list);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_last - tests whether @list is the last entry in list @head
|
||||
* @list: the entry to test
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline int list_is_last(const struct list_head *list,
|
||||
const struct list_head *head)
|
||||
{
|
||||
return list->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(const struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty_careful - tests whether a list is empty and not being modified
|
||||
* @head: the list to test
|
||||
*
|
||||
* Description:
|
||||
* tests whether a list is empty _and_ checks that no other CPU might be
|
||||
* in the process of modifying either member (next or prev)
|
||||
*
|
||||
* NOTE: using list_empty_careful() without synchronization
|
||||
* can only be safe if the only activity that can happen
|
||||
* to the list entry is list_del_init(). Eg. it cannot be used
|
||||
* if another CPU could re-list_add() it.
|
||||
*/
|
||||
static inline int list_empty_careful(const struct list_head *head)
|
||||
{
|
||||
struct list_head *next = head->next;
|
||||
return (next == head) && (next == head->prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_rotate_left - rotate the list to the left
|
||||
* @head: the head of the list
|
||||
*/
|
||||
static inline void list_rotate_left(struct list_head *head)
|
||||
{
|
||||
struct list_head *first;
|
||||
|
||||
if (!list_empty(head)) {
|
||||
first = head->next;
|
||||
list_move_tail(first, head);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_is_singular - tests whether a list has just one entry.
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_is_singular(const struct list_head *head)
|
||||
{
|
||||
return !list_empty(head) && (head->next == head->prev);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
container_of(ptr, type, member)
|
||||
|
||||
/**
|
||||
* list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define list_first_entry(ptr, type, member) \
|
||||
list_entry((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* list_last_entry - get the last element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define list_last_entry(ptr, type, member) \
|
||||
list_entry((ptr)->prev, type, member)
|
||||
|
||||
/**
|
||||
* list_first_entry_or_null - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note that if the list is empty, it returns NULL.
|
||||
*/
|
||||
#define list_first_entry_or_null(ptr, type, member) \
|
||||
(!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
|
||||
|
||||
/**
|
||||
* list_next_entry - get the next element in list
|
||||
* @pos: the type * to cursor
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_next_entry(pos, member, type) \
|
||||
list_entry((pos)->member.next, type, member)
|
||||
|
||||
/**
|
||||
* list_prev_entry - get the prev element in list
|
||||
* @pos: the type * to cursor
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_prev_entry(pos, member, type) \
|
||||
list_entry((pos)->member.prev, type, member)
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* __list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*
|
||||
* This variant doesn't differ from list_for_each() any more.
|
||||
* We don't do prefetching in either case.
|
||||
*/
|
||||
#define __list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop cursor.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev_safe(pos, n, head) \
|
||||
for (pos = (head)->prev, n = pos->prev; \
|
||||
pos != (head); \
|
||||
pos = n, n = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member, type) \
|
||||
for (pos = list_entry((head)->next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_reverse - iterate backwards over list of given type.
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_reverse(pos, head, member, type) \
|
||||
for (pos = list_entry((head)->prev, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, type, member))
|
||||
|
||||
/**
|
||||
* list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
|
||||
* @pos: the type * to use as a start point
|
||||
* @head: the head of the list
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Prepares a pos entry for use as a start point in list_for_each_entry_continue().
|
||||
*/
|
||||
#define list_prepare_entry(pos, head, member, type) \
|
||||
((pos) ? : list_entry(head, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_continue - continue iteration over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Continue to iterate over list of given type, continuing after
|
||||
* the current position.
|
||||
*/
|
||||
#define list_for_each_entry_continue(pos, head, member, type) \
|
||||
for (pos = list_entry(pos->member.next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_continue_reverse - iterate backwards from the given point
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Start to iterate over list of given type backwards, continuing after
|
||||
* the current position.
|
||||
*/
|
||||
#define list_for_each_entry_continue_reverse(pos, head, member, type) \
|
||||
for (pos = list_entry(pos->member.prev, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_from - iterate over list of given type from the current point
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type, continuing from current position.
|
||||
*/
|
||||
#define list_for_each_entry_from(pos, head, member, type) \
|
||||
for (; &pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member, type) \
|
||||
for (pos = list_entry((head)->next, type, member), \
|
||||
n = list_entry(pos->member.next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_continue - continue list iteration safe against removal
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type, continuing after current point,
|
||||
* safe against removal of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_continue(pos, n, head, member, type) \
|
||||
for (pos = list_entry(pos->member.next, type, member), \
|
||||
n = list_entry(pos->member.next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_from - iterate over list from current point safe against removal
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate over list of given type from current point, safe against
|
||||
* removal of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_from(pos, n, head, member, type) \
|
||||
for (n = list_entry(pos->member.next, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, type, member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Iterate backwards over list of given type, safe against removal
|
||||
* of list entry.
|
||||
*/
|
||||
#define list_for_each_entry_safe_reverse(pos, n, head, member, type) \
|
||||
for (pos = list_entry((head)->prev, type, member), \
|
||||
n = list_entry(pos->member.prev, type, member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.prev, type, member))
|
||||
|
||||
/**
|
||||
* list_safe_reset_next - reset a stale list_for_each_entry_safe loop
|
||||
* @pos: the loop cursor used in the list_for_each_entry_safe loop
|
||||
* @n: temporary storage used in list_for_each_entry_safe
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* list_safe_reset_next is not safe to use in general if the list may be
|
||||
* modified concurrently (eg. the lock is dropped in the loop body). An
|
||||
* exception to this is if the cursor element (pos) is pinned in the list,
|
||||
* and list_safe_reset_next is called after re-taking the lock and before
|
||||
* completing the current iteration of the loop body.
|
||||
*/
|
||||
#define list_safe_reset_next(pos, n, member, type) \
|
||||
n = list_entry(pos->member.next, type, member)
|
||||
|
||||
#endif
|
99
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/lite-utils.h
vendored
Normal file
99
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/lite-utils.h
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2017-2019 Tencent Group. All rights reserved.
|
||||
* License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Edit by shockcao@tencent.com 2018/3/15
|
||||
*/
|
||||
|
||||
#ifndef __LITE_UTILS_H__
|
||||
#define __LITE_UTILS_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#if defined(_PLATFORM_IS_LINUX_)
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#include "lite-list.h"
|
||||
#include "qcloud_iot_import.h"
|
||||
|
||||
#define LITE_TRUE (1)
|
||||
#define LITE_FALSE (0)
|
||||
|
||||
#ifndef container_of
|
||||
#define container_of(ptr, type, member) \
|
||||
((type *) ((char *) (ptr) - offsetof(type, member)))
|
||||
#endif
|
||||
|
||||
#define LITE_MINIMUM(a, b) (((a) <= (b)) ? (a) : (b))
|
||||
#define LITE_MAXIMUM(a, b) (((a) >= (b)) ? (a) : (b))
|
||||
#define LITE_isdigit(c) (((c) <= '9' && (c) >= '0') ? (LITE_TRUE) : (LITE_FALSE))
|
||||
|
||||
#if defined(_PLATFORM_IS_LINUX_)
|
||||
#define LITE_ASSERT(expr) assert(expr)
|
||||
#else
|
||||
#define LITE_ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
HAL_Printf("### %s | %s(%d): ASSERT FAILED ###: %s is FALSE\r\n", \
|
||||
__FILE__, __func__, __LINE__, #expr); \
|
||||
} \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
char *LITE_strdup(const char *src);
|
||||
char *LITE_format_string(const char *fmt, ...);
|
||||
char *LITE_format_nstring(const int len, const char *fmt, ...);
|
||||
void LITE_hexbuf_convert(unsigned char *digest, char *out, int buflen, int uppercase);
|
||||
void LITE_hexstr_convert(char *hexstr, uint8_t *out_buf, int len);
|
||||
void LITE_replace_substr(char orig[], char key[], char swap[]);
|
||||
|
||||
char *LITE_json_value_of(char *key, char *src);
|
||||
list_head_t *LITE_json_keys_of(char *src, char *prefix);
|
||||
void LITE_json_keys_release(list_head_t *keylist);
|
||||
char *LITE_json_string_value_strip_transfer(char *key, char *src);
|
||||
|
||||
|
||||
int LITE_get_int32(int32_t *value, char *src);
|
||||
int LITE_get_int16(int16_t *value, char *src);
|
||||
int LITE_get_int8(int8_t *value, char *src);
|
||||
int LITE_get_uint32(uint32_t *value, char *src);
|
||||
int LITE_get_uint16(uint16_t *value, char *src);
|
||||
int LITE_get_uint8(uint8_t *value, char *src);
|
||||
int LITE_get_float(float *value, char *src);
|
||||
int LITE_get_double(double *value, char *src);
|
||||
int LITE_get_boolean(bool *value, char *src);
|
||||
int LITE_get_string(int8_t *value, char *src, uint16_t max_len);
|
||||
|
||||
|
||||
typedef struct _json_key_t {
|
||||
char *key;
|
||||
list_head_t list;
|
||||
} json_key_t;
|
||||
|
||||
#define foreach_json_keys_in(src, iter_key, keylist, pos) \
|
||||
for(keylist = (void *)LITE_json_keys_of((char *)src, ""), \
|
||||
pos = (void *)list_first_entry((list_head_t *)keylist, json_key_t, list), \
|
||||
iter_key = ((json_key_t *)pos)->key; \
|
||||
(iter_key = ((json_key_t *)pos)->key); \
|
||||
pos = list_next_entry((json_key_t *)pos, list, json_key_t))
|
||||
|
||||
#endif /* __LITE_UTILS_H__ */
|
52
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/platform.h
vendored
Normal file
52
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/platform.h
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PLATFORM_H_
|
||||
#define PLATFORM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PATH_MAX 4096
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#include <direct.h>
|
||||
#include <limits.h>
|
||||
typedef unsigned long ssize_t;
|
||||
#define getcwd(buffer,len) _getcwd(buffer,len)
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__linux__)
|
||||
#include <pthread.h>
|
||||
#include <fcntl.h>
|
||||
//#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <signal.h>
|
||||
#include <limits.h>
|
||||
#include <time.h>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PLATFORM_H_ */
|
96
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/qcloud_iot_export.h
vendored
Normal file
96
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/qcloud_iot_export.h
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_H_
|
||||
#define QCLOUD_IOT_EXPORT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
/* IoT C-SDK version info */
|
||||
#define QCLOUD_IOT_DEVICE_SDK_VERSION "3.1.0"
|
||||
|
||||
/**************** QCloud IoT C-SDK constants begin ************************/
|
||||
|
||||
/* MAX size of client ID */
|
||||
#define MAX_SIZE_OF_CLIENT_ID (80)
|
||||
|
||||
/* MAX size of product ID */
|
||||
#define MAX_SIZE_OF_PRODUCT_ID (10)
|
||||
|
||||
/* MAX size of product secret */
|
||||
#define MAX_SIZE_OF_PRODUCT_SECRET (32)
|
||||
|
||||
/* MAX size of device name */
|
||||
#define MAX_SIZE_OF_DEVICE_NAME (48)
|
||||
|
||||
/* MAX size of device secret */
|
||||
#define MAX_SIZE_OF_DEVICE_SECRET (64)
|
||||
|
||||
/* MAX size of device cert file name */
|
||||
#define MAX_SIZE_OF_DEVICE_CERT_FILE_NAME (128)
|
||||
|
||||
/* MAX size of device key file name */
|
||||
#define MAX_SIZE_OF_DEVICE_SECRET_FILE_NAME (128)
|
||||
|
||||
/* MAX num of subdevice */
|
||||
#define MAX_NUM_SUB_DEV (5)
|
||||
|
||||
/**************** QCloud IoT C-SDK constants end *************************/
|
||||
|
||||
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];
|
||||
#endif
|
||||
|
||||
#ifdef DEV_DYN_REG_ENABLED
|
||||
char product_secret[MAX_SIZE_OF_PRODUCT_SECRET + 1];
|
||||
#endif
|
||||
} DeviceInfo;
|
||||
|
||||
#ifdef GATEWAY_ENABLED
|
||||
typedef struct {
|
||||
DeviceInfo gw_info;
|
||||
DeviceInfo sub_dev_info[MAX_NUM_SUB_DEV];
|
||||
unsigned int sub_dev_num;
|
||||
} GatewayDeviceInfo;
|
||||
#endif
|
||||
|
||||
|
||||
#include "qcloud_iot_export_variables.h"
|
||||
#include "qcloud_iot_export_error.h"
|
||||
#include "qcloud_iot_export_log.h"
|
||||
#include "qcloud_iot_export_mqtt.h"
|
||||
#include "qcloud_iot_export_ota.h"
|
||||
#include "qcloud_iot_export_data_template.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_H_ */
|
77
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/qcloud_iot_export_variables.h
vendored
Normal file
77
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/qcloud_iot_export_variables.h
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_EXPORT_VARIABLES_H_
|
||||
#define QCLOUD_IOT_EXPORT_VARIABLES_H_
|
||||
|
||||
/*
|
||||
* Below variables are dependant on user situation (network status/device memory/application context)
|
||||
* Adjust the default value to meet your requirement
|
||||
*/
|
||||
|
||||
/* default MQTT/CoAP timeout value when connect/pub/sub (unit: ms) */
|
||||
#define QCLOUD_IOT_MQTT_COMMAND_TIMEOUT (5 * 1000)
|
||||
|
||||
/* default MQTT keep alive interval (unit: ms) */
|
||||
#define QCLOUD_IOT_MQTT_KEEP_ALIVE_INTERNAL (240 * 1000)
|
||||
|
||||
/* default MQTT Tx buffer size, MAX: 16*1024 */
|
||||
#define QCLOUD_IOT_MQTT_TX_BUF_LEN (2048)
|
||||
|
||||
/* default MQTT Rx buffer size, MAX: 16*1024 */
|
||||
#define QCLOUD_IOT_MQTT_RX_BUF_LEN (2048)
|
||||
|
||||
/* default COAP Tx buffer size, MAX: 1*1024 */
|
||||
#define COAP_SENDMSG_MAX_BUFLEN (512)
|
||||
|
||||
/* default COAP Rx buffer size, MAX: 1*1024 */
|
||||
#define COAP_RECVMSG_MAX_BUFLEN (512)
|
||||
|
||||
/* MAX MQTT reconnect interval (unit: ms) */
|
||||
#define MAX_RECONNECT_WAIT_INTERVAL (60 * 1000)
|
||||
|
||||
/* MAX valid time when connect to MQTT server. 0: always valid */
|
||||
/* Use this only if the device has accurate UTC time. Otherwise, set to 0 */
|
||||
#define MAX_ACCESS_EXPIRE_TIMEOUT (0)
|
||||
|
||||
|
||||
|
||||
/* log print/upload related variables */
|
||||
/* MAX size of log buffer for one log item including header and content */
|
||||
#define MAX_LOG_MSG_LEN (511)
|
||||
|
||||
#if defined(__linux__)
|
||||
#undef MAX_LOG_MSG_LEN
|
||||
#define MAX_LOG_MSG_LEN (1023)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Log upload related params, which will affect the size of device memory/disk consumption
|
||||
* the default value can be changed for different user situation
|
||||
*/
|
||||
// size of buffer for log upload
|
||||
#define LOG_UPLOAD_BUFFER_SIZE 5000
|
||||
|
||||
// Max size of one http log upload. Should not larger than 5000
|
||||
#define MAX_HTTP_LOG_POST_SIZE 3000
|
||||
|
||||
// MAX size for saving log into NVS (files/FLASH) after upload fail
|
||||
#define MAX_LOG_SAVE_SIZE (3*LOG_UPLOAD_BUFFER_SIZE)
|
||||
|
||||
// interval of log upload (unit: ms) Decrease this value if LOG_UPLOAD_BUFFER_SIZE is small
|
||||
#define LOG_UPLOAD_INTERVAL_MS 2000
|
||||
|
||||
|
||||
#endif /* QCLOUD_IOT_EXPORT_VARIABLES_H_ */
|
570
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/qcloud_iot_import.h
vendored
Normal file
570
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/qcloud_iot_import.h
vendored
Normal file
@@ -0,0 +1,570 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making IoT Hub available.
|
||||
* Copyright (C) 2016 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef QCLOUD_IOT_IMPORT_H_
|
||||
#define QCLOUD_IOT_IMPORT_H_
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
#include "platform.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define _IN_ /* indicate an input parameter */
|
||||
#define _OU_ /* indicate a output parameter */
|
||||
|
||||
#define IOT_TRUE (1) /* indicate boolean value true */
|
||||
#define IOT_FALSE (0) /* indicate boolean value false */
|
||||
|
||||
#define Max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define Min(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* QCloud IoT C-SDK Hardware Abstraction Layer
|
||||
* Platform/OS/IP stack/SSL dependant functions
|
||||
* Check platform folder for reference implementaions
|
||||
* Require porting when adapt SDK to new platform/OS
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Create a thread/task
|
||||
*
|
||||
* @param stack_size thread stack size
|
||||
* @param priority thread priority
|
||||
* @param taskname task name
|
||||
* @param fn thread runtime function callback
|
||||
* @param arg thread function context
|
||||
* @return a valid thread handle when success, or NULL otherwise
|
||||
*/
|
||||
void * HAL_ThreadCreate(uint16_t stack_size, int priority, char * taskname,void *(*fn)(void*), void* arg);
|
||||
|
||||
/**
|
||||
* @brief Destroy a thread/task
|
||||
*
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_ThreadDestroy(void *thread_t);
|
||||
|
||||
/**
|
||||
* @brief create semaphore
|
||||
*
|
||||
* @return a valid semaphore handle when success, or NULL otherwise
|
||||
*/
|
||||
void *HAL_SemaphoreCreate(void);
|
||||
|
||||
/**
|
||||
* @brief Destroy semaphore
|
||||
* @param sem semaphore handle
|
||||
*/
|
||||
void HAL_SemaphoreDestroy(void *sem);
|
||||
|
||||
/**
|
||||
* @brief Post semaphore
|
||||
* @param sem semaphore handle
|
||||
*/
|
||||
void HAL_SemaphorePost(void *sem);
|
||||
|
||||
/**
|
||||
* @brief Wait for semaphore
|
||||
* @param sem semaphore handle
|
||||
* @param timeout_ms waiting timeout value (unit: ms)
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_SemaphoreWait(void *sem, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Create mutex
|
||||
*
|
||||
* @return a valid mutex handle when success, or NULL otherwise
|
||||
*/
|
||||
void *HAL_MutexCreate(void);
|
||||
|
||||
/**
|
||||
* @brief Destroy mutex
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
*/
|
||||
void HAL_MutexDestroy(_IN_ void *mutex);
|
||||
|
||||
/**
|
||||
* @brief Lock a mutex in blocking way
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
*/
|
||||
void HAL_MutexLock(_IN_ void *mutex);
|
||||
|
||||
/**
|
||||
* @brief Lock a mutex in non-blocking way
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
* @return 0 for success, or err code for failure
|
||||
*/
|
||||
int HAL_MutexTryLock(_IN_ void *mutex);
|
||||
|
||||
/**
|
||||
* @brief Unlock/release mutex
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
*/
|
||||
void HAL_MutexUnlock(_IN_ void *mutex);
|
||||
|
||||
/**
|
||||
* @brief Malloc memory
|
||||
*
|
||||
* @param size Expected memory size (unit: byte)
|
||||
* @return pointer to the memory
|
||||
*/
|
||||
void *HAL_Malloc(_IN_ uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Free memory
|
||||
*
|
||||
* @param ptr pointer to the pre-malloc memory
|
||||
*/
|
||||
void HAL_Free(_IN_ void *ptr);
|
||||
|
||||
/**
|
||||
* @brief Print data to console in format
|
||||
*
|
||||
* @param fmt print format
|
||||
* @param ... variable number of arguments
|
||||
*/
|
||||
void HAL_Printf(_IN_ const char *fmt, ...);
|
||||
|
||||
/**
|
||||
* @brief Print data to string in format
|
||||
*
|
||||
* @param str destination string
|
||||
* @param len Max size of the output
|
||||
* @param fmt print format
|
||||
* @param ... variable number of arguments
|
||||
* @return number of bytes that print successfull
|
||||
*/
|
||||
int HAL_Snprintf(_IN_ char *str, const int len, const char *fmt, ...);
|
||||
|
||||
/**
|
||||
Print data to string in format
|
||||
*
|
||||
* @param str destination string
|
||||
* @param len Max size of the output
|
||||
* @param fmt print format
|
||||
* @param ap arguments list
|
||||
* @return number of bytes that print successfull
|
||||
|
||||
*/
|
||||
int HAL_Vsnprintf(_OU_ char *str, _IN_ const int len, _IN_ const char *fmt, _IN_ va_list ap);
|
||||
|
||||
/**
|
||||
* @brief Get timestamp in millisecond
|
||||
*
|
||||
* @return timestamp in millisecond
|
||||
*/
|
||||
uint32_t HAL_GetTimeMs(void);
|
||||
|
||||
/**
|
||||
* @brief Delay operation in blocking way
|
||||
*
|
||||
* @param ms sleep interval in millisecond
|
||||
*/
|
||||
void HAL_DelayMs(_IN_ uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Sleep for a while
|
||||
*
|
||||
* @param ms sleep interval in millisecond
|
||||
*/
|
||||
void HAL_SleepMs(_IN_ uint32_t ms);
|
||||
|
||||
/**
|
||||
* @brief Set device info to NVS(flash/files)
|
||||
*
|
||||
* @param pdevInfo reference to device info
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_SetDevInfo(void *pdevInfo);
|
||||
|
||||
/**
|
||||
* @brief Get device info from NVS(flash/files)
|
||||
*
|
||||
* @param pdevInfo reference to device info
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_GetDevInfo(void *pdevInfo);
|
||||
|
||||
#ifdef GATEWAY_ENABLED
|
||||
/**
|
||||
* @brief Get gateway device info from NVS(flash/files)
|
||||
*
|
||||
* @param pgwDeviceInfo reference to gateway device info
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_GetGwDevInfo(void *pgwDeviceInfo);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the name of file which contain device info
|
||||
*
|
||||
* @param file_name the name of file which contain device info
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_SetDevInfoFile(const char *file_name);
|
||||
|
||||
|
||||
/**
|
||||
* Define timer structure, platform dependant
|
||||
*/
|
||||
struct Timer {
|
||||
#if defined(__linux__) && defined(__GLIBC__)
|
||||
struct timeval end_time;
|
||||
#else
|
||||
uintptr_t end_time;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef struct Timer Timer;
|
||||
|
||||
/**
|
||||
* @brief Check if timer expires or not
|
||||
*
|
||||
* @param timer reference to timer
|
||||
* @return true = expired, false = not expired yet
|
||||
*/
|
||||
bool HAL_Timer_expired(Timer *timer);
|
||||
|
||||
/**
|
||||
* @brief Set the countdown/expired value for the timer
|
||||
*
|
||||
* @param timer reference to timer
|
||||
* @param timeout_ms countdown/expired value (unit: millisecond)
|
||||
*/
|
||||
void HAL_Timer_countdown_ms(Timer *timer, unsigned int timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Set the countdown/expired value for the timer
|
||||
*
|
||||
* @param timer reference to timer
|
||||
* @param timeout countdown/expired value (unit: second)
|
||||
*/
|
||||
void HAL_Timer_countdown(Timer *timer, unsigned int timeout);
|
||||
|
||||
/**
|
||||
* @brief Check the remain time of the timer
|
||||
*
|
||||
* @param timer reference to timer
|
||||
* @return 0 if expired, or the left time in millisecond
|
||||
*/
|
||||
int HAL_Timer_remain(Timer *timer);
|
||||
|
||||
/**
|
||||
* @brief Init the timer
|
||||
*
|
||||
* @param timer reference to timer
|
||||
*/
|
||||
void HAL_Timer_init(Timer *timer);
|
||||
|
||||
/**
|
||||
* @brief Get local time in format: %Y-%m-%d %z %H:%M:%S
|
||||
*
|
||||
* @return string of formatted time
|
||||
*/
|
||||
char* HAL_Timer_current(void);
|
||||
|
||||
/**
|
||||
* @brief Get timestamp in second
|
||||
*
|
||||
* @return timestamp in second
|
||||
*/
|
||||
long HAL_Timer_current_sec(void);
|
||||
|
||||
#ifdef AT_TCP_ENABLED
|
||||
int HAL_AT_TCP_Init(void);
|
||||
uintptr_t HAL_AT_TCP_Connect(const char *host, uint16_t port);
|
||||
int HAL_AT_TCP_Disconnect(uintptr_t fd);
|
||||
int HAL_AT_TCP_Write(uintptr_t fd, const unsigned char *buf, uint32_t len, uint32_t timeout_ms, size_t *written_len);
|
||||
int HAL_AT_TCP_Read(uintptr_t fd, uint8_t *buf, uint32_t len, uint32_t timeout_ms, uint32_t *read_len);
|
||||
int at_device_init(void);
|
||||
int HAL_AT_Uart_Init(void);
|
||||
int HAL_AT_Uart_Deinit(void);
|
||||
int HAL_AT_Uart_Send(void *data, uint32_t size);
|
||||
int HAL_AT_Uart_Recv(void *data, uint32_t expect_size, uint32_t *recv_size, uint32_t timeout);
|
||||
#endif
|
||||
|
||||
|
||||
/********** TLS/DTLS network sturcture and operations **********/
|
||||
|
||||
#ifndef AUTH_WITH_NOTLS
|
||||
/**
|
||||
* @brief Define structure for TLS connection parameters
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
const char *ca_crt;
|
||||
uint16_t ca_crt_len;
|
||||
|
||||
#ifdef AUTH_MODE_CERT
|
||||
/**
|
||||
* Device with certificate
|
||||
*/
|
||||
const char *cert_file; // public certificate file
|
||||
const char *key_file; // pravite certificate file
|
||||
#else
|
||||
/**
|
||||
* Device with PSK
|
||||
*/
|
||||
const char *psk; // PSK string
|
||||
const char *psk_id; // PSK ID
|
||||
#endif
|
||||
|
||||
size_t psk_length; // PSK length
|
||||
|
||||
unsigned int timeout_ms; // SSL handshake timeout in millisecond
|
||||
|
||||
} SSLConnectParams;
|
||||
|
||||
|
||||
typedef SSLConnectParams TLSConnectParams;
|
||||
|
||||
/**
|
||||
* @brief Setup TLS connection with server
|
||||
*
|
||||
* @param pConnectParams reference to TLS connection parameters
|
||||
* @host server address
|
||||
* @port server port
|
||||
* @return TLS connect handle when success, or 0 otherwise
|
||||
*/
|
||||
uintptr_t HAL_TLS_Connect(TLSConnectParams *pConnectParams, const char *host, int port);
|
||||
|
||||
/**
|
||||
* @brief Disconnect with TLS server and release resources
|
||||
*
|
||||
* @param handle TLS connect handle
|
||||
*/
|
||||
void HAL_TLS_Disconnect(uintptr_t handle);
|
||||
|
||||
/**
|
||||
* @brief Write data via TLS connection
|
||||
*
|
||||
* @param handle TLS connect handle
|
||||
* @param data source data to write
|
||||
* @param totalLen length of data
|
||||
* @param timeout_ms timeout value in millisecond
|
||||
* @param written_len length of data written successfully
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_TLS_Write(uintptr_t handle, unsigned char *data, size_t totalLen, uint32_t timeout_ms,
|
||||
size_t *written_len);
|
||||
|
||||
/**
|
||||
* @brief Read data via TLS connection
|
||||
*
|
||||
* @param handle TLS connect handle
|
||||
* @param data destination data buffer where to put data
|
||||
* @param totalLen length of data
|
||||
* @param timeout_ms timeout value in millisecond
|
||||
* @param read_len length of data read successfully
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_TLS_Read(uintptr_t handle, unsigned char *data, size_t totalLen, uint32_t timeout_ms,
|
||||
size_t *read_len);
|
||||
|
||||
/********** DTLS network **********/
|
||||
#ifdef COAP_COMM_ENABLED
|
||||
typedef SSLConnectParams DTLSConnectParams;
|
||||
|
||||
/**
|
||||
* @brief Setup DTLS connection with server
|
||||
*
|
||||
* @param pConnectParams reference to DTLS connection parameters
|
||||
* @host server address
|
||||
* @port server port
|
||||
* @return DTLS connect handle when success, or 0 otherwise
|
||||
*/
|
||||
uintptr_t HAL_DTLS_Connect(DTLSConnectParams *pConnectParams, const char *host, int port);
|
||||
|
||||
/**
|
||||
* @brief Disconnect with DTLS server and release resources
|
||||
*
|
||||
* @param handle DTLS connect handle
|
||||
*/
|
||||
void HAL_DTLS_Disconnect(uintptr_t handle);
|
||||
|
||||
/**
|
||||
* @brief Write data via DTLS connection
|
||||
*
|
||||
* @param handle DTLS connect handle
|
||||
* @param data source data to write
|
||||
* @param totalLen length of data
|
||||
* @param timeout_ms timeout value in millisecond
|
||||
* @param written_len length of data written successfully
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_DTLS_Write(uintptr_t handle, const unsigned char *data, size_t datalen, size_t *written_len);
|
||||
|
||||
/**
|
||||
* @brief Read data via DTLS connection
|
||||
*
|
||||
* @param handle DTLS connect handle
|
||||
* @param data destination data buffer where to put data
|
||||
* @param totalLen length of data
|
||||
* @param timeout_ms timeout value in millisecond
|
||||
* @param read_len length of data read successfully
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_DTLS_Read(uintptr_t handle, unsigned char *data, size_t datalen, uint32_t timeout_ms,
|
||||
size_t *read_len);
|
||||
|
||||
#endif //COAP_COMM_ENABLED
|
||||
#endif //AUTH_WITH_NOTLS
|
||||
|
||||
|
||||
/********** TCP network **********/
|
||||
/**
|
||||
* @brief Setup TCP connection with server
|
||||
*
|
||||
* @host server address
|
||||
* @port server port
|
||||
* @return TCP socket handle (value>0) when success, or 0 otherwise
|
||||
*/
|
||||
uintptr_t HAL_TCP_Connect(const char *host, uint16_t port);
|
||||
|
||||
/**
|
||||
* @brief Disconnect with server and release resource
|
||||
*
|
||||
* @param fd TCP Socket handle
|
||||
* @return 0 when success
|
||||
*/
|
||||
int HAL_TCP_Disconnect(uintptr_t fd);
|
||||
|
||||
/**
|
||||
* @brief Write data via TCP connection
|
||||
*
|
||||
* @param fd TCP socket handle
|
||||
* @param data source data to write
|
||||
* @param len length of data
|
||||
* @param timeout_ms timeout value in millisecond
|
||||
* @param written_len length of data written successfully
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_TCP_Write(uintptr_t fd, const unsigned char *data, uint32_t len, uint32_t timeout_ms,
|
||||
size_t *written_len);
|
||||
|
||||
/**
|
||||
* @brief Read data via TCP connection
|
||||
*
|
||||
* @param fd TCP socket handle
|
||||
* @param data destination data buffer where to put data
|
||||
* @param len length of data
|
||||
* @param timeout_ms timeout value in millisecond
|
||||
* @param read_len length of data read successfully
|
||||
* @return QCLOUD_RET_SUCCESS for success, or err code for failure
|
||||
*/
|
||||
int HAL_TCP_Read(uintptr_t fd, unsigned char *data, uint32_t len, uint32_t timeout_ms,
|
||||
size_t *read_len);
|
||||
|
||||
/********** UDP network **********/
|
||||
#ifdef COAP_COMM_ENABLED
|
||||
/**
|
||||
* @brief Setup UDP connection with server
|
||||
*
|
||||
* @host server address
|
||||
* @port server port
|
||||
* @return UPD socket handle (value>0) when success, or 0 otherwise
|
||||
*/
|
||||
uintptr_t HAL_UDP_Connect(const char *host, unsigned short port);
|
||||
|
||||
/**
|
||||
* @brief Disconnect with server and release resource
|
||||
*
|
||||
* @param fd UDP Socket handle
|
||||
* @return 0 when success
|
||||
*/
|
||||
void HAL_UDP_Disconnect(uintptr_t fd);
|
||||
|
||||
/**
|
||||
* @brief Write data via UDP connection
|
||||
*
|
||||
* @param fd UDP socket handle
|
||||
* @param data source data to write
|
||||
* @param len length of data
|
||||
* @return length of data written when success, or err code for failure
|
||||
*/
|
||||
int HAL_UDP_Write(uintptr_t fd, const unsigned char *data, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Read data via UDP connection
|
||||
*
|
||||
* @param fd UDP socket handle
|
||||
* @param data destination data buffer where to put data
|
||||
* @param len length of data
|
||||
* @return length of data read when success, or err code for failure
|
||||
*/
|
||||
int HAL_UDP_Read(uintptr_t fd, unsigned char *data, unsigned int len);
|
||||
|
||||
/**
|
||||
* @brief Read data via UDP connection
|
||||
*
|
||||
* @param fd UDP socket handle
|
||||
* @param data destination data buffer where to put data
|
||||
* @param len length of data
|
||||
* @param timeout_ms timeout value in millisecond
|
||||
* @return length of data read when success, or err code for failure
|
||||
*/
|
||||
int HAL_UDP_ReadTimeout(uintptr_t fd, unsigned char *p_data, unsigned int datalen, unsigned int timeout_ms);
|
||||
#endif //COAP_COMM_ENABLED
|
||||
|
||||
#ifdef LOG_UPLOAD
|
||||
/* Functions for saving/reading logs into/from NVS(files/FLASH) after log upload fail/recover */
|
||||
/**
|
||||
* @brief Functions for saving logs into NVS(files/FLASH) after log upload fail
|
||||
* @param log source log buffer
|
||||
* @param len length of log to save
|
||||
* @return length of data save when success, or 0 for failure
|
||||
*/
|
||||
size_t HAL_Log_Save(const char *log, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Functions for reading logs from NVS(files/FLASH) when log upload ready
|
||||
* @param buf destination log buffer
|
||||
* @param len length of log to read
|
||||
* @return length of data read when success, or 0 for failure
|
||||
*/
|
||||
size_t HAL_Log_Read(char *buf, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Functions for deleting logs in NVS(files/FLASH).
|
||||
* @return 0 when success
|
||||
*/
|
||||
int HAL_Log_Del(void);
|
||||
|
||||
/**
|
||||
* @brief Functions for reading the size of logs in NVS(files/FLASH).
|
||||
* @return 0 when nothing exist
|
||||
*/
|
||||
size_t HAL_Log_Get_Size(void);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#endif /* QCLOUD_IOT_IMPORT_H_ */
|
7
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/utils_getopt.h
vendored
Normal file
7
components/connectivity/qcloud-iot-explorer-sdk/3rdparty/include/utils_getopt.h
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef __UTILS_GETOPT_H__
|
||||
#define __UTILS_GETOPT_H__
|
||||
|
||||
extern char* utils_optarg; /* pointer to argument of current option */
|
||||
int utils_getopt(int nargc, char* const* nargv, const char* options);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user