stm32F407学习之19:HTTP客户端(IAP)

最近打算写个HTTP下载程序的功能。 直接上代码

一、编写HTTP客户端
httpclient.h

#ifndef __HTTP_CLIENT_H__
#define __HTTP_CLIENT_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include "stm32f4xx.h"
#include "board.h"
#include "rtx_os.h"

#include "lwip/init.h"
#include "lwip/netif.h"
#include "lwip/tcp.h"
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/dns.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>



// 回调函数类型定义
typedef void (*http_data_callback_t)(const uint8_t *data, size_t len, void *user_data);

// HTTP客户端状态
typedef enum {
    DOWNLOAD_STATE_IDLE,         // 空闲状态
    DOWNLOAD_STATE_STARTING,     // 开始下载
    DOWNLOAD_STATE_DOWNLOADING,  // 正在下载
    DOWNLOAD_STATE_COMPLETED,    // 下载完成
    DOWNLOAD_STATE_ERROR,        // 发生错误
    DOWNLOAD_STATE_FINISHED      // 升级结束
} download_state_t;

typedef struct {
    http_data_callback_t data_callback;
    void *user_data;
    size_t total_len; // 总数据长度
    size_t received_len; // 已接收的数据长度
    int is_header_received; // 是否已经接收完HTTP头
    int is_error_occurred; // 是否发生错误
    char *error_message; // 错误信息
	  char *file;          //待下载的文件
    download_state_t state; // 当前下载状态
		char is_chunked;     //支持分段
} http_client_state_t;


// 初始化HTTP客户端
void http_client_init(http_client_state_t *state);


// 下载文件
err_t http_client_download(const char *server_ip, uint16_t port) ;

// 获取当前下载状态
download_state_t http_client_get_state(void);


// 获取错误信息
const char* http_client_get_error_message(void);


static void *memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) {
    if (needle_len == 0) {
        return (void *)haystack;
    }

    const unsigned char *h = (const unsigned char *)haystack;
    const unsigned char *n = (const unsigned char *)needle;
    for (size_t i = 0; i <= haystack_len - needle_len; ++i) {
        if (memcmp(h + i, n, needle_len) == 0) {
            return (void *)(h + i);
        }
    }

    return NULL;
}
	
#ifdef __cplusplus
}
#endif

#endif


httpclient.c


#include "httpclient.h"
#include "lwip_client.h"
#include "rlog.h"
#define SERVER_PORT 80            // 服务器端口号

http_client_state_t client_state = {
    .data_callback = NULL,
    .user_data = NULL,
    .total_len = 0,
    .received_len = 0,
    .is_header_received = 0,
    .is_error_occurred = 0,
    .error_message = NULL,
    .file = NULL,
    .state = DOWNLOAD_STATE_IDLE,
    .is_chunked = 0
};

void tcp_dw_err(void *arg, err_t err) {
    RLOG_ERROR("TCP error: %d\n", err);
    client_state.is_error_occurred = 1;
    client_state.error_message = "TCP connection error";
    client_state.state = DOWNLOAD_STATE_ERROR;
}

err_t tcp_connected(void *arg, struct tcp_pcb *tpcb, err_t err) {
    RLOG_DEBUG("TCP connected\n");
    if (err == ERR_OK) {
        RLOG_DEBUG("TCP connected\n");
        client_state.state = DOWNLOAD_STATE_DOWNLOADING;
        char *request = "GET ";
        char *file_path = (char *)arg;
        char *request_end = " HTTP/1.1\r\nHost: ";
        char *host = "192.168.1.104"; // 这里假设服务器IP是固定的,可以根据需要动态设置
        char *full_request = malloc(strlen(request) + strlen(file_path) + strlen(request_end) + strlen(host) + 1);
        if (full_request) {
            sprintf(full_request, "%s%s%s%s\r\n\r\n", request, file_path, request_end, host);
            tcp_write(tpcb, full_request, strlen(full_request), TCP_WRITE_FLAG_COPY);
            RLOG_DEBUG("%s\r\n", full_request);
            free(full_request);
        }
        tcp_output(tpcb);
    } else {
        RLOG_DEBUG("Failed to connect to server: %d\n", err);
        client_state.is_error_occurred = 1;
        client_state.error_message = "Failed to connect to server";
        client_state.state = DOWNLOAD_STATE_ERROR;
    }
    return err;
}


err_t tcp_dw_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) {
    if (err == ERR_OK) {
        if (p != NULL) {
            RLOG_DEBUG("Received %d bytes\n", p->len);
            // 处理 HTTP 响应头
            if (!client_state.is_header_received) {
                char *header_end = memmem(p->payload, p->len, "\r\n\r\n", 4);
                if (header_end) {
                    // 找到响应头结束标志
                    header_end += 4; // 跳过 "\r\n\r\n"
                    int header_len = header_end - (char *)p->payload;
                    // 检查状态码
                    char *status_code = memmem(p->payload, header_len, "HTTP/1.1 200 OK", 15);
									  if(!status_code) status_code = memmem(p->payload, header_len, "HTTP/1.0 200 OK", 15);
                    if (status_code) {
                        RLOG_DEBUG("HTTP 200 OK received\n");
                        client_state.is_header_received = 1;

                        // 解析 Content-Length
                        char *content_length = memmem(p->payload, header_len, "Content-Length: ", 16);
                        if (content_length) {
                            content_length += 16; // 跳过 "Content-Length: "
                            char *end = memchr(content_length, '\r', header_len - (content_length - (char *)p->payload));
                            if (end) {
                                *end = '\0'; // 终止字符串
                                client_state.total_len = atoi(content_length);
                                RLOG_DEBUG("Content-Length: %d\n", client_state.total_len);
                            }
                        }

                        // 检查是否使用分块传输编码
                        char *transfer_encoding = memmem(p->payload, header_len, "Transfer-Encoding: chunked", 26);
                        if (transfer_encoding) {
                            client_state.is_chunked = 1;
                            RLOG_DEBUG("Chunked Transfer Encoding detected\n");
                        }

                        // 调用回调函数处理剩余数据
                        if (client_state.data_callback) {
                            client_state.data_callback(header_end, p->len - header_len, client_state.user_data);
                        }
                        client_state.received_len += p->len - header_len;
                    } else {
                        RLOG_DEBUG("HTTP status code is not 200 OK\n");
                        client_state.is_error_occurred = 1;
                        client_state.error_message = "HTTP status code is not 200 OK";
                        client_state.state = DOWNLOAD_STATE_ERROR;
                        tcp_close(tpcb);
                        pbuf_free(p);
                        return ERR_OK;
                    }
                } else {
                    RLOG_DEBUG("HTTP header not complete yet\n");
                    // 如果响应头不完整,继续接收
                    tcp_output(tpcb);
                    pbuf_free(p);
                    return ERR_OK;
                }
            } else {
                // 已经处理过响应头,直接处理数据
                if (client_state.is_chunked) {
                    // 处理分块数据
                    char *chunk_size_str = memmem(p->payload, p->len, "\r\n", 2);
                    if (chunk_size_str) {
                        chunk_size_str += 2; // 跳过 "\r\n"
                        int chunk_size = strtol(chunk_size_str, NULL, 16);
                        if (chunk_size > 0) {
                            // 处理当前块
                            char *chunk_data = memmem(p->payload, p->len, "\r\n", 2) + 2;
                            if (client_state.data_callback) {
                                client_state.data_callback(chunk_data, chunk_size, client_state.user_data);
                            }
                            client_state.received_len += chunk_size;
                        } else {
                            // 最后一个块,接收完成
                            client_state.state = DOWNLOAD_STATE_COMPLETED;
                            RLOG_DEBUG("File downloaded successfully. Total received: %d bytes\n", client_state.received_len);
                            tcp_close(tpcb);
                        }
                    }
                } else {
                    // 不是分块传输,直接处理数据
                    if (client_state.data_callback) {
                        client_state.data_callback(p->payload, p->len, client_state.user_data);
                    }
                    client_state.received_len += p->len;
                }
            }
            tcp_recved(tpcb, p->len);
            pbuf_free(p);
            RLOG_DEBUG("File downloaded successfully. current received: %d bytes\n", client_state.received_len);

            // 检查是否接收完整个文件
            if (client_state.received_len >= client_state.total_len) {
                client_state.state = DOWNLOAD_STATE_COMPLETED;
                RLOG_DEBUG("File downloaded successfully. Total received: %d bytes\n", client_state.received_len);
                tcp_close(tpcb);
            } else {
                // 继续接收
                tcp_output(tpcb);
            }
        } else {
            // 数据接收完成
            if (client_state.received_len == client_state.total_len) {
                client_state.state = DOWNLOAD_STATE_COMPLETED;
                RLOG_DEBUG("File downloaded successfully. Total received: %d bytes\n", client_state.received_len);
            } else {
                client_state.is_error_occurred = 1;
                client_state.error_message = "Incomplete file received";
                client_state.state = DOWNLOAD_STATE_ERROR;
                RLOG_DEBUG("Incomplete file received. Total received: %d bytes\n", client_state.received_len);
            }
            tcp_close(tpcb);
        }
    } else {
        RLOG_DEBUG("Error in data receive: %d\n", err);
        client_state.is_error_occurred = 1;
        client_state.error_message = "Error in data receive";
        client_state.state = DOWNLOAD_STATE_ERROR;
        tcp_close(tpcb);
    }
    return err;
}


err_t tcp_dw_sent(void *arg, struct tcp_pcb *tpcb, u16_t len) {
    err_t err = ERR_OK;
    if (err != ERR_OK) {
        RLOG_DEBUG("Error in data send: %d\n", err);
        client_state.is_error_occurred = 1;
        client_state.error_message = "Error in data send";
        client_state.state = DOWNLOAD_STATE_ERROR;
        tcp_close(tpcb);
    }
    return err;
}


err_t tcp_dw_poll(void *arg, struct tcp_pcb *tpcb) {
    if (client_state.is_error_occurred) {
        RLOG_DEBUG("Error occurred: %s\n", client_state.error_message);
        tcp_close(tpcb);
    }
    return ERR_OK;
}


void http_client_init(http_client_state_t *state) {
    memcpy(&client_state, state, sizeof(http_client_state_t));
}


err_t http_client_download(const char *server_ip, uint16_t port) {
    struct tcp_pcb *pcb = NULL;
    struct ip_addr server_ip_addr;

    pcb = tcp_new();
    if (pcb == NULL) {
        client_state.state = DOWNLOAD_STATE_ERROR;
        client_state.error_message = "Failed to create TCP PCB";
        return ERR_ARG;
    }

    if (strcmp(server_ip,"default") == 0) {
			IP4_ADDR(&server_ip_addr, 192, 168, 1, 104);
		} else {
			tcp_close(pcb);
			return ERR_ARG;
		}	

		err_t err = tcp_connect(pcb, &server_ip_addr, port, tcp_connected);
		if (err != ERR_OK) {
				client_state.state = DOWNLOAD_STATE_ERROR;
				client_state.error_message = "Failed to connect to server";
				tcp_close(pcb);
				return ERR_CONN;
		}
		tcp_arg(pcb, (void *)client_state.file);
		tcp_err(pcb, tcp_dw_err);
		tcp_recv(pcb, tcp_dw_recv);
		tcp_sent(pcb, tcp_dw_sent);
		tcp_poll(pcb, tcp_dw_poll, 1);
		return err;
}



download_state_t http_client_get_state(void) {
	return client_state.state;
}

const char* http_client_get_error_message(void) {
	return client_state.error_message;
}

upg_task.h

#ifndef __UPG_TASK_H__
#define __UPG_TASK_H__

#ifdef __cplusplus
extern "C" {
#endif
	
#include "stm32f4xx.h"
#include "board.h"
#include "rtx_os.h"

void upg_task_create(void);

	
	
#ifdef __cplusplus
}
#endif

#endif


upg_task.c

#include <stdio.h>
#include "rtx_os.h"
#include "board.h"
#include "upg_task.h"
#include "httpclient.h"
#include "appflash.h"
#include "rlog.h"



// 状态机状态
typedef enum {
    UPG_STATE_INIT,
    UPG_STATE_DOWNLOAD,
    UPG_STATE_WAIT,
	UPG_STATE_CHECK,
	UPG_STATE_WRITE,
    UPG_STATE_ERROR,
	UPG_STATE_FINISHED,
} upg_state_t;


static uint32_t file_length = 0;
static uint32_t lootcnt = 0;
// 回调函数示例
void savedata(const uint8_t *data, size_t len, void *user_data) {
    // 这里实现将数据保存到Flash的逻辑
    // 例如,使用硬件平台提供的Flash写入API
	  file_length += len;
	lootcnt ++;
    RLOG_DEBUG("Saving %d bytes to Flash. total_len = %d  lootcnt = %d\n", len,file_length, lootcnt);
    // 假设有一个函数 flash_write(uint8_t *data, size_t len) 用于写入Flash
    // flash_write((uint8_t *)data, len);
	  //osDelay(5000);
}



//动态属性
const osThreadAttr_t upg_task_attr = {
    .name = "upgTask",  // 任务名称
    .stack_size = 2048,  // 任务栈大小
    .priority = osPriorityHigh,  // 任务优先级
};


//http://192.168.1.104/Application.bin
//task2
void UpgTask(void *argument) {
	// 执行任务逻辑
	// ...
	osDelay(3000);
	RLOG_DEBUG("UPGTask called..\n");
	upg_state_t current_state = UPG_STATE_INIT;

    // 初始化HTTP客户端
	http_client_state_t client_state;
	
	// 设置服务器IP和文件路径
     char *server_ip = "default";
   char *downloadfile = "/application.bin";
	//char *downloadfile = "/text.bin";
   uint8_t retry = 0;
	download_state_t download_state;
	err_t err = ERR_OK;
	
	client_state.state = DOWNLOAD_STATE_STARTING;
    client_state.data_callback = savedata;
    client_state.user_data = NULL;
    client_state.received_len = 0;
    client_state.is_header_received = 0;
    client_state.is_error_occurred = 0;
    client_state.error_message = NULL;
	  client_state.file = downloadfile;   //待下载的文件
    http_client_init(&client_state);

    retry = 0;
		
    while (1) {
			  RLOG_DEBUG("UpgTask  current_state = %d\r\n",current_state);
        switch (current_state) {
            case UPG_STATE_INIT:
                RLOG_DEBUG("Initializing...\n");
                // 开始下载
                err = http_client_download(server_ip, 80);
				if(err == ERR_OK){
					current_state = UPG_STATE_DOWNLOAD;
				}
				else{
					if(++retry >= 3) {  //尝试5次
						current_state = UPG_STATE_ERROR;
					}
					osDelay(500);
				}
                break;

            case UPG_STATE_DOWNLOAD:
                RLOG_DEBUG("Downloading...\n");
                // 进入等待状态
                current_state = UPG_STATE_WAIT;
                break;

            case UPG_STATE_WAIT:
                // 获取当前下载状态
                download_state = http_client_get_state();
                if (download_state == DOWNLOAD_STATE_COMPLETED) {
                    RLOG_DEBUG("Download completed successfully.\n");
                    current_state = UPG_STATE_CHECK;
                } else if (download_state == DOWNLOAD_STATE_ERROR) {
                    const char *error_message = http_client_get_error_message();
                    RLOG_DEBUG("Error occurred: %s\n", error_message);
                    current_state = UPG_STATE_ERROR;
                }
                // 这里可以添加其他任务或事件处理
                // 例如,调用lwip的定时器处理函数
                break;
				
			case UPG_STATE_CHECK:
				RLOG_DEBUG("Program Check.\n");
				//current_state = UPG_STATE_ERROR;
				current_state = UPG_STATE_WRITE;
				break; 
				
			case UPG_STATE_WRITE:	
			    //只更新头部,不执行真正的写操作
				RLOG_DEBUG("Program write.\n");   
				current_state = UPG_STATE_FINISHED;
				break;
				
			case UPG_STATE_FINISHED:
					RLOG_DEBUG("Program finished.\n");
					return ;

			case UPG_STATE_ERROR:
					RLOG_DEBUG("Program terminated due to error.\n");
					return ;

			default:
					RLOG_DEBUG("Unknown state.\n");
					return ;
        }
	  // 延时 1 秒
      osDelay(1000);  // 参数单位为毫秒
    }
}



void upg_task_create(void)
{
	osThreadNew(UpgTask, NULL, &upg_task_attr);  // 使用默认属性创建任务
}


二、验证结果

[10:34:21.215]收←◆[DEBUG] UPGTask called..

[10:34:21.288]收←◆[DEBUG] UpgTask  current_state = 0
[DEBUG] Initializing...
[DEBUG] TCP connected
[DEBUG] TCP connected
[DEBUG] GET /application.bin HTTP/1.1
Host: 192.168.1.104


[DEBUG] Received 154 bytes
[DEBUG] HTTP 200 OK received
[DEBUG] Content-Length: 82692
[DEBUG] Saving 0 bytes to Flash. total_len = 0  lootcnt = 1
[DEBUG] File downloaded successfully. current received: 0 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 1460  lootcnt = 2
[DEBUG] File downloaded successfully. current received: 1460 bytes
[DEBUG] Received 588 bytes
[DEBUG] Saving 588 bytes to Flash. total_len = 2048  lootcnt = 3
[DEBUG] File downloaded successfully. current received: 2048 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 3508  lootcnt = 4
[DEBUG] File downloaded successfully. current received: 3508 bytes
[DEBUG] Received 872 bytes
[DEBUG] Saving 872 bytes to Flash. total_len = 4380  lootcnt = 5
[DEBUG] File downloaded successfully. current received: 4380 bytes

[10:34:21.356]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 5840  lootcnt = 6
[DEBUG] File downloaded successfully. current received: 5840 bytes
[DEBUG] Received 588 bytes
[DEBUG] Saving 588 bytes to Flash. total_len = 6428  lootcnt = 7
[DEBUG] File downloaded successfully. current received: 6428 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 7888  lootcnt = 8
[DEBUG] File downloaded successfully. current received: 7888 bytes
[DEBUG] Received 872 bytes
[DEBUG] Saving 872 bytes to Flash. total_len = 8760  lootcnt = 9
[DEBUG] File downloaded successfully. current received: 8760 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 10220  lootcnt = 10
[DEBUG] File downloaded successfully. current received: 10220 bytes
[DEBUG] Received 588 bytes
[DEBUG] Saving 588 bytes to Flash. total_len = 10808  lootcnt = 11
[DEBUG] File downloaded successfully. current received: 10808 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 12268  lootcnt = 12
[DEBUG] File downloaded successfully. current received: 12268 bytes
[DEBUG] Received 872 bytes
[DEBUG] Saving 872 bytes to Flash. total_len = 13140  lootcnt = 13
[DEBUG] File downloaded successfully. current received: 13140 bytes

[10:34:21.414]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 14600  lootcnt = 14
[DEBUG] File downloaded successfully. current received: 14600 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 16060  lootcnt = 15
[DEBUG] File downloaded successfully. current received: 16060 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 17520  lootcnt = 16
[DEBUG] File downloaded successfully. current received: 17520 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 18980  lootcnt = 17
[DEBUG] File downloaded successfully. current received: 18980 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 20440  lootcnt = 18
[DEBUG] File downloaded successfully. current received: 20440 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 21900  lootcnt = 19
[DEBUG] File downloaded successfully. current received: 21900 bytes

[10:34:21.478]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 23360  lootcnt = 20
[DEBUG] File downloaded successfully. current received: 23360 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 24820  lootcnt = 21
[DEBUG] File downloaded successfully. current received: 24820 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 26280  lootcnt = 22
[DEBUG] File downloaded successfully. current received: 26280 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 27740  lootcnt = 23
[DEBUG] File downloaded successfully. current received: 27740 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 29200  lootcnt = 24
[DEBUG] File downloaded successfully. current received: 29200 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 30660  lootcnt = 25
[DEBUG] File downloaded successfully. current received: 30660 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 32120  lootcnt = 26
[DEBUG] File downloaded successfully. current received: 32120 bytes

[10:34:21.542]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 33580  lootcnt = 27
[DEBUG] File downloaded successfully. current received: 33580 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 35040  lootcnt = 28
[DEBUG] File downloaded successfully. current received: 35040 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 36500  lootcnt = 29
[DEBUG] File downloaded successfully. current received: 36500 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 37960  lootcnt = 30
[DEBUG] File downloaded successfully. current received: 37960 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 39420  lootcnt = 31
[DEBUG] File downloaded successfully. current received: 39420 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 40880  lootcnt = 32
[DEBUG] File downloaded successfully. current received: 40880 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 42340  lootcnt = 33
[DEBUG] File downloaded successfully. current received: 42340 bytes

[10:34:21.598]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 43800  lootcnt = 34
[DEBUG] File downloaded successfully. current received: 43800 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 45260  lootcnt = 35
[DEBUG] File downloaded successfully. current received: 45260 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 46720  lootcnt = 36
[DEBUG] File downloaded successfully. current received: 46720 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 48180  lootcnt = 37
[DEBUG] File downloaded successfully. current received: 48180 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 49640  lootcnt = 38
[DEBUG] File downloaded successfully. current received: 49640 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 51100  lootcnt = 39
[DEBUG] File downloaded successfully. current received: 51100 bytes

[10:34:21.664]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 52560  lootcnt = 40
[DEBUG] File downloaded successfully. current received: 52560 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 54020  lootcnt = 41
[DEBUG] File downloaded successfully. current received: 54020 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 55480  lootcnt = 42
[DEBUG] File downloaded successfully. current received: 55480 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 56940  lootcnt = 43
[DEBUG] File downloaded successfully. current received: 56940 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 58400  lootcnt = 44
[DEBUG] File downloaded successfully. current received: 58400 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 59860  lootcnt = 45
[DEBUG] File downloaded successfully. current received: 59860 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 61320  lootcnt = 46
[DEBUG] File downloaded successfully. current received: 61320 bytes

[10:34:21.727]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 62780  lootcnt = 47
[DEBUG] File downloaded successfully. current received: 62780 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 64240  lootcnt = 48
[DEBUG] File downloaded successfully. current received: 64240 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 65700  lootcnt = 49
[DEBUG] File downloaded successfully. current received: 65700 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 67160  lootcnt = 50
[DEBUG] File downloaded successfully. current received: 67160 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 68620  lootcnt = 51
[DEBUG] File downloaded successfully. current received: 68620 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 70080  lootcnt = 52
[DEBUG] File downloaded successfully. current received: 70080 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 71540  lootcnt = 53
[DEBUG] File downloaded successfully. current received: 71540 bytes

[10:34:21.791]收←◆[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 73000  lootcnt = 54
[DEBUG] File downloaded successfully. current received: 73000 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 74460  lootcnt = 55
[DEBUG] File downloaded successfully. current received: 74460 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 75920  lootcnt = 56
[DEBUG] File downloaded successfully. current received: 75920 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 77380  lootcnt = 57
[DEBUG] File downloaded successfully. current received: 77380 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 78840  lootcnt = 58
[DEBUG] File downloaded successfully. current received: 78840 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 80300  lootcnt = 59
[DEBUG] File downloaded successfully. current received: 80300 bytes
[DEBUG] Received 1460 bytes
[DEBUG] Saving 1460 bytes to Flash. total_len = 81760  lootcnt = 60
[DEBUG] File downloaded successfully. current received: 81760 bytes

[10:34:21.841]收←◆[DEBUG] Received 932 bytes
[DEBUG] Saving 932 bytes to Flash. total_len = 82692  lootcnt = 61
[DEBUG] File downloaded successfully. current received: 82692 bytes
[DEBUG] File downloaded successfully. Total received: 82692 bytes
[DEBUG] File downloaded successfully. Total received: 82692 bytes
TestTask called..
LedTask called..
NullTask called..

[10:34:22.849]收←◆[DEBUG] UpgTask  current_state = 1

[10:34:22.896]收←◆[DEBUG] Downloading...
TestTask called..
LedTask called..
NullTask called..

[10:34:23.882]收←◆[DEBUG] UpgTask  current_state = 2

[10:34:23.936]收←◆[DEBUG] Download completed successfully.
TestTask called..
LedTask called..
NullTask called..

[10:34:24.900]收←◆[DEBUG] UpgTask  current_state = 3

[10:34:24.946]收←◆[DEBUG] Program Check.
TestTask called..
LedTask called..
NullTask called..

[10:34:25.917]收←◆[DEBUG] UpgTask  current_state = 4

[10:34:25.967]收←◆[DEBUG] Program write.
TestTask called..
LedTask called..
NullTask called..

[10:34:26.935]收←◆[DEBUG] UpgTask  current_state = 6

[10:34:26.996]收←◆[DEBUG] Program finished.
LedTask called..
NullTask called..

三、其它
在实际验证的时候,好像HTTP分段功能有问题。后期有空再调试吧。另外,调试过程中,需要要修改PBUF_POOL_BUFSIZE, 将值调整为2048后,下载不发丢包。

#define PBUF_POOL_BUFSIZE       2048

image

posted @ 2025-09-12 10:41  cupid8505  阅读(11)  评论(0)    收藏  举报