diff --git a/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.c b/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.c index c2cc823..34c0937 100644 --- a/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.c +++ b/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.c @@ -21,6 +21,17 @@ #ifdef F_STORAGE extern void save_data(uint8_t *data, uint32_t data_len, uint16_t block_number); +static uint32_t g_tftp_save_data = 0; + +uint32_t get_tftp_received_size(void) +{ + return g_tftp_save_data; +} + +void clear_tftp_received_size(void) +{ + g_tftp_save_data = 0; +} void save_data(uint8_t *data, uint32_t data_len, uint16_t block_number) { //Nothing to do with received data yet.. @@ -30,6 +41,7 @@ void save_data(uint8_t *data, uint32_t data_len, uint16_t block_number) str = data; str += data_len; *str = 0x0; + g_tftp_save_data += data_len; //Store received data size PRINTF("\r\n++Data #%d-%lu:\r\n%s\r\n", block_number, data_len, data); } #endif diff --git a/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.h b/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.h index 49f64b7..1d4fc6e 100644 --- a/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.h +++ b/21_m1284p_WIZNET_TFTP_client_FATFS/Internet/TFTP/tftp.h @@ -102,6 +102,8 @@ void TFTP_exit(void); int TFTP_run(void); void TFTP_read_request(uint32_t server_ip, uint8_t *filename); void tftp_timeout_handler(void); +uint32_t get_tftp_received_size(void); +void clear_tftp_received_size(void); #ifdef __cplusplus } diff --git a/21_m1284p_WIZNET_TFTP_client_FATFS/debug.log b/21_m1284p_WIZNET_TFTP_client_FATFS/debug.log index 97c0222..17032f8 100644 --- a/21_m1284p_WIZNET_TFTP_client_FATFS/debug.log +++ b/21_m1284p_WIZNET_TFTP_client_FATFS/debug.log @@ -1,12 +1,15 @@ ########## SW1 was pressed. TFTP IP address : 192.168.0.100 TFTP IP address (32 bit) : 0xC0A80064 -[TFTP_read_request] Set Tftp Server : 0xc0a80064 +[TFTP_read_request] Set Tftp Server : 0xC0A80064 >> TFTP RRQ : FileName(test.txt), Mode(octet) -[recv_tftp_packet] Set Server Port : 49769 +[recv_tftp_packet] Server IP faults +from IP : 0x4B041004, Server IP : 0xC0A80064 +[recv_tftp_packet] Set Server Port : 53664 << TFTP_OACK : >> TFTP ACK : Block Number(0) << TFTP_DATA : opcode(3), block_num(1) + ++Data #1-109: #1 Hello to TFTP server! #2 Hello to TFTP server again! @@ -16,3 +19,13 @@ TFTP IP address (32 bit) : 0xC0A80064 >> TFTP ACK : Block Number(1) + +++TFTP transfer complete:[2] SUCCESS, received 109 bytes + +.. +Last attemp on large file result (ff_lfn_required.c : 243509): + +>> TFTP ACK : Block Number(476) + +++TFTP transfer complete:[2] SUCCESS, received 243509 bytes + diff --git a/21_m1284p_WIZNET_TFTP_client_FATFS/main.c b/21_m1284p_WIZNET_TFTP_client_FATFS/main.c index 2bcc3e4..c0a84cf 100644 --- a/21_m1284p_WIZNET_TFTP_client_FATFS/main.c +++ b/21_m1284p_WIZNET_TFTP_client_FATFS/main.c @@ -10,8 +10,9 @@ * Then prints out it contents head in a serial terminal. * TODO: * OK(v1.1) 1. Print-out received file from TFTP to serial console (small file < 512 bytes OK). - * 2. Print-out received file from TFTP to serial console (multi-packet files > 512 bytes). + * OK(v1.2) 2. Print-out received file from TFTP to serial console (multi-packet files > 512 bytes). * 3. Write-in data to SD-card file "readme_txt". + * 4. Add handlers for CHK_RAM_LEAKAGE && CHK_UPTIME. * * Remark: * Checked with PC tftp-server (WIN7) - tftpd64.exe @@ -60,7 +61,7 @@ volatile unsigned long _millis; // for millis tick !! Overflow every ~49.7 days //*********Program metrics const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции -const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.1 Static IP TFTP Client && FATFS SDCARD WIZNET_5500 ETHERNET 25/03/2019\r\n"; // Program name +const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.2 Static IP TFTP Client && FATFS SDCARD WIZNET_5500 ETHERNET 27/03/2019\r\n"; // Program name #if defined(__AVR_ATmega128__) const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128 @@ -565,9 +566,10 @@ int main() printf("\r\n########## SW1 was pressed.\r\n"); memset(tftp_filename, 0x0, 20); - //strncpy(tftp_filename, "test.txt", TFTP_FILE_NAME_SIZE); - strncpy(tftp_filename, "README.md", TFTP_FILE_NAME_SIZE); + strncpy(tftp_filename, "test.txt", TFTP_FILE_NAME_SIZE); + //strncpy(tftp_filename, "README.md", TFTP_FILE_NAME_SIZE); //strncpy(tftp_filename, "tftpd32.ini", TFTP_FILE_NAME_SIZE); + //strncpy(tftp_filename, "ff_lfn_required.c", TFTP_FILE_NAME_SIZE); tftp_server = ((uint32_t)tftp_destip[0] << 24) | ((uint32_t)tftp_destip[1] << 16) | ((uint32_t)tftp_destip[2] << 8) | ((uint32_t)tftp_destip[3]); @@ -577,23 +579,34 @@ int main() TFTP_read_request(tftp_server, tftp_filename); + clear_tftp_received_size(); uint8_t _ret = 0; - //while(1) { - uint8_t i = 3; - while(i--){ + while(1){ wdt_reset(); _ret = TFTP_run(); if(_ret != TFTP_PROGRESS) + { + //Print-out result TFTP complete + if(_ret == TFTP_SUCCESS) + { + PRINTF("\r\n++TFTP transfer complete:[%u] SUCCESS, received %lu bytes\r\n", _ret, get_tftp_received_size()); + } + else if(_ret == TFTP_FAIL) + { + PRINTF("\r\n--TFTP transfer complete:[%u] FAIL, received %lu bytes\r\n", _ret, get_tftp_received_size()); + } + else + { + PRINTF("\r\n??TFTP transfer complete:[%u] UNKNOWN, received %lu bytes\r\n\r\n", _ret, get_tftp_received_size()); + } break; - //_delay_ms(1);//Just for debug + } } _delay_ms(1000); //!! Debug only //PRINTF("SW1 is pressed\r\n"); - - }//if(prev_sw1) prev_sw1 = 0; // Store SW1 state for next iteration }//if(!sw1_read())