TCP communication sample for mbed classic by using 3 GR-PEACHs.

Dependencies:   EthernetInterface mbed-rtos mbed

For mbed-os sample

For mbed-os sample, please refer to the following.
mbed-os用サンプルについては以下を参照ください。

https://developer.mbed.org/users/1050186/code/TCP_Comm_sample/

Warning! 注意!

When exporting and using it, increase the following stack size.
エクスポートして使用する際は、以下のスタックサイズを増やしてください。

EthernetInterface/lwip/lwipopts.h

#define TCPIP_THREAD_STACKSIZE      1024
->
#define TCPIP_THREAD_STACKSIZE      2048

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

What is this ?

TCP communication sample program by using three GR-PEACHs.


Structure

GR-PEACH, ethernet cable and router.
/media/uploads/1050186/structure2.png


The IP address uses static IP address in this sample program. DHCP function of router does not use.

TCPPacket.h (IP address config)

/* GR-PEACH No1 */
#define PEACH_1_IP_ADDRESS      "192.168.2.1"
#define PEACH_1_PORT            11000

/* GR-PEACH No2 */
#define PEACH_2_IP_ADDRESS      "192.168.2.2"
#define PEACH_2_PORT            12000

/* GR-PEACH No3 */
#define PEACH_3_IP_ADDRESS      "192.168.2.3"
#define PEACH_3_PORT            13000

/* Other */
#define SUB_NET_MASK            "255.255.255.0"
#define DEFAULT_GATEWAY         "192.168.2.200"


In order to specify each GR-PEACH's own MAC address, the following function is added to main.cpp.

GR-PEACH NoMAC address
10x74, 0x90, 0x50, 0x00, 0x56, 0xA1
20x74, 0x90, 0x50, 0x00, 0x56, 0xA2
30x74, 0x90, 0x50, 0x00, 0x56, 0xA3

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x74;
    mac[1] = 0x90;
    mac[2] = 0x50;
    mac[3] = 0x00;
    mac[4] = 0x56;
    mac[5] = 0xA1;
}

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x74;
    mac[1] = 0x90;
    mac[2] = 0x50;
    mac[3] = 0x00;
    mac[4] = 0x56;
    mac[5] = 0xA2;
}

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x74;
    mac[1] = 0x90;
    mac[2] = 0x50;
    mac[3] = 0x00;
    mac[4] = 0x56;
    mac[5] = 0xA3;
}


In sample program, the communication among GR-PEACH do by Ethernet and use TCP. Therefore, in this program, it is defined send side is client and receive side is server side.
In addition, to send data in TCP communication, client side needs a port number that identifies the application of server side.
The port number of server side in TCP communication is shown below.

GR-PEACH NoRole (Client / Server)port number
1Client11000(unused)
2Client / Server12000
3Server13000



Code of three PEACHs

There is the code of three GR-PEACHs in main.cpp. You can specify GR-PEACH to use by changing the following macro.

Specify GR-PEACH

/**** Selection of PEACH *****/
#define USE_PEACH       (1)     /* 1(PEACH No1) or 2(PEACH No2) or 3(PEACH No3) */
/*****************************/



How to use

  1. Please write bin file to GR-PEACH No1 after build by setting USE_PEACH to 1.
  2. Please write bin file to GR-PEACH No2 after build by setting USE_PEACH to 2.
  3. Please write bin file to GR-PEACH No3 after build by setting USE_PEACH to 3.
  4. Please connect GR-PEACH, ethernet cable and router like as structure picture.
  5. Please start terminal software.
  6. Please press the reset button of GR-PEACH in order of GR-PEACH No3、GR-PEACH No2、GR-PEACH No1.
  7. An IP address is output on terminal.
    Please refer to the following link about how to use the terminal.
    The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
    https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
    https://developer.mbed.org/handbook/SerialPC
  8. After the IP address,
    in case of GR-PEACH No1, transmitted data is output, in case of GR-PEACH No2, received data and transmitted data is output, and in case of GR-PEACH No3, received data is output on terminal.
  9. GR-PEACH No1 sends 1 byte to GR-PEACH No2 every 1 second while incrementing.
    GR-PEACH No2 sends received data as is to GR-PEACH No3.
GR-PEACH No1 sample start!!
IP Address is 192.168.2.1
Now connecting...
Send message : 1
Now connecting...
Send message : 2
Now connecting...
Send message : 3
GR-PEACH No2 sample start!!
IP Address is 192.168.2.2
Received message : 1
Now connecting...
Send message : 1
Received message : 2
Now connecting...
Send message : 2
Received message : 3
Now connecting...
Send message : 3
GR-PEACH No3 sample start!!
IP Address is 192.168.2.3
Received message : 1
Received message : 2
Received message : 3



概要

GR-PEACHを3台使ったTCP通信のサンプルプログラムです。


構成

GR-PEACH、イーサーネットケーブル、ルータ。
/media/uploads/1050186/structure2.png


IPアドレスは固定アドレスを使います。ルータのDHCP機能は使用しません。

TCPPacket.h (IP address config)

/* GR-PEACH No1 */
#define PEACH_1_IP_ADDRESS      "192.168.2.1"
#define PEACH_1_PORT            11000

/* GR-PEACH No2 */
#define PEACH_2_IP_ADDRESS      "192.168.2.2"
#define PEACH_2_PORT            12000

/* GR-PEACH No3 */
#define PEACH_3_IP_ADDRESS      "192.168.2.3"
#define PEACH_3_PORT            13000

/* Other */
#define SUB_NET_MASK            "255.255.255.0"
#define DEFAULT_GATEWAY         "192.168.2.200"


GR-PEACHそれぞれのMACアドレスを指定するために、以下の関数をmain.cppに追加しています。

GR-PEACH NoMAC address
10x74, 0x90, 0x50, 0x00, 0x56, 0xA1
20x74, 0x90, 0x50, 0x00, 0x56, 0xA2
30x74, 0x90, 0x50, 0x00, 0x56, 0xA3

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x74;
    mac[1] = 0x90;
    mac[2] = 0x50;
    mac[3] = 0x00;
    mac[4] = 0x56;
    mac[5] = 0xA1;
}

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x74;
    mac[1] = 0x90;
    mac[2] = 0x50;
    mac[3] = 0x00;
    mac[4] = 0x56;
    mac[5] = 0xA2;
}

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x74;
    mac[1] = 0x90;
    mac[2] = 0x50;
    mac[3] = 0x00;
    mac[4] = 0x56;
    mac[5] = 0xA3;
}


サンプルプログラムでは、GR-PEACH 間の通信は全てEtherで行いTCPを用います。 そのため、予めTCP通信におる送信側をクライアント、受信側をサーバと定義します。
またTCP通信では、クライアント側はデータ送信するためにサーバ側のアプリケーションを特定する番号、つまり、ポート番号が必要です。
そこで、TCP通信でサーバ側となるGR-PEACH のポート番号を以下に示します。

GR-PEACH NoTCP通信の役割(クライアント/サーバ)ポート番号
1クライアント11000(未使用)
2クライアント / サーバ12000
3サーバ13000



3台のコードについて

GR-PEACH3台のコードはmain.cppにあります。
以下のマクロを変更することで、使用するGR-PEACHを指定できます。

Specify GR-PEACH

/**** Selection of PEACH *****/
#define USE_PEACH       (1)     /* 1(PEACH No1) or 2(PEACH No2) or 3(PEACH No3) */
/*****************************/



使い方

  1. USE_PEACHを1に設定してビルドして、GR-PEACH No1に書き込みます。
  2. USE_PEACHを2に設定してビルドして、GR-PEACH No2に書き込みます。
  3. USE_PEACHを3に設定してビルドして、GR-PEACH No3に書き込みます。
  4. 構成図のようにGR-PEACHとイーサーネットケーブルとルータを接続します。
  5. Terminalソフトを立ち上げます。。
  6. GR-PEACH No3、GR-PEACH No2、GR-PEACH No1の順にGR-PEACHをリセットします。
  7. 3.Terminal上にIPアドレスが出力されます。
    Terminalの使い方は以下のリンクを参照下さい。
    mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。
    https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
    https://developer.mbed.org/handbook/SerialPC
    IPアドレスの後、GR-PEACH No1の場合は送信データ、GR-PEACH No2の場合は受信データと送信データ、GR-PEACH No3の場合は受信データがTerminalに出力されます。
  8. GR-PEACH No1は1秒間隔で1ByteのデータをインクリメントしながらGR-PEACH No2に送信します。
    GR-PEACH No2は受信したデータをそのままGR-PEACH No3に送信します。
GR-PEACH No1 sample start!!
IP Address is 192.168.2.1
Now connecting...
Send message : 1
Now connecting...
Send message : 2
Now connecting...
Send message : 3
GR-PEACH No2 sample start!!
IP Address is 192.168.2.2
Received message : 1
Now connecting...
Send message : 1
Received message : 2
Now connecting...
Send message : 2
Received message : 3
Now connecting...
Send message : 3
GR-PEACH No3 sample start!!
IP Address is 192.168.2.3
Received message : 1
Received message : 2
Received message : 3
Committer:
1050186
Date:
Fri Apr 14 03:35:01 2017 +0000
Revision:
1:908da4276ab9
Parent:
0:75a565860f44
Modify main.cpp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
1050186 0:75a565860f44 1 #include "mbed.h"
1050186 0:75a565860f44 2 #include "rtos.h"
1050186 0:75a565860f44 3 #include "EthernetInterface.h"
1050186 0:75a565860f44 4 #include "TCPPacket.h"
1050186 0:75a565860f44 5
1050186 0:75a565860f44 6 /**** Selection of PEACH *****/
1050186 0:75a565860f44 7 #define USE_PEACH (1) /* 1(PEACH No1) or 2(PEACH No2) or 3(PEACH No3) */
1050186 0:75a565860f44 8 /*****************************/
1050186 0:75a565860f44 9
1050186 0:75a565860f44 10 #if USE_PEACH == 1 /* in case of PEACH No1 */
1050186 0:75a565860f44 11 Thread TCPTask;
1050186 0:75a565860f44 12 EthernetInterface eth;
1050186 0:75a565860f44 13 DigitalOut led1(LED1);
1050186 0:75a565860f44 14
1050186 0:75a565860f44 15 static tcp_packet send_packet;
1050186 0:75a565860f44 16
1050186 0:75a565860f44 17 int TCP_send(tcp_packet* send_data, int length, const char* adress, int port) {
1050186 0:75a565860f44 18 int ret;
1050186 0:75a565860f44 19 int retry_cnt = 0;
1050186 0:75a565860f44 20 TCPSocketConnection socket;
1050186 0:75a565860f44 21
1050186 0:75a565860f44 22 printf("Now connecting...\n");
1050186 0:75a565860f44 23 while (socket.connect(adress, port) < 0) {
1050186 0:75a565860f44 24 printf("Unable to connect to (%s) on port (%d)\n", adress, port);
1050186 0:75a565860f44 25 retry_cnt++;
1050186 0:75a565860f44 26 if (retry_cnt >= TCPSEND_CONN_RETRY_MAX) {
1050186 0:75a565860f44 27 socket.close();
1050186 0:75a565860f44 28 return -1;
1050186 0:75a565860f44 29 }
1050186 0:75a565860f44 30 }
1050186 0:75a565860f44 31 ret = socket.send_all((char*)send_data, length);
1050186 0:75a565860f44 32 socket.close();
1050186 0:75a565860f44 33
1050186 0:75a565860f44 34 return ret;
1050186 0:75a565860f44 35 }
1050186 0:75a565860f44 36
1050186 0:75a565860f44 37 void tcp_comm_task(void) {
1050186 0:75a565860f44 38 int ret;
1050186 0:75a565860f44 39
1050186 0:75a565860f44 40 memset(&send_packet, 0, sizeof(send_packet));
1050186 0:75a565860f44 41 eth.init(PEACH_1_IP_ADDRESS, SUB_NET_MASK, DEFAULT_GATEWAY);
1050186 0:75a565860f44 42 ret = eth.connect();
1050186 0:75a565860f44 43 if (ret == 0) {
1050186 0:75a565860f44 44 printf("IP Address is %s\n", eth.getIPAddress());
1050186 0:75a565860f44 45
1050186 0:75a565860f44 46 send_packet.data = 0;
1050186 0:75a565860f44 47 while (1) {
1050186 0:75a565860f44 48 // create data
1050186 0:75a565860f44 49 if (send_packet.data < 0xFF) {
1050186 0:75a565860f44 50 send_packet.data++;
1050186 0:75a565860f44 51 } else {
1050186 0:75a565860f44 52 send_packet.data = 0;
1050186 0:75a565860f44 53 }
1050186 0:75a565860f44 54 // Send message
1050186 0:75a565860f44 55 ret = TCP_send(&send_packet, sizeof(send_packet), PEACH_2_IP_ADDRESS, PEACH_2_PORT);
1050186 0:75a565860f44 56 if (ret >= 0) {
1050186 1:908da4276ab9 57 printf("Send message : %d\n", send_packet.data);
1050186 0:75a565860f44 58 led1 = !led1;
1050186 0:75a565860f44 59 } else {
1050186 0:75a565860f44 60 printf("send failed!!\n");
1050186 0:75a565860f44 61 }
1050186 0:75a565860f44 62 Thread::wait(1000);
1050186 0:75a565860f44 63 }
1050186 0:75a565860f44 64 } else {
1050186 0:75a565860f44 65 printf("Network Connect Error \n");
1050186 0:75a565860f44 66 }
1050186 0:75a565860f44 67 }
1050186 0:75a565860f44 68
1050186 0:75a565860f44 69 /****** main ******/
1050186 0:75a565860f44 70 int main(void) {
1050186 0:75a565860f44 71 printf("GR-PEACH No1 sample start!!\n");
1050186 0:75a565860f44 72
1050186 0:75a565860f44 73 /* Start TCP communicationl processing */
1050186 0:75a565860f44 74 TCPTask.start(callback(tcp_comm_task));
1050186 0:75a565860f44 75
1050186 0:75a565860f44 76 /* Wait for the threads to finish */
1050186 0:75a565860f44 77 TCPTask.join();
1050186 0:75a565860f44 78 }
1050186 0:75a565860f44 79
1050186 0:75a565860f44 80 // set mac address
1050186 0:75a565860f44 81 void mbed_mac_address(char *mac) {
1050186 0:75a565860f44 82 mac[0] = 0x74;
1050186 0:75a565860f44 83 mac[1] = 0x90;
1050186 0:75a565860f44 84 mac[2] = 0x50;
1050186 0:75a565860f44 85 mac[3] = 0x00;
1050186 0:75a565860f44 86 mac[4] = 0x56;
1050186 0:75a565860f44 87 mac[5] = 0xA1;
1050186 0:75a565860f44 88 }
1050186 0:75a565860f44 89
1050186 0:75a565860f44 90 #elif USE_PEACH == 2 /* in case of PEACH No2 */
1050186 0:75a565860f44 91 Thread TCPTask;
1050186 0:75a565860f44 92 EthernetInterface eth;
1050186 0:75a565860f44 93 TCPSocketServer server;
1050186 0:75a565860f44 94 DigitalOut led2(LED2);
1050186 0:75a565860f44 95
1050186 0:75a565860f44 96 #define CONNECT_PENDING_NUM (2)
1050186 0:75a565860f44 97 static tcp_packet send_packet;
1050186 0:75a565860f44 98 static tcp_packet recv_packet;
1050186 0:75a565860f44 99
1050186 0:75a565860f44 100 int TCP_send(tcp_packet* send_data, int length, const char* adress, int port) {
1050186 0:75a565860f44 101 int ret;
1050186 0:75a565860f44 102 int retry_cnt = 0;
1050186 0:75a565860f44 103 TCPSocketConnection socket;
1050186 0:75a565860f44 104
1050186 0:75a565860f44 105 printf("Now connecting...\n");
1050186 0:75a565860f44 106 while (socket.connect(adress, port) < 0) {
1050186 0:75a565860f44 107 printf("Unable to connect to (%s) on port (%d)\n", adress, port);
1050186 0:75a565860f44 108 retry_cnt++;
1050186 0:75a565860f44 109 if (retry_cnt >= TCPSEND_CONN_RETRY_MAX) {
1050186 0:75a565860f44 110 socket.close();
1050186 0:75a565860f44 111 return -1;
1050186 0:75a565860f44 112 }
1050186 0:75a565860f44 113 }
1050186 0:75a565860f44 114 ret = socket.send_all((char*)send_data, length);
1050186 0:75a565860f44 115 socket.close();
1050186 0:75a565860f44 116
1050186 0:75a565860f44 117 return ret;
1050186 0:75a565860f44 118 }
1050186 0:75a565860f44 119
1050186 0:75a565860f44 120 static int TCP_receive(tcp_packet* recv_data, int length) {
1050186 0:75a565860f44 121 int ret;
1050186 0:75a565860f44 122 TCPSocketConnection client;
1050186 0:75a565860f44 123
1050186 0:75a565860f44 124 ret = server.accept(client);
1050186 0:75a565860f44 125 if (ret == 0) {
1050186 0:75a565860f44 126 client.set_blocking(false, 1500); // Timeout after 1.5s
1050186 0:75a565860f44 127
1050186 0:75a565860f44 128 ret = client.receive((char*)recv_data, length);
1050186 0:75a565860f44 129 client.close();
1050186 0:75a565860f44 130 }
1050186 0:75a565860f44 131
1050186 0:75a565860f44 132 return ret;
1050186 0:75a565860f44 133 }
1050186 0:75a565860f44 134
1050186 0:75a565860f44 135 void tcp_comm_task(void) {
1050186 0:75a565860f44 136 int ret;
1050186 0:75a565860f44 137
1050186 0:75a565860f44 138 memset(&send_packet, 0, sizeof(send_packet));
1050186 0:75a565860f44 139 memset(&recv_packet, 0, sizeof(recv_packet));
1050186 0:75a565860f44 140 eth.init(PEACH_2_IP_ADDRESS, SUB_NET_MASK, DEFAULT_GATEWAY);
1050186 0:75a565860f44 141 ret = eth.connect();
1050186 0:75a565860f44 142 if (ret == 0) {
1050186 0:75a565860f44 143 printf("IP Address is %s\n", eth.getIPAddress());
1050186 0:75a565860f44 144
1050186 0:75a565860f44 145 server.bind(PEACH_2_PORT);
1050186 0:75a565860f44 146 server.listen(CONNECT_PENDING_NUM); // number of pending connections
1050186 0:75a565860f44 147 while (1) {
1050186 0:75a565860f44 148 // Receive message
1050186 0:75a565860f44 149 ret = TCP_receive(&recv_packet, sizeof(recv_packet));
1050186 0:75a565860f44 150 if (ret >= 0) {
1050186 0:75a565860f44 151 printf("Received message : %d\n", recv_packet.data);
1050186 0:75a565860f44 152 // Send message
1050186 1:908da4276ab9 153 memcpy(&send_packet, &recv_packet, sizeof(send_packet));
1050186 0:75a565860f44 154 ret = TCP_send(&send_packet, sizeof(send_packet), PEACH_3_IP_ADDRESS, PEACH_3_PORT);
1050186 0:75a565860f44 155 if (ret >= 0) {
1050186 1:908da4276ab9 156 printf("Send message : %d\n", send_packet.data);
1050186 0:75a565860f44 157 led2 = !led2;
1050186 0:75a565860f44 158 } else {
1050186 0:75a565860f44 159 printf("send failed!!\n");
1050186 0:75a565860f44 160 }
1050186 0:75a565860f44 161 } else {
1050186 0:75a565860f44 162 printf("receive failed!!\n");
1050186 0:75a565860f44 163 }
1050186 0:75a565860f44 164 Thread::wait(100);
1050186 0:75a565860f44 165 }
1050186 0:75a565860f44 166 } else {
1050186 0:75a565860f44 167 printf("Network Connect Error \n");
1050186 0:75a565860f44 168 }
1050186 0:75a565860f44 169 }
1050186 0:75a565860f44 170
1050186 0:75a565860f44 171 /****** main ******/
1050186 0:75a565860f44 172 int main(void) {
1050186 0:75a565860f44 173 printf("GR-PEACH No2 sample start!!\n");
1050186 0:75a565860f44 174
1050186 0:75a565860f44 175 /* Start TCP communicationl processing */
1050186 0:75a565860f44 176 TCPTask.start(callback(tcp_comm_task));
1050186 0:75a565860f44 177
1050186 0:75a565860f44 178 /* Wait for the threads to finish */
1050186 0:75a565860f44 179 TCPTask.join();
1050186 0:75a565860f44 180 }
1050186 0:75a565860f44 181
1050186 0:75a565860f44 182 // set mac address
1050186 0:75a565860f44 183 void mbed_mac_address(char *mac) {
1050186 0:75a565860f44 184 mac[0] = 0x74;
1050186 0:75a565860f44 185 mac[1] = 0x90;
1050186 0:75a565860f44 186 mac[2] = 0x50;
1050186 0:75a565860f44 187 mac[3] = 0x00;
1050186 0:75a565860f44 188 mac[4] = 0x56;
1050186 0:75a565860f44 189 mac[5] = 0xA2;
1050186 0:75a565860f44 190 }
1050186 0:75a565860f44 191
1050186 0:75a565860f44 192 #elif USE_PEACH == 3 /* in case of PEACH No3 */
1050186 0:75a565860f44 193 Thread TCPTask;
1050186 0:75a565860f44 194 EthernetInterface eth;
1050186 0:75a565860f44 195 TCPSocketServer server;
1050186 0:75a565860f44 196 DigitalOut led3(LED3);
1050186 0:75a565860f44 197
1050186 0:75a565860f44 198 #define CONNECT_PENDING_NUM (2)
1050186 0:75a565860f44 199 static tcp_packet recv_packet;
1050186 0:75a565860f44 200
1050186 0:75a565860f44 201 static int TCP_receive(tcp_packet* recv_data, int length) {
1050186 0:75a565860f44 202 int ret;
1050186 0:75a565860f44 203 TCPSocketConnection client;
1050186 0:75a565860f44 204
1050186 0:75a565860f44 205 ret = server.accept(client);
1050186 0:75a565860f44 206 if (ret == 0) {
1050186 0:75a565860f44 207 client.set_blocking(false, 1500); // Timeout after 1.5s
1050186 0:75a565860f44 208
1050186 0:75a565860f44 209 ret = client.receive((char*)recv_data, length);
1050186 0:75a565860f44 210 client.close();
1050186 0:75a565860f44 211 }
1050186 0:75a565860f44 212
1050186 0:75a565860f44 213 return ret;
1050186 0:75a565860f44 214 }
1050186 0:75a565860f44 215
1050186 0:75a565860f44 216 void tcp_comm_task(void) {
1050186 0:75a565860f44 217 int ret;
1050186 0:75a565860f44 218
1050186 0:75a565860f44 219 memset(&recv_packet, 0, sizeof(recv_packet));
1050186 0:75a565860f44 220 eth.init(PEACH_3_IP_ADDRESS, SUB_NET_MASK, DEFAULT_GATEWAY);
1050186 0:75a565860f44 221 ret = eth.connect();
1050186 0:75a565860f44 222 if (ret == 0) {
1050186 0:75a565860f44 223 printf("IP Address is %s\n", eth.getIPAddress());
1050186 0:75a565860f44 224
1050186 0:75a565860f44 225 server.bind(PEACH_3_PORT);
1050186 0:75a565860f44 226 server.listen(CONNECT_PENDING_NUM); // number of pending connections
1050186 0:75a565860f44 227 while (1) {
1050186 0:75a565860f44 228 // Receive message
1050186 0:75a565860f44 229 ret = TCP_receive(&recv_packet, sizeof(recv_packet));
1050186 0:75a565860f44 230 if (ret >= 0) {
1050186 0:75a565860f44 231 printf("Received message : %d\n", recv_packet.data);
1050186 0:75a565860f44 232 led3 = !led3;
1050186 0:75a565860f44 233 } else {
1050186 0:75a565860f44 234 printf("receive failed!!\n");
1050186 0:75a565860f44 235 }
1050186 0:75a565860f44 236 Thread::wait(100);
1050186 0:75a565860f44 237 }
1050186 0:75a565860f44 238 } else {
1050186 0:75a565860f44 239 printf("Network Connect Error \n");
1050186 0:75a565860f44 240 }
1050186 0:75a565860f44 241 }
1050186 0:75a565860f44 242
1050186 0:75a565860f44 243 /****** main ******/
1050186 0:75a565860f44 244 int main(void) {
1050186 0:75a565860f44 245 printf("GR-PEACH No3 sample start!!\n");
1050186 0:75a565860f44 246
1050186 0:75a565860f44 247 /* Start TCP communicationl processing */
1050186 0:75a565860f44 248 TCPTask.start(callback(tcp_comm_task));
1050186 0:75a565860f44 249
1050186 0:75a565860f44 250 /* Wait for the threads to finish */
1050186 0:75a565860f44 251 TCPTask.join();
1050186 0:75a565860f44 252 }
1050186 0:75a565860f44 253
1050186 0:75a565860f44 254 // set mac address
1050186 0:75a565860f44 255 void mbed_mac_address(char *mac) {
1050186 0:75a565860f44 256 mac[0] = 0x74;
1050186 0:75a565860f44 257 mac[1] = 0x90;
1050186 0:75a565860f44 258 mac[2] = 0x50;
1050186 0:75a565860f44 259 mac[3] = 0x00;
1050186 0:75a565860f44 260 mac[4] = 0x56;
1050186 0:75a565860f44 261 mac[5] = 0xA3;
1050186 0:75a565860f44 262 }
1050186 0:75a565860f44 263
1050186 0:75a565860f44 264 #endif