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:
131:938ab88facae
Child:
135:2f4290590e51
--- a/main_app_functions.cpp	Tue Jul 21 20:03:35 2015 +0000
+++ b/main_app_functions.cpp	Tue Sep 01 17:21:11 2015 +0000
@@ -5,59 +5,59 @@
 int header_app_init ( void )
 {
  
-    send_msg ( "" );
+    vz_printf ( "\r\n" );
  
-    if ( debug_app_init ) send_msg ( "init_wdt() :: %s", ( init_wdt () == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "init_wdt() :: %s", ( init_wdt () == 0 ) ? "Ok" : "Failure" );
     
-    if ( debug_app_init ) send_msg ( "config_lpc() :: %s", ( config_lpc () == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "config_lpc() :: %s", ( config_lpc () == 0 ) ? "Ok" : "Failure" );
     
-    if ( debug_app_init ) send_msg ( "start_cpld() :: %s", ( start_cpld () == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "start_cpld() :: %s", ( start_cpld () == 0 ) ? "Ok" : "Failure" );
     
     if( sdram_init() == 1 ) {
-        send_msg("******* Failed to initialize SDRAM *******");
+        vz_printf ("******* Failed to initialize SDRAM *******");
         return 1;
     } else {
-        send_msg("******* Success to initialize SDRAM *******");
+        vz_printf ("******* Success to initialize SDRAM *******");
     }
     
     int init_fsystem_ret = init_fsystem();
     if( init_fsystem_ret & BIT0 )
     {
-        send_msg("******* File system configured!!*******");
+        vz_printf ("******* File system configured!!*******");
     }
     
     if( init_fsystem_ret & BIT1 )
     {
-        send_msg("******* File System Ready *******");
+        vz_printf ("******* File System Ready *******");
     }
     
     {
         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] );
+        vz_printf ( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] );
     }
     
     eth_status = __init_eth__ ();
     if ( eth_status )
     {
-        send_msg("******* Cannot connect to eth *******");
+        vz_printf ("******* Cannot connect to eth *******");
     } else {
-        send_msg("******* Connection eth - ok *******");
-        int init_prompt_eth_ret = init_prompt_eth();
+        vz_printf ("******* Connection eth - ok *******");
+        int vz_io_eth_init_ret = vz_io_eth_init ();
         
-        if ( init_prompt_eth_ret == BIT0 ) send_msg("******* Prompt eth UDP Ready *******");
+        if ( vz_io_eth_init_ret == BIT0 ) vz_printf ("******* Prompt eth UDP Ready *******");
         
-        if ( init_prompt_eth_ret == BIT1 ) send_msg("******* Prompt eth TCP Ready *******");
+        if ( vz_io_eth_init_ret == BIT1 ) vz_printf ("******* Prompt eth TCP Ready *******");
         
-        if ( debug_app_init ) send_msg ( "init_prompt_eth() :: %s", ( init_prompt_eth_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "vz_io_eth_init () :: %s", ( vz_io_eth_init_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_external_wdt() :: %s", ( init_external_wdt () == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_external_wdt () :: %s", ( init_external_wdt () == 0 ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_bl() :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_bl () :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_clock () :: %s", ( init_clock () == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_clock () :: %s", ( init_clock () == 0 ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_pwr_src () :: %s", ( init_pwr_src () == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_pwr_src () :: %s", ( init_power_source () == 0 ) ? "Ok" : "Failure" );
     }
     
     sync_timer.start();
@@ -79,34 +79,34 @@
         while( v_cb == NULL ) {
             Vector * v_cb = new Vector();
             if( sync_timer.read() > 5 ) {
-                if( debug_memory ) send_msg("Call_Box vector allocation fail");
+                if( debug_memory ) vz_printf ("Call_Box vector allocation fail");
                 sync_timer.reset();
             }
         }
     }
     
-    if ( debug_app_init ) send_msg ( "v_cb :: %s", ( v_cb not_eq NULL ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "v_cb :: %s", ( v_cb not_eq NULL ) ? "Ok" : "Failure" );
     
     v_call = new Vector();
     if( v_call == NULL ) {
         while( v_call == NULL ) {
             Vector * v_call = new Vector();
             if( sync_timer.read() > 5 ) {
-                if( debug_memory ) send_msg("Call vector allocation fail");
+                if( debug_memory ) vz_printf ("Call vector allocation fail");
                 sync_timer.reset();
             }
         }
     }
     
-    if ( debug_app_init ) send_msg ( "v_call :: %s", ( v_call not_eq NULL ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "v_call :: %s", ( v_call not_eq NULL ) ? "Ok" : "Failure" );
     
     ts = new Timeslice();
     if( ts == NULL ) {
         memory_is_over = true;
-        if( debug_memory ) send_msg("TS allocation fail");
+        if( debug_memory ) vz_printf ("TS allocation fail");
     }
     
-    if ( debug_app_init ) send_msg ( "TS :: %s", ( ts not_eq NULL ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "TS :: %s", ( ts not_eq NULL ) ? "Ok" : "Failure" );
     
     for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) {
         cb_rx_buffer[ i ] = 0;
@@ -115,15 +115,13 @@
     
     reset_leds();
     
-    udp_timer.start();
+    if ( debug_app_init ) vz_printf ( "init_fw_handler() :: %s", ( init_fw_handler() == 0 ) ? "Ok" : "Failure" );
     
-    if ( debug_app_init ) send_msg ( "init_fw_handler() :: %s", ( init_fw_handler() == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "init_ranges() :: %s", ( init_ranges() == 0 ) ? "Ok" : "Failure" );
     
-    if ( debug_app_init ) send_msg ( "init_ranges() :: %s", ( init_ranges() == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "init_refresh() :: %s", ( init_refresh() == 0 ) ? "Ok" : "Failure" );
     
-    if ( debug_app_init ) send_msg ( "init_refresh() :: %s", ( init_refresh() == 0 ) ? "Ok" : "Failure" );
-    
-    if ( debug_app_init ) send_msg ( "init_sync_refresh() :: %s", ( init_sync_refresh() == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "init_sync_refresh() :: %s", ( init_sync_refresh() == 0 ) ? "Ok" : "Failure" );
     
     count = 0;
     
@@ -137,19 +135,17 @@
     
     invite_retry_timer.start();
     
-    if ( debug_app_init ) send_msg ( "hex_init() :: %s", ( hex_init() == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "hex_init() :: %s", ( hex_init() == 0 ) ? "Ok" : "Failure" );
     
     reset_leds();
     
     lpc_low_level_input_counter = 0;
     
-    if ( debug_app_init ) send_msg ( "init_hello () :: %s", ( init_hello ()  == 0 ) ? "Ok" : "Failure" );
+    if ( debug_app_init ) vz_printf ( "init_hello () :: %s", ( init_hello ()  == 0 ) ? "Ok" : "Failure" );
     
     test_ts_timer.start ();
     
-    pwr_src_timer.start ();
-    
-    send_msg ( "" );
+    vz_printf ( "\r\n" );
     
     return ( 0 );   
 }
@@ -161,24 +157,24 @@
     
     if ( eth_status )
     {
-        send_msg("******* Cannot connect to eth *******");
+        vz_printf ("******* Cannot connect to eth *******");
     } else {
-        send_msg("******* Connection eth - ok *******");
-        int init_prompt_eth_ret = init_prompt_eth();
+        vz_printf ("******* Connection eth - ok *******");
+        int vz_io_eth_init_ret = vz_io_eth_init ();
         
-        if ( init_prompt_eth_ret == BIT0 ) send_msg("******* Prompt eth UDP Ready *******");
+        if ( vz_io_eth_init_ret == BIT0 ) vz_printf ("******* Prompt eth UDP Ready *******");
         
-        if ( init_prompt_eth_ret == BIT1 ) send_msg("******* Prompt eth TCP Ready *******");
+        if ( vz_io_eth_init_ret == BIT1 ) vz_printf ("******* Prompt eth TCP Ready *******");
         
-        if ( debug_app_init ) send_msg ( "init_prompt_eth() :: %s", ( init_prompt_eth_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "vz_io_eth_init () :: %s", ( vz_io_eth_init_ret == ( BIT0 bitor BIT1 ) ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_external_wdt() :: %s", ( init_external_wdt() == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_external_wdt() :: %s", ( init_external_wdt() == 0 ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_bl() :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_bl() :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_clock() :: %s", ( init_clock() == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_clock() :: %s", ( init_clock() == 0 ) ? "Ok" : "Failure" );
         
-        if ( debug_app_init ) send_msg ( "init_pwr_src () :: %s", ( init_pwr_src () == 0 ) ? "Ok" : "Failure" );
+        if ( debug_app_init ) vz_printf ( "init_pwr_src () :: %s", ( init_power_source () == 0 ) ? "Ok" : "Failure" );
     }
     
     return eth_status;
@@ -187,8 +183,8 @@
 
 int show_stats ( void )
 {
-    char str[ 200 ];
-    int snprintf_ret = snprintf( str, 200, ""
+    char str [ 256 ];
+    int snprintf_ret = snprintf( str, sizeof ( str ) - 1,
             "\n\rReceived Pkgs::\n\r "
             "Boot :: %u\n\r "
             "Registry :: %u\n\r "
@@ -211,9 +207,11 @@
             flood_counter,
             bootloader_cbx_counter
     );
-    send_msg( str );
+    
+    vz_printf ( "%s", str );
     
-    if ( debug_string_length ) debug_msg("str.length ( %d )", snprintf_ret );
+    if ( debug_string_length ) vz_debug ( "str.length ( %d )", snprintf_ret );
+    
     return ( snprintf_ret );
 }
 
@@ -235,103 +233,116 @@
     return ( 0 );
 }
 
-int show_cb_list ( Vector * v_cb )
+int 
+show_cb_list ( Vector * v_cb )
 {
-    uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size();
+    uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb -> size();
 
-    if( ( max_ext % 2 ) == 0 ) missed_cb++;
+    if ( ( max_ext % 2 ) == 0 ) missed_cb ++;
 
-    if( min_ext % 2 ) missed_cb++;
+    if ( min_ext % 2 ) missed_cb ++;
 
-    if( min_ext == 0 && max_ext == 0 ) missed_cb = 0;
+    if ( min_ext == 0 && max_ext == 0 ) missed_cb = 0;
 
-    send_msg("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, ts->remain_timeslices(), v_call->size() );
+    vz_printf ("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- "
+        "Remain_timeslices :: %d :: v_call->size() :: %d", 
+        v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, 
+        ts->remain_timeslices(), v_call->size() 
+    );
+        
     if( v_cb->size() == 1 ) {
-        send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() );
-    } else if( v_cb->size() > 1 ) {
-        char str[ 1024 ];
-        int ext_list[ MAX_CB_IN_A_BRANCH ];
+        vz_printf (" %d ", ( ( Call_Box * )v_cb -> get_element( 0 ) ) -> get_ext () );
+    } else if( v_cb -> size() > 1 ) {
+        char str [ 1024 ];
+        int ext_list [ MAX_CB_IN_A_BRANCH ];
         register int i = 0;
-        for( ; i < v_cb->size(); i++ ) {
-            ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext();
+        for( ; i < v_cb -> size(); i++ ) {
+            ext_list [ i ] = ( ( Call_Box * )v_cb->get_element ( i ) ) -> get_ext ();
         }
 
         qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp );
 
         char aux[ 16 ];
-        strcpy( str, "\r\n> " );
-        for( i = 0; i < v_cb->size() - 1; i++ ) {
-            sprintf( aux, "%i, ", ext_list[ i ] );
-            strcat( str, aux );
-            if( ( i not_eq 0 ) and not( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " );
+        strcpy ( str, "\r\n> " );
+        for ( i = 0; i < v_cb -> size () - 1; i ++ )
+        {
+            sprintf ( aux, "%i, ", ext_list [ i ] );
+            strcat ( str, aux );
+            if ( ( i not_eq 0 ) and not ( ( i + 1 ) % 16 ) ) strcat ( str, "\r\n> " );
         }
-        sprintf( aux, "%i ", ext_list[ i ] );
-        strcat( str, aux );
-        send_msg( "%s", str );
+        sprintf ( aux, "%i ", ext_list [ i ] );
+        strcat ( str, aux );
+        vz_printf ( "%s", str );
     }
     
     return ( 0 );
 }
 
-int show_cb_long_list ( Vector * v_cb, bool show_time )
+int 
+show_cb_long_list ( Vector * v_cb, bool show_time, bool show_invite )
 {
-    uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size();
+    uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb -> size ();
 
-    if( ( max_ext % 2 ) == 0 ) missed_cb++;
+    if ( ( max_ext % 2 ) == 0 ) missed_cb ++;
 
-    if( min_ext % 2 ) missed_cb++;
+    if ( min_ext % 2 ) missed_cb ++;
 
-    if( min_ext == 0 && max_ext == 0 ) missed_cb = 0;
+    if ( min_ext == 0 && max_ext == 0 ) missed_cb = 0;
 
     {
-        int ext_list[ MAX_CB_IN_A_BRANCH ];
+        int ext_list [ MAX_CB_IN_A_BRANCH ];
         
-        if( v_cb->size() >= 1 ) {
-            for( register int i = 0; i < v_cb->size(); i++ )
+        if ( v_cb -> size () >= 1 )
+        {
+            for ( register int i = 0; i < v_cb -> size (); i ++ )
             {
-                ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext();
+                ext_list [ i ] = ( ( Call_Box * )v_cb -> get_element ( i ) ) -> get_ext ();
             }
-            qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp );
+            qsort ( ext_list, v_cb -> size (), sizeof ( int ), ls_comp );
         }   
         
-        send_msg("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, ts->remain_timeslices(), v_call->size() );
+        vz_printf ("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- "
+            "Remain_timeslices :: %d :: v_call->size() :: %d", 
+            v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, 
+            ts->remain_timeslices(), v_call->size() 
+        );
         
-        for( register uint8_t i = 0; i < v_cb->size(); i++ ) {
-            
-            Call_Box * cb = find_CB( v_cb, ext_list[ i ] );
+        for ( register uint8_t i = 0; i < v_cb -> size (); i ++ )
+        {    
+            Call_Box * cb = find_CB ( v_cb, ext_list [ i ] );
     
-            if( cb not_eq NULL )
+            if ( cb not_eq NULL )
             {
-                char cb_status[ 32 ];
-                char cb_sip_status[ 32 ];
+                char cb_status [ 32 ];
+                char cb_sip_status [ 32 ];
                 switch ( cb -> get_status () )
                 {
                     case cb_idle : {
-                        strcpy( cb_status, "cb_idle" );
+                        strcpy ( cb_status, "cb_idle" );
                         break;
                     }
                     case cb_ringing : {
-                        strcpy( cb_status, "cb_ringing" );
+                        strcpy ( cb_status, "cb_ringing" );
                         break;
                     }
                     case cb_trying : {
-                        strcpy( cb_status,"cb_trying" );
+                        strcpy ( cb_status,"cb_trying" );
                         break;
                     }
                     case cb_on_call : {
-                        strcpy( cb_status, "cb_on_call" );
+                        strcpy ( cb_status, "cb_on_call" );
                         break;
                     }
                     case cb_busy : {
-                        strcpy( cb_status, "cb_busy" );
+                        strcpy ( cb_status, "cb_busy" );
                         break;
                     }
                     case cb_denied : {
-                        strcpy( cb_status, "cb_denied" );
+                        strcpy ( cb_status, "cb_denied" );
                         break;
                     }
                     case cb_bootloader : {               
-                        strcpy( cb_status, "cb_bootloader" );
+                        strcpy ( cb_status, "cb_bootloader" );
                         break;
                     }
                 }
@@ -339,49 +350,49 @@
                 switch( cb -> get_sip_status () ) 
                 {
                     case sip_idle : {
-                        strcpy( cb_sip_status, "sip_idle" );
+                        strcpy ( cb_sip_status, "sip_idle" );
                         break;
                     }
                     case sip_waiting_trying : {
-                        strcpy( cb_sip_status, "sip_waiting_trying" );
+                        strcpy ( cb_sip_status, "sip_waiting_trying" );
                         break;
                     }
                     case sip_trying : {
-                        strcpy( cb_sip_status, "sip_trying" );
+                        strcpy ( cb_sip_status, "sip_trying" );
                         break;
                     }
                     case sip_ringing : {
-                        strcpy( cb_sip_status, "sip_ringing" );
+                        strcpy ( cb_sip_status, "sip_ringing" );
                         break;
                     }
                     case sip_busy : {
-                        strcpy( cb_sip_status, "sip_busy" );
+                        strcpy ( cb_sip_status, "sip_busy" );
                         break;
                     }
                     case sip_ok : {
-                        strcpy( cb_sip_status, "sip_ok" );
+                        strcpy ( cb_sip_status, "sip_ok" );
                         break;
                     }
                     case sip_on_call : {
-                        strcpy( cb_sip_status, "sip_on_call" );
+                        strcpy ( cb_sip_status, "sip_on_call" );
                         break;
                     }
                     case sip_denied : {
-                        strcpy( cb_sip_status, "sip_denied" );
+                        strcpy ( cb_sip_status, "sip_denied" );
                         break;
                     }
                 }
                 
-                char cbx_to_string[ 254 ];
+                char cbx_to_string [ 254 ];
                 snprintf ( cbx_to_string, sizeof ( cbx_to_string ), 
                     "Ext :: %5i :: Port :: %5i :: Status -- %s - %s",
                     cb->get_ext(), cb->get_port(), cb_status, cb_sip_status
                 );
                 
-                if( cb->get_timeslice() not_eq 0 )
+                if( cb -> get_timeslice () not_eq 0 )
                 {
-                    char aux[ 32 ];
-                    snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i",  cb->get_timeslice() );
+                    char aux [ 32 ];
+                    snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i",  cb->get_timeslice () );
                     strcat( cbx_to_string, aux );
                 }
                 
@@ -400,9 +411,9 @@
                 
                     else {
                         char strcat_tmp [ 16 ];
-                        if ( get_overflow_times_tmp == 1 ) snprintf( strcat_tmp, sizeof ( strcat_tmp ) - 1, "1 time ]" );
+                        if ( get_overflow_times_tmp == 1 ) snprintf ( strcat_tmp, sizeof ( strcat_tmp ) - 1, "1 time ]" );
                         
-                        else snprintf( strcat_tmp, sizeof ( strcat_tmp ) - 1, "%u times ]", get_overflow_times_tmp );
+                        else snprintf ( strcat_tmp, sizeof ( strcat_tmp ) - 1, "%u times ]", get_overflow_times_tmp );
                         
                         strcat ( get_timer_msg, strcat_tmp );
                     }
@@ -410,7 +421,18 @@
                     strcat ( cbx_to_string, get_timer_msg );
                 }
                 
-                send_msg( cbx_to_string );
+                if ( show_invites )
+                {
+                    char get_invites_msg [ 32 ];
+                    
+                    snprintf ( get_invites_msg, 
+                        sizeof ( get_invites_msg ) -1, 
+                            " :: invites :: %u ", cb -> get_invite_counter () );
+                    
+                    strcat ( cbx_to_string, get_invites_msg );
+                }
+                
+                vz_printf ( cbx_to_string );
             }
         }   
     }
@@ -420,92 +442,96 @@
 
 int show_cb ( Vector * v_cb )
 {
-    send_msg("Registered %d ( of %d ) CBx ( %d - %d ) -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, ts->remain_timeslices(), v_call->size() );
-    for( register uint8_t i = 0; i < v_cb->size(); i++ ) {
-        Call_Box * cb = ( Call_Box * )v_cb->get_element( i );
-        char cb_status[ 32 ];
-        char cb_sip_status[ 32 ];
+    vz_printf ("Registered %d ( of %d ) CBx ( %d - %d ) -- Remain_timeslices :: %d :: v_call->size() :: %d", 
+        v_cb->size(), max_registered_cbx, min_ext, max_ext, ts->remain_timeslices(), v_call->size() 
+    );
+    
+    for( register uint8_t i = 0; i < v_cb -> size (); i++ )
+    {
+        Call_Box * cb = ( Call_Box * )v_cb -> get_element ( i );
+        char cb_status [ 32 ];
+        char cb_sip_status [ 32 ];
         switch ( cb -> get_status () )
         {
             case cb_idle : {
-                strcpy( cb_status, "cb_idle" );
+                strcpy ( cb_status, "cb_idle" );
                 break;
             }
             case cb_ringing : {
-                strcpy( cb_status, "cb_ringing" );
+                strcpy ( cb_status, "cb_ringing" );
                 break;
             }
             case cb_trying : {
-                strcpy( cb_status,"cb_trying" );
+                strcpy ( cb_status,"cb_trying" );
                 break;
             }
             case cb_on_call : {
-                strcpy( cb_status, "cb_on_call" );
+                strcpy ( cb_status, "cb_on_call" );
                 break;
             }
             case cb_busy : {
-                strcpy( cb_status, "cb_busy" );
+                strcpy ( cb_status, "cb_busy" );
                 break;
             }
             case cb_denied : {
-                strcpy( cb_status, "cb_denied" );
+                strcpy ( cb_status, "cb_denied" );
                 break;
             }
             case cb_bootloader : {               
-                strcpy( cb_status, "cb_bootloader" );
+                strcpy ( cb_status, "cb_bootloader" );
                 break;
             }
         }
         switch( cb -> get_sip_status () ) {
             case sip_idle : {
-                strcpy( cb_sip_status, "sip_idle" );
+                strcpy ( cb_sip_status, "sip_idle" );
                 break;
             }
             case sip_waiting_trying : {
-                strcpy( cb_sip_status, "sip_waiting_trying" );
+                strcpy ( cb_sip_status, "sip_waiting_trying" );
                 break;
             }
             case sip_trying : {
-                strcpy( cb_sip_status, "sip_trying" );
+                strcpy ( cb_sip_status, "sip_trying" );
                 break;
             }
             case sip_ringing : {
-                strcpy( cb_sip_status, "sip_ringing" );
+                strcpy ( cb_sip_status, "sip_ringing" );
                 break;
             }
             case sip_busy : {
-                strcpy( cb_sip_status, "sip_busy" );
+                strcpy ( cb_sip_status, "sip_busy" );
                 break;
             }
             case sip_ok : {
-                strcpy( cb_sip_status, "sip_ok" );
+                strcpy ( cb_sip_status, "sip_ok" );
                 break;
             }
             case sip_on_call : {
-                strcpy( cb_sip_status, "sip_on_call" );
+                strcpy ( cb_sip_status, "sip_on_call" );
                 break;
             }
             case sip_denied : {
-                strcpy( cb_sip_status, "sip_denied" );
+                strcpy ( cb_sip_status, "sip_denied" );
                 break;
             }
         }
         
-        char cbx_to_string[ 254 ];
+        char cbx_to_string [ 254 ];
         snprintf ( cbx_to_string, sizeof ( cbx_to_string ), 
             "Ext :: %5i :: Port :: %5i :: Status -- %s - %s",
-            cb->get_ext(), cb->get_port(), cb_status, cb_sip_status
+            cb -> get_ext (), cb -> get_port (), cb_status, cb_sip_status
         );
         
-        if( cb->get_timeslice() not_eq 0 )
+        if ( cb -> get_timeslice () not_eq 0 )
         {
-            char aux[ 32 ];
-            snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i",  cb->get_timeslice() );
-            strcat( cbx_to_string, aux );
+            char aux [ 32 ];
+            snprintf ( aux, sizeof ( aux ), " -- on TimeSlice :: %i",  cb -> get_timeslice () );
+            strcat ( cbx_to_string, aux );
         }
         
         
-        send_msg( cbx_to_string );
+        vz_printf ( cbx_to_string );
     }
     
     return ( 0 );
@@ -513,7 +539,7 @@
 
 int show_cb_sip ( Vector * v_cb )
 {
-    send_msg(":: Sip :: %u", v_cb -> size () );
+    vz_printf (":: Sip :: %u", v_cb -> size () );
     for ( register uint8_t i = 0; i < v_cb -> size (); i++ )
     {
         Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( i );
@@ -541,7 +567,7 @@
             strcat ( tmp_send_msg, strcat_tmp );
         }
         
-        send_msg ( tmp_send_msg );
+        vz_printf ( tmp_send_msg );
     }    
     
     return ( 0 );
@@ -550,23 +576,23 @@
 int show_sizes ( void )
 {
     sizes = false;
-    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_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter );
-    send_msg("RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter );
-    send_msg("Call_New (%u) -- Call_Delete (%u)", call_new_counter, call_delete_counter );
-    send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter );
-    send_msg("Memory is %s", ( memory_is_over ) ? "Over" : "Ok" );
-    send_msg("Missed_Pkg :: %d ::", missed_pkg );
-    send_msg("Sizeof Sip :: %u", sizeof( Sip ) );
-    send_msg("Sizeof Call_Box :: %u", sizeof ( Call_Box ) );
-    send_msg("Sizeof VZ_call :: %u", sizeof( VZ_call ) );
-    send_msg("Sizeof RTP :: %u", sizeof( RTP ) );
-    send_msg("Sizeof RTP_Header :: %u", sizeof( RTP_Header ) );
-    send_msg("Sizeof RTP_Body :: %u", sizeof( RTP_Body ) );
-    send_msg("Sizeof Vector :: %u", sizeof( Vector ) );
-    send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) );
-    send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) );
+    vz_printf ( "CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter );
+    vz_printf ( "SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter );
+    vz_printf ( "RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter );
+    vz_printf ( "RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter );
+    vz_printf ( "Call_New (%u) -- Call_Delete (%u)", call_new_counter, call_delete_counter );
+    vz_printf ( "lpc_low_level_input_counter :: %d", lpc_low_level_input_counter );
+    vz_printf ( "Memory is %s", ( memory_is_over ) ? "Over" : "Ok" );
+    vz_printf ( "Missed_Pkg :: %d ::", missed_pkg );
+    vz_printf ( "Sizeof Sip :: %u", sizeof ( Sip ) );
+    vz_printf ( "Sizeof Call_Box :: %u", sizeof ( Call_Box ) );
+    vz_printf ( "Sizeof VZ_call :: %u", sizeof ( VZ_call ) );
+    vz_printf ( "Sizeof RTP :: %u", sizeof ( RTP ) );
+    vz_printf ( "Sizeof RTP_Header :: %u", sizeof ( RTP_Header ) );
+    vz_printf ( "Sizeof RTP_Body :: %u", sizeof ( RTP_Body ) );
+    vz_printf ( "Sizeof Vector :: %u", sizeof ( Vector ) );
+    vz_printf ("Sizeof Timeslice :: %u", sizeof ( Timeslice ) );
+    vz_printf ( "Sizeof Watchdog :: %u", sizeof ( Watchdog ) );
     
     return ( 0 );
 }
@@ -575,6 +601,9 @@
 {
     fd_set fdSet;
     FD_ZERO(&fdSet);
+    
+    udp_query = false;
+    from_eth = false;
 
     for( register uint8_t i = 0; i < v_cb->size(); i++ ) {
         Call_Box * cb = (Call_Box *)v_cb->get_element( i );
@@ -616,11 +645,13 @@
 
     if ( ret > 0 )
     {  
-        for( register uint8_t i = 0; i < v_cb->size(); i++ ) {
-            Call_Box * cb = (Call_Box *)v_cb->get_element( i );
-            int fd =  cb->get_sip_socket_fd();
-            if( FD_ISSET( fd, &fdSet ) ) {
-                int rcv = cb->sip_udp_incomming_pkg();
+        for ( register uint8_t i = 0; i < v_cb -> size (); i++ ) 
+        {
+            Call_Box * cb = ( Call_Box * )v_cb -> get_element ( i );
+            int fd =  cb -> get_sip_socket_fd ();
+            if ( FD_ISSET ( fd, &fdSet ) ) 
+            {
+                int rcv = cb -> sip_udp_incomming_pkg ();
             }
         }
         
@@ -655,11 +686,13 @@
                 /* caso nao haja timeslice disponivel informar servidor */
                 if ((bl_ts == 0) and !(bl_start_flag)) {
                     strncpy(bl_send_buffer + 2,"cbxdead\x00",8);
-                    int udp_bl_client_ret = udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, strlen( bl_send_buffer ) );
+                    int udp_bl_client_ret = udp_bl_client.sendTo ( udp_bl_server, bl_send_buffer, strlen ( bl_send_buffer ) );
                     
                     if ( udp_bl_client_ret not_eq strlen( bl_send_buffer ) )
                     {
-                            // TODO implementar os reconnects do bl
+                            reconnect_bl ();
+                            miss_bl_udp_send_pkg ++;
+                            if ( debug_reconnect ) vz_printf ( "[%d] Reconnect BL - %d", bl_peer, udp_bl_client_ret );
                     }
                 } else {
                     
@@ -682,7 +715,14 @@
                             }
                             pc.printf("\r\n}");
                         }
-                        udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, strlen( bl_send_buffer ) );
+                        int udp_bl_client_ret = udp_bl_client.sendTo ( udp_bl_server, bl_send_buffer, strlen ( bl_send_buffer ) );
+                        
+                        if ( udp_bl_client_ret not_eq strlen( bl_send_buffer ) )
+                        {
+                                reconnect_bl ();
+                                miss_bl_udp_send_pkg ++;
+                                if ( debug_reconnect ) vz_printf ( "[%d] Reconnect BL - %d", bl_peer, udp_bl_client_ret );
+                        }
                     }
                     
                     /* pacote para indicar o termino do processo de atualizacao */
@@ -751,22 +791,22 @@
         
         // verifica o socket do prompt-UDP-ETH                
         if( FD_ISSET( udp_client.get_fd(), &fdSet ) ) {
-            char to_prompt_process[ PROMPT_UDP_COMMAND_SIZE ];
+            char to_prompt_process [ PROMPT_UDP_COMMAND_SIZE ];
             for( register int i = 0; i < PROMPT_UDP_COMMAND_SIZE; i++ ) to_prompt_process[ i ] = 0;
             
-            int prompt_process_msg_rcv = udp_client.receiveFrom( udp_server, to_prompt_process, ( sizeof( to_prompt_process ) - 1 ) );
+            int prompt_process_msg_rcv = udp_client.receiveFrom ( udp_server, to_prompt_process, ( PROMPT_UDP_COMMAND_SIZE - 1 ) );
             
-            to_prompt_process[ prompt_process_msg_rcv ] = 0;
-            if( prompt_process_msg_rcv == -1 )
+            if ( prompt_process_msg_rcv == -1 )
             {
-                if( debug_reconnect ) send_msg("Reconnect Prompt Process");
-                reconnect_udp_prompt_process();
-                miss_prompt_udp_rcv_pkg++;
+                if ( debug_reconnect ) vz_printf ("Reconnect Prompt Process");
+                reconnect_udp_prompt_process ();
+                miss_prompt_udp_rcv_pkg ++;
             } 
-                else if( prompt_process_msg_rcv > 0 )
+                else if ( prompt_process_msg_rcv > 0 )
             {
                 udp_query = true;
-                prompt_process( to_prompt_process, prompt_process_msg_rcv );
+                from_eth = true;
+                prompt_process ( to_prompt_process, prompt_process_msg_rcv );
             }
         } 
         
@@ -780,15 +820,15 @@
             
             Endpoint udp_wdt_server;
             
-            int wake_msg_rcv = udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) );
+            int wake_msg_rcv = udp_wdt_client.receiveFrom ( udp_wdt_server, wake_msg, sizeof ( wake_msg ) );
             
-            if ( dmissed_wdt ) debug_msg("wake_msg_rcv :: %d -- wake_msg :: %s", wake_msg_rcv, wake_msg );
+            if ( dmissed_wdt ) vz_debug ("wake_msg_rcv :: %d -- wake_msg :: %s", wake_msg_rcv, wake_msg );
             
             if( wake_msg_rcv == -1 )
             {
-                if( debug_reconnect ) send_msg("Reconnect Extern wdt");
-                reconnect_extern_wdt_socket();
-                miss_wdt_send_pkg++;
+                if( debug_reconnect ) vz_printf ("Reconnect Extern wdt");
+                reconnect_extern_wdt_socket ();
+                miss_wdt_send_pkg ++;
             } 
                 else if( wake_msg_rcv > 0 )
             {
@@ -799,69 +839,42 @@
                     bool question_alive = ( wake_msg[ 5 ] == '?' );
                     if( wake_msg[ 5 ] == '*' ) wdt.kick();
                     
-                    if ( dmissed_wdt ) if ( wake_msg [ 5 ] == '?' ) debug_msg("Recebi o alive ???");
+                    if ( dmissed_wdt ) if ( wake_msg [ 5 ] == '?' ) vz_debug ("Recebi o alive ???");
                     
-                    snprintf( wake_msg, WAKE_MSG_SIZE - 1,"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u:", 
-                        uptime, 
-                        invite_counter, 
-                        external_wdt, 
-                        ( wdt.WatchdogCausedReset() ) ? '1' : '0', 
-                        cb_new_counter, 
-                        v_cb->size(),
-                        ts->remain_timeslices(), 
-                        sip_socket_send_failure, 
-                        v_call->size(),
-                        pkg_cksok,
-                        pkg_ckserr,
-                        pkg_zero,
-                        out_of_range,
-                        missed_pkg,
-                        delayed_pkg_to_cb,
-                        cpld_pkg_tx_counter,
-                        cpld_pkg_rx_counter,
-                        eth_wdt,
-                        pkg_wdt,
-                        miss_fw_send_pkg,
-                        miss_prompt_udp_send_pkg,
-                        miss_sip_registry_send_pkg,
-                        miss_sip_invite_send_pkg,
-                        miss_sip_bye_send_pkg,
-                        miss_sip_unregistry_send_pkg,
-                        miss_sip_ok_send_pkg,
-                        miss_sip_rcv_bye_send_pkg,
-                        miss_wdt_send_pkg,
-                        miss_prompt_udp_send_pkg,
-                        miss_ftp_udp_send_pkg,
-                        miss_prompt_udp_rcv_pkg,
-                        miss_clock_send_pkg
-                    );
+                    build_wdt_string ( wake_msg, WAKE_MSG_SIZE - 1 );
+                    
                     wake_msg[ WAKE_MSG_SIZE - 1 ] = 0;
                     
-                    int send = udp_wdt_client.sendTo ( udp_wdt_server, wake_msg, strlen( wake_msg ) );
-                    if( send not_eq strlen( wake_msg ) )
+                    int send = udp_wdt_client.sendTo ( udp_wdt_server, wake_msg, strlen ( wake_msg ) );
+                    if( send not_eq strlen ( wake_msg ) )
                     {
-                        if( debug_reconnect ) debug_msg("Reconnect Extern wdt (%d, %d)", send, strlen( wake_msg ) );
+                        if ( debug_reconnect ) vz_debug ("Reconnect Extern wdt (%d, %d)", send, strlen ( wake_msg ) );
                         reconnect_extern_wdt_socket ();
-                        miss_wdt_send_pkg++;
-                    }
-
-                    if( ( (!question_alive) && ( cb_new_counter <= MAX_CB_IN_A_BRANCH ) && ( cb_new_counter >= 2 ) ) ) {
-                        external_wdt = EXTERN_WDT_IDLE;
-                        if ( dmissed_wdt ) debug_msg("kickando");
+                        miss_wdt_send_pkg ++;
                     }
                     
-                    if ( dmissed_wdt ) debug_msg("Mandei send = %d[::%s::] to [%s:%i]", send, wake_msg, udp_wdt_server.get_address (), udp_wdt_server.get_port () );
+                    if ( ( 
+                            (!question_alive) 
+                            && ( cb_new_counter <= MAX_CB_IN_A_BRANCH ) 
+                            && ( ( cb_new_counter >=  MIN_CBX_IN_A_BRANCH ) || ( disable_wdt_from_cbx ) ) 
+                    ) ) 
+                    {
+                        external_wdt = EXTERN_WDT_IDLE;
+                        if ( dmissed_wdt ) vz_debug ("kickando");
+                    }
+                    
+                    if ( dmissed_wdt ) vz_debug ("Mandei send = %d[::%s::] to [%s:%i]", send, wake_msg, udp_wdt_server.get_address (), udp_wdt_server.get_port () );
                     
                 } else if( !( strncmp( wake_msg, "reset", 5 ) ) ) {
                     external_wdt = 0;
 
                     sprintf( wake_msg, "rst:%u:", uptime );
-                    int send = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) );
+                    int send = udp_wdt_client.sendTo ( udp_wdt_server, wake_msg, strlen( wake_msg ) );
                     if( send not_eq strlen( wake_msg ) )
                     {
-                        if( debug_reconnect ) send_msg("Reconnect Extern wdt");
-                        reconnect_extern_wdt_socket();
-                        miss_wdt_send_pkg++;
+                        if( debug_reconnect ) vz_printf ("Reconnect Extern wdt");
+                        reconnect_extern_wdt_socket ();
+                        miss_wdt_send_pkg ++;
                     }
                 }
             }
@@ -879,19 +892,13 @@
 int show_cb_content ( void )
 {
     Call_Box * cb = find_CB ( v_cb, print_this_cb );
-    if ( cb not_eq NULL )
-    {
+    if ( cb not_eq NULL ) {
         cb -> print_yourself ();
-    }
-        else
-    {
-        if( print_values )
-        {
-            debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
-        }
-            else 
-        {
-            send_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
+    } else {
+        if ( print_values ) {
+            vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
+        } else {
+            vz_printf ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
         }
     }
     
@@ -900,22 +907,18 @@
 
 int show_cb_content_all ( void )
 {
-    if ( v_cb -> size () == 0 )
-    {
-        send_msg("known CBx :: 0");
+    if ( v_cb -> size () == 0 ) {
+        vz_printf ("known CBx :: 0");
     }
     
     for ( register uint8_t i = 0; i < v_cb->size(); i++ )
     {
         Call_Box * cb = (Call_Box *)v_cb->get_element( i );
                 
-        if ( cb not_eq NULL )
-        {
+        if ( cb not_eq NULL ) {
             cb -> print_yourself ();
-        }
-            else
-        {
-            if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", i );
+        } else {
+            if ( print_values ) vz_debug ("Objeto CBx ( %d ) nao encontrado", i );
         }
     }
     
@@ -924,7 +927,7 @@
 
 int show_rtp ( void )
 {
-    send_msg(":: RTP :: %u", v_cb->size() );
+    vz_printf (":: RTP :: %u", v_cb->size() );
     
     int ext_list[ MAX_CB_IN_A_BRANCH ];
         
@@ -941,7 +944,7 @@
         Call_Box * cb = find_CB( v_cb, ext_list[ i ] );
         if( cb not_eq NULL )
         {
-            send_msg("CBX ( %d,  %d ) - SIP  ( %d,  %d ) - RTP ( %d )", 
+            vz_printf ("CBX ( %d,  %d ) - SIP  ( %d,  %d ) - RTP ( %d )", 
                 cb -> get_ext (),
                 cb -> get_port (),
                 cb -> get_sip_ext (), 
@@ -954,48 +957,45 @@
     return ( 0 );
 }
 
-int fuck_rtp ( Vector * v_cb )
+int 
+fuck_rtp ( Vector * v_cb )
 {
     Call_Box * cb = find_CB( v_cb, frtp_target );
-    if ( cb not_eq NULL )
-    {
+    
+    if ( cb not_eq NULL ) {
         cb -> set_rtp_port ( -1008789032 );
-    }
-        else
-    {
-        debug_msg("frtp fail");
+    } else {
+        vz_debug ("frtp fail");
     }
     
     return ( 0 );
 }
 
-int show_hex_cb_content ( void )
+int 
+show_hex_cb_content ( void )
 {
     uint8_t * ptr = ( uint8_t * ) find_CB ( v_cb, print_hex_this_cb );    
     
     if ( ptr not_eq NULL )
     {
-        send_msg ("Values :: %p\r\n", ( void *) ptr );            
+        vz_printf ( "Values :: %p\r\n", ( void *) ptr );            
+        
         for ( register int i = 0; i < sizeof( Call_Box ); i++ )
         {
             if( debug_uart3 ) pc.printf("%x", *ptr++ );
             
             if ( ( i % 32 ) == 0 )
             {
-                if( i not_eq 0 )
-                {
+                if ( i not_eq 0 ) {
                     if( debug_uart3 ) pc.printf("\n\r> ");
-                }  
-                    else
-                {
+                } else {
                     if( debug_uart3 ) pc.printf(" ");
                 }
-            }        
-                else
-            {
+            } else {
                 if( debug_uart3 ) pc.printf(" ");
             }
         }
+        
         if ( debug_uart3 ) pc.printf("\n\r> ");
         
         if ( tcp_session ) {
@@ -1019,7 +1019,7 @@
     }
         else
     {
-        if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
+        if ( print_values ) vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
     }
     
     return ( 0 );
@@ -1029,7 +1029,7 @@
 {
     if ( v_cb -> size () == 0 )
     {
-        send_msg("known CBx :: 0");    
+        vz_printf ("known CBx :: 0");    
     }
     
     for ( register uint8_t j = 0; j < v_cb->size(); j++ )
@@ -1038,30 +1038,27 @@
                     
         if ( ptr not_eq NULL )
         {
-            send_msg ("Values :: %p\r\n", ( void *) ptr );
+            vz_printf ("Values :: %p\r\n", ( void *) ptr );
             for ( register int i = 0; i < sizeof( Call_Box ); i++ )
             {
                 if( debug_uart3 ) pc.printf("%x", *ptr++ );
                 
                 if ( ( i % 32 ) == 0 )
                 {
-                    if( i not_eq 0 )
-                    {
+                    if( i not_eq 0 ) {
                         if( debug_uart3 ) pc.printf("\n\r> ");
-                    }  
-                        else
-                    {
+                    } else {
                         if( debug_uart3 ) pc.printf(" ");
                     }
-                }        
-                    else
-                {
+                } else {
                     if( debug_uart3 ) pc.printf(" ");
                 }
             }
+            
             if ( debug_uart3 ) pc.printf("\n\r> ");
             
-            if ( tcp_session ) {
+            if ( tcp_session )
+            {
                 char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ];
                 
                 for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0;
@@ -1079,16 +1076,11 @@
                 tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) );
                 tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) );
             }
-        }
-            else
-        {
-            if ( print_values ) 
-            {
-                debug_msg ("Objeto CBx ( %d ) nao encontrado", j );
-            }
-                else 
-            {
-                send_msg ("Objeto CBx ( %d ) nao encontrado", j );
+        } else {
+            if ( print_values ) {
+                vz_debug ("Objeto CBx ( %d ) nao encontrado", j );
+            } else {
+                vz_printf ("Objeto CBx ( %d ) nao encontrado", j );
             }
         }
     }
@@ -1097,7 +1089,7 @@
 }
 
 
-int show_cB_sip ( void )
+int show_cb_sip ( void )
 {
     Call_Box * cb = find_CB ( v_cb, print_this_sip );
     
@@ -1105,35 +1097,27 @@
     {
         if( cb -> sip_print_yourself () == -1 )
         {
-            if( print_values )
-            {
-                debug_msg("Sip param of %d equals NULL", print_this_sip );
-            }
-                else 
-            {
-                send_msg("Sip param of %d equals NULL", print_this_sip );
+            if( print_values ) {
+                vz_debug ("Sip param of %d equals NULL", print_this_sip );
+            } else {
+                vz_printf ("Sip param of %d equals NULL", print_this_sip );
             }
         }
-    }
-        else
-    {
-        if ( print_values ) 
-        {
-            debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
-        }
-            else 
-        {
-            send_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
+    } else {
+        if ( print_values ) {
+            vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
+        } else {
+            vz_printf ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
         }                
     }
     
     return ( 0 );    
 }
-int show_cB_sip_all ( void )
+int show_cb_sip_all ( void )
 {    
     if ( v_cb -> size () == 0 )
     {
-        send_msg("known CBx :: 0");
+        vz_printf ("known CBx :: 0");
     }
     
     for ( register uint8_t i = 0; i < v_cb->size(); i++ )
@@ -1144,36 +1128,29 @@
         {
             if ( cb -> sip_print_yourself () == -1 )
             {
-                if ( print_values )
-                {
-                    debug_msg ("Sip param of %d equals NULL", print_this_sip );
-                }
-                    else 
-                {
-                    send_msg ("Sip param of %d equals NULL", print_this_sip );
+                if ( print_values ) {
+                    vz_debug ("Sip param of %d equals NULL", print_this_sip );
+                } else {
+                    vz_printf ("Sip param of %d equals NULL", print_this_sip );
                 }
             }
-        }
-            else
-        {
-            if( print_values )
-            {
-                debug_msg ("CBx %d not found", print_this_sip );
-            }
-                else 
-            {
-                send_msg ("CBx %d not found", print_this_sip );
+        } else {
+            if( print_values ) {
+                vz_debug ("CBx %d not found", print_this_sip );
+            } else {
+                vz_printf ("CBx %d not found", print_this_sip );
             }
         }
     }
     return ( 0 );    
 }
 
-int show_cB_hex_sip ( void )
+int show_cb_hex_sip ( void )
 {
     uint8_t * ptr = NULL;
     
     Call_Box * cb = find_CB ( v_cb, print_hex_this_sip );
+    
     if( cb not_eq NULL )
     {
         ptr = ( uint8_t * ) cb -> get_sip ();
@@ -1181,27 +1158,23 @@
 
     if ( ptr not_eq NULL )
     {
-        send_msg ("Values :: %p\r\n", ( void *) ptr );
+        vz_printf ("Values :: %p\r\n", ( void *) ptr );
         for ( register int i = 0; i < sizeof( Sip ); i++ )
         {
             if( debug_uart3 ) pc.printf("%x", *ptr++ );
             
             if ( ( i % 32 ) == 0 )
             {
-                if( i not_eq 0 )
-                {
+                if( i not_eq 0 ) {
                     if( debug_uart3 ) pc.printf("\n\r> ");
-                }  
-                    else
-                {
+                } else {
                     if( debug_uart3 ) pc.printf(" ");
                 }
-            }        
-                else
-            {
+            } else {
                 if( debug_uart3 ) pc.printf(" ");
             }
         }
+        
         if ( debug_uart3 ) pc.printf("\n\r> ");
         
         if ( tcp_session ) {
@@ -1260,7 +1233,7 @@
     }
         else
     {
-        if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
+        if ( print_values ) vz_debug ("Objeto CBx ( %d ) nao encontrado", print_this_cb );
     }
     
     
@@ -1269,13 +1242,13 @@
 
 int show_rtp_on_call ( void )
 {
-    send_msg(":: CAll RTP :: %u", v_call->size() );
+    vz_printf (":: CAll RTP :: %u", v_call->size() );
     
     for( register uint8_t i = 0; i < v_call->size(); i++ ) {
         VZ_call * call = ( VZ_call * )v_call->get_element( i );
         if( call not_eq NULL )
         {
-            send_msg("CBX ( %d,  %d ) - Server ( %d,  %d )", 
+            vz_printf ("CBX ( %d,  %d ) - Server ( %d,  %d )", 
                 call->get_cb_ext(),
                 call->get_cb_port(), 
                 call->get_rtp_server_ext(), 
@@ -1293,18 +1266,15 @@
     
     if ( call not_eq NULL )
     {
-        send_msg ("Values :: %p\r\n", ( void *) call );
+        vz_printf ("Values :: %p\r\n", ( void *) call );
         call -> print_yourself ();
     }
         else
     {            
-        if( print_values )
-        {
-            debug_msg("Call %d not found", print_this_call );
-        }
-            else 
-        {
-            send_msg("Call %d not found", print_this_call );
+        if( print_values ) {
+            vz_debug ("Call %d not found", print_this_call );
+        } else {
+            vz_printf ("Call %d not found", print_this_call );
         }
     }
     
@@ -1323,19 +1293,16 @@
 
     if ( ptr not_eq NULL )
     {
-        send_msg ("Values :: %p\r\n", ( void *) ptr );
+        vz_printf ("Values :: %p\r\n", ( void *) ptr );
         for ( register int i = 0; i < sizeof( VZ_call ); i++ )
         {
             if( debug_uart3 ) pc.printf("%x", *ptr++ );
             
             if ( ( i % 32 ) == 0 )
             {
-                if( i not_eq 0 )
-                {
+                if( i not_eq 0 ) {
                     if( debug_uart3 ) pc.printf("\n\r> ");
-                }  
-                    else
-                {
+                } else {
                     if( debug_uart3 ) pc.printf(" ");
                 }
             }        
@@ -1405,11 +1372,11 @@
     {   
         if( print_values )
         {
-            debug_msg("Call %d not found", print_this_call );
+            vz_debug ("Call %d not found", print_this_call );
         }
             else 
         {
-            send_msg("Call %d not found", print_this_call );
+            vz_printf ("Call %d not found", print_this_call );
         }
     }
     
@@ -1429,7 +1396,7 @@
 
     if ( ptr not_eq NULL )
     {
-        send_msg ("Values :: %p\r\n", ( void *) ptr );
+        vz_printf ("Values :: %p\r\n", ( void *) ptr );
         for ( register int i = 0; i < sizeof( RTP ); i++ )
         {
             if( debug_uart3 ) pc.printf("%x", *ptr++ );
@@ -1511,11 +1478,11 @@
     {   
         if( print_values )
         {
-            debug_msg("Call %d not found", print_this_rtp );
+            vz_debug ("Call %d not found", print_this_rtp );
         }
             else 
         {
-            send_msg("Call %d not found", print_this_rtp );
+            vz_printf ("Call %d not found", print_this_rtp );
         }
     }
     
@@ -1530,18 +1497,18 @@
     {
         if ( call -> check_rtp () not_eq NULL )
         {
-            send_msg ("Values :: %p\r\n", ( void *) call -> check_rtp () );
+            vz_printf ("Values :: %p\r\n", ( void *) call -> check_rtp () );
             call -> rtp_print_yourself ();
         }
             else
         {
             if( print_values )
             {
-                debug_msg("Call->RTP %d not found", print_this_rtp );
+                vz_debug ("Call->RTP %d not found", print_this_rtp );
             }
                 else 
             {
-                send_msg("Call->RTP %d not found", print_this_rtp );
+                vz_printf ("Call->RTP %d not found", print_this_rtp );
             }       
         }
     }
@@ -1549,11 +1516,11 @@
     {            
         if( print_values )
         {
-            debug_msg("Call->RTP %d not found", print_this_rtp );
+            vz_debug ("Call->RTP %d not found", print_this_rtp );
         }
             else 
         {
-            send_msg("Call->RTP %d not found", print_this_rtp );
+            vz_printf ("Call->RTP %d not found", print_this_rtp );
         }
     }
     
@@ -1577,7 +1544,7 @@
 
 int show_cb_stats ( void )
 {
-    send_msg( 
+    vz_printf ( 
         "\r\n"
         "   PKG_CKS OK: %d ( %003.2f )\r\n"
         "   PKG_CKS ERR: %d ( %003.2f )\r\n"
@@ -1603,17 +1570,16 @@
 
 int reset_missed_send_udp ( void )
 {
-    miss_fw_send_pkg = 0;                                                                                                                 
-    miss_prompt_udp_send_pkg = 0;                                                                                                         
-    miss_sip_registry_send_pkg = 0;                                                                                                       
-    miss_sip_invite_send_pkg = 0;                                                                                                         
-    miss_sip_bye_send_pkg = 0;                                                                                                            
-    miss_sip_unregistry_send_pkg = 0;                                                                                                     
-    miss_sip_ok_send_pkg = 0;                                                                                                             
+    miss_fw_send_pkg = 0;
+    miss_prompt_udp_send_pkg = 0;
+    miss_sip_registry_send_pkg = 0;
+    miss_sip_invite_send_pkg = 0;
+    miss_sip_bye_send_pkg = 0;
+    miss_sip_ok_send_pkg = 0;
     miss_sip_rcv_bye_send_pkg = 0;
     miss_wdt_send_pkg = 0;
     miss_prompt_udp_send_pkg = 0;
-    miss_ftp_udp_send_pkg = 0;
+    miss_rtp_udp_send_pkg = 0;
     miss_prompt_udp_rcv_pkg = 0;
     
     return ( 0 );
@@ -1621,13 +1587,12 @@
 
 int show_missed_send_udp_pkg ( void )
 {
-    send_msg(   "\r\nMissed pkgs ::\r\n "
+    vz_printf (   "\r\nMissed pkgs ::\r\n "
                 "FW: %d\r\n "
                 "Prompt UDP %d\r\n "
                 "Registry %d\r\n "
                 "Invite %d\r\n "
                 "Bye %d\r\n "
-                "Unregistry %d\r\n "
                 "UDP incoming ( invite ans ) %d\r\n "
                 "UDP incoming ( bye from * ) %d\r\n "
                 "Wdt [ alive | rst ] %d\r\n "
@@ -1639,85 +1604,96 @@
         miss_sip_registry_send_pkg, 
         miss_sip_invite_send_pkg, 
         miss_sip_bye_send_pkg, 
-        miss_sip_unregistry_send_pkg, 
         miss_sip_ok_send_pkg, 
         miss_sip_rcv_bye_send_pkg, 
         miss_wdt_send_pkg, 
         miss_prompt_udp_send_pkg,
         miss_prompt_udp_rcv_pkg,
-        miss_ftp_udp_send_pkg 
+        miss_rtp_udp_send_pkg 
     );
     
     return ( 0 );
 }
 
-int invite_ack_to_cb_handler ( Vector * v_cb, Vector * v_call )
+int 
+invite_ack_to_cb_handler ( Vector * v_cb, Vector * v_call )
 {    
     static int retry_invite_pkg = 0;
     bool need_retry = false;
     Call_Box * cb = NULL;
 
-    for ( register int i = 0; i < v_cb -> size (); i++ )
+    for ( register uint8_t i = 0; i < v_cb -> size (); i++ )
     {
-        retry_invite_pkg++;
-        if ( retry_invite_pkg >= v_cb->size () ) retry_invite_pkg = 0;
+        retry_invite_pkg ++;
+        if ( retry_invite_pkg >= v_cb -> size () ) retry_invite_pkg = 0;
         
         cb = (Call_Box * )v_cb -> get_element ( i );
+        
         if ( cb not_eq NULL )
         {
-            if ( ( cb -> get_status () == cb_ringing ) or ( cb -> get_status () == cb_trying ) or ( cb -> get_status () == cb_on_call ) )
+            switch ( cb -> get_status () )
             {
-                need_retry = true;
-                break;
+                case cb_ringing :
+                case cb_trying :
+                case cb_on_call :
+                    need_retry = true;
+                    break;
             }
+            
+            if ( need_retry ) break;
         }
     }
     
     if ( need_retry )
     {
+        uint16_t ext = cb -> get_ext ();
+        uint16_t port = cb -> get_port ();
+        
         if ( cb -> get_invite_response () == false )
         {
             buffer [ TIMESLICE_PLACE ] = cb -> get_timeslice ();
             
             do_not_show_this_invite_pkg = true;
             
-            send2callboxes ( build_cb_package ( cb -> get_ext (), cb -> get_port (), INVITE, ( char * )buffer,
+            send2callboxes ( build_cb_package ( ext, port, INVITE, ( char * )buffer,
                cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
 
-            //if ( debug_invite ) debug_msg ("[%d] resend invite OK to Cbx : ( %d,  %d )", cb -> get_ext (), cb -> get_ext (), cb -> get_port () );
+            if ( debug_resend_invite ) vz_debug ("[%d] resend invite OK to Cbx : ( %d,  %d )", ext, ext, port );
         } 
         
-        if ( find_Call ( v_call, cb->get_ext () ) == NULL )
+        if ( find_Call ( v_call, ext ) == NULL )
         {
-        
-            if ( ( ( cb -> get_status () == cb_ringing ) or ( cb -> get_status () == cb_trying ) ) )
+            uint8_t cb_status = cb -> get_status ();
+            
+            if ( ( ( cb_status == cb_ringing ) or ( cb_status == cb_trying ) ) )
             {
                     char rtp_src_tmp_write_buffer [ CB_BUFFER_SIZE ];
+                    
                     uint8_t rtp_dst_tmp_write_buffer [ CB_BUFFER_SIZE ];
                     
                     for ( register int i = 0; i < RTP_MSG_SIZE; i++ ) rtp_src_tmp_write_buffer [ i ] = 0x00;
                     
-                    send2callboxes ( build_cb_package ( cb -> get_ext (), cb -> get_port (), AUDIO, 
+                    send2callboxes ( build_cb_package ( ext, port, AUDIO, 
                         rtp_src_tmp_write_buffer, AUDIO, RTP_MSG_SIZE, rtp_dst_tmp_write_buffer ) );
             } else {
-                if ( cb->get_invite_retry_count() == 0 )
+                if ( cb -> get_invite_retry_count () == 0 )
                 {
-                    cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 );
+                    cb -> set_msg_id ( ( cb->get_msg_id () + 1 ) & ~BIT7 );
 
-                    for ( register uint8_t i = 0; i < v_call->size(); i++ )
+                    for ( register uint8_t i = 0; i < v_call -> size(); i++ )
                     {
-                        VZ_call * call = ( VZ_call * )v_call->get_element( i );
-                        if( call->get_cb_ext() == cb->get_ext() )
+                        VZ_call * call = ( VZ_call * )v_call -> get_element ( i );
+                        if ( call -> get_cb_ext () == ext )
                         {
-                            v_call->remove_element( i );
-                            if( call not_eq NULL ) delete( call );
+                            v_call -> remove_element ( i );
+                            if ( call not_eq NULL ) delete( call );
                             break;
                         }
                     }
                     
-                    ts->return_timeslice( cb->call_end () );
+                    ts -> return_timeslice ( cb -> call_end () );
                     
-                    if( debug_invite ) debug_msg( "[%d]-- No audio pkgs --", cb->get_ext () );
+                    if( debug_invite or debug_resend_invite ) vz_debug ( "[%d] No audio pkgs from cbx", ext );
                 }
             }
         }
@@ -1756,7 +1732,7 @@
                         send2callboxes( pkg2cb );
                     }
                     
-                } else if ( debug_main ) debug_msg ("[%d] received missed package -- Type :: %i", ext, type );
+                } else if ( debug_main ) vz_debug ("[%d] received missed package -- Type :: %i", ext, type );
             }
         }
     }
@@ -1768,18 +1744,23 @@
 {
     int return_value = 0;
     
-    if( timer_sync_refresh.read_ms() > 250 * 2 )
+    // analizar este caso com mais cuidado
+    // dado que vão ter 2 carinhas "perdidos"
+    // perceber a frequencia de envio de pacotes
+    // perceber possiveis gargalos nesses envios
+    if( timer_sync_refresh.read_ms () > 250 * 2 )
     {
-        timer_sync_refresh.reset();
+        timer_sync_refresh.reset ();
     
         static uint8_t time_to_mode = TIME_TO_REFRESH;
     
-        if ( time_to_mode == TIME_TO_REFRESH ){
+        if ( time_to_mode == TIME_TO_REFRESH )
+        {
             time_to_mode = TIME_TO_WAKE_UP;
             if ( !do_not_refresh ) return_value = refresh ( v_cb );
         } else {
             time_to_mode = TIME_TO_REFRESH;
-            if ( wake_all ) if ( v_call->size() == 0 ) wake_all_up ( v_cb );
+            if ( wake_all and ( v_call -> size() == 0 ) ) wake_all_up ( v_cb );
         }
     }
     
@@ -1811,9 +1792,9 @@
                 send2callboxes( build_cb_package( cb->get_ext (), cb->get_port (), CB_BYE,
                     ( char * )buffer, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                 
-                if( debug_invite ) debug_msg("[%d] Received Bye from *", cb->get_ext () );
+                if( debug_invite ) vz_debug ("[%d] Received Bye from *", cb->get_ext () );
             }
-        } else if( debug_main ) debug_msg("[%d] Missed bye request", ext_to__be_removed );
+        } else if( debug_main ) vz_debug ("[%d] Missed bye request", ext_to__be_removed );
     }
     
     return ( 0 );    
@@ -1835,7 +1816,7 @@
         }
         if( ts_reset && !bl_start_flag )
         {
-            if( debug_invite ) debug_msg("Resetando TS");
+            if( debug_invite ) vz_debug ("Resetando TS");
             ts->reset();
         }
     }
@@ -1843,14 +1824,17 @@
     return ( 0 );    
 }
 
+
+void show_lpc_low_level_input_counter ( void )
+{
+    vz_printf ("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter );
+    lpc_low_level_input_counter = 0;
+}
+
 int show_wdt_status ( void )
 {
-    send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter );
-    
-    lpc_low_level_input_counter = 0;
-
     if( eth_status == 0 ) {
-        send_msg( "Wdt last reset: %s - status_eth :: Connected - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )",
+        vz_printf ( "Wdt last reset: %s - status_eth :: Connected - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )",
                   ( wdt.WatchdogCausedReset() ) ? "true" : "false",
                   EXTERN_WDT_IDLE - external_wdt,
                   EXTERN_WDT_IDLE,
@@ -1858,7 +1842,7 @@
                   RX_CB_IDLE
                 );
     } else {
-        send_msg( "Wdt last reset: %s - status_eth :: Disconnected :: since %3d sec - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )",
+        vz_printf ( "Wdt last reset: %s - status_eth :: Disconnected :: since %3d sec - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )",
                   ( wdt.WatchdogCausedReset() ) ? "true" : "false",
                   ETH_CONNECT_TIMEOUT - eth_wdt,
                   EXTERN_WDT_IDLE - external_wdt,
@@ -1884,7 +1868,7 @@
     if ( pkg_wdt ) pkg_wdt--;
     if ( eth_wdt ) eth_wdt--;
 
-    if ( eth_wdt && external_wdt && pkg_wdt ){
+    if ( eth_wdt && external_wdt && ( pkg_wdt || disable_wdt_from_cbx ) ){
         wdt.kick();
         return ( 0 );
     }
@@ -1901,7 +1885,7 @@
         {
             if (  ( cb->get_status () == cb_idle ) && ( cb->get_sip_status () == sip_idle ) && ( cb -> is_rtp_timer_timeout () ) )
             {
-                if ( debug_reset_rtp ) debug_msg( "[%d] rtp reset", cb -> get_ext () );
+                if ( debug_reset_rtp ) vz_debug ( "[%d] rtp reset", cb -> get_ext () );
                 cb -> cb_set_status( cb_idle );
                 cb -> set_sip_status ( sip_idle );
                 cb -> reset_rtp_timer ();
@@ -1920,14 +1904,14 @@
     {
         xmemcpy ( buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE );
         status = WAITING;
-        missed_pkg--;
+        missed_pkg --;
     }
         else
     // long path
     {
         xmemcpy ( cb_rx_buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE );
         status = WAITING;
-        missed_pkg--;
+        missed_pkg --;
         xmemcpy ( buffer, cb_rx_buffer, CB_BUFFER_SIZE );
   
         if ( debug_show_rx_cpld )
@@ -1944,7 +1928,7 @@
             
             strcat ( str, "\n\r " );
             
-            send_msg ( "%s", str );
+            vz_printf ( "%s", str );
         }            
     }
 
@@ -1962,13 +1946,13 @@
         
         if ( type == TELEMETRY )
         {
-            telemetry_counter++;
+            telemetry_counter ++;
             if ( debug_telemetry ) show_last_rx = true;
         }
 
         if( type not_eq AUDIO )
         {
-            if ( debug_cb_rx ) { send_msg ("[%d %d] -- Type :: %d", ext, port, type ); }
+            if ( debug_cb_rx ) { vz_printf ("[%d %d] -- Type :: %d", ext, port, type ); }
             
             if( 
                 type == TELEMETRY or
@@ -1981,7 +1965,7 @@
                 type == FW6
              ) type = FW;
             
-            if ( debug_sqn ) { send_msg ("[%d %d] -- Type :: %d -- seq_num :: %u", ext, port, type, cb_tx_buffer [ SEQ_NUM_PLACE ] ); }
+            if ( debug_sqn ) { vz_printf ("[%d %d] -- Type :: %d -- seq_num :: %u", ext, port, type, cb_tx_buffer [ SEQ_NUM_PLACE ] ); }
 
             Call_Box * cb = find_CB ( v_cb, ext );
             if ( cb not_eq NULL ) 
@@ -1993,25 +1977,25 @@
                         send2callboxes( build_cb_package( ext, port, REGISTRY,
                             ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
                     } else {
-                        if ( debug_main ) debug_msg("[%d] Received ack pkg with seq_num %d", ext, data[ 0 ] );
+                        if ( debug_main ) vz_debug ("[%d] Received ack pkg with seq_num %d", ext, data[ 0 ] );
 
                         switch ( type )
                         {
                             case INVITE : {
-                                if ( debug_main or debug_invite ) debug_msg ("[%d] Invite ACK - msg_id %d -- Cbx seqNum %d", ext, cb->get_msg_id(), data[ 0 ] );
+                                if ( debug_main or debug_invite ) vz_debug ("[%d] Invite ACK - msg_id %d -- Cbx seqNum %d", ext, cb->get_msg_id(), data[ 0 ] );
                                 break;
                             }
                             case CB_BYE : {
-                                if ( debug_main or debug_invite ) debug_msg ("[%d] BYE ACK - msg_id %d", ext, cb->get_msg_id() );
+                                if ( debug_main or debug_invite ) vz_debug ("[%d] BYE ACK - msg_id %d", ext, cb->get_msg_id() );
                                 cb -> set_bye_response_ok ();
                                 break;
                             }
                             case REGISTRY : {
-                                if ( debug_main or debug_aging ) debug_msg ("[%d] Registry ACK - msg_id %d", ext, cb->get_msg_id() );
+                                if ( debug_main or debug_aging ) vz_debug ("[%d] Registry ACK - msg_id %d", ext, cb->get_msg_id() );
                                 break;
                             }
                             default : {
-                                if ( debug_main or debug_aging ) debug_msg ("[%d] ACK msg_id :: %d :: type %d", ext, cb->get_msg_id(), type );
+                                if ( debug_main or debug_aging ) vz_debug ("[%d] ACK msg_id :: %d :: type %d", ext, cb->get_msg_id(), type );
                             }
                         }
                         if ( type not_eq REGISTRY and type not_eq CB_BYE and type not_eq INVITE ) type = DO_NOTHING;
@@ -2022,7 +2006,7 @@
                             {
                                 if ( call -> get_elapsed_time () < 120000 )
                                 {
-                                    if ( debug_invite ) debug_msg("[%d] ack bye ignored", ext );
+                                    if ( debug_invite ) vz_debug ("[%d] ack bye ignored", ext );
                                     type = DO_NOTHING;
                                 }
                             }
@@ -2068,7 +2052,7 @@
         
         char cmd_msg [ CB_BUFFER_SIZE ] = "pend\r";
         
-        if ( debug_hello ) debug_msg("Enviando pend_all nro [ %i ]", hello_times ); 
+        if ( debug_hello ) vz_debug ("Enviando pend_all nro [ %i ]", hello_times ); 
         
         send2callboxes( build_cb_package( BROADCAST_EXT, BROADCAST_EXT, PROMPT, cmd_msg, ( 0x11 + hello_times ), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) );
         
@@ -2078,7 +2062,7 @@
 
 void show_hello_status_function ( void )
 {
-    send_msg ("hello_sync.read :: %d -- hello_times :: %u", ( int ) hello_sync.read (), hello_times );        
+    vz_printf ("hello_sync.read :: %d -- hello_times :: %u", ( int ) hello_sync.read (), hello_times );        
 }
 
 void show_last_rx_pkg_from_cbx ( void )
@@ -2095,14 +2079,14 @@
         
         if ( ( i not_eq 0 ) && !( ( i + 1 ) % 25 ) )
         { 
-            send_msg ( "%s", str );
+            vz_printf ( "%s", str );
             strcpy ( str, "" );
         } 
         
         else { strcat ( str, " " ); }
     }
     
-    send_msg ( "%s", str );
+    vz_printf ( "%s", str );
 }
 
 void show_last_tx_pkg_from_cbx ( void )
@@ -2119,51 +2103,154 @@
         
         if ( ( i not_eq 0 ) && !( ( i + 1 ) % 25 ) )
         { 
-            send_msg ( "%s", str );
+            vz_printf ( "%s", str );
             strcpy ( str, "" );
         } 
         
         else { strcat ( str, " " ); }
     }
     
-    send_msg ( "%s", str );
+    vz_printf ( "%s", str );
 }
 
 /* Funcao para leitura da fonte de alimentacao e aviso ao servidor */
 void check_power_source ( void )
 {
     static uint8_t samples = 0, warn_back = 0, wait_to_warn = 0; 
-    //static uint16_t wait_to_warn = 0;
 
-    pwr_src_timer.stop();
-    pwr_src_timer.reset();
+    power_source_timer.stop ();
+    power_source_timer.reset ();
 
-    if (pwr_src_in) {
-        if (samples < 8) samples++;
+    if ( pwr_src_in )
+    {
+        if ( samples < 8 ) samples ++;
     } else {
-        if (samples > 0) samples--;
+        if ( samples > 0 ) samples --;
     }
     
-    if (wait_to_warn) wait_to_warn--;
+    if ( wait_to_warn ) wait_to_warn --;
     
-    if (samples >= 8) {
-        pwr_src_status = 1;
-        if (!wait_to_warn) {         
-            wait_to_warn = 255;
+    if ( samples >= 8 )
+    {
+        power_source_status = 1;
+        if (!wait_to_warn )
+        {
+            wait_to_warn = u8_WAIT_TO_WARN; 
             warn_back = 1;
-            pwr_src_client.sendTo( pwr_src_server, "mainpowerisdown", strlen( "mainpowerisdown" ) );
-            debug_msg( "Main power is DOWN!" );
+            int power_source_client_ret = power_source_client.sendTo ( pwr_src_server, "mainpowerisdown", u8_POWER_MSG_LENGTH );
+            
+            if ( power_source_client_ret not_eq u8_POWER_MSG_LENGTH )
+            {
+                reconnect_power_source ();
+                miss_power_source_send_pkg ++;
+                if ( debug_reconnect ) vz_debug (
+                    "Reconnect power_source_client_ret [ %d - %d ]", 
+                    power_source_client_ret, u8_POWER_MSG_LENGTH 
+                );
+            }
+                
+            vz_debug ( "Main power is DOWN!");
         } else {
             wait_to_warn--;
         }
     }
-    if ((samples == 0) and (warn_back)) {
-        pwr_src_status = 0;
+    
+    if ( ( samples == 0 ) and ( warn_back ) )
+    {
+        power_source_status = 0;
         warn_back = 0;
         wait_to_warn = 0;
-        pwr_src_client.sendTo( pwr_src_server, "mainpowerisback", strlen( "mainpowerisback" ) );
-        debug_msg( "Main power is BACK!" );
+        int power_source_client_ret = power_source_client.sendTo ( pwr_src_server, "mainpowerisback", u8_POWER_MSG_LENGTH );
+        if ( power_source_client_ret not_eq u8_POWER_MSG_LENGTH );
+        {
+            reconnect_power_source ();
+            miss_power_source_send_pkg ++;
+            if ( debug_reconnect ) vz_debug (
+                "Reconnect power_source_client_ret [ %d - %d ]", 
+                power_source_client_ret, u8_POWER_MSG_LENGTH 
+            );
+        }
+        vz_debug ( "Main power is BACK!" );
+    }
+    
+    power_source_timer.start ();
+}
+
+void update_config_values ( void )
+{
+    if ( cm -> min_ext_was_modified () or cm -> max_ext_was_modified () ) init_ranges ();
+    
+    if ( cm -> header_ip_was_modified () or 
+            cm -> net_mask_was_modified () or
+                cm -> gateway_was_modified () ) 
+    {
+        __reconnect ();    
+    }
+    
+    if  ( cm -> header_ip_was_modified () or 
+            cm -> shift_port_was_modified () or
+                cm -> server_ext_was_modified () or
+                    cm -> server_port_was_modified () or
+                        cm -> server_ip_was_modified ()
+        ) 
+    {
+        for ( register uint8_t i = 0; i < v_cb -> size (); i++ )
+        {
+            Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( i );
+            
+            if  ( cb not_eq NULL ) {
+                cb -> update ();
+            }
+        }                            
     }
     
-    pwr_src_timer.start();
+    if ( cm -> server_ip_was_modified () ) reconnect_power_source ();
+    
+    if ( cm -> fw_server_ip_was_modified () or cm -> fw_server_port_was_modified () ) {
+        re_start_fw ();
+    }
+}
+
+char * build_wdt_string ( char * wake_msg, const size_t length )
+{
+    if ( wake_msg == NULL ) return ( NULL );
+    
+    snprintf( wake_msg, length,"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u:", 
+        uptime, 
+        invite_counter, 
+        external_wdt, 
+        ( wdt.WatchdogCausedReset() ) ? '1' : '0', 
+        cb_new_counter, 
+        v_cb->size(),
+        ts->remain_timeslices(), 
+        sip_socket_send_failure, 
+        v_call->size(),
+        pkg_cksok,
+        pkg_ckserr,
+        pkg_zero,
+        out_of_range,
+        missed_pkg,
+        delayed_pkg_to_cb,
+        cpld_pkg_tx_counter,
+        cpld_pkg_rx_counter,
+        eth_wdt,
+        pkg_wdt,
+        miss_fw_send_pkg,
+        miss_prompt_udp_send_pkg,
+        miss_sip_registry_send_pkg,
+        miss_sip_invite_send_pkg,
+        miss_sip_bye_send_pkg,
+        miss_sip_ok_send_pkg,
+        miss_sip_rcv_bye_send_pkg,
+        miss_wdt_send_pkg,
+        miss_rtp_udp_send_pkg,
+        miss_prompt_udp_rcv_pkg,
+        miss_clock_send_pkg,
+        miss_sip_inc_pkg,
+        miss_power_source_send_pkg,
+        miss_bl_udp_send_pkg,
+        miss_rtp_udp_rcv_pkg
+    );
+    
+    return ( wake_msg );
 }
\ No newline at end of file