Tomo Yamanaka / Mbed OS TCP_Comm_sample

You are viewing an older revision! See the latest version

Homepage

For mbed classic sample

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

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

Warning! 注意!

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

mbed-os/features/FEATURE_LWIP/lwip-interface/lwipopts.h

#define TCPIP_THREAD_STACKSIZE      1200
->
#define TCPIP_THREAD_STACKSIZE      2400

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 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) */
/*****************************/


使い方


All wikipages