diff --git a/APP_Framework/Applications/app_test/Kconfig b/APP_Framework/Applications/app_test/Kconfig index c5e5894cd..68eab6176 100644 --- a/APP_Framework/Applications/app_test/Kconfig +++ b/APP_Framework/Applications/app_test/Kconfig @@ -1,10 +1,10 @@ menu "test app" - menuconfig USER_TEST + config USER_TEST bool "Enable application test function " - default n + default y if USER_TEST - menuconfig USER_TEST_ADC + config USER_TEST_ADC bool "Config test adc" default n if USER_TEST_ADC @@ -15,7 +15,7 @@ menu "test app" endif endif - menuconfig USER_TEST_DAC + config USER_TEST_DAC bool "Config test dac" default n if USER_TEST_DAC @@ -26,7 +26,7 @@ menu "test app" endif endif - menuconfig USER_TEST_FS + config USER_TEST_FS bool "Config test fs with sd or usb" default n if USER_TEST_FS @@ -38,7 +38,7 @@ menu "test app" endif - menuconfig USER_TEST_GPIO + config USER_TEST_GPIO select BSP_USING_GPIO select RESOURCES_PIN select BSP_USING_LED @@ -53,7 +53,7 @@ menu "test app" endif endif - menuconfig USER_TEST_LORA + config USER_TEST_LORA select BSP_USING_UART select BSP_USING_GPIO select RESOURCES_PIN @@ -72,7 +72,7 @@ menu "test app" endif endif - menuconfig USER_TEST_RS485 + config USER_TEST_RS485 select BSP_USING_UART select BSP_USING_GPIO select RESOURCES_PIN @@ -90,7 +90,7 @@ menu "test app" endif endif - menuconfig USER_TEST_RTC + config USER_TEST_RTC select BSP_USING_RTC bool "Config test rtc" default n @@ -102,7 +102,7 @@ menu "test app" endif endif - menuconfig USER_TEST_HWTIMER + config USER_TEST_HWTIMER select BSP_USING_HWTIMER select BSP_USING_GPIO select RESOURCES_PIN @@ -120,7 +120,7 @@ menu "test app" endif endif - menuconfig USER_TEST_WDT + config USER_TEST_WDT select BSP_USING_WDT0 bool "Config test watchdog" default n @@ -132,7 +132,7 @@ menu "test app" endif endif - menuconfig USER_TEST_LCD_EDU + config USER_TEST_LCD_EDU select BSP_USING_LCD bool "Config test lcd in PrivOpen" default n @@ -144,7 +144,7 @@ menu "test app" endif endif - menuconfig USER_TEST_TOUCH + config USER_TEST_TOUCH select BSP_USING_TOUCH bool "Config test touch" default n @@ -159,7 +159,7 @@ menu "test app" endif endif - menuconfig USER_TEST_I2C + config USER_TEST_I2C select BSP_USING_I2C bool "Config test i2c" default n @@ -171,7 +171,7 @@ menu "test app" endif endif - menuconfig USER_TEST_CAN + config USER_TEST_CAN select BSP_USING_CAN bool "Config test can" default n @@ -183,7 +183,7 @@ menu "test app" endif endif - menuconfig USER_TEST_CAMERA + config USER_TEST_CAMERA select BSP_USING_CAMERA select BSP_USING_LCD bool "Config test camera with lcd" @@ -207,9 +207,9 @@ menu "test app" bool "Config test lcd device" default n - menuconfig USER_TEST_ETHERNET + config USER_TEST_ETHERNET bool "Config test ethernet only for edu-riscv64" - default n + default y if USER_TEST_ETHERNET if ADD_XIZI_FEATURES choice @@ -225,7 +225,7 @@ menu "test app" endif endif - menuconfig USER_TEST_FLASH + config USER_TEST_FLASH bool "Config test w25q128 device" default n if USER_TEST_FLASH @@ -236,47 +236,47 @@ menu "test app" endif endif - menuconfig USER_TEST_TIMER + config USER_TEST_TIMER bool "Config test soft timer" default n - menuconfig USER_TEST_HASH + config USER_TEST_HASH bool "Config test hash" default n - menuconfig USER_TEST_RADIX + config USER_TEST_RADIX bool "Config test radix tree" default n - menuconfig USER_TEST_RBTREE + config USER_TEST_RBTREE bool "Config test red black tree" default n - menuconfig USER_TEST_WEBSERVER + config USER_TEST_WEBSERVER bool "Config test webserver" default n - menuconfig USER_TEST_MQTTCLIENT + config USER_TEST_MQTTCLIENT bool "Config test mqtt client" default n - menuconfig USER_TEST_FTPCLIENT + config USER_TEST_FTPCLIENT bool "Config test ftp client" - default n + default y - menuconfig USER_TEST_LORA_P2P + config USER_TEST_LORA_P2P bool "Config test lora p2p" default n - menuconfig USER_TEST_LORAWAN_SINGLEGW + config USER_TEST_LORAWAN_SINGLEGW bool "Config test lorawan single channel gateway" default n - menuconfig USER_TEST_CANOPEN + config USER_TEST_CANOPEN bool "Config test CanOpen" default n - menuconfig USER_TEST_USB_CAMERA + config USER_TEST_USB_CAMERA bool "Config test usb camera" default n diff --git a/APP_Framework/Applications/app_test/Makefile b/APP_Framework/Applications/app_test/Makefile index 6016dcb7a..9cd620d12 100644 --- a/APP_Framework/Applications/app_test/Makefile +++ b/APP_Framework/Applications/app_test/Makefile @@ -122,7 +122,7 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y) endif ifeq ($(CONFIG_USER_TEST_FTPCLIENT),y) - SRC_FILES += + SRC_FILES += test_ftp/test_ftp.c endif ifeq ($(CONFIG_USER_TEST_LORA_P2P),y) @@ -137,9 +137,5 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y) SRC_FILES += endif - ifeq ($(CONFIG_USER_TEST_USB_CAMERA),y) - SRC_FILES += - endif - include $(KERNEL_ROOT)/compiler.mk endif diff --git a/APP_Framework/Applications/app_test/test_ftp/img/01.png b/APP_Framework/Applications/app_test/test_ftp/img/01.png new file mode 100644 index 000000000..ecf8ae8e6 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/01.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/02.png b/APP_Framework/Applications/app_test/test_ftp/img/02.png new file mode 100644 index 000000000..1c99e096a Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/02.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/03.png b/APP_Framework/Applications/app_test/test_ftp/img/03.png new file mode 100644 index 000000000..28c7339df Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/03.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/04.png b/APP_Framework/Applications/app_test/test_ftp/img/04.png new file mode 100644 index 000000000..f45b3588f Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/04.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/05.png b/APP_Framework/Applications/app_test/test_ftp/img/05.png new file mode 100644 index 000000000..9c3f3e064 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/05.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/06.png b/APP_Framework/Applications/app_test/test_ftp/img/06.png new file mode 100644 index 000000000..0b04f45c1 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/06.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/07.png b/APP_Framework/Applications/app_test/test_ftp/img/07.png new file mode 100644 index 000000000..26d9ef32c Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/07.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/08.png b/APP_Framework/Applications/app_test/test_ftp/img/08.png new file mode 100644 index 000000000..49bd8a3e3 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/08.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/09.png b/APP_Framework/Applications/app_test/test_ftp/img/09.png new file mode 100644 index 000000000..60f289d79 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/09.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/img/10.png b/APP_Framework/Applications/app_test/test_ftp/img/10.png new file mode 100644 index 000000000..e56ec0712 Binary files /dev/null and b/APP_Framework/Applications/app_test/test_ftp/img/10.png differ diff --git a/APP_Framework/Applications/app_test/test_ftp/readme.md b/APP_Framework/Applications/app_test/test_ftp/readme.md new file mode 100644 index 000000000..2a3484806 --- /dev/null +++ b/APP_Framework/Applications/app_test/test_ftp/readme.md @@ -0,0 +1,43 @@ +# 基于矽璓已实现的Lwip,在Riscv上实现FTP协议的Client功能 # + +## 1. 简介 +利用w5500网络编程的api实现了ftp客户端的功能,具体功能包括向ftp服务器发送指定命令,根据用户名登陆ftp服务器,获取文件大小,下载指定文件并保存至sd卡内,并提供了测试函数模拟从ftp服务器山下载10个4KB文件的过程 + +## 2. 数据结构设计说明 +全局变量: +char sendBuffer[]:输出缓冲区 +char recvBuffer[]:输入缓冲区 + +包括以下函数功能,分别为: +`SendCommand`:发送指定的指令 +`EnterPasv`:进入被动模式 +`Login`:根据用户名登陆ftp服务器 +`GetFileSize`:获取指定文件的大小 +`Download`:下载指定文件 + + +## 3. 测试程序说明 +测试了创建套接字,与服务器建立连接并根据传入的用户名和密码发送登陆指令。登陆成功后下载服务器上指定的10个4KB大小的txt文件,然后调用开发板的相关api在系统根目录中创建对应的文件,写入从服务器接收到的数据。 + +## 4. 运行结果(##需结合运行测试截图按步骤说明##) +![image](img/01.png) +![image](img/02.png) +打开menuconfig之后,将test_ftp开启(y),将Using TFcard device 和 Using W5500 as network device 开启(y)保存后退出 + +![image](img/03.png) +编译XiZi-cortex-m3-emulator.elf成功 + +![image](img/04.png) +启动kflash烧录bin文件,按reset键重置成功进入系统并显示SD卡已挂载 + +![image](img/05.png) +执行TestTfp命令,可以看到成功登陆ftp服务器,并开始下载10个大小为4KB的文件。 + +![image](img/06.png) +服务器日志信息 + +![image](img/07.png) +读取sd卡中的文件可以看到10个大小为4KB的文件被成功下载 +![image](img/08.png) +![image](img/09.png) +![image](img/10.png) \ No newline at end of file diff --git a/APP_Framework/Applications/app_test/test_ftp/test_ftp.c b/APP_Framework/Applications/app_test/test_ftp/test_ftp.c new file mode 100644 index 000000000..a1e0aa572 --- /dev/null +++ b/APP_Framework/Applications/app_test/test_ftp/test_ftp.c @@ -0,0 +1,243 @@ +/* +* Copyright (c) 2020 AIIT Ubiquitous Team +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL +v2. +* You may obtain a copy of Mulan PSL v2 at: +* +http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +#include +#include +#include +#include +#define SOCKET_DATA 2 +#define SOCKET_CMD 3 +char sendBuffer[1024]; +char recvBuffer[1024]; + +int SendCommand(char *cmd) +{ + int ret; + ret = wiz_sock_send(SOCKET_CMD,cmd,(int)strlen(cmd)); + if(ret < 0 ){ + return 0; + } + return 1; +} +int RecvRespond(char * respond,int len) +{ + int ret; + int off; + len -= -1; + for(off = 0;off < len;off += ret){ + ret = wiz_sock_recv(SOCKET_CMD,&respond[off],1); + if(ret < 0 ){ + printf("recv respond error\r\n"); + return 0; + } + if(respond[off] == '\n'){ + break; + } + } + respond[off + 1]=0; + return atoi(respond); +} +int EnterPasv(uint8_t *ipaddr,int *port) +{ + int ret; + char *find; + int ip1,ip2,ip3,ip4,tmp1,tmp2; + ret = SendCommand("PASV\r\n"); + if(ret != 1){ + return 0; + } + ret=RecvRespond(recvBuffer,1024); + if(ret != 227){ + return 0; + } + find=strrchr(recvBuffer,'('); + sscanf(find,"(%d,%d,%d,%d,%d,%d)",&ip1,&ip2,&ip3,&ip4,&tmp1,&tmp2); + ipaddr[0] = ip1; + ipaddr[1] = ip2; + ipaddr[2] = ip3; + ipaddr[3] = ip4; + *port = tmp1 * 256 + tmp2; + return 1; +} +int Login(uint8_t addr[4],int port,char *username,char *password) +{ + int ret; + printf("connect....\n"); + ret = wiz_sock_connect(SOCKET_CMD,addr,port); + if(ret != 1){ + printf("connect server failed\r\n"); + return 0; + } + printf("connect ok.\r\n"); + + ret = RecvRespond(recvBuffer,1024); + if(ret != 220){ + printf("bad server ret=%d\r\n",ret); + return 0; + } + printf("login....\r\n"); + sprintf(sendBuffer,"USER %s\r\n",username); + ret = SendCommand(sendBuffer); + + if(ret != 1){ + return 0; + } + ret = RecvRespond(recvBuffer,1024); + if(ret == 220)ret = RecvRespond(recvBuffer,1024); + if(ret != 331){ + return 0; + } + sprintf(sendBuffer,"PASS %s\r\n",password); + ret = SendCommand(sendBuffer); + if(ret != 1){ + return 0; + } + ret = RecvRespond(recvBuffer,1024); + if(ret != 230){ + return 0; + } + printf("login sucess \r\n"); + + + ret = SendCommand("TYPE I\r\n"); + if(ret != 1){ + return 0; + } + ret = RecvRespond(recvBuffer,1024); + if(ret != 200){ + return 0; + } + return 1; +} +int GetFileSize(char * name) +{ + int ret; + int size; + sprintf(sendBuffer,"SIZE %s\r\n",name); + ret = SendCommand(sendBuffer); + if(ret != 1){ + return 0; + } + ret = RecvRespond(recvBuffer,1024); + if(ret != 213){ + printf("get file size failed\r\n"); + return 0; + } + size = atoi(recvBuffer + 4); + return size; +} +int Download(char *name) +{ + wiz_socket(SOCKET_DATA, Sn_MR_TCP,12345,0); + int len = GetFileSize(name); + char *buf = malloc(len+1); + printf("downloading file %s\r\n",name); + int it; + int ret; + uint8_t addr[4]; + int port; + ret = EnterPasv(addr,&port); + + if(ret != 1){ + wiz_sock_disconnect(SOCKET_DATA); + return 0; + } + ret = wiz_sock_connect(SOCKET_DATA,addr,port); + if(ret != 1){ + wiz_sock_disconnect(SOCKET_DATA); + printf("fail to connect data port\r\n"); + return 0; + } + sprintf(sendBuffer,"RETR %s\r\n",name); + ret = SendCommand(sendBuffer); + if(ret != 1){ + wiz_sock_disconnect(SOCKET_DATA); + return 0; + } + ret = RecvRespond(recvBuffer,1024); + if(ret!=150){ + wiz_sock_disconnect(SOCKET_DATA); + return 0; + } + for(it = 0;it < len;it += ret){ + ret = wiz_sock_recv(SOCKET_DATA,((char *)buf + it),len-it); + if(ret<0){ + printf("download was interupted\r\n"); + break; + } + } + buf[len] = 0; + printf("download %d/%d bytes complete. \r\n",it,len); + ret = RecvRespond(recvBuffer,1024); + if(ret != 226){ + wiz_sock_disconnect(SOCKET_DATA); + return 0; + } + wiz_sock_disconnect(SOCKET_DATA); + + printf("creating file %s ....\r\n",name); + int fd=open(name,O_RDWR | O_CREAT); + if(fd > 0){ + ret = write(fd,buf,strlen(buf)); + if(ret < 0 ){ + printf("write failed\r\n"); + } + else printf("success!\r\n"); + close(fd); + } + else { + printf("create file %s failed\r\n",name); + } + if(buf != NULL){ + free(buf); + } + return 1; +} +void Init() +{ + + wiz_socket(SOCKET_CMD, Sn_MR_TCP,54321,0); + printf("socket created\n"); +} +void Quit() +{ + wiz_sock_disconnect(SOCKET_CMD); +} +int TestFtp() +{ + + Init(); + + uint8_t ip[4] = {192,168,130,70}; + Login(ip,21,"frank","114514"); + + Download("File0.txt"); + Download("File1.txt"); + Download("File2.txt"); + Download("File3.txt"); + Download("File4.txt"); + Download("File5.txt"); + Download("File6.txt"); + Download("File7.txt"); + Download("File8.txt"); + Download("File9.txt"); + + Quit(); + + return 0; +} +PRIV_SHELL_CMD_FUNCTION(TestFtp, Implement ftp, PRIV_SHELL_CMD_MAIN_ATTR); + +// make BOARD=edu-riscv64 +// sudo kflash -t build/XiZi-edu-riscv64.bin -p /dev/ttyUSB0 \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/edu-riscv64/README.md b/Ubiquitous/XiZi_IIoT/board/edu-riscv64/README.md index f29654841..faa57feea 100644 --- a/Ubiquitous/XiZi_IIoT/board/edu-riscv64/README.md +++ b/Ubiquitous/XiZi_IIoT/board/edu-riscv64/README.md @@ -185,3 +185,4 @@ sudo kflash -t build/XiZi-edu-riscv64.bin -p /dev/ttyUSB0 如果编译 & 烧写无误,将会在串口终端上看到信息打印输出。 ![terminal](img/terminal.png) + \ No newline at end of file diff --git a/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Kconfig b/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Kconfig index 67bf8db13..45bdc5957 100755 --- a/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Kconfig +++ b/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/Kconfig @@ -18,7 +18,7 @@ menuconfig BSP_USING_SPI menuconfig BSP_USING_SOFT_SPI bool "Using TFcard device" - default n + default y select BSP_USING_SPI select MOUNT_SDCARD select RESOURCES_SPI_SD @@ -115,7 +115,7 @@ menuconfig BSP_USING_WDT menuconfig BSP_USING_WIZCHIP bool "Using w5500 as network device" - default n + default y select RESOURCES_WIZCHIP select BSP_USING_SPI if BSP_USING_WIZCHIP diff --git a/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Kconfig b/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Kconfig index f7f10a646..4f1b364af 100644 --- a/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Kconfig +++ b/Ubiquitous/XiZi_IIoT/board/edu-riscv64/third_party_driver/dvp/Kconfig @@ -29,7 +29,7 @@ if BSP_USING_CAMERA default "camera_drv" config CAMERA_DEVICE_NAME string "camera device name" - default "camera_dev" + default "video0" choice prompt "set camera framesize and fps"