ok

Dependencies:   EthernetInterfaceAA mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
avnisha
Date:
Thu Mar 27 20:21:51 2014 +0000
Commit message:
ok

Changed in this revision

EthernetInterface.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 28aa4f51f1e2 EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Thu Mar 27 20:21:51 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/avnisha/code/EthernetInterfaceAA/#9d67d590f84f
diff -r 000000000000 -r 28aa4f51f1e2 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 27 20:21:51 2014 +0000
@@ -0,0 +1,78 @@
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "Socket.h"
+#include "TCPSocketServer.h"
+#include "TCPSocketConnection.h"
+ 
+DigitalOut myled(LED1);
+Serial tty_pc(USBTX, USBRX);
+ 
+void eth_main(const void *context)
+{
+    puts("Starting " __FILE__ " " __DATE__ " " __TIME__);
+        
+    Ethernet eth;
+    eth.set_link(eth.AutoNegotiate);
+ 
+    EthernetInterface ethif;
+    ethif.init();
+    ethif.connect();
+ 
+    printf("IP %s\n", ethif.getIPAddress());
+ 
+    TCPSocketServer server;
+    TCPSocketConnection sock;
+    bool active = false;
+    unsigned short port = 8000;
+ 
+    server.bind(port);
+    server.listen();
+ 
+    server.set_blocking(false, 500); // SET NON-BLOCKING
+ 
+    printf("listening at %s:%hu\n", ethif.getIPAddress(), port);
+ 
+    while(true)
+    {
+        myled = eth.link();
+ 
+        if (active)
+        {
+       
+#ifdef OLD
+            char c;
+            if (sock.receive(&c, 1) <= 0) // NON-BLOCKING (!?) RECEIVE TO CHECK IF SOCKET ACTIVE
+                Thread::wait(500);
+#endif               
+            if (!sock.is_connected())
+            {
+                puts("connection closed");
+                sock.close(true);
+                active = false;
+                server.bind(port);
+                server.listen();
+                printf("listening at %s:%hd\n", ethif.getIPAddress(), port);
+            }
+        }
+        else
+        {
+            if (server.accept(sock) == 0)
+            {
+                active = true;
+                server.close();
+                puts("connection established");
+            }
+        }
+    }
+}
+ 
+int main()
+{
+    Thread eth_thread(eth_main, 0);
+    
+    while (1)
+    {
+        // forever
+    }
+}
diff -r 000000000000 -r 28aa4f51f1e2 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Thu Mar 27 20:21:51 2014 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#ee87e782d34f
diff -r 000000000000 -r 28aa4f51f1e2 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 27 20:21:51 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file