Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
119:ee6a53069455
Parent:
117:e9facba9db27
Child:
121:ee02790d00b7
--- a/call.cpp	Fri Apr 24 13:54:24 2015 +0000
+++ b/call.cpp	Thu Apr 30 15:42:41 2015 +0000
@@ -6,18 +6,16 @@
     
     this->rtp_server_ext = rtp_server_ext;
     this->rtp_server_port = rtp_server_port;
-    this->rtp_server.set_address( __RTP_SEVER_IP__, rtp_server_port );
+    this->rtp_server.set_address( SERVER_IP, rtp_server_port );
     rtp_sock.set_blocking( false, 0 );
-    debug_msg("primeiro");
     this->rtp_sock.bind( cb_port ); // rtp port
-    debug_msg("segundo");
     this->rtp_sock.init();
     this->rtp = new RTP( this->cb_ext );
     
     if( rtp == NULL )
     { 
         memory_is_over = true;
-        if( debug_memory ) debug_msg("Call_Box cb allocation fail");
+        if( debug_memory ) debug_msg("[%d] Call_Box cb allocation fail", this->cb_ext );
     }
     
     t.start();
@@ -34,6 +32,8 @@
 
 char * VZ_call::get_eth_message( int * length ){
     uint8_t * pkg;
+    Endpoint rtp_from;
+    
     *length = rtp_sock.receiveFrom( rtp_server, server2cb, sizeof( server2cb ) );
     t.reset();
     
@@ -54,36 +54,39 @@
     return NULL;
 }
 
-int VZ_call::send_message( char * buffer  ){
-    t.reset();
-    return( this->rtp_sock.sendTo( this->rtp_server, buffer, __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ) );
-    
-    /*
-    //FIXME verificar como fica se eu esperar o sendTo chegar em != 0
-    int8_t sent = 0;
-    do{
-        sent = this->rtp_sock.sendTo( this->rtp_server, buffer, __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ) );
-    }while( sent == 0 );
-    return( sent );
-    */
-}
-
-uint8_t * VZ_call::build_cb_package( void ){
-    // return __build_cb_package__( cb_ext, cb_port, __AUDIO__, server2cb, buffer );
-    // colocar esta funcao novamente pra envio de msg, assim como encapsular melhor a funcao
-    // de criacao dos pacotes pro cb em algumas funcoes.
-    return 0x00;
+int VZ_call::send_message ( char * buffer  )
+{
+    this->t.reset();
+    int send = this->rtp_sock.sendTo( this->rtp_server, buffer, CB_AUDIO_DATA_SIZE + this->rtp->header_size() );
+    if( send != CB_AUDIO_DATA_SIZE + this->rtp->header_size() )
+    {
+        if( debug_reconnect )
+        {
+            send_msg("[%d] Reconnect RTP", this->cb_ext );
+            miss_ftp_udp_send_pkg++;
+        }
+        reconnect();
+    }
+    return( send );
 }
 
 char * VZ_call::build_eth_package( uint8_t * buffer ){
     return this->rtp->build_eth_package( ( char * )buffer );    
 }
 
-int VZ_call::get_cb_ext(){ return this->cb_ext; }
-int VZ_call::get_cb_port(){ return this->cb_port; }
+int VZ_call::get_cb_ext ()
+{ 
+    return this->cb_ext; 
+}
+
+int VZ_call::get_cb_port ()
+{ 
+    return this->cb_port; 
+}
 
 int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; }
 int VZ_call::get_rtp_server_port(){ return rtp_server_port; }
+
 uint8_t * VZ_call::get_cb2server_buffer(){ return cb2server; }
 char * VZ_call::get_server2cb_buffer(){ return server2cb; }
 inline uint8_t * VZ_call::get_buffer(){ return buffer; }
@@ -96,7 +99,7 @@
     return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false;
 }
 
-int VZ_call::get_elapsed_time( void ){
+uint16_t VZ_call::get_elapsed_time( void ){
     return ( finish.read_ms() );
 }
 
@@ -112,7 +115,6 @@
     cbx_pkg_idle_timer.start();
 }
 
-
 int VZ_call::print_yourself ( void )
 {
     send_msg("t :: %d", ( int  ) t.read () );
@@ -136,4 +138,11 @@
 int VZ_call::rtp_print_yourself ( void )
 {
     return rtp -> print_yourself ();
+}
+
+void VZ_call::reconnect ( void )
+{
+    this->rtp_sock.close();
+    this->rtp_sock.set_blocking( false, 0 );
+    this->rtp_sock.bind( cb_port );
 }
\ No newline at end of file