ハイパー・マイコン mbedでインターネット 電子工作 3章 リスト3-1 TCPMessageBoardのプログラム  

Dependencies:   EthernetInterface TextLCD mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
sunifu
Date:
Wed Jul 09 14:02:53 2014 +0000
Commit message:
Ver1.0

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 2809bb7303a8 EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Wed Jul 09 14:02:53 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa
diff -r 000000000000 -r 2809bb7303a8 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Jul 09 14:02:53 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
diff -r 000000000000 -r 2809bb7303a8 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 09 14:02:53 2014 +0000
@@ -0,0 +1,66 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "TextLCD.h" 
+
+#define MESSAGEBOARD_SERVER_PORT   55555
+
+TextLCD lcd(p24, p26, p27, p28, p29, p30); 
+
+int main() {
+    int stat;
+    EthernetInterface eth;
+ 
+    lcd.cls();
+    
+    // USE DHCP
+    eth.init();
+    // Use Static IP
+    //eth.init("192.168.0.9","255.255.255.0","192.168.0.1");
+
+    stat = eth.connect();
+
+    lcd.locate(0,1);
+    printf("\r\n");   
+    if ( stat == 0 ){
+        printf("IPAddress[%s]\r\n",eth.getIPAddress());
+        lcd.printf("%s",eth.getIPAddress());
+    }else{
+        printf("DHCP Error...\r\n");
+        lcd.printf("DHCP Error!");
+        exit(-1);
+    }
+    
+    TCPSocketServer server;
+    server.bind(MESSAGEBOARD_SERVER_PORT);
+    server.listen();
+    
+    while (true) {
+    
+        printf("Wait for new connection...\r\n");
+        TCPSocketConnection client;
+        server.accept(client);
+        
+        printf("Connection from: %s\r\n", client.get_address());
+        char buffer[17];
+        while (true) {
+            int n = client.receive(buffer, sizeof(buffer));
+            
+            buffer[n]='\0';
+            if ( !client.is_connected() ){
+                printf("Disconnection...\r\n");
+                break;
+            }
+            lcd.locate(0,0);
+            lcd.printf("                ");
+            if ( n > 0 ){     
+                lcd.locate(0,0);
+                lcd.printf("%s",buffer);      
+                printf("Send Character[%d:%s]\r\n",n,buffer);
+            }
+            else{
+                printf("[0]-\r\n");
+            }     
+        }        
+        client.close();
+    }
+}
diff -r 000000000000 -r 2809bb7303a8 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Jul 09 14:02:53 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#88a1a9c26ae3
diff -r 000000000000 -r 2809bb7303a8 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 09 14:02:53 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1
\ No newline at end of file