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

Dependencies:   EthernetInterface TextLCD mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
sunifu
Date:
Fri Jul 11 14:34:23 2014 +0000
Commit message:
2014.07.11

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri Jul 11 14:34:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#9b2d10dc0392
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Jul 11 14:34:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#44f34c09bd37
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 11 14:34:23 2014 +0000
@@ -0,0 +1,72 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "TextLCD.h"
+
+TextLCD lcd(p24, p26, p27, p28, p29, p30);
+DigitalIn sw(p21);
+AnalogOut  out(p18);
+AnalogIn in(p20);
+
+// DES_ADDRESS(Static IP)
+const char* DES_ADDRESS = "192.168.0.21";
+//const char* DES_ADDRESS = "192.168.0.26";
+
+const int PORT = 50505;
+const int DSIZE = 1024;
+
+UDPSocket server;
+Endpoint client;
+unsigned short rtmp,wtmp;
+unsigned char rbuf[DSIZE], wbuf[DSIZE];
+
+void read(void) {
+    int i;
+    for ( i = 0 ; i < DSIZE ; i=i+2 ){
+        rtmp = in.read_u16();
+        rbuf[i] = (unsigned char)(rtmp & 0x00FF);
+        rbuf[i+1] = (unsigned char)((rtmp>>8)&0x00FF) ;          
+        wait(0.0001);  
+    }    
+    server.sendTo(client, (char*)rbuf, sizeof(rbuf));     
+}       
+
+void write(void) {
+    int i;
+
+    server.receiveFrom(client, (char*)wbuf, sizeof(wbuf));
+    for ( i = 0 ; i < DSIZE ; i=i+2 ){
+        wtmp = (unsigned char)(wbuf[i+1]);
+        wtmp <<=8;
+        wtmp |= (unsigned char)wbuf[i] ;
+        out.write_u16(wtmp) ;
+        wait(0.0001);
+    }            
+}    
+  
+ 
+int main (void) {
+    EthernetInterface eth;
+
+    eth.init("192.168.0.26","255.255.255.0","192.168.0.1"); 
+    //eth.init("192.168.0.21","255.255.255.0","192.168.0.1"); 
+
+    eth.connect();
+    lcd.printf("%s", eth.getIPAddress());
+    
+    server.bind( PORT );
+    server.set_blocking(false) ;
+    client.set_address(DES_ADDRESS, PORT);
+
+    while(1) {
+        if ( sw == 0 ){
+            lcd.locate(0,1);
+            lcd.printf("Listen...");    
+                        
+            write();
+        }else{
+            read();
+            lcd.locate(0,1);
+            lcd.printf("Talk...  ");
+        }
+    }    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Jul 11 14:34:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#53e6cccd8782
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jul 11 14:34:23 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b
\ No newline at end of file