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:
- 126:1f90756250fb
- Parent:
- 124:c1b6c893e1c3
- Child:
- 132:05cd37f7e007
diff -r 8ff4dc96ad58 -r 1f90756250fb call_box_manager.cpp --- a/call_box_manager.cpp Wed May 13 21:18:12 2015 +0000 +++ b/call_box_manager.cpp Wed May 20 19:50:31 2015 +0000 @@ -4,47 +4,55 @@ Timer timer_aging; Timer timer_sync_refresh; -Call_Box * find_CB( Vector * v_cb, int ext ){ +Call_Box * find_CB ( Vector * v_cb, const int ext ) +{ Call_Box * cb = NULL; - for ( register int i = 0; i < v_cb->size (); i++ ) + for ( register int i = 0; i < v_cb -> size (); i++ ) { - cb = ( Call_Box * )v_cb->get_element( i ); - if ( cb != NULL ) + cb = ( Call_Box * ) v_cb -> get_element ( i ); + if ( cb not_eq NULL ) { - if( cb->get_ext() == ext ) return( cb ); + if ( cb -> get_ext () == ext ) return ( cb ); } } - return( NULL ); + return ( NULL ); } int refresh ( Vector * v_cb ) { - if( v_cb != NULL) + if ( v_cb not_eq NULL) { static int lst_index = 0; - if( v_cb->size() > 0 ) + if ( v_cb -> size () > 0 ) { //FIXME pode acontecder problemas por ser static - static uint8_t data[ CB_BUFFER_SIZE ], write_buffer[ CB_BUFFER_SIZE ]; + static uint8_t data [ CB_BUFFER_SIZE ], write_buffer [ CB_BUFFER_SIZE ]; led4 = 0; - if( lst_index >= v_cb->size() ) lst_index = 0; + + if ( lst_index >= v_cb -> size () ) lst_index = 0; - Call_Box * cb = (Call_Box * )v_cb->get_element( lst_index++ ); + Call_Box * cb = ( Call_Box * ) v_cb -> get_element ( lst_index++ ); - if ( ( cb != NULL ) && ( cb -> get_status () == cb_idle ) ) + if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) ) { - - if( cb->get_ext() % 2 == 1 ){ - Call_Box * cb_master = find_CB( v_cb, cb->get_ext() - 1 ); - if ( ( cb_master != NULL ) && ( cb_master -> get_status () != cb_idle ) ) return( 0x20 ); + if ( cb -> get_ext () % 2 == 1 ) + { + Call_Box * cb_master = find_CB ( v_cb, cb -> get_ext () - 1 ); + + if ( ( cb_master not_eq NULL ) and ( cb_master -> get_status () not_eq cb_idle ) ) return ( 0x20 ); } - - cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); + else + { + // checking slave status + Call_Box * cb_slave = find_CB ( v_cb, cb -> get_ext () + 1 ); + + if ( ( cb_slave not_eq NULL ) and ( cb_slave -> get_status () not_eq cb_idle ) ) return ( 0x21 ); + } send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), REGISTRY, - ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); if( debug_refresh ) send_msg("[%d] Refresh", cb->get_ext() ); @@ -54,7 +62,7 @@ }else return( -1 ); } -void wake_all_up( Vector * v_cb ) +void wake_all_up ( Vector * v_cb ) { /*** [ Principio ] @@ -73,13 +81,14 @@ ***/ uint8_t data[ CB_BUFFER_SIZE ], write_buffer[ CB_BUFFER_SIZE ]; - if( ( v_cb != NULL ) ){ + if( ( v_cb not_eq NULL ) ) + { static int ext_list[ MAX_CB_IN_A_BRANCH + 1 ]; static uint8_t last_size = 0; uint8_t size = v_cb->size(); static int wake_all_up_index = 0; - if( last_size != size ) + 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(); @@ -94,18 +103,16 @@ if( ( ext_list[ wake_all_up_index ] % 2 ) == 0 ) { //testa se o slave nao esta registrado - if( ( size == 1 ) || ( ( wake_all_up_index + 1 ) == size ) || ( ext_list[ wake_all_up_index + 1 ] != ( ext_list[ wake_all_up_index ] + 1 ) ) ) + 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 != NULL ) && ( cb -> get_status () == cb_idle ) ) - { - cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); - + 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->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); if( debug_wake ) send_msg("%d without %d - ping sent to %d", ext_list[ wake_all_up_index ], ext_list[ wake_all_up_index ] + 1, cb->get_ext() + 1 ); @@ -113,25 +120,23 @@ } }else{ - if( ( size == 1 ) || ( wake_all_up_index == 0 ) || ( wake_all_up_index >= 1 ) && ( ext_list[ wake_all_up_index - 1 ] != ( ext_list[ wake_all_up_index ] - 1 ) ) ) + 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 != NULL ) && ( cb -> get_status () == cb_idle ) ) + if ( ( cb not_eq NULL ) and ( cb -> get_status () == cb_idle ) ) { - cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); - send2callboxes( build_cb_package( ( cb->get_ext() - 1 ), ( cb->get_port() - 1 ), PROMPT, - ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); + ( char * )data, cb -> msg_id_update (), CB_BUFFER_SIZE - VZ_HEADER_OFFSET, write_buffer ) ); - if( debug_wake ) send_msg("%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 ( debug_wake ) send_msg ("%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; + if ( ++wake_all_up_index >= size ) wake_all_up_index = 0; } } \ No newline at end of file