Forráskód Böngészése

update:优化http fota的日志和报错输出

Dozingfiretruck 2 éve
szülő
commit
aa00169ab4

+ 18 - 9
components/network/libhttp/luat_http_client.c

@@ -71,6 +71,10 @@ static void http_resp_error(luat_http_ctrl_t *http_ctrl, int error_code) {
 #ifdef LUAT_USE_FOTA
 	if (http_ctrl->isfota){
 		luat_fota_end(0);
+		if (http_ctrl->parser.status_code){
+			error_code = 0;
+			http_ctrl->body_len = 0;
+		}
 	}
 #endif
 	if (http_ctrl->close_state == 0 && http_ctrl->headers_complete && http_ctrl->re_request_count < HTTP_RE_REQUEST_MAX){
@@ -165,7 +169,7 @@ static int on_body(http_parser* parser, const char *at, size_t length){
 		luat_fs_fwrite(at, length, 1, http_ctrl->fd);
 	}
 #ifdef LUAT_USE_FOTA
-	else if(http_ctrl->isfota){
+	else if(http_ctrl->isfota && parser->status_code == 200){
 		if (luat_fota_write((uint8_t*)at, length) < 0){
 			luat_fota_end(0);
 			http_resp_error(http_ctrl, HTTP_ERROR_FOTA);
@@ -195,17 +199,22 @@ static int on_message_complete(http_parser* parser){
 	}
 #ifdef LUAT_USE_FOTA
 	else if(http_ctrl->isfota){
-		int result = luat_fota_done();
-		while (result>0){
-			luat_timer_mdelay(100);
-			result = luat_fota_done();
-		}
-		if (result==0){
-			luat_fota_end(1);
+		if (parser->status_code == 200){
+			int result = luat_fota_done();
+			while (result>0){
+				luat_timer_mdelay(100);
+				result = luat_fota_done();
+			}
+			if (result==0){
+				luat_fota_end(1);
+			}else{
+				luat_fota_end(0);
+				http_resp_error(http_ctrl, HTTP_ERROR_FOTA);
+				return -1;
+			}
 		}else{
 			luat_fota_end(0);
 			http_resp_error(http_ctrl, HTTP_ERROR_FOTA);
-			return -1;
 		}
 	}
 #endif

+ 1 - 7
components/network/libhttp/luat_lib_http.c

@@ -333,12 +333,6 @@ int32_t l_http_callback(lua_State *L, void* ptr){
 	}
 
 	lua_pushinteger(L, http_ctrl->parser.status_code);
-#ifdef LUAT_USE_FOTA
-	if(http_ctrl->isfota){
-		luat_cbcwait(L, idp, 1);
-		goto exit;
-	}
-#endif
 	lua_newtable(L);
 	// LLOGD("http_ctrl->headers:%.*s",http_ctrl->headers_len,http_ctrl->headers);
 	header = http_ctrl->headers;
@@ -378,7 +372,7 @@ int32_t l_http_callback(lua_State *L, void* ptr){
 		goto exit;
 	}
 #ifdef LUAT_USE_FOTA
-	else if(http_ctrl->isfota){
+	else if(http_ctrl->isfota && http_ctrl->parser.status_code == 200){
 		lua_pushinteger(L, http_ctrl->body_len);
 		luat_cbcwait(L, idp, 3); // code, headers, body
 	}

+ 6 - 3
script/libs/libfota.lua

@@ -53,7 +53,6 @@ local libfota = {}
 
 
 local function fota_task(cbFnc,storge_location, len, param1,ota_url,ota_port,libfota_timeout,server_cert, client_cert, client_key, client_password)
-    -- log.info("http.get", "fota_task")
     if cbFnc == nil then
         cbFnc = function() end
     end
@@ -82,9 +81,13 @@ local function fota_task(cbFnc,storge_location, len, param1,ota_url,ota_port,lib
         
     end
     local code, headers, body = http.request("GET", ota_url, nil, nil, {fota=true,timeout = libfota_timeout},server_cert, client_cert, client_key, client_password).wait()
-    log.info("http.get", code, headers, body)
+    log.info("http fota", code, headers, body)
     if code == 200 then
-        ret = 0
+        if body == 0 then
+            ret = 4
+        else
+            ret = 0
+        end
     elseif code == -4 then
         ret = 1
     elseif code == -5 then