Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
132:05cd37f7e007
Parent:
126:1f90756250fb
Child:
133:3d136f5ffd66
--- a/call_box_manager.cpp	Tue Jul 21 20:03:35 2015 +0000
+++ b/call_box_manager.cpp	Tue Sep 01 17:21:11 2015 +0000
@@ -6,6 +6,8 @@
 
 Call_Box * find_CB ( Vector * v_cb, const int ext )
 {
+    //fixme
+    // if ( v_cb == NULL ) return NULL;
     Call_Box * cb = NULL;
     for ( register int i = 0; i < v_cb -> size (); i++ )
     {
@@ -22,40 +24,55 @@
 {
     if ( v_cb not_eq NULL)
     {
-        static int lst_index = 0;
+        static int list_index = 0;
             
         if ( v_cb -> size () > 0 )
         {
-            //FIXME pode acontecder problemas por ser static
             static uint8_t data [ CB_BUFFER_SIZE ], write_buffer [ CB_BUFFER_SIZE ];
             
             led4 = 0;
             
-            if ( lst_index >= v_cb -> size () ) lst_index = 0;
+            if ( list_index >= v_cb -> size () ) list_index = 0;
             
-            Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( lst_index++ );
+            Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( list_index++ );
             
             if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) )
             {
-                if ( cb -> get_ext () % 2 == 1 )
+                int local_ext = cb -> get_ext ();
+                if ( local_ext % 2 == 1 )
                 { 
-                    Call_Box * cb_master = find_CB ( v_cb, cb -> get_ext () - 1 );
-                    
-                    if ( ( cb_master not_eq NULL ) and ( cb_master -> get_status () not_eq cb_idle ) ) return ( 0x20 );
+                    // if ( ! list_exception_ext -> find_value ( local_ext ) )
+                    {
+                        Call_Box * cb_master = find_CB ( v_cb, local_ext - 1 );
+                        
+                        if ( ( cb_master not_eq NULL ) and ( cb_master -> get_status () not_eq cb_idle ) ) return ( 0x20 );
+                    }
                 }
                     else
                 {
-                    // checking slave status
-                    Call_Box * cb_slave = find_CB ( v_cb, cb -> get_ext () + 1 );
-                    
-                    if ( ( cb_slave not_eq NULL ) and ( cb_slave -> get_status () not_eq cb_idle ) ) return ( 0x21 );
-                }
+                    // if ( ! list_exception_ext -> find_value ( local_ext ) )
+                    {
+                        // checking slave status
+                        Call_Box * cb_slave = find_CB ( v_cb, local_ext + 1 );
                         
-                send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), REGISTRY, 
-                    ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
-                
-                if( debug_refresh ) send_msg("[%d] Refresh", cb->get_ext() );
-                
+                        if ( ( cb_slave not_eq NULL ) and ( cb_slave -> get_status () not_eq cb_idle ) ) return ( 0x21 );
+                    }
+                }
+                /*
+                    condição adicionada para minimizar o comportamento do cbx perder o tx, 
+                    pacotes vindo shiftados pra cabeceira, e não perdendo o rx, portando
+                    o cbx não resetava sozinho, idéia, deixar ele rebotar pelo wdt dele.
+                */
+                if ( ( cb -> get_timer () < ACCEPTABLE_DELAY ) and ( cb -> get_overflow_times () == 0 ) )
+                {
+                    send2callboxes( build_cb_package( local_ext, cb->get_port(), REGISTRY, 
+                        ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
+                        
+                    if( debug_refresh ) vz_printf ("[%d] Refresh", local_ext );
+                } else {
+                    if ( debug_dont_refresh ) vz_debug ("Nao pedindo registro para o [%d]( %d, %d )", 
+                        local_ext, cb -> get_timer (), cb -> get_overflow_times () );    
+                }
                 return( 0 );
             }else return( -5 );
         }else return( -3 );
@@ -114,7 +131,7 @@
                         send2callboxes( build_cb_package( ( cb->get_ext() + 1 ), ( cb->get_port() + 1 ), PROMPT, 
                             ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
         
-                        if( debug_wake ) send_msg("%d without %d - ping sent to %d", 
+                        if( debug_wake ) vz_printf ("%d without %d - ping sent to %d", 
                             ext_list[ wake_all_up_index ], ext_list[ wake_all_up_index ] + 1, cb->get_ext() + 1 );
                     }
                 }
@@ -131,7 +148,7 @@
                         send2callboxes( build_cb_package( ( cb->get_ext() - 1 ), ( cb->get_port() - 1 ), PROMPT, 
                             ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                         
-                        if ( debug_wake ) send_msg ("%d without %d - ping sent to %d", 
+                        if ( debug_wake ) vz_printf ("%d without %d - ping sent to %d", 
                             ext_list [ wake_all_up_index ], ext_list [ wake_all_up_index ] - 1, cb -> get_ext () - 1 );
                     }
                 }