![](/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
Diff: main.cpp
- Revision:
- 132:05cd37f7e007
- Parent:
- 130:850163037da5
- Child:
- 135:2f4290590e51
--- a/main.cpp Tue Jul 21 20:03:35 2015 +0000 +++ b/main.cpp Tue Sep 01 17:21:11 2015 +0000 @@ -7,17 +7,25 @@ int header_app_init_ret = header_app_init (); - send_msg( "header_app_init %s" , ( header_app_init_ret == 0 ) ? "Ok" : "Failure" ); + vz_printf ( "header_app_init %s" , ( header_app_init_ret == 0 ) ? "Ok" : "Failure" ); - if ( header_app_init_ret == 0 ) send_msg("Ready"); + if ( header_app_init_ret == 0 ) vz_printf ("Ready"); debug_uart3 = false; + power_source_timer.start (); + /*------------------------------------------ main loop ---------------------------------------------------------------*/ while( true ) { - prompt_process( NULL, 0 ); + prompt_process ( NULL, 0 ); + + if ( cm -> was_modified () ) + { + update_config_values (); + cm -> set_modified_false (); + } if ( show_last_rx ) { @@ -56,7 +64,7 @@ //35 sec. if( ( count > 7 ) and ( wake_all == false ) ) { wake_all = true; - if( debug_wake == true ) send_msg( "Time to wake" ); + if( debug_wake == true ) vz_printf ( "Time to wake" ); } // enable na variavel que exibe lista com estatisticas de pacotes que falharam ao serem enviados via interface eth @@ -66,7 +74,7 @@ if ( show_wake_all_up_status ) { - send_msg("wake_all_up status :: %s", ( wake_all ) ? "Enable" : "Disable" ); + vz_printf ("wake_all_up status :: %s", ( wake_all ) ? "Enable" : "Disable" ); show_wake_all_up_status = false; } @@ -93,9 +101,10 @@ if ( long_list ) { - show_cb_long_list ( v_cb, show_time ); + show_cb_long_list ( v_cb, show_time, show_invites ); long_list = false; show_time = false; + show_invites = false; } if ( pshowcb ) @@ -125,11 +134,10 @@ if( pflood == true ) flood(); if( debug_eth ) { - send_msg("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); + vz_printf ("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); debug_eth = false; } - - + // chechando se existe um pacote vindo do cbx pendente if( status != WAITING ) @@ -166,16 +174,28 @@ } // usado pra testes - if ( registra ) { - int internal_ext = 8000; - registra = false; - for( register uint8_t i = 0; i < MAX_CB_IN_A_BRANCH - 2; i++ ) { - v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); - } + if ( registra ) + { + int internal_ext = 8000; + registra = false; + for( register uint8_t i = 0; i < MAX_CB_IN_A_BRANCH - 2; i++ ) { + v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); + } + } + + if ( registra4 ) + { + int internal_ext = 8000; + registra4 = false; + for( register uint8_t i = 0; i < 4; i++ ) + { + v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); + } + } } - check_udp_packages_pending ( v_cb ); + check_udp_packages_pending ( v_cb ); if( dshow_rtp == true ) { @@ -201,7 +221,7 @@ } else { - debug_msg("rescue rtp fail"); + vz_debug ("rescue rtp fail"); } } @@ -243,19 +263,19 @@ if ( print_sip_var ) { - show_cB_sip (); + show_cb_sip (); print_sip_var = false; } if ( print_sip_all ) { - show_cB_sip_all (); + show_cb_sip_all (); print_sip_all = false; } if ( print_hex_sip_var ) { - show_cB_hex_sip (); + show_cb_hex_sip (); print_hex_sip_var = false; } @@ -302,6 +322,18 @@ pcks_s = false; } + if ( show_wdt_string ) + { + char wdt_msg [ 1024 ]; + build_wdt_string ( wdt_msg, sizeof ( wdt_msg ) - 1 ); + + int siRet = strlen ( wdt_msg ); + + vz_printf ( "wdt_msg.length::%d\r\n%s", siRet, wdt_msg ); + + show_wdt_string = false; + } + if( reset_missed_send_udp_pkg ) { reset_missed_send_udp (); @@ -309,7 +341,6 @@ reset_missed_send_udp_pkg = false; } - if ( missed_send_udp_pkg ) { show_missed_send_udp_pkg (); @@ -337,25 +368,27 @@ case CB_BYE : { - cb_bye_counter++; - Call_Box * cb = find_CB( v_cb, ext ); - if( cb != NULL ) { - if( debug_invite or debug_main ) debug_msg("[%d] Bye pkg - msg_id %d e pkg_id %d", ext, cb->get_msg_id(), data[ 0 ] ); + cb_bye_counter ++; + Call_Box * cb = find_CB ( v_cb, ext ); + if ( cb != NULL ) + { + if ( debug_invite or debug_main ) vz_debug ("[%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 ) { + if ( cb -> get_status () != cb_idle ) + { already_removed = false; - data[ TIMESLICE_PLACE ] = 0; + data [ TIMESLICE_PLACE ] = 0; - send2callboxes( build_cb_package( ext, port, CB_BYE, - ( char * )data, data[ 0 ] or_eq BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + send2callboxes ( build_cb_package ( ext, port, CB_BYE, + ( char * )data, data [ 0 ] or_eq BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - ts->return_timeslice( cb->call_end () ); + ts -> return_timeslice ( cb -> call_end () ); } - if( already_removed ) if( debug_main or debug_invite ) debug_msg( "[%d] Already removed from inviting queue", ext ); + if ( already_removed ) if ( debug_main or debug_invite ) vz_debug ( "[%d] Already removed from inviting queue", ext ); already_removed = true; @@ -379,11 +412,11 @@ } } - if( already_removed ) if( debug_main or debug_invite ) debug_msg( "[%d] Already removed from vector call", ext ); + if( already_removed ) if( debug_main or debug_invite ) vz_debug ( "[%d] Already removed from vector call", ext ); cb -> registry(); - } else if ( debug_invite or debug_main ) debug_msg("[%d] Bye from who ?", ext ); + } else if ( debug_invite or debug_main ) vz_debug ("[%d] Bye from who ?", ext ); } break; @@ -391,13 +424,13 @@ { if ( drop_invite_pkg ) { - debug_msg("[%d] Dropando invite pck - msg id :: %d", ext, data[ 0 ] ); + vz_debug ("[%d] Dropando invite pck - msg id :: %d", ext, data[ 0 ] ); break; } invite_counter++; - if ( debug_invite ) debug_msg ("[%d] Invite request", ext ); + if ( debug_invite ) vz_debug ("[%d] Invite request", ext ); Call_Box * cb = find_CB ( v_cb, ext ); @@ -405,13 +438,13 @@ { if ( v_cb -> size () < MAX_CB_IN_A_BRANCH ) { - if ( debug_main or debug_invite ) debug_msg ( "[%d] Adding CBx", ext ); + if ( debug_main or debug_invite ) vz_debug ( "[%d] Adding CBx", ext ); cb = new Call_Box ( ext, port ); if ( cb == NULL ) { memory_is_over = true; - if ( debug_memory or debug_invite ) debug_msg ("[%d] Invite allocation cb fail", ext ); + if ( debug_memory or debug_invite ) vz_debug ("[%d] Invite allocation cb fail", ext ); } else { v_cb->add ( cb ); } @@ -420,19 +453,21 @@ if ( cb != NULL ) { + cb -> update_invite_counter (); + cb -> invite_retry_count_reset (); cb -> set_msg_id ( data [ 0 ] ); if ( cb -> get_status () == cb_idle ) { cb -> call_config (); - if ( test_ts ) debug_msg ("TST::IDLE"); + if ( test_ts ) vz_debug ("TST::IDLE"); } else { data [ TIMESLICE_PLACE ] = cb -> get_timeslice (); cb -> set_invite_response_pending (); - if ( test_ts ) debug_msg ("TST::%u ", data [ TIMESLICE_PLACE ]); + if ( test_ts ) vz_debug ("TST::%u ", data [ TIMESLICE_PLACE ]); send2callboxes ( build_cb_package ( ext, port, INVITE, ( char * )data, cb->msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); @@ -452,20 +487,20 @@ { if( v_cb->size() < MAX_CB_IN_A_BRANCH ) { - if( debug_main ) debug_msg("[%d] Adding Cbx", ext ); + if( debug_main ) vz_debug ("[%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 ); + if( debug_memory ) vz_debug ("[%d] Registry cb allocation fail", ext ); } else { v_cb->add( cb ); - if( debug_main ) debug_msg("[%d] Added CBx", ext ); + if( debug_main ) vz_debug ("[%d] Added CBx", ext ); } } } - if ( debug_main ) debug_msg("[%d %d] Registered", ext, port ); + if ( debug_main ) vz_debug ("[%d %d] Registered", ext, port ); int registry_ret = -1; @@ -483,7 +518,7 @@ case BOOT : { boot_counter++; if( debug_boot == true ){ - send_msg("[%d %d] Boot pkg -- pkg-id %d", ext, port, data[ 0 ] ); + vz_printf ("[%d %d] Boot pkg -- pkg-id %d", ext, port, data[ 0 ] ); } send2callboxes( build_cb_package( ext, port, REGISTRY, ( char * )data, data[ 0 ] bitor BIT7, CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); @@ -491,17 +526,13 @@ break; case FW : { - if ( debug_fw_print ) send_msg ("[%d %d]::FW pkg::", ext, port ); + if ( debug_fw_print ) vz_printf ("[%d %d]::FW pkg::", ext, port ); fw_cbx_pkg ( ext, ( 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++) { @@ -534,7 +565,13 @@ } pc.printf("\r\n}"); } - udp_bl_client.sendTo( udp_bl_server, bl_send_buffer, UDP_BL_SIZE ); + int udp_bl_client_ret = udp_bl_client.sendTo ( udp_bl_server, bl_send_buffer, UDP_BL_SIZE ); + if ( udp_bl_client_ret not_eq UDP_BL_SIZE ) + { + reconnect_bl (); + miss_bl_udp_send_pkg ++; + if ( debug_reconnect ) vz_printf ( "[%d] Reconnect BL - %d", ext, udp_bl_client_ret ); + } } break; @@ -543,13 +580,13 @@ if( cb == NULL ) { if( v_cb->size() < MAX_CB_IN_A_BRANCH ) { - if( debug_main ) debug_msg("[%d] Adding Cbx", ext ); + if( debug_main ) vz_debug ("[%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( debug_main ) vz_debug ("[%d] Added CBx", ext ); } } } @@ -559,12 +596,12 @@ // if( ( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ) or xstrmatch ( ( uint8_t * )data, ( uint8_t * )"pong" ) ) if ( ( strncasecmp ( ( const char * )data, "ping", 4 ) == 0 ) or ( strncasecmp ( ( const char * )data, "pong", 4 ) == 0 ) ) { - if( debug_ping ) send_msg( "[%d %d] Prompt pkg :: Ping", ext, port ); + if( debug_ping ) vz_printf ( "[%d %d] Prompt pkg :: Ping", ext, port ); } else { prompt_counter++; - send_msg( "[%i, %i] Prompt pkg::", ext, port ); + vz_printf ( "[%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" ); @@ -585,7 +622,7 @@ case AUDIO : { audio_counter++; if ( received_audio_from_cb ) { - debug_msg("[%d] audio pkg", ext ); + vz_debug ("[%d] audio pkg", ext ); } VZ_call * call = find_Call ( v_call, ext ); @@ -598,20 +635,20 @@ } else { char * pkg = call -> build_eth_package ( data + 2 ); call -> send_message ( pkg ); - call -> cbx_pkg_idle_timer_reset(); + call -> cbx_pkg_idle_timer_reset (); } } - Call_Box * cb = find_CB( v_cb, ext ); + Call_Box * cb = find_CB ( v_cb, ext ); if ( cb != NULL ) { - if ( cb -> get_invite_response() == false ) + 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 ); + if ( debug_main ) vz_debug ("[%d] received missed package", ext ); } } break; @@ -647,15 +684,14 @@ if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; if( wdt_timer.read() >= 1 ) { - if ( -1 == wdt_update () ) debug_msg("Erro!!!!!"); + if ( -1 == wdt_update () ) vz_debug ("Erro!!!!!"); wdt_timer.reset(); } if( debug_wdt ) { show_wdt_status (); - debug_wdt = false; - + debug_wdt = false; } update_all_cb_timer ( v_cb ); @@ -663,9 +699,13 @@ if ( !dont_say_hello_again ) send_hello_to_cbx (); /* Verificacao da fonte de alimentacao */ - if ( pwr_src_timer.read () > 1 ) + if ( power_source_timer.read () > 1 ) { - check_power_source(); + check_power_source (); } + +%: ifdef MODE_TEST + wdt.kick(); +%: endif }// fim while }// fim main \o/ \ No newline at end of file