work in progress

Experiment - work in progress...

Revision:
5:444939b4790a
Parent:
4:87d3a005c4de
--- a/RefRX.cpp	Sat Jul 20 11:26:05 2013 +0000
+++ b/RefRX.cpp	Sat Jul 20 12:36:22 2013 +0000
@@ -5,7 +5,7 @@
 
 bool RefRX::_initialized = false;
 
-Mutex RefRX::_refs_access = Mutex();
+Mutex RefRX::_refs_access;
 float RefRX::_ref1 = 0;
 float RefRX::_ref2 = 0;
 float RefRX::_ref3 = 0;
@@ -14,7 +14,7 @@
 int RefRX::_listen_port = 0;
 int RefRX::_destination_control_port = 0;
 
-Thread RefRX::_RX_thread = Thread(RefRX::_RX_thread_cycle);
+Thread* RefRX::_RX_thread = NULL;
 
 // /////end of static members
 
@@ -37,28 +37,33 @@
 }
 
 
-void RefRX::init (const int listen_port, const int destination_control_port)
+void RefRX::init (const int listen_port, const int destination_control_port, Thread & worker_thread)
 {
     if(_initialized)
         return;
     
     _listen_port = listen_port;
     _destination_control_port = destination_control_port;
+    _RX_thread = &worker_thread;
     
     _initialized = true;
     
-    _RX_thread.signal_set(REFRX_THREAD_START);
+    _RX_thread->signal_set(REFRX_THREAD_START);
 }
 
 
-void RefRX::_RX_thread_cycle (void const *args)
+void RefRX::worker (void const *args)
 {
-    _RX_thread.signal_wait(REFRX_THREAD_START);
+    _RX_thread->signal_wait(REFRX_THREAD_START);
 
     //Setup RX socket
     UDPSocket sock;
     sock.bind(_listen_port);
     Endpoint remote_endpoint;
+    
+    DigitalOut led3 (LED3);
+    led3 = 1;
+    Thread::wait(1000);
 
     //Start listeing loop
     while(1)
@@ -74,10 +79,12 @@
         switch (result) {
           case -1:
             //TODO: memorize error without the following message.
-            printf("Failed to read from UDP Socket\n\r");
+            //printf("Failed to read from UDP Socket\n\r");
+            led3 = 0;
             break;
           case 0:
             // error ?
+            led3 = 0;
             break;
           default:
             //socket.getRemoteEndpoint().getAddress().toString()
@@ -91,6 +98,9 @@
             _ref3 = one_over_uint32_max * refs[2];
             _ref4 = one_over_uint32_max * refs[3];
             _refs_access.unlock();
+            led3 = 0;
+            Thread::wait(100);
+            led3 = 1;
             
             //respond
             /*