![](/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:
- 87:679ee0d594a9
- Parent:
- 86:bf7b0d4c3232
- Child:
- 89:0fe315117b00
diff -r bf7b0d4c3232 -r 679ee0d594a9 main.cpp --- a/main.cpp Mon Jan 05 12:43:12 2015 +0000 +++ b/main.cpp Tue Jan 06 16:37:03 2015 +0000 @@ -13,8 +13,9 @@ #include "shared_variables.h" #include "prompt.h" #include "configs.h" +#include "sdram.h" -volatile u16_t bleuba = 0; +volatile u16_t lpc_low_level_input_counter = 0; int main(){ init_wdt(); @@ -23,11 +24,21 @@ start_cpld(); + if( sdram_init() == 1 ) + { + send_msg("******* Failed to initialize SDRAM *******"); + return 1; + } + else + { + send_msg("******* Success to initialize SDRAM *******"); + } + init_fsystem(); short int eth_status = __init_eth__(); if( eth_status ){ - send_msg("Cannot connect to eth\n\r"); + send_msg("******* Cannot connect to eth *******"); }else{ send_msg("******* Connection eth - ok *******"); init_prompt_eth(); @@ -61,7 +72,7 @@ /* gerencia o tipo do pacote para providenciar tratamento adequado */ volatile uint8_t type = __DO_NOTHING__; - /* representa a lista dos Call Boxes atualmente reconhecidos pela cabeceira */ + /* representa a lista dos Call Boxes atualmente recfonhecidos pela cabeceira */ Vector * v_cb = new Vector(); /* representa a lista de ligacoes ativas na cabeceira */ @@ -69,6 +80,7 @@ /* gerencia a distribuicao de timeslice para os call boxes */ Timeslice * ts = new Timeslice(); + if( ts == NULL ) memory_is_over = true; /* instancia o vetor de call boxes // calls */ if( v_cb == NULL ){ @@ -89,6 +101,9 @@ } } + if( v_cb == NULL ) memory_is_over = true; + if( v_call == NULL ) memory_is_over = true; + for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ cb_rx_buffer[ i ] = 0; cb_tx_buffer[ i ] = 0; @@ -136,9 +151,9 @@ send_msg( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] ); } -#define NUM_SOCK 50 -#define TEST_SERVER_IP "192.168.120.7" -#define ETH_MSG_SIZE 1600 +//#define NUM_SOCK 50 +//#define TEST_SERVER_IP "192.168.120.7" +//#define ETH_MSG_SIZE 1600 //UDPSocket sock[ NUM_SOCK ]; //Endpoint server[ NUM_SOCK ]; @@ -386,20 +401,7 @@ ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); }else if( ( data[ 0 ] & BIT7 ) == BIT7 ){ if( debug_main ) debug_msg("Received ack pkg with seq_num %d", data[ 0 ] ); - //algum motivo pra sempre receber alguma coisa com o type == 7 ??? - if( type == 0x07 ){ - 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; - } + switch( type ){ case __INVITE__ : { if( debug_main || debug_invite ) debug_msg("Invite Ack from %d on msg_id %d", ext, cb->get_msg_id() ); @@ -428,36 +430,49 @@ }else type = __DO_NOTHING__; } - if( main_test == true ){ + if( main_test == true ) + { + main_test = 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_New (%u) -- RTP_Delete (%u)", rtp_new_counter, rtp_delete_counter ); - main_test = false; + 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("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("Received ETH Pkg ( bleuba ) %d", bleuba ); + 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( regystry_test == true ) { regystry_test = false; if( type == __DO_NOTHING__ ) { - if( next_value < ( 5010 + 38 ) ) + //if( next_value < ( 5010 + __MAX_CB_IN_A_BRANCH__ - 2 ) ) { type = __REGISTRY__; data = buffer; ext = next_value; port = next_value++; } + /* else { - if( nex_test_registry > ( 5010 + 38 - 1 ) ) nex_test_registry = 5010; + if( nex_test_registry > ( 5010 + __MAX_CB_IN_A_BRANCH__ - 1 - 2 ) ) nex_test_registry = 5010; type = __REGISTRY__; data = buffer; ext = nex_test_registry; port = nex_test_registry++; } + */ } } @@ -558,11 +573,17 @@ if( cb == NULL ){ if( debug_main ) debug_msg( "Adding CBx :: %i", ext ); cb = new Call_Box( ext, port ); - v_cb->add( cb ); + + if( cb == NULL ){ + memory_is_over = true; + }else{ + v_cb->add( cb ); + } } - //cb->registry(); - cb->set_msg_id( data[ 0 ] ); - invite_handler( v_call, v_cb, ts, cb ); + if( cb != NULL ){ + cb->set_msg_id( data[ 0 ] ); + invite_handler( v_call, v_cb, ts, cb ); + } }break; case __REGISTRY__ : { registry_counter++; @@ -572,12 +593,16 @@ if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); cb = new Call_Box( ext, port ); - v_cb->add( cb ); - if( debug_main ) debug_msg("Added CBx -- %d", ext ); + if( cb == NULL ){ + memory_is_over = true; + }else{ + v_cb->add( cb ); + if( debug_main ) debug_msg("Added CBx -- %d", ext ); + } } if( debug_main ) debug_msg("Registered %d - %d", ext, port ); - cb->registry(); + if( cb != NULL ) cb->registry(); }break; case __BOOT__ : { @@ -587,14 +612,28 @@ }break; case __TELEMETRY__ : { Call_Box * cb = __find_CB__( v_cb, ext ); + if( cb == NULL ){ + send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, + ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + + /* if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); cb = new Call_Box( ext, port ); - v_cb->add( cb ); - if( debug_main ) debug_msg("Added CBx -- %d", ext ); + + if( cb == NULL ){ + memory_is_over = true; + }else{ + v_cb->add( cb ); + if( debug_main ) debug_msg("Added CBx -- %d", ext ); + } + */ } - cb->registry(); - //FIXME mandar um pacote do tipo 2 pro cbx ? + /* + if( cb != NULL ){ + cb->registry(); + }*/ + telemetry_counter++; if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); build_telemetry_report( ext, port, ( char *)data ); @@ -607,14 +646,23 @@ case __PROMPT__ : { Call_Box * cb = __find_CB__( v_cb, ext ); + if( cb == NULL ){ + send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, + ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); + /* if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); cb = new Call_Box( ext, port ); - v_cb->add( cb ); - if( debug_main ) debug_msg("Added CBx -- %d", ext ); + if( cb == NULL ){ + memory_is_over = true; + }else{ + v_cb->add( cb ); + if( debug_main ) debug_msg("Added CBx -- %d", ext ); + } + */ } - cb->registry(); + //if( cb!= NULL ) cb->registry(); if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ){ if( debug_ping ) send_msg( "Prompt pkg from ( %i, %i ) :: Ping", ext, port ); @@ -766,7 +814,7 @@ if( wdt_show ) send_msg( "Sent %d bytes in response", sent ); - if( (!question_alive) && ( cb_new_counter <= 46 ) && ( cb_new_counter >= 2 ) ) { + 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 ) ) ){ @@ -795,8 +843,8 @@ } if( debug_wdt ){ - send_msg("Received ETH Pkg ( bleuba ) %d", bleuba ); - bleuba = 0; + 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 ){