VZTECH / Mbed 2 deprecated main_src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Files at this revision

API Documentation at this revision

Comitter:
klauss
Date:
Mon Nov 24 16:43:16 2014 +0000
Parent:
73:3b4e282eeff7
Child:
75:bd3c647b860b
Commit message:
validando organiza??o de arquivos | ainda em desenvolvimento.

Changed in this revision

UART3Interrupt.cpp Show annotated file Show diff for this revision Revisions of this file
UART3Interrupt.h Show annotated file Show diff for this revision Revisions of this file
bootloader_cbx.cpp Show annotated file Show diff for this revision Revisions of this file
bootloader_cbx.h Show annotated file Show diff for this revision Revisions of this file
bootloader_cbx_handler.cpp Show diff for this revision Revisions of this file
bootloader_cbx_handler.h Show diff for this revision Revisions of this file
call.cpp Show annotated file Show diff for this revision Revisions of this file
call.h Show annotated file Show diff for this revision Revisions of this file
call_box.cpp Show annotated file Show diff for this revision Revisions of this file
call_box.h Show annotated file Show diff for this revision Revisions of this file
call_box_manager.cpp Show annotated file Show diff for this revision Revisions of this file
call_box_manager.h Show annotated file Show diff for this revision Revisions of this file
call_manager.cpp Show annotated file Show diff for this revision Revisions of this file
call_manager.h Show annotated file Show diff for this revision Revisions of this file
configs.cpp Show annotated file Show diff for this revision Revisions of this file
configs.h Show annotated file Show diff for this revision Revisions of this file
debug.cpp Show annotated file Show diff for this revision Revisions of this file
debug.h Show annotated file Show diff for this revision Revisions of this file
eth.cpp Show annotated file Show diff for this revision Revisions of this file
eth.h Show annotated file Show diff for this revision Revisions of this file
file_system_manager.cpp Show annotated file Show diff for this revision Revisions of this file
file_system_manager.h Show annotated file Show diff for this revision Revisions of this file
flood.cpp Show annotated file Show diff for this revision Revisions of this file
flood.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
parallelcpld.cpp Show annotated file Show diff for this revision Revisions of this file
parallelcpld.h Show annotated file Show diff for this revision Revisions of this file
prompt.cpp Show annotated file Show diff for this revision Revisions of this file
prompt.h Show annotated file Show diff for this revision Revisions of this file
ring_buffer.h Show annotated file Show diff for this revision Revisions of this file
rtp.h Show annotated file Show diff for this revision Revisions of this file
rtpbuf.cpp Show annotated file Show diff for this revision Revisions of this file
rtpbuf.h Show annotated file Show diff for this revision Revisions of this file
shared_variables.cpp Show annotated file Show diff for this revision Revisions of this file
shared_variables.h Show annotated file Show diff for this revision Revisions of this file
sip.cpp Show annotated file Show diff for this revision Revisions of this file
sip.h Show annotated file Show diff for this revision Revisions of this file
sip_manager.cpp Show annotated file Show diff for this revision Revisions of this file
sip_manager.h Show annotated file Show diff for this revision Revisions of this file
telemetry.cpp Show annotated file Show diff for this revision Revisions of this file
telemetry.h Show annotated file Show diff for this revision Revisions of this file
utils.cpp Show annotated file Show diff for this revision Revisions of this file
utils.h Show annotated file Show diff for this revision Revisions of this file
vector.cpp Show annotated file Show diff for this revision Revisions of this file
vz_protocol.cpp Show annotated file Show diff for this revision Revisions of this file
vz_protocol.h Show annotated file Show diff for this revision Revisions of this file
wdt_manager.cpp Show annotated file Show diff for this revision Revisions of this file
wdt_manager.h Show annotated file Show diff for this revision Revisions of this file
--- a/UART3Interrupt.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/UART3Interrupt.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,41 +1,30 @@
-#include "mbed.h"
-#include <stdint.h>
 #include "UART3Interrupt.h"
-#include "configs.h"
 
-char RXBuffer[DATA_SIZE];                         // UART3 RX Buffer
-//volatile uint8_t IntBuff[900];                 // Interrupt Buffer
-//static volatile uint8_t *RXHeadPtr;                  // Buffer Head Pointer
-//static volatile uint8_t *RXTailPtr;                  // Buffer Tail Pointer 
-//static volatile uint16_t move = 0;                       
-//uint8_t status = 0;
+char RXBuffer[__CB_BUFFER_SIZE__];
+///< UART3 RX Buffer
+
 volatile uint16_t RX_c = 0;   
 
-void SerialRecvInterrupt (void) {                 // UART3 Serial Interrupt Handler
+///< UART3 Serial Interrupt Handler
+void SerialRecvInterrupt( void ){
+    while ( LPC_UART3 -> LSR & ( 0<<1 ) ) {}
+    // Receive data from UART3 RX
+    *( RXBuffer + RX_c ) = LPC_UART3 -> RBR;
     
-    while ( LPC_UART3->LSR & (0<<1) ) {}     
-    *(RXBuffer+RX_c) = LPC_UART3->RBR;          // Receive data from UART3 RX
-    
-    if (RXBuffer[RX_c] != RXBuffer[RX_c-1]) {
+    if( RXBuffer[ RX_c ] != RXBuffer[ RX_c - 1 ] ){
        // led3 =!led3;    
     }
     
     RX_c++;
     
-    if ( RX_c == 300 )
-    { 
-       status = 1;
+    if ( RX_c == 300 ){ 
+       status = __READ__;
     }
-        
 }
 
 void RXFrameSync (void) {
-    
-//    led1 = !led1;
-//    led4 = !led4;
-    
     RX_c = 0;
-    status = 0;
+    status = __WAITING__;
 }
 
 
--- a/UART3Interrupt.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/UART3Interrupt.h	Mon Nov 24 16:43:16 2014 +0000
@@ -1,13 +1,16 @@
 #ifndef _UART3INTERRUPT_H
 #define _UART3INTERRUPT_H
-#include "configs.h"
 
-extern char RXBuffer[DATA_SIZE];          // UART3 RX Buffer
+#include <stdint.h>
+#include "mbed.h"
+#include "vz_protocol.h"
+
+extern char RXBuffer[ __CB_BUFFER_SIZE__ ];
+///< UART3 RX Buffer
 extern volatile uint8_t status;
 
 void SerialRecvInterrupt (void);
-//void RcvRX( void );
-//void initRX ( void );
+
 void RXFrameSync (void);
 
 #endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootloader_cbx.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,95 @@
+#include "bootloader_cbx.h"
+
+Timer bl_timer;
+bool listen_udp = false;
+char last_client_ip[ 16 ];
+int last_client_port;
+UDPSocket bl_cbx_server;
+Endpoint bl_cbx_client;
+
+int init_bl_handler( void ){
+    bl_timer.stop();
+    bl_timer.reset();
+    bl_timer.start();
+    
+    int bind_ret = bl_cbx_server.bind( UDP_BOOTLOADER_PORT );
+    
+    bl_cbx_server.set_blocking( false, 2 );
+    
+    return( bind_ret );
+}
+
+char * listen_bl_socket( char * buffer, int *length ){
+    *length = bl_cbx_server.receiveFrom( bl_cbx_client, buffer, __CB_BUFFER_SIZE__ );
+    
+    if( *length == -1 ){
+        int ret = bl_cbx_server.bind( UDP_BOOTLOADER_PORT );    
+        
+        if( ret == -1 ){
+            bl_cbx_server.close(); 
+            bl_cbx_server.bind( UDP_BOOTLOADER_PORT );
+            //FIXME colocar alguma variavel de status pra nem mandar msgs eth caso nao tenha conectado
+        }
+    }else if( *length > 0){
+        buffer[ *length ] = '\0';
+        buffer[ strlen( buffer ) - 1 ] = '\0';
+        bl_timer.reset();
+        return( buffer );
+    }    
+    return( NULL );
+}
+
+int bl_handler( void ){
+    int length = 0;
+    char bl_msg[ 320 ];
+    char * bl_data;
+    int bl_ext;
+    int bl_port;
+    static int id_msg = 0x11;
+    
+    if( listen_udp ){
+        listen_bl_socket( bl_msg, &length );
+        if( bl_timer.read() > 60 ){
+            listen_udp = false;
+            bl_timer.reset();    
+        }
+    }else if( bl_timer.read() > 7 && !listen_udp ){
+        listen_bl_socket( bl_msg, &length );
+        if( length > 0 ){ 
+            listen_udp = true;
+            strcpy( last_client_ip, bl_cbx_client.get_address() );
+            last_client_port = bl_cbx_client.get_port();
+        }else bl_timer.reset();
+    }
+    
+    if( length > 0 ){
+        uint8_t bl_msg_to_cbx[ __CB_BUFFER_SIZE__ ];
+        send_msg("Bootloader order received");
+        bl_data = strtok( bl_msg, " " ); 
+        bl_ext = atoi( bl_data );
+        bl_data += strlen( bl_data) + 1;
+        
+        bl_port = convert_ext_to_port( bl_ext );
+        
+        send_msg("Received msg from :: %s:%d to CBx %i", last_client_ip, last_client_port, bl_ext );
+        send_msg("Message received == %s--", bl_data );
+        send2callboxes( __build_cb_package__( bl_ext, bl_port, __BOOTLOADER_CBX__, bl_data, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, bl_msg_to_cbx ) );
+        
+        //FIXME talvez nao seja preciso do strcat
+        strcat( bl_data, "\n\r" );
+        int sent = bl_cbx_server.sendTo( bl_cbx_client, bl_data, strlen( bl_data ) );
+        
+        if( dbl ) send_msg("%i bytes de resposta", sent);
+        
+        return( sent );
+    }
+    return( 0 );    
+}
+
+int bl_cbx_reply_to_eth( int ext, char * eth_data ){
+    int sent = bl_cbx_server.sendTo( bl_cbx_client, eth_data, strlen( eth_data ) );
+        
+    if( dbl ) send_msg( "%i bytes de resposta", sent );
+    
+    return( sent );
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bootloader_cbx.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,46 @@
+/**
+ * @file bootloader_cbx_handler.h
+ * @Synopsis Implementa as funcionalidades de comunicação Eth->Cbx necessárias para a gravação do CBx
+ * @author Jhonatan Casale
+ * @version 1
+ * @date 2014-11-06
+ */
+#ifndef __BOOTLOADER_CBX_HANDLER_H__
+#define __BOOTLOADER_CBX_HANDLER_H__
+
+#include "debug.h"
+#include "vz_protocol.h"
+#include "parallelcpld.h"
+#include "utils.h"
+
+#define udp_idle 0x00
+///< Variáveis de controle do inicio do protocolo de comunicação, não utilizadas atualmente.
+#define udp_waiting_start_pkg 0x01
+///< Variáveis de controle do inicio do protocolo de comunicação, não utilizadas atualmente.
+#define udp_listen 0x02
+///< Variáveis de controle do inicio do protocolo de comunicação, não utilizadas atualmente.
+
+extern bool listen_udp;
+///< Variável de controle que habilita o processamento continuo de pacotes chegando na porta eth.
+extern Timer bl_timer;
+///< Timer de controle responsavel por dar timeout por inatividade ( ausência de chegada de pacotes eth ).
+extern UDPSocket bl_cbx_server;
+///< Socket de controle da conexão eth.
+extern Endpoint bl_cbx_client;
+///< Socket de controle da conexão eth.
+
+extern char last_client_ip[ 16 ];
+///< Variável de controle histórico.
+extern int last_client_port;
+///< Variável de controle histórico.
+
+int init_bl_handler( void );
+///< Inicia as funcionalidade necessárias para o uso do protocolo.
+char * listen_bl_socket( char * buffer, int *length );
+///< Função responsavel por ouvir a porta UDP verificando se existem dados para processamento.
+int bl_handler( void );
+///< Responsavel por controlar em que momento a porta UDP será ouvida e controla o fluxo dos dados eth->CBx.
+int bl_cbx_reply_to_eth( int ext, char * data );
+///< Envia o pacote recebido para a referência eth contida nos sockets.
+
+#endif
\ No newline at end of file
--- a/bootloader_cbx_handler.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-#include "bootloader_cbx_handler.h"
-
-Timer bl_timer;
-bool listen_udp = false;
-char last_client_ip[ 16 ];
-int last_client_port;
-UDPSocket bl_cbx_server;
-Endpoint bl_cbx_client;
-
-int init_bl_handler( void ){
-    bl_timer.stop();
-    bl_timer.reset();
-    bl_timer.start();
-    
-    int bind_ret = bl_cbx_server.bind( UDP_BOOTLOADER_PORT );
-    
-    bl_cbx_server.set_blocking( false, 2 );
-    
-    return( bind_ret );
-}
-
-char * listen_bl_socket( char * buffer, int *length ){
-    *length = bl_cbx_server.receiveFrom( bl_cbx_client, buffer, __CB_BUFFER_SIZE__ );
-    
-    if( *length == -1 ){
-        int ret = bl_cbx_server.bind( UDP_BOOTLOADER_PORT );    
-        
-        if( ret == -1 ){
-            bl_cbx_server.close(); 
-            bl_cbx_server.bind( UDP_BOOTLOADER_PORT );
-            //FIXME colocar alguma variavel de status pra nem mandar msgs eth caso nao tenha conectado
-        }
-    }else if( *length > 0){
-        buffer[ *length ] = '\0';
-        buffer[ strlen( buffer ) - 1 ] = '\0';
-        bl_timer.reset();
-        return( buffer );
-    }    
-    return( NULL );
-}
-
-int bl_handler( void ){
-    int length = 0;
-    char bl_msg[ 320 ];
-    char * bl_data;
-    int bl_ext;
-    int bl_port;
-    static int id_msg = 0x11;
-    
-    if( listen_udp ){
-        listen_bl_socket( bl_msg, &length );
-        if( bl_timer.read() > 60 ){
-            listen_udp = false;
-            bl_timer.reset();    
-        }
-    }else if( bl_timer.read() > 7 && !listen_udp ){
-        listen_bl_socket( bl_msg, &length );
-        if( length > 0 ){ 
-            listen_udp = true;
-            strcpy( last_client_ip, bl_cbx_client.get_address() );
-            last_client_port = bl_cbx_client.get_port();
-        }else bl_timer.reset();
-    }
-    
-    if( length > 0 ){
-        uint8_t bl_msg_to_cbx[ __CB_BUFFER_SIZE__ ];
-        send_msg("Bootloader order received");
-        bl_data = strtok( bl_msg, " " ); 
-        bl_ext = atoi( bl_data );
-        bl_data += strlen( bl_data) + 1;
-        
-        bl_port = convert_ext_to_port( bl_ext );
-        
-        send_msg("Received msg from :: %s:%d to CBx %i", last_client_ip, last_client_port, bl_ext );
-        send_msg("Message received == %s--", bl_data );
-        __send_to_cb__( __build_cb_package__( bl_ext, bl_port, __BOOTLOADER_CBX__, bl_data, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, bl_msg_to_cbx ) );
-        
-        //FIXME talvez nao seja preciso do strcat
-        strcat( bl_data, "\n\r" );
-        int sent = bl_cbx_server.sendTo( bl_cbx_client, bl_data, strlen( bl_data ) );
-        
-        if( dbl ) send_msg("%i bytes de resposta", sent);
-        
-        return( sent );
-    }
-    return( 0 );    
-}
-
-int bl_cbx_reply_to_eth( int ext, char * eth_data ){
-    int sent = bl_cbx_server.sendTo( bl_cbx_client, eth_data, strlen( eth_data ) );
-        
-    if( dbl ) send_msg( "%i bytes de resposta", sent );
-    
-    return( sent );
-}
\ No newline at end of file
--- a/bootloader_cbx_handler.h	Wed Nov 19 14:06:13 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-/**
- * @file bootloader_cbx_handler.h
- * @Synopsis Implementa as funcionalidades de comunicação Eth->Cbx necessárias para a gravação do CBx
- * @author Jhonatan Casale
- * @version 1
- * @date 2014-11-06
- */
-#ifndef __BOOTLOADER_CBX_HANDLER_H__
-#define __BOOTLOADER_CBX_HANDLER_H__
-
-#include "prompt.h"
-#include "debug.h"
-#include "vz_protocol.h"
-
-#define udp_idle 0x00
-///< Variáveis de controle do inicio do protocolo de comunicação, não utilizadas atualmente.
-#define udp_waiting_start_pkg 0x01
-///< Variáveis de controle do inicio do protocolo de comunicação, não utilizadas atualmente.
-#define udp_listen 0x02
-///< Variáveis de controle do inicio do protocolo de comunicação, não utilizadas atualmente.
-
-extern bool listen_udp;
-///< Variável de controle que habilita o processamento continuo de pacotes chegando na porta eth.
-extern Timer bl_timer;
-///< Timer de controle responsavel por dar timeout por inatividade ( ausência de chegada de pacotes eth ).
-extern UDPSocket bl_cbx_server;
-///< Socket de controle da conexão eth.
-extern Endpoint bl_cbx_client;
-///< Socket de controle da conexão eth.
-
-extern char last_client_ip[ 16 ];
-///< Variável de controle histórico.
-extern int last_client_port;
-///< Variável de controle histórico.
-
-int init_bl_handler( void );
-///< Inicia as funcionalidade necessárias para o uso do protocolo.
-char * listen_bl_socket( char * buffer, int *length );
-///< Função responsavel por ouvir a porta UDP verificando se existem dados para processamento.
-int bl_handler( void );
-///< Responsavel por controlar em que momento a porta UDP será ouvida e controla o fluxo dos dados eth->CBx.
-int bl_cbx_reply_to_eth( int ext, char * data );
-///< Envia o pacote recebido para a referência eth contida nos sockets.
-
-#endif
\ No newline at end of file
--- a/call.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/call.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,5 +1,4 @@
 #include "call.h"
-#include "debug.h"
 
 VZ_call::VZ_call( int cb_ext, int cb_port, int rtp_server_ext, int rtp_server_port ){
     this->cb_ext = cb_ext;
--- a/call.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/call.h	Mon Nov 24 16:43:16 2014 +0000
@@ -9,15 +9,15 @@
 #ifndef __CALL_H__
 #define __CALL_H__
 
-#include "rtp.h"
-#include "rtpbuf.h"
+#include <stdlib.h>
+#include <stdint.h>
 #include "mbed.h"
 #include "EthernetInterface.h"
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
 #include "object.h"
 #include "vz_protocol.h"
+#include "rtp.h"
+#include "rtpbuf.h"
+#include "debug.h"
 
 extern DigitalOut led1;
 
--- a/call_box.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/call_box.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,5 +1,4 @@
 #include "call_box.h"
-#include "prompt.h"
 
 Call_Box::Call_Box( int ext, int port ){
     this->ext = ext;
--- a/call_box.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/call_box.h	Mon Nov 24 16:43:16 2014 +0000
@@ -13,6 +13,7 @@
 #include "object.h"
 #include "sip.h"
 #include "debug.h"
+
 #define __TIMEOUT__  30  
 ///< O tempo que a Header demora para "pingar" o Call_Box para saber se esta tudo bem.
 #define __MAX_ATTEMPTS__  5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/call_box_manager.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,34 @@
+#include "call_box_manager.h"
+
+Call_Box * __find_CB__( Vector * v_cb, int ext ){
+    Call_Box * cb = NULL;
+    for( register int i = 0; i < v_cb->size(); i++ ){
+        cb = ( Call_Box * )v_cb->get_element( i );
+        if( cb->get_ext() == ext ) return( cb );
+    }
+    return( NULL );
+}
+
+void registry_aging( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){
+    Call_Box * cb = NULL;
+    if( v_cb && data && write_buffer ){
+        for( register int i = 0; i < v_cb->size(); i++ ){
+            cb = (Call_Box * )v_cb->get_element( i );
+            if( cb->is_timeout() ){
+                if( cb->reconfigure_timeout() == 0x00 ){
+                    if( debug_alive ) debug_msg("( ext %d removed )", cb->get_ext() );
+                    //cb->unregistry();
+                    v_cb->remove_element( i );
+                    delete( cb );
+                    break;
+                }else{
+                    if( debug_alive ) debug_msg("Ping Cbx %d", cb->get_ext() );      
+                    cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) );                
+                    send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __REGISTRY__, 
+                        ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
+                    cb->registry();
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/call_box_manager.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,55 @@
+#ifndef __CALL_BOX_MANAGER_H__
+#define __CALL_BOX_MANAGER_H__
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "debug.h"
+#include "vz_protocol.h"
+#include "vector.h"
+#include "call_box.h"
+#include "parallelcpld.h"
+
+/**
+ * @Synopsis Busca por um determinado Call_box no vetor de Call_box usando como chave de busca o ramal.
+ *
+ * @param v_cb O vetor contendo todos os Call_box conhecidos pela Header em determinado momento.
+ * @param ext O ramal pelo qual se irá buscar o CBx.
+ *
+ * @return NULL caso não tenha sido encontrado nenhum CBx com esse ramal; retorna um ponteiro para o Call_box que possui esse ramal,
+ * caso o mesmo tenha sido encontrado.
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *  Vector * v_cb = new Vector();
+ *      //assumindo que esse vetor de Call_Box já foi populado.
+ *  int ext = 5218;
+ *  Call_Box * cb = __find_CB__( v_cb, ext );
+ * ...
+ * @endcode
+ */
+Call_Box * __find_CB__( Vector * v_cb, int ext );
+
+/**
+ * @Synopsis Função responsavel por "envelhecer" os registros na Header, na prática, é essa função que pergunta de tempo
+ * em tempo se o CBx ainda continua ativo; Essa função também é responsavel por remover o CBx do v_cb assim como deletar o elemento cb
+ * assossiado.
+ *
+ * @param v_cb Um vetor contendo todos os Call_box conhecidos pela Header em um determinado momento.
+ * @param data Usado para a criação do pacote de "ping" que a Header irá enviar para o CBx.
+ * @param write_buffer Local de memória onde efetivamente irá ser montado o pacote para envio ao CBx do pacote de "ping" ( Registry ).
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *  Vector * v_cb = new Vector();
+ *      //assumindo que esse vetor de Call_Box já foi populado.
+ *  uint8_t buffer[ 300 ];
+ *      uint8_t write_buffer[ 300 ];
+ *  registry_aging( v_cb, buffer, write_buffer );
+ * ...
+ * @endcode
+ */
+void registry_aging( Vector * v_cb, uint8_t * data, uint8_t * write_buffer );
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/call_manager.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,34 @@
+#include "call_manager.h"
+
+VZ_call * __find_Call__( Vector * v_call, int ext ){
+    VZ_call * call = NULL;
+    for( register int i = 0; i < v_call->size(); i++ ){
+        call = ( VZ_call * )v_call->get_element( i );
+        if( call->get_cb_ext() == ext ) return( call );
+    }
+    return( NULL );
+}
+
+/* remove calls por timeout */
+void call_manager( Vector * v_call, Vector * v_cb, uint8_t * data, uint8_t * write_buffer, Timeslice * ts ){
+    for( register int i = 0; i < v_call->size(); i++ ){
+        VZ_call * call = ( VZ_call * )v_call->get_element( i );
+        if( call->is_timetofinish() ){
+            v_call->remove_element( i );
+            Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() );
+            if( cb ){ 
+                cb->status = cb_idle;
+                ts->return_timeslice( cb->get_timeslice() );
+                cb->set_timeslice( 0x00 );
+                data[ __TIMESLICE_PLACE__ ] = 0x00;
+                cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) );
+                send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __CB_BYE__, 
+                    ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
+                cb->send_bye();
+                set_status( cb->sip->status, sip_idle );
+                cb->re_start_timer();
+            }
+            delete( call );    
+        }
+    }    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/call_manager.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,61 @@
+#ifndef __CALL_MANAGER_H__
+#define __CALL_MANAGER_H__
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "debug.h"
+#include "vz_protocol.h"
+#include "vector.h"
+#include "call.h"
+#include "call_box.h"
+#include "timeslice.h"
+#include "parallelcpld.h"
+#include "call_box_manager.h"
+#include "utils.h"
+
+/**
+ * @Synopsis Busca por uma determinada ligação vz_call no vetor de v_calusando como chave de busca o ramal.
+ *
+ * @param v_call Um vetor contendo todas as vz_calls em andamento em um dado momento.
+ * @param ext O ramal pelo qual se irá buscar a vz_call.
+ *
+ * @return NULL, caso essa chamada não tenha sido encontrada; um ponteiro para esta chamada, caso a mesma tenha sido encontrada.
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *  Vector * v_call = new Vector();
+ *      //assumindo que esse vetor de VZ_call já foi populado.
+ *  int ext = 5218;
+ *  VZ_call * call = __find_Call__( v_call, ext );
+ * ...
+ * @endcode
+ */
+VZ_call * __find_Call__( Vector * v_call, int ext );
+
+/**
+ * @Synopsis Responsável por remover calls por timeout.
+ *
+ * @param v_call Um vetor contendo todas as vz_calls em andamento em um dado momento.
+ * @param v_cb Um vetor contendo todos os Call_box conhecidos pela Header em um determinado momento.
+ * @param data Usado para a criação do pacote de "ping" que a Header irá enviar para o CBx.
+ * @param write_buffer Local de memória onde efetivamente irá ser montado o pacote para envio ao CBx. 
+ * @param ts O timeslice que será possivelmente devolvido.
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *  Vector * v_call = new Vector();
+ *  Vector * v_cb = new Vector();
+ *      // assumindo que os vetores já foram populados.
+ *  uint8_t buffer[ 300 ];
+ *      uint8_t write_buffer[ 300 ];
+ *      Timeslice * ts = new Timeslice();
+ *      ...
+ *      call_manager( v_call, v_cb, buffer, write_buffer, ts ); 
+ * ...
+ * @endcode
+ */
+void call_manager( Vector * v_call, Vector * v_cb, uint8_t * data, uint8_t * write_buffer, Timeslice * ts );
+
+#endif
\ No newline at end of file
--- a/configs.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/configs.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,33 +1,9 @@
 #include "configs.h"
-#include "mbed.h"
-#include <stdint.h>
-#include "UART3Interrupt.h" 
-#include "parallelcpld.h"
-
-QSPIFileSystem qspifs("qspi");  // file system
-Watchdog wdt;
 
 //*****************************************************************************
 //                             Pins/Modules Config
 //***************************************************************************** 
 
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
-DigitalOut CAB_LED(p24);
-
-DigitalOut DataReady(p11);                  //IO 27        
-
-DigitalOut data0(p30);                      //LSB
-DigitalOut data1(p31);
-DigitalOut data2(p32);
-DigitalOut data3(p33);
-DigitalOut data4(p34);
-DigitalOut data5(p37);
-DigitalOut data6(p38);
-DigitalOut data7(p39);                      //MSB
-
 InterruptIn NextData(p8);                   //IO 96
 InterruptIn FrameSync(p17);                 // GCLK1
 
@@ -41,10 +17,8 @@
 DigitalOut ENABLE_F_TX(p20);
 
 Serial  Uart3(p9,p10);  // default baudrate = 9600; Sem paridade, 8bits, 1 stop-bit 
-Serial  pc (USBTX,USBRX);
 
 void start_cpld( void ) {                        //CPLD Start
-
     static uint16_t reset = 10000;
     ENABLE_F_REG = 1;                                
     ENABLE_F_TX = 1;
@@ -55,8 +29,8 @@
     RST = 0;        
 }
 
-void config_lpc( void ) {                                       // Configure LPC4088
-
+///< Configure LPC4088
+void config_lpc( void ){
     Uart3.attach(&SerialRecvInterrupt, Uart3.RxIrq);       // UART3_IRQ configuration 
     Uart3.format(8,SerialBase::Forced1,1);                 // UART3 mode configuration
     Uart3.baud(2000000);                                
@@ -117,13 +91,4 @@
         while ( !(LPC_UART0->LSR &= (1<<5))  ) {} 
         LPC_UART0->THR = *src++;   
     }
-}
-
-void xstrcpy(uint8_t * dest, const uint8_t * src) {
-  while (*src)  *dest++ = *src++;
-  *dest = 0; 
-}
-
-void xmemcpy(uint8_t * dest, uint8_t * src, uint16_t size){
-  while (size--) *dest++ = *src++;
 }
\ No newline at end of file
--- a/configs.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/configs.h	Mon Nov 24 16:43:16 2014 +0000
@@ -1,30 +1,11 @@
 #ifndef _CONFIGS_H
 #define _CONFIGS_H
+
+#include <stdint.h>
 #include "mbed.h"
-#include "QSPIFileSystem.h"
-#include "wdt.h"
-
-#define DATA_SIZE         300
-
-extern QSPIFileSystem qspifs;       //FileSystem
-extern Watchdog wdt;
-
-extern DigitalOut led1;
-extern DigitalOut led2;
-extern DigitalOut led3;
-extern DigitalOut led4;
-extern DigitalOut CAB_LED;
-
-extern DigitalOut DataReady;                  //IO 27        
-
-extern DigitalOut data0;                      //LSB
-extern DigitalOut data1;
-extern DigitalOut data2;
-extern DigitalOut data3;
-extern DigitalOut data4;
-extern DigitalOut data5;
-extern DigitalOut data6;
-extern DigitalOut data7;                      //MSB
+#include "UART3Interrupt.h"
+#include "parallelcpld.h"
+#include "vz_protocol.h"
 
 extern InterruptIn NextData;                   //IO 96
 extern InterruptIn FrameSync;
@@ -38,15 +19,12 @@
 extern DigitalOut ENABLE_F_TX;
 
 extern Serial  Uart3;  // default baudrate = 9600; Sem paridade, 8bits, 1 stop-bit 
-extern Serial  pc ;
 
 void start_cpld( void );
 void config_lpc( void );
-void uart3_puts(uint8_t *src, uint16_t size);
+void uart3_puts( uint8_t *src, uint16_t size );
 void uart0_puts( uint8_t *src );
-void uart0_text( const char* src);
-void uart0_putsx(volatile uint8_t *src );
-void xmemcpy(uint8_t * dest, uint8_t * src, uint16_t size);
-
+void uart0_text( const char* src );
+void uart0_putsx( volatile uint8_t *src );
 
 #endif
--- a/debug.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/debug.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,6 +1,4 @@
 #include "debug.h"
-#include "string.h"
-#include "prompt.h"
 
 UDPSocket debug;
 Endpoint debug_server;
@@ -17,4 +15,25 @@
          debug.sendTo( debug_server, debug_msg1, size+5 );
     }else
         {}
-}
\ No newline at end of file
+}
+
+uint8_t debug_sip = 0;
+uint8_t debug_vector = 0;
+uint8_t debug_cb = 0;
+uint8_t debug_main = 0;
+uint8_t debug_cks = 0;
+uint8_t debug_cb_rx = 0;
+uint8_t debug_cb_tx = 0;
+uint8_t debug_eth_rx = 0;
+uint8_t debug_eth_tx = 0;
+uint8_t debug_prompt_eth = 0;
+uint8_t debug_file = 0;
+bool dparallel = false;
+bool dbl = false;
+bool udp_request = false;
+bool cb_session = false;
+bool cb_status = false;
+bool debug_telemetry = false;
+bool main_test = false;
+
+uint8_t test_debug = 1;
\ No newline at end of file
--- a/debug.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/debug.h	Mon Nov 24 16:43:16 2014 +0000
@@ -12,9 +12,8 @@
 #include <stdio.h>
 #include "mbed.h"
 #include "EthernetInterface.h"
-
-#include "configs.h"
-#include "prompt.h"
+#include "string.h"
+#include "shared_variables.h"
 
 extern char debug_msg1[ 1024+64 ];
 ///< Buffer usado na composisão da mensagem enviada pela macro debug_msg
@@ -23,6 +22,47 @@
 extern char msg_[ 1024 ];
 ///< Buffer utilizado pela macro send_msg
 
+extern bool cb_session;
+///< Não utilizada atualmente.
+extern bool cb_status;
+///< Não utilizada atualmente.
+extern bool debug_telemetry;
+///< Variável de controle que aciona o debug de telemetria.
+extern bool main_test;
+///< Variável de controle para acionamento de algum comando de interesse.
+
+extern uint8_t debug_sip;
+///< Variável de controle que ativa o debug sip.
+extern uint8_t debug_prompt;
+///< Variável de controle que ativa o debug do prompt.
+extern uint8_t debug_vector;
+///< Variável de controle que ativa o debug do vector.
+extern uint8_t debug_cb;
+///< Variável de controle que ativa o debug da classe Call_box.
+extern uint8_t debug_main;
+///< Variável de controle que ativa o debug da main.
+extern uint8_t debug_cks;
+///< Variável de controle que ativa o debug do ckechsum dos pacotes recebidos.
+extern uint8_t debug_cb_rx;
+///< Variável de controle que ativa o debug dos pacotes recebidos do CBx.
+extern uint8_t debug_cb_tx;
+///< Variável de controle que ativa o debug dos pacotes enviados para o CBx.
+extern uint8_t debug_eth_rx;
+///< Variável de controle que ativa o debug dos pacotes recebidos da eth \note não implementado.
+extern uint8_t debug_eth_tx;
+///< Variável de controle que ativa o debug dos pacotes enviados para a eth \note não implementado.
+extern uint8_t debug_prompt_eth;
+///< Variável de controle que ativa o debug do prompt eth.
+extern uint8_t debug_file;
+///< Variável de controle que ativa o debug do sistema de arquivos.
+extern bool dbl;
+///< Variável de controle que ativa o debug do protocolo de bootloader dos CBx
+extern bool dparallel;
+///< Variável de controle que aciona o debug de envio de pacotes pro cb, quando se
+///< quer transmitir um pacote enquanto outro pacote, já esta em transmissao.
+extern uint8_t test_debug;
+///< Variável de controle que ativa o debug de test.
+
 /**
  * @Synopsis Função usada anteriormente para formatação da string que debug, não esta mais em uso.
  *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eth.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,88 @@
+#include "eth.h"
+
+EthernetInterface eth;
+
+int __init_eth__(){    
+    static bool initialized = false;
+    char buff_ip[ 16 ] = "";
+    char buff_msk[ 16 ] = "";
+    char buff_gtw[ 16 ] = "";
+    wdt.kick();
+    pc.printf("\n\r");
+    FILE *fp = fopen( "/qspi/myip.txt", "r");
+    if( fp == NULL ){
+        if( debug_file ) debug_msg("Failed to open /qspi/myip.txt" );
+        strncpy( buff_ip, __MY_IP__, 20 );    
+    }else{
+        int read = fread( buff_ip, 1, 512, fp );
+        if( read > 0 ){
+            for( int i = 0; i < read; i++ ) 
+                if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){
+                    buff_ip[ i ] = '\0';
+                    break;
+                }
+            if( debug_file ) debug_msg("Eth ip %s", buff_ip );
+        }else{
+            if( debug_file ) debug_msg("Failed to read /qspi/myip.txt" );
+            strncpy( buff_ip, __MY_IP__, 20 );
+        }
+    }
+    fclose( fp );
+    buff_ip[ 15 ] = 0;
+        
+    fp = fopen( "/qspi/mymask.txt", "r");
+    if( fp == NULL ){
+        if( debug_file ) debug_msg("Failed to open /qspi/mymask.txt" );
+        strncpy( buff_msk, __MY_MSK__, 20 );    
+    }else{
+        int read = fread( buff_msk, 1, 512, fp );
+        if( read > 0 ){
+            for( int i = 0; i < read; i++ ) 
+                if( buff_msk[ i ] == '\n' || buff_msk[ i ] == '\r' ){
+                    buff_msk[ i ] = '\0';
+                    break;
+                }
+            if( debug_file ) debug_msg("mascara de rede Eth %s", buff_msk );
+        }else{
+            if( debug_file ) debug_msg("Failed to read /qspi/mymask.txt" );
+            strncpy( buff_msk, __MY_MSK__, 20 );
+        }
+    }
+    fclose( fp );
+    buff_msk[ 15 ] = 0;
+    
+    fp = fopen( "/qspi/mygate.txt", "r");
+    if( fp == NULL ){
+        if( debug_file ) debug_msg("Failed to open /qspi/mygate.txt" );
+        strncpy( buff_gtw, __MY_GTW__, 20 );    
+    }else{
+        int read = fread( buff_gtw, 1, 512, fp );
+        if( read > 0 ){
+            for( int i = 0; i < read; i++ ) 
+                if( buff_gtw[ i ] == '\n' || buff_gtw[ i ] == '\r' ){
+                    buff_gtw[ i ] = '\0';
+                    break;
+                }
+            if( debug_file ) debug_msg("Ip Gateway Eth %s", buff_gtw );
+        }else{
+            if( debug_file ) debug_msg("Failed to read /qspi/mygate.txt" );
+            strncpy( buff_gtw, __MY_GTW__, 20 );
+        }
+    }
+    fclose( fp );
+    buff_gtw[ 15 ] = 0;
+    
+    if( !initialized ){
+        //eth.init( buff_ip, buff_msk, buff_gtw );
+        eth.init( buff_ip, buff_msk, __MY_GTW__ );
+        initialized = true;
+        return eth.connect();
+    }
+    
+    if( !eth.disconnect() ){
+        return eth.connect();
+    }
+    else{
+        return eth.connect();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eth.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,27 @@
+#ifndef __ETH_H__
+#define __ETH_H__
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "debug.h"
+#include "vz_protocol.h"
+#include "wdt_manager.h"
+
+/**
+ * @Synopsis Responsavel por inicializar as configurações iniciais de conexão eth
+ *
+ * @return 0 ( zero ) caso tenha uma execução bem sucedida, um numero negativo, caso contrário.
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *   int eth_status = __init_eth__();
+ * ...
+ * @endcode
+ */
+int __init_eth__( void );
+
+extern EthernetInterface eth;
+///< Representa o link com o mundo externo.
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/file_system_manager.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,3 @@
+#include "file_system_manager.h"
+
+QSPIFileSystem qspifs("qspi");
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/file_system_manager.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,8 @@
+#ifndef __FILE_SYSTEM_MANAGER_H__
+#define __FILE_SYSTEM_MANAGER_H__
+
+#include "QSPIFileSystem.h"
+
+extern QSPIFileSystem qspifs;
+
+#endif
\ No newline at end of file
--- a/flood.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/flood.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,8 +1,4 @@
-#include "mbed.h"
 #include "flood.h"
-#include "parallelcpld.h"
-#include "prompt.h"
-#include "utils.h"
 
 uint8_t pflood = 0;
 
@@ -23,10 +19,10 @@
         }
         flood_start++;
         Bflood[6] = 0x40;
-        xmemcpy( TXBuffer, Bflood, 300 );
-        xmemcpy( cb_tx_buffer, Bflood, 300 );
+        //xmemcpy( TXBuffer, Bflood, 300 );
+        //xmemcpy( cb_tx_buffer, Bflood, 300 );
 
-        send2callboxes();
+        send2callboxes( Bflood );
         pc.printf("F");
         if( tcp_session ){
             tcp_client.send_all( "F", strlen( "F" ) );
--- a/flood.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/flood.h	Mon Nov 24 16:43:16 2014 +0000
@@ -8,6 +8,9 @@
 #ifndef _FLOOD_H__
 #define _FLOOD_H__
 
+#include "mbed.h"
+#include "parallelcpld.h"
+
 extern uint8_t pflood;
 ///< Variável de controle que liga/desliga o flood da Header.
 extern Timer tflood;
--- a/main.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/main.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,13 +1,18 @@
-#include "bits.h"
-#include "utils.h"
+#include "telemetry.h"                                                                                                                  
+#include "eth.h"                                                                                                                        
+#include "bits.h"                                                                                                                       
+#include "UART3Interrupt.h" // for RXBuffer[ __CB_BUFFER_SIZE__ ];                                                                                 
+#include "utils.h"                                                                                                                      
+#include "parallelcpld.h"                                                                                                               
+#include "debug.h"                                                                                                                      
+#include "flood.h"                                                                                                                      
+#include "bootloader_cbx.h"                                                                                                             
+#include "call_manager.h"                                                                                                               
+#include "call_box_manager.h"                                                                                                           
+#include "sip_manager.h"                                                                                                                
+#include "shared_variables.h"
+#include "prompt.h"
 #include "configs.h"
-#include "UART3Interrupt.h"
-#include "parallelcpld.h"
-#include "prompt.h"
-#include "debug.h"
-#include "utils.h"
-#include "flood.h"
-#include "bootloader_cbx_handler.h"
 
 volatile uint8_t status = 0x00;
 
@@ -245,12 +250,15 @@
         if( pflood == 1 ) flood();               
         
         if( status != __WAITING__ ){
-            xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ );
-            __read_cb_buffer__( buffer, buffer_from_cb_ptr );     
+            xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ );    
+            //__read_cb_buffer__( buffer, buffer_from_cb_ptr );
             status = __WAITING__;
+            __read_cb_buffer__( buffer, cb_rx_buffer );
         
             data = __parse_vz_pkg__( &ext, &port, &type, buffer );
             
+            debug_msg("-->%x<--", type );
+            
             if( data != NULL ){                
                 if( debug_alive == 1 && debug_cb_rx ) debug_msg("Pkg from CBx :: %d -- Type :: %d", ext, type );
                 if( type != __AUDIO__ ){
@@ -261,7 +269,7 @@
                             // some pkg reply
                             if( ( data[ 0 ] | BIT7 ) == cb->get_msg_id() ){                        
                                 if( type == __BOOT__ ) type = __REGISTRY__;
-                                __send_to_cb__( __build_cb_package__( ext, port, type, 
+                                send2callboxes( __build_cb_package__( ext, port, type, 
                                 ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                                 type = __DO_NOTHING__;
                                 if( debug_main ) debug_msg("-- Renviado ultimo pkg --");
@@ -379,7 +387,7 @@
                             v_call->remove_element( i );    
                             set_status( cb->sip->status, sip_idle);
                             data[ __TIMESLICE_PLACE__ ] = 0x00;
-                            __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__,
+                            send2callboxes( __build_cb_package__( ext, port, __CB_BYE__,
                                 ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                             set_status( cb->sip->status, sip_idle );
                             delete( call );
@@ -410,7 +418,7 @@
                     set_status(cb->status,cb_idle);
                     cb->set_timeslice( 0x00 );
                     data[ __TIMESLICE_PLACE__ ] = 0x00;
-                    __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, 
+                    send2callboxes( __build_cb_package__( ext, port, __INVITE__, 
                         ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                     if( debug_main ) debug_msg( "denying call - another call box on call" );    
                     break;
@@ -427,7 +435,7 @@
                     case cb_on_call : {
                         // a priori, nao fazer nada
                         //data[ __TIMESLICE_PLACE__ ] = 0x00;
-                        //__send_to_cb__( __build_cb_package__( ext, port, __BYE__, 
+                        //send2callboxes( __build_cb_package__( ext, port, __BYE__, 
                         //    ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                     }break;
                     
@@ -443,14 +451,14 @@
                             //sem timeslice pra tratar com o *
                             set_status(cb->status,cb_idle);
                             data[ __TIMESLICE_PLACE__ ] = 0x00;
-                            __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, 
+                            send2callboxes( __build_cb_package__( ext, port, __INVITE__, 
                                 ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                             set_status( cb->sip->status, sip_idle );
                             if( debug_main ) debug_msg( "-- Trying -- without TS -- %s ", write_buffer );
                         }else{
                             set_status(cb->status,cb_busy);
                             data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice();
-                            __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, 
+                            send2callboxes( __build_cb_package__( ext, port, __INVITE__, 
                                 ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                             
                             if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] );
@@ -464,7 +472,7 @@
                                 set_status(cb->status,cb_on_call);
                                 
                                 if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] );
-                                __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, 
+                                send2callboxes( __build_cb_package__( ext, port, __INVITE__, 
                                     ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                                 if( debug_main ) debug_msg( "-- Trying -- accepting call request --" );
                             }else{
@@ -473,7 +481,7 @@
                                 cb->set_timeslice( 0x00 );
                                 data[ __TIMESLICE_PLACE__ ] = 0x00;
                                 if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] );
-                                __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, 
+                                send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, 
                                     ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                                 if( debug_main ) debug_msg( "-- Trying -- denying call request --" );
                                 set_status( cb->sip->status, sip_idle);
@@ -486,7 +494,7 @@
                         cb->set_timeslice( 0x00 );
                         data[ __TIMESLICE_PLACE__ ] = 0x00;
                         if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] );
-                        __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, 
+                        send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, 
                             ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                         if( debug_main ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" );
                         set_status( cb->sip->status, sip_idle );
@@ -513,7 +521,7 @@
                 }break;
             case __BOOT__ : {
                 boot_counter++;
-                __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, 
+                send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, 
                     ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                 }break;
             case __TELEMETRY__ : {
@@ -583,7 +591,7 @@
                 uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, 
                     tmp, __AUDIO__, length, write_buffer );
                 
-                __send_to_cb__( pkg2cb );
+                send2callboxes( pkg2cb );
             }
         }
         if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer );
@@ -605,7 +613,7 @@
                             delete( call );
                         }
                     }
-                    __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, 
+                    send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, 
                         ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
                     //FIXMEj talvez eu nao precise dessa linha mudar o set_status( cb->sip->status, sip_idle ); pra ver o que acontece
                     //cb->reset_sip();
--- a/parallelcpld.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/parallelcpld.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,9 +1,26 @@
 #include "parallelcpld.h"
 
-uint8_t TXBuffer[DATA_SIZE];          
-///<UART3 TX Buffer -- Buffer de transmissao para o CPLD
+DigitalOut data0(p30);                      //LSB
+DigitalOut data1(p31);
+DigitalOut data2(p32);
+DigitalOut data3(p33);
+DigitalOut data4(p34);
+DigitalOut data5(p37);
+DigitalOut data6(p38);
+DigitalOut data7(p39);                      //MSB
+
+DigitalOut DataReady(p11);                  
+///<IO 27
+
+uint8_t cb_tx_buffer[ __CB_BUFFER_SIZE__ ];
+
+uint8_t TXBuffer[ __CB_BUFFER_SIZE__ ]; 
+
 uint8_t tx_clear = 1;
 
+ring_buffer * rb = ring_buffer_init( NULL );
+ring_buffer test;
+
 // Print a variable using parallel protocol
 void parallel_write( uint8_t data ){   
     data0 = BIT0&(data);
@@ -17,16 +34,21 @@
 }
 
 // Needs: function parallel_write/ Global variables: TXBuffer, tx_clear / Configuration extern interrupt
-void send2callboxes(){
+void send2callboxes( uint8_t * buffer ){
     // Send the first position of TXBuffer first
     if( tx_clear == 1 ){
-        //tx_clear = 0;
-        //parallel_write( TXBuffer[ 0 ] );                  
-        //DataReady = 1;
+        tx_clear = 0;
+        xmemcpy( TXBuffer, buffer, __CB_BUFFER_SIZE__ );
+        parallel_write( TXBuffer[ 0 ] );
+        DataReady = 1;
+        xmemcpy( cb_tx_buffer, buffer, __CB_BUFFER_SIZE__ );           
     }else{
         // Error if the transmission is still in use
-        if( dparallel ) debug_msg( "Error: Low Overflow Parallel Write TX" );
-        //pc.printf( "\n\rError: Low Overflow Parallel Write TX\n\r" );    
+        uint8_t ret = ring_buffer_add( rb, buffer );
+        
+        if( ret == 0x01 ) if( dparallel ) send_msg("Error: Ring buffer fully charged");
+        
+        if( ret == 0x00 ) if( dparallel ) send_msg("Success : package queued -- on queue %u", rb->size );
     }
 }
 
@@ -50,6 +72,15 @@
         tx_clear = 1;
         c = 0;
     }
-    
     c++;
+}
+
+void tx_buffer_ring_buffer_handler( void ){
+    if( ( rb->size != 0x00 ) && ( tx_clear == 1 ) ){
+        uint8_t buffer[ __CB_BUFFER_SIZE__ ];
+        uint8_t * _rb_next = ring_buffer_get_next( rb );
+        xmemcpy( buffer, _rb_next, __CB_BUFFER_SIZE__ );
+        if( dparallel ) send_msg( "Ring Buffer less one -- remain %u", rb->size );
+        send2callboxes( buffer );
+    }
 }
\ No newline at end of file
--- a/parallelcpld.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/parallelcpld.h	Mon Nov 24 16:43:16 2014 +0000
@@ -1,17 +1,40 @@
-#ifndef _PARALLELCPLD_H
-#define _PARALLELCPLD_H
+#ifndef __PARALLELCPLD_H__
+#define __PARALLELCPLD_H__
 
 #include <stdint.h>
 #include "mbed.h"
 #include "bits.h"
+#include "ring_buffer.h"
 #include "debug.h"
-#include "configs.h"
+#include "utils.h"
+#include "vz_protocol.h"
+
+//alguém explica por que eu nao consido deixar esse cara como extern ???
+extern ring_buffer * rb;
  
-extern uint8_t TXBuffer[DATA_SIZE];
+extern uint8_t TXBuffer[ __CB_BUFFER_SIZE__ ];
+///<UART3 TX Buffer -- Buffer de transmissao para o CPLD
 extern uint8_t tx_clear;
 
+extern uint8_t cb_tx_buffer[ __CB_BUFFER_SIZE__ ];
+///< Armazena o ultimo pacote enviado para os CBx
+
 void parallel_write( uint8_t data);
-void send2callboxes();
+//void send2callboxes();
+void send2callboxes( uint8_t * buffer );
 void get2();
+void tx_buffer_ring_buffer_handler( void );
+
+extern DigitalOut data0;                      //LSB
+extern DigitalOut data1;
+extern DigitalOut data2;
+extern DigitalOut data3;
+extern DigitalOut data4;
+extern DigitalOut data5;
+extern DigitalOut data6;
+extern DigitalOut data7;                      //MSB
+
+extern DigitalOut DataReady;
+///<IO 27
 
 #endif
\ No newline at end of file
--- a/prompt.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/prompt.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,57 +1,8 @@
 #include "prompt.h"
-#include "utils.h"
-
-TCPSocketServer tcp_server;
-TCPSocketConnection tcp_client;
-Timer tcp_timer;
-Timer udp_timer;
 
-UDPSocket udp_server;
-Endpoint udp_client;
-                    
-uint8_t debug_alive = 0;
-uint8_t debug_sip = 0;
-uint8_t debug_vector = 0;
-uint8_t debug_cb = 0;
-uint8_t debug_main = 0;
-uint8_t debug_cks = 0;
-uint8_t pcks_s = 0;
-uint8_t pshowcb = 0;
-uint8_t debug_cb_rx = 0;
-uint8_t debug_cb_tx = 0;
-uint8_t debug_eth_rx = 0;
-uint8_t debug_eth_tx = 0;
-uint8_t debug_prompt_eth = 0;
-uint8_t debug_file = 0;
-bool dparallel = false;
-bool dbl = false;
-bool from_eth = false;
-bool udp_request = false;
-bool tcp_session = false;
-bool cb_session = false;
-bool cb_status = false;
-bool reset_cks = false;
-bool debug_telemetry = false;
-bool main_test = false;
 bool flood_silence = false;
-bool list = false;
-bool r_stats;
-bool rx = false;
-bool tx = false;
-bool stats = false;
 bool delayed_flood = false;
 
-uint16_t boot_counter = 0; 
-uint16_t registry_counter = 0; 
-uint16_t invite_counter = 0; 
-uint16_t audio_counter = 0; 
-uint16_t telemetry_counter = 0; 
-uint16_t cb_bye_counter = 0; 
-uint16_t prompt_counter = 0; 
-uint16_t flood_counter = 0; 
-uint16_t bootloader_cbx_counter = 0;
-
-uint8_t test_debug = 1;
 #define PVERSION 5          // Sempre atualizar a versao do prompt
 
 char __debug_buf__[ DEBUGBUFSIZE ];
@@ -644,7 +595,7 @@
             cmd[ str_end + 1 ] = 0x00;
             
             int port = convert_ext_to_port( ext_count );
-            __send_to_cb__( __build_cb_package__( ext_count, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
+            send2callboxes( __build_cb_package__( ext_count, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
             pc.printf("\r\nSilence sent to ext=%d port=%d", ext_count, port );
             
             if( tcp_session ){ 
@@ -1126,8 +1077,9 @@
             
             ref = debug_buf;
             
-            debug_buf[ strlen( debug_buf ) ] = 0x0D;
-            debug_buf[ strlen( debug_buf ) + 1 ] = 0x00;
+            //debug_buf[ strlen( debug_buf ) ] = 0x0D;
+            strcat( debug_buf, "\r" );
+            //debug_buf[ strlen( debug_buf ) + 1 ] = 0x00;
             
             split = strtok( debug_buf + 4, " " );
             ext = atoi( split );
@@ -1139,13 +1091,14 @@
             promptcb_last_ext = ext;
             promptcb_last_port = port;
             
-            int tmp = strlen( cmd );
-            cmd[ tmp ] = 0x0D;
-            cmd[ tmp + 1 ] = 0x00;
+            //int tmp = strlen( cmd );
+            //cmd[ tmp ] = 0x0D;
+            //cmd[ tmp + 1 ] = 0x00;
             strcpy( promptcb_last_cmd, cmd );
+            //strcat( cmd, "\r\r\r" );
             
             pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd );
-            __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
+            send2callboxes( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
             pc.printf("\n\rComando enviado\n\r");
             
             if( from_eth ){
@@ -1171,7 +1124,7 @@
             debug_buf[ bufptr++ ] = 0x00;
 
             pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n",promptcb_last_ext, promptcb_last_port, debug_buf + 4 );
-            __send_to_cb__( __build_cb_package__( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf + 4, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
+            send2callboxes( __build_cb_package__( promptcb_last_ext, promptcb_last_port, __PROMPT__, debug_buf + 4, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
             pc.printf("\n\rComando enviado\n\r");
         }
 
@@ -1581,7 +1534,7 @@
             pc.printf("\n\r--------------------------------------------------------\n\r");
             for( uint16_t i = 0; i < strlen( cmd ) ; i++ ) pc.printf( "%02x ", cmd[ i ] );
             
-            __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
+            send2callboxes( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
             pc.printf("\n\r--------------------------------------------------------\n\r");
             for( uint16_t i = 0; i < 300 ; i++ ){
                 pc.printf( "%02x ", write_buffer[ i ] );
@@ -1649,18 +1602,6 @@
         pc.printf("> ");
     }    
     return( NULL );
-}
-
-int convert_ext_to_port( int ext ){
-  if( ext < 1000 ) return ext;
-  
-  else{
-      int aux = 0;
-      aux = ( ext / 1000 ) * 1000;
-      ext -= aux;
-      aux += ext % 100;
-      return( aux );
-  }
 } 
 
 void set_ip( char * new_header_ip ){
--- a/prompt.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/prompt.h	Mon Nov 24 16:43:16 2014 +0000
@@ -9,16 +9,16 @@
 #ifndef _PROMPT_H
 #define _PROMPT_H
 
+#include <stdint.h>
 #include "mbed.h"
-#include "stdint.h"
-
-#include "configs.h"
-
-#include "vz_protocol.h"
-
-#include "parallelcpld.h"
-
+#include "EthernetInterface.h"
+#include "telemetry.h" // used for __TELEMETRY_SERVER_IP__ and __TELEMETRY_SERVER_PORT__
+#include "utils.h" // need for convert_ext_to_port()
 #include "flood.h"
+#include "shared_variables.h"
+#include "debug.h"
+#include "wdt_manager.h"
+#include "file_system_manager.h"
 
 #define TCP_IDLE_MAX_TIME 45 
 ///< Define o tempo maximo de espera por um novo comando via eth, dado que já estamos em uma sessão TCP
@@ -26,42 +26,6 @@
 #define DEBUGBUFSIZE 50
 ///< Define o tamanho do buffer de entrada de dados.
 
-extern uint8_t debug_sip;
-///< Variável de controle que ativa o debug sip.
-extern uint8_t debug_alive;
-///< Variável de controle que ativa o debug de impressao periódica dos cbx registrados na lógica.
-extern uint8_t debug_prompt;
-///< Variável de controle que ativa o debug do prompt.
-extern uint8_t debug_vector;
-///< Variável de controle que ativa o debug do vector.
-extern uint8_t debug_cb;
-///< Variável de controle que ativa o debug da classe Call_box.
-extern uint8_t debug_main;
-///< Variável de controle que ativa o debug da main.
-extern uint8_t debug_cks;
-///< Variável de controle que ativa o debug do ckechsum dos pacotes recebidos.
-extern uint8_t debug_cb_rx;
-///< Variável de controle que ativa o debug dos pacotes recebidos do CBx.
-extern uint8_t debug_cb_tx;
-///< Variável de controle que ativa o debug dos pacotes enviados para o CBx.
-extern uint8_t debug_eth_rx;
-///< Variável de controle que ativa o debug dos pacotes recebidos da eth \note não implementado.
-extern uint8_t debug_eth_tx;
-///< Variável de controle que ativa o debug dos pacotes enviados para a eth \note não implementado.
-extern uint8_t debug_prompt_eth;
-///< Variável de controle que ativa o debug do prompt eth.
-extern uint8_t debug_file;
-///< Variável de controle que ativa o debug do sistema de arquivos.
-extern bool dbl;
-///< Variável de controle que ativa o debug do protocolo de bootloader dos CBx
-    
-extern uint8_t test_debug;
-///< Variável de controle que ativa o debug de test.
-
-extern uint8_t pcks_s;
-///< Variável de controle que ativa a exibição dos contadores de cks dos pacotes.
-extern uint8_t pshowcb;
-///< Variável de controle que ativa a exibição dos CBx registrados.
 extern uint8_t dog;
 ///< Variável de controle que ativa a mensagem de boas vindas.
 
@@ -81,6 +45,10 @@
 extern FILE *ftip;          ///< arquivo de IP do servidor para envio de telemetria
 extern FILE *ftport;        ///< arquivo de Porta UDP do servidor para envio de telemetria
 
+extern bool flood_silence;
+extern bool delayed_flood;
+///< Variável de controle do envio de pacotes de flood off
+
 /**
  * @Synopsis Principal função de processamento de comandos.
  *
@@ -292,92 +260,8 @@
  */
 void set_gateway( char * new_gateway );
 
-extern bool from_eth;
-///< Variável de controle que indica se o comando processado veio do teclado ( serial ) ou se via eth.
-extern bool tcp_session;
-///< Variável de controle que indica se estamos ou não em uma sessão TCP com algum usuàrio.
-extern TCPSocketServer tcp_server;
-///< Socket responsavel por ouvir determinado porta TCP.
-extern TCPSocketConnection tcp_client;
-///< Representa a presença de algum cliente logado em uma sessão TCP.
-extern Timer tcp_timer;
-///< Timer responsavel por dar timeout por não utilização de recurso.
-
-extern UDPSocket udp_server;
-///< Socket responsavel por ouvir determinada porta udp.
-extern Endpoint udp_client;
-///< Representa a presença de algum cliente udp.
-
-extern bool udp_request;
-///< Variável de controle que nos diz se trata-se de um request vindo da porta UDP.
 extern char * debug_buf;
 ///< Buffer de entrada dos dados via serial.
 
-extern bool dparallel;
-
-extern bool cb_session;
-///< Não utilizada atualmente.
-extern bool cb_status;
-///< Não utilizada atualmente.
-extern bool reset_cks;
-///< Variável de controle que reseta os contadores de cks dos pacotes.
-extern bool debug_telemetry;
-///< Variável de controle que aciona o debug de telemetria.
-extern bool main_test;
-///< Variável de controle para acionamento de algum comando de interesse.
-extern bool list;
-///< Variável de controle para listar os CBx registrados na lógica da Header.
-extern bool rx;
-///< Variável de controle para exibição do ultima pacote recebido dos CBx
-extern bool tx;
-///< Variável de controle para exibição do ultimo pacote enviado para o CBx.
-extern bool stats;
-///< Variável de controle para exibição dos contadores de pacotes recebidos por tipo.
-extern bool r_stats;
-///< Variável de controle para resetar os contadores de pacotes recebidos por tipo.
-extern bool delayed_flood;
-///< Variável de controle do envio de pacotes de flood off
-
-extern uint16_t boot_counter;
-///< Contador dos pacotes de BOOT recebidos
-extern uint16_t registry_counter; 
-///< Contador dos pacotes de REGISTRY recebidos
-extern uint16_t invite_counter; 
-///< Contador dos pacotes de INVITE recebidos
-extern uint16_t audio_counter; 
-///< Contador dos pacotes de AUDIO recebidos
-extern uint16_t telemetry_counter; 
-///< Contador dos pacotes de TELEMETRY recebidos
-extern uint16_t cb_bye_counter; 
-///< Contador dos pacotes de CB_BYE recebidos
-extern uint16_t prompt_counter; 
-///< Contador dos pacotes de PROMPT recebidos
-extern uint16_t flood_counter;
-///< Contador dos pacotes de FLOOD recebidos
-extern uint16_t bootloader_cbx_counter;
-///< Contador dos pacotes de BOOTLOADER_CBX recebidos
-
-extern Timer udp_timer;
-///< Timer controlador do timeout de requests UDP.
-
-/**
- * @Synopsis Função que converte o ramal para a porta, por definição de projeto, cara ramo possui o numero da centena incremental
- * permanecendo o resto igual, por exemplo no ramo pilo os ramais são 5000, 5001 -- no lote 1 5100, 5101 -- porem a porta sempre
- * se manteve a mesma, o CBx esta configurado como ramal 5000 e porta 5000, assim como o ramal 5100 e porta 5000, em outras palavras
- * dado um ramal, calcular a porta é o mesmo que eliminar a centena do numero.
- *
- * @param ext O ramal do qual se quer calcular a porta vinculada.
- *
- * @return O valor calculado da porta.
- *
- * Exemplo:
- * @code
- * ...
- *  int ext = 5220;
- *  int port = convert_ext_to_port( ext );
- * ...
- * @endcode
- */
-int convert_ext_to_port( int ext );
 
 #endif
\ No newline at end of file
--- a/ring_buffer.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/ring_buffer.h	Mon Nov 24 16:43:16 2014 +0000
@@ -1,10 +1,10 @@
 #ifndef __RING_BUFFER_H__
 #define __RING_BUFFER_H__
 
-#include <assert.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include "vz_protocol.h"
+#include <assert.h> // for unit_test
+#include <stdint.h> // for uint8*
+#include <stdlib.h> // for NULL ...
+#include "vz_protocol.h" // for __CB_BUFFER_SIZE__
 
 #define RING_BUFFER_SIZE 3
 
--- a/rtp.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/rtp.h	Mon Nov 24 16:43:16 2014 +0000
@@ -15,13 +15,9 @@
 #include <string.h>
 #include "mbed.h"
 #include "EthernetInterface.h"
+#include "debug.h"
+#include "shared_variables.h"
 #include "vz_protocol.h"
-#include "debug.h"
-
-#define __RTP_HEADER_OFFSET__ 12
-///< Identifica o inicio dos dados de audio ( payload )
-#define __RTP_HEADER_SIZE__ 12
-///< Indica o tamanho ( em bytes ) ocupado pelo cabeçalho rtp.
 
 class RTP_Header{
     private :
--- a/rtpbuf.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/rtpbuf.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,11 +1,6 @@
 #include <stdlib.h>
 
 #include "rtpbuf.h"
-
-static void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size) {
-  size >>= 2;
-  while (size--) *dest++ = *src++;
-}
 /*
 static void xmemcpy(uint8_t * dest, uint8_t * src, uint16_t size) {
   while (size--) *dest++ = *src++;
--- a/rtpbuf.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/rtpbuf.h	Mon Nov 24 16:43:16 2014 +0000
@@ -11,6 +11,7 @@
 
 #include <stdint.h>
 #include "debug.h"
+#include "utils.h"
 
 #define RTPBUF_PKGSIZE 240 
 ///< 30ms @ 8Ksamples/sec
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared_variables.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,65 @@
+#include "shared_variables.h"
+
+bool from_eth = false;
+
+bool tcp_session = false;
+
+bool reset_cks = false;
+
+TCPSocketServer tcp_server;
+
+TCPSocketConnection tcp_client;
+
+Timer tcp_timer;
+
+Timer udp_timer;
+
+uint8_t debug_alive = 0;
+
+UDPSocket udp_server;
+
+Endpoint udp_client;
+
+uint8_t pcks_s = 0;
+
+bool list = false;
+
+bool r_stats;
+
+bool rx = false;
+
+bool tx = false;
+
+bool stats = false;
+
+uint16_t boot_counter = 0; 
+
+uint16_t registry_counter = 0; 
+
+uint16_t invite_counter = 0; 
+
+uint16_t audio_counter = 0; 
+
+uint16_t telemetry_counter = 0; 
+
+uint16_t cb_bye_counter = 0; 
+
+uint16_t prompt_counter = 0; 
+
+uint16_t flood_counter = 0; 
+
+uint16_t bootloader_cbx_counter = 0;
+
+uint8_t pshowcb = 0;
+
+Serial pc (USBTX,USBRX);
+
+DigitalOut led1(LED1);
+
+DigitalOut led2(LED2);
+
+DigitalOut led3(LED3);
+
+DigitalOut led4(LED4);
+
+DigitalOut CAB_LED(p24);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/shared_variables.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,98 @@
+#ifndef __SHARED_VARIABLES_H__
+#define __SHARED_VARIABLES_H__
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+
+extern bool from_eth;
+///< Variável de controle que indica se o comando processado veio do teclado ( serial ) ou se via eth.
+
+extern bool tcp_session;
+///< Variável de controle que indica se estamos ou não em uma sessão TCP com algum usuàrio.
+
+extern TCPSocketServer tcp_server;
+///< Socket responsavel por ouvir determinado porta TCP.
+
+extern TCPSocketConnection tcp_client;
+///< Representa a presença de algum cliente logado em uma sessão TCP.
+
+extern Timer tcp_timer;
+///< Timer responsavel por dar timeout por não utilização de recurso.
+
+extern UDPSocket udp_server;
+///< Socket responsavel por ouvir determinada porta udp.
+
+extern Endpoint udp_client;
+///< Representa a presença de algum cliente udp.
+
+extern bool udp_request;
+///< Variável de controle que nos diz se trata-se de um request vindo da porta UDP.
+
+extern uint8_t debug_alive;
+///< Variável de controle que ativa o debug de impressao periódica dos cbx registrados na lógica.
+
+extern Timer udp_timer;
+///< Timer controlador do timeout de requests UDP.
+
+extern bool reset_cks;
+///< Variável de controle que reseta os contadores de cks dos pacotes.
+
+extern uint8_t pcks_s;
+///< Variável de controle que ativa a exibição dos contadores de cks dos pacotes.
+
+extern uint8_t pshowcb;
+///< Variável de controle que ativa a exibição dos CBx registrados.
+
+extern bool list;
+///< Variável de controle para listar os CBx registrados na lógica da Header.
+extern bool rx;
+///< Variável de controle para exibição do ultima pacote recebido dos CBx
+extern bool tx;
+///< Variável de controle para exibição do ultimo pacote enviado para o CBx.
+extern bool stats;
+///< Variável de controle para exibição dos contadores de pacotes recebidos por tipo.
+extern bool r_stats;
+///< Variável de controle para resetar os contadores de pacotes recebidos por tipo.
+
+extern uint16_t boot_counter;
+///< Contador dos pacotes de BOOT recebidos
+
+extern uint16_t registry_counter; 
+///< Contador dos pacotes de REGISTRY recebidos
+
+extern uint16_t invite_counter; 
+///< Contador dos pacotes de INVITE recebidos
+
+extern uint16_t audio_counter; 
+///< Contador dos pacotes de AUDIO recebidos
+
+extern uint16_t telemetry_counter; 
+///< Contador dos pacotes de TELEMETRY recebidos
+
+extern uint16_t cb_bye_counter; 
+///< Contador dos pacotes de CB_BYE recebidos
+
+extern uint16_t prompt_counter; 
+///< Contador dos pacotes de PROMPT recebidos
+
+extern uint16_t flood_counter;
+///< Contador dos pacotes de FLOOD recebidos
+
+extern uint16_t bootloader_cbx_counter;
+///< Contador dos pacotes de BOOTLOADER_CBX recebidos
+
+extern Serial pc;
+///< Objeto que possibilita a excrita ( via printf ) de texto na serial
+
+extern DigitalOut led1;
+extern DigitalOut led2;
+extern DigitalOut led3;
+extern DigitalOut led4;
+extern DigitalOut CAB_LED;
+
+#define __RTP_HEADER_OFFSET__ 12
+///< Identifica o inicio dos dados de audio ( payload )
+#define __RTP_HEADER_SIZE__ 12
+///< Indica o tamanho ( em bytes ) ocupado pelo cabeçalho rtp.
+
+#endif
\ No newline at end of file
--- a/sip.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/sip.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,11 +1,10 @@
 #include "sip.h"
-#include "utils.h"
-#include "prompt.h"
 
 void Sip::__init_sock__( void ){
     sip_server.set_address( this->server_ip , this->server_port );
     sock.set_blocking( false, 1 ); // verificar isso com mais cuidado depois
     sock.bind( this->my_port );
+    //sock.init();
     sock.init();
 }
 
@@ -183,10 +182,8 @@
     itoa( get_id(), callbox_string, 10 );
  
     if( status != sip_on_call ){
-         set_status(status, sip_waiting_trying );
-    }
-    
-    else return( NULL );
+         set_status( status, sip_waiting_trying );
+    }else return( NULL );
     
     int cseq = 0;
  
@@ -206,9 +203,8 @@
     //static int id_ = 0;
     int length = 0;
     bool waiting = false;
-    
     VZ_call * call = NULL;
-    while( t.read() < __INVITE_MAX_WAITING_TIME__ ){    
+    while( t.read() < __INVITE_MAX_WAITING_TIME__ ){
         loop_times++;        
         length = sock.receiveFrom( sip_server, buffer, sizeof( buffer ) );
         if( length > 0 ){
@@ -216,7 +212,7 @@
             //debug_msg("Pacotes recebidos :: %d", id_ );
             buffer[ length ] = 0;
             received_loop_times++;
-            if( ( status == sip_trying ) || ( status == sip_ringing ) ){            
+            if( ( status == sip_trying ) || ( status == sip_ringing ) || ( status == sip_waiting_trying ) ){            
                 if( !( strncasecmp( buffer + 12, "ok", strlen("ok") ) ) ){
                     // tratar depois o esquema do Cseq ::
                     //debug_msg( "Cseq == %d", cseq );
@@ -272,21 +268,24 @@
                 }
             }
         }else if( reconnect.read() > 4 ){
-            sock.close();
-            sock.bind( this->my_port );
-            sock.init();
-            sock.set_blocking( false, 1 );
-            if( debug_sip ) debug_msg("Reconnect");
-            reconnect.reset();
+            //sock.close();
+            //sock.bind( this->my_port );
+            //sock.init();
+            //sock.set_blocking( false, 1 );
+            //if( debug_sip ) debug_msg("Reconnect");
+            if( received_loop_times != 0 ){
+                send_msg(" %d bytes lidos ", length );
+                reconnect.reset();
+            }
             //sock.sendTo( sip_server, buffer, sizeof( buffer ) );
-            led4 = !led4;
+            //led4 = !led4;
         }
         if( waiting == true ){
             char * tmp = call->get_eth_message( &length );
             if( tmp != NULL ){
                 uint8_t * pkg2cb = __build_cb_package__( this->my_ext, this->my_port, __AUDIO__, 
                     tmp, __AUDIO__, length, (uint8_t *)buffer );
-                __send_to_cb__( pkg2cb );
+                send2callboxes( pkg2cb );
             }
         }
     }
--- a/sip.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/sip.h	Mon Nov 24 16:43:16 2014 +0000
@@ -14,10 +14,11 @@
 #include <string.h>
 #include "mbed.h"
 #include "EthernetInterface.h"
+
 #include "call.h"
 #include "vz_protocol.h"
+#include "parallelcpld.h" // need for send confort song to CBx
 #include "debug.h"
-//#include "configs.h"
 
 #define __INVITE_MAX_WAITING_TIME__ 30
 ///< Indica o timeout de espera de resposta de pedido de ligação para o servidor, após esse tempo responde ligação encerrado para o Call_box
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip_manager.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,25 @@
+#include "sip_manager.h"
+
+int sip_manager( Vector * v_cb ){
+    static int index = 0;
+    if( v_cb != NULL ){
+        if( v_cb->size() > 0 ){
+            if( index >= v_cb->size() ) index = 0;    
+        }else return 0;
+        Call_Box * cb = (Call_Box * )v_cb->get_element( index );
+        /*  Retorna 
+            = 0 :: ok
+            < 0 :: tive problemas
+            > 0 :: devo remover essa call do vetor de calls 
+        */
+        int returned_value = 0;
+        
+        if( cb->status == cb_on_call || cb->status == cb_idle ){
+            //debug_msg("");
+            returned_value = cb->listen_SIP_server();
+        }
+        index++;
+        return( returned_value );
+    }
+    return( -1 );
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sip_manager.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,34 @@
+#ifndef __SIP_MANAGER_H__
+#define __SIP_MANAGER_H__
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "debug.h"
+#include "vector.h"
+#include "call_box.h"
+
+/**
+ * @Synopsis Responsavel por escutar a porta de conexão com o servidor, verificando se o mesmo mandou algum dado.
+ *
+ * @param v_cb Um vetor contendo todos os Call_box conhecidos pela Header em um determinado momento.
+ * @param v_call Um vetor contendo todas as vz_calls em andamento em um dado momento.
+ *
+ * @return 0 ( zero ) se tudo correu bem, um numero menor do que zero, caso algum problema tenha acontecido na execusão, e um numero
+ * maior que zero indicando o ramal que deve ser removido do vetor de ligações.
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *  Vector * v_cb = new Vector();
+ *  Vector * v_call = new Vector();
+ *      // assumindo que os vetores já foram populados.
+ *  int ret = sip_manager( v_cb, v_call );                                                                  
+ *  if( ret > 0x00 ){
+ *          // tratar esse request
+ *  }          
+ * ...
+ * @endcode
+ */
+int sip_manager( Vector * v_cb ); 
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/telemetry.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,127 @@
+#include "telemetry.h"
+
+UDPSocket t_sock;                                                                                                                      
+
+Endpoint t_server;
+
+void init_telemetry_handler( void ){
+    char buff_ip[ 16 ] = "";
+    char buff_port[ 8 ] = "";
+    int telemetry_port = 0;
+    
+    FILE *fp = fopen( "/qspi/telemetry_ip.txt", "r");
+    if( fp == NULL ){
+        if( debug_file ) debug_msg("Failed to open /qspi/telemetry_ip.txt" );
+        strncpy( buff_ip, __TELEMETRY_SERVER_IP__, 20 );    
+    }else{
+        int read = fread( buff_ip, 1, 512, fp );
+        if( read > 0 ){
+            for( int i = 0; i < read; i++ ) 
+                if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){
+                    buff_ip[ i ] = '\0';
+                    break;
+                }
+            if( debug_file ) debug_msg("Telemetry server ip %s", buff_ip );
+        }else{
+            if( debug_file ) debug_msg("Failed to open /qspi/telemetry_ip.txt" );
+            strncpy( buff_ip, __TELEMETRY_SERVER_IP__, 20 );
+        }
+    }
+    fclose( fp );
+    
+    fp = fopen( "/qspi/telemetry_port.txt", "r");
+    if( fp == NULL ) {
+        if( debug_sip ) debug_msg("Failed to open /qspi/telemetry_port.txt" );
+        telemetry_port = __TELEMETRY_SERVER_PORT__;
+    } else {
+        if( fread( (void *)buff_port, 1, 32, fp ) > 0 ) {
+            telemetry_port = atoi( buff_port );
+            if( debug_sip ) debug_msg("Telemetry server port %d", buff_port );
+        } else {
+            if( debug_sip ) debug_msg("Failed to read /qspi/telemetry_port.txt" );
+            telemetry_port = __TELEMETRY_SERVER_PORT__;
+        }
+    }
+    fclose( fp );    
+    
+    //int addr = t_server.set_address( __TELEMETRY_SERVER_IP__ , __TELEMETRY_SERVER_PORT__ );
+    int addr = t_server.set_address( buff_ip , telemetry_port );
+    if( debug_telemetry ) send_msg(" Valor de retorno set_address -- %d ", addr );
+    t_sock.set_blocking( false, 1 );
+    
+    int bind = t_sock.bind( __TELEMETRY_HEADER_PORT__ );
+    if( debug_telemetry ) send_msg(" Valor de retorno bind -- %d ", bind );
+}
+
+void re_start_telemetry( void ){
+    int close = t_sock.close();
+    if( debug_telemetry ) send_msg(" Valor de retorno close-- %d ", close );
+    
+    init_telemetry_handler();
+}
+
+void build_telemetry_report( int ext, int port, char * data ){
+    char aux[ __CB_BUFFER_SIZE__ + 6 ];
+    char tmp[ 6 ];
+    strcpy( aux, itoa( ext, tmp, 10 ) );
+    strcat( aux, " " );
+    
+    //strncat( aux, (char * )data, __TELEMETRY_SIZE__ );
+    /*
+    pc.printf("\n\r 1. ");
+    uint8_t count = 2;
+    for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ){
+        if( i > 0 && !( i % 15 )  ) pc.printf("\n\r%2i. ", count++ );
+        pc.printf("%3x ", data[ i ] );
+    }
+    pc.printf("\n\r");
+    */
+    //pulando o byte de id ( sequence number )
+    data += __SEQ_NUM_SIZE__;
+    //pulando os bytes do clock
+    data += __CLOCK_SYNC_SIZE__;
+    
+    uint8_t offset = strlen( aux );
+    
+    for( register uint16_t i = 0; i < __TELEMETRY_SIZE__; i++ ) aux[ i + offset ] = data[ i ];
+    
+    for( register uint16_t i = __TELEMETRY_SIZE__ + offset; i < __CB_BUFFER_SIZE__; i++ ) aux[ i ] = 0;
+    
+        int sent = t_sock.sendTo( t_server, aux, __CB_BUFFER_SIZE__ );
+    if( debug_telemetry ) send_msg(" Valor de retorno sent-- %d ", sent );
+    
+    if( sent == -1 ){ 
+        re_start_telemetry();
+        sent = t_sock.sendTo( t_server, aux, __CB_BUFFER_SIZE__ );
+        
+        if( debug_telemetry ) send_msg(" Valor de retorno sent-- %d ", sent );
+    }
+    
+    if( debug_telemetry ){
+        pc.printf("\n\r 1. ");
+        uint8_t count = 2;
+        for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ){
+            if( i > 0 && !( i % 15 )  ) pc.printf("\n\r%2i. ", count++ );
+            pc.printf("%3x ", aux[ i ] );
+        }
+        pc.printf("\n\r");
+        
+        char msg_to_eth[ 1024 ];
+        strcpy( msg_to_eth, tmp );
+        strcat( msg_to_eth, " " );
+        for( register uint16_t i = 0; i < __TELEMETRY_SIZE__; i++ ){
+            strcat( msg_to_eth, itoa( data[ i ], tmp, 16 ) );
+            strcat( msg_to_eth, " " );
+        }
+        for( register uint16_t i = __TELEMETRY_SIZE__; i < __CB_BUFFER_SIZE__ - 1; i++ ){
+            strcat( msg_to_eth, itoa( 0, tmp, 16 ) );
+            strcat( msg_to_eth, " " );
+        }
+        strcat( msg_to_eth, itoa( 0, tmp, 16 ) );
+        
+        if( tcp_session ){ 
+            int debug_sent = tcp_client.send_all( msg_to_eth, strlen( msg_to_eth ) );
+            if( debug_telemetry ) send_msg("%d - bytes enviados pro prompt-eth", debug_sent );
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/telemetry.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,53 @@
+#ifndef __TELEMETRY_H__
+#define __TELEMETRY_H__
+
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "vz_protocol.h" // for __CB_BUFFER_SIZE__
+#include "utils.h" // for itoa();
+#include "debug.h" // for [ en | dis ]able debugs
+
+#define __TELEMETRY_SERVER_IP__ "192.168.120.144"
+///< Estabelece o IP default para onde os dados de telemetria são enviados.
+#define __TELEMETRY_SERVER_PORT__ 9192 
+///< Estabelece a porta default do servidor  para onde os dados de telemetria são enviados
+#define __TELEMETRY_HEADER_PORT__ 9321 
+///< Estabelece a porta default da Header, de onde os pacotes de telemetria são enviados.
+#define __TELEMETRY_SIZE__ __CB_BUFFER_SIZE__ - ( __VZ_HEADER_OFFSET__ + __CLOCK_SYNC_SIZE__ + __SEQ_NUM_SIZE__ )
+///< Indica o nro de bytes efetivos no envio de um pacote de telemetria
+
+/**
+ * @Synopsis Efetivamente inicializa a conexão UDP com o server.
+ */
+void init_telemetry_handler( void );
+
+/**
+ * @Synopsis Fecha e abre novamente a conexão UDP com o server 
+ */
+void re_start_telemetry( void );
+
+/**
+ * @Synopsis Responsavel por formatar e enviar o pacote de telemetria para o servidor de interesse.
+ *
+ * @param ext Ramal do CBx emissor do pacote de telemetria.
+ * @param port Porta do CBx emissor do pacote de telemetria.
+ * @param data Vetor contendo os dados de telemetria em si.
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *  ext = 5160;
+ *  port = 5060;
+ *  //assumindo que data_from_cb contém os dados vindos do Call_box.
+ *  build_telemetry_report( ext, port, ( char * )data_from_cb );
+ * ...
+ * @endcode
+ */
+void build_telemetry_report( int ext, int port, char * data );
+
+extern UDPSocket t_sock;
+///< Canal de entrada/saida de dados entre Header/Server
+extern Endpoint t_server;
+///< Representação do link com o server pro qual os pacotes são enviados.
+
+#endif
\ No newline at end of file
--- a/utils.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/utils.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,13 +1,6 @@
 #include "utils.h"
-#include "prompt.h"
 
-EthernetInterface eth;
-uint8_t cb_tx_buffer[ __CB_BUFFER_SIZE__ ];
-
-ring_buffer * rb = ring_buffer_init( NULL );
-                                                                                      
-UDPSocket t_sock;                                                                                                                      
-Endpoint t_server;
+int ls_comp( const void * a, const void * b ){ return( *( int * )a - *( int * )b ); }
 
 void reverse( char str[], int length ){
     int start = 0;
@@ -45,336 +38,30 @@
     return( str );
 }
 
-void reset_leds( void ){
-    led1 = led2 = 1;
-    led3 = led4 = 0;
-}
+void reset_leds( void ){ led1 = led2 = 1; led3 = led4 = 0; }
 
-int __init_eth__(){    
-    static bool initialized = false;
-    char buff_ip[ 16 ] = "";
-    char buff_msk[ 16 ] = "";
-    char buff_gtw[ 16 ] = "";
-    wdt.kick();
-    pc.printf("\n\r");
-    FILE *fp = fopen( "/qspi/myip.txt", "r");
-    if( fp == NULL ){
-        if( debug_file ) debug_msg("Failed to open /qspi/myip.txt" );
-        strncpy( buff_ip, __MY_IP__, 20 );    
-    }else{
-        int read = fread( buff_ip, 1, 512, fp );
-        if( read > 0 ){
-            for( int i = 0; i < read; i++ ) 
-                if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){
-                    buff_ip[ i ] = '\0';
-                    break;
-                }
-            if( debug_file ) debug_msg("Eth ip %s", buff_ip );
-        }else{
-            if( debug_file ) debug_msg("Failed to read /qspi/myip.txt" );
-            strncpy( buff_ip, __MY_IP__, 20 );
-        }
-    }
-    fclose( fp );
-    buff_ip[ 15 ] = 0;
-        
-    fp = fopen( "/qspi/mymask.txt", "r");
-    if( fp == NULL ){
-        if( debug_file ) debug_msg("Failed to open /qspi/mymask.txt" );
-        strncpy( buff_msk, __MY_MSK__, 20 );    
-    }else{
-        int read = fread( buff_msk, 1, 512, fp );
-        if( read > 0 ){
-            for( int i = 0; i < read; i++ ) 
-                if( buff_msk[ i ] == '\n' || buff_msk[ i ] == '\r' ){
-                    buff_msk[ i ] = '\0';
-                    break;
-                }
-            if( debug_file ) debug_msg("mascara de rede Eth %s", buff_msk );
-        }else{
-            if( debug_file ) debug_msg("Failed to read /qspi/mymask.txt" );
-            strncpy( buff_msk, __MY_MSK__, 20 );
-        }
-    }
-    fclose( fp );
-    buff_msk[ 15 ] = 0;
-    
-    fp = fopen( "/qspi/mygate.txt", "r");
-    if( fp == NULL ){
-        if( debug_file ) debug_msg("Failed to open /qspi/mygate.txt" );
-        strncpy( buff_gtw, __MY_GTW__, 20 );    
-    }else{
-        int read = fread( buff_gtw, 1, 512, fp );
-        if( read > 0 ){
-            for( int i = 0; i < read; i++ ) 
-                if( buff_gtw[ i ] == '\n' || buff_gtw[ i ] == '\r' ){
-                    buff_gtw[ i ] = '\0';
-                    break;
-                }
-            if( debug_file ) debug_msg("Ip Gateway Eth %s", buff_gtw );
-        }else{
-            if( debug_file ) debug_msg("Failed to read /qspi/mygate.txt" );
-            strncpy( buff_gtw, __MY_GTW__, 20 );
-        }
-    }
-    fclose( fp );
-    buff_gtw[ 15 ] = 0;
-    
-    if( !initialized ){
-        //eth.init( buff_ip, buff_msk, buff_gtw );
-        eth.init( buff_ip, buff_msk, __MY_GTW__ );
-        initialized = true;
-        return eth.connect();
-    }
-    
-    if( !eth.disconnect() ){
-        return eth.connect();
-    }
-    else{
-        return eth.connect();
-    }
-}
-
-Call_Box * __find_CB__( Vector * v_cb, int ext ){
-    Call_Box * cb = NULL;
-    for( register int i = 0; i < v_cb->size(); i++ ){
-        cb = ( Call_Box * )v_cb->get_element( i );
-        if( cb->get_ext() == ext ) return( cb );
-    }
-    return( NULL );
-}
-
-VZ_call * __find_Call__( Vector * v_call, int ext ){
-    VZ_call * call = NULL;
-    for( register int i = 0; i < v_call->size(); i++ ){
-        call = ( VZ_call * )v_call->get_element( i );
-        if( call->get_cb_ext() == ext ) return( call );
-    }
-    return( NULL );
-}
-
-void registry_aging( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){
-    Call_Box * cb = NULL;
-    if( v_cb && data && write_buffer ){
-        for( register int i = 0; i < v_cb->size(); i++ ){
-            cb = (Call_Box * )v_cb->get_element( i );
-            if( cb->is_timeout() ){
-                if( cb->reconfigure_timeout() == 0x00 ){
-                    if( debug_alive ) debug_msg("( ext %d removed )", cb->get_ext() );
-                    //cb->unregistry();
-                    v_cb->remove_element( i );
-                    delete( cb );
-                    break;
-                }else{
-                    if( debug_alive ) debug_msg("Ping Cbx %d", cb->get_ext() );      
-                    cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) );                
-                    __send_to_cb__( __build_cb_package__( cb->get_ext(), cb->get_port(), __REGISTRY__, 
-                        ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
-                    cb->registry();
-                }
-            }
-        }
-    }
-}
-
-int sip_manager( Vector * v_cb ){ 
-    static int index = 0;
-    if( v_cb != NULL ){
-        if( v_cb->size() > 0 ){
-            if( index >= v_cb->size() ) index = 0;    
-        }else return 0;
-        Call_Box * cb = (Call_Box * )v_cb->get_element( index );
-        /*  Retorna 
-            = 0 :: ok
-            < 0 :: tive problemas
-            > 0 :: devo remover essa call do vetor de calls 
-        */
-        int returned_value = 0;
-        
-        if( cb->status == cb_on_call || cb->status == cb_idle ){
-            //debug_msg("");
-            returned_value = cb->listen_SIP_server();
-        }
-        index++;
-        return( returned_value );
-    }
-    led1 = !led1;
-    return( -1 );
+int convert_ext_to_port( int ext ){
+  if( ext < 1000 ) return ext;
+  
+  else{
+      int aux = 0;
+      aux = ( ext / 1000 ) * 1000;
+      ext -= aux;
+      aux += ext % 100;
+      return( aux );
+  }
 }
 
-/* remove calls por timeout */
-void call_manager( Vector * v_call, Vector * v_cb, uint8_t * data, uint8_t * write_buffer, Timeslice * ts ){
-    for( register int i = 0; i < v_call->size(); i++ ){
-        VZ_call * call = ( VZ_call * )v_call->get_element( i );
-        if( call->is_timetofinish() ){
-            v_call->remove_element( i );
-            Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() );
-            if( cb ){ 
-                cb->status = cb_idle;
-                ts->return_timeslice( cb->get_timeslice() );
-                cb->set_timeslice( 0x00 );
-                data[ __TIMESLICE_PLACE__ ] = 0x00;
-                cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) );
-                __send_to_cb__( __build_cb_package__( cb->get_ext(), cb->get_port(), __CB_BYE__, 
-                    ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
-                cb->send_bye();
-                set_status( cb->sip->status, sip_idle );
-                cb->re_start_timer();
-            }
-            delete( call );    
-        }
-    }    
+void xstrcpy(uint8_t * dest, const uint8_t * src ){
+  while (*src)  *dest++ = *src++;
+  *dest = 0; 
 }
 
-void build_telemetry_report( int ext, int port, char * data ){
-    char aux[ __CB_BUFFER_SIZE__ + 6 ];
-    char tmp[ 6 ];
-    strcpy( aux, itoa( ext, tmp, 10 ) );
-    strcat( aux, " " );
-    
-    //strncat( aux, (char * )data, __TELEMETRY_SIZE__ );
-    /*
-    pc.printf("\n\r 1. ");
-    uint8_t count = 2;
-    for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ){
-        if( i > 0 && !( i % 15 )  ) pc.printf("\n\r%2i. ", count++ );
-        pc.printf("%3x ", data[ i ] );
-    }
-    pc.printf("\n\r");
-    */
-    //pulando o byte de id ( sequence number )
-    data += __SEQ_NUM_SIZE__;
-    //pulando os bytes do clock
-    data += __CLOCK_SYNC_SIZE__;
-    
-    uint8_t offset = strlen( aux );
-    
-    for( register uint16_t i = 0; i < __TELEMETRY_SIZE__; i++ ) aux[ i + offset ] = data[ i ];
-    
-    for( register uint16_t i = __TELEMETRY_SIZE__ + offset; i < __CB_BUFFER_SIZE__; i++ ) aux[ i ] = 0;
-    
-        int sent = t_sock.sendTo( t_server, aux, __CB_BUFFER_SIZE__ );
-    if( debug_telemetry ) send_msg(" Valor de retorno sent-- %d ", sent );
-    
-    if( sent == -1 ){ 
-        re_start_telemetry();
-        sent = t_sock.sendTo( t_server, aux, __CB_BUFFER_SIZE__ );
-        
-        if( debug_telemetry ) send_msg(" Valor de retorno sent-- %d ", sent );
-    }
-    
-    if( debug_telemetry ){
-        pc.printf("\n\r 1. ");
-        uint8_t count = 2;
-        for( register int i = 0; i < __CB_BUFFER_SIZE__; i++ ){
-            if( i > 0 && !( i % 15 )  ) pc.printf("\n\r%2i. ", count++ );
-            pc.printf("%3x ", aux[ i ] );
-        }
-        pc.printf("\n\r");
-        
-        char msg_to_eth[ 1024 ];
-        strcpy( msg_to_eth, tmp );
-        strcat( msg_to_eth, " " );
-        for( register uint16_t i = 0; i < __TELEMETRY_SIZE__; i++ ){
-            strcat( msg_to_eth, itoa( data[ i ], tmp, 16 ) );
-            strcat( msg_to_eth, " " );
-        }
-        for( register uint16_t i = __TELEMETRY_SIZE__; i < __CB_BUFFER_SIZE__ - 1; i++ ){
-            strcat( msg_to_eth, itoa( 0, tmp, 16 ) );
-            strcat( msg_to_eth, " " );
-        }
-        strcat( msg_to_eth, itoa( 0, tmp, 16 ) );
-        
-        if( tcp_session ){ 
-            int debug_sent = tcp_client.send_all( msg_to_eth, strlen( msg_to_eth ) );
-            if( debug_telemetry ) send_msg("%d - bytes enviados pro prompt-eth", debug_sent );
-        }
-    }
+void xmemcpy(uint8_t * dest, uint8_t * src, uint16_t size ){
+  while (size--) *dest++ = *src++;
 }
 
-void __send_to_cb__( uint8_t * buffer ){
-    if( tx_clear == 1 ){
-        tx_clear = 0;
-        xmemcpy( TXBuffer, buffer, DATA_SIZE );
-        parallel_write( TXBuffer[ 0 ] );
-        DataReady = 1;
-        xmemcpy( cb_tx_buffer, buffer, __CB_BUFFER_SIZE__ );           
-        //send2callboxes();
-    }else{
-        uint8_t ret = ring_buffer_add( rb, buffer );
-        
-        if( ret == 0x01 ) if( dparallel ) send_msg("Error: Ring buffer fully charged");
-        
-        if( ret == 0x00 ) if( dparallel ) send_msg("Success : package queued -- on queue %u", rb->size );
-    }
-}
-
-void tx_buffer_ring_buffer_handler( void ){
-    if( rb->size != 0x00 ){
-        if( tx_clear == 1 ){
-            uint8_t * buffer = ring_buffer_get_next( rb );
-            xmemcpy( TXBuffer, buffer, DATA_SIZE );
-            xmemcpy( cb_tx_buffer, buffer, __CB_BUFFER_SIZE__ );
-            if( dparallel ) send_msg("Ring Buffer less one -- remain %u", rb->size );
-            send2callboxes();
-        }
-    }
-}
-
-void init_telemetry_handler( void ){
-    char buff_ip[ 16 ] = "";
-    char buff_port[ 8 ] = "";
-    int telemetry_port = 0;
-    
-    FILE *fp = fopen( "/qspi/telemetry_ip.txt", "r");
-    if( fp == NULL ){
-        if( debug_file ) debug_msg("Failed to open /qspi/telemetry_ip.txt" );
-        strncpy( buff_ip, __TELEMETRY_SERVER_IP__, 20 );    
-    }else{
-        int read = fread( buff_ip, 1, 512, fp );
-        if( read > 0 ){
-            for( int i = 0; i < read; i++ ) 
-                if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){
-                    buff_ip[ i ] = '\0';
-                    break;
-                }
-            if( debug_file ) debug_msg("Telemetry server ip %s", buff_ip );
-        }else{
-            if( debug_file ) debug_msg("Failed to open /qspi/telemetry_ip.txt" );
-            strncpy( buff_ip, __TELEMETRY_SERVER_IP__, 20 );
-        }
-    }
-    fclose( fp );
-    
-    fp = fopen( "/qspi/telemetry_port.txt", "r");
-    if( fp == NULL ) {
-        if( debug_sip ) debug_msg("Failed to open /qspi/telemetry_port.txt" );
-        telemetry_port = __TELEMETRY_SERVER_PORT__;
-    } else {
-        if( fread( (void *)buff_port, 1, 32, fp ) > 0 ) {
-            telemetry_port = atoi( buff_port );
-            if( debug_sip ) debug_msg("Telemetry server port %d", buff_port );
-        } else {
-            if( debug_sip ) debug_msg("Failed to read /qspi/telemetry_port.txt" );
-            telemetry_port = __TELEMETRY_SERVER_PORT__;
-        }
-    }
-    fclose( fp );    
-    
-    //int addr = t_server.set_address( __TELEMETRY_SERVER_IP__ , __TELEMETRY_SERVER_PORT__ );
-    int addr = t_server.set_address( buff_ip , telemetry_port );
-    if( debug_telemetry ) send_msg(" Valor de retorno set_address -- %d ", addr );
-    t_sock.set_blocking( false, 1 );
-    
-    int bind = t_sock.bind( __TELEMETRY_HEADER_PORT__ );
-    if( debug_telemetry ) send_msg(" Valor de retorno bind -- %d ", bind );
-}
-
-void re_start_telemetry( void ){
-    int close = t_sock.close();
-    if( debug_telemetry ) send_msg(" Valor de retorno close-- %d ", close );
-    
-    init_telemetry_handler();
-}
-
-int ls_comp( const void * a, const void * b ){ return( *( int * )a - *( int * )b ); }
\ No newline at end of file
+void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size){
+  size >>= 2;
+  while (size--) *dest++ = *src++;
+}
\ No newline at end of file
--- a/utils.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/utils.h	Mon Nov 24 16:43:16 2014 +0000
@@ -9,36 +9,13 @@
 #ifndef __UTILS_H__
 #define __UTILS_H__
 
-#include <iostream>
-#include <string.h>
-#include "debug.h"
+#include <iostream> // need for swap
 #include "mbed.h"
-#include "EthernetInterface.h"
-#include "vz_protocol.h"
-#include "vector.h"
-#include "sip.h"
-#include "call.h"
-#include "call_box.h"
-#include "timeslice.h"
-#include "parallelcpld.h"
-#include "prompt.h"
-#include "configs.h"
-#include "ring_buffer.h"
-
-extern uint8_t cb_tx_buffer[ __CB_BUFFER_SIZE__ ];
-///< Armazena o ultimo pacote enviado para os CBx
-
-extern ring_buffer * rb;
+#include "shared_variables.h"
+#include "debug.h"
 
 using namespace std;
 
-extern DigitalOut led1;
-extern DigitalOut led2;
-extern DigitalOut led3;
-extern DigitalOut led4;
-extern EthernetInterface eth;
-extern UDPSocket t_sock;
-extern Endpoint t_server;
 #define set_status(a,b) _set_status(a,b)
 #define _set_status(a,b){ \
   if( a != b ) if( debug_sip )debug_msg("Anterior %d -- Atual %d", a, b ); \
@@ -95,83 +72,6 @@
 void reset_leds( void );
 
 /**
- * @Synopsis Responsavel por inicializar as configurações iniciais de conexão eth
- *
- * @return 0 ( zero ) caso tenha uma execução bem sucedida, um numero negativo, caso contrário.
- *
- * Exemplo:
- * @code
- * ...
- *   int eth_status = __init_eth__();
- * ...
- * @endcode
- */
-int __init_eth__( void );
-
-/**
- * @Synopsis Busca por um determinado Call_box no vetor de Call_box usando como chave de busca o ramal.
- *
- * @param v_cb O vetor contendo todos os Call_box conhecidos pela Header em determinado momento.
- * @param ext O ramal pelo qual se irá buscar o CBx.
- *
- * @return NULL caso não tenha sido encontrado nenhum CBx com esse ramal; retorna um ponteiro para o Call_box que possui esse ramal,
- * caso o mesmo tenha sido encontrado.
- *
- * Exemplo:
- * @code
- * ...
- *  Vector * v_cb = new Vector();
- *      //assumindo que esse vetor de Call_Box já foi populado.
- *  int ext = 5218;
- *  Call_Box * cb = __find_CB__( v_cb, ext );
- * ...
- * @endcode
- */
-Call_Box * __find_CB__( Vector * v_cb, int ext );
-
-/**
- * @Synopsis Busca por uma determinada ligação vz_call no vetor de v_calusando como chave de busca o ramal.
- *
- * @param v_call Um vetor contendo todas as vz_calls em andamento em um dado momento.
- * @param ext O ramal pelo qual se irá buscar a vz_call.
- *
- * @return NULL, caso essa chamada não tenha sido encontrada; um ponteiro para esta chamada, caso a mesma tenha sido encontrada.
- *
- * Exemplo:
- * @code
- * ...
- *  Vector * v_call = new Vector();
- *      //assumindo que esse vetor de VZ_call já foi populado.
- *  int ext = 5218;
- *  VZ_call * call = __find_Call__( v_call, ext );
- * ...
- * @endcode
- */
-VZ_call * __find_Call__( Vector * v_call, int ext );
-
-/**
- * @Synopsis Função responsavel por "envelhecer" os registros na Header, na prática, é essa função que pergunta de tempo
- * em tempo se o CBx ainda continua ativo; Essa função também é responsavel por remover o CBx do v_cb assim como deletar o elemento cb
- * assossiado.
- *
- * @param v_cb Um vetor contendo todos os Call_box conhecidos pela Header em um determinado momento.
- * @param data Usado para a criação do pacote de "ping" que a Header irá enviar para o CBx.
- * @param write_buffer Local de memória onde efetivamente irá ser montado o pacote para envio ao CBx do pacote de "ping" ( Registry ).
- *
- * Exemplo:
- * @code
- * ...
- *  Vector * v_cb = new Vector();
- *      //assumindo que esse vetor de Call_Box já foi populado.
- *  uint8_t buffer[ 300 ];
- *      uint8_t write_buffer[ 300 ];
- *  registry_aging( v_cb, buffer, write_buffer );
- * ...
- * @endcode
- */
-void registry_aging( Vector * v_cb, uint8_t * data, uint8_t * write_buffer );
-
-/**
  * @Synopsis Responsavel por escutar a porta de conexão com o servidor, verificando se o mesmo mandou algum dado.
  *
  * @param v_cb Um vetor contendo todos os Call_box conhecidos pela Header em um determinado momento.
@@ -193,68 +93,6 @@
  * ...
  * @endcode
  */
-int sip_manager( Vector * v_cb ); 
-
-/**
- * @Synopsis Responsável por remover calls por timeout.
- *
- * @param v_call Um vetor contendo todas as vz_calls em andamento em um dado momento.
- * @param v_cb Um vetor contendo todos os Call_box conhecidos pela Header em um determinado momento.
- * @param data Usado para a criação do pacote de "ping" que a Header irá enviar para o CBx.
- * @param write_buffer Local de memória onde efetivamente irá ser montado o pacote para envio ao CBx. 
- * @param ts O timeslice que será possivelmente devolvido.
- *
- * Exemplo:
- * @code
- * ...
- *  Vector * v_call = new Vector();
- *  Vector * v_cb = new Vector();
- *      // assumindo que os vetores já foram populados.
- *  uint8_t buffer[ 300 ];
- *      uint8_t write_buffer[ 300 ];
- *      Timeslice * ts = new Timeslice();
- *      ...
- *      call_manager( v_call, v_cb, buffer, write_buffer, ts ); 
- * ...
- * @endcode
- */
-void call_manager( Vector * v_call, Vector * v_cb, uint8_t * data, uint8_t * write_buffer, Timeslice * ts );
-
-/**
- * @Synopsis Responsavel por formatar e enviar o pacote de telemetria para o servidor de interesse.
- *
- * @param ext Ramal do CBx emissor do pacote de telemetria.
- * @param port Porta do CBx emissor do pacote de telemetria.
- * @param data Vetor contendo os dados de telemetria em si.
- *
- * Exemplo:
- * @code
- * ...
- *  ext = 5160;
- *  port = 5060;
- *  //assumindo que data_from_cb contém os dados vindos do Call_box.
- *  build_telemetry_report( ext, port, ( char * )data_from_cb );
- * ...
- * @endcode
- */
-void build_telemetry_report( int ext, int port, char * data );
-
-/**
- * @Synopsis Executa chamada para chamada de baixo nivel send2callboxes para efetivamente enviar os dados para o CBx.
- *
- * @param buffer O pacote VZ que será enviado para os CBx.
- *
- * Exemplo:
- * @code
- * ...
- * //assumindo que o pacote já foi montado em pkg.
- *  __send_to_cb__( pkg );
- * ...
- * @endcode
- */
-void __send_to_cb__( uint8_t * buffer );
-
-void tx_buffer_ring_buffer_handler( void );
 
 /**
  * @Synopsis Função usada na ordenação dos CBx para exibição no comando "ls"
@@ -277,14 +115,26 @@
 int ls_comp( const void * a, const void * b );
 
 /**
- * @Synopsis Efetivamente inicializa a conexão UDP com o server.
+ * @Synopsis Função que converte o ramal para a porta, por definição de projeto, cara ramo possui o numero da centena incremental
+ * permanecendo o resto igual, por exemplo no ramo pilo os ramais são 5000, 5001 -- no lote 1 5100, 5101 -- porem a porta sempre
+ * se manteve a mesma, o CBx esta configurado como ramal 5000 e porta 5000, assim como o ramal 5100 e porta 5000, em outras palavras
+ * dado um ramal, calcular a porta é o mesmo que eliminar a centena do numero.
+ *
+ * @param ext O ramal do qual se quer calcular a porta vinculada.
+ *
+ * @return O valor calculado da porta.
+ *
+ * Exemplo:
+ * @code
+ * ...
+ *  int ext = 5220;
+ *  int port = convert_ext_to_port( ext );
+ * ...
+ * @endcode
  */
-void init_telemetry_handler( void );
-
+int convert_ext_to_port( int ext );
 
-/**
- * @Synopsis Fecha e abre novamente a conexão UDP com o server 
- */
-void re_start_telemetry( void );
-
+void xstrcpy( uint8_t * dest, const uint8_t * src);
+void xmemcpy( uint8_t * dest, uint8_t * src, uint16_t size);
+void xmemcpy32(uint32_t * dest, uint32_t * src, uint16_t size);
 #endif
\ No newline at end of file
--- a/vector.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/vector.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,5 +1,4 @@
 #include "vector.h"
-#include "prompt.h"
 
 Vector::Vector(){
     this->objects = NULL;
--- a/vz_protocol.cpp	Wed Nov 19 14:06:13 2014 +0000
+++ b/vz_protocol.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -1,6 +1,5 @@
 #include "vz_protocol.h"
 
-
 //#include "debug.h"
     
 //extern DigitalOut led2;
--- a/vz_protocol.h	Wed Nov 19 14:06:13 2014 +0000
+++ b/vz_protocol.h	Mon Nov 24 16:43:16 2014 +0000
@@ -6,16 +6,15 @@
  * @date 2014-11-05
  */
 
-#ifndef _VZ_PROTOCOL_H__
-#define _VZ_PROTOCOL_H__
+#ifndef __VZ_PROTOCOL_H__
+#define __VZ_PROTOCOL_H__
 
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
-#include "rtp.h"
+#include "shared_variables.h" // for __RTP_HEADER_SIZE__ 
+#include "utils.h" // for xmemcpy
 #include "bits.h"
-#include "prompt.h" // por conta do flood/tcp_session
-// 7 + 14 + 1 == ts
 
 #define __START_PKG_COUNT__ 100 
 ///< Estabelece o inicio dos pacotes RTP, não utilizado atualmente
@@ -32,13 +31,6 @@
 #define __TCP_PORT__ 8709 
 ///< Antiga porta TCP que a Header ouvia, descontinuado.
 
-#define __TELEMETRY_SERVER_IP__ "192.168.120.163" 
-///< Estabelece o IP default para onde os dados de telemetria são enviados.
-#define __TELEMETRY_SERVER_PORT__ 9192 
-///< Estabelece a porta default do servidor  para onde os dados de telemetria são enviados
-#define __TELEMETRY_HEADER_PORT__ 9321 
-///< Estabelece a porta default da Header, de onde os pacotes de telemetria são enviados.
-
 #define __VZ_HEADER_OFFSET__ 7 
 ///< Indica o inicio dos dados recebidos efetivamente no pacote VZ.
 #define __CB_BUFFER_SIZE__ 300 
@@ -49,8 +41,6 @@
 ///< Indica o numero de bytes ocupados pelo relogio no pacote transmitido.
 #define __SEQ_NUM_SIZE__ 1 
 ///< Indica o numero de bytes ocupados para uso de sequence number.
-#define __TELEMETRY_SIZE__ __CB_BUFFER_SIZE__ - ( __VZ_HEADER_OFFSET__ + __CLOCK_SYNC_SIZE__ + __SEQ_NUM_SIZE__ ) 
-///< Indica o nro de bytes efetivos no envio de um pacote de telemetria
 #define __ETH_BUFFER_SIZE__ __CB_BUFFER_SIZE__ + __RTP_HEADER_SIZE__ + 1 // 313
 ///< Indica o tamanho real do pacote que será enviado do CBx para o servidor via eth
 #define __CB_AUDIO_DATA_SIZE__ 240 
@@ -215,7 +205,7 @@
  *  int ext = 1011;
  *  port = 1011;
  *  type = __REGISTRY__;
- *  __send_to_cb__( __build_cb_package__( ext, port, type, 
+ *  send2callboxes( __build_cb_package__( ext, port, type, 
  *              ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); 
  * ...
  * @endcode
@@ -254,6 +244,4 @@
 uint8_t * __write_cb_buffer__( uint8_t * dest, uint8_t * src );
 uint8_t * __write_eth_buffer__( uint8_t * dest, uint8_t * src );
 
-//FIXME esta function deveria estar como extern
-extern void __send_to_cb__( uint8_t * buffer );
 #endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wdt_manager.cpp	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,3 @@
+#include "wdt_manager.h"
+
+Watchdog wdt;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wdt_manager.h	Mon Nov 24 16:43:16 2014 +0000
@@ -0,0 +1,8 @@
+#ifndef __WDT_MANAGER_H__
+#define __WDT_MANAGER_H__
+
+#include "wdt.h"
+
+extern Watchdog wdt;
+
+#endif
\ No newline at end of file