![](/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: call_box_manager.cpp
- Revision:
- 135:2f4290590e51
- Parent:
- 134:395678c651d8
diff -r 395678c651d8 -r 2f4290590e51 call_box_manager.cpp --- a/call_box_manager.cpp Tue Sep 01 19:34:34 2015 +0000 +++ b/call_box_manager.cpp Thu Sep 10 20:11:35 2015 +0000 @@ -6,11 +6,12 @@ Call_Box * find_CB ( Vector * v_cb, const int ext ) { - //fixme - // if ( v_cb == NULL ) return NULL; - Call_Box * cb = NULL; + if ( v_cb == NULL ) return NULL; + for ( register int i = 0; i < v_cb -> size (); i++ ) { + Call_Box * cb = NULL; + cb = ( Call_Box * ) v_cb -> get_element ( i ); if ( cb not_eq NULL ) { @@ -20,15 +21,14 @@ return ( NULL ); } -int refresh ( Vector * v_cb ) +int +refresh ( Vector * v_cb ) { if ( v_cb not_eq NULL ) - { - static int list_index = 0; - + { if ( v_cb -> size () > 0 ) { - static uint8_t data [ CB_BUFFER_SIZE ], write_buffer [ CB_BUFFER_SIZE ]; + static int list_index = 0; led4 = 0; @@ -40,48 +40,23 @@ { int local_ext = cb -> get_ext (); - if ( local_ext % 2 == 1 ) - { - // if ( ! list_exception_ext -> find_value ( local_ext ) ) - { - // checking master status - Call_Box * cb_master = find_CB ( v_cb, local_ext - 1 ); - - if ( cb_master not_eq NULL ) - { - if ( cb_master -> get_status () not_eq cb_idle ) return ( 0x20 ); - - else if ( cb_master -> get_timer () >= cm -> get_acceptable_delay () ) return ( 0x40 ); - } - } - } - else + Call_Box * pair = cb -> get_pair_cbx (); + + if ( pair not_eq NULL ) { - // if ( ! list_exception_ext -> find_value ( local_ext ) ) - { - // checking slave status - Call_Box * cb_slave = find_CB ( v_cb, local_ext + 1 ); - - if ( cb_slave not_eq NULL ) - { - if ( cb_slave -> get_status () not_eq cb_idle ) return ( 0x21 ); - - else if ( cb_slave -> get_timer () >= cm -> get_acceptable_delay () ) return ( 0x41 ); - } - } + if ( pair -> get_status () not_eq cb_idle ) return ( local_ext % 2 == 1 ) ? ( 0x21 ) : ( 0x20 ); + + else if ( ( not ( cm -> get_cbx_detach_mode () ) ) and ( pair -> get_timer () >= cm -> get_acceptable_delay () ) ) return ( local_ext % 2 == 1 ) ? ( 0x41 ) : ( 0x40 ); } - /* - condição adicionada para minimizar o comportamento do cbx perder o tx, - pacotes vindo shiftados pra cabeceira, e não perdendo o rx, portando - o cbx não resetava sozinho, idéia, deixar ele rebotar pelo wdt dele. - */ if ( ( cb -> get_timer () < cm -> get_acceptable_delay () ) and ( cb -> get_overflow_times () == 0 ) ) { + static uint8_t data [ CB_BUFFER_SIZE ], write_buffer [ CB_BUFFER_SIZE ]; + send2callboxes( build_cb_package( local_ext, cb->get_port(), REGISTRY, ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - if( debug_refresh ) vz_printf ("[%d] Refresh", local_ext ); + if ( debug_refresh ) vz_printf ("[%d] Refresh", local_ext ); } else { if ( debug_dont_refresh ) vz_debug ("Nao pedindo registro para o [%d]( %d, %d )", local_ext, cb -> get_timer (), cb -> get_overflow_times () ); @@ -110,63 +85,47 @@ - Caso nao esteja, encaminha mensagem de ping para o CBx ausente da dupla. ***/ - uint8_t data[ CB_BUFFER_SIZE ], write_buffer[ CB_BUFFER_SIZE ]; - if( ( v_cb not_eq NULL ) ) + if ( ( v_cb not_eq NULL ) ) { - static int ext_list[ MAX_CB_IN_A_BRANCH + 1 ]; + static int ext_list [ u8_MAX_CB_IN_A_BRANCH + 1 ]; static uint8_t last_size = 0; - uint8_t size = v_cb->size(); + uint8_t size = v_cb -> size (); static int wake_all_up_index = 0; - if( last_size not_eq size ) - { - for( register int i = 0; i < size; i++ ){ - ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); - } + if ( last_size not_eq size ) { + for ( register int i = 0; i < size; i++ ) + ext_list [ i ] = ( ( Call_Box * ) v_cb -> get_element ( i ) ) -> get_ext (); - qsort( ext_list, v_cb->size(), sizeof( int ), wake_comp ); + qsort ( ext_list, v_cb -> size (), sizeof ( int ), wake_comp ); } - if( size > 0 ) + if ( size > 0 ) { - // testa se eh o master - if( ( ext_list[ wake_all_up_index ] % 2 ) == 0 ) + Call_Box * cb = find_CB ( v_cb, ext_list [ wake_all_up_index ] ); + + if ( cb not_eq NULL ) { - //testa se o slave nao esta registrado - if( ( size == 1 ) or ( ( wake_all_up_index + 1 ) == size ) or ( ( ext_list[ wake_all_up_index + 1 ] not_eq ( ext_list[ wake_all_up_index ] + 1 ) ) ) ) - { - strcpy( ( char * )data, "ping\r" ); - Call_Box * cb = find_CB( v_cb, ext_list[ wake_all_up_index ] ); - - // verifica se o master esta em chamada. - if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) ) - { - send2callboxes( build_cb_package( ( cb->get_ext() + 1 ), ( cb->get_port() + 1 ), PROMPT, - ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + Call_Box * pair = cb -> get_pair_cbx (); + + if ( ( cb -> get_status () == cb_idle ) and ( pair == NULL ) ) + { + uint8_t data [ CB_BUFFER_SIZE ], write_buffer [ CB_BUFFER_SIZE ]; + + strcpy ( ( char * )data, "ping\r" ); + + int cb_ext = cb -> get_ext (); + + int ext_to_ping = ( ( cb_ext % 2 ) == 0 ) ? cb_ext + 1 : cb_ext - 1; + + send2callboxes ( build_cb_package ( ext_to_ping, ext_to_ping, PROMPT, ( char * )data, + cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + + if ( debug_wake ) vz_printf ("%d without %d - ping sent to %d", + cb_ext, ext_to_ping, ext_to_ping ); + } + } + } - if( debug_wake ) vz_printf ("%d without %d - ping sent to %d", - ext_list[ wake_all_up_index ], ext_list[ wake_all_up_index ] + 1, cb->get_ext() + 1 ); - } - } - - }else{ - if( ( size == 1 ) or ( wake_all_up_index == 0 ) or ( wake_all_up_index >= 1 ) and ( ( ext_list[ wake_all_up_index - 1 ] not_eq ( ext_list[ wake_all_up_index ] - 1 ) ) ) ) - { - strcpy( ( char * )data, "ping\r" ); - Call_Box * cb = find_CB( v_cb, ( ext_list[ wake_all_up_index ] ) ); - - // verifica se o slave esta em chamada. - if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) ) - { - send2callboxes( build_cb_package( ( cb->get_ext() - 1 ), ( cb->get_port() - 1 ), PROMPT, - ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - - if ( debug_wake ) vz_printf ("%d without %d - ping sent to %d", - ext_list [ wake_all_up_index ], ext_list [ wake_all_up_index ] - 1, cb -> get_ext () - 1 ); - } - } - } - } if ( ++wake_all_up_index >= size ) wake_all_up_index = 0; } } \ No newline at end of file