Initial Example Project
Dependencies: SDFileSystem WIZnet_Library mbed
Fork of Nucleo_L152RE_W5500HelloWorld_ver2 by
Revision 5:0a1a21449539, committed 2018-01-24
- Comitter:
- peter_h
- Date:
- Wed Jan 24 09:59:13 2018 +0000
- Parent:
- 4:17797698535b
- Commit message:
- Initial version;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 17797698535b -r 0a1a21449539 main.cpp --- a/main.cpp Tue Jan 19 00:25:34 2016 +0000 +++ b/main.cpp Wed Jan 24 09:59:13 2018 +0000 @@ -1,23 +1,20 @@ -// Nucloe_L152RE_W5500_Ethernet shield Exmaple +// Nucloe_L152RE_W5500_Ethernet Example #include "mbed.h" #include "WIZnetInterface.h" -#include "SDFileSystem.h" -#include "UDPSocket.h" +//#include "SDFileSystem.h" -//#define USE_DHCP 1 // DHCP 사용할때 사용 +#define USE_DHCP 1 // DHCP #define TCP_PORT 5000 -#define UDP_PORT 7000 const char * IP_Addr = "192.168.0.194"; const char * IP_Subnet = "255.255.255.0"; const char * IP_Gateway = "192.168.0.1"; unsigned char MAC_Addr[6] = {0x00,0x08,0xDC,0x01,0x02,0x03}; -const char * UDP_IP = "0.0.0.0"; -SDFileSystem sd(PA_7, PA_6, PA_5, PB_5, "sd"); +// SDFileSystem sd(PA_7, PA_6, PA_5, PB_5, "sd"); DigitalOut myled1(LED1); Serial pc(USBTX, USBRX); @@ -35,15 +32,15 @@ char buffer[128]; //SD-CARD - printf("Hello World!\n"); - mkdir("/sd/mydir", 0777); - FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); - if(fp == NULL) { - error("Could not open file for write\n"); - } - fprintf(fp, "Hello fun SD Card World!"); - fclose(fp); - printf("Goodbye World!\r\n"); + // printf("Hello World!\n"); + // mkdir("/sd/mydir", 0777); + // FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); + // if(fp == NULL) { + // error("Could not open file for write\n"); + // } + // fprintf(fp, "Hello fun SD Card World!"); + // fclose(fp); + // printf("Goodbye World!\r\n"); //SD-CARD END while(1) @@ -78,42 +75,22 @@ pc.printf("Error ethernet.init() - ret = %d\r\n", ret); exit(0); } - - TCPSocketServer TCP_server; // TCP Socket open - UDPSocket UDP_server; // UDP Socket open - - UDP_server.init(); - Endpoint nist; - nist.set_address(UDP_IP, UDP_PORT); - UDP_server.bind(UDP_PORT); - pc.printf("UDP PORT %d \r\n", UDP_PORT); - - TCP_server.bind(TCP_PORT); - pc.printf("TCP PORT %d \r\n", TCP_PORT); - TCP_server.listen(); - - pc.printf("server %s on port %d: \r\n", nist.get_address(), nist.get_port()); - int m = UDP_server.receiveFrom(nist, buffer, sizeof(buffer)); - if(m > 0){ - UDP_server.sendTo(nist, buffer, m); - pc.printf("UDP Data Send OK\r\n"); - } - pc.printf("UDP Close\r\n"); + TCPSocketServer server; + server.bind(TCP_PORT); + server.listen(); while (1) { - pc.printf("\nWait for TCP connection...\r\n"); - TCPSocketConnection TCP_client; - if(TCP_server.accept(TCP_client) == 0) - { - pc.printf("Connection from: %s\r\n", TCP_client.get_address()); - while (TCP_client.is_connected() == true) { - int n = TCP_client.receive(buffer, sizeof(buffer)); - if(n > 0) - TCP_client.send_all(buffer, n); - if(TCP_client.is_fin_received()){ - TCP_client.close(); - } - } + pc.printf("\nWait for new connection...\r\n"); + TCPSocketConnection client; + server.accept(client); + client.set_blocking(false, 0); // Timeout=0. + pc.printf("Connection from: %s\r\n", client.get_address()); + while (client.is_connected() == true) { + int n = client.receive(buffer, sizeof(buffer)); + if(n > 0) + client.send_all(buffer, n); + if(client.is_fin_received()) + client.close(); } pc.printf("Disconnected.\r\n"); }