Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: sip.cpp
- Revision:
- 74:81c47fff88a5
- Parent:
- 50:d9b6577a70f5
- Child:
- 76:9f5f99dd895a
diff -r 3b4e282eeff7 -r 81c47fff88a5 sip.cpp --- 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 ); } } }