First positive steps in TFTP client working..
This commit is contained in:
@@ -26,7 +26,16 @@ void save_data(uint8_t *data, uint32_t data_len, uint16_t block_number)
|
|||||||
//Nothing to do with received data yet..
|
//Nothing to do with received data yet..
|
||||||
//TODO: Add your own handler here
|
//TODO: Add your own handler here
|
||||||
//Print out data as string
|
//Print out data as string
|
||||||
PRINTF("Data #%d-%lu:\r\n%s\r\n", block_number, data_len, data);
|
/*
|
||||||
|
uint8_t _tmp_msg[256] = "\0";
|
||||||
|
memset(_tmp_msg, 0x0, 256);
|
||||||
|
strncpy(_tmp_msg, data, data_len);
|
||||||
|
*/
|
||||||
|
uint8_t * str;
|
||||||
|
str = data;
|
||||||
|
str += data_len;
|
||||||
|
*str = 0x0;
|
||||||
|
PRINTF("++Data #%d-%lu:\r\n%s\r\n", block_number, data_len, data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -537,7 +546,7 @@ static void recv_tftp_packet(uint8_t *packet, uint32_t packet_len, uint32_t from
|
|||||||
if(from_ip != get_server_ip()) {
|
if(from_ip != get_server_ip()) {
|
||||||
#ifdef __TFTP_DEBUG__
|
#ifdef __TFTP_DEBUG__
|
||||||
DBG_PRINT(ERROR_DBG, "[%s] Server IP faults\r\n", __func__);
|
DBG_PRINT(ERROR_DBG, "[%s] Server IP faults\r\n", __func__);
|
||||||
DBG_PRINT(ERROR_DBG, "from IP : %08x, Server IP : %08x\r\n", from_ip, get_server_ip());
|
DBG_PRINT(ERROR_DBG, "from IP : 0x%08lX, Server IP : 0x%08lX\r\n", from_ip, get_server_ip());
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -548,7 +557,7 @@ static void recv_tftp_packet(uint8_t *packet, uint32_t packet_len, uint32_t from
|
|||||||
if((get_tftp_state() == STATE_WRQ) || (get_tftp_state() == STATE_RRQ)) {
|
if((get_tftp_state() == STATE_WRQ) || (get_tftp_state() == STATE_RRQ)) {
|
||||||
set_server_port(from_port);
|
set_server_port(from_port);
|
||||||
#ifdef __TFTP_DEBUG__
|
#ifdef __TFTP_DEBUG__
|
||||||
DBG_PRINT(INFO_DBG, "[%s] Set Server Port : %d\r\n", __func__, from_port);
|
DBG_PRINT(INFO_DBG, "[%s] Set Server Port : %u\r\n", __func__, from_port);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,7 +583,7 @@ static void recv_tftp_packet(uint8_t *packet, uint32_t packet_len, uint32_t from
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
// Unknown Mesage
|
// Unknown Message
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -654,7 +663,7 @@ void TFTP_read_request(uint32_t server_ip, uint8_t *filename)
|
|||||||
{
|
{
|
||||||
set_server_ip(server_ip);
|
set_server_ip(server_ip);
|
||||||
#ifdef __TFTP_DEBUG__
|
#ifdef __TFTP_DEBUG__
|
||||||
DBG_PRINT(INFO_DBG, "[%s] Set Tftp Server : %x\r\n", __func__, server_ip);
|
DBG_PRINT(INFO_DBG, "[%s] Set Tftp Server : 0x%lx\r\n", __func__, server_ip);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_progress_state = TFTP_PROGRESS;
|
g_progress_state = TFTP_PROGRESS;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "../../globals.h"
|
#include "../../globals.h"
|
||||||
|
|
||||||
#define F_APP_TFTP
|
#define F_APP_TFTP
|
||||||
|
|||||||
@@ -1,3 +1,18 @@
|
|||||||
########## SW1 was pressed.
|
########## SW1 was pressed.
|
||||||
TFTP IP address : 192.168.0.100
|
TFTP IP address : 192.168.0.100
|
||||||
TFTP IP address (32 bit) : 3232235620
|
TFTP IP address (32 bit) : 0xC0A80064
|
||||||
|
[TFTP_read_request] Set Tftp Server : 0xc0a80064
|
||||||
|
>> TFTP RRQ : FileName(test.txt), Mode(octet)
|
||||||
|
[recv_tftp_packet] Set Server Port : 49769
|
||||||
|
<< 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!
|
||||||
|
#3 It works!
|
||||||
|
#4 New string for test..
|
||||||
|
#5 Bumped :))
|
||||||
|
|
||||||
|
|
||||||
|
>> TFTP ACK : Block Number(1)
|
||||||
|
|||||||
@@ -5,9 +5,16 @@
|
|||||||
* Author: maxx
|
* Author: maxx
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* 21.TODO: Example TFTP client + SD card FATFS (for reading and saving a file from PC TFTP server).
|
* 21.Example TFTP client + SD card FATFS (for reading and saving a file from PC TFTP server).
|
||||||
** After pressing the SW1 button, it reads the “readme.txt” file from the PC TFTP server and saves it on the SD card.
|
** After pressing the SW1 button, it reads the “readme.txt” file from the PC TFTP server and saves it on the SD card.
|
||||||
* Then prints out it contents head in a serial terminal.
|
* 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).
|
||||||
|
* 3. Write-in data to SD-card file "readme_txt".
|
||||||
|
*
|
||||||
|
* Remark:
|
||||||
|
* Checked with PC tftp-server (WIN7) - tftpd64.exe
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
@@ -53,7 +60,7 @@ volatile unsigned long _millis; // for millis tick !! Overflow every ~49.7 days
|
|||||||
//*********Program metrics
|
//*********Program metrics
|
||||||
const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции
|
const char compile_date[] PROGMEM = __DATE__; // Mmm dd yyyy - Дата компиляции
|
||||||
const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции
|
const char compile_time[] PROGMEM = __TIME__; // hh:mm:ss - Время компиляции
|
||||||
const char str_prog_name[] PROGMEM = "\r\nAtMega1284p v1.0 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.1 Static IP TFTP Client && FATFS SDCARD WIZNET_5500 ETHERNET 25/03/2019\r\n"; // Program name
|
||||||
|
|
||||||
#if defined(__AVR_ATmega128__)
|
#if defined(__AVR_ATmega128__)
|
||||||
const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128
|
const char PROGMEM str_mcu[] = "ATmega128"; //CPU is m128
|
||||||
@@ -96,19 +103,19 @@ int freeRam (void)
|
|||||||
//ISR (TIMER0_COMP_vect )
|
//ISR (TIMER0_COMP_vect )
|
||||||
ISR (TIMER0_COMPA_vect)
|
ISR (TIMER0_COMPA_vect)
|
||||||
{
|
{
|
||||||
static uint8_t fatfs_10ms;
|
static uint16_t tftp_1sec;
|
||||||
// Compare match Timer0
|
// Compare match Timer0
|
||||||
// Here every 1ms
|
// Here every 1ms
|
||||||
_millis++; // INC millis tick
|
_millis++; // INC millis tick
|
||||||
// Тест мигаем при в ходе в прерывание
|
// Тест мигаем при в ходе в прерывание
|
||||||
// 500Hz FREQ OUT
|
// 500Hz FREQ OUT
|
||||||
// LED_TGL;
|
// LED_TGL;
|
||||||
if(++fatfs_10ms > 9 )
|
if(++tftp_1sec > 999)
|
||||||
{
|
{
|
||||||
//Here every 10ms
|
//Here every 1 sec
|
||||||
fatfs_10ms = 0;
|
tftp_1sec = 0;
|
||||||
//Timer++; /* Performance counter for this module (for FatFS test) */
|
//TFTP time handler
|
||||||
disk_timerproc(); // FAT FS timing func
|
tftp_timeout_handler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,8 +216,8 @@ uint16_t adc_read(uint8_t channel)
|
|||||||
|
|
||||||
|
|
||||||
//***************** TFTP client INIT: BEGIN
|
//***************** TFTP client INIT: BEGIN
|
||||||
uint8_t g_socket_rcv_buf[MAX_MTU_SIZE];
|
uint8_t g_tftp_socket_rcv_buf[MAX_MTU_SIZE];
|
||||||
uint8_t g_op_mode = NORMAL_MODE;
|
uint8_t g_tftp_op_mode = NORMAL_MODE;
|
||||||
uint8_t tftp_filename[50];
|
uint8_t tftp_filename[50];
|
||||||
uint32_t tftp_server;
|
uint32_t tftp_server;
|
||||||
//***************** TFTP client INIT: END
|
//***************** TFTP client INIT: END
|
||||||
@@ -517,7 +524,7 @@ int main()
|
|||||||
print_network_information();
|
print_network_information();
|
||||||
|
|
||||||
//TFTP init
|
//TFTP init
|
||||||
TFTP_init(SOCK_TFTP, g_socket_rcv_buf);
|
TFTP_init(SOCK_TFTP, g_tftp_socket_rcv_buf);
|
||||||
|
|
||||||
|
|
||||||
/* Loopback Test: TCP Server and UDP */
|
/* Loopback Test: TCP Server and UDP */
|
||||||
@@ -532,8 +539,10 @@ int main()
|
|||||||
/*
|
/*
|
||||||
* https://www.hw-group.com/software/hercules-setup-utility
|
* https://www.hw-group.com/software/hercules-setup-utility
|
||||||
* */
|
* */
|
||||||
|
/*
|
||||||
loopback_tcps(SOCK_TCPS,ethBuf0,PORT_TCPS);
|
loopback_tcps(SOCK_TCPS,ethBuf0,PORT_TCPS);
|
||||||
loopback_udps(SOCK_UDPS,ethBuf0,PORT_UDPS);
|
loopback_udps(SOCK_UDPS,ethBuf0,PORT_UDPS);
|
||||||
|
*/
|
||||||
|
|
||||||
//loopback_ret = loopback_tcpc(SOCK_TCPS, gDATABUF, destip, destport);
|
//loopback_ret = loopback_tcpc(SOCK_TCPS, gDATABUF, destip, destport);
|
||||||
//if(loopback_ret < 0) printf("loopback ret: %ld\r\n", loopback_ret); // TCP Socket Error code
|
//if(loopback_ret < 0) printf("loopback ret: %ld\r\n", loopback_ret); // TCP Socket Error code
|
||||||
@@ -557,25 +566,31 @@ int main()
|
|||||||
printf("\r\n########## SW1 was pressed.\r\n");
|
printf("\r\n########## SW1 was pressed.\r\n");
|
||||||
//strncpy(tftp_filename, 0x00, 50);
|
//strncpy(tftp_filename, 0x00, 50);
|
||||||
memset(tftp_filename, 0x0, 50);
|
memset(tftp_filename, 0x0, 50);
|
||||||
strncpy(tftp_filename, "test.txt", 8);
|
//strncpy(tftp_filename, "test.txt", 8);
|
||||||
|
//strncpy(tftp_filename, "README.md", 9);
|
||||||
|
strncpy(tftp_filename, "tftpd32.ini", 11);
|
||||||
|
|
||||||
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]);
|
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]);
|
||||||
|
|
||||||
PRINTF("TFTP IP address : %d.%d.%d.%d\r\n",tftp_destip[0],tftp_destip[1],tftp_destip[2],tftp_destip[3]);
|
PRINTF("TFTP IP address : %d.%d.%d.%d\r\n",tftp_destip[0],tftp_destip[1],tftp_destip[2],tftp_destip[3]);
|
||||||
PRINTF("TFTP IP address (32 bit) : %lu\r\n",tftp_server);
|
PRINTF("TFTP IP address (32 bit) : 0x%lX\r\n",tftp_server);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
TFTP_read_request(tftp_server, tftp_filename);
|
TFTP_read_request(tftp_server, tftp_filename);
|
||||||
|
|
||||||
uint8_t _ret = 0;
|
uint8_t _ret = 0;
|
||||||
while(1) {
|
//while(1) {
|
||||||
|
uint8_t i = 3;
|
||||||
|
while(i--){
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
_ret = TFTP_run();
|
_ret = TFTP_run();
|
||||||
if(_ret != TFTP_PROGRESS)
|
if(_ret != TFTP_PROGRESS)
|
||||||
break;
|
break;
|
||||||
|
_delay_ms(1);//Just for debug
|
||||||
}
|
}
|
||||||
*/
|
_delay_ms(1000);//Just for debug
|
||||||
|
|
||||||
//!! Debug only
|
//!! Debug only
|
||||||
//PRINTF("SW1 is pressed\r\nADC0/PA0 is: %u\r\n", adc_read(0));
|
//PRINTF("SW1 is pressed\r\nADC0/PA0 is: %u\r\n", adc_read(0));
|
||||||
//PRINTF("SW1 is pressed\r\n");
|
//PRINTF("SW1 is pressed\r\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user