From bd01eb4bddc63468e50bc5462c3571c7a3380869 Mon Sep 17 00:00:00 2001 From: "ethan.du" Date: Fri, 22 Nov 2019 14:09:55 +0800 Subject: [PATCH] optimize print log& shadow declaration --- platform/module/ec20_freertos_tcp/ec20.c | 34 +++---- .../module/esp8266_freertos_tcp/esp8266.c | 50 ++-------- platform/module/m26_freertos_tcp/m26.c | 36 ++++---- .../module/sim800c_freertos_tcp/sim800c.c | 28 +++--- samples/ota/ota_sample.c | 2 +- src/mqtt/src/mqtt_client.c | 2 +- src/sdk-impl/uiot_export_shadow.h | 92 +------------------ src/shadow/include/shadow_client.h | 90 +++++++++++++++++- src/shadow/include/shadow_client_common.h | 1 - src/shadow/include/shadow_client_json.h | 3 +- src/shadow/src/shadow_client.c | 2 + src/shadow/src/shadow_client_common.c | 2 +- 12 files changed, 155 insertions(+), 187 deletions(-) diff --git a/platform/module/ec20_freertos_tcp/ec20.c b/platform/module/ec20_freertos_tcp/ec20.c index e9c0e31..6e4e589 100644 --- a/platform/module/ec20_freertos_tcp/ec20.c +++ b/platform/module/ec20_freertos_tcp/ec20.c @@ -139,7 +139,7 @@ int HAL_AT_TCP_Disconnect(utils_network_pt pNetwork) ret = at_exec_cmd(resp, at_command, 0, "AT+QICLOSE=%d\r\n",pNetwork->handle-1); if(SUCCESS_RET != ret) { - HAL_Printf("close TCP link fail!\n"); + LOG_ERROR("close TCP link fail!\n"); } else { @@ -391,7 +391,7 @@ static int urc_qird_recv_func(const char *data, uint32_t size) ret |= ring_buff_push_data(&(g_ring_tcp_buff[link_num]), &temp_char, 1); if(SUCCESS_RET != ret) { - HAL_Printf("copy data to tcp buff fail\n"); + LOG_ERROR("copy data to tcp buff fail\n"); } } } @@ -448,7 +448,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "ATE0\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("ATE0 set fail!\n"); + LOG_ERROR("ATE0 set fail!\n"); goto end; } @@ -464,7 +464,7 @@ static int ec20_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CPIN?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("please check SIM card status!\n"); + LOG_ERROR("please check SIM card status!\n"); continue; } @@ -473,7 +473,7 @@ static int ec20_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CSQ\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("bad signal!\n"); + LOG_ERROR("bad signal!\n"); continue; } @@ -482,7 +482,7 @@ static int ec20_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CREG?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("not network regist!\n"); + LOG_ERROR("not network regist!\n"); continue; } @@ -491,7 +491,7 @@ static int ec20_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CGREG?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("not Attach GPRS!\n"); + LOG_ERROR("not Attach GPRS!\n"); continue; } @@ -500,7 +500,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+CEREG?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("check TCPIP mode fail!\n"); + LOG_ERROR("check TCPIP mode fail!\n"); goto end; } @@ -509,7 +509,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+COPS?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("query current Network Operator fail!\n"); + LOG_ERROR("query current Network Operator fail!\n"); goto end; } @@ -519,7 +519,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QICSGP=1,1,\"UNINET\",\"\",\"\",0\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("AT+QICSGP CHN-UNICOM fail!\n"); + LOG_ERROR("AT+QICSGP CHN-UNICOM fail!\n"); goto end; } } @@ -529,7 +529,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QICSGP=1,1,\"CMNET\",\"\",\"\",0\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("AT+QICSGP CHINA MOBILE fail!\n"); + LOG_ERROR("AT+QICSGP CHINA MOBILE fail!\n"); goto end; } } @@ -539,7 +539,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QICSGP=1,1,\"CTNET\",\"\",\"\",0\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("AT+QICSGP CHN-CT fail!\n"); + LOG_ERROR("AT+QICSGP CHN-CT fail!\n"); goto end; } } @@ -559,7 +559,7 @@ static int ec20_init() if(retry_time == 10) { - HAL_Printf("sim800c init fail!\n"); + LOG_ERROR("sim800c init fail!\n"); goto end; } @@ -568,7 +568,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+CTZU=3\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("Enable automatic time zone update via NITZ and update LOCAL time to RTC fail!\n"); + LOG_ERROR("Enable automatic time zone update via NITZ and update LOCAL time to RTC fail!\n"); goto end; } @@ -577,7 +577,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIDEACT=1\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("Deactivate context profile fail!\n"); + LOG_ERROR("Deactivate context profile fail!\n"); goto end; } @@ -586,7 +586,7 @@ static int ec20_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIACT=1\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("Activate context profile fail!\n"); + LOG_ERROR("Activate context profile fail!\n"); goto end; } @@ -650,7 +650,7 @@ int HAL_AT_TCP_Connect(_IN_ void * pNetwork, _IN_ const char *host, _IN_ uint16_ if(SUCCESS_RET != ret) { - HAL_Printf("build TCP link fail!\n"); + LOG_ERROR("build TCP link fail!\n"); goto end; } else diff --git a/platform/module/esp8266_freertos_tcp/esp8266.c b/platform/module/esp8266_freertos_tcp/esp8266.c index 3c00ed1..72e4b28 100644 --- a/platform/module/esp8266_freertos_tcp/esp8266.c +++ b/platform/module/esp8266_freertos_tcp/esp8266.c @@ -129,7 +129,7 @@ int HAL_AT_TCP_Disconnect(utils_network_pt pNetwork) ret = at_exec_cmd(resp, at_command, 0, "AT+CIPCLOSE=%d\r\n",pNetwork->handle-1); if(SUCCESS_RET != ret) { - HAL_Printf("close TCP link fail!\n"); + LOG_ERROR("close TCP link fail!\n"); } else { @@ -256,43 +256,13 @@ static int urc_recvdata_recv_func(const char *data, uint32_t size) ret |= ring_buff_push_data(&(g_ring_tcp_buff[link_num]), &temp_char, 1); if(SUCCESS_RET != ret) { - HAL_Printf("copy data to tcp buff fail\n"); + LOG_ERROR("copy data to tcp buff fail\n"); } } } return SUCCESS_RET; } -/* -static int urc_recvlen_recv_judge(const char *data, uint32_t size) -{ - char temp[13] = {0}; - if(size > 12) - { - memcpy(temp, &data[1],12); - temp[12] = '\0'; - if(0 == strncmp(temp, "+CIPRECVLEN:", size)) - { - return SUCCESS_RET; - } - else - { - return FAILURE_RET; - } - } - else - { - if(0 == strncmp(data, "+CIPRECVLEN:", size)) - { - return SUCCESS_RET; - } - else - { - return FAILURE_RET; - } - } -} -*/ static int urc_recvlen_recv_judge(const char *data, uint32_t size) { @@ -368,7 +338,7 @@ static int esp8266_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+RST\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("AT rst fail!\n"); + LOG_ERROR("AT rst fail!\n"); goto end; } @@ -380,7 +350,7 @@ static int esp8266_init() ret |= at_exec_cmd(resp, at_command, 0, "ATE0\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("ATE0 set fail!\n"); + LOG_ERROR("ATE0 set fail!\n"); goto end; } @@ -389,7 +359,7 @@ static int esp8266_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CWMODE=1\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("set Wi-Fi mode to station fail!\n"); + LOG_ERROR("set Wi-Fi mode to station fail!\n"); continue; } @@ -398,7 +368,7 @@ static int esp8266_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CIPMUX=1\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("set mutil link fail!\n"); + LOG_ERROR("set mutil link fail!\n"); continue; } @@ -407,7 +377,7 @@ static int esp8266_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CWJAP=\"ucloud-guest\",\"ucloud.cn\"\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("link Wi-Fi AP fail!\n"); + LOG_ERROR("link Wi-Fi AP fail!\n"); continue; } @@ -416,7 +386,7 @@ static int esp8266_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CIFSR\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("get ip addr fail!\n"); + LOG_ERROR("get ip addr fail!\n"); continue; } @@ -488,7 +458,7 @@ int HAL_AT_TCP_Connect(_IN_ void * pNetwork, _IN_ const char *host, _IN_ uint16_ ret = at_exec_cmd(resp, at_command, 0, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d\r\n", link_num, pNet->pHostAddress, pNet->port); if(SUCCESS_RET != ret) { - HAL_Printf("build TCP link fail!\n"); + LOG_ERROR("build TCP link fail!\n"); goto end; } else @@ -503,7 +473,7 @@ int HAL_AT_TCP_Connect(_IN_ void * pNetwork, _IN_ const char *host, _IN_ uint16_ ret = at_exec_cmd(resp, at_command, 0, "AT+CIPRECVMODE=1\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("set tcp receive data mode fail!\n"); + LOG_ERROR("set tcp receive data mode fail!\n"); goto end; } diff --git a/platform/module/m26_freertos_tcp/m26.c b/platform/module/m26_freertos_tcp/m26.c index 3a5e576..db114bc 100644 --- a/platform/module/m26_freertos_tcp/m26.c +++ b/platform/module/m26_freertos_tcp/m26.c @@ -92,7 +92,7 @@ int HAL_AT_Read(_IN_ utils_network_pt pNetwork, _OU_ unsigned char *buffer, _IN_ ret |= ring_buff_push_data(&(g_ring_tcp_buff[link_num]), &temp_char, 1); if(SUCCESS_RET != ret) { - HAL_Printf("copy data to tcp buff fail\n"); + LOG_ERROR("copy data to tcp buff fail\n"); } } } @@ -176,7 +176,7 @@ int HAL_AT_TCP_Disconnect(utils_network_pt pNetwork) ret = at_exec_cmd(resp, at_command, 0, "AT+QICLOSE=%d\r",pNetwork->handle-1); if(SUCCESS_RET != ret) { - HAL_Printf("close TCP link fail!\n"); + LOG_ERROR("close TCP link fail!\n"); } else { @@ -452,7 +452,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "ATE0\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("ATE0 set fail!\n"); + LOG_ERROR("ATE0 set fail!\n"); goto end; } @@ -468,7 +468,7 @@ static int m26_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CPIN?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("please check SIM card status!\n"); + LOG_ERROR("please check SIM card status!\n"); continue; } @@ -477,7 +477,7 @@ static int m26_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CSQ\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("bad signal!\n"); + LOG_ERROR("bad signal!\n"); continue; } @@ -486,7 +486,7 @@ static int m26_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CREG?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("not network regist!\n"); + LOG_ERROR("not network regist!\n"); continue; } @@ -495,7 +495,7 @@ static int m26_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CGREG?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("not Attach GPRS!\n"); + LOG_ERROR("not Attach GPRS!\n"); continue; } @@ -504,7 +504,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIMODE?\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("check TCPIP mode fail!\n"); + LOG_ERROR("check TCPIP mode fail!\n"); goto end; } @@ -517,7 +517,7 @@ static int m26_init() if(retry_time == 10) { - HAL_Printf("sim800c init fail!\n"); + LOG_ERROR("sim800c init fail!\n"); goto end; } @@ -526,7 +526,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIFGCNT=0\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("set foreground fail!\n"); + LOG_ERROR("set foreground fail!\n"); goto end; } @@ -535,7 +535,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QICSGP=1, \"CMNET\"\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("set apn fail!\n"); + LOG_ERROR("set apn fail!\n"); goto end; } @@ -544,7 +544,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIDEACT\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("shut down GPRS/CSD PDP fail!\n"); + LOG_ERROR("shut down GPRS/CSD PDP fail!\n"); goto end; } @@ -553,7 +553,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIMUX=1\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("set multi link mode fail!\n"); + LOG_ERROR("set multi link mode fail!\n"); goto end; } @@ -562,7 +562,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIREGAPP\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("set APN fail!\n"); + LOG_ERROR("set APN fail!\n"); goto end; } @@ -571,7 +571,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QIACT\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("build wireless link fail!\n"); + LOG_ERROR("build wireless link fail!\n"); goto end; } @@ -580,7 +580,7 @@ static int m26_init() ret = at_exec_cmd(resp, at_command, 0, "AT+QILOCIP\r\n"); if(SUCCESS_RET != ret) { - HAL_Printf("fetch local IP address fail!\n"); + LOG_ERROR("fetch local IP address fail!\n"); goto end; } @@ -642,7 +642,7 @@ int HAL_AT_TCP_Connect(_IN_ void * pNetwork, _IN_ const char *host, _IN_ uint16_ ret = at_exec_cmd(resp, at_command, 0, "AT+QIDNSGIP=\"%s\"\r", pNet->pHostAddress); if(SUCCESS_RET != ret) { - HAL_Printf("build TCP link fail!\n"); + LOG_ERROR("build TCP link fail!\n"); goto end; } @@ -651,7 +651,7 @@ int HAL_AT_TCP_Connect(_IN_ void * pNetwork, _IN_ const char *host, _IN_ uint16_ ret = at_exec_cmd(resp, at_command, 0, "AT+QIOPEN=%d,\"TCP\",\"%s\",\"%d\"\r", link_num, domain_ip_addr, pNet->port); if(SUCCESS_RET != ret) { - HAL_Printf("build TCP link fail!\n"); + LOG_ERROR("build TCP link fail!\n"); goto end; } else diff --git a/platform/module/sim800c_freertos_tcp/sim800c.c b/platform/module/sim800c_freertos_tcp/sim800c.c index b5140dc..53601f1 100644 --- a/platform/module/sim800c_freertos_tcp/sim800c.c +++ b/platform/module/sim800c_freertos_tcp/sim800c.c @@ -93,7 +93,7 @@ int HAL_AT_Read(_IN_ utils_network_pt pNetwork, _OU_ unsigned char *buffer, _IN_ ret |= ring_buff_push_data(&(g_ring_tcp_buff[link_num]), &temp_char, 1); if(SUCCESS_RET != ret) { - HAL_Printf("copy data to tcp buff fail\n"); + LOG_ERROR("copy data to tcp buff fail\n"); } } } @@ -177,7 +177,7 @@ int HAL_AT_TCP_Disconnect(utils_network_pt pNetwork) ret = at_exec_cmd(resp, at_command, 0, "AT+CIPCLOSE=%d\r",pNetwork->handle-1); if(SUCCESS_RET != ret) { - HAL_Printf("close TCP link fail!\n"); + LOG_ERROR("close TCP link fail!\n"); } else { @@ -406,7 +406,7 @@ static int sim800c_init() ret = at_exec_cmd(resp, at_command, 0, "ATE0\r"); if(SUCCESS_RET != ret) { - HAL_Printf("ATE0 set fail!\n"); + LOG_ERROR("ATE0 set fail!\n"); goto end; } @@ -422,7 +422,7 @@ static int sim800c_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CPIN?\r"); if(SUCCESS_RET != ret) { - HAL_Printf("please check SIM card status!\n"); + LOG_ERROR("please check SIM card status!\n"); continue; } @@ -431,7 +431,7 @@ static int sim800c_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CSQ\r"); if(SUCCESS_RET != ret) { - HAL_Printf("bad signal!\n"); + LOG_ERROR("bad signal!\n"); continue; } @@ -440,7 +440,7 @@ static int sim800c_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CREG?\r"); if(SUCCESS_RET != ret) { - HAL_Printf("not network regist!\n"); + LOG_ERROR("not network regist!\n"); continue; } @@ -449,7 +449,7 @@ static int sim800c_init() ret |= at_exec_cmd(resp, at_command, 0, "AT+CGATT?\r"); if(SUCCESS_RET != ret) { - HAL_Printf("not Attach GPRS!\n"); + LOG_ERROR("not Attach GPRS!\n"); continue; } @@ -462,7 +462,7 @@ static int sim800c_init() if(retry_time == 10) { - HAL_Printf("sim800c init fail!\n"); + LOG_ERROR("sim800c init fail!\n"); goto end; } @@ -471,7 +471,7 @@ static int sim800c_init() ret = at_exec_cmd(resp, at_command, 0, "AT+CIPMUX=1\r"); if(SUCCESS_RET != ret) { - HAL_Printf("set multi link mode fail!\n"); + LOG_ERROR("set multi link mode fail!\n"); goto end; } @@ -480,7 +480,7 @@ static int sim800c_init() ret = at_exec_cmd(resp, at_command, 0, "AT+CSTT=\"3GNET\"\r"); if(SUCCESS_RET != ret) { - HAL_Printf("set APN fail!\n"); + LOG_ERROR("set APN fail!\n"); goto end; } @@ -489,7 +489,7 @@ static int sim800c_init() ret = at_exec_cmd(resp, at_command, 0, "AT+CIICR\r"); if(SUCCESS_RET != ret) { - HAL_Printf("build wireless link fail!\n"); + LOG_ERROR("build wireless link fail!\n"); goto end; } @@ -498,7 +498,7 @@ static int sim800c_init() ret = at_exec_cmd(resp, at_command, 0, "AT+CIFSR\r"); if(SUCCESS_RET != ret) { - HAL_Printf("fetch local IP address fail!\n"); + LOG_ERROR("fetch local IP address fail!\n"); goto end; } @@ -507,7 +507,7 @@ static int sim800c_init() ret = at_exec_cmd(resp, at_command, 0, "AT+CIPQSEND=1\r"); if(SUCCESS_RET != ret) { - HAL_Printf("fast send mode fail!\n"); + LOG_ERROR("fast send mode fail!\n"); goto end; } @@ -569,7 +569,7 @@ int HAL_AT_TCP_Connect(_IN_ void * pNetwork, _IN_ const char *host, _IN_ uint16_ ret = at_exec_cmd(resp, at_command, 0, "AT+CIPSTART=%d,\"TCP\",\"%s\",\"%d\"\r", link_num, pNet->pHostAddress, pNet->port); if(SUCCESS_RET != ret) { - HAL_Printf("build TCP link fail!\n"); + LOG_ERROR("build TCP link fail!\n"); goto end; } else diff --git a/samples/ota/ota_sample.c b/samples/ota/ota_sample.c index c07eb23..e8c9bf3 100644 --- a/samples/ota/ota_sample.c +++ b/samples/ota/ota_sample.c @@ -29,7 +29,7 @@ #define UIOT_MY_DEVICE_SECRET "DEVICE_SECRET" -#define OTA_BUF_LEN (5000) +#define OTA_BUF_LEN (1024) static void event_handler(void *pClient, void *handle_context, MQTTEventMsg *msg) { diff --git a/src/mqtt/src/mqtt_client.c b/src/mqtt/src/mqtt_client.c index 405068c..977fc62 100644 --- a/src/mqtt/src/mqtt_client.c +++ b/src/mqtt/src/mqtt_client.c @@ -253,7 +253,7 @@ static void on_message_callback_get_device_secret(void *pClient, MQTTMessage *me HAL_Free(Password); return; } -extern char ringBuff[]; + int IOT_MQTT_Dynamic_Register(MQTTInitParams *pParams) { POINTER_VALID_CHECK(pParams, ERR_PARAM_INVALID); diff --git a/src/sdk-impl/uiot_export_shadow.h b/src/sdk-impl/uiot_export_shadow.h index 44b7eb1..ffdfb75 100644 --- a/src/sdk-impl/uiot_export_shadow.h +++ b/src/sdk-impl/uiot_export_shadow.h @@ -21,96 +21,8 @@ extern "C" { #endif -#include "uiot_export_mqtt.h" -#include "mqtt_client.h" - -/** - * @brief 请求响应返回的类型 - */ -typedef enum { - ACK_NONE = -3, // 请求超时 - ACK_TIMEOUT = -2, // 请求超时 - ACK_REJECTED = -1, // 请求拒绝 - ACK_ACCEPTED = 0 // 请求接受 -} RequestAck; - -/** - * @brief 操作云端设备文档可以使用的三种方式 - */ -typedef enum { - GET, // 获取云端设备文档 - UPDATE, // 更新或创建云端设备文档 - UPDATE_AND_RESET_VER, // 更新同时重置版本号 - DELETE, // 删除部分云端设备文档 - DELETE_ALL, // 删除全部云端设备文档中的属性,不需要一个个添加需要删除的属性 - REPLY_CONTROL_UPDATE, // 设备处理完服务端的control消息后回应的update消息 - REPLY_CONTROL_DELETE, // 设备处理完服务端的control消息后回应的delete消息 -} Method; - -/** - * @brief JSON文档中支持的数据类型 - */ -typedef enum { - JINT32, // 32位有符号整型 - JINT16, // 16位有符号整型 - JINT8, // 8位有符号整型 - JUINT32, // 32位无符号整型 - JUINT16, // 16位无符号整型 - JUINT8, // 8位无符号整型 - JFLOAT, // 单精度浮点型 - JDOUBLE, // 双精度浮点型 - JBOOL, // 布尔型 - JSTRING, // 字符串 - JOBJECT // JSON对象 -} JsonDataType; - -/** - * @brief 定义设备的某个属性, 实际就是一个JSON文档节点 - */ -typedef struct _JSONNode { - char *key; // 该JSON节点的Key - void *data; // 该JSON节点的Value - JsonDataType type; // 该JSON节点的数据类型 -} DeviceProperty; - -/** - * @brief 每次文档请求响应的回调函数 - * - * @param pClient ShadowClient对象 - * @param method 文档操作方式 - * @param requestAck 请求响应类型 - * @param pJsonDocument 云端响应返回的文档 - * @param userContext 用户数据 - * - */ -typedef void (*OnRequestCallback)(void *pClient, Method method, RequestAck requestAck, const char *pJsonDocument, void *userContext); - -/** - * @brief 文档操作请求的参数结构体定义 - */ -typedef struct _RequestParam { - Method method; // 文档请求方式: GET, UPDATE, DELETE等 - - List *property_delta_list; // 该请求需要修改的属性 - - uint32_t timeout_sec; // 请求超时时间, 单位:s - - OnRequestCallback request_callback; // 请求回调方法 - - void *user_context; // 用户数据, 会通过回调方法OnRequestCallback返回 - -} RequestParams; - -/** - * @brief 设备属性处理回调函数 - * - * @param pClient ShadowClient对象 - * @param pParams 设备影子文档修改请求 - * @param pJsonValueBuffer 设备属性值 - * @param valueLength 设备属性值长度 - * @param DeviceProperty 设备属性结构体 - */ -typedef void (*OnPropRegCallback)(void *pClient, RequestParams *pParams, char *pJsonValueBuffer, uint32_t valueLength, DeviceProperty *pProperty); +#include "uiot_import.h" +#include "shadow_client.h" /** * @brief 构造ShadowClient diff --git a/src/shadow/include/shadow_client.h b/src/shadow/include/shadow_client.h index 5064f5e..dd712ad 100644 --- a/src/shadow/include/shadow_client.h +++ b/src/shadow/include/shadow_client.h @@ -23,8 +23,7 @@ extern "C" { #include #include "mqtt_client.h" -#include "shadow_client_json.h" -#include "uiot_export_shadow.h" + /* 在任意给定时间内, 处于appending状态的请求最大个数 */ #define MAX_APPENDING_REQUEST_AT_ANY_GIVEN_TIME (10) @@ -42,6 +41,93 @@ extern "C" { #define MAX_WAIT_TIME_SEC 1 #define MAX_WAIT_TIME_MS 1000 +/** + * @brief 请求响应返回的类型 + */ +typedef enum { + ACK_NONE = -3, // 请求超时 + ACK_TIMEOUT = -2, // 请求超时 + ACK_REJECTED = -1, // 请求拒绝 + ACK_ACCEPTED = 0 // 请求接受 +} RequestAck; + +/** + * @brief 操作云端设备文档可以使用的三种方式 + */ +typedef enum { + GET, // 获取云端设备文档 + UPDATE, // 更新或创建云端设备文档 + UPDATE_AND_RESET_VER, // 更新同时重置版本号 + DELETE, // 删除部分云端设备文档 + DELETE_ALL, // 删除全部云端设备文档中的属性,不需要一个个添加需要删除的属性 + REPLY_CONTROL_UPDATE, // 设备处理完服务端的control消息后回应的update消息 + REPLY_CONTROL_DELETE, // 设备处理完服务端的control消息后回应的delete消息 +} Method; + +/** + * @brief JSON文档中支持的数据类型 + */ +typedef enum { + JINT32, // 32位有符号整型 + JINT16, // 16位有符号整型 + JINT8, // 8位有符号整型 + JUINT32, // 32位无符号整型 + JUINT16, // 16位无符号整型 + JUINT8, // 8位无符号整型 + JFLOAT, // 单精度浮点型 + JDOUBLE, // 双精度浮点型 + JBOOL, // 布尔型 + JSTRING, // 字符串 + JOBJECT // JSON对象 +} JsonDataType; + +/** + * @brief 定义设备的某个属性, 实际就是一个JSON文档节点 + */ +typedef struct _JSONNode { + char *key; // 该JSON节点的Key + void *data; // 该JSON节点的Value + JsonDataType type; // 该JSON节点的数据类型 +} DeviceProperty; + +/** + * @brief 每次文档请求响应的回调函数 + * + * @param pClient ShadowClient对象 + * @param method 文档操作方式 + * @param requestAck 请求响应类型 + * @param pJsonDocument 云端响应返回的文档 + * @param userContext 用户数据 + * + */ +typedef void (*OnRequestCallback)(void *pClient, Method method, RequestAck requestAck, const char *pJsonDocument, void *userContext); + +/** + * @brief 文档操作请求的参数结构体定义 + */ +typedef struct _RequestParam { + Method method; // 文档请求方式: GET, UPDATE, DELETE等 + + List *property_delta_list; // 该请求需要修改的属性 + + uint32_t timeout_sec; // 请求超时时间, 单位:s + + OnRequestCallback request_callback; // 请求回调方法 + + void *user_context; // 用户数据, 会通过回调方法OnRequestCallback返回 + +} RequestParams; + +/** + * @brief 设备属性处理回调函数 + * + * @param pClient ShadowClient对象 + * @param pParams 设备影子文档修改请求 + * @param pJsonValueBuffer 设备属性值 + * @param valueLength 设备属性值长度 + * @param DeviceProperty 设备属性结构体 + */ +typedef void (*OnPropRegCallback)(void *pClient, RequestParams *pParams, char *pJsonValueBuffer, uint32_t valueLength, DeviceProperty *pProperty); /** * @brief 该结构体用于保存已登记的设备属性及设备属性处理的回调方法 diff --git a/src/shadow/include/shadow_client_common.h b/src/shadow/include/shadow_client_common.h index 63c8732..53c93be 100644 --- a/src/shadow/include/shadow_client_common.h +++ b/src/shadow/include/shadow_client_common.h @@ -22,7 +22,6 @@ extern "C" { #endif #include "shadow_client.h" -#include "uiot_export_shadow.h" //设备影子相关topic #define SHADOW_PUBLISH_REQUEST_TEMPLATE "/$system/%s/%s/shadow/upstream" diff --git a/src/shadow/include/shadow_client_json.h b/src/shadow/include/shadow_client_json.h index 2bb0cbd..2ca765b 100644 --- a/src/shadow/include/shadow_client_json.h +++ b/src/shadow/include/shadow_client_json.h @@ -26,9 +26,8 @@ extern "C" { #include #include -#include "uiot_export.h" #include "uiot_import.h" -#include "uiot_export_shadow.h" +#include "shadow_client.h" /* 回复消息中的消息字段 */ #define METHOD_FIELD "Method" diff --git a/src/shadow/src/shadow_client.c b/src/shadow/src/shadow_client.c index 92a9b5c..bc4cbb6 100644 --- a/src/shadow/src/shadow_client.c +++ b/src/shadow/src/shadow_client.c @@ -27,6 +27,8 @@ extern "C" { #include "lite-utils.h" #include "shadow_client_common.h" +int IOT_Shadow_Request_Add_Delta_Property(void *handle, RequestParams *pParams, DeviceProperty *pProperty); + void* IOT_Shadow_Construct(const char *product_sn, const char *device_sn, void *ch_signal) { FUNC_ENTRY; diff --git a/src/shadow/src/shadow_client_common.c b/src/shadow/src/shadow_client_common.c index f312ee9..3df93d5 100644 --- a/src/shadow/src/shadow_client_common.c +++ b/src/shadow/src/shadow_client_common.c @@ -114,7 +114,7 @@ int shadow_common_update_property(UIoT_Shadow *pShadow, DeviceProperty *pPropert } else if((DELETE == method) || (REPLY_CONTROL_DELETE == method)) { - HAL_Printf("delete property\n"); + LOG_INFO("delete property\n"); property_bak->data = NULL; } else