![](/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
call_box_manager.cpp@104:62646ef786a3, 2015-02-25 (annotated)
- Committer:
- klauss
- Date:
- Wed Feb 25 18:44:11 2015 +0000
- Revision:
- 104:62646ef786a3
- Parent:
- 92:92df17f538a8
- Child:
- 105:a930035b6556
- Remo??o do implementado para bootloader cbx.; - Remo??o do implementado para telemetria.; - Remo??o do implementado ( comentado ) em file_system_manager.cpp; - BUGFIX perda de conex?o serial quando recebido um comando via eth;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 74:81c47fff88a5 | 1 | #include "call_box_manager.h" |
klauss | 74:81c47fff88a5 | 2 | |
klauss | 80:61d61c9eb75c | 3 | Timer timer_refresh; |
klauss | 78:1353744f01e1 | 4 | Timer timer_aging; |
klauss | 89:0fe315117b00 | 5 | Timer timer_sync_refresh; |
klauss | 78:1353744f01e1 | 6 | |
klauss | 74:81c47fff88a5 | 7 | Call_Box * __find_CB__( Vector * v_cb, int ext ){ |
klauss | 74:81c47fff88a5 | 8 | Call_Box * cb = NULL; |
klauss | 74:81c47fff88a5 | 9 | for( register int i = 0; i < v_cb->size(); i++ ){ |
klauss | 74:81c47fff88a5 | 10 | cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 74:81c47fff88a5 | 11 | if( cb->get_ext() == ext ) return( cb ); |
klauss | 74:81c47fff88a5 | 12 | } |
klauss | 74:81c47fff88a5 | 13 | return( NULL ); |
klauss | 74:81c47fff88a5 | 14 | } |
klauss | 74:81c47fff88a5 | 15 | |
klauss | 80:61d61c9eb75c | 16 | int refresh( Vector * v_cb, uint8_t * data, uint8_t * write_buffer, Call_Box * cb ){ |
klauss | 80:61d61c9eb75c | 17 | if( v_cb != NULL && data != NULL && write_buffer != NULL ){ |
klauss | 81:3656f00ab3db | 18 | static int lst_index = 0; |
klauss | 81:3656f00ab3db | 19 | |
klauss | 80:61d61c9eb75c | 20 | if( cb != NULL ){ |
klauss | 80:61d61c9eb75c | 21 | timer_refresh.reset(); |
klauss | 80:61d61c9eb75c | 22 | |
klauss | 92:92df17f538a8 | 23 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 81:3656f00ab3db | 24 | |
klauss | 80:61d61c9eb75c | 25 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __REGISTRY__, |
klauss | 80:61d61c9eb75c | 26 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 80:61d61c9eb75c | 27 | |
klauss | 81:3656f00ab3db | 28 | if( debug_refresh ) send_msg("Refresh specific %d", cb->get_ext() ); |
klauss | 81:3656f00ab3db | 29 | |
klauss | 80:61d61c9eb75c | 30 | return( 0x10 ); |
klauss | 89:0fe315117b00 | 31 | }else{ |
klauss | 80:61d61c9eb75c | 32 | if( v_cb->size() > 0 ){ |
klauss | 81:3656f00ab3db | 33 | if( lst_index >= v_cb->size() ) lst_index = 0; |
klauss | 80:61d61c9eb75c | 34 | |
klauss | 80:61d61c9eb75c | 35 | Call_Box * cb = (Call_Box * )v_cb->get_element( lst_index++ ); |
klauss | 80:61d61c9eb75c | 36 | |
klauss | 89:0fe315117b00 | 37 | if( cb != NULL && cb->status == cb_idle ){ |
klauss | 89:0fe315117b00 | 38 | |
klauss | 81:3656f00ab3db | 39 | if( cb->get_ext() % 2 == 1 ){ |
klauss | 81:3656f00ab3db | 40 | Call_Box * cb_master = __find_CB__( v_cb, cb->get_ext() - 1 ); |
klauss | 86:bf7b0d4c3232 | 41 | if( cb_master != NULL && cb_master->status != cb_idle ) return( 0x20 ); |
klauss | 81:3656f00ab3db | 42 | } |
klauss | 89:0fe315117b00 | 43 | |
klauss | 92:92df17f538a8 | 44 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 81:3656f00ab3db | 45 | |
klauss | 80:61d61c9eb75c | 46 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __REGISTRY__, |
klauss | 80:61d61c9eb75c | 47 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 80:61d61c9eb75c | 48 | |
klauss | 81:3656f00ab3db | 49 | if( debug_refresh ) send_msg("Refresh %d", cb->get_ext() ); |
klauss | 81:3656f00ab3db | 50 | |
klauss | 80:61d61c9eb75c | 51 | return( 0 ); |
klauss | 89:0fe315117b00 | 52 | }else return( -5 ); |
klauss | 89:0fe315117b00 | 53 | }else return( -3 ); |
klauss | 89:0fe315117b00 | 54 | } |
klauss | 89:0fe315117b00 | 55 | }else return( -1 ); |
klauss | 80:61d61c9eb75c | 56 | } |
klauss | 80:61d61c9eb75c | 57 | |
klauss | 80:61d61c9eb75c | 58 | //FiXME se validar, nao preciso de tantos parametros ... |
klauss | 74:81c47fff88a5 | 59 | void registry_aging( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){ |
klauss | 80:61d61c9eb75c | 60 | for( register int i = 0; i < v_cb->size(); i++ ){ |
klauss | 80:61d61c9eb75c | 61 | Call_Box * cb = (Call_Box * )v_cb->get_element( i ); |
klauss | 80:61d61c9eb75c | 62 | if( cb->is_timeout() ){ |
klauss | 80:61d61c9eb75c | 63 | if( debug_aging ) debug_msg("sands for %d", cb->get_ext() ); |
klauss | 80:61d61c9eb75c | 64 | if( cb->has_next_try() == false ){ |
klauss | 80:61d61c9eb75c | 65 | if( debug_aging ) debug_msg( "time to really go ( ext %d removed )", cb->get_ext() ); |
klauss | 80:61d61c9eb75c | 66 | v_cb->remove_element( i ); |
klauss | 80:61d61c9eb75c | 67 | delete( cb ); |
klauss | 80:61d61c9eb75c | 68 | break; |
klauss | 89:0fe315117b00 | 69 | } |
klauss | 80:61d61c9eb75c | 70 | } |
klauss | 80:61d61c9eb75c | 71 | } |
klauss | 78:1353744f01e1 | 72 | } |
klauss | 78:1353744f01e1 | 73 | |
klauss | 78:1353744f01e1 | 74 | void wake_all_up( Vector * v_cb, uint8_t * data, uint8_t * write_buffer ){ |
klauss | 104:62646ef786a3 | 75 | /** |
klauss | 104:62646ef786a3 | 76 | * Esta função busca por, dado uma lista de cbx, procura por buracos, |
klauss | 104:62646ef786a3 | 77 | * ou seja, slaves/masters que deveriam estar registrados uma vez que |
klauss | 104:62646ef786a3 | 78 | * o outro master/slave esta registrado, e manda um "ping" para esse cbx, |
klauss | 104:62646ef786a3 | 79 | * para efetivamente criar ele na lógica. |
klauss | 104:62646ef786a3 | 80 | */ |
klauss | 78:1353744f01e1 | 81 | if( v_cb != NULL && data != NULL && write_buffer != NULL ){ |
klauss | 104:62646ef786a3 | 82 | static int ext_list[ __MAX_CB_IN_A_BRANCH__ + 1 ]; |
klauss | 104:62646ef786a3 | 83 | static uint8_t last_size = 0; |
klauss | 78:1353744f01e1 | 84 | uint8_t size = v_cb->size(); |
klauss | 104:62646ef786a3 | 85 | static int wake_all_up_index = 0; |
klauss | 78:1353744f01e1 | 86 | |
klauss | 104:62646ef786a3 | 87 | if( last_size != size ) |
klauss | 104:62646ef786a3 | 88 | { |
klauss | 78:1353744f01e1 | 89 | for( register int i = 0; i < size; i++ ){ |
klauss | 78:1353744f01e1 | 90 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 78:1353744f01e1 | 91 | } |
klauss | 78:1353744f01e1 | 92 | |
klauss | 78:1353744f01e1 | 93 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 104:62646ef786a3 | 94 | } |
klauss | 104:62646ef786a3 | 95 | |
klauss | 104:62646ef786a3 | 96 | if( size > 0 ) |
klauss | 104:62646ef786a3 | 97 | { |
klauss | 104:62646ef786a3 | 98 | // testa se eh o master |
klauss | 104:62646ef786a3 | 99 | if( ( ext_list[ wake_all_up_index ] % 2 ) == 0 ) |
klauss | 104:62646ef786a3 | 100 | { |
klauss | 104:62646ef786a3 | 101 | //testa se o slave nao esta registrado |
klauss | 104:62646ef786a3 | 102 | if( ( size == 1 ) || ( ( wake_all_up_index + 1 ) == size ) || ( ext_list[ wake_all_up_index + 1 ] != ( ext_list[ wake_all_up_index ] + 1 ) ) ) |
klauss | 104:62646ef786a3 | 103 | { |
klauss | 104:62646ef786a3 | 104 | strcpy( ( char * )data, "ping\r\r\r\n" ); |
klauss | 104:62646ef786a3 | 105 | Call_Box * cb = __find_CB__( v_cb, ext_list[ wake_all_up_index ] ); |
klauss | 104:62646ef786a3 | 106 | if( cb != NULL ) |
klauss | 104:62646ef786a3 | 107 | { |
klauss | 104:62646ef786a3 | 108 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 104:62646ef786a3 | 109 | |
klauss | 104:62646ef786a3 | 110 | send2callboxes( __build_cb_package__( ( cb->get_ext() + 1 ), ( cb->get_port() + 1 ), __PROMPT__, |
klauss | 104:62646ef786a3 | 111 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 104:62646ef786a3 | 112 | |
klauss | 104:62646ef786a3 | 113 | if( debug_wake ) send_msg("%d without %d - ping sent to %d", |
klauss | 104:62646ef786a3 | 114 | ext_list[ wake_all_up_index ], ext_list[ wake_all_up_index ] + 1, cb->get_ext() + 1 ); |
klauss | 104:62646ef786a3 | 115 | } |
klauss | 104:62646ef786a3 | 116 | } |
klauss | 78:1353744f01e1 | 117 | |
klauss | 104:62646ef786a3 | 118 | }else{ |
klauss | 104:62646ef786a3 | 119 | 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 ) ) ) |
klauss | 104:62646ef786a3 | 120 | { |
klauss | 104:62646ef786a3 | 121 | strcpy( ( char * )data, "ping\r\r\r\n" ); |
klauss | 104:62646ef786a3 | 122 | Call_Box * cb = __find_CB__( v_cb, ( ext_list[ wake_all_up_index ] ) ); |
klauss | 104:62646ef786a3 | 123 | if( cb != NULL ) |
klauss | 104:62646ef786a3 | 124 | { |
klauss | 104:62646ef786a3 | 125 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 104:62646ef786a3 | 126 | |
klauss | 104:62646ef786a3 | 127 | send2callboxes( __build_cb_package__( ( cb->get_ext() - 1 ), ( cb->get_port() - 1 ), __PROMPT__, |
klauss | 104:62646ef786a3 | 128 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 104:62646ef786a3 | 129 | |
klauss | 104:62646ef786a3 | 130 | if( debug_wake ) send_msg("%d without %d - ping sent to %d", |
klauss | 104:62646ef786a3 | 131 | ext_list[ wake_all_up_index ], ext_list[ wake_all_up_index ] - 1, cb->get_ext() - 1 ); |
klauss | 78:1353744f01e1 | 132 | } |
klauss | 74:81c47fff88a5 | 133 | } |
klauss | 74:81c47fff88a5 | 134 | } |
klauss | 74:81c47fff88a5 | 135 | } |
klauss | 104:62646ef786a3 | 136 | if( ++wake_all_up_index >= size ) wake_all_up_index = 0; |
klauss | 74:81c47fff88a5 | 137 | } |
klauss | 74:81c47fff88a5 | 138 | } |