Browse Source

v1.0.7发布后,针对rt-thread的整理修改

ouysd 6 years ago
parent
commit
b900c6357b

+ 0 - 39
SConscript_rtthread

@@ -1,39 +0,0 @@
-Import('RTT_ROOT')
-from building import *
-
-# get current directory
-cwd = GetCurrentDir()
-
-# The set of source files associated with this SConscript file.
-src = []
-path = []
-
-src += Glob('jiot-c-sdk/src/jclient/*.c')
-src += Glob('jiot-c-sdk/src/sisclient/*.c')
-src += Glob('jiot-c-sdk/src/mqtt/MQTTClient-C/src/*.c')
-src += Glob('jiot-c-sdk/src/mqtt/MQTTPacket/src/*.c')
-src += Glob('jiot-c-sdk/common/*.c')
-src += Glob('jiot-c-sdk/public/net/tcp/*.c')
-src += Glob('jiot-c-sdk/platform/os/rt-thread/*.c')
-
-path += [cwd + '/jiot-c-sdk/common']
-path += [cwd + '/jiot-c-sdk/include/jclient']
-path += [cwd + '/jiot-c-sdk/include/mqtt']
-path += [cwd + '/jiot-c-sdk/include/sisclient']
-path += [cwd + '/jiot-c-sdk/platform/os/rt-thread']
-path += [cwd + '/jiot-c-sdk/src/mqtt/MQTTPacket/src']
-path += [cwd + '/jiot-c-sdk/public/net/tcp']
-
-if GetDepend(['PKG_USING_JIOT_EXAMPLES']):
-	src += Glob('samples/*.c')
-	
-if GetDepend(['JIOT_SSL']):
-
-	src += Glob('jiot-c-sdk/public/net/ssl/*.c')
-	src += Glob('jiot-c-sdk/platform/ssl/mbedtls/*.c')
-	path += [cwd + '/jiot-c-sdk/platform/ssl/mbedtls']
-	path += [cwd + '/jiot-c-sdk/public/net/ssl']
-	
-group = DefineGroup('jiot-c-sdk', src, depend = [''], CPPPATH = path)
-
-Return('group')

+ 8 - 2
jiot-c-sdk/common/jiot_httpclient.c

@@ -463,7 +463,7 @@ int httpclient_retrieve_content(httpclient_t *client, char *data, int len,
     countdown_ms(&timer, timeout_ms);
 
     /* Receive data */
-    DEBUG_LOG("Current data: %s", data);
+//    DEBUG_LOG("Current data: %s", data);
 
     client_data->is_more = JIOT_TRUE;
 
@@ -591,7 +591,7 @@ int httpclient_retrieve_content(httpclient_t *client, char *data, int len,
             readLen = client_data->retrieve_len;
         }
 
-        DEBUG_LOG("Total-Payload: %d Bytes; Read: %d Bytes", readLen, len);
+//        DEBUG_LOG("Total-Payload: %d Bytes; Read: %d Bytes", readLen, len);
 
         do 
         {
@@ -729,6 +729,12 @@ int httpclient_response_parse(httpclient_t *client, char *data, int len, UINT32
     /* try to read more header again until find response head ending "\r\n\r\n" */
     while (NULL == (ptr_body_end = strstr(data, "\r\n\r\n"))) 
     {
+    	/* check read length, against buf overflow */
+        if(len >= HTTPCLIENT_CHUNK_SIZE - HTTPCLIENT_RAED_HEAD_SIZE)
+        {
+        	return JIOT_ERR_HTTP_HEADER_TOO_LONG;
+        }
+
         /* try to read more header */
         ret = httpclient_recv(client, data + len,  HTTPCLIENT_RAED_HEAD_SIZE, &new_trf_len, left_ms(&timer));
         if (ret != JIOT_SUCCESS) 

+ 2 - 2
jiot-c-sdk/common/jiot_httpclient.h

@@ -57,14 +57,14 @@ extern "C"
 #define  JIOT_ERR_HTTP_ERROR                         -18006               //HTTP位置错误 
 #define  JIOT_ERR_HTTP_CLOSED                        -18007               //远程Host关闭连接
 #define  JIOT_ERR_HTTP_BREAK                         -18008               //连接中断
-
+#define  JIOT_ERR_HTTP_HEADER_TOO_LONG               -18009               //HPPT头过长
 
 #define  HTTPCLIENT_MIN(x,y) (((x)<(y))?(x):(y))
 #define  HTTPCLIENT_MAX(x,y) (((x)>(y))?(x):(y))
 
 #define  HTTPCLIENT_AUTHB_SIZE     128
 
-#define  HTTPCLIENT_CHUNK_SIZE     512
+#define  HTTPCLIENT_CHUNK_SIZE     1152 //wenhe
 #define  HTTPCLIENT_RAED_HEAD_SIZE 128            /* read header */
 #define  HTTPCLIENT_SEND_BUF_SIZE  512
  

+ 61 - 2
jiot-c-sdk/include/jclient/jiot_client.h

@@ -9,7 +9,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#define SDK_VERSION "v1.0.6"
+#define SDK_VERSION "v1.0.7"
+
+#ifndef SDK_PLATFORM
+#define SDK_PLATFORM "unknown"
+#endif
 
 #define NO_LOG_LEVL         0       //不输出日志
 #define ERROR_LOG_LEVL      1       //输出错误日志
@@ -132,6 +136,36 @@ typedef struct VersionReportRsp
   int code ;    
 }VersionReportRsp;
 
+// ota
+typedef struct OtaUpgradeInformReq
+{
+  long long  seq_no;
+  unsigned int size;
+  char* url;
+  char* md5;
+  char* app_ver;
+  long task_id;
+}OtaUpgradeInformReq;
+typedef struct OtaUpgradeInformRsp
+{
+  long long  seq_no ;
+  int code ;
+}OtaUpgradeInformRsp;
+
+typedef struct OtaStatusReportReq
+{
+  long long  seq_no ;
+  int  step ;
+  char* desc ;
+  long task_id;
+}OtaStatusReportReq;
+typedef struct OtaStatusReportRsp
+{
+  long long  seq_no ;
+  int code ;
+}OtaStatusReportRsp;
+
+
 
 /**
  * 函数说明: 处理服务端返回JIOT客户端上报设备属性请求回复
@@ -178,6 +212,23 @@ typedef int jiotPropertySetReq(void* pContext,JHandle handle,PropertySetReq *Req
  */
 typedef int jiotMsgDeliverReq(void* pContext,JHandle handle,MsgDeliverReq *Req,int errcode);
 
+/**
+ * 函数说明: 服务端下发给JIOT客户下发OTA升级请求。
+ * 参数:    pContext:用户注册的上下文信息
+ *          handle  JIOT客户端句柄
+ *          Req :OTA升级信息的结构体指针
+ *          errcode :错误码
+ */
+typedef int jiotOtaUpgradeInformReq(void* pContext,JHandle handle,OtaUpgradeInformReq *Req,int errcode);
+
+/**
+ * 函数说明: JIOT客户端上报OTA升级状态回复
+ * 参数:    pContext:用户注册的上下文信息
+ *          handle  JIOT客户端句柄
+ *          pResp :接收回复消息的结构体指针
+ *          errcode :错误码
+ */
+typedef int jiotOtaStatusReportRsp(void* pContext,JHandle handle,const OtaStatusReportRsp * Rsp,int errcode);
 
 //JClient处理接收消息的回调函数
 typedef struct JClientMessageCallback
@@ -187,6 +238,8 @@ typedef struct JClientMessageCallback
     jiotVersionReportRsp    *_cbVersionReportRsp;
     jiotPropertySetReq      *_cbPropertySetReq;      
     jiotMsgDeliverReq       *_cbMsgDeliverReq;
+    jiotOtaUpgradeInformReq *_cbOtaUpgradeInformReq;
+    jiotOtaStatusReportRsp  *_cbOtaStatusReportRsp;
 } JClientMessageCallback;
 
 /**
@@ -328,7 +381,13 @@ JiotResult jiotEventReportReq(JHandle handle,const EventReportReq *pReq);
  */
 JiotResult jiotVersionReportReq(JHandle handle,const VersionReportReq * pReq);
 
-
+/**
+ * 函数说明: JIOT客户端上报设备OTA升级状态请求。
+ * 参数:    handle  JIOT客户端句柄
+ *          pReq :上报消息的结构体指针
+ * 返回值:
+ */
+JiotResult jiotOtaStatusReportReq(JHandle handle,const OtaStatusReportReq * pReq);
 
 #endif
 

+ 4 - 1
jiot-c-sdk/include/jclient/jiot_code.h

@@ -22,6 +22,7 @@
 #define  JIOT_ERR_EVENT_CONTENT_FORMAT_ERROR         10016              //事件内容异常
 #define  JIOT_ERR_DATA_CONTENT_FORMAT_ERROR          10017              //数据内容异常
 #define  JIOT_ERR_VERSION_APP_VAR_FORMAT_ERROR       10018              //版本信息异常
+#define  JIOT_ERR_VERSION_APP_ERROR 				 10019				//版本异常
   
 #define  JIOT_ERR_MQTT_ERR                           11001              //MQTT异常
 #define  JIOT_ERR_MQTT_PING_PACKET_ERROR             11002              //MQTT心跳异常
@@ -68,6 +69,8 @@
 #define  JIOT_ERR_SIS_CONTENT_ERROR                 14004               //SIS 数据内容错误
 #define  JIOT_ERR_SIS_JSON_PARSE_FAIL               14005               //SIS Json解析错误
 
-
+#define  JIOT_ERR_OTA_DESC_FORMAT_ERROR       		15001               //ota DESC格式错误
+#define  JIOT_ERR_OTA_STEP_VALUE_ERROR       		15002               //ota STEP错误
+#define  JIOT_ERR_OTA_FORMAT_ERROR            		15003				//ota异常
 
 #endif

+ 8 - 0
jiot-c-sdk/platform/os/rt-thread/jiot_timer.c

@@ -70,9 +70,12 @@ void jiot_timer_countdown(S_JIOT_TIME_TYPE* timer,UINT32 millisecond)
 
 UINT64 jiot_timer_now_ms()
 {
+	return time(NULL) * 1000;
     /*struct timeval now;
     gettimeofday(&now, NULL);
     return now.tv_sec*1000 + now.tv_usec/1000 ;*/
+	/*由于有些环境无法使用gettimeofday函数,因此使用系统tick来实现该功能*/
+	/*
 #if (RT_TICK_PER_SECOND == 1000)
     return (UINT64)rt_tick_get();
 #else
@@ -84,13 +87,17 @@ UINT64 jiot_timer_now_ms()
 
     return (tick + RT_TICK_PER_SECOND - 1)/RT_TICK_PER_SECOND;
 #endif
+*/
 }
 
 UINT32 jiot_timer_now()
 {
+	return time(NULL);
     /*struct timeval now;
     gettimeofday(&now, NULL);
     return now.tv_sec;*/
+	/*由于有些环境无法使用gettimeofday函数,因此使用系统tick来实现该功能*/
+	/*
 #if (RT_TICK_PER_SECOND == 1000)
     return (UINT32)(rt_tick_get() / 1000);
 #else
@@ -102,6 +109,7 @@ UINT32 jiot_timer_now()
 
     return (tick + RT_TICK_PER_SECOND - 1)/RT_TICK_PER_SECOND / 1000;
 #endif
+*/
 }
 
 void jiot_timer_s2str(UINT32 second,char* buf )

+ 334 - 3
jiot-c-sdk/src/jclient/jiot_client.c

@@ -57,6 +57,10 @@ typedef struct JClient
 #define EVENT_NAME_MAX_LEN      32
 #define EVENT_CONTENT_MAX_LEN   2048
 #define APP_VERSION_MAX_LEN     24
+#define APP_OTA_DESC_MAX_LEN    1024
+#define APP_OTA_STEP_VALUE_LEFT  -6
+#define APP_OTA_STEP_VALUE_RIGHT  104
+#define APP_OTA_STEP_VALUE_SUCCESS  200
 
 #define CODE_MAX 999
 #define CODE_OK  0 
@@ -85,6 +89,9 @@ if (NULL == X)\
 #define  JMQTT_TOPIC_VERSION_REPORT_REQ          "pub/sys/%s/%s/version/report"
 #define  JMQTT_TOPIC_IOT_PING_REQ                "pub/sys/%s/%s/iotping/req"
 #define  JMQTT_TOPIC_DEF_UP                      "pub/def/%s/%s/%s"            //上行
+//ota
+#define  JMQTT_TOPIC_OTA_UPGRADEINFORM_RSP       "pub/sys/%s/%s/ota/upgrade_inform_resp"
+#define  JMQTT_TOPIC_OTA_STATUSREPORT_REQ        "pub/sys/%s/%s/ota/status_report"
 
 #define  JMQTT_SUBTOPIC_SYS_4_DEV                    "sub/sys/%s/%s/+/+"        
 #define  JMQTT_SUBTOPIC_SYS_4_PRO                    "sub/sys/%s/*/msg/deliver"         
@@ -99,6 +106,10 @@ if (NULL == X)\
 
 #define  JMQTT_SHORTTOPIC_VERSION_REPORT_RSP          "version/report_resp"
 
+//ota
+#define  JMQTT_SHORTTOPIC_OTA_UPGRADEINFORM_REQ       "ota/upgrade_inform"
+#define  JMQTT_SHORTTOPIC_OTA_STATUSREPORT_RSP        "ota/status_report_resp"
+
 int _jiotPingReq(JClient * pClient);
 int _jiotPingRsp( void * pContext , MessageData * msg);
 
@@ -110,6 +121,10 @@ int _jiotPropertySetReq( void * pContext , MessageData * msg);
 int _jiotMsgDeliverReq( void * pContext , MessageData * msg);
 int _jiotVersionReportRsp( void * pContext , MessageData * msg);
 
+// ota
+int _jiotOtaUpgradeInformReq(void* pContext, MessageData* msg);
+int _jiotOtaStatusReportRsp( void * pContext , MessageData * msg);
+
 
 int _jiotSubscribe(void * pContext);
 int _jiotConnectedHandle( void * pContext );
@@ -157,7 +172,7 @@ void jiotSetLogLevel(int logLevl)
 
 JHandle jiotInit()
 {
-	INFO_LOG("SDK_VERSION[%s] SDK_BUILDID[%s]\n", SDK_VERSION, SDK_BUILDID);
+	INFO_LOG("SDK_VERSION[%s] SDK_PLATFORM[%s] SDK_BUILDID[%s]\n", SDK_VERSION, SDK_PLATFORM, SDK_BUILDID);
 
     JClient *pClient = jiot_malloc(sizeof(JClient));
 
@@ -206,6 +221,9 @@ JHandle jiotInit()
     pClient->cb._cbVersionReportRsp     = NULL;
     pClient->cb._cbPropertySetReq       = NULL;
     pClient->cb._cbMsgDeliverReq        = NULL;
+    pClient->cb._cbOtaUpgradeInformReq        = NULL;
+    pClient->cb._cbOtaStatusReportRsp         = NULL;
+
 
     pClient->handleCb._cbConnectedHandle         = NULL ;
     pClient->handleCb._cbConnectFailHandle       = NULL ;
@@ -238,6 +256,8 @@ void jiotRegister(JHandle handle,void* pContext, JClientMessageCallback *cb,JCli
     pClient->cb._cbVersionReportRsp     = cb->_cbVersionReportRsp;
     pClient->cb._cbPropertySetReq       = cb->_cbPropertySetReq;
     pClient->cb._cbMsgDeliverReq        = cb->_cbMsgDeliverReq;
+    pClient->cb._cbOtaUpgradeInformReq        = cb->_cbOtaUpgradeInformReq;
+    pClient->cb._cbOtaStatusReportRsp         = cb->_cbOtaStatusReportRsp;
     
     pClient->handleCb._cbConnectedHandle         = handleCb->_cbConnectedHandle;
     pClient->handleCb._cbConnectFailHandle       = handleCb->_cbConnectFailHandle;
@@ -264,6 +284,9 @@ void jiotUnRegister(JHandle handle)
     pClient->cb._cbVersionReportRsp     = NULL;
     pClient->cb._cbPropertySetReq       = NULL;
     pClient->cb._cbMsgDeliverReq        = NULL;
+    pClient->cb._cbOtaUpgradeInformReq        = NULL;
+    pClient->cb._cbOtaStatusReportRsp        = NULL;
+
 
     pClient->handleCb._cbConnectedHandle         = NULL;
     pClient->handleCb._cbConnectFailHandle       = NULL;
@@ -582,7 +605,8 @@ JiotResult jiotPropertyReportReq(JHandle handle,const PropertyReportReq *pReq)
                 break;
             }
 
-            if (strlen(pReq->pProperty[i].value) > PROPERTY_VALUE_MAX_LEN)
+            len = strlen(pReq->pProperty[i].value) ;
+            if (len > PROPERTY_VALUE_MAX_LEN ||(len <= 0))
             {
                 ERROR_LOG("property value format err [%s]",pReq->pProperty[i].value);
                 nRet = JIOT_ERR_PROPERTY_VALUE_FORMAT_ERROR; 
@@ -799,7 +823,7 @@ JiotResult jiotVersionReportReq(JHandle handle,const VersionReportReq * pReq)
         if(pReq->app_ver==NULL)
         {
             ERROR_LOG("app_ver is NULL ");
-            nRet = JIOT_ERR_VERSION_APP_VAR_FORMAT_ERROR; 
+            nRet = JIOT_ERR_VERSION_APP_ERROR;
             break;
         }
 
@@ -814,6 +838,7 @@ JiotResult jiotVersionReportReq(JHandle handle,const VersionReportReq * pReq)
         cJiotJSON_AddItemToObject(root,"seq_no",cJiotJSON_CreateInt64(seqNo));
         cJiotJSON_AddItemToObject(root,"app_ver",cJiotJSON_CreateString(pReq->app_ver));
         cJiotJSON_AddItemToObject(root,"sdk_ver",cJiotJSON_CreateString(SDK_VERSION));
+        cJiotJSON_AddItemToObject(root,"platform",cJiotJSON_CreateString(SDK_PLATFORM));
         cJiotJSON_AddItemToObject(root,"time",cJiotJSON_CreateInt64(jiot_timer_now()));
     }while(0);
     
@@ -848,7 +873,121 @@ JiotResult jiotVersionReportReq(JHandle handle,const VersionReportReq * pReq)
 
     return JRet;
 }
+JiotResult jiotOtaStatusReportReq(JHandle handle,const OtaStatusReportReq * pReq)
+{
+	char strBuf[21] = {0};
+    JiotResult JRet ;
+    JRet.errCode = JIOT_SUCCESS;
+    JRet.seqNo = -1;
+
+    JClient * pClient  = (JClient *)handle;
+    if(pClient == NULL)
+    {
+        JRet.errCode =  JIOT_ERR_JCLI_ERR;
+        return JRet ;
+    }
+
+    JMQTTClient * pJMqttCli =pClient->pJMqttCli;
+    if(pClient->pJMqttCli == NULL)
+    {
+        JRet.errCode =  JIOT_ERR_MQTT_ERR;
+        return JRet ;
+    }
+
+    if(pReq == NULL)
+    {
+        ERROR_LOG("PropertyReportReq argument is NULL");
+        JRet.errCode =  JIOT_ERR_ARGU_FORMAT_ERROR;
+        return JRet ;
+    }
+
+    int nRet = JIOT_SUCCESS;
+
+    long long  seqNo = pReq->seq_no ;
+    if(seqNo == 0)
+    {
+        seqNo = jiotNextSeqNo(handle);
+    }
+
+    cJiotJSON * root =  cJiotJSON_CreateObject();
+    do
+    {
+        if (seqNo <=0)
+        {
+        	jiot_lltoa(strBuf, seqNo);
+            ERROR_LOG("seq_no err [%s]", strBuf);
+            nRet = JIOT_ERR_SEQNO_ERROR;
+            break;
+        }
+
+        cJiotJSON_AddItemToObject(root,"seq_no",cJiotJSON_CreateInt64(seqNo));
+
+        cJiotJSON * data=cJiotJSON_CreateObject();
+        cJiotJSON_AddItemToObject(root,"data",data);
+
+        if (pReq->step != APP_OTA_STEP_VALUE_SUCCESS &&
+        		(pReq->step < APP_OTA_STEP_VALUE_LEFT || pReq->step > APP_OTA_STEP_VALUE_RIGHT))
+        {
+                ERROR_LOG("step value err [%d]",pReq->step);
+                nRet = JIOT_ERR_OTA_STEP_VALUE_ERROR;
+                break;
+        }
+        cJiotJSON_AddItemToObject(data,"step",cJiotJSON_CreateInt64(pReq->step));
+
+		if (pReq->desc == NULL)
+		{
+			ERROR_LOG("desc is NULL");
+			nRet = JIOT_ERR_OTA_FORMAT_ERROR;
+			break;
+		}
+        if (strlen(pReq->desc) == 0 || strlen(pReq->desc) > APP_OTA_DESC_MAX_LEN)
+        {
+            ERROR_LOG("desc format err [%s]",pReq->desc);
+            nRet = JIOT_ERR_OTA_DESC_FORMAT_ERROR;
+            break;
+        }
+    	cJiotJSON_AddItemToObject(data,"desc",cJiotJSON_CreateString(pReq->desc));
 
+        if (pReq->task_id < 0)
+        {
+			ERROR_LOG("task_id value err [%ld]",pReq->task_id);
+			nRet = JIOT_ERR_OTA_STEP_VALUE_ERROR;
+			break;
+        }
+        cJiotJSON_AddItemToObject(data,"task_id",cJiotJSON_CreateInt64(pReq->task_id));
+
+    }while(0);
+
+    if(nRet == JIOT_SUCCESS)
+    {
+        char* pPayload = cJiotJSON_PrintUnformatted(root) ;
+        char tempTopic[128] = {0};
+
+        sprintf(tempTopic,JMQTT_TOPIC_OTA_STATUSREPORT_REQ,pClient->szProductKey,pClient->szDeviceName);
+
+        MQTTMessage message = MQTTMessage_initializer ;
+        message.payload = (void*)pPayload;
+        message.payloadlen = strlen(pPayload);
+
+        nRet = jiot_mqtt_publish(pJMqttCli,tempTopic,&message,seqNo,E_JCLIENT_MSG_NORMAL);
+        if (nRet != JIOT_SUCCESS)
+        {
+            ERROR_LOG("publish message failed, Topic:[%s] message:[%s]",tempTopic,pPayload);
+        }
+        DEBUG_LOG("Topic:[%s] message:[%s]",tempTopic,pPayload);
+        if(pPayload != NULL)
+        {
+            jiot_free(pPayload);
+            pPayload = NULL;
+        }
+    }
+    cJiotJSON_Delete(root);
+
+    JRet.errCode = nRet;
+    JRet.seqNo = seqNo ;
+
+    return JRet;
+}
 
 int _jiotPropertySetRsp(JClient * pClient ,const PropertySetRsp * pRsp)
 {
@@ -1012,6 +1151,55 @@ int _jiotMsgDeliverRsp(JClient * pClient, MsgDeliverRsp * pRsp )
 
 }
 
+// ota
+int _jiotOtaUpgradeInformRsp(JClient * pClient ,const OtaUpgradeInformRsp * pRsp)
+{
+    int nRet = JIOT_SUCCESS;
+
+	if(pClient == NULL)
+    {
+        nRet =  JIOT_ERR_JCLI_ERR;
+        return nRet ;
+    }
+
+    JMQTTClient * pJMqttCli =pClient->pJMqttCli;
+    if(pClient->pJMqttCli == NULL)
+    {
+        nRet =  JIOT_ERR_MQTT_ERR;
+        return nRet ;
+    }
+
+
+    cJiotJSON * root =  cJiotJSON_CreateObject();
+    long long  seqNo = pRsp->seq_no ;
+    cJiotJSON_AddItemToObject(root,"seq_no",cJiotJSON_CreateInt64(seqNo));
+    cJiotJSON_AddItemToObject(root,"code",cJiotJSON_CreateInt64(pRsp->code));
+    char* pPayload = cJiotJSON_PrintUnformatted(root) ;
+    char tempTopic[128] = {0};
+
+    sprintf(tempTopic,JMQTT_TOPIC_OTA_UPGRADEINFORM_RSP,pClient->szProductKey,pClient->szDeviceName);
+
+    MQTTMessage message = MQTTMessage_Qos0_initializer ;
+    message.payload = (void*)pPayload;
+    message.payloadlen = strlen(pPayload);
+
+    nRet = jiot_mqtt_publish(pJMqttCli,tempTopic,&message,seqNo ,E_JCLIENT_MSG_NORMAL);
+    if (nRet != JIOT_SUCCESS)
+    {
+        ERROR_LOG("publish message failed, Topic:[%s] message:[%s]",tempTopic,pPayload);
+    }
+    DEBUG_LOG("Topic:[%s] message:[%s]",tempTopic,pPayload);
+    if(pPayload != NULL)
+    {
+        jiot_free(pPayload);
+        pPayload = NULL;
+    }
+
+    cJiotJSON_Delete(root);
+
+    return nRet;
+}
+
 int _jiotPingReq(JClient * pClient)
 {
 	char strBuf[21] = {0};
@@ -1162,6 +1350,16 @@ int _jiotSysMsg( void * pContext , MessageData * msg)
         return _jiotVersionReportRsp(pContext,msg);
     }
     else
+    if (0==strcmp(szShortTopicName,JMQTT_SHORTTOPIC_OTA_UPGRADEINFORM_REQ))
+    {
+        return _jiotOtaUpgradeInformReq(pContext,msg);
+    }
+    else
+    if (0==strcmp(szShortTopicName,JMQTT_SHORTTOPIC_OTA_STATUSREPORT_RSP))
+    {
+        return _jiotOtaStatusReportRsp(pContext,msg);
+    }
+    else
     {
         ERROR_LOG("topicName is error %s",msg->topicName->lenstring.data);
     }
@@ -1529,6 +1727,139 @@ int _jiotMsgDeliverReq( void * pContext , MessageData * msg)
 
     return nRet;   
 }
+// ota
+int _jiotOtaUpgradeInformReq(void* pContext, MessageData* msg)
+{
+    ENTRY;
+    JClient *pClient  = (JClient *)pContext;
+    if(pClient == NULL)
+    {
+        return JIOT_FAIL;
+    }
+
+    JMQTTClient * pJMqttCli =pClient->pJMqttCli;
+    if(pJMqttCli == NULL)
+    {
+        return JIOT_FAIL;
+    }
+
+    int nRet = JIOT_SUCCESS;
+    OtaUpgradeInformReq req;
+    memset(&req,0,sizeof(OtaUpgradeInformReq));
+
+
+    cJiotJSON * root = NULL;
+    do
+    {
+        root = cJiotJSON_Parse(msg->message->payload);
+        ASSERT_JSONOBJ(root);
+        cJiotJSON * obj  = NULL ;
+
+        obj = cJiotJSON_GetObjectItem(root,"seq_no");
+        ASSERT_JSONOBJ(obj);
+        req.seq_no = obj->valueint64;
+
+        cJiotJSON * data = NULL;
+        data = cJiotJSON_GetObjectItem(root,"data");
+        ASSERT_JSONOBJ(obj);
+
+        obj = cJiotJSON_GetObjectItem(data,"size");
+        ASSERT_JSONOBJ(obj);
+        req.size = obj->valueint64;
+
+        obj = cJiotJSON_GetObjectItem(data,"url");
+        ASSERT_JSONOBJ(obj);
+        req.url = obj->valuestring;
+
+        obj = cJiotJSON_GetObjectItem(data,"md5");
+        ASSERT_JSONOBJ(obj);
+        req.md5 = obj->valuestring;
+
+        obj = cJiotJSON_GetObjectItem(data,"app_ver");
+        ASSERT_JSONOBJ(obj);
+        req.app_ver = obj->valuestring;
+
+        obj = cJiotJSON_GetObjectItem(data,"task_id");
+        ASSERT_JSONOBJ(obj);
+        req.task_id = obj->valueint64;
+
+    }while(0);
+
+    OtaUpgradeInformRsp rsp ;
+    rsp.seq_no =  req.seq_no;
+    if (g_errcode != JIOT_SUCCESS)
+    {
+        rsp.code = g_errcode;
+    }
+    else
+    {
+        rsp.code = 0;
+    }
+
+    _jiotOtaUpgradeInformRsp(pClient,&rsp);
+
+    if (pClient->cb._cbOtaUpgradeInformReq != NULL)
+    {
+        pClient->cb._cbOtaUpgradeInformReq(pClient->pContext,(void*)pClient,&req,g_errcode);
+    }
+    else
+    {
+        ERROR_LOG("_cbOtaUpgradeReq not Register");
+    }
+
+    cJiotJSON_Delete(root);
+
+    return nRet;
+}
+int _jiotOtaStatusReportRsp( void * pContext , MessageData * msg)
+{
+    ENTRY;
+    JClient *pClient  = (JClient *)pContext;
+    if(pClient == NULL)
+    {
+        return JIOT_FAIL;
+    }
+
+    JMQTTClient * pJMqttCli =pClient->pJMqttCli;
+    if(pJMqttCli == NULL)
+    {
+        return JIOT_FAIL;
+    }
+
+    int nRet = JIOT_SUCCESS;
+    OtaStatusReportRsp rsp;
+    memset(&rsp,0,sizeof(VersionReportRsp));
+
+    cJiotJSON * root = NULL;
+    do
+    {
+        root = cJiotJSON_Parse(msg->message->payload);
+        ASSERT_JSONOBJ(root);
+        cJiotJSON * obj  = NULL ;
+
+        obj = cJiotJSON_GetObjectItem(root,"seq_no");
+        ASSERT_JSONOBJ(root);
+        rsp.seq_no = obj->valueint64;
+
+        obj = cJiotJSON_GetObjectItem(root,"code");
+        ASSERT_JSONOBJ(root);
+        rsp.code = obj->valueint64;
+    }while(0);
+
+    if (pClient->cb._cbOtaStatusReportRsp != NULL)
+    {
+        pClient->cb._cbOtaStatusReportRsp(pClient->pContext,(void*)pClient,&rsp,g_errcode);
+    }
+    else
+    {
+        ERROR_LOG("cbOtaReportRsp not Register");
+    }
+
+    cJiotJSON_Delete(root);
+
+    return nRet;
+}
+
 
 int _jiotPingRsp( void * pContext , MessageData * msg)
 {

+ 2 - 2
jiot-c-sdk/src/mqtt/MQTTClient-C/src/jiot_mqtt_client.c

@@ -1907,7 +1907,7 @@ int jiot_create_thread(JMQTTClient * pClient)
     {
         pClient->isRun = false ;
         ERROR_LOG("run jiot_retrans_thread error!");
-        jiot_pthread_cancel(&pClient->threadRecv);
+        jiot_pthread_cancel(&pClient->threadRetrans);
         return JIOT_FAIL;
     }
 
@@ -2502,4 +2502,4 @@ int common_check_topic(const char * topicName,E_TOPIC_TYPE type)
     }
 
     return JIOT_SUCCESS;
-}
+}

+ 1 - 1
samples/demo.c

@@ -467,7 +467,7 @@ static int start_demo_test()
 }
 
 
-#ifdef PKG_USING_JIOT-C-SDK
+#ifdef RT_USING_JIOT_C_SDK
 #include <finsh.h>
 
 MSH_CMD_EXPORT_ALIAS(start_demo_test, start_demo_test,Example: start_demo_test);