![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
main.cpp
- Committer:
- klauss
- Date:
- 2015-04-30
- Revision:
- 119:ee6a53069455
- Parent:
- 118:b93b17c50910
- Child:
- 120:770f00554b1e
File content as of revision 119:ee6a53069455:
#include "main_includes_configs.h" int main() { debug_uart3 = true; int header_app_init_ret = header_app_init (); send_msg( "header_app_init %s" , ( header_app_init_ret == 0 ) ? "Ok" : "Failure" ); if ( header_app_init_ret == 0 ) send_msg("Ready"); debug_uart3 = false; /*------------------------------------------ main loop ---------------------------------------------------------------*/ while( true ) { if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); if( sync_timer.read() > 5 ) { sync_timer.reset(); if( debug_cks == true ) { pcks_s = true; } if( debug_alive == true ) { pshowcb = true; } if( !( ++count % 15 ) ) { if( eth_status ) { try_reconnect_with_eth (); } } //35 sec. if( ( count > 7 ) && ( wake_all == false ) ) { wake_all = true; if( debug_wake == true ) send_msg( "Time to wake" ); } // enable na variavel que exibe lista com estatisticas de pacotes que falharam ao serem enviados via interface eth if ( debug_missed ) { missed_send_udp_pkg = true; } } prompt_process( NULL, 0 ); check_clock (); if ( r_stats ) { reset_stats (); r_stats = false; stats = true; } if ( stats ) { show_stats (); stats =false; } if ( list ) { show_cb_list ( v_cb ); list = false; } if ( long_list ) { show_cb_long_list ( v_cb ); long_list = false; } if ( pshowcb ) { show_cb ( v_cb ); pshowcb = false; } if ( show_current_time ) { show_clock (); show_current_time = false;; } if ( test_flag_unusual ) _this_is_a_only_test (); if( show_sip == true ){ show_sip = false; send_msg(":: Sip :: %u", v_cb->size() ); for( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); send_msg("ext :: %d -- port :: %d -- timer %d", cb->get_sip_ext(), cb->get_sip_port(), cb->get_timer() ); } } if( pflood == true ) flood(); if( debug_eth ) { debug_eth = false; send_msg("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); } if( status != WAITING ) { pkg_wdt = RX_CB_IDLE; xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE ); status = WAITING; missed_pkg--; xmemcpy( buffer, cb_rx_buffer, CB_BUFFER_SIZE ); if( rx ) { char str[ 1024 ]; strcpy( str, "RX :: \n\r " ); for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) { char tmp[ 16 ]; strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); else strcat( str, " " ); } send_msg( "%s", str ); rx = false; } data = parse_vz_pkg ( &ext, &port, &type, buffer ); if( data != NULL ) { if( min_ext == 0 ) min_ext = ext; if( ext > max_ext ) max_ext = ext; if( ext < min_ext ) min_ext = ext; if( debug_fw ){ fw_cbx_pkg( ext, port, ( char *)buffer ); } if( type == TELEMETRY ) telemetry_counter++; if( type != AUDIO ) { if( type == TELEMETRY || type == CB_STATS || type == FW1 || type == FW2 || type == FW3 || type == FW4 || type == FW5 || type == FW6 ) type = FW; if( debug_cb_rx == true ){ send_msg("[%d %d] -- Type :: %d", ext, port, type ); } Call_Box * cb = __find_CB__( v_cb, ext ); if( cb != NULL ) { if( data[ 0 ] & BIT7 ) { if( type == BOOT ) { send2callboxes( build_cb_package( ext, port, REGISTRY, ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); } else { if( debug_main ) debug_msg("[%d] Received ack pkg with seq_num %d", ext, data[ 0 ] ); switch( type ) { case INVITE : { if( debug_main || debug_invite ) debug_msg("[%d] Invite Ack - msg_id %d -- Cbx seqNum %d", ext, cb->get_msg_id(), data[ 0 ] ); break; } case CB_BYE : { if( debug_main || debug_invite ) debug_msg("[%d] BYE Ack - msg_id %d", ext, cb->get_msg_id() ); cb->set_bye_response_ok(); break; } case REGISTRY : { if( debug_main || debug_aging ) debug_msg("[%d] Registry ACK - msg_id %d", ext, cb->get_msg_id() ); break; } default : { if( debug_main || debug_aging ) debug_msg("[%d] ACK msg_id :: %d :: type %d", ext, cb->get_msg_id(), type ); } } if( type != REGISTRY && type != CB_BYE && type != INVITE ) type = DO_NOTHING; if( type == CB_BYE ){ VZ_call * call = __find_Call__( v_call, ext ); if( call != NULL ){ if( call->get_elapsed_time() < 120000 ){ if( debug_invite ) debug_msg("[%d] ack bye ignored", ext ); type = DO_NOTHING; } } } } } } } } else type = DO_NOTHING; } if( sizes == true ) { sizes = false; send_msg("CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter ); send_msg("SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter ); send_msg("RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter ); send_msg("RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter ); send_msg("Call_New (%u) -- Call_Delete (%u)", call_new_counter, call_delete_counter ); send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); send_msg("Memory is %s", ( memory_is_over ) ? "Over" : "Ok" ); send_msg("Missed_Pkg :: %d ::", missed_pkg ); send_msg("Sizeof Sip :: %u", sizeof( Sip ) ); send_msg("Sizeof Call_Box :: %u", sizeof ( Call_Box ) ); send_msg("Sizeof VZ_call :: %u", sizeof( VZ_call ) ); send_msg("Sizeof RTP :: %u", sizeof( RTP ) ); send_msg("Sizeof RTP_Header :: %u", sizeof( RTP_Header ) ); send_msg("Sizeof RTP_Body :: %u", sizeof( RTP_Body ) ); send_msg("Sizeof Vector :: %u", sizeof( Vector ) ); send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) ); send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) ); } if ( registra ) { int internal_ext = 8000; registra = false; for( register uint8_t i = 0; i < 4; i++ ) { v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); } } { fd_set fdSet; FD_ZERO(&fdSet); for( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = (Call_Box *)v_cb->get_element( i ); FD_SET( cb->get_sip_socket_fd(), &fdSet); } /* Recepcao de pacotes UDP para atualizacao de callboxes */ FD_SET( udp_bl_client.get_fd(), &fdSet); /* Recepcao de pacotes UDP para "tickagem" do watchdog */ FD_SET( udp_wdt_client.get_fd(), &fdSet); // adiciona o socket de comandos prompt-UDP-ETH FD_SET( udp_client.get_fd(), &fdSet ); // adiciona o socket de pedido de clock para o servidor FD_SET( clock_sock.get_fd(), &fdSet ); struct timeval t; t.tv_sec = 0; t.tv_usec = 0; int ret = lwip_select( FD_SETSIZE, &fdSet, NULL, NULL, &t ); if ((udp_bl_timer.read() > 30) and (bl_start_flag)) { udp_bl_timer.stop(); udp_bl_timer.reset(); bl_start_flag = 0; if (bl_ts != 0) { ts->return_timeslice( bl_ts ); bl_ts = 0; } if (bl_cb != NULL) { bl_cb->set_timeslice( 0 ); set_status( bl_cb->status, cb_idle ); bl_cb = NULL; } } if( ret > 0 ) { for( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = (Call_Box *)v_cb->get_element( i ); int fd = cb->get_sip_socket_fd(); if( FD_ISSET( fd, &fdSet ) ) { int rcv = cb->sip_udp_incomming_pkg(); } } /* Tratamento dos pacotes de bootloader vindo do servidor */ if( FD_ISSET( udp_bl_client.get_fd(), &fdSet ) ) { if( udp_bl_client.receiveFrom( udp_bl_server, bl_recv_buffer, sizeof( bl_recv_buffer ) ) > 0 ) { uint16_t cnt = 0; if (debug_bootloader) { pc.printf("\r\nPACOTE SRV->HDR {"); for (cnt = 0;cnt < UDP_BL_SIZE;cnt++) { if ((cnt % 30) == 0) { pc.printf("\r\n "); pc.printf(hex16(cnt)); pc.printf(" : "); } pc.printf(hex8(bl_recv_buffer[cnt])); pc.printf(", "); } pc.printf("\r\n}"); } bl_peer = ((uint8_t)bl_recv_buffer[0])*256 + (uint8_t)bl_recv_buffer[1]; bl_send_buffer[0] = bl_recv_buffer[0]; bl_send_buffer[1] = bl_recv_buffer[1]; for (cnt = 2;cnt < UDP_BL_SIZE;cnt++) { bl_send_buffer[cnt] = 0; } if ((bl_ts == 0) and !(bl_start_flag)) { bl_ts = ts->get_timeslice(); } /* caso nao haja timeslice disponivel informar servidor */ if ((bl_ts == 0) and !(bl_start_flag)) { strncpy(bl_send_buffer + 2,"cbxdead\x00",8); udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, strlen( bl_send_buffer ) ); } else { /* pacote para verificar se o callbox esta disponivel */ if (!(strncmp(bl_recv_buffer + 2,"avaiable?",9))) { bl_start_flag = 1; udp_bl_timer.start(); udp_bl_timer.reset(); strncpy(bl_send_buffer + 2,"cbxalive\x00",9); if (debug_bootloader) { pc.printf("\r\nPACOTE HDR->SRV {"); for (cnt = 0;cnt < UDP_BL_SIZE;cnt++) { if ((cnt % 30) == 0) { pc.printf("\r\n "); pc.printf(hex16(cnt)); pc.printf(" : "); } pc.printf(hex8(bl_send_buffer[cnt])); pc.printf(", "); } pc.printf("\r\n}"); } udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, strlen( bl_send_buffer ) ); } /* pacote para indicar o termino do processo de atualizacao */ else if (!(strncmp(bl_recv_buffer + 2,"finished",8))) { bl_start_flag = 0; if (bl_ts != 0) { ts->return_timeslice( bl_ts ); bl_ts = 0; } if (bl_cb != NULL) { bl_cb->set_timeslice( 0 ); set_status( bl_cb->status, cb_idle ); bl_cb = NULL; } } /* pacotes a serem repassados para o callbox */ else if (bl_start_flag) { uint16_t bl_cnt = 0; udp_bl_timer.reset(); /* pacote de ERASE enviado para o cbx */ /* neste momento a cabeceira sabe que o servidor se comunicou com o callbox */ if (!(strncmp(bl_recv_buffer + 2,"\x45",1))) { bl_cb = __find_CB__( v_cb, bl_peer ); if (bl_cb != NULL) { bl_cb->set_timeslice( bl_ts ); set_status( bl_cb->status, cb_bootloader ); } } /* pacote de OK enviado para o cbx */ /* neste momento a cabeceira desaloca o timeslice do callbox */ if (!(strncmp(bl_recv_buffer + 2,"\x4f\x00\x00\x00",4))) { ts->return_timeslice( bl_ts ); bl_ts = 0; if (bl_cb != NULL) { bl_cb->set_timeslice( 0 ); } } bl_cbx_buffer[0] = bl_ts; for (bl_cnt = 0; bl_cnt < BL_SIZE; bl_cnt++) { bl_cbx_buffer[bl_cnt + 1] = bl_recv_buffer[bl_cnt + 2]; } if (debug_bootloader) { pc.printf("\r\nPACOTE HDR->CBX {"); for (cnt = 0;cnt < BL_SIZE + 1;cnt++) { if ((cnt % 30) == 0) { pc.printf("\r\n "); pc.printf(hex16(cnt)); pc.printf(" : "); } pc.printf(hex8(bl_cbx_buffer[cnt])); pc.printf(", "); } pc.printf("\r\n}"); } if (bl_cb != NULL) { bl_port = bl_cb->get_port(); } else { bl_port = bl_peer; } send2callboxes( build_cb_package( bl_peer, bl_port, BOOTLOADER_CBX,bl_cbx_buffer, 0, BL_SIZE + 1, write_buffer) ); } } } } // verifica o socket do prompt-UDP-ETH if( FD_ISSET( udp_client.get_fd(), &fdSet ) ) { char to_prompt_process[ PROMPT_UDP_COMMAND_SIZE ]; for( register int i = 0; i < PROMPT_UDP_COMMAND_SIZE; i++ ) to_prompt_process[ i ] = 0; int prompt_process_msg_rcv = udp_client.receiveFrom( udp_server, to_prompt_process, ( sizeof( to_prompt_process ) - 1 ) ); to_prompt_process[ prompt_process_msg_rcv ] = 0; if( prompt_process_msg_rcv == -1 ) { if( debug_reconnect ) send_msg("Reconnect Prompt Process"); reconnect_udp_prompt_process(); miss_prompt_udp_rcv_pkg++; } else if( prompt_process_msg_rcv > 0 ) { udp_query = true; prompt_process( to_prompt_process, prompt_process_msg_rcv ); } } // verifica o socket do watchdog if( FD_ISSET( udp_wdt_client.get_fd(), &fdSet ) ) { char wake_msg[ 768 ]; Endpoint udp_wdt_server; int wake_msg_rcv = udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ); if( wake_msg_rcv == -1 ) { if( debug_reconnect ) send_msg("Reconnect Extern wdt"); reconnect_extern_wdt_socket(); miss_wdt_send_pkg++; } else if( wake_msg_rcv > 0 ) { if( !( strncmp( wake_msg, "alive", 5 ) ) ) { // Just ckeck but not set 'alive?' // 'alive*' - force wdt tick right now // Ckecking and set 'alive' bool question_alive = ( wake_msg[ 5 ] == '?' ); if( wake_msg[ 5 ] == '*' ) wdt.kick(); snprintf( wake_msg, ( 768 - 1 ),"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u:", uptime, invite_counter, external_wdt, ( wdt.WatchdogCausedReset() ) ? '1' : '0', cb_new_counter, v_cb->size(), ts->remain_timeslices(), sip_socket_send_failure, v_call->size(), pkg_cksok, pkg_ckserr, pkg_zero, out_of_range, missed_pkg, delayed_pkg_to_cb, cpld_pkg_tx_counter, cpld_pkg_rx_counter, eth_wdt, pkg_wdt, miss_fw_send_pkg, miss_prompt_udp_send_pkg, miss_sip_registry_send_pkg, miss_sip_invite_send_pkg, miss_sip_bye_send_pkg, miss_sip_unregistry_send_pkg, miss_sip_ok_send_pkg, miss_sip_rcv_bye_send_pkg, miss_wdt_send_pkg, miss_prompt_udp_send_pkg, miss_ftp_udp_send_pkg, miss_prompt_udp_rcv_pkg, miss_closk_send_pkg ); wake_msg[ 768 - 1 ] = 0; int send = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); if( send != strlen( wake_msg ) ) { if( debug_reconnect ) debug_msg("Reconnect Extern wdt (%d, %d)", send, strlen( wake_msg ) ); reconnect_extern_wdt_socket(); miss_wdt_send_pkg++; } if( ( (!question_alive) && ( cb_new_counter <= MAX_CB_IN_A_BRANCH ) && ( cb_new_counter >= 2 ) ) ) { external_wdt = EXTERN_WDT_IDLE; } } else if( !( strncmp( wake_msg, "reset", 5 ) ) ) { external_wdt = 0; sprintf( wake_msg, "rst:%u:", uptime ); int send = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); if( send != strlen( wake_msg ) ) { if( debug_reconnect ) send_msg("Reconnect Extern wdt"); reconnect_extern_wdt_socket(); miss_wdt_send_pkg++; } } } } if( FD_ISSET( clock_sock.get_fd(), &fdSet ) ) { update_clock (); } } } if ( cogumelo ) { cogumelo = false; for( register int i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); if ( cb ) { set_status( cb->status, cb_on_call ); set_status( cb->sip->status, sip_on_call ); } else { debug_msg("%d congumelo missed", i ); } } } if ( gnomo ) { gnomo = false; for( register int i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); if ( cb ) { set_status( cb->status, cb_idle ); set_status( cb->sip->status, sip_idle ); } else { debug_msg("%d gnomo missed", i ); } } } if( dshow_rtp == true ){ dshow_rtp = false; send_msg(":: RTP :: %u", v_cb->size() ); int ext_list[ MAX_CB_IN_A_BRANCH ]; if( v_cb->size() >= 1 ) { for( register int i = 0; i < v_cb->size(); i++ ) { ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); } qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); } for ( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = __find_CB__( v_cb, ext_list[ i ] ); if( cb != NULL ) { send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", cb -> get_ext (), cb -> get_port (), cb -> get_sip_ext (), cb -> get_sip_port (), cb -> get_rtp_port () ); } } } if( malasia ) { malasia = false; // conclusao, mudar o nro nao impala, talvez mudar o nro no pacote ... Call_Box * cb = __find_CB__( v_cb, 5016 ); if( cb != NULL ) { cb -> set_rtp_port ( cb -> get_rtp_port () * 10 + 1 ); send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", cb -> get_ext (), cb -> get_port (), cb -> get_sip_ext (), cb -> get_sip_port (), cb -> get_rtp_port () ); } } if( york ) { york = false; Call_Box * cb = __find_CB__( v_cb, 5016 ); if( cb != NULL ) { cb -> set_rtp_port ( 80 ); send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", cb -> get_ext (), cb -> get_port (), cb -> get_sip_ext (), cb -> get_sip_port (), cb -> get_rtp_port () ); } } if ( frtp ) { frtp = false; Call_Box * cb = __find_CB__( v_cb, frtp_target ); if ( cb != NULL ) { cb -> set_rtp_port ( -1008789032 ); } else { debug_msg("frtp fail"); } } if ( rescue_rtp ) { rescue_rtp = false; Call_Box * cb = __find_CB__( v_cb, rescue_rtp_target ); if ( cb != NULL ) { cb -> set_rtp_port ( rescue_rtp_value ); } else { debug_msg("rescue rtp fail"); } } if( america ) { america = false; Call_Box * cb = __find_CB__( v_cb, 5016 ); if( cb != NULL ) { cb -> set_rtp_port ( 8929415 ); send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", cb -> get_ext (), cb -> get_port (), cb -> get_sip_ext (), cb -> get_sip_port (), cb -> get_rtp_port () ); } } //begin debug_print if ( print_v_cb ) { print_v_cb = false; v_cb->print_yourself (); } if ( print_v_call ) { print_v_call = false; v_call->print_yourself (); } if ( print_cb_var ) { print_cb_var = false; Call_Box * cb = __find_CB__ ( v_cb, print_this_cb ); if ( cb != NULL ) { cb -> print_yourself (); } else { if( print_values ) { debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); } else { send_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); } } } if ( print_cb_all ) { print_cb_all = false; if ( v_cb -> size () == 0 ) { send_msg("known CBx :: 0"); } for ( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = (Call_Box *)v_cb->get_element( i ); if ( cb != NULL ) { cb -> print_yourself (); } else { if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", i ); } } } if ( print_hex_cb_var ) { print_hex_cb_var = false; uint8_t * ptr = ( uint8_t * ) __find_CB__ ( v_cb, print_hex_this_cb ); if ( ptr != NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) { if( debug_uart3 ) pc.printf("%x", *ptr++ ); if ( ( i % 32 ) == 0 ) { if( i != 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } else { if( debug_uart3 ) pc.printf(" "); } } else { if( debug_uart3 ) pc.printf(" "); } } if ( debug_uart3 ) pc.printf("\n\r> "); if ( tcp_session ) { char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; uint8_t * ptr = ( uint8_t * ) __find_CB__ ( v_cb, print_hex_this_cb ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) { char tmp[ 16 ]; sprintf( tmp, "%x ", *ptr++ ); strcat( aux, tmp ); } strcat( aux, "\n\r\0" ); tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); } } else { if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); } } if ( print_hex_cb_all ) { print_hex_cb_all = false; if ( v_cb -> size () == 0 ) { send_msg("known CBx :: 0"); } for ( register uint8_t j = 0; j < v_cb->size(); j++ ) { uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); if ( ptr != NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) { if( debug_uart3 ) pc.printf("%x", *ptr++ ); if ( ( i % 32 ) == 0 ) { if( i != 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } else { if( debug_uart3 ) pc.printf(" "); } } else { if( debug_uart3 ) pc.printf(" "); } } if ( debug_uart3 ) pc.printf("\n\r> "); if ( tcp_session ) { char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) { char tmp[ 16 ]; sprintf( tmp, "%x ", *ptr++ ); strcat( aux, tmp ); } strcat( aux, "\n\r\0" ); tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); } } else { if ( print_values ) { debug_msg ("Objeto CBx ( %d ) nao encontrado", j ); } else { send_msg ("Objeto CBx ( %d ) nao encontrado", j ); } } } } //begin Sip debug print { if ( print_sip_var ) { print_sip_var = false; Call_Box * cb = __find_CB__ ( v_cb, print_this_sip ); if ( cb != NULL ) { if( ( cb -> sip ) != NULL ) { cb -> sip -> print_yourself (); } else { if( print_values ) { debug_msg("Sip param of %d equals NULL", print_this_sip ); } else { send_msg("Sip param of %d equals NULL", print_this_sip ); } } } else { if ( print_values ) { debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); } else { send_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); } } } if ( print_sip_all ) { print_sip_all = false; if ( v_cb -> size () == 0 ) { send_msg("known CBx :: 0"); } for ( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = (Call_Box *)v_cb->get_element( i ); if ( cb != NULL ) { if( ( cb -> sip ) != NULL ) { cb -> sip -> print_yourself (); } else { if( print_values ) { debug_msg("Sip param of %d equals NULL", print_this_sip ); } else { send_msg("Sip param of %d equals NULL", print_this_sip ); } } } else { if( print_values ) { debug_msg("CBx %d not found", print_this_sip ); } else { send_msg("CBx %d not found", print_this_sip ); } } } } if ( print_hex_sip_var ) { uint8_t * ptr = NULL; print_hex_sip_var = false; Call_Box * cb = __find_CB__ ( v_cb, print_hex_this_sip ); if( cb != NULL ) { if( ( cb -> sip ) != NULL ) ptr = ( uint8_t * ) cb -> sip; } if ( ptr != NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( Sip ); i++ ) { if( debug_uart3 ) pc.printf("%x", *ptr++ ); if ( ( i % 32 ) == 0 ) { if( i != 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } else { if( debug_uart3 ) pc.printf(" "); } } else { if( debug_uart3 ) pc.printf(" "); } } if ( debug_uart3 ) pc.printf("\n\r> "); if ( tcp_session ) { char aux[ ( 32 * 3 ) + 5 ]; for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; ptr = NULL; print_hex_sip_var = false; Call_Box * cb = __find_CB__ ( v_cb, print_hex_this_sip ); if( cb != NULL ) { if( ( cb -> sip ) != NULL ) ptr = ( uint8_t * ) cb -> sip; } if ( ptr != NULL ) { bool finished = false; volatile int i = 0; int count = 0; Timer dont_overwrite_tcp_buffer; dont_overwrite_tcp_buffer.reset (); dont_overwrite_tcp_buffer.start (); while ( !finished ) { if( dont_overwrite_tcp_buffer.read_ms () >= 500 ) { dont_overwrite_tcp_buffer.reset(); for ( ; i < sizeof( Sip ); i++ ) { char tmp[ 16 ]; sprintf( tmp, "%x ", *ptr++ ); strcat( aux, tmp ); count++; if ( count >= 32 ) { count = 0; i++; break; } } strcat ( aux, "\n\r\0" ); tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); if ( i >= sizeof ( Sip ) ) finished = true; strcpy ( aux, "\0" ); } } dont_overwrite_tcp_buffer.reset(); dont_overwrite_tcp_buffer.stop(); tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); } } } else { if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); } } /* if ( print_hex_cb_all ) { print_hex_cb_all = false; if ( v_cb -> size () == 0 ) { send_msg("known CBx :: 0"); } for ( register uint8_t j = 0; j < v_cb->size(); j++ ) { uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); if ( ptr != NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) { if( debug_uart3 ) pc.printf("%x", *ptr++ ); if ( ( i % 32 ) == 0 ) { if( i != 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } else { if( debug_uart3 ) pc.printf(" "); } } else { if( debug_uart3 ) pc.printf(" "); } } if ( debug_uart3 ) pc.printf("\n\r> "); if ( tcp_session ) { char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); for ( register int i = 0; i < sizeof( Call_Box ); i++ ) { char tmp[ 16 ]; sprintf( tmp, "%x ", *ptr++ ); strcat( aux, tmp ); } strcat( aux, "\n\r\0" ); tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); } } else { if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", j ); } } } */ }//end Sip debug print if( dcallshow_rtp == true ){ dcallshow_rtp = false; send_msg(":: CAll RTP :: %u", v_call->size() ); for( register uint8_t i = 0; i < v_call->size(); i++ ) { VZ_call * call = ( VZ_call * )v_call->get_element( i ); if( call != NULL ) { send_msg("CBX ( %d, %d ) - Server ( %d, %d )", call->get_cb_ext(), call->get_cb_port(), call->get_rtp_server_ext(), call->get_rtp_server_port() ); } } } if ( print_call_var ) { print_call_var = false; VZ_call * call = __find_Call__( v_call, print_this_call ); if ( call != NULL ) { send_msg ("Values :: %p\r\n", ( void *) call ); call -> print_yourself (); } else { if( print_values ) { debug_msg("Call %d not found", print_this_call ); } else { send_msg("Call %d not found", print_this_call ); } } } if ( print_hex_call_var ) { print_hex_call_var = false; VZ_call * call = __find_Call__( v_call, print_hex_this_call ); uint8_t * ptr = NULL; if( call != NULL ) { ptr = ( uint8_t * ) call; } if ( ptr != NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( VZ_call ); i++ ) { if( debug_uart3 ) pc.printf("%x", *ptr++ ); if ( ( i % 32 ) == 0 ) { if( i != 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } else { if( debug_uart3 ) pc.printf(" "); } } else { if( debug_uart3 ) pc.printf(" "); } } if ( debug_uart3 ) pc.printf("\n\r> "); if ( tcp_session ) { char aux[ ( 32 * 3 ) + 5 ]; for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; ptr = NULL; VZ_call * call = __find_Call__( v_call, print_hex_this_call ); uint8_t * ptr = NULL; if( call != NULL ) { ptr = ( uint8_t * ) call; } if ( ptr != NULL ) { bool finished = false; volatile int i = 0; int count = 0; Timer dont_overwrite_tcp_buffer; dont_overwrite_tcp_buffer.reset (); dont_overwrite_tcp_buffer.start (); while ( !finished ) { if( dont_overwrite_tcp_buffer.read_ms () >= 20 ) { dont_overwrite_tcp_buffer.reset(); for ( ; i < sizeof( VZ_call ); i++ ) { char tmp[ 16 ]; sprintf( tmp, "%x ", *ptr++ ); strcat( aux, tmp ); count++; if ( count >= 32 ) { count = 0; i++; break; } } strcat ( aux, "\n\r\0" ); tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); if ( i >= sizeof ( VZ_call ) ) finished = true; strcpy ( aux, "\0" ); } } dont_overwrite_tcp_buffer.reset(); dont_overwrite_tcp_buffer.stop(); tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); } } } else { if( print_values ) { debug_msg("Call %d not found", print_this_call ); } else { send_msg("Call %d not found", print_this_call ); } } } if ( print_hex_rtp_var ) { print_hex_rtp_var = false; VZ_call * call = __find_Call__( v_call, print_hex_this_rtp ); uint8_t * ptr = NULL; if( call != NULL ) { ptr = ( uint8_t * ) call -> check_rtp (); } if ( ptr != NULL ) { send_msg ("Values :: %p\r\n", ( void *) ptr ); for ( register int i = 0; i < sizeof( RTP ); i++ ) { if( debug_uart3 ) pc.printf("%x", *ptr++ ); if ( ( i % 32 ) == 0 ) { if( i != 0 ) { if( debug_uart3 ) pc.printf("\n\r> "); } else { if( debug_uart3 ) pc.printf(" "); } } else { if( debug_uart3 ) pc.printf(" "); } } if ( debug_uart3 ) pc.printf("\n\r> "); if ( tcp_session ) { char aux[ ( 32 * 3 ) + 5 ]; for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; ptr = NULL; VZ_call * call = __find_Call__( v_call, print_hex_this_rtp ); uint8_t * ptr = NULL; if( call != NULL ) { ptr = ( uint8_t * ) call -> check_rtp (); } if ( ptr != NULL ) { bool finished = false; volatile int i = 0; int count = 0; Timer dont_overwrite_tcp_buffer; dont_overwrite_tcp_buffer.reset (); dont_overwrite_tcp_buffer.start (); while ( !finished ) { if( dont_overwrite_tcp_buffer.read_ms () >= 20 ) { dont_overwrite_tcp_buffer.reset(); for ( ; i < sizeof( RTP ); i++ ) { char tmp[ 16 ]; sprintf( tmp, "%x ", *ptr++ ); strcat( aux, tmp ); count++; if ( count >= 32 ) { count = 0; i++; break; } } strcat ( aux, "\n\r\0" ); tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); if ( i >= sizeof ( RTP ) ) finished = true; strcpy ( aux, "\0" ); } } dont_overwrite_tcp_buffer.reset(); dont_overwrite_tcp_buffer.stop(); tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); } } } else { if( print_values ) { debug_msg("Call %d not found", print_this_rtp ); } else { send_msg("Call %d not found", print_this_rtp ); } } } if ( print_rtp_var ) { print_rtp_var = false; VZ_call * call = __find_Call__( v_call, print_this_rtp ); if ( call != NULL ) { if ( call -> check_rtp () != NULL ) { send_msg ("Values :: %p\r\n", ( void *) call -> check_rtp () ); call -> rtp_print_yourself (); } else { if( print_values ) { debug_msg("Call->RTP %d not found", print_this_rtp ); } else { send_msg("Call->RTP %d not found", print_this_rtp ); } } } else { if( print_values ) { debug_msg("Call->RTP %d not found", print_this_rtp ); } else { send_msg("Call->RTP %d not found", print_this_rtp ); } } } //end debug_print if( reset_cks == true ) { pkg_cksok = 0; pkg_ckserr = 0; pkg_zero = 0; reset_cks = false; out_of_range = 0; missed_pkg = 0; delayed_pkg_to_cb = 0; cpld_pkg_tx_counter = 0; cpld_pkg_rx_counter = 0; pcks_s = true; } // exibe os contadores de cks de pacotes recebidos na interface CBx->Header, e outros contadores relacionados if( pcks_s == true ) { send_msg( "\r\n" " PKG_CKS OK: %d ( %003.2f )\r\n" " PKG_CKS ERR: %d ( %003.2f )\r\n" " PKG_0: %d ( %003.2f )\r\n" " Out_of_range: %d ( %003.2f )\r\n" " Miss_Pkg: %d\r\n" " TX_delayed: %d\n\r" " TX_Counter: %d\n\r" " RX_Counter: %d\r\n", pkg_cksok, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_cksok / cpld_pkg_rx_counter ) * 100, pkg_ckserr, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_ckserr / cpld_pkg_rx_counter ) * 100, pkg_zero, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_zero / cpld_pkg_rx_counter ) * 100, out_of_range, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) out_of_range / cpld_pkg_rx_counter ) * 100, missed_pkg, delayed_pkg_to_cb, cpld_pkg_tx_counter, cpld_pkg_rx_counter ); pcks_s = false; } // zera os contadores de pacotes que resultaram em falha de envio vio ETH if( reset_missed_send_udp_pkg ){ miss_fw_send_pkg = 0; miss_prompt_udp_send_pkg = 0; miss_sip_registry_send_pkg = 0; miss_sip_invite_send_pkg = 0; miss_sip_bye_send_pkg = 0; miss_sip_unregistry_send_pkg = 0; miss_sip_ok_send_pkg = 0; miss_sip_rcv_bye_send_pkg = 0; miss_wdt_send_pkg = 0; miss_prompt_udp_send_pkg = 0; miss_ftp_udp_send_pkg = 0; miss_prompt_udp_rcv_pkg = 0; reset_missed_send_udp_pkg = false; missed_send_udp_pkg = true; } // exibe estatisticas de pacotes que resultaram em falha de envio na interface ETH if( missed_send_udp_pkg ) { send_msg( "\r\nMissed pkgs ::\r\n " "FW: %d\r\n " "Prompt UDP %d\r\n " "Registry %d\r\n " "Invite %d\r\n " "Bye %d\r\n " "Unregistry %d\r\n " "UDP incoming ( invite ans ) %d\r\n " "UDP incoming ( bye from * ) %d\r\n " "Wdt [ alive | rst ] %d\r\n " "Rcv prompt %d\r\n " "[ debug | send ]_msg %d\r\n " "RTP %d\r\n", miss_fw_send_pkg, miss_prompt_udp_send_pkg, miss_sip_registry_send_pkg, miss_sip_invite_send_pkg, miss_sip_bye_send_pkg, miss_sip_unregistry_send_pkg, miss_sip_ok_send_pkg, miss_sip_rcv_bye_send_pkg, miss_wdt_send_pkg, miss_prompt_udp_send_pkg, miss_prompt_udp_rcv_pkg, miss_ftp_udp_send_pkg ); missed_send_udp_pkg = false; } if( flood_bug_pkg ){ static int id = 0x10; if( id < 10 ) id = 0x0b; send2callboxes( build_cb_package( 5828, 5123, REGISTRY, ( char * )buffer, id++, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); } if( led_sync_timer.read() > 1 ) { led_sync_timer.reset(); led3 = !led3; CAB_LED = !CAB_LED; } switch( type ) { case DO_NOTHING : {} break; case CB_BYE : { cb_bye_counter++; Call_Box * cb = __find_CB__( v_cb, ext ); if( cb != NULL ) { if( debug_invite || debug_main ) debug_msg("[%d] Bye pkg - msg_id %d e pkg_id %d", ext, cb->get_msg_id(), data[ 0 ] ); bool already_removed = true; if( cb->get_status() != cb_idle ) { already_removed = false; data[ TIMESLICE_PLACE ] = 0; send2callboxes( build_cb_package( ext, port, CB_BYE, ( char * )data, data[ 0 ] |= BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); ts->return_timeslice( cb->call_end () ); } if( already_removed ) if( debug_main || debug_invite ) debug_msg( "[%d] Already removed from inviting queue", ext ); already_removed = true; 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 ) { already_removed = false; data[ TIMESLICE_PLACE ] = 0; v_call->remove_element( i ); send2callboxes( build_cb_package( ext, port, CB_BYE, ( char * )data, data[ 0 ] |= BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); delete( call ); ts->return_timeslice( cb->call_end () ); } } if( already_removed ) if( debug_main || debug_invite ) debug_msg( "[%d] Already removed from vector call", ext ); cb -> registry(); } else if( debug_invite || debug_main ) debug_msg("[%d] Bye from who ?", ext ); } break; case INVITE : { if( drop_invite_pkg ){ debug_msg("[%d] Dropando invite pck - msg id :: %d", ext, data[ 0 ] ); break; } invite_counter++; if( debug_invite ) debug_msg("[%d] Invite request", ext); Call_Box * cb = __find_CB__( v_cb, ext ); if( cb == NULL ) { if( v_cb->size() < MAX_CB_IN_A_BRANCH ) { if( debug_main ) debug_msg( "[%d] Adding CBx", ext ); cb = new Call_Box( ext, port ); if( cb == NULL ) { memory_is_over = true; if( debug_memory ) debug_msg("[%d] Invite allocation cb fail", ext ); } else { v_cb->add( cb ); } } } if( cb != NULL ) { cb->invite_retry_count_reset(); cb->set_msg_id( data[ 0 ] ); if( cb->status == cb_idle ){ cb -> call_config (); } else { data[ TIMESLICE_PLACE ] = cb->get_timeslice(); cb->set_invite_response_pending(); send2callboxes( build_cb_package( ext, port, INVITE, ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); } invite_handler( v_call, v_cb, ts, cb ); } } break; case REGISTRY : { registry_counter++; Call_Box * cb = __find_CB__( v_cb, ext ); if( cb == NULL ) { if( v_cb->size() < MAX_CB_IN_A_BRANCH ) { if( debug_main ) debug_msg("[%d] Adding Cbx", ext ); cb = new Call_Box( ext, port ); if( cb == NULL ) { memory_is_over = true; if( debug_memory ) debug_msg("[%d] Registry cb allocation fail", ext ); } else { v_cb->add( cb ); if( debug_main ) debug_msg("[%d] Added CBx", ext ); } } } if( debug_main ) debug_msg("[%d %d] Registered", ext, port ); if( cb != NULL ) cb->registry(); } break; case BOOT : { boot_counter++; if( debug_boot == true ){ send_msg("[%d %d] Boot pkg -- pkg-id %d", ext, port, data[ 0 ] ); } send2callboxes( build_cb_package( ext, port, REGISTRY, ( char * )data, data[ 0 ] | BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); } break; case FW : { if( debug_fw_print ) send_msg("[%d %d]::FW pkg::", ext, port ); fw_cbx_pkg( ext, port, ( char *)buffer ); } break; case BOOTLOADER_CBX : { uint16_t bl_cnt2 = 0; //char bl_send_buffer[ BL_SIZE + 2 ]; //int ret = bl_cbx_reply_to_eth( ext, ( char * )data ); //BLEUBA //pc.printf("\r\nCBX RESPONDEU BOOTLOADER!\r\n"); if (debug_bootloader) { pc.printf("\r\npacote CBX->HDR {"); for (bl_cnt2 = 0;bl_cnt2 < BL_SIZE + 1;bl_cnt2++) { if ((bl_cnt2 % 30) == 0) { pc.printf("\r\n "); pc.printf(hex16(bl_cnt2)); pc.printf(" : "); } pc.printf(hex8(data[bl_cnt2])); pc.printf(", "); } pc.printf("\r\n}"); } bootloader_cbx_counter++; bl_send_buffer[0] = (char)(ext >> 8); bl_send_buffer[1] = (char)(ext & 0xff); for (bl_cnt2 = 0; bl_cnt2 < BL_SIZE; bl_cnt2++) { bl_send_buffer[bl_cnt2 + 2] = data[bl_cnt2 + 1]; } if (debug_bootloader) { pc.printf("\r\npacote HDR->SRV {"); for (bl_cnt2 = 0;bl_cnt2 < UDP_BL_SIZE;bl_cnt2++) { if ((bl_cnt2 % 30) == 0) { pc.printf("\r\n "); pc.printf(hex16(bl_cnt2)); pc.printf(" : "); } pc.printf(hex8(bl_send_buffer[bl_cnt2])); pc.printf(", "); } pc.printf("\r\n}"); } udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, UDP_BL_SIZE ); } break; case PROMPT : { Call_Box * cb = __find_CB__( v_cb, ext ); if( cb == NULL ) { if( v_cb->size() < MAX_CB_IN_A_BRANCH ) { if( debug_main ) debug_msg("[%d] Adding Cbx", ext ); cb = new Call_Box( ext, port ); if( cb == NULL ){ memory_is_over = true; }else{ v_cb->add( cb ); if( debug_main ) debug_msg("[%d] Added CBx", ext ); } } } if( cb!= NULL ) cb->registry(); if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ) { if( debug_ping ) send_msg( "[%d %d] Prompt pkg :: Ping", ext, port ); } else { prompt_counter++; //fixme isso nao poderia ser resolvido com um sendmsg ? send_msg( "[%i, %i] Prompt pkg::", ext, port ); for( register uint8_t i = 0; i < 32; i++ ) { if( debug_uart3 ) pc.printf("%c", data[ i ] ); if( i == 15 ) if( debug_uart3 ) pc.printf( "\r\n" ); } if( debug_uart3 ) pc.printf("\n\r> "); if( tcp_session ) { char aux[ CB_BUFFER_SIZE + 3 ]; strncpy( aux, (char * )data, CB_BUFFER_SIZE ); strcat( aux, "\n\r\0" ); tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); } } } break; case AUDIO : { audio_counter++; if ( received_audio_from_cb ) { debug_msg("[%d] audio pkg", ext ); } VZ_call * call = __find_Call__( v_call, ext ); if( call != NULL ) { if ( drop_rtp_from_cbx_pkg ){ led2 = !led2; break; } else { char * pkg = call->build_eth_package( data + 2 ); call->send_message( pkg ); call->cbx_pkg_idle_timer_reset(); } } Call_Box * cb = __find_CB__( v_cb, ext ); if( cb != NULL ){ if ( cb->get_invite_response() == false ) { cb->set_invite_response_ok(); cb->invite_retry_count_reset(); } else { if( debug_main ) debug_msg("[%d] received missed package", ext ); } } } break; }// fim switch { // rajada if( invite_retry_timer.read_ms() >= 20 ) { invite_retry_timer.reset(); static int retry_invite_pkg = 0; bool need_retry = false; Call_Box * cb = NULL; for ( register int i = 0; i < v_cb->size(); i++ ) { retry_invite_pkg++; if ( retry_invite_pkg >= v_cb->size() ) retry_invite_pkg = 0; cb = (Call_Box * )v_cb->get_element( i ); if ( cb != NULL ) { if ( ( cb->status == cb_ringing ) || ( cb->status == cb_trying ) || ( cb->status == cb_on_call ) ) { need_retry = true; break; } } } if ( need_retry ) { if( cb->get_invite_response() == false ) { cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); buffer[ TIMESLICE_PLACE ] = cb->get_timeslice(); send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), INVITE, ( char * )buffer, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); if( debug_invite ) debug_msg("[%d] resend invite OK to Cbx : ( %d, %d )", cb->get_ext(), cb->get_ext(), cb->get_port() ); } if ( __find_Call__( v_call, cb->get_ext () ) == NULL ) { if ( ( ( cb->status == cb_ringing ) || ( cb->status == cb_trying ) ) ) { char rtp_src_tmp_write_buffer [ CB_BUFFER_SIZE ]; uint8_t rtp_dst_tmp_write_buffer [ CB_BUFFER_SIZE ]; for ( register int i = 0; i < RTP_MSG_SIZE; i++ ) rtp_src_tmp_write_buffer [ i ] = 'U'; // 0x55 send2callboxes( build_cb_package( cb->get_ext (), cb->get_port (), AUDIO, rtp_src_tmp_write_buffer, AUDIO, RTP_MSG_SIZE, rtp_dst_tmp_write_buffer ) ); } else { if ( cb->get_invite_retry_count() == 0 ) { cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); 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() == cb->get_ext() ) { v_call->remove_element( i ); if( call != NULL ) delete( call ); break; } } ts->return_timeslice( cb->call_end () ); if( debug_invite ) debug_msg( "[%d]-- No audio pkgs --", cb->get_ext () ); } } } } } } // fim rajada for( register uint8_t i = 0; i < v_call->size(); i++ ) { VZ_call * call = ( VZ_call * )v_call->get_element( i ); if ( call != NULL ) { int length = 0; char * tmp = call->get_eth_message( &length ); if( tmp != NULL ) { int cb_port = 0xffff; Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); if( cb != NULL ) { cb_port = cb->get_port(); if ( drop_rtp_from_ast_pkg ) { led1 = !led1; } else { uint8_t * pkg2cb = build_cb_package( call->get_cb_ext(), cb_port, AUDIO, tmp, AUDIO, length, write_buffer ); send2callboxes( pkg2cb ); } } else if( debug_main ) debug_msg("[%d] received missed package -- Type :: %i", ext, type ); } } } if( timer_sync_refresh.read_ms() > 250 ) { timer_sync_refresh.reset(); static uint8_t time_to_mode = TIME_TO_REFRESH; if ( time_to_mode == TIME_TO_REFRESH ){ time_to_mode = TIME_TO_WAKE_UP; refresh ( v_cb ); } else { time_to_mode = TIME_TO_REFRESH; if ( wake_all ) if ( v_call->size() == 0 ) wake_all_up ( v_cb ); } } // check sip messages only for cbx in call ? int ext_to__be_removed = sip_manager( v_cb ); if( ext_to__be_removed > 0 ) { Call_Box * cb = __find_CB__( v_cb, ext_to__be_removed ); if( cb != NULL ) { //if( cb->status == cb_on_call ) // poderia ser if( cb->status != cb_idle ) ??? if( cb->status == cb_on_call ) { buffer[ TIMESLICE_PLACE ] = 0; 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_to__be_removed ) { v_call->remove_element( i ); delete( call ); } } ts->return_timeslice( cb->call_end ( false ) ); send2callboxes( build_cb_package( cb->get_ext (), cb->get_port (), CB_BYE, ( char * )buffer, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); if( debug_invite ) debug_msg("[%d] Received Bye from *", cb->get_ext () ); } } else if( debug_main ) debug_msg("[%d] Missed bye request", ext_to__be_removed ); } /* Verifica andamento de ligações para eventualmente encerra-las por timeout */ call_manager( v_call, v_cb, ts ); /* tratamento de pedidos de ligação */ invite_handler( v_call, v_cb, ts, NULL ); /* rotina de verificação de TS's perdidos */ if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != __MAX_TIMESLICES__ ) ) { bool ts_reset = true; for( register uint8_t i = 0; i < v_cb->size(); i++ ) { uint16_t cb_status = ((Call_Box *)v_cb->get_element( i ))->get_status(); uint16_t cb_sip_status = ((Call_Box *)v_cb->get_element( i ))->get_sip_status(); if ((cb_status != cb_idle) and (cb_sip_status != sip_idle)) { ts_reset = false; break; } } if( ts_reset && !bl_start_flag ) { if( debug_invite ) debug_msg("Resetando TS"); ts->reset(); } } /* rotina "zeradora" de portas RTP */ for ( register uint8_t i = 0; i < v_cb->size(); i++ ) { Call_Box * cb = (Call_Box *) v_cb->get_element (i); if ( cb != NULL ) { if ( ( cb->get_status () == cb_idle ) && ( cb->get_sip_status () == sip_idle ) && ( cb -> is_rtp_timer_timeout () ) ) { if ( debug_reset_rtp ) debug_msg( "[%d] rtp reset", cb -> get_ext () ); set_status ( cb -> status, cb_idle ); set_status ( cb->sip->status, sip_idle ); cb -> reset_rtp_timer (); cb -> set_rtp_port ( 0 ); } } } /* rotina que esvazia possiveis pacotes que não foram transmitidos para evitar conflito */ tx_buffer_ring_buffer_handler(); type = DO_NOTHING; if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; if( wdt_timer.read() >= 1 ) { //FIXME remove myself //registry_test = true; //invite_retry_time = true; uptime++; current_time++; wdt_timer.reset(); if( wdt_show ) debug_wdt = true; if( external_wdt ) external_wdt--; if( pkg_wdt ) pkg_wdt--; if( eth_wdt ) eth_wdt--; if( eth_wdt && external_wdt && pkg_wdt ){ wdt.kick(); } } if( debug_wdt ) { send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); lpc_low_level_input_counter = 0; debug_wdt = false; if( eth_status == 0 ) { send_msg( "Wdt last reset: %s - status_eth :: Connected - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )", ( wdt.WatchdogCausedReset() ) ? "true" : "false", EXTERN_WDT_IDLE - external_wdt, EXTERN_WDT_IDLE, RX_CB_IDLE - pkg_wdt, RX_CB_IDLE ); } else { send_msg( "Wdt last reset: %s - status_eth :: Disconnected :: since %3d sec - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )", ( wdt.WatchdogCausedReset() ) ? "true" : "false", ETH_CONNECT_TIMEOUT - eth_wdt, EXTERN_WDT_IDLE - external_wdt, EXTERN_WDT_IDLE, RX_CB_IDLE - pkg_wdt, RX_CB_IDLE ); } } } }