修复USB流控问题导致边接收边保存时数据丢包问题
This commit is contained in:
parent
204586f281
commit
6bc617180c
@ -113,7 +113,7 @@ void Transfer_file(uint8_t *buffer)
|
||||
char file_name[64];
|
||||
// ESP_LOGI(TAG,"Transfer_file");
|
||||
data_len = buffer[1] << 8 | buffer[2];
|
||||
ESP_LOGI(TAG,"data_len:%d",data_len);
|
||||
// ESP_LOGI(TAG,"data_len:%d",data_len);
|
||||
data_buff = malloc(data_len +10);
|
||||
if(buffer[0] == 0x01) {//文件名
|
||||
if (WaitPrnBufBytes(&uart_interface_data,data_len,1000,(uint8_t*)&data_buff[0]) == data_len)
|
||||
@ -134,7 +134,6 @@ void Transfer_file(uint8_t *buffer)
|
||||
printf("Failed to open file for writing\n");
|
||||
return;
|
||||
}
|
||||
// fclose(file);
|
||||
}
|
||||
|
||||
} else if(buffer[0] == 0x02) {//文件内容
|
||||
@ -150,18 +149,28 @@ void Transfer_file(uint8_t *buffer)
|
||||
if (written != (data_len - 4)) {
|
||||
ESP_LOGE("SPIFFS", "fwrite failed, written=%d", written);
|
||||
} else {
|
||||
ESP_LOGI("SPIFFS", "Write success: %d bytes", written);
|
||||
// ESP_LOGI("SPIFFS", "Write success: %d bytes", written);
|
||||
}
|
||||
if(data_buff[0] == 0xff && data_buff[1] == 0xff)
|
||||
{
|
||||
fclose(file);
|
||||
ESP_LOGI(TAG,"data_buff[0]:%X %X",data_buff[0],data_buff[1]);
|
||||
}
|
||||
ESP_LOGI(TAG,"data_buff[0]:%X %X",data_buff[0],data_buff[1]);
|
||||
// ESP_LOGI(TAG,"data_buff[0]:%X %X",data_buff[0],data_buff[1]);
|
||||
crc_calc = crc16_modbus((uint8_t*)&data_buff[2],data_len-4);
|
||||
}else{
|
||||
ESP_LOGE(TAG,"fail:%d",data_len);
|
||||
}
|
||||
|
||||
if(crc_calc != crc_received)
|
||||
{
|
||||
ESP_LOG_BUFFER_HEXDUMP("Recv str: ", &data_buff[0], 1024, ESP_LOG_INFO);
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(100/ portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
}
|
||||
} else if(buffer[0] == 0x03) {//删除所有文件
|
||||
if (WaitPrnBufBytes(&uart_interface_data,2,0xffff,(uint8_t*)&data_buff[0]) == 2)
|
||||
{
|
||||
@ -169,7 +178,7 @@ void Transfer_file(uint8_t *buffer)
|
||||
}
|
||||
delete_all_file();
|
||||
}
|
||||
ESP_LOGI(TAG,"crc:%X----%X",crc_calc,crc_received);
|
||||
// ESP_LOGI(TAG,"crc:%X----%X",crc_calc,crc_received);
|
||||
free(data_buff);
|
||||
}
|
||||
|
||||
@ -187,7 +196,7 @@ void Read_CMD_task(void *pvParameter)
|
||||
{
|
||||
|
||||
frameStreamRead(&uart_interface_data,&ch,1);
|
||||
ESP_LOGI(TAG, "Read:%X,%ld,---%ld:%ld",ch,frameStreamRecLen(&uart_interface_data),uart_interface_data.read,uart_interface_data.write);
|
||||
// ESP_LOGI(TAG, "Read:%X,%ld,---%ld:%ld",ch,frameStreamRecLen(&uart_interface_data),uart_interface_data.read,uart_interface_data.write);
|
||||
if(ch == 0xAA)
|
||||
{
|
||||
if (WaitPrnBufBytes(&uart_interface_data,2,0xffff,&data[0]) == 2)
|
||||
|
||||
@ -83,7 +83,7 @@ void app_main(void)
|
||||
ESP_LOGI(TAG, "Found file: %s, size: %ld bytes", off_line_tool.directory[0].name, off_line_tool.directory[0].size);
|
||||
ESP_LOGI(TAG, "Found file: %s, size: %ld bytes", off_line_tool.directory[1].name, off_line_tool.directory[1].size);
|
||||
ESPFlash_Init();
|
||||
stream_init(&uart_interface_data,1024*100);
|
||||
stream_init(&uart_interface_data,1024*50);
|
||||
|
||||
ESP_LOGI(TAG, "mem free:%ld",esp_get_free_heap_size());
|
||||
gpio_config_t config = {
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#define EX_UART_NUM UART_NUM_1
|
||||
#define PATTERN_CHR_NUM (3) /*!< Set the number of consecutive and identical characters received by receiver which defines a UART pattern*/
|
||||
|
||||
#define BUF_SIZE (1024)
|
||||
#define BUF_SIZE (4096)
|
||||
#define ECHO_TASK_STACK_SIZE (4096)
|
||||
|
||||
#define RD_BUF_SIZE (BUF_SIZE)
|
||||
@ -32,29 +32,33 @@ static void echo_task(void *arg)
|
||||
|
||||
while (1) {
|
||||
|
||||
int len = usb_serial_jtag_read_bytes(data, (BUF_SIZE - 1), 2000 / portTICK_PERIOD_MS);
|
||||
int len = usb_serial_jtag_read_bytes(data, (BUF_SIZE - 1), 200 / portTICK_PERIOD_MS);
|
||||
|
||||
// Write data back to the USB SERIAL JTAG
|
||||
if (len) {
|
||||
// usb_serial_jtag_write_bytes((const char *) data, len, 20 / portTICK_PERIOD_MS);
|
||||
if(frameStreamRecEmptyLen(&uart_interface_data) < 1024*30)
|
||||
if(frameStreamRecEmptyLen(&uart_interface_data) < 1024*4)
|
||||
{
|
||||
ESP_LOGE(TAG,"frameStream Be almost full:%d",len);
|
||||
// ESP_LOGE(TAG,"frameStream Be almost full:%d",len);
|
||||
frameStreamWrite(&uart_interface_data,&data[0],len);
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(10/ portTICK_PERIOD_MS);
|
||||
if(frameStreamRecEmptyLen(&uart_interface_data) > 1024*32)
|
||||
len = usb_serial_jtag_read_bytes(data, 0, 200 / portTICK_PERIOD_MS);//Ë¢ÐÂÁ÷¿Ø
|
||||
if(frameStreamRecEmptyLen(&uart_interface_data) > 1024*6)
|
||||
{
|
||||
ESP_LOGE(TAG,"frameStream: %ld",frameStreamRecEmptyLen(&uart_interface_data));
|
||||
// ESP_LOGE(TAG,"frameStream: %ld",frameStreamRecEmptyLen(&uart_interface_data));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
frameStreamWrite(&uart_interface_data,&data[0],len);
|
||||
}
|
||||
|
||||
// uart_write_bytes(EX_UART_NUM, (const char *) data, len);
|
||||
// data[len] = '\0';
|
||||
// ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, len, ESP_LOG_INFO);
|
||||
// ESP_LOG_BUFFER_HEXDUMP("Recv str: ", data, 8, ESP_LOG_INFO);
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user