//TEST Modifications #define BUFF_SIZE 5242880 //5MB //270336 //264Kbytes #define FILE_264KB 266000 #define FILE_519KB 532000 #define FILE_1_01MB 1064000 #define FILE_2_02MB 2128000 #define FILE_3_04MB 3192000 #define FILE_4_05MB 4256000 #define FILE_4_93MB 5175200 #define FILE_BOOTBIN 4297352 static uint8_t uc_buffer[BUFF_SIZE]; static uint32_t u32_buf_index=0; static uint32_t u32_buf_index_rd=0; //TEST Modifications static BaseType_t prvStoreFileWork( FTPClient_t *pxClient ) { BaseType_t xRc, xWritten; //TEST Modifications BaseType_t counter, rd_count, num_line; uint8_t b_flag = 0; static FF_FILE *pc_file = NULL; size_t size; static BaseType_t buf_idx; //TEST Modifications /* Read from the data socket until all has been read or until a negative value is returned. */ for( ; ; ) { char *pcBuffer; /* The "zero-copy" method: */ xRc = FreeRTOS_recv( pxClient->xTransferSocket, ( void * ) &pcBuffer, 0x20000u, FREERTOS_ZERO_COPY | FREERTOS_MSG_DONTWAIT ); if( xRc <= 0 ) { break; } pxClient->ulRecvBytes += xRc; //TEST Modifications for(counter=0;counter= FILE_519KB) { FreeRTOS_printf( ("prvStoreFileWork: Written bytes: %u\n", buf_idx) ); // Close the file ff_fclose(pc_file); //Check the buffer: 98 'A'+CR+LF - 2660 lines rd_count = 0; num_line = 0; do { for(counter=0;counter<100;counter++) { if(((counter==99)&&(uc_buffer[rd_count]!=10)) || //LF ((counter==98)&&(uc_buffer[rd_count]!=13))) //CR { FreeRTOS_printf( ("prvStoreFileWork: CORRUPTED BUFFER - Line %u\n", num_line) ); b_flag = 1; } else if((counter<=97)&&(uc_buffer[rd_count]!=0x41)) { FreeRTOS_printf( ("prvStoreFileWork: CORRUPTED BUFFER - Line %u\n", num_line) ); b_flag = 1; } rd_count++; } num_line++; } while(rd_count < u32_buf_index); if(b_flag == 0) { //#if 0 // Save into a file pc_file = ff_fopen("/ram/ccopy.txt", "w"); if(pc_file != NULL) { size = ff_fwrite(uc_buffer, 1, u32_buf_index, pc_file); FreeRTOS_printf( ("prvStoreFileWork: Written bytes: %u\n", size) ); ff_fclose(pc_file); } //#endif // Verify the written file memset(uc_buffer,0,u32_buf_index); pc_file = ff_fopen("/ram/ccopy.txt", "r"); if(pc_file != NULL) { size = ff_fread(uc_buffer, 1, u32_buf_index, pc_file); FreeRTOS_printf( ("prvStoreFileWork: Read bytes: %u\n", size) ); //Check the buffer: 98 'A'+CR+LF - 2660 lines rd_count = 0; num_line = 0; do { for(counter=0;counter<100;counter++) { if(((counter==99)&&(uc_buffer[rd_count]!=10)) || //LF ((counter==98)&&(uc_buffer[rd_count]!=13))) //CR { FreeRTOS_printf( ("prvStoreFileWork: CORRUPTED FILE - Line %u\n", num_line) ); } else if((counter<=97)&&(uc_buffer[rd_count]!=0x41)) { FreeRTOS_printf( ("prvStoreFileWork: CORRUPTED FILE - Line %u\n", num_line) ); } rd_count++; } num_line++; } while(rd_count < u32_buf_index); ff_fclose(pc_file); } } //u32_buf_index = 0; //xWritten = ff_fwrite( uc_buffer, 1, u32_buf_index, pxClient->pxWriteHandle ); } // xWritten = xRc; //TEST Modifications xWritten = ff_fwrite( pcBuffer, 1, xRc, pxClient->pxWriteHandle ); FreeRTOS_recv( pxClient->xTransferSocket, ( void * ) NULL, xRc, 0 ); if( xWritten != xRc ) { xRc = -1; /* bHadError: a transfer got aborted because of an error. */ pxClient->bits1.bHadError = pdTRUE_UNSIGNED; break; } } return xRc; }