![](/media/cache/profiles/asdf.png.50x50_q85.png)
W7500P TCP UART 예제
Dependencies: mbed WIZnetInterface
W7500P 개발보드의 TCP 서버 예제 입니다.
텔넷포트(23)를 기본설정으로 사용중이며, DHCP를 통해 인터넷 연결설정이 됩니다.
Diff: main.cpp
- Revision:
- 2:97a6b36f2bc9
- Parent:
- 1:ea9223739b1b
- Child:
- 3:4bfea09eabf8
--- a/main.cpp Tue Oct 12 06:49:09 2021 +0000 +++ b/main.cpp Tue Oct 12 07:20:31 2021 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" #include "EthernetInterface.h" -#define ECHO_SERVER_PORT 23 +#define ECHO_SERVER_PORT 23 Serial pc(USBTX, USBRX); @@ -9,14 +9,20 @@ { pc.baud(115200); - pc.printf("Hello World\n"); - pc.printf("Wait a second...\r\n"); + pc.printf("안녕 세상!\n"); + pc.printf("잠깐만...\r\n"); + + uint8_t mac_addr[6] = {0x00, 0x11, 0x22, 0x11, 0xAB, 0xAB}; + //uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; - uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; - EthernetInterface eth; - eth.init(mac_addr); //Use DHCP + EthernetInterface eth; + eth.init(mac_addr); //Use DHCP eth.connect(); - pc.printf("Server IP Address is %s\r\n", eth.getIPAddress()); + + pc.printf("서버주소: %s\r\n", eth.getIPAddress()); + pc.printf("서브넷 마스크: %s\r\n", eth.getNetworkMask()); + pc.printf("게이트웨이: %s\r\n", eth.getGateway()); + pc.printf("맥어드레스: %s\r\n", eth.getMACAddress()); TCPSocketServer server; server.bind(ECHO_SERVER_PORT); @@ -24,12 +30,12 @@ while (true) { - pc.printf("Wait for new connection...\r\n"); + pc.printf("새로운 연결 대기중...\r\n"); TCPSocketConnection client; server.accept(client); client.set_blocking(false, 15000); // Timeout after (1.5)s - pc.printf("Connection from: %s\r\n", client.get_address()); + pc.printf("클라이언트 연결됨: %s\r\n", client.get_address()); char buffer[256]; while (true) { int n = client.receive(buffer, sizeof(buffer)); @@ -37,7 +43,7 @@ // print received message to terminal buffer[n] = '\0'; - pc.printf("Received message from Client :'%s'\r\n",buffer); + pc.printf("클라이언트로 부터 받은 메시지:'%s'\r\n",buffer); // reverse the message char temp; @@ -48,7 +54,7 @@ } // print reversed message to terminal - pc.printf("Sending message to Client: '%s'\r\n",buffer); + pc.printf("클라이언트로 메시지 보냄: '%s'\r\n",buffer); // Echo received message back to client client.send_all(buffer, n); @@ -56,5 +62,7 @@ } client.close(); } + + pc.printf("Bye Bye.\r\n"); }