Threads + Network Demo

Dependencies:   EthernetInterface mbed-rtos mbed-src

Fork of TestNetComm by Malcolm Nixon

Revision:
6:97573a8dce83
Parent:
5:18415c556f04
--- a/main.cpp	Sun May 04 14:11:44 2014 +0000
+++ b/main.cpp	Sat May 10 21:52:53 2014 +0000
@@ -2,6 +2,8 @@
 #include "Thread.h"
 #include "mbed.h"
 
+Serial pc(USBTX, USBRX);
+
 void led2ThreadProc(const void *param)
 {
     // Toggle LED2
@@ -26,23 +28,37 @@
 
 int main(void)
 {
-    // Start LED toggle(s)
+    int nr;
+    
+    // Start LED2 toggle
+    pc.printf("Starting LED 2 thread\r\n");
     Thread led2(led2ThreadProc);
+    osDelay(1000);
+    
+    // Start LED3 toggle
+    pc.printf("Starting LED 3 thread\r\n");
     Thread led3(led3ThreadProc);
+    osDelay(1000);
 
-    // Start the network
-    EthernetInterface::init("192.168.5.100", "255.255.255.0", "0.0.0.0");
-    EthernetInterface::connect();
+    // Initialize the network
+    pc.printf("Initializing network\r\n");
+    nr = EthernetInterface::init("192.168.100.5", "255.255.255.0", "0.0.0.0");
+    pc.printf(" Network Init: %d\r\n", nr);
+    
+    // Connect to the network
+    pc.printf("Connecting to the network\r\n");
+    nr = EthernetInterface::connect();
+    pc.printf(" Connected: %d\r\n", nr);
 
     // Construct the server
     TCPSocketServer svr;
     svr.bind(1234);
     svr.listen();
 
-    TCPSocketConnection conn;
     for (;;)
     {
         // Accept the next connection
+        TCPSocketConnection conn;
         svr.accept(conn);
             
         // Manage the connection