forked from xuos/xiuos
				
			23/07/12 Add W5500 iperf; Add lwip http test.
This commit is contained in:
		
							parent
							
								
									d7aa29e0df
								
							
						
					
					
						commit
						edd5a5ccb9
					
				| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c
 | 
					SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c wiz_iperf.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@ uint32_t get_gbuf_size() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wiz_NetInfo *get_gnetinfo() {
 | 
					wiz_NetInfo *get_gnetinfo() {
 | 
				
			||||||
  static wiz_NetInfo g_wiz_netinfo = {.mac = {0x00, 0x08, 0xdc, 0x11, 0x11, 0x11},
 | 
					  static wiz_NetInfo g_wiz_netinfo = {.mac = {0x00, 0x08, 0xdc, 0x11, 0x11, 0x11},
 | 
				
			||||||
                                      .ip = {192, 168, 131, 42},
 | 
					                                      .ip = {192, 168, 130, 77},
 | 
				
			||||||
                                      .sn = {255, 255, 254, 0},
 | 
					                                      .sn = {255, 255, 254, 0},
 | 
				
			||||||
                                      .gw = {192, 168, 130, 1},
 | 
					                                      .gw = {192, 168, 130, 1},
 | 
				
			||||||
                                      .dns = {0, 0, 0, 0},
 | 
					                                      .dns = {0, 0, 0, 0},
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,462 @@
 | 
				
			||||||
 | 
					#include "socket.h"
 | 
				
			||||||
 | 
					#include "w5500.h"
 | 
				
			||||||
 | 
					#include "connect_w5500.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define IPERF_PORT          5001
 | 
				
			||||||
 | 
					#define IPERF_BUFSZ         (4 * 1024)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define IPERF_MODE_STOP     0
 | 
				
			||||||
 | 
					#define IPERF_MODE_SERVER   1
 | 
				
			||||||
 | 
					#define IPERF_MODE_CLIENT   2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct{
 | 
				
			||||||
 | 
					    int mode;
 | 
				
			||||||
 | 
					    uint8 host[4];
 | 
				
			||||||
 | 
					    uint16 port;
 | 
				
			||||||
 | 
					} IPERF_PARAM;
 | 
				
			||||||
 | 
					static IPERF_PARAM param = {IPERF_MODE_STOP, {0, 0, 0, 0}, IPERF_PORT};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void iperf_udp_client(void *thread_param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int sock;
 | 
				
			||||||
 | 
					    uint8 *buffer;
 | 
				
			||||||
 | 
					    uint16 local_port = 4840;
 | 
				
			||||||
 | 
					    uint32 packet_count = 0;
 | 
				
			||||||
 | 
					    uint32 tick;
 | 
				
			||||||
 | 
					    int send_size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    send_size = IPERF_BUFSZ > 1470 ? 1470 : IPERF_BUFSZ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sock = 0;   // w5500支持8个socket独立工作,todo socket端口管理
 | 
				
			||||||
 | 
					    // setSn_TXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					    // setSn_RXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    buffer = malloc(IPERF_BUFSZ);
 | 
				
			||||||
 | 
					    if (buffer == NULL){
 | 
				
			||||||
 | 
					        printf("[%s:%d] malloc failed\n", __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    for(int i = 0; i < IPERF_BUFSZ; i++)
 | 
				
			||||||
 | 
					        buffer[i] = i % 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    KPrintf("iperf udp mode run...\n");
 | 
				
			||||||
 | 
					    while (param.mode != IPERF_MODE_STOP){
 | 
				
			||||||
 | 
					        switch(getSn_SR(sock)){
 | 
				
			||||||
 | 
					            case SOCK_CLOSED:
 | 
				
			||||||
 | 
					                wiz_socket(sock, Sn_MR_UDP, local_port, 0x00);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            case SOCK_UDP:
 | 
				
			||||||
 | 
					                packet_count++;
 | 
				
			||||||
 | 
					                tick = CurrentTicksGain();
 | 
				
			||||||
 | 
					                buffer[0] = (uint8)(packet_count >> 24);
 | 
				
			||||||
 | 
					                buffer[1] = (uint8)(packet_count >> 16);
 | 
				
			||||||
 | 
					                buffer[2] = (uint8)(packet_count >> 8);
 | 
				
			||||||
 | 
					                buffer[3] = (uint8)(packet_count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                buffer[4] = (uint8)((tick / TICK_PER_SECOND) >> 24);
 | 
				
			||||||
 | 
					                buffer[5] = (uint8)((tick / TICK_PER_SECOND) >> 16);
 | 
				
			||||||
 | 
					                buffer[6] = (uint8)((tick / TICK_PER_SECOND) >> 8);
 | 
				
			||||||
 | 
					                buffer[7] = (uint8)((tick / TICK_PER_SECOND));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                buffer[8] = (uint8)(((tick % TICK_PER_SECOND) * 1000) >> 24);
 | 
				
			||||||
 | 
					                buffer[9] = (uint8)(((tick % TICK_PER_SECOND) * 1000) >> 16);
 | 
				
			||||||
 | 
					                buffer[10] = (uint8)(((tick % TICK_PER_SECOND) * 1000) >> 8);
 | 
				
			||||||
 | 
					                buffer[11] = (uint8)(((tick % TICK_PER_SECOND) * 1000));
 | 
				
			||||||
 | 
					                wiz_sock_sendto(sock, buffer, send_size, param.host, param.port);
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if(getSn_SR(sock) != SOCK_CLOSED) wiz_sock_close(sock);
 | 
				
			||||||
 | 
					    free(buffer);
 | 
				
			||||||
 | 
					    KPrintf("iperf udp mode exit...\n");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void iperf_udp_server(void *thread_param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int sock, sender_len, r_size;
 | 
				
			||||||
 | 
					    uint8 *buffer, client_addr[4];
 | 
				
			||||||
 | 
					    uint16 client_port;
 | 
				
			||||||
 | 
					    uint32 pcount = 0, last_pcount = 0;
 | 
				
			||||||
 | 
					    uint32 lost, total;
 | 
				
			||||||
 | 
					    uint64 recvlen;
 | 
				
			||||||
 | 
					    x_ticks_t tick1, tick2;
 | 
				
			||||||
 | 
					    struct timeval timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    buffer = malloc(IPERF_BUFSZ);
 | 
				
			||||||
 | 
					    if (buffer == NULL){
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sock = 0; //todo
 | 
				
			||||||
 | 
					    // setSn_RXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					    // setSn_TXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    KPrintf("iperf udp server run...\n");
 | 
				
			||||||
 | 
					    while (param.mode != IPERF_MODE_STOP){
 | 
				
			||||||
 | 
					        tick1 = CurrentTicksGain();
 | 
				
			||||||
 | 
					        tick2 = tick1;
 | 
				
			||||||
 | 
					        lost = 0;
 | 
				
			||||||
 | 
					        total = 0;
 | 
				
			||||||
 | 
					        recvlen = 0;
 | 
				
			||||||
 | 
					        while ((tick2 - tick1) < (TICK_PER_SECOND * 5)){
 | 
				
			||||||
 | 
					            switch(getSn_SR(sock)){
 | 
				
			||||||
 | 
					                case SOCK_UDP:
 | 
				
			||||||
 | 
					                    if ((r_size = getSn_RX_RSR(sock)) > 0){
 | 
				
			||||||
 | 
					                        if (r_size > IPERF_BUFSZ) r_size = IPERF_BUFSZ;
 | 
				
			||||||
 | 
					                        memset(buffer, 0, IPERF_BUFSZ);
 | 
				
			||||||
 | 
					                        wiz_sock_recvfrom(sock, buffer, r_size, client_addr, &client_port);
 | 
				
			||||||
 | 
					                        recvlen += r_size;
 | 
				
			||||||
 | 
					                        last_pcount = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3];
 | 
				
			||||||
 | 
					                        if(last_pcount > pcount){
 | 
				
			||||||
 | 
					                            total += last_pcount - pcount;
 | 
				
			||||||
 | 
					                            lost += last_pcount - pcount - 1;
 | 
				
			||||||
 | 
					                            pcount = last_pcount;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        else if(last_pcount < 10){
 | 
				
			||||||
 | 
					                            pcount = last_pcount;
 | 
				
			||||||
 | 
					                            total = 1;
 | 
				
			||||||
 | 
					                            lost = 0;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    tick2 = CurrentTicksGain();
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                case SOCK_CLOSED:
 | 
				
			||||||
 | 
					                    wiz_socket(sock, Sn_MR_UDP, param.port, 0x00);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (recvlen > 0){
 | 
				
			||||||
 | 
					            long data;
 | 
				
			||||||
 | 
					            int integer, decimal;
 | 
				
			||||||
 | 
					            KTaskDescriptorType tid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            tid = GetKTaskDescriptor();
 | 
				
			||||||
 | 
					            data = recvlen * TICK_PER_SECOND / 125 / (tick2 - tick1);
 | 
				
			||||||
 | 
					            integer = data/1000;
 | 
				
			||||||
 | 
					            decimal = data%1000;
 | 
				
			||||||
 | 
					            KPrintf("%s: %d.%03d0 Mbps! recv:%d lost:%d total:%d\n", tid->task_base_info.name, integer, decimal, total - lost, lost, total);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    free(buffer);
 | 
				
			||||||
 | 
					    if(getSn_SR(sock) != SOCK_CLOSED) wiz_sock_close(sock);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void iperf_client(void *thread_param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int i;
 | 
				
			||||||
 | 
					    int sock = 0;
 | 
				
			||||||
 | 
					    int ret;
 | 
				
			||||||
 | 
					    uint8_t *send_buf, connected = 0;
 | 
				
			||||||
 | 
					    uint64 sentlen;
 | 
				
			||||||
 | 
					    x_ticks_t tick1, tick2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // setSn_RXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					    // setSn_TXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    send_buf = (uint8_t *) malloc(IPERF_BUFSZ);
 | 
				
			||||||
 | 
					    if (!send_buf) return ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (i = 0; i < IPERF_BUFSZ; i ++)
 | 
				
			||||||
 | 
					        send_buf[i] = i & 0xff;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (param.mode != IPERF_MODE_STOP)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        while((getSn_SR(sock) != SOCK_ESTABLISHED || !connected) && param.mode != IPERF_MODE_STOP){
 | 
				
			||||||
 | 
					            switch (getSn_SR(sock)) {
 | 
				
			||||||
 | 
					                case SOCK_ESTABLISHED:
 | 
				
			||||||
 | 
					                    if (getSn_IR(sock) & Sn_IR_CON) {
 | 
				
			||||||
 | 
					                        KPrintf("Connected\n", sock);
 | 
				
			||||||
 | 
					                        setSn_IR(sock, Sn_IR_CON);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    connected = 1;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                case SOCK_CLOSE_WAIT:
 | 
				
			||||||
 | 
					                    wiz_sock_disconnect(sock);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                case SOCK_INIT:
 | 
				
			||||||
 | 
					                    KPrintf("Socket %d:try to connect to [%d.%d.%d.%d:%d]...", 
 | 
				
			||||||
 | 
					                        sock, param.host[0], param.host[1], param.host[2], param.host[3], param.port);
 | 
				
			||||||
 | 
					                    ret = wiz_sock_connect(sock, param.host, param.port);
 | 
				
			||||||
 | 
					                    if (ret != SOCK_OK){
 | 
				
			||||||
 | 
					                        printf("failed, wait 1s to try again\n");
 | 
				
			||||||
 | 
					                        MdelayKTask(1000);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                case SOCK_CLOSED:
 | 
				
			||||||
 | 
					                    if(connected) KPrintf("Socket %d:closed\n", sock);
 | 
				
			||||||
 | 
					                    wiz_socket(sock, Sn_MR_TCP, param.port, 0x00);
 | 
				
			||||||
 | 
					                    connected = 0;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sentlen = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        tick1 = CurrentTicksGain();
 | 
				
			||||||
 | 
					        while (param.mode != IPERF_MODE_STOP){
 | 
				
			||||||
 | 
					            tick2 = CurrentTicksGain();
 | 
				
			||||||
 | 
					            if (tick2 - tick1 >= TICK_PER_SECOND * 5){
 | 
				
			||||||
 | 
					                long data;
 | 
				
			||||||
 | 
					                int integer, decimal;
 | 
				
			||||||
 | 
					                KTaskDescriptorType tid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                tid = GetKTaskDescriptor();
 | 
				
			||||||
 | 
					                data = sentlen * TICK_PER_SECOND / 125 / (tick2 - tick1);
 | 
				
			||||||
 | 
					                integer = data/1000;
 | 
				
			||||||
 | 
					                decimal = data%1000;
 | 
				
			||||||
 | 
					                KPrintf("%s: %d.%03d0 Mbps!\n", tid->task_base_info.name, integer, decimal);
 | 
				
			||||||
 | 
					                tick1 = tick2;
 | 
				
			||||||
 | 
					                sentlen = 0;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            ret = wiz_sock_send(sock, send_buf, IPERF_BUFSZ);
 | 
				
			||||||
 | 
					            if (ret > 0){
 | 
				
			||||||
 | 
					                sentlen += ret;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (ret < 0) break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(getSn_SR(sock) != SOCK_CLOSED)wiz_sock_close(sock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        KPrintf("Disconnected, iperf client exit!");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    free(send_buf);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void iperf_server(void *thread_param)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uint8_t *recv_data;
 | 
				
			||||||
 | 
					    x_ticks_t tick1, tick2;
 | 
				
			||||||
 | 
					    int sock = -1, connected = 0, bytes_received;
 | 
				
			||||||
 | 
					    uint64 recvlen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sock = 0; //todo
 | 
				
			||||||
 | 
					    // setSn_RXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					    // setSn_TXBUF_SIZE(sock, 16);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    recv_data = (uint8_t *)malloc(IPERF_BUFSZ);
 | 
				
			||||||
 | 
					    if (recv_data == NULL){
 | 
				
			||||||
 | 
					        KPrintf("No memory!\n");
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (param.mode != IPERF_MODE_STOP){
 | 
				
			||||||
 | 
					        while((getSn_SR(sock) != SOCK_ESTABLISHED || !connected)){
 | 
				
			||||||
 | 
					            switch (getSn_SR(sock)) {
 | 
				
			||||||
 | 
					                case SOCK_ESTABLISHED:
 | 
				
			||||||
 | 
					                    if (getSn_IR(sock) & Sn_IR_CON) {
 | 
				
			||||||
 | 
					                        KPrintf("Socket %d:Connected\n", sock);
 | 
				
			||||||
 | 
					                        setSn_IR(sock, Sn_IR_CON);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    recvlen = 0;
 | 
				
			||||||
 | 
					                    tick1 = CurrentTicksGain();
 | 
				
			||||||
 | 
					                    connected = 1;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                case SOCK_CLOSE_WAIT:
 | 
				
			||||||
 | 
					                    wiz_sock_disconnect(sock);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                case SOCK_INIT:
 | 
				
			||||||
 | 
					                    KPrintf("Socket %d:Listen, port [%d]\n", sock, param.port);
 | 
				
			||||||
 | 
					                    wiz_sock_listen(sock);
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                case SOCK_CLOSED:
 | 
				
			||||||
 | 
					                    if(connected) KPrintf("Socket %d:closed\n", sock);
 | 
				
			||||||
 | 
					                    wiz_socket(sock, Sn_MR_TCP, param.port, 0x00);
 | 
				
			||||||
 | 
					                    connected = 0;
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					                default:
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if(param.mode == IPERF_MODE_STOP) goto __exit;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if ((bytes_received = getSn_RX_RSR(sock)) > 0) {
 | 
				
			||||||
 | 
					            if (bytes_received > IPERF_BUFSZ) bytes_received = IPERF_BUFSZ;
 | 
				
			||||||
 | 
					            memset(recv_data, 0, IPERF_BUFSZ);
 | 
				
			||||||
 | 
					            wiz_sock_recv(sock, recv_data, bytes_received);
 | 
				
			||||||
 | 
					            recvlen += bytes_received;
 | 
				
			||||||
 | 
					        }            
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        tick2 = CurrentTicksGain();
 | 
				
			||||||
 | 
					        if (tick2 - tick1 >= TICK_PER_SECOND * 5){
 | 
				
			||||||
 | 
					            long data;
 | 
				
			||||||
 | 
					            int integer, decimal;
 | 
				
			||||||
 | 
					            KTaskDescriptorType tid;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            tid = GetKTaskDescriptor();
 | 
				
			||||||
 | 
					            data = recvlen * TICK_PER_SECOND / 125 / (tick2 - tick1);
 | 
				
			||||||
 | 
					            integer = data/1000;
 | 
				
			||||||
 | 
					            decimal = data%1000;
 | 
				
			||||||
 | 
					            KPrintf("%s: %d.%03d0 Mbps!\n", tid->task_base_info.name, integer, decimal);
 | 
				
			||||||
 | 
					            tick1 = tick2;
 | 
				
			||||||
 | 
					            recvlen = 0;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__exit:
 | 
				
			||||||
 | 
					    if(getSn_SR(sock) != SOCK_CLOSED)wiz_sock_close(sock);
 | 
				
			||||||
 | 
					    if (recv_data) free(recv_data);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void iperf_usage(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    KPrintf("Usage: iperf [-s|-c host] [options] [multi-threaded]\n");
 | 
				
			||||||
 | 
					    KPrintf("       iperf [-h|--stop]\n");
 | 
				
			||||||
 | 
					    KPrintf("\n");
 | 
				
			||||||
 | 
					    KPrintf("Client/Server:\n");
 | 
				
			||||||
 | 
					    KPrintf("  -p #         server port to listen on/connect to\n");
 | 
				
			||||||
 | 
					    KPrintf("\n");
 | 
				
			||||||
 | 
					    KPrintf("Server specific:\n");
 | 
				
			||||||
 | 
					    KPrintf("  -s           run in server mode\n");
 | 
				
			||||||
 | 
					    KPrintf("\n");
 | 
				
			||||||
 | 
					    KPrintf("Client specific:\n");
 | 
				
			||||||
 | 
					    KPrintf("  -c <host>    run in client mode, connecting to <host>\n");
 | 
				
			||||||
 | 
					    KPrintf("\n");
 | 
				
			||||||
 | 
					    KPrintf("Miscellaneous:\n");
 | 
				
			||||||
 | 
					    KPrintf("  -h           print this message and quit\n");
 | 
				
			||||||
 | 
					    KPrintf("  --stop       stop iperf program\n");
 | 
				
			||||||
 | 
					    KPrintf("  -u           testing UDP protocol\n");
 | 
				
			||||||
 | 
					    KPrintf("  -m <time>    the number of multi-threaded \ns");
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int iperf(int argc, char **argv)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    int mode = 0; /* server mode */
 | 
				
			||||||
 | 
					    char *host = NULL;
 | 
				
			||||||
 | 
					    int port = IPERF_PORT;
 | 
				
			||||||
 | 
					    int numtid = 1;
 | 
				
			||||||
 | 
					    int use_udp = 0;
 | 
				
			||||||
 | 
					    int index = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (argc == 1)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        goto __usage;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (strcmp(argv[1], "-u") == 0)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        index = 2;
 | 
				
			||||||
 | 
					        use_udp = 1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (strcmp(argv[index], "-h") == 0) goto __usage;
 | 
				
			||||||
 | 
					    else if (strcmp(argv[index], "--stop") == 0)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        /* stop iperf */
 | 
				
			||||||
 | 
					        param.mode = IPERF_MODE_STOP;
 | 
				
			||||||
 | 
					        MdelayKTask(10);
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else if (strcmp(argv[index], "-s") == 0)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        mode = IPERF_MODE_SERVER; /* server mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* iperf -s -p 5000 */
 | 
				
			||||||
 | 
					        if (argc >= 4)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (strcmp(argv[index + 1], "-p") == 0)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                port = atoi(argv[index + 2]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else goto __usage;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else if (strcmp(argv[index], "-c") == 0)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        mode = IPERF_MODE_CLIENT; /* client mode */
 | 
				
			||||||
 | 
					        if (argc < 3) goto __usage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        host = argv[index + 1];
 | 
				
			||||||
 | 
					        if (argc >= 5)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            /* iperf -c host -p port */
 | 
				
			||||||
 | 
					            if (strcmp(argv[index + 2], "-p") == 0)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                port = atoi(argv[index + 3]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else goto __usage;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else goto __usage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (argc >= 7)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if(strcmp(argv[argc - 2], "-m") == 0)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            numtid = atoi(argv[argc - 1]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else  goto __usage;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* start iperf */
 | 
				
			||||||
 | 
					    if (param.mode == IPERF_MODE_STOP)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        int i = 0;
 | 
				
			||||||
 | 
					        char tid_name[NAME_NUM_MAX + 1] = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        param.mode = mode;
 | 
				
			||||||
 | 
					        param.port = port;
 | 
				
			||||||
 | 
					        if (host) {
 | 
				
			||||||
 | 
					            uint32 t1,t2,t3,t4;
 | 
				
			||||||
 | 
					            sscanf(host, "%d.%d.%d.%d", &t1, &t2, &t3, &t4);
 | 
				
			||||||
 | 
					            param.host[0] = (uint8)t1;
 | 
				
			||||||
 | 
					            param.host[1] = (uint8)t2;
 | 
				
			||||||
 | 
					            param.host[2] = (uint8)t3;
 | 
				
			||||||
 | 
					            param.host[3] = (uint8)t4;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (i = 0; i < numtid; i++)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            int32 tid = 0;
 | 
				
			||||||
 | 
					            void (*function)(void *parameter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (use_udp)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (mode == IPERF_MODE_CLIENT)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfc%02d", i + 1);
 | 
				
			||||||
 | 
					                    function = iperf_udp_client;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else if (mode == IPERF_MODE_SERVER)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfd%02d", i + 1);
 | 
				
			||||||
 | 
					                    function = iperf_udp_server;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                if (mode == IPERF_MODE_CLIENT)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfc%02d", i + 1);
 | 
				
			||||||
 | 
					                    function = iperf_client;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else if (mode == IPERF_MODE_SERVER)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfd%02d", i + 1);
 | 
				
			||||||
 | 
					                    function = iperf_server;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            tid = KTaskCreate(tid_name, function, NULL, 4096, 25);
 | 
				
			||||||
 | 
					            if (tid) StartupKTask(tid);
 | 
				
			||||||
 | 
					            MdelayKTask(10);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        KPrintf("Please stop iperf firstly, by:\n");
 | 
				
			||||||
 | 
					        KPrintf("iperf --stop\n");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__usage:
 | 
				
			||||||
 | 
					    iperf_usage();
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
 | 
				
			||||||
 | 
					                 iperf, iperf,
 | 
				
			||||||
 | 
					                 iperf throughput test);
 | 
				
			||||||
| 
						 | 
					@ -78,6 +78,10 @@ Modification:
 | 
				
			||||||
#include <connect_can.h>
 | 
					#include <connect_can.h>
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef BSP_USING_LWIP
 | 
				
			||||||
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void entry(void);
 | 
					extern void entry(void);
 | 
				
			||||||
extern int HwUsartInit();
 | 
					extern int HwUsartInit();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -209,6 +213,8 @@ struct InitSequenceDesc _board_init[] =
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef BSP_USING_CAN
 | 
					#ifdef BSP_USING_CAN
 | 
				
			||||||
	{ "can", HwCanInit },
 | 
						{ "can", HwCanInit },
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef BSP_USING_LWIP
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    { " NONE ", NONE },
 | 
					    { " NONE ", NONE },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,8 @@
 | 
				
			||||||
#include <lwip/timeouts.h>
 | 
					#include <lwip/timeouts.h>
 | 
				
			||||||
#include <netif/etharp.h>
 | 
					#include <netif/etharp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <sys_arch.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void eth_irq_handler(void) {
 | 
					void eth_irq_handler(void) {
 | 
				
			||||||
    static x_base eth_irq_lock;
 | 
					    static x_base eth_irq_lock;
 | 
				
			||||||
    eth_irq_lock = DISABLE_INTERRUPT();
 | 
					    eth_irq_lock = DISABLE_INTERRUPT();
 | 
				
			||||||
| 
						 | 
					@ -275,5 +277,11 @@ struct pbuf *low_level_input(struct netif *netif)
 | 
				
			||||||
    return p;
 | 
					    return p;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					extern void LwipSetIPTest(int argc, char *argv[]);
 | 
				
			||||||
 | 
					int HwEthInit(void) {
 | 
				
			||||||
 | 
					//   lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
 | 
					  LwipSetIPTest(1, NULL);
 | 
				
			||||||
 | 
					  return EOK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,6 +62,8 @@ int32_t low_level_init(struct netif *netif);
 | 
				
			||||||
err_t low_level_output(struct netif *netif, struct pbuf *p);
 | 
					err_t low_level_output(struct netif *netif, struct pbuf *p);
 | 
				
			||||||
struct pbuf *low_level_input(struct netif *netif);
 | 
					struct pbuf *low_level_input(struct netif *netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int HwEthInit(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
SRC_FILES += lwiperf/lwiperf.c
 | 
					SRC_FILES += lwiperf/lwiperf.c http/http_client.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,7 +64,8 @@
 | 
				
			||||||
 * HTTPC_DEBUG: Enable debugging for HTTP client.
 | 
					 * HTTPC_DEBUG: Enable debugging for HTTP client.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
#ifndef HTTPC_DEBUG
 | 
					#ifndef HTTPC_DEBUG
 | 
				
			||||||
#define HTTPC_DEBUG                 LWIP_DBG_OFF
 | 
					#define HTTPC_DEBUG                 LWIP_DBG_ON
 | 
				
			||||||
 | 
					// #define HTTPC_DEBUG                 LWIP_DBG_OFF
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Set this to 1 to keep server name and uri in request state */
 | 
					/** Set this to 1 to keep server name and uri in request state */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* ---------- Debug options ---------- */
 | 
					/* ---------- Debug options ---------- */
 | 
				
			||||||
#ifndef LWIP_DEBUG
 | 
					#ifndef LWIP_DEBUG
 | 
				
			||||||
#define LWIP_DEBUG 
 | 
					#define LWIP_DEBUG  1
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef LWIP_DEBUG
 | 
					#ifdef LWIP_DEBUG
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -142,19 +142,19 @@
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef LWIP_DEBUG
 | 
					#ifdef LWIP_DEBUG
 | 
				
			||||||
#define LWIP_DEBUG_FLAG 1
 | 
					#define LWIP_DEBUGF(debug_flag, message) do { \
 | 
				
			||||||
#define LWIP_DEBUGF(debug, message) do { \
 | 
					 | 
				
			||||||
                               if ( \
 | 
					                               if ( \
 | 
				
			||||||
                                   ((LWIP_DEBUG_FLAG) & LWIP_DBG_ON) && \
 | 
					                                   ((debug_flag) & LWIP_DBG_ON) && \
 | 
				
			||||||
                                   ((LWIP_DEBUG_FLAG) & LWIP_DBG_TYPES_ON) && \
 | 
					                                   ((debug_flag) & LWIP_DBG_TYPES_ON) && \
 | 
				
			||||||
                                   ((s16_t)((LWIP_DEBUG_FLAG) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \
 | 
					                                   (debug_flag)) { \
 | 
				
			||||||
                                 LWIP_PLATFORM_DIAG(message); \
 | 
					                                 LWIP_PLATFORM_DIAG(message); \
 | 
				
			||||||
                                 if ((LWIP_DEBUG_FLAG) & LWIP_DBG_HALT) { \
 | 
					                                 if ((debug_flag) & LWIP_DBG_HALT) { \
 | 
				
			||||||
                                   while(1); \
 | 
					                                   while(1); \
 | 
				
			||||||
                                 } \
 | 
					                                 } \
 | 
				
			||||||
                               } \
 | 
					                               } \
 | 
				
			||||||
                             } while(0)
 | 
					                             } while(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                  //  ((s16_t)((debug_flag) & LWIP_DBG_MASK_LEVEL) >= LWIP_DBG_MIN_LEVEL)) { \
 | 
				
			||||||
// #define LWIP_DEBUGF(debug, message) do { \
 | 
					// #define LWIP_DEBUGF(debug, message) do { \
 | 
				
			||||||
//                                  LWIP_PLATFORM_DIAG(message); \
 | 
					//                                  LWIP_PLATFORM_DIAG(message); \
 | 
				
			||||||
//                              } while(0)
 | 
					//                              } while(0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c
 | 
					SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c http_test.c
 | 
				
			||||||
# SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c
 | 
					# SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,68 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <shell.h>
 | 
				
			||||||
 | 
					#include <debug.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "lwip/apps/http_client.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void httpc_app_recv_end(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err) {
 | 
				
			||||||
 | 
					    httpc_state_t **req = (httpc_state_t**)arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    LWIP_DEBUGF(LWIP_DEBUG, ("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len));
 | 
				
			||||||
 | 
					    printf("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len);
 | 
				
			||||||
 | 
					    *req = NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_t httpc_app_headers_done(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len) {
 | 
				
			||||||
 | 
					    LWIP_DEBUGF(LWIP_DEBUG, ("[%s] headers done call back.\n", __func__));
 | 
				
			||||||
 | 
					    printf("[%s] headers done call back, content len: %d.\n", __func__, content_len);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					err_t httpc_app_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) {
 | 
				
			||||||
 | 
					    printf("[%s] Get %d Data\n", __func__, p->len);
 | 
				
			||||||
 | 
					   
 | 
				
			||||||
 | 
					    pbuf_free(p);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ip_addr_t *get_server_ip() {
 | 
				
			||||||
 | 
					    static ip_addr_t server_ip;
 | 
				
			||||||
 | 
					    return &server_ip;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					httpc_state_t **get_conn_state() {
 | 
				
			||||||
 | 
					    static httpc_state_t *conn_state;
 | 
				
			||||||
 | 
					    return &conn_state;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					httpc_connection_t *get_conn_setting() {
 | 
				
			||||||
 | 
					    static httpc_connection_t conn_setting;
 | 
				
			||||||
 | 
					    return &conn_setting;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void httpc_get_file_app(int argc, char *argv[]) {
 | 
				
			||||||
 | 
					    // deal input ip
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // get file from server
 | 
				
			||||||
 | 
					    const uint8_t server_ip_by_arr[4] = {39, 156, 66, 10};
 | 
				
			||||||
 | 
					    // const uint8_t server_ip_by_arr[4] = {114, 215, 151, 106};
 | 
				
			||||||
 | 
					    IP4_ADDR(get_server_ip(), 
 | 
				
			||||||
 | 
					        server_ip_by_arr[0], server_ip_by_arr[1], server_ip_by_arr[2], server_ip_by_arr[3]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    get_conn_setting()->use_proxy = 0;
 | 
				
			||||||
 | 
					    get_conn_setting()->result_fn = httpc_app_recv_end;
 | 
				
			||||||
 | 
					    get_conn_setting()->headers_done_fn = httpc_app_headers_done;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    LWIP_DEBUGF(HTTPC_DEBUG, ("[%s] Calling httpc_get_file\n", __func__));
 | 
				
			||||||
 | 
					    printf("[%s] Calling httpc_get_file\n", __func__);
 | 
				
			||||||
 | 
					    err_t errnum = httpc_get_file(get_server_ip(), 80, "/index.html", get_conn_setting(), httpc_app_recv, NULL, get_conn_state());
 | 
				
			||||||
 | 
					    // err_t errnum = httpc_get_file_dns("https://www.baidu.com", 80, "/index.html", get_conn_setting(), httpc_app_recv, NULL, get_conn_state());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (errnum != ERR_OK) {
 | 
				
			||||||
 | 
					        printf("httpc_get_file failed (%d)\n", errnum);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
 | 
				
			||||||
 | 
					     lwip_http_test, httpc_get_file_app, get file from net server);
 | 
				
			||||||
| 
						 | 
					@ -678,8 +678,6 @@ lwiperf_example_init(void)
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(8),
 | 
					 | 
				
			||||||
//     iperf, iperf, netutils iperf);
 | 
					 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(8),
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(8),
 | 
				
			||||||
    iperf, iperf, netutils iperf);
 | 
					    iperf, iperf, netutils iperf);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,7 @@ static void LwipSetIPTask(void *param)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint8_t enet_port = *(uint8_t *)param; ///< test enet port 
 | 
					    uint8_t enet_port = *(uint8_t *)param; ///< test enet port 
 | 
				
			||||||
    printf("lw: [%s] config netport id[%d]\n", __func__, enet_port);
 | 
					    printf("lw: [%s] config netport id[%d]\n", __func__, enet_port);
 | 
				
			||||||
 | 
					    // lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
    lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
					    lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,59 +37,17 @@
 | 
				
			||||||
ip4_addr_t ping_addr;
 | 
					ip4_addr_t ping_addr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/******************************************************************************/
 | 
					/******************************************************************************/
 | 
				
			||||||
 | 
					char arg_ip[20] = {192, 168, 130, 50};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void LwipPingTest(int argc, char *argv[])
 | 
					void LwipPingTest(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int result = 0;
 | 
					    int result = 0;
 | 
				
			||||||
    uint8_t enet_port = 0; ///< test enet port 0
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(argc >= 4)
 | 
					    if (argc == 2) {
 | 
				
			||||||
    {
 | 
					        printf("lw: [%s] ping %s\n", __func__, argv[1]);
 | 
				
			||||||
        printf("lw: [%s] ip %s mask %s gw %s for netport %s\n", __func__, argv[1], argv[2], argv[3], argv[4]);
 | 
					 | 
				
			||||||
        sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
 | 
					 | 
				
			||||||
        sscanf(argv[2], "%d.%d.%d.%d", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
 | 
					 | 
				
			||||||
        sscanf(argv[3], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
 | 
					 | 
				
			||||||
        sscanf(argv[4], "%d", &enet_port);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if(0 == enet_port)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            memcpy(lwip_eth0_ipaddr, lwip_ipaddr, strlen(lwip_ipaddr));
 | 
					 | 
				
			||||||
            memcpy(lwip_eth0_netmask, lwip_netmask, strlen(lwip_netmask));
 | 
					 | 
				
			||||||
            memcpy(lwip_eth0_gwaddr, lwip_gwaddr, strlen(lwip_gwaddr));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if(1 == enet_port)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            memcpy(lwip_eth1_ipaddr, lwip_ipaddr, strlen(lwip_ipaddr));
 | 
					 | 
				
			||||||
            memcpy(lwip_eth1_netmask, lwip_netmask, strlen(lwip_netmask));
 | 
					 | 
				
			||||||
            memcpy(lwip_eth1_gwaddr, lwip_gwaddr, strlen(lwip_gwaddr));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else if(argc == 3)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        sscanf(argv[2], "%d", &enet_port);
 | 
					 | 
				
			||||||
        printf("lw: [%s] gw %s netport %d\n", __func__, argv[1], enet_port);
 | 
					 | 
				
			||||||
        if(isdigit(argv[1][0]))
 | 
					        if(isdigit(argv[1][0]))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if(sscanf(argv[1], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]) == EOF)
 | 
					            if(sscanf(argv[1], "%d.%d.%d.%d", &arg_ip[0], &arg_ip[1], &arg_ip[2], &arg_ip[3]) == EOF)
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                lw_notice("input wrong ip\n");
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
#if (LWIP_DHCP) && (PING_USE_SOCKETS)
 | 
					 | 
				
			||||||
        else
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            get_url_ip(argv[1]);
 | 
					 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else if(argc == 2)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        printf("lw: [%s] gw %s\n", __func__, argv[1]);
 | 
					 | 
				
			||||||
        if(isdigit(argv[1][0]))
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            if(sscanf(argv[1], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]) == EOF)
 | 
					 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                lw_notice("input wrong ip\n");
 | 
					                lw_notice("input wrong ip\n");
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
| 
						 | 
					@ -106,12 +64,11 @@ void LwipPingTest(int argc, char *argv[])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    printf("lw: [%s] argc %d\n", __func__, argc);
 | 
					    printf("lw: [%s] argc %d\n", __func__, argc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    IP4_ADDR(&ping_addr, lwip_gwaddr[0], lwip_gwaddr[1], lwip_gwaddr[2], lwip_gwaddr[3]);
 | 
					    IP4_ADDR(&ping_addr, arg_ip[0], arg_ip[1], arg_ip[2], arg_ip[3]);
 | 
				
			||||||
    lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
					 | 
				
			||||||
    ping_init(&ping_addr);
 | 
					    ping_init(&ping_addr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(5),
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(2),
 | 
				
			||||||
     ping, LwipPingTest, ping [IP] 10 times);
 | 
					     ping, LwipPingTest, ping [IP] 10 times);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue