![](/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:
- 135:2f4290590e51
- Parent:
- 132:05cd37f7e007
- Child:
- 136:2da626f30efa
diff -r 395678c651d8 -r 2f4290590e51 main.cpp --- a/main.cpp Tue Sep 01 19:34:34 2015 +0000 +++ b/main.cpp Thu Sep 10 20:11:35 2015 +0000 @@ -62,7 +62,7 @@ } //35 sec. - if( ( count > 7 ) and ( wake_all == false ) ) { + if( ( count > 7 ) and ( wake_all == false ) and ( not wake_all_disable ) and ( cm -> get_cbx_wake_mode () ) ) { wake_all = true; if( debug_wake == true ) vz_printf ( "Time to wake" ); } @@ -74,7 +74,7 @@ if ( show_wake_all_up_status ) { - vz_printf ("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; } @@ -166,6 +166,20 @@ test_ts_timer.reset (); } + else if ( simulate ) + { + simulate = false; + + data = buffer; + + data [ SEQ_NUM_PLACE ] = seq_num_to_simulate; + + ext = ext_to_simulate; + + port = port_to_simulate; + + type = num_type_to_simulate; + } if( sizes == true ) { @@ -179,7 +193,7 @@ { int internal_ext = 8000; registra = false; - for( register uint8_t i = 0; i < MAX_CB_IN_A_BRANCH - 2; i++ ) { + for( register uint8_t i = 0; i < u8_MAX_CB_IN_A_BRANCH - 2; i++ ) { v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); } } @@ -193,6 +207,15 @@ v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); } } + + if ( need_registry_someone ) + { + need_registry_someone = false; + + v_cb -> add ( new Call_Box ( ext_to_be_registered, ext_to_be_registered ) ); + + ext_to_be_registered = 0; + } } check_udp_packages_pending ( v_cb ); @@ -361,7 +384,26 @@ CAB_LED = !CAB_LED; } - switch( type ) + if ( boolWho_is_your_pair ) + { + boolWho_is_your_pair = false; + + Call_Box * cb = find_CB ( v_cb, u16Who_is_your_pair ); + + if ( cb not_eq NULL ) + { + cb = cb -> get_pair_cbx (); + + if ( cb not_eq NULL ) vz_printf ( "[%d] pair [%d]", u16Who_is_your_pair, cb -> get_ext () ); + + else vz_printf ( "[%d] pair nao encontrado", u16Who_is_your_pair ); + + } else vz_printf ( "[%d] nao encontrado", u16Who_is_your_pair ); + + u16Who_is_your_pair = 0; + } + + switch ( type ) { case DO_NOTHING :{} break; @@ -408,13 +450,13 @@ delete( call ); - ts->return_timeslice( cb->call_end () ); + ts -> return_timeslice ( cb -> call_end () ); } } if( already_removed ) if( debug_main or debug_invite ) vz_debug ( "[%d] Already removed from vector call", ext ); - cb -> registry(); + cb -> registry (); } else if ( debug_invite or debug_main ) vz_debug ("[%d] Bye from who ?", ext ); } @@ -428,31 +470,17 @@ break; } - invite_counter++; + invite_counter ++; if ( debug_invite ) vz_debug ("[%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 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 ) vz_debug ("[%d] Invite allocation cb fail", ext ); - } else { - v_cb->add ( cb ); - } - } - } - - if ( cb != NULL ) - { + if ( cb == NULL ) cb = try_add_new_cbx ( v_cb, ext ); + + if ( cb == NULL ) { + if ( debug_memory or debug_invite ) vz_debug ("[%d] Invite allocation cb fail", ext ); + } else { cb -> update_invite_counter (); cb -> invite_retry_count_reset (); @@ -480,37 +508,25 @@ break; case REGISTRY : { - registry_counter++; + /* + Colocar um if, de que se o cbx já existia, e tinha dado timeout + ou por slave ou por mestre, resetar o timer dos 2 + */ + 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 ) vz_debug ("[%d] Adding Cbx", ext ); - cb = new Call_Box( ext, port ); - - if( cb == NULL ) { - memory_is_over = true; - if( debug_memory ) vz_debug ("[%d] Registry cb allocation fail", ext ); - } else { - v_cb->add( cb ); - if( debug_main ) vz_debug ("[%d] Added CBx", ext ); - } - } - } + if ( cb == NULL ) cb = try_add_new_cbx ( v_cb, ext ); - if ( debug_main ) vz_debug ("[%d %d] Registered", ext, port ); - + if ( cb == NULL and debug_memory ) vz_debug ( "[%d] Registry cb allocation fail", ext ); + int registry_ret = -1; - if ( cb != NULL ) registry_ret = cb -> registry (); + if ( cb not_eq NULL ) registry_ret = cb -> registry (); if ( ( registry_ret > 0 ) and eth_status ) try_reconnect_with_eth (); - /* Resetando o timer usado no wdt somente no recebimento de - pacotes validos do tipo REGISTRY. - */ + if ( debug_main and registry_ret ) vz_debug ( "[%d %d] Registered", ext, port ); + pkg_wdt = RX_CB_IDLE; } break; @@ -578,22 +594,10 @@ 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 ) 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 ) vz_debug ("[%d] Added CBx", ext ); - } - } - } + if ( cb == NULL ) cb = try_add_new_cbx ( v_cb, ext ); - if( cb!= NULL ) cb -> registry (); + if( cb != NULL ) cb -> registry (); -// 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 ) vz_printf ( "[%d %d] Prompt pkg :: Ping", ext, port ); @@ -601,7 +605,9 @@ else { prompt_counter++; + 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" );