Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
86:bf7b0d4c3232
Parent:
85:b6f2dc1d0f4f
Child:
87:679ee0d594a9
--- a/main.cpp	Sun Jan 04 13:56:08 2015 +0000
+++ b/main.cpp	Mon Jan 05 12:43:12 2015 +0000
@@ -125,6 +125,34 @@
     
     send_msg("Ready");
     
+    bool regystry_test = false;
+    
+    static int next_value = 5010;
+    static int nex_test_registry = next_value;
+    
+    {
+        char s[ 32 ];
+        mbed_mac_address( s );
+        send_msg( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] );
+    }
+            
+#define NUM_SOCK 50
+#define TEST_SERVER_IP "192.168.120.7"
+#define ETH_MSG_SIZE 1600   
+
+    //UDPSocket sock[ NUM_SOCK ];
+    //Endpoint server[ NUM_SOCK ];
+ 
+    /*
+    for( register int i = 0; i < NUM_SOCK; i++ )
+    {   
+        int ref = ( i + 10000 );
+        server[ i ].set_address( TEST_SERVER_IP, ref );
+        sock[ i ].set_blocking( false, 0 );
+        int bind_ret = sock[ i ].bind( ref );
+        send_msg("Sock %2d ( %d )%s", i, ref, ( bind_ret ) ? "Fail" : "Ok" );
+    }
+    */
     /*------------------------------------------ main loop ---------------------------------------------------------------*/
     while( true ){
         if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size();
@@ -314,7 +342,7 @@
         
         if( status != __WAITING__ ){
             pkg_wdt = RX_CB_IDLE;
-            xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ );    
+            xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ );
             status = __WAITING__;
             missed_pkg--;
             xmemcpy( buffer, cb_rx_buffer, __CB_BUFFER_SIZE__ );    
@@ -401,15 +429,6 @@
         }
         
         if( main_test == true ){
-            /*
-            static int next_value = 5010;
-            Call_Box * cb = new Call_Box( next_value, next_value++ );
-            v_cb->add( cb );
-            cb->cb_set_status( cb_on_call );
-            cb->set_timeslice( ts->get_timeslice() );
-            */
-         //   cb = new Call_Box( 5011, 5011 );
-         //   v_cb->add( cb );
             send_msg("CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter );
             send_msg("SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter );
             send_msg("RTP_New (%u) -- RTP_Delete (%u)", rtp_new_counter, rtp_delete_counter );
@@ -418,6 +437,30 @@
             send_msg("Received ETH Pkg ( bleuba ) %d", bleuba );
         }
         
+        if( regystry_test == true )
+        {
+            regystry_test = false;
+            
+            if( type == __DO_NOTHING__ )
+            {
+                if( next_value < ( 5010 + 38 ) )
+                {   
+                    type = __REGISTRY__;
+                    data = buffer;
+                    ext = next_value;
+                    port = next_value++;
+                }
+                    else
+                {
+                    if( nex_test_registry > ( 5010 + 38 - 1 ) ) nex_test_registry = 5010;
+                    type = __REGISTRY__;
+                    data = buffer;
+                    ext = nex_test_registry;
+                    port = nex_test_registry++;
+                }
+            }
+        }
+        
         if( reset_cks == true ){
             pkg_cksok = 0;
             pkg_ckserr = 0;
@@ -426,7 +469,7 @@
         }
         
         if( pcks_s == true ){
-            send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d :: PKG_ZERO: %d :: Out_of_range: %d :: Missed_Pkg :: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range, missed_pkg );
+            send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d :: PKG_ZERO: %d :: Out_of_range: %d :: Missed_Pkg :: %d :: CPLD_RCV :: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range, missed_pkg, received_cpld_pkg );
             pcks_s = false;
         }
         
@@ -702,6 +745,8 @@
         if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT;
         
         if( wdt_timer.read() >= 1 ){
+            regystry_test = true;
+            
             char wake_msg[ 48 ];
             uptime++;
             int read = udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) );
@@ -773,5 +818,20 @@
                 );
             }
         }
+        /*
+        {        
+            char eth_msg[ ETH_MSG_SIZE ];
+            for( register int i = 0; i < NUM_SOCK; i++ )
+            {
+                int rcv  = sock[ i ].receiveFrom( server[ i ], eth_msg, sizeof ( eth_msg ) );
+                if( rcv > 0 )
+                {   
+                    int sent = sock[ i ].sendTo( server[ i ], eth_msg, rcv );
+                    
+                    if( sent < 0 ) send_msg("Sent -1");
+                }
+            }
+        }
+        */
     }
 }
\ No newline at end of file