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: mbed mbed-rtos EthernetInterface
Diff: main.cpp
- Revision:
- 1:8485adfbbd18
- Parent:
- 0:e894a0665114
- Child:
- 3:791851ed2989
--- a/main.cpp Mon Dec 10 19:41:42 2018 +0000 +++ b/main.cpp Mon Dec 10 20:13:16 2018 +0000 @@ -4,6 +4,9 @@ */ #include "mbed.h" +#include "EthernetInterface.h" +#include "rtos.h" + #define ON (1) #define OFF (0) @@ -17,6 +20,23 @@ #define COLOR_WHITE (0b111) #define COLOR_BLACK (0b000) + + +/*** Network Information ***/ +///myIpAddrこのモータドライバのIPアドレスを入力 +#define myIpAddr "10.42.0.98" +/// myPortこのプログラムで使用するポートを入力 +#define myPort 50000 +/// NetMask このモータドライバ用のネットマスクを入力 +#define NetMask "255.255.255.0" +/// Gateway このモータドライバ用のゲートウェイを入力 +#define Gateway "10.42.0.1" + +//Network +DigitalOut EthRecv_LED(LED1); +DigitalOut EthSend_LED(LED2); +DigitalOut Ethconnect_LED(LED4); + DigitalOut led_ctrl_5v(p8); DigitalOut led_ctrl_12v(p9); DigitalOut led_ctrl_24v(p10); @@ -34,6 +54,15 @@ Serial pc(USBTX, USBRX, 9600); +Mutex g_mtx; +typedef struct{ + char color,data; +}MONITOR; + +MONITOR mon; + + + I2C i2c_master(p28, p27); const char master_addr = 0x70; @@ -42,6 +71,54 @@ void LedCheck(void); +//Ehternet Thread +void ethernet_thread(void){ + char in_buf[64]; + + EthernetInterface eth; + //eth.init(); + eth.init(myIpAddr,NetMask,Gateway); + eth.connect(); + printf("\nServer IP Address is %s\n", eth.getIPAddress()); + + TCPSocketServer server; + server.bind(myPort); + server.listen(); + + while (true) { + printf("\nWait for new connection...\n"); + TCPSocketConnection *client = new TCPSocketConnection; + server.accept(*client); + + printf("Connection from: %s\n", client->get_address()); + + while (client->is_connected()) { + + Ethconnect_LED = 1; + int len = client->receive(in_buf, sizeof(in_buf)); + EthRecv_LED = !EthRecv_LED; + // print received message to terminal +// in_buf[len] = '\0'; + if(len > 0){ + // Timeout_timer.reset(); + in_buf[len] = '\0'; + //Get data + EthRecv_LED = !EthRecv_LED; + g_mtx.lock(); + memcpy(&mon.color, &in_buf[0], 1); + memcpy(&mon.data, &in_buf[1], 1); + //printf("Received message from Client :'%f'\n",pipe_pwmduty); + g_mtx.unlock(); + } + } + printf("\nclient closed\n"); + Ethconnect_LED = 0; + client->close(); + delete client; + } +} + + // main() runs in its own thread in the OS int main() {