![](/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:
- 104:62646ef786a3
- Parent:
- 102:98c7155e8bea
- Child:
- 105:a930035b6556
--- a/main.cpp Thu Feb 19 18:04:33 2015 +0000 +++ b/main.cpp Wed Feb 25 18:44:11 2015 +0000 @@ -1,4 +1,3 @@ -#include "telemetry.h" #include "eth.h" #include "bits.h" #include "UART3Interrupt.h" // for RXBuffer[ __CB_BUFFER_SIZE__ ]; @@ -128,12 +127,8 @@ reset_leds(); udp_timer.start(); - - init_telemetry_handler(); - //debug_msg(""); init_fw_handler(); - //debug_msg(""); led2 = 0; init_ranges(); @@ -163,11 +158,12 @@ led1 = 0; send_msg("Ready"); - //bool registry_test = false; - //static int next_value = 5002; + //bool registry_test = true; + //bool registry_test2 = false; + + //static int next_value = 5000; //static int nex_test_registry = next_value; - //bool invite_retry_time = false; Timer invite_retry_timer; invite_retry_timer.start(); debug_uart3 = false; @@ -190,7 +186,6 @@ pshowcb = true; } - if( !( ++count % 15 ) ) { if( eth_status ) { eth_status = __init_eth__(); @@ -213,6 +208,19 @@ //FIXMEj colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ... prompt_process( NULL ); + + if( reconnect_stats ) + { + reconnect_stats = false; + char str[ 256 ]; + snprintf( str, 256, + "Reconnetc Status from :: \nFW :: %d\nPrompt UDP :: %d\n", + + miss_fw_send_pkg, + miss_prompt_udp_send_pkg + ); + send_msg( str ); + } if( r_stats ) { boot_counter = 0; @@ -479,9 +487,13 @@ fw_cbx_pkg( ext, port, ( char *)buffer ); } - if( type == __TELEMETRY__ ) telemetry_counter++; + if( type == __TELEMETRY__ ) + { + telemetry_counter++; + //FIXME colocar o dtelos aqui + } - if( type != __AUDIO__ ) { + if( type != __AUDIO__ ) { if( type == __TELEMETRY__ || type == __CB_STATS__ || @@ -542,8 +554,8 @@ } else type = __DO_NOTHING__; } - if( main_test == true ) { - main_test = false; + 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 ); @@ -562,29 +574,40 @@ send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) ); send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) ); } - - //static int wdt_count = 0; + /* - if( registry_test == true ) { - registry_test = false; - - if( wdt_count++ > 5 || v_cb->size() < 66 ) { - wdt_count = 0; - - if( type == __DO_NOTHING__ ) { - if( next_value < ( 5002 + __MAX_CB_IN_A_BRANCH__ - 2 ) ) { - //type = __REGISTRY__; - data = buffer; - ext = next_value; - port = next_value++; - } else { - if( nex_test_registry > ( 5002 + __MAX_CB_IN_A_BRANCH__ - 1 - 2 ) ) nex_test_registry = 5002; - //type = __REGISTRY__; - data = buffer; - ext = nex_test_registry; - port = nex_test_registry++; - } - } + static int ext_random_index = 0; + static int ext_random[ 10 ] = { 5878, 5919, 5030, 5797, 5980, 5499, 5151, 5340, 5782, 5494 }; + + if( registry_test ) + { + if( type == __DO_NOTHING__ ) + { + pkg_wdt = RX_CB_IDLE; + type = __REGISTRY__; + data = buffer; + ext = ext_random[ ext_random_index ]; + port = ext_random[ ext_random_index ]; + } + if( ext_random_index++ >= 9 ) + { + registry_test = false; + } + + } + */ + /* + if( registry_test2 ) + { + registry_test2 = false; + + if( type == __DO_NOTHING__ ) + { + pkg_wdt = RX_CB_IDLE; + type = __REGISTRY__; + data = buffer; + ext = 6662; + port = 6662; } } */ @@ -617,7 +640,16 @@ char wake_msg[ 768 ]; Endpoint udp_wdt_server; - if( udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ) > 0 ){ + 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 @@ -625,14 +657,6 @@ bool question_alive = ( wake_msg[ 5 ] == '?' ); if( wake_msg[ 5 ] == '*' ) wdt.kick(); - /* - uint8_t registered_cbx = v_cb->size(); - for( register int i = 0; i < v_cb->size(); i++ ){ - Call_Box * cb = (Call_Box * )v_cb->get_element( i ); - if( cb->is_timeout() ){ if( registered_cbx ) registered_cbx--; } - } - */ - snprintf( wake_msg, 48,"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u:", uptime, invite_counter, @@ -643,10 +667,15 @@ ts->remain_timeslices(), sip_socket_send_failure, v_call->size() - // registered_cbx ); wake_msg[ 768 - 1 ] = 0; - udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); + 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( ( (!question_alive) && ( cb_new_counter <= __MAX_CB_IN_A_BRANCH__ ) && ( cb_new_counter >= 2 ) ) ) { external_wdt = EXTERN_WDT_IDLE; @@ -655,7 +684,13 @@ external_wdt = 0; sprintf( wake_msg, "rst:%u:", uptime ); - udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); + 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++; + } } } } @@ -688,7 +723,7 @@ ( char * )buffer, id++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); } - if( led_sync_timer.read() > 1 ) { + if( led_sync_timer.read() >= 1 ) { led_sync_timer.reset(); led3 = !led3; CAB_LED = !CAB_LED; @@ -833,12 +868,6 @@ } break; - case __TELEMETRY__ : { - if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); - build_telemetry_report( ext, port, ( char *)data ); - } - break; - case __FW__ : { if( debug_fw_print ) send_msg("::FW pkg from %d - %d::", ext, port ); fw_cbx_pkg( ext, port, ( char *)buffer ); @@ -992,20 +1021,23 @@ } else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); } } - - //if( v_call->size() == 0 ) refresh( v_cb, buffer, write_buffer, NULL ); if( timer_sync_refresh.read_ms() > 250 ) { timer_sync_refresh.reset(); static uint8_t mode = TIME_TO_REFRESH; - + if( mode == TIME_TO_REFRESH ) { mode = TIME_TO_WAKE_UP; refresh( v_cb, buffer, write_buffer, NULL ); } else { mode = TIME_TO_REFRESH; if( wake_all ) if( v_call->size() == 0 ) wake_all_up( v_cb, buffer, write_buffer ); + + if( main_test == true ) + { + //registry_test2 = true; + } } } @@ -1086,9 +1118,6 @@ if( wdt_timer.read() >= 1 ) { //FIXME remove myself - //registry_test = true; - //invite_retry_time = true; - uptime++; wdt_timer.reset();