![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
debugs removidos - ligacao em pares ok
Dependencies: EthernetInterface NTPClient mbed-rtos mbed
Fork of header_main by
Diff: main.cpp
- Revision:
- 4:de46f0d9b14d
- Parent:
- 3:cd9148672e25
diff -r cd9148672e25 -r de46f0d9b14d main.cpp --- a/main.cpp Wed Sep 10 18:21:48 2014 +0000 +++ b/main.cpp Thu Sep 11 14:23:47 2014 +0000 @@ -105,8 +105,9 @@ if( data != NULL ){ if( type == __CB_BYE__ ){ - debug_msg("--> %s <--", buffer); + 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 ); if( cb != NULL ){ @@ -123,7 +124,6 @@ // ack from CBx debug_msg("-- ACK do meu pkg --"); type = __DO_NOTHING__; - debug_msg("morri aqui"); } } } @@ -147,17 +147,18 @@ case __CB_BYE__ : { Call_Box * cb = __find_CB__( v_cb, ext ); if( cb != NULL ){ + debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); data[ 0 ] |= BIT7; cb->set_msg_id( data[ 0 ] ); debug_msg( " Request bye from CBx " ); for( register uint8_t i = 0; i < v_call->size(); i++ ){ VZ_call * call = (VZ_call *)v_call->get_element( i ); if( call->get_cb_ext() == ext ){ + cb->send_bye(); ts->return_timeslice( cb->get_timeslice() ); cb->set_timeslice( 0x00 ); set_status( cb->status, cb_idle ); - v_call->remove_element( i ); - cb->send_bye(); + 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__, @@ -173,6 +174,7 @@ debug_msg("ok -- recebido o invite pelo menos"); Call_Box * cb = __find_CB__( v_cb, ext ); if( cb == NULL ){ + debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); cb = new Call_Box( ext, port ); v_cb->add( cb ); set_status( cb->status, cb_idle ); @@ -226,7 +228,7 @@ debug_msg( "-- Trying -- aceitando pedido de invite -- %s ", write_buffer ); //debug_pkg( 300, write_buffer ); }else{ - set_status(cb->status,cb_idle); + set_status( cb->status,cb_idle); ts->return_timeslice( cb->get_timeslice() ); cb->set_timeslice( 0x00 ); data[ __TIMESLICE_PLACE__ ] = 0x00; @@ -237,43 +239,36 @@ set_status( cb->sip->status, sip_idle); } } - }break; - + }break; case cb_busy : { // tratar sip }break; } }break; - case __REGISTRY__ : - { - Call_Box * cb_master = NULL; - Call_Box * cb_slave = NULL; + case __REGISTRY__ : { + Call_Box * cb = NULL; - data[ 0 ] |= BIT7; - cb_master = __find_CB__( v_cb, ext ); - cb_slave = __find_CB__( v_cb, ext + 1 ); - if( cb_master != NULL ){ - cb_master->reset_elapsed_time(); - }else if( cb_slave != NULL ){ - cb_slave->reset_elapsed_time(); + data[ 0 ] |= BIT7 ; + cb = __find_CB__( v_cb, ext ); + if( cb != NULL ){ + cb->reset_elapsed_time(); + debug_msg(" reset_elapsed_time CBx -- %d", ext ); }else{ - cb_master = new Call_Box( ext, port ); - cb_slave = new Call_Box( ext + 1, port + 1 ); - - v_cb->add( cb_master ); - v_cb->add( cb_slave ); - debug_msg("Registrados"); + 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 ); } - cb_master->registry(); - cb_slave->registry(); - }break; - case __BOOT__ : - __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, - ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); - break; - case __TELEMETRY__ : - debug_msg("Leitura da bateria :: ( Id : %x, MSB : %x, LSB : %x )", data[ 0 ], data[ 1 ], data[ 2 ] ); - break; + debug_msg("::Registrado %d - %d::", ext, port ); + cb->registry(); + }break; + case __BOOT__ : { + __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, + ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + }break; + case __TELEMETRY__ : { + debug_msg("Leitura da bateria :: ( Id : %x, MSB : %x, LSB : %x )", data[ 0 ], data[ 1 ], data[ 2 ] ); + }break; case __AUDIO__ : { Call_Box * cb; VZ_call * call = NULL; @@ -288,6 +283,8 @@ call->send_message( pkg ); cb = __find_CB__( v_cb, ext ); if( cb != NULL ) cb->reset_elapsed_time(); + }else{ + debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); } }break; }// fim switch @@ -299,36 +296,45 @@ Call_Box * cb = NULL; int cb_port = 0xffff; cb = __find_CB__( v_cb, call->get_cb_ext() ); - if( cb != NULL ) cb_port = cb->get_port(); + + if( cb != NULL ){ + cb_port = cb->get_port(); + }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); + uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, tmp, __AUDIO__, length, write_buffer ); + __send_to_cb__( pkg2cb ); } } //nessa funcao eu deveria me registar a cada 2 min por exemplo registry_aging( v_cb, data, write_buffer ); + int ret = sip_manager( v_cb, v_call, write_buffer ); if( ret > 0x00 ){ Call_Box * cb = __find_CB__( v_cb, ret ); - if( cb->status == cb_on_call ){ - ts->return_timeslice( cb->get_timeslice() ); - cb->set_timeslice( 0x00 ); - set_status(cb->status,cb_idle); - buffer[ __TIMESLICE_PLACE__ ] = 0x00; - cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); - for( register uint8_t i = 0; i < v_call->size(); i++ ){ - VZ_call * call = ( VZ_call * )v_call->get_element( i ); - if( call->get_cb_ext() == ret ){ - v_call->remove_element( i ); - delete( call ); + if( cb != NULL ){ + if( cb->status == cb_on_call ){ + ts->return_timeslice( cb->get_timeslice() ); + cb->set_timeslice( 0x00 ); + set_status(cb->status,cb_idle); + buffer[ __TIMESLICE_PLACE__ ] = 0x00; + cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); + for( register uint8_t i = 0; i < v_call->size(); i++ ){ + VZ_call * call = ( VZ_call * )v_call->get_element( i ); + if( call->get_cb_ext() == ret ){ + v_call->remove_element( i ); + delete( call ); + } } + __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(); + set_status( cb->sip->status, sip_idle ); } - __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(); - set_status( cb->sip->status, sip_idle ); - } + }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); } + call_manager( v_call, v_cb, data, write_buffer, ts ); static uint8_t flag = 0; @@ -339,7 +345,7 @@ if (flag == 1) { flag = 0; } } /* eu deveria tirar ts que nao constam em chamadas aqui */ - for( register uint8_t i = 0; i < v_cb->size(); i++ ){ +/* for( register uint8_t i = 0; i < v_cb->size(); i++ ){ Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); if( cb->get_timeslice() != 0x00 ){ VZ_call * call = __find_Call__( v_call, cb->get_ext() ); @@ -350,6 +356,6 @@ } } } - type = __DO_NOTHING__; +*/ type = __DO_NOTHING__; } } \ No newline at end of file