![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
voltando a versao de n aberturas e fechamentos de sockets data 19/09
Dependencies: EthernetInterface NTPClient mbed-rtos mbed EALib
Fork of header_main_publish by
Diff: main.cpp
- Revision:
- 9:ffa64f38ef9c
- Parent:
- 8:e3bfe62a477e
- Child:
- 10:22da1a0ac1e1
diff -r e3bfe62a477e -r ffa64f38ef9c main.cpp --- a/main.cpp Mon Sep 15 15:13:52 2014 +0000 +++ b/main.cpp Mon Sep 15 17:51:46 2014 +0000 @@ -30,9 +30,10 @@ /* referencia e inicio da conexao com a ethernet */ EthernetInterface eth; - volatile int eth_status = __init_eth__( ð ); + int eth_status = __init_eth__( ð ); + if( eth_status ){ - debug_msg("Falha ao conectar com a Eth"); + debug_msg("Sem conexao eth"); } /* debugs */ @@ -107,6 +108,9 @@ data = __parse_cb_buffer__( &ext, &port, &type, buffer ); if( data != NULL ){ + if( type == __CB_BYE__ ){ + debug_msg("--> %s <--", buffer); + } debug_msg("Procurando pelo CBx :: %d -- Type :: %d", ext, type ); if( type != __AUDIO__ ){ Call_Box * cb = __find_CB__( v_cb, ext ); @@ -118,7 +122,6 @@ if( type == __BOOT__ ) type = __REGISTRY__; __send_to_cb__( __build_cb_package__( ext, port, type, ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - cb->set_msg_id( 0x11 ); type = __DO_NOTHING__; debug_msg("-- Renviado ultimo pkg --"); }else if( data[ 0 ] == ( cb->get_msg_id() | BIT7 ) ){ @@ -135,7 +138,7 @@ if( t.read() > 5 ){ for( register uint8_t i = 0; i < v_cb->size(); i++ ){ Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); - debug_msg("~Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); + debug_msg(" Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); } t.reset(); led3 = !led3; @@ -213,11 +216,12 @@ cb->set_timeslice( ts->get_timeslice() ); if( cb->get_timeslice() == 0x00 ){ //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__, ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); set_status( cb->sip->status, sip_idle); - debug_msg( "-- Trying -- Sem TS -- " ); + debug_msg( "-- Trying -- Sem TS -- %s ", write_buffer ); }else{ set_status(cb->status,cb_busy); data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); @@ -236,7 +240,7 @@ debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - debug_msg( "-- Trying -- aceitando pedido de invite -- "); + debug_msg( "-- Trying -- aceitando pedido de invite -- %s ", write_buffer ); //debug_pkg( 300, write_buffer ); }else{ set_status( cb->status,cb_idle); @@ -246,9 +250,8 @@ debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - debug_msg( "-- Trying -- Negando pedido de invite -- " ); + debug_msg( "-- Trying -- Negando pedido de invite -- %s ", write_buffer ); set_status( cb->sip->status, sip_idle); - debug_msg( "-- Trying -- Negando pedido de invite -- " ); } } }break; @@ -266,7 +269,7 @@ cb->reset_elapsed_time(); debug_msg(" reset_elapsed_time CBx -- %d", ext ); }else{ - debug_msg("criando CBx :: %d -- Type :: %d", ext, type ); + debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); cb = new Call_Box( ext, port ); v_cb->add( cb ); debug_msg(" Criado CBx -- %d", ext ); @@ -279,19 +282,7 @@ ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); }break; case __TELEMETRY__ : { - debug_msg("Ext :: %d ::", ext ); - //TODO implementar que quando, a header recebe um pacote de telemetria - //verifica se o call box esta alocado, caso contratio, manda um pacote - //pro cbx pedindo esse registro. - /* - data[ 0 ] |= BIT7 ; - Call_Box * cb = __find_CB__( v_cb, ext ); - if( cb == NULL ){ - __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, - ( char * )buffer, 0, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - } - debug_msg("fim telemetry"); - */ + debug_msg("Tele"); }break; case __AUDIO__ : { Call_Box * cb; @@ -303,7 +294,7 @@ //debug_pkg( 242, data ); //char * pkg = call->build_eth_package( oitocentos ); //char * pkg = call->build_eth_package( data ); - char * pkg = call->build_eth_package( data ); + char * pkg = call->build_eth_package( data + 2 ); call->send_message( pkg ); cb = __find_CB__( v_cb, ext ); if( cb != NULL ) cb->reset_elapsed_time(); @@ -311,8 +302,7 @@ debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); } }break; - }// fim switch - //if( type != __DO_NOTHING__ ) debug_msg( "sai do switch" ); + }// fim switch for( register int i = 0; i < v_call->size(); i++ ){ VZ_call * call = ( VZ_call * )v_call->get_element( i ); int length = 0; @@ -332,6 +322,7 @@ __send_to_cb__( pkg2cb ); } } + //nessa funcao eu deveria me registar a cada 2 min por exemplo registry_aging( v_cb, buffer, write_buffer ); int ret = sip_manager( v_cb, v_call, write_buffer ); @@ -351,7 +342,6 @@ delete( call ); } } - cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); cb->reset_sip(); @@ -360,7 +350,7 @@ }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); } - call_manager( v_call, v_cb, buffer, write_buffer, ts ); + call_manager( v_call, v_cb, data, write_buffer, ts ); static uint8_t flag = 0; if( v_call->size() == 0 ){