Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed
You are viewing an older revision! See the latest version
Homepage
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.
The IP address uses static IP address in this sample program. DHCP function of router doed 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.
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;
}
There are 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¶
概要¶
GR-PEACHを3台使ったTCP通信のサンプルプログラムです。
構成¶
GR-PEACH、イーサーネットケーブル、ルータ。
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に追加しています。
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-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) */ /*****************************/