work in progress

Experiment - work in progress...

Files at this revision

API Documentation at this revision

Comitter:
MatteoT
Date:
Sat Jul 20 12:36:22 2013 +0000
Parent:
4:87d3a005c4de
Commit message:
test good

Changed in this revision

RefRX.cpp Show annotated file Show diff for this revision Revisions of this file
RefRX.h Show annotated file Show diff for this revision Revisions of this file
--- 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
             /*
--- a/RefRX.h	Sat Jul 20 11:26:05 2013 +0000
+++ b/RefRX.h	Sat Jul 20 12:36:22 2013 +0000
@@ -22,17 +22,20 @@
     static int _listen_port;
     static int _destination_control_port;
     
-    static Thread _RX_thread;
-    static void _RX_thread_cycle (void const *args);
+    static Thread* _RX_thread;
     
   public:
+    
+    /** Thread procedure
+     */
+    static void worker (void const *args);
   
     /** Initialization procedure.
      *  @param listen_port
      *  @param destination_control_port remote port for the transmission control.
      *  @param ref1 pilot references to be overwritten.
      */
-    static void init (const int listen_port, const int destination_control_port);
+    static void init (const int listen_port, const int destination_control_port, Thread & worker_thread);
     
     /** Get references and store to parameters.
      *  Involves the use of a Mutex with trylock().