![](/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
main.cpp@89:0fe315117b00, 2015-01-07 (annotated)
- Committer:
- klauss
- Date:
- Wed Jan 07 21:48:53 2015 +0000
- Revision:
- 89:0fe315117b00
- Parent:
- 87:679ee0d594a9
- Child:
- 91:c2a86b1f8aaa
wip
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 74:81c47fff88a5 | 1 | #include "telemetry.h" |
klauss | 74:81c47fff88a5 | 2 | #include "eth.h" |
klauss | 74:81c47fff88a5 | 3 | #include "bits.h" |
klauss | 74:81c47fff88a5 | 4 | #include "UART3Interrupt.h" // for RXBuffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 74:81c47fff88a5 | 5 | #include "utils.h" |
klauss | 74:81c47fff88a5 | 6 | #include "parallelcpld.h" |
klauss | 74:81c47fff88a5 | 7 | #include "debug.h" |
klauss | 74:81c47fff88a5 | 8 | #include "flood.h" |
klauss | 74:81c47fff88a5 | 9 | #include "bootloader_cbx.h" |
klauss | 74:81c47fff88a5 | 10 | #include "call_manager.h" |
klauss | 74:81c47fff88a5 | 11 | #include "call_box_manager.h" |
klauss | 74:81c47fff88a5 | 12 | #include "sip_manager.h" |
klauss | 74:81c47fff88a5 | 13 | #include "shared_variables.h" |
klauss | 74:81c47fff88a5 | 14 | #include "prompt.h" |
klauss | 0:4d17cd9c8f9d | 15 | #include "configs.h" |
klauss | 87:679ee0d594a9 | 16 | #include "sdram.h" |
klauss | 0:4d17cd9c8f9d | 17 | |
klauss | 89:0fe315117b00 | 18 | #define vz_LIM 8 |
klauss | 89:0fe315117b00 | 19 | |
klauss | 87:679ee0d594a9 | 20 | volatile u16_t lpc_low_level_input_counter = 0; |
klauss | 85:b6f2dc1d0f4f | 21 | |
klauss | 0:4d17cd9c8f9d | 22 | int main(){ |
klauss | 81:3656f00ab3db | 23 | init_wdt(); |
klauss | 79:9bc12aa305a9 | 24 | |
klauss | 81:3656f00ab3db | 25 | config_lpc(); |
klauss | 79:9bc12aa305a9 | 26 | |
klauss | 0:4d17cd9c8f9d | 27 | start_cpld(); |
klauss | 79:9bc12aa305a9 | 28 | |
klauss | 89:0fe315117b00 | 29 | if( sdram_init() == 1 ){ |
klauss | 87:679ee0d594a9 | 30 | send_msg("******* Failed to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 31 | return 1; |
klauss | 89:0fe315117b00 | 32 | } else { |
klauss | 87:679ee0d594a9 | 33 | send_msg("******* Success to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 34 | } |
klauss | 87:679ee0d594a9 | 35 | |
klauss | 43:455522f98de5 | 36 | init_fsystem(); |
klauss | 43:455522f98de5 | 37 | |
klauss | 89:0fe315117b00 | 38 | { |
klauss | 89:0fe315117b00 | 39 | char s[ 32 ]; |
klauss | 89:0fe315117b00 | 40 | mbed_mac_address( s ); |
klauss | 89:0fe315117b00 | 41 | send_msg( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] ); |
klauss | 89:0fe315117b00 | 42 | } |
klauss | 89:0fe315117b00 | 43 | |
klauss | 78:1353744f01e1 | 44 | short int eth_status = __init_eth__(); |
klauss | 8:e3bfe62a477e | 45 | if( eth_status ){ |
klauss | 87:679ee0d594a9 | 46 | send_msg("******* Cannot connect to eth *******"); |
klauss | 43:455522f98de5 | 47 | }else{ |
klauss | 81:3656f00ab3db | 48 | send_msg("******* Connection eth - ok *******"); |
klauss | 78:1353744f01e1 | 49 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 50 | init_external_wdt() |
klauss | 8:e3bfe62a477e | 51 | } |
klauss | 78:1353744f01e1 | 52 | |
klauss | 78:1353744f01e1 | 53 | Timer sync_timer, led_sync_timer; |
klauss | 78:1353744f01e1 | 54 | sync_timer.start(), led_sync_timer.start(); |
klauss | 0:4d17cd9c8f9d | 55 | |
klauss | 0:4d17cd9c8f9d | 56 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 57 | int ext = 0; |
klauss | 0:4d17cd9c8f9d | 58 | |
klauss | 0:4d17cd9c8f9d | 59 | /* representa porta do call box */ |
klauss | 78:1353744f01e1 | 60 | int port = 0; |
klauss | 78:1353744f01e1 | 61 | |
klauss | 0:4d17cd9c8f9d | 62 | /* buffer para onde se copia os dados vindos do cb para tratameno interno */ |
klauss | 0:4d17cd9c8f9d | 63 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 64 | |
klauss | 0:4d17cd9c8f9d | 65 | /* buffer de escrita do pacote de saida que sera enviado pro cb / servidor */ |
klauss | 0:4d17cd9c8f9d | 66 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 67 | |
klauss | 0:4d17cd9c8f9d | 68 | /* ponteiro que aponta para os dados vindo do CPLD */ |
klauss | 0:4d17cd9c8f9d | 69 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 0:4d17cd9c8f9d | 70 | |
klauss | 62:07e5bdc9f8f7 | 71 | /* Armazena o ultimo pacote recebido dos CBx */ |
klauss | 62:07e5bdc9f8f7 | 72 | uint8_t cb_rx_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 62:07e5bdc9f8f7 | 73 | |
klauss | 0:4d17cd9c8f9d | 74 | /* referencia para os dados contidos no pacote, sem o header */ |
klauss | 0:4d17cd9c8f9d | 75 | uint8_t * data = NULL; |
klauss | 0:4d17cd9c8f9d | 76 | |
klauss | 0:4d17cd9c8f9d | 77 | /* gerencia o tipo do pacote para providenciar tratamento adequado */ |
klauss | 0:4d17cd9c8f9d | 78 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 79 | |
klauss | 87:679ee0d594a9 | 80 | /* representa a lista dos Call Boxes atualmente recfonhecidos pela cabeceira */ |
klauss | 0:4d17cd9c8f9d | 81 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 82 | |
klauss | 0:4d17cd9c8f9d | 83 | /* representa a lista de ligacoes ativas na cabeceira */ |
klauss | 0:4d17cd9c8f9d | 84 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 85 | |
klauss | 0:4d17cd9c8f9d | 86 | /* gerencia a distribuicao de timeslice para os call boxes */ |
klauss | 0:4d17cd9c8f9d | 87 | Timeslice * ts = new Timeslice(); |
klauss | 89:0fe315117b00 | 88 | if( ts == NULL ) |
klauss | 89:0fe315117b00 | 89 | { |
klauss | 89:0fe315117b00 | 90 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 91 | if( debug_memory ) debug_msg("TS allocation fail"); |
klauss | 89:0fe315117b00 | 92 | } |
klauss | 78:1353744f01e1 | 93 | |
klauss | 81:3656f00ab3db | 94 | /* instancia o vetor de call boxes // calls */ |
klauss | 0:4d17cd9c8f9d | 95 | if( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 96 | while( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 97 | Vector * v_cb = new Vector(); |
klauss | 78:1353744f01e1 | 98 | if( sync_timer.read() > 5 ){ |
klauss | 48:195c97f12e8e | 99 | send_msg("Erro ao alocar o vetor de CBx"); |
klauss | 78:1353744f01e1 | 100 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 101 | } |
klauss | 0:4d17cd9c8f9d | 102 | } |
klauss | 0:4d17cd9c8f9d | 103 | }else if( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 104 | while( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 105 | Vector * v_call = new Vector(); |
klauss | 78:1353744f01e1 | 106 | if( sync_timer.read() > 5 ){ |
klauss | 48:195c97f12e8e | 107 | send_msg("Erro ao alocar o vetor de Calls"); |
klauss | 78:1353744f01e1 | 108 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 109 | } |
klauss | 0:4d17cd9c8f9d | 110 | } |
klauss | 0:4d17cd9c8f9d | 111 | } |
klauss | 63:0d95da692bb4 | 112 | |
klauss | 89:0fe315117b00 | 113 | if( v_cb == NULL ) |
klauss | 89:0fe315117b00 | 114 | { |
klauss | 89:0fe315117b00 | 115 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 116 | if( debug_memory ) debug_msg("Call_Box vector allocation fail"); |
klauss | 89:0fe315117b00 | 117 | } |
klauss | 89:0fe315117b00 | 118 | |
klauss | 89:0fe315117b00 | 119 | if( v_call == NULL ) |
klauss | 89:0fe315117b00 | 120 | { |
klauss | 89:0fe315117b00 | 121 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 122 | if( debug_memory ) debug_msg("Call vector allocation fail"); |
klauss | 89:0fe315117b00 | 123 | } |
klauss | 87:679ee0d594a9 | 124 | |
klauss | 63:0d95da692bb4 | 125 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 63:0d95da692bb4 | 126 | cb_rx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 127 | cb_tx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 128 | } |
klauss | 63:0d95da692bb4 | 129 | |
klauss | 0:4d17cd9c8f9d | 130 | reset_leds(); |
klauss | 78:1353744f01e1 | 131 | |
klauss | 33:735fd60e96d8 | 132 | udp_timer.start(); |
klauss | 68:b54993674190 | 133 | |
klauss | 68:b54993674190 | 134 | init_telemetry_handler(); |
klauss | 68:b54993674190 | 135 | |
klauss | 81:3656f00ab3db | 136 | init_ranges(); |
klauss | 81:3656f00ab3db | 137 | |
klauss | 80:61d61c9eb75c | 138 | init_refresh(); |
klauss | 80:61d61c9eb75c | 139 | |
klauss | 78:1353744f01e1 | 140 | init_aging(); |
klauss | 78:1353744f01e1 | 141 | |
klauss | 89:0fe315117b00 | 142 | init_sync_refresh(); |
klauss | 89:0fe315117b00 | 143 | |
klauss | 81:3656f00ab3db | 144 | //init_invite_pgk_retry_manager(); |
klauss | 81:3656f00ab3db | 145 | |
klauss | 81:3656f00ab3db | 146 | //void init_bye_pgk_retry_manager(); |
klauss | 89:0fe315117b00 | 147 | |
klauss | 62:07e5bdc9f8f7 | 148 | static uint8_t count = 0; |
klauss | 78:1353744f01e1 | 149 | |
klauss | 89:0fe315117b00 | 150 | //short int bl_ret = init_bl_handler(); |
klauss | 89:0fe315117b00 | 151 | //if( dbl ) send_msg("Valor de retorno do bl_habdler = %d", bl_ret ); |
klauss | 67:cdedc64d9921 | 152 | |
klauss | 78:1353744f01e1 | 153 | uint8_t max_registered_cbx = 0; |
klauss | 78:1353744f01e1 | 154 | |
klauss | 81:3656f00ab3db | 155 | bool wake_all = false; |
klauss | 81:3656f00ab3db | 156 | |
klauss | 81:3656f00ab3db | 157 | uint16_t pkg_wdt = RX_CB_IDLE; |
klauss | 81:3656f00ab3db | 158 | uint16_t eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 83:b8a1d8fdeaeb | 159 | uint32_t uptime = 0; |
klauss | 83:b8a1d8fdeaeb | 160 | |
klauss | 68:b54993674190 | 161 | send_msg("Ready"); |
klauss | 68:b54993674190 | 162 | |
klauss | 86:bf7b0d4c3232 | 163 | bool regystry_test = false; |
klauss | 86:bf7b0d4c3232 | 164 | static int next_value = 5010; |
klauss | 86:bf7b0d4c3232 | 165 | static int nex_test_registry = next_value; |
klauss | 86:bf7b0d4c3232 | 166 | |
klauss | 89:0fe315117b00 | 167 | uint8_t vz_lim = vz_LIM; |
klauss | 86:bf7b0d4c3232 | 168 | |
klauss | 78:1353744f01e1 | 169 | /*------------------------------------------ main loop ---------------------------------------------------------------*/ |
Cola | 21:0bd688722e81 | 170 | while( true ){ |
klauss | 78:1353744f01e1 | 171 | if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); |
klauss | 78:1353744f01e1 | 172 | |
klauss | 78:1353744f01e1 | 173 | if( sync_timer.read() > 5 ){ |
klauss | 78:1353744f01e1 | 174 | sync_timer.reset(); |
klauss | 78:1353744f01e1 | 175 | |
klauss | 78:1353744f01e1 | 176 | if( debug_cks == true ){ |
klauss | 81:3656f00ab3db | 177 | pcks_s = true; |
klauss | 78:1353744f01e1 | 178 | } |
klauss | 78:1353744f01e1 | 179 | |
klauss | 78:1353744f01e1 | 180 | if( debug_alive == true ){ |
klauss | 81:3656f00ab3db | 181 | pshowcb = true; |
klauss | 78:1353744f01e1 | 182 | } |
klauss | 81:3656f00ab3db | 183 | |
klauss | 81:3656f00ab3db | 184 | if( !( ++count % 15 ) ){ |
klauss | 78:1353744f01e1 | 185 | if( eth_status ){ |
klauss | 78:1353744f01e1 | 186 | eth_status = __init_eth__(); |
klauss | 78:1353744f01e1 | 187 | if( eth_status ){ |
klauss | 78:1353744f01e1 | 188 | if( debug_main ) debug_msg("Cannot connect to eth"); |
klauss | 78:1353744f01e1 | 189 | }else{ |
klauss | 78:1353744f01e1 | 190 | if( debug_main ) debug_msg("Connection eth - ok"); |
klauss | 78:1353744f01e1 | 191 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 192 | init_external_wdt() |
klauss | 78:1353744f01e1 | 193 | } |
klauss | 78:1353744f01e1 | 194 | } |
klauss | 78:1353744f01e1 | 195 | } |
klauss | 81:3656f00ab3db | 196 | //35 sec. |
klauss | 81:3656f00ab3db | 197 | if( ( count > 7 ) && ( wake_all == false ) ){ |
klauss | 81:3656f00ab3db | 198 | wake_all = true; |
klauss | 78:1353744f01e1 | 199 | if( debug_wake == true ) send_msg( "Time to wake" ); |
klauss | 78:1353744f01e1 | 200 | } |
klauss | 78:1353744f01e1 | 201 | } |
klauss | 78:1353744f01e1 | 202 | |
klauss | 68:b54993674190 | 203 | //FIXMEj colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ... |
klauss | 35:96885a7931f0 | 204 | prompt_process( NULL ); |
klauss | 63:0d95da692bb4 | 205 | |
klauss | 63:0d95da692bb4 | 206 | if( r_stats ){ |
klauss | 63:0d95da692bb4 | 207 | boot_counter = 0; |
klauss | 63:0d95da692bb4 | 208 | registry_counter = 0; |
klauss | 63:0d95da692bb4 | 209 | invite_counter = 0; |
klauss | 63:0d95da692bb4 | 210 | audio_counter = 0; |
klauss | 63:0d95da692bb4 | 211 | telemetry_counter = 0; |
klauss | 63:0d95da692bb4 | 212 | cb_bye_counter = 0; |
klauss | 63:0d95da692bb4 | 213 | prompt_counter = 0; |
klauss | 63:0d95da692bb4 | 214 | flood_counter = 0; |
klauss | 67:cdedc64d9921 | 215 | bootloader_cbx_counter = 0; |
klauss | 63:0d95da692bb4 | 216 | r_stats = false; |
klauss | 63:0d95da692bb4 | 217 | stats = true; |
klauss | 63:0d95da692bb4 | 218 | } |
klauss | 81:3656f00ab3db | 219 | |
klauss | 63:0d95da692bb4 | 220 | if( stats ){ |
klauss | 63:0d95da692bb4 | 221 | char str[ 200 ]; |
klauss | 81:3656f00ab3db | 222 | snprintf( str, 200, "\n\rReceived Pkgs::\n\r Boot :: %u\n\r Registry :: %u\n\r Ivite :: %u\n\r Audio :: %u\n\r Telemetry :: %u\n\r Cb_bye :: %u\n\r Prompt :: %u\n\r Flood :: %u\n\r Bootloader_cbx :: %u\n\r", |
klauss | 67:cdedc64d9921 | 223 | boot_counter, registry_counter, invite_counter, audio_counter, telemetry_counter, cb_bye_counter, prompt_counter, flood_counter, bootloader_cbx_counter ); |
klauss | 63:0d95da692bb4 | 224 | send_msg( str ); |
klauss | 63:0d95da692bb4 | 225 | stats =false; |
klauss | 63:0d95da692bb4 | 226 | } |
klauss | 63:0d95da692bb4 | 227 | |
klauss | 62:07e5bdc9f8f7 | 228 | if( list ){ |
klauss | 78:1353744f01e1 | 229 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 78:1353744f01e1 | 230 | |
klauss | 78:1353744f01e1 | 231 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 78:1353744f01e1 | 232 | |
klauss | 78:1353744f01e1 | 233 | if( min_ext % 2 ) missed_cb++; |
klauss | 78:1353744f01e1 | 234 | |
klauss | 78:1353744f01e1 | 235 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 78:1353744f01e1 | 236 | |
klauss | 78:1353744f01e1 | 237 | send_msg("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, ts->remain_timeslices(), v_call->size() ); |
klauss | 78:1353744f01e1 | 238 | if( v_cb->size() == 1 ){ |
klauss | 78:1353744f01e1 | 239 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 78:1353744f01e1 | 240 | }else if( v_cb->size() > 1 ){ |
klauss | 62:07e5bdc9f8f7 | 241 | char str[ 1024 ]; |
klauss | 78:1353744f01e1 | 242 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 62:07e5bdc9f8f7 | 243 | register int i = 0; |
klauss | 62:07e5bdc9f8f7 | 244 | for( ; i < v_cb->size(); i++ ){ |
klauss | 78:1353744f01e1 | 245 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 62:07e5bdc9f8f7 | 246 | } |
klauss | 62:07e5bdc9f8f7 | 247 | |
klauss | 62:07e5bdc9f8f7 | 248 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 62:07e5bdc9f8f7 | 249 | |
klauss | 62:07e5bdc9f8f7 | 250 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 251 | strcpy( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 252 | for( i = 0; i < v_cb->size() - 1; i++ ){ |
klauss | 62:07e5bdc9f8f7 | 253 | sprintf( aux, "%i, ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 254 | strcat( str, aux ); |
klauss | 78:1353744f01e1 | 255 | if( ( i != 0 ) && !( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 256 | } |
klauss | 62:07e5bdc9f8f7 | 257 | sprintf( aux, "%i ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 258 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 259 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 260 | } |
klauss | 62:07e5bdc9f8f7 | 261 | list = false; |
klauss | 62:07e5bdc9f8f7 | 262 | } |
klauss | 62:07e5bdc9f8f7 | 263 | |
klauss | 81:3656f00ab3db | 264 | if( long_list ){ |
klauss | 81:3656f00ab3db | 265 | //FIXME implementar um algoritmo que me mostre o timeout de cada cbx do lado da linha, desse. |
klauss | 85:b6f2dc1d0f4f | 266 | /* |
klauss | 81:3656f00ab3db | 267 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 81:3656f00ab3db | 268 | |
klauss | 81:3656f00ab3db | 269 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 81:3656f00ab3db | 270 | |
klauss | 81:3656f00ab3db | 271 | if( min_ext % 2 ) missed_cb++; |
klauss | 81:3656f00ab3db | 272 | |
klauss | 81:3656f00ab3db | 273 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 81:3656f00ab3db | 274 | |
klauss | 81:3656f00ab3db | 275 | send_msg("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, ts->remain_timeslices(), v_call->size() ); |
klauss | 81:3656f00ab3db | 276 | if( v_cb->size() == 1 ){ |
klauss | 81:3656f00ab3db | 277 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 81:3656f00ab3db | 278 | }else if( v_cb->size() > 1 ){ |
klauss | 81:3656f00ab3db | 279 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 280 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 81:3656f00ab3db | 281 | register int i = 0; |
klauss | 81:3656f00ab3db | 282 | for( ; i < ( v_cb->size() * 2 ); i += 2 ){ |
klauss | 81:3656f00ab3db | 283 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 81:3656f00ab3db | 284 | ext_list[ i + 1 ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_elapsed_time(); |
klauss | 81:3656f00ab3db | 285 | } |
klauss | 81:3656f00ab3db | 286 | |
klauss | 81:3656f00ab3db | 287 | qsort( ext_list, v_cb->size(), sizeof( int ) * 2, ls_comp ); |
Cola | 24:270b436a1bb0 | 288 | |
klauss | 81:3656f00ab3db | 289 | char aux[ 16 ]; |
klauss | 81:3656f00ab3db | 290 | strcpy( str, "\r\n> " ); |
klauss | 81:3656f00ab3db | 291 | for( i = 0; i < ( v_cb->size() * 2 ) - 2; i++ ){ |
klauss | 81:3656f00ab3db | 292 | sprintf( aux, "%i - %i,", ext_list[ i ], ext_list[ i + 1 ] ); |
klauss | 81:3656f00ab3db | 293 | strcat( str, aux ); |
klauss | 81:3656f00ab3db | 294 | strcat( str, "\r\n> " ); |
klauss | 81:3656f00ab3db | 295 | } |
klauss | 81:3656f00ab3db | 296 | sprintf( aux, "%i - %i,", ext_list[ i ], ext_list[ i + 1 ] ); |
klauss | 81:3656f00ab3db | 297 | strcat( str, aux ); |
klauss | 81:3656f00ab3db | 298 | send_msg( "%s", str ); |
klauss | 81:3656f00ab3db | 299 | } |
klauss | 85:b6f2dc1d0f4f | 300 | */ |
klauss | 85:b6f2dc1d0f4f | 301 | long_list = false; |
klauss | 52:12930cef17c4 | 302 | } |
klauss | 52:12930cef17c4 | 303 | |
klauss | 78:1353744f01e1 | 304 | if( pshowcb == true ){ |
klauss | 78:1353744f01e1 | 305 | send_msg("Registered %d ( of %d ) CBx ( %d - %d ) -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, ts->remain_timeslices(), v_call->size() ); |
Cola | 24:270b436a1bb0 | 306 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 30:8dfb6d8de53d | 307 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 308 | char cb_status[ 32 ]; |
klauss | 78:1353744f01e1 | 309 | char cb_sip_status[ 32 ]; |
klauss | 78:1353744f01e1 | 310 | switch( cb->status ){ |
klauss | 78:1353744f01e1 | 311 | case cb_idle : { strcpy( cb_status, "cb_idle" ); break; } |
klauss | 78:1353744f01e1 | 312 | case cb_ringing : { strcpy( cb_status, "cb_ringing" ); break; } |
klauss | 78:1353744f01e1 | 313 | case cb_trying : { strcpy( cb_status,"cb_trying" ); break; } |
klauss | 78:1353744f01e1 | 314 | case cb_on_call : { strcpy( cb_status, "cb_on_call" ); break; } |
klauss | 78:1353744f01e1 | 315 | case cb_busy : { strcpy( cb_status, "cb_busy" ); break; } |
klauss | 78:1353744f01e1 | 316 | case cb_denied : { strcpy( cb_status, "cb_denied" ); break; } |
klauss | 78:1353744f01e1 | 317 | } |
klauss | 78:1353744f01e1 | 318 | switch( cb->sip->status ){ |
klauss | 78:1353744f01e1 | 319 | case sip_idle : { strcpy( cb_sip_status, "sip_idle" ); break; } |
klauss | 78:1353744f01e1 | 320 | case sip_waiting_trying : { strcpy( cb_sip_status, "sip_waiting_trying" ); break; } |
klauss | 78:1353744f01e1 | 321 | case sip_trying : { strcpy( cb_sip_status, "sip_trying" ); break; } |
klauss | 78:1353744f01e1 | 322 | case sip_ringing : { strcpy( cb_sip_status, "sip_ringing" ); break; } |
klauss | 78:1353744f01e1 | 323 | case sip_busy : { strcpy( cb_sip_status, "sip_busy" ); break; } |
klauss | 78:1353744f01e1 | 324 | case sip_ok : { strcpy( cb_sip_status, "sip_ok" ); break; } |
klauss | 78:1353744f01e1 | 325 | case sip_on_call : { strcpy( cb_sip_status, "sip_on_call" ); break; } |
klauss | 78:1353744f01e1 | 326 | case sip_denied : { strcpy( cb_sip_status, "sip_denied" ); break; } |
klauss | 78:1353744f01e1 | 327 | } |
klauss | 78:1353744f01e1 | 328 | char cbx_to_string[ 254 ]; |
klauss | 78:1353744f01e1 | 329 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 330 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 78:1353744f01e1 | 331 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 78:1353744f01e1 | 332 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 333 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 78:1353744f01e1 | 334 | strcat( cbx_to_string, cb_status ); |
klauss | 78:1353744f01e1 | 335 | strcat( cbx_to_string, " - " ); |
klauss | 78:1353744f01e1 | 336 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 78:1353744f01e1 | 337 | if( cb->get_timeslice() != 0 ){ |
klauss | 78:1353744f01e1 | 338 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 78:1353744f01e1 | 339 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 78:1353744f01e1 | 340 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 341 | } |
klauss | 78:1353744f01e1 | 342 | send_msg( cbx_to_string ); |
klauss | 48:195c97f12e8e | 343 | } |
klauss | 78:1353744f01e1 | 344 | pshowcb = false; |
klauss | 48:195c97f12e8e | 345 | } |
Cola | 22:d2a4b5939115 | 346 | |
klauss | 81:3656f00ab3db | 347 | if( pflood == true ) flood(); |
klauss | 81:3656f00ab3db | 348 | |
klauss | 81:3656f00ab3db | 349 | if( debug_eth ){ |
klauss | 81:3656f00ab3db | 350 | debug_eth = false; |
klauss | 81:3656f00ab3db | 351 | send_msg("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); |
klauss | 81:3656f00ab3db | 352 | } |
klauss | 30:8dfb6d8de53d | 353 | |
klauss | 0:4d17cd9c8f9d | 354 | if( status != __WAITING__ ){ |
klauss | 81:3656f00ab3db | 355 | pkg_wdt = RX_CB_IDLE; |
klauss | 86:bf7b0d4c3232 | 356 | xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 357 | status = __WAITING__; |
klauss | 81:3656f00ab3db | 358 | missed_pkg--; |
klauss | 78:1353744f01e1 | 359 | xmemcpy( buffer, cb_rx_buffer, __CB_BUFFER_SIZE__ ); |
klauss | 81:3656f00ab3db | 360 | |
klauss | 81:3656f00ab3db | 361 | if( debug_cpld ){ |
klauss | 81:3656f00ab3db | 362 | rx = true; |
klauss | 81:3656f00ab3db | 363 | tx = true; |
klauss | 81:3656f00ab3db | 364 | } |
klauss | 81:3656f00ab3db | 365 | |
klauss | 81:3656f00ab3db | 366 | if( rx ){ |
klauss | 81:3656f00ab3db | 367 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 368 | strcpy( str, "RX :: \n\r " ); |
klauss | 81:3656f00ab3db | 369 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 81:3656f00ab3db | 370 | char tmp[ 16 ]; |
klauss | 81:3656f00ab3db | 371 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 81:3656f00ab3db | 372 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 81:3656f00ab3db | 373 | |
klauss | 81:3656f00ab3db | 374 | else strcat( str, " " ); |
klauss | 81:3656f00ab3db | 375 | } |
klauss | 81:3656f00ab3db | 376 | send_msg( "%s", str ); |
klauss | 81:3656f00ab3db | 377 | rx = false; |
klauss | 81:3656f00ab3db | 378 | } |
klauss | 81:3656f00ab3db | 379 | |
klauss | 34:f19d9735428e | 380 | data = __parse_vz_pkg__( &ext, &port, &type, buffer ); |
klauss | 0:4d17cd9c8f9d | 381 | |
klauss | 78:1353744f01e1 | 382 | if( data != NULL ){ |
klauss | 78:1353744f01e1 | 383 | if( min_ext == 0 ) min_ext = ext; |
klauss | 78:1353744f01e1 | 384 | |
klauss | 78:1353744f01e1 | 385 | if( ext > max_ext ) max_ext = ext; |
klauss | 78:1353744f01e1 | 386 | |
klauss | 78:1353744f01e1 | 387 | if( ext < min_ext ) min_ext = ext; |
klauss | 78:1353744f01e1 | 388 | |
klauss | 78:1353744f01e1 | 389 | if( debug_cb_rx == true ) debug_msg("Pkg from CBx :: %d -- Type :: %d", ext, type ); |
klauss | 78:1353744f01e1 | 390 | |
klauss | 7:019b08223b87 | 391 | if( type != __AUDIO__ ){ |
klauss | 0:4d17cd9c8f9d | 392 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 393 | if( cb != NULL ){ |
klauss | 78:1353744f01e1 | 394 | if( ( data[ 0 ] & BIT7 ) >= BIT7 ){ |
klauss | 78:1353744f01e1 | 395 | if( type == __BOOT__ ){ |
klauss | 78:1353744f01e1 | 396 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 78:1353744f01e1 | 397 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 81:3656f00ab3db | 398 | }else if( ( data[ 0 ] & BIT7 ) == BIT7 ){ |
klauss | 81:3656f00ab3db | 399 | if( debug_main ) debug_msg("Received ack pkg with seq_num %d", data[ 0 ] ); |
klauss | 87:679ee0d594a9 | 400 | |
klauss | 81:3656f00ab3db | 401 | switch( type ){ |
klauss | 81:3656f00ab3db | 402 | case __INVITE__ : { |
klauss | 81:3656f00ab3db | 403 | if( debug_main || debug_invite ) debug_msg("Invite Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 404 | cb->set_invite_response_ok(); |
klauss | 81:3656f00ab3db | 405 | break; |
klauss | 81:3656f00ab3db | 406 | } |
klauss | 81:3656f00ab3db | 407 | case __CB_BYE__ : { |
klauss | 81:3656f00ab3db | 408 | if( debug_main || debug_invite ) debug_msg("BYE Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 409 | cb->set_bye_response_ok(); |
klauss | 81:3656f00ab3db | 410 | break; |
klauss | 81:3656f00ab3db | 411 | } |
klauss | 81:3656f00ab3db | 412 | case __REGISTRY__ : { |
klauss | 81:3656f00ab3db | 413 | if( debug_main || debug_aging ) debug_msg("Registry ACK from %d in pkg :: %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 414 | break; |
klauss | 81:3656f00ab3db | 415 | } |
klauss | 81:3656f00ab3db | 416 | default : { |
klauss | 81:3656f00ab3db | 417 | if( debug_main || debug_aging ) debug_msg("ACK from %d in pkg :: %d :: type %d", ext, cb->get_msg_id(), type ); |
klauss | 81:3656f00ab3db | 418 | } |
klauss | 81:3656f00ab3db | 419 | } |
klauss | 82:f55d13babca0 | 420 | if( type != __REGISTRY__ && type != __CB_BYE__ ) type = __DO_NOTHING__; |
klauss | 82:f55d13babca0 | 421 | //if( type != __REGISTRY__ ) type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 422 | } |
klauss | 0:4d17cd9c8f9d | 423 | } |
klauss | 0:4d17cd9c8f9d | 424 | } |
klauss | 0:4d17cd9c8f9d | 425 | } |
klauss | 0:4d17cd9c8f9d | 426 | }else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 427 | } |
klauss | 78:1353744f01e1 | 428 | |
klauss | 87:679ee0d594a9 | 429 | if( main_test == true ) |
klauss | 87:679ee0d594a9 | 430 | { |
klauss | 87:679ee0d594a9 | 431 | main_test = false; |
klauss | 85:b6f2dc1d0f4f | 432 | send_msg("CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter ); |
klauss | 85:b6f2dc1d0f4f | 433 | send_msg("SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter ); |
klauss | 87:679ee0d594a9 | 434 | send_msg("RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter ); |
klauss | 87:679ee0d594a9 | 435 | send_msg("RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter ); |
klauss | 87:679ee0d594a9 | 436 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 437 | send_msg("Memory is %s", ( memory_is_over ) ? "Over" : "Ok" ); |
klauss | 81:3656f00ab3db | 438 | send_msg("Missed_Pkg :: %d ::", missed_pkg ); |
klauss | 87:679ee0d594a9 | 439 | send_msg("Sizeof Sip :: %u", sizeof( Sip ) ); |
klauss | 87:679ee0d594a9 | 440 | send_msg("Sizeof Call_Box :: %u", sizeof( Call_Box ) ); |
klauss | 87:679ee0d594a9 | 441 | send_msg("Sizeof VZ_call :: %u", sizeof( VZ_call ) ); |
klauss | 87:679ee0d594a9 | 442 | send_msg("Sizeof RTP :: %u", sizeof( RTP ) ); |
klauss | 87:679ee0d594a9 | 443 | send_msg("Sizeof RTP_Header :: %u", sizeof( RTP_Header ) ); |
klauss | 87:679ee0d594a9 | 444 | send_msg("Sizeof RTP_Body :: %u", sizeof( RTP_Body ) ); |
klauss | 87:679ee0d594a9 | 445 | send_msg("Sizeof Vector :: %u", sizeof( Vector ) ); |
klauss | 87:679ee0d594a9 | 446 | send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) ); |
klauss | 87:679ee0d594a9 | 447 | send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) ); |
klauss | 81:3656f00ab3db | 448 | } |
klauss | 89:0fe315117b00 | 449 | |
klauss | 89:0fe315117b00 | 450 | static int wdt_count = 0; |
klauss | 86:bf7b0d4c3232 | 451 | if( regystry_test == true ) |
klauss | 86:bf7b0d4c3232 | 452 | { |
klauss | 86:bf7b0d4c3232 | 453 | regystry_test = false; |
klauss | 86:bf7b0d4c3232 | 454 | |
klauss | 89:0fe315117b00 | 455 | Timer sel; |
klauss | 89:0fe315117b00 | 456 | int tempo = 0; |
klauss | 89:0fe315117b00 | 457 | sel.start(); |
klauss | 89:0fe315117b00 | 458 | |
klauss | 89:0fe315117b00 | 459 | fd_set fdSet; |
klauss | 89:0fe315117b00 | 460 | FD_ZERO(&fdSet); |
klauss | 89:0fe315117b00 | 461 | |
klauss | 89:0fe315117b00 | 462 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 89:0fe315117b00 | 463 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 89:0fe315117b00 | 464 | FD_SET( cb->get_sip_socket_fd(), &fdSet); |
klauss | 89:0fe315117b00 | 465 | |
klauss | 89:0fe315117b00 | 466 | } |
klauss | 89:0fe315117b00 | 467 | |
klauss | 89:0fe315117b00 | 468 | struct timeval t; |
klauss | 89:0fe315117b00 | 469 | t.tv_sec = 0; |
klauss | 89:0fe315117b00 | 470 | t.tv_usec = 0; |
klauss | 89:0fe315117b00 | 471 | int ret = lwip_select( FD_SETSIZE, &fdSet, NULL, NULL, &t ); |
klauss | 89:0fe315117b00 | 472 | |
klauss | 89:0fe315117b00 | 473 | //int ret = lwip_select( FD_SETSIZE, &fdSet, NULL, NULL, NULL ); |
klauss | 89:0fe315117b00 | 474 | //send_msg("Ret:%d - Time::%d ", ret, sel.read_us() ); |
klauss | 89:0fe315117b00 | 475 | if(ret > 0 ){ |
klauss | 89:0fe315117b00 | 476 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 89:0fe315117b00 | 477 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 89:0fe315117b00 | 478 | int fd = cb->get_sip_socket_fd(); |
klauss | 89:0fe315117b00 | 479 | if( FD_ISSET( fd, &fdSet ) ){ |
klauss | 89:0fe315117b00 | 480 | //if( FD_ISSET( fd, &fdSet ) )send_msg( "ISSET %d - %d", cb->get_ext(), fd ); |
klauss | 89:0fe315117b00 | 481 | int rcv = cb->sip_udp_drop_once(); |
klauss | 89:0fe315117b00 | 482 | //if( rcv > 0 ) send_msg("Drop %d - %d", cb->get_ext(), rcv ); |
klauss | 89:0fe315117b00 | 483 | } |
klauss | 86:bf7b0d4c3232 | 484 | } |
klauss | 89:0fe315117b00 | 485 | } |
klauss | 89:0fe315117b00 | 486 | |
klauss | 89:0fe315117b00 | 487 | tempo = sel.read_us(); |
klauss | 89:0fe315117b00 | 488 | debug_msg("Time::%d", tempo ); |
klauss | 89:0fe315117b00 | 489 | if( wdt_count++ > 5 || v_cb->size() < 66 ){ |
klauss | 89:0fe315117b00 | 490 | wdt_count = 0; |
klauss | 89:0fe315117b00 | 491 | |
klauss | 89:0fe315117b00 | 492 | if( type == __DO_NOTHING__ ) |
klauss | 89:0fe315117b00 | 493 | { |
klauss | 89:0fe315117b00 | 494 | if( next_value < ( 5010 + __MAX_CB_IN_A_BRANCH__ - 2 ) ) |
klauss | 89:0fe315117b00 | 495 | { |
klauss | 89:0fe315117b00 | 496 | type = __REGISTRY__; |
klauss | 89:0fe315117b00 | 497 | data = buffer; |
klauss | 89:0fe315117b00 | 498 | ext = next_value; |
klauss | 89:0fe315117b00 | 499 | port = next_value++; |
klauss | 89:0fe315117b00 | 500 | } |
klauss | 89:0fe315117b00 | 501 | else |
klauss | 89:0fe315117b00 | 502 | { |
klauss | 89:0fe315117b00 | 503 | if( nex_test_registry > ( 5010 + __MAX_CB_IN_A_BRANCH__ - 1 - 2 ) ) nex_test_registry = 5010; |
klauss | 89:0fe315117b00 | 504 | type = __REGISTRY__; |
klauss | 89:0fe315117b00 | 505 | data = buffer; |
klauss | 89:0fe315117b00 | 506 | ext = nex_test_registry; |
klauss | 89:0fe315117b00 | 507 | port = nex_test_registry++; |
klauss | 89:0fe315117b00 | 508 | } |
klauss | 86:bf7b0d4c3232 | 509 | } |
klauss | 86:bf7b0d4c3232 | 510 | } |
klauss | 86:bf7b0d4c3232 | 511 | } |
klauss | 86:bf7b0d4c3232 | 512 | |
klauss | 89:0fe315117b00 | 513 | |
klauss | 81:3656f00ab3db | 514 | if( reset_cks == true ){ |
klauss | 81:3656f00ab3db | 515 | pkg_cksok = 0; |
klauss | 81:3656f00ab3db | 516 | pkg_ckserr = 0; |
klauss | 81:3656f00ab3db | 517 | reset_cks = false; |
klauss | 81:3656f00ab3db | 518 | pcks_s = true; |
klauss | 81:3656f00ab3db | 519 | } |
klauss | 81:3656f00ab3db | 520 | |
klauss | 81:3656f00ab3db | 521 | if( pcks_s == true ){ |
klauss | 86:bf7b0d4c3232 | 522 | send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d :: PKG_ZERO: %d :: Out_of_range: %d :: Missed_Pkg :: %d :: CPLD_RCV :: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range, missed_pkg, received_cpld_pkg ); |
klauss | 81:3656f00ab3db | 523 | pcks_s = false; |
klauss | 81:3656f00ab3db | 524 | } |
klauss | 81:3656f00ab3db | 525 | |
klauss | 78:1353744f01e1 | 526 | if( led_sync_timer.read() > 1 ){ |
klauss | 78:1353744f01e1 | 527 | led_sync_timer.reset(); |
klauss | 78:1353744f01e1 | 528 | led3 = !led3; |
klauss | 78:1353744f01e1 | 529 | CAB_LED = !CAB_LED; |
klauss | 78:1353744f01e1 | 530 | } |
klauss | 78:1353744f01e1 | 531 | |
klauss | 0:4d17cd9c8f9d | 532 | switch( type ){ |
klauss | 0:4d17cd9c8f9d | 533 | case __DO_NOTHING__ :{} |
klauss | 0:4d17cd9c8f9d | 534 | break; |
klauss | 0:4d17cd9c8f9d | 535 | |
klauss | 0:4d17cd9c8f9d | 536 | case __CB_BYE__ : { |
klauss | 81:3656f00ab3db | 537 | //FIXME como mandar um BYE pro servidor ? |
klauss | 63:0d95da692bb4 | 538 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 539 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 540 | if( cb != NULL ){ |
klauss | 81:3656f00ab3db | 541 | if( debug_invite || debug_main ) debug_msg("Received bye pkg with msg_id %d e pkg_id %d", cb->get_msg_id(), data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 542 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 543 | cb->set_msg_id( data[ 0 ] ); |
klauss | 81:3656f00ab3db | 544 | if( debug_main || debug_invite ) debug_msg( "Request bye from CBx " ); |
klauss | 81:3656f00ab3db | 545 | bool already_removed = true; |
klauss | 0:4d17cd9c8f9d | 546 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 547 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 548 | if( call->get_cb_ext() == ext ){ |
klauss | 81:3656f00ab3db | 549 | already_removed = false; |
klauss | 4:de46f0d9b14d | 550 | cb->send_bye(); |
klauss | 78:1353744f01e1 | 551 | |
klauss | 0:4d17cd9c8f9d | 552 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 553 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 554 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 555 | |
klauss | 0:4d17cd9c8f9d | 556 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 557 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 558 | |
klauss | 81:3656f00ab3db | 559 | v_call->remove_element( i ); |
klauss | 81:3656f00ab3db | 560 | |
klauss | 74:81c47fff88a5 | 561 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 562 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 82:f55d13babca0 | 563 | |
klauss | 82:f55d13babca0 | 564 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 565 | |
klauss | 3:cd9148672e25 | 566 | delete( call ); |
klauss | 29:7246460b73f8 | 567 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 568 | } |
klauss | 0:4d17cd9c8f9d | 569 | } |
klauss | 82:f55d13babca0 | 570 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from vector call" ); |
klauss | 82:f55d13babca0 | 571 | |
klauss | 82:f55d13babca0 | 572 | //ok, mas nem sempre o cbx "entrou em call |
klauss | 82:f55d13babca0 | 573 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 574 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 82:f55d13babca0 | 575 | if( cb->get_ext() == ext ) { |
klauss | 82:f55d13babca0 | 576 | already_removed = true; |
klauss | 82:f55d13babca0 | 577 | if( cb->get_status() != cb_idle ) { |
klauss | 82:f55d13babca0 | 578 | already_removed = false; |
klauss | 82:f55d13babca0 | 579 | cb->send_bye(); |
klauss | 82:f55d13babca0 | 580 | |
klauss | 82:f55d13babca0 | 581 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 82:f55d13babca0 | 582 | cb->set_timeslice( 0x00 ); |
klauss | 82:f55d13babca0 | 583 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 82:f55d13babca0 | 584 | |
klauss | 82:f55d13babca0 | 585 | set_status( cb->status, cb_idle ); |
klauss | 82:f55d13babca0 | 586 | set_status( cb->sip->status, sip_idle ); |
klauss | 82:f55d13babca0 | 587 | |
klauss | 82:f55d13babca0 | 588 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 82:f55d13babca0 | 589 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 82:f55d13babca0 | 590 | |
klauss | 82:f55d13babca0 | 591 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 82:f55d13babca0 | 592 | |
klauss | 82:f55d13babca0 | 593 | cb->re_start_timer(); |
klauss | 82:f55d13babca0 | 594 | } |
klauss | 82:f55d13babca0 | 595 | } |
klauss | 82:f55d13babca0 | 596 | } |
klauss | 82:f55d13babca0 | 597 | |
klauss | 82:f55d13babca0 | 598 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from inviting queue" ); |
klauss | 81:3656f00ab3db | 599 | |
klauss | 78:1353744f01e1 | 600 | cb->registry(); |
klauss | 81:3656f00ab3db | 601 | }else if( debug_invite || debug_main ) debug_msg("Bye from who ? %d", ext ); |
klauss | 7:019b08223b87 | 602 | }break; |
klauss | 7:019b08223b87 | 603 | |
klauss | 0:4d17cd9c8f9d | 604 | case __INVITE__ : { |
klauss | 63:0d95da692bb4 | 605 | invite_counter++; |
klauss | 78:1353744f01e1 | 606 | if( debug_invite ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 0:4d17cd9c8f9d | 607 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 608 | if( cb == NULL ){ |
klauss | 89:0fe315117b00 | 609 | if( v_cb->size() < vz_lim ) |
klauss | 89:0fe315117b00 | 610 | { |
klauss | 78:1353744f01e1 | 611 | if( debug_main ) debug_msg( "Adding CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 612 | cb = new Call_Box( ext, port ); |
klauss | 87:679ee0d594a9 | 613 | |
klauss | 87:679ee0d594a9 | 614 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 615 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 616 | if( debug_memory ) debug_msg("Invite allocation cb fail"); |
klauss | 87:679ee0d594a9 | 617 | }else{ |
klauss | 87:679ee0d594a9 | 618 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 619 | } |
klauss | 89:0fe315117b00 | 620 | } |
klauss | 0:4d17cd9c8f9d | 621 | } |
klauss | 87:679ee0d594a9 | 622 | if( cb != NULL ){ |
klauss | 87:679ee0d594a9 | 623 | cb->set_msg_id( data[ 0 ] ); |
klauss | 87:679ee0d594a9 | 624 | invite_handler( v_call, v_cb, ts, cb ); |
klauss | 87:679ee0d594a9 | 625 | } |
klauss | 0:4d17cd9c8f9d | 626 | }break; |
klauss | 4:de46f0d9b14d | 627 | case __REGISTRY__ : { |
klauss | 63:0d95da692bb4 | 628 | registry_counter++; |
klauss | 78:1353744f01e1 | 629 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 89:0fe315117b00 | 630 | if( v_cb->size() < vz_lim ){ |
klauss | 78:1353744f01e1 | 631 | if( cb == NULL ){ |
klauss | 78:1353744f01e1 | 632 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 4:de46f0d9b14d | 633 | cb = new Call_Box( ext, port ); |
klauss | 85:b6f2dc1d0f4f | 634 | |
klauss | 87:679ee0d594a9 | 635 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 636 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 637 | if( debug_memory ) debug_msg("Registry cb allocation fail"); |
klauss | 87:679ee0d594a9 | 638 | }else{ |
klauss | 87:679ee0d594a9 | 639 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 640 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 641 | } |
klauss | 0:4d17cd9c8f9d | 642 | } |
klauss | 89:0fe315117b00 | 643 | } |
klauss | 78:1353744f01e1 | 644 | if( debug_main ) debug_msg("Registered %d - %d", ext, port ); |
klauss | 78:1353744f01e1 | 645 | |
klauss | 87:679ee0d594a9 | 646 | if( cb != NULL ) cb->registry(); |
klauss | 78:1353744f01e1 | 647 | |
klauss | 4:de46f0d9b14d | 648 | }break; |
klauss | 4:de46f0d9b14d | 649 | case __BOOT__ : { |
klauss | 63:0d95da692bb4 | 650 | boot_counter++; |
klauss | 74:81c47fff88a5 | 651 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 78:1353744f01e1 | 652 | ( char * )data, data[ 0 ] | BIT7, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 653 | }break; |
klauss | 4:de46f0d9b14d | 654 | case __TELEMETRY__ : { |
klauss | 78:1353744f01e1 | 655 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 87:679ee0d594a9 | 656 | |
klauss | 78:1353744f01e1 | 657 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 658 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 87:679ee0d594a9 | 659 | ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 87:679ee0d594a9 | 660 | |
klauss | 87:679ee0d594a9 | 661 | /* |
klauss | 78:1353744f01e1 | 662 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 78:1353744f01e1 | 663 | cb = new Call_Box( ext, port ); |
klauss | 87:679ee0d594a9 | 664 | |
klauss | 87:679ee0d594a9 | 665 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 666 | memory_is_over = true; |
klauss | 87:679ee0d594a9 | 667 | }else{ |
klauss | 87:679ee0d594a9 | 668 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 669 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 670 | } |
klauss | 87:679ee0d594a9 | 671 | */ |
klauss | 78:1353744f01e1 | 672 | } |
klauss | 87:679ee0d594a9 | 673 | /* |
klauss | 87:679ee0d594a9 | 674 | if( cb != NULL ){ |
klauss | 87:679ee0d594a9 | 675 | cb->registry(); |
klauss | 87:679ee0d594a9 | 676 | }*/ |
klauss | 87:679ee0d594a9 | 677 | |
klauss | 63:0d95da692bb4 | 678 | telemetry_counter++; |
klauss | 78:1353744f01e1 | 679 | if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); |
klauss | 53:bb492a8f115a | 680 | build_telemetry_report( ext, port, ( char *)data ); |
klauss | 4:de46f0d9b14d | 681 | }break; |
klauss | 36:728498a78e1e | 682 | |
klauss | 67:cdedc64d9921 | 683 | case __BOOTLOADER_CBX__ : { |
klauss | 67:cdedc64d9921 | 684 | bootloader_cbx_counter++; |
klauss | 67:cdedc64d9921 | 685 | int ret = bl_cbx_reply_to_eth( ext, ( char * )data ); |
klauss | 67:cdedc64d9921 | 686 | }break; |
klauss | 67:cdedc64d9921 | 687 | |
klauss | 36:728498a78e1e | 688 | case __PROMPT__ : { |
klauss | 78:1353744f01e1 | 689 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 87:679ee0d594a9 | 690 | |
klauss | 78:1353744f01e1 | 691 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 692 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 87:679ee0d594a9 | 693 | ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 87:679ee0d594a9 | 694 | /* |
klauss | 78:1353744f01e1 | 695 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 78:1353744f01e1 | 696 | cb = new Call_Box( ext, port ); |
klauss | 87:679ee0d594a9 | 697 | if( cb == NULL ){ |
klauss | 87:679ee0d594a9 | 698 | memory_is_over = true; |
klauss | 87:679ee0d594a9 | 699 | }else{ |
klauss | 87:679ee0d594a9 | 700 | v_cb->add( cb ); |
klauss | 87:679ee0d594a9 | 701 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 702 | } |
klauss | 87:679ee0d594a9 | 703 | */ |
klauss | 48:195c97f12e8e | 704 | } |
klauss | 78:1353744f01e1 | 705 | |
klauss | 87:679ee0d594a9 | 706 | //if( cb!= NULL ) cb->registry(); |
klauss | 48:195c97f12e8e | 707 | |
klauss | 78:1353744f01e1 | 708 | if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ){ |
klauss | 78:1353744f01e1 | 709 | if( debug_ping ) send_msg( "Prompt pkg from ( %i, %i ) :: Ping", ext, port ); |
klauss | 78:1353744f01e1 | 710 | }else{ |
klauss | 78:1353744f01e1 | 711 | prompt_counter++; |
klauss | 78:1353744f01e1 | 712 | //fixme isso nao poderia ser resolvido com um sendmsg ? |
klauss | 78:1353744f01e1 | 713 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 78:1353744f01e1 | 714 | for( register uint8_t i = 0; i < 32; i++ ){ |
klauss | 78:1353744f01e1 | 715 | pc.printf("%c", data[ i ] ); |
klauss | 78:1353744f01e1 | 716 | if( i == 15 ) pc.printf( "\r\n" ); |
klauss | 78:1353744f01e1 | 717 | } |
klauss | 78:1353744f01e1 | 718 | pc.printf("\n\r> "); |
klauss | 78:1353744f01e1 | 719 | |
klauss | 78:1353744f01e1 | 720 | if( tcp_session ){ |
klauss | 78:1353744f01e1 | 721 | char aux[ __CB_BUFFER_SIZE__ + 3 ]; |
klauss | 78:1353744f01e1 | 722 | strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); |
klauss | 78:1353744f01e1 | 723 | strcat( aux, "\n\r\0" ); |
klauss | 78:1353744f01e1 | 724 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 78:1353744f01e1 | 725 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 78:1353744f01e1 | 726 | } |
klauss | 48:195c97f12e8e | 727 | } |
klauss | 36:728498a78e1e | 728 | }break; |
klauss | 0:4d17cd9c8f9d | 729 | case __AUDIO__ : { |
klauss | 63:0d95da692bb4 | 730 | audio_counter++; |
klauss | 78:1353744f01e1 | 731 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 0:4d17cd9c8f9d | 732 | if( call != NULL ){ |
klauss | 30:8dfb6d8de53d | 733 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 0:4d17cd9c8f9d | 734 | call->send_message( pkg ); |
klauss | 78:1353744f01e1 | 735 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 736 | if( cb != NULL ) cb->reset_elapsed_time(); |
klauss | 18:01a93677e40c | 737 | }else{ |
klauss | 78:1353744f01e1 | 738 | if( debug_main ) debug_msg("received missed package from CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 739 | } |
klauss | 0:4d17cd9c8f9d | 740 | }break; |
klauss | 9:ffa64f38ef9c | 741 | }// fim switch |
klauss | 81:3656f00ab3db | 742 | |
klauss | 78:1353744f01e1 | 743 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 744 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 745 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 746 | char * tmp = call->get_eth_message( &length ); |
klauss | 0:4d17cd9c8f9d | 747 | if( tmp != NULL ){ |
klauss | 0:4d17cd9c8f9d | 748 | int cb_port = 0xffff; |
klauss | 78:1353744f01e1 | 749 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 4:de46f0d9b14d | 750 | |
klauss | 4:de46f0d9b14d | 751 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 752 | cb_port = cb->get_port(); |
klauss | 78:1353744f01e1 | 753 | |
klauss | 78:1353744f01e1 | 754 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 0:4d17cd9c8f9d | 755 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 4:de46f0d9b14d | 756 | |
klauss | 78:1353744f01e1 | 757 | send2callboxes( pkg2cb ); |
klauss | 78:1353744f01e1 | 758 | }else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 759 | } |
klauss | 14:22a35f575502 | 760 | } |
klauss | 81:3656f00ab3db | 761 | //if( v_call->size() == 0 ) refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 89:0fe315117b00 | 762 | |
klauss | 89:0fe315117b00 | 763 | if( timer_sync_refresh.read_ms() > 500 ) |
klauss | 89:0fe315117b00 | 764 | { |
klauss | 89:0fe315117b00 | 765 | timer_sync_refresh.reset(); |
klauss | 89:0fe315117b00 | 766 | |
klauss | 89:0fe315117b00 | 767 | static uint8_t mode = TIME_TO_REFRESH; |
klauss | 89:0fe315117b00 | 768 | |
klauss | 89:0fe315117b00 | 769 | if( mode == TIME_TO_REFRESH ){ |
klauss | 89:0fe315117b00 | 770 | mode = TIME_TO_WAKE_UP; |
klauss | 89:0fe315117b00 | 771 | refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 89:0fe315117b00 | 772 | }else{ |
klauss | 89:0fe315117b00 | 773 | mode = TIME_TO_REFRESH; |
klauss | 89:0fe315117b00 | 774 | //if( wake_all ) if( v_call->size() == 0 ) wake_all_up( v_cb, buffer, write_buffer ); |
klauss | 89:0fe315117b00 | 775 | } |
klauss | 89:0fe315117b00 | 776 | } |
klauss | 89:0fe315117b00 | 777 | |
klauss | 89:0fe315117b00 | 778 | |
klauss | 89:0fe315117b00 | 779 | //refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 78:1353744f01e1 | 780 | |
klauss | 78:1353744f01e1 | 781 | //Fixme pensar melhor nessa parte durante ligacoes, pode complicar com muitos cbx ... |
klauss | 81:3656f00ab3db | 782 | //if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 4:de46f0d9b14d | 783 | |
klauss | 78:1353744f01e1 | 784 | // check sip messages only for cbx in call ? |
klauss | 78:1353744f01e1 | 785 | int ext_to__be_removed = sip_manager( v_cb ); |
klauss | 78:1353744f01e1 | 786 | if( ext_to__be_removed > 0x00 ){ |
klauss | 78:1353744f01e1 | 787 | Call_Box * cb = __find_CB__( v_cb, ext_to__be_removed ); |
klauss | 4:de46f0d9b14d | 788 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 789 | if( cb->status == cb_on_call ){ |
klauss | 4:de46f0d9b14d | 790 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 791 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 792 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 793 | |
klauss | 78:1353744f01e1 | 794 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 795 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 796 | |
klauss | 4:de46f0d9b14d | 797 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 4:de46f0d9b14d | 798 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 78:1353744f01e1 | 799 | if( call->get_cb_ext() == ext_to__be_removed ){ |
klauss | 4:de46f0d9b14d | 800 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 801 | delete( call ); |
klauss | 4:de46f0d9b14d | 802 | } |
klauss | 2:93bec7313ccc | 803 | } |
klauss | 78:1353744f01e1 | 804 | |
klauss | 82:f55d13babca0 | 805 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 82:f55d13babca0 | 806 | //cb->set_msg_id( 80 ); |
klauss | 81:3656f00ab3db | 807 | |
klauss | 82:f55d13babca0 | 808 | //debug_msg("msg_id -- %d", cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 809 | |
klauss | 74:81c47fff88a5 | 810 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 4:de46f0d9b14d | 811 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 812 | |
klauss | 81:3656f00ab3db | 813 | //cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 814 | } |
klauss | 78:1353744f01e1 | 815 | }else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d", ext ); |
klauss | 0:4d17cd9c8f9d | 816 | } |
klauss | 13:ae278302dffe | 817 | |
klauss | 81:3656f00ab3db | 818 | /* Verifica andamento de ligações para eventualmente encerra-las por timeout */ |
klauss | 10:22da1a0ac1e1 | 819 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 0:4d17cd9c8f9d | 820 | |
klauss | 81:3656f00ab3db | 821 | /* tratamento de pedidos de ligação */ |
klauss | 81:3656f00ab3db | 822 | invite_handler( v_call, v_cb, ts, NULL ); |
klauss | 78:1353744f01e1 | 823 | |
klauss | 81:3656f00ab3db | 824 | /* rotina de verificação de TS's perdidos */ |
klauss | 78:1353744f01e1 | 825 | if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != __MAX_TIMESLICES__ ) ){ |
klauss | 78:1353744f01e1 | 826 | bool ts_reset = true; |
klauss | 78:1353744f01e1 | 827 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 82:f55d13babca0 | 828 | if ( ( ( Call_Box * )v_cb->get_element( i ) )->get_status() != cb_idle && |
klauss | 82:f55d13babca0 | 829 | ( ( Call_Box * )v_cb->get_element( i ) )->get_sip_status() != sip_idle ) |
klauss | 82:f55d13babca0 | 830 | { |
klauss | 78:1353744f01e1 | 831 | ts_reset = false; |
klauss | 78:1353744f01e1 | 832 | break; |
klauss | 78:1353744f01e1 | 833 | } |
klauss | 78:1353744f01e1 | 834 | } |
klauss | 78:1353744f01e1 | 835 | if( ts_reset ){ |
klauss | 81:3656f00ab3db | 836 | if( debug_invite ) debug_msg("Resetando TS"); |
klauss | 78:1353744f01e1 | 837 | ts->reset(); |
klauss | 78:1353744f01e1 | 838 | } |
klauss | 0:4d17cd9c8f9d | 839 | } |
klauss | 78:1353744f01e1 | 840 | |
klauss | 81:3656f00ab3db | 841 | //invite_pgk_retry_manager( v_call, v_cb, buffer, write_buffer ); |
klauss | 81:3656f00ab3db | 842 | |
klauss | 81:3656f00ab3db | 843 | /* escuta se existe algum procedimento de gravação de cbx */ |
klauss | 67:cdedc64d9921 | 844 | bl_handler(); |
klauss | 78:1353744f01e1 | 845 | |
klauss | 81:3656f00ab3db | 846 | /* rotina que esvazia possiveis pacotes que não foram transmitidos para evitar conflito */ |
klauss | 72:895ca792c647 | 847 | tx_buffer_ring_buffer_handler(); |
klauss | 33:735fd60e96d8 | 848 | |
klauss | 30:8dfb6d8de53d | 849 | type = __DO_NOTHING__; |
klauss | 81:3656f00ab3db | 850 | |
klauss | 81:3656f00ab3db | 851 | if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 81:3656f00ab3db | 852 | |
klauss | 83:b8a1d8fdeaeb | 853 | if( wdt_timer.read() >= 1 ){ |
klauss | 86:bf7b0d4c3232 | 854 | regystry_test = true; |
klauss | 86:bf7b0d4c3232 | 855 | |
klauss | 83:b8a1d8fdeaeb | 856 | char wake_msg[ 48 ]; |
klauss | 83:b8a1d8fdeaeb | 857 | uptime++; |
klauss | 82:f55d13babca0 | 858 | int read = udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ); |
klauss | 82:f55d13babca0 | 859 | |
klauss | 89:0fe315117b00 | 860 | bool force_alive = false ; |
klauss | 89:0fe315117b00 | 861 | |
klauss | 82:f55d13babca0 | 862 | if( read > 0 ){ |
klauss | 85:b6f2dc1d0f4f | 863 | eth_pkg_received++; |
klauss | 89:0fe315117b00 | 864 | |
klauss | 82:f55d13babca0 | 865 | if( !( strncmp( wake_msg, "alive", 5 ) ) ){ |
klauss | 83:b8a1d8fdeaeb | 866 | // Just ckeck but not set 'alive?' |
klauss | 83:b8a1d8fdeaeb | 867 | // Ckecking and set 'alive' |
klauss | 84:b64f0e3b283e | 868 | bool question_alive = ( wake_msg[ 5 ] == '?' ); |
klauss | 89:0fe315117b00 | 869 | force_alive = ( wake_msg[ 5 ] == '*' ); |
klauss | 89:0fe315117b00 | 870 | |
klauss | 89:0fe315117b00 | 871 | if( wake_msg[ 5 ] == '@' ) |
klauss | 89:0fe315117b00 | 872 | { |
klauss | 89:0fe315117b00 | 873 | vz_lim = wake_msg[ 6 ]; |
klauss | 89:0fe315117b00 | 874 | } |
klauss | 84:b64f0e3b283e | 875 | |
klauss | 85:b6f2dc1d0f4f | 876 | snprintf( wake_msg, 48,"wdt:%u,%u,%u,%c,%u:", uptime, invite_counter, external_wdt, ( wdt.WatchdogCausedReset() ) ? '1' : '0', cb_new_counter ); |
klauss | 83:b8a1d8fdeaeb | 877 | wake_msg[ 48 - 1 ] = 0; |
klauss | 83:b8a1d8fdeaeb | 878 | int sent = 0; |
klauss | 84:b64f0e3b283e | 879 | sent = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 83:b8a1d8fdeaeb | 880 | |
klauss | 83:b8a1d8fdeaeb | 881 | if( wdt_show ) send_msg( "Sent %d bytes in response", sent ); |
klauss | 84:b64f0e3b283e | 882 | |
klauss | 89:0fe315117b00 | 883 | if( ( (!question_alive) && ( cb_new_counter <= __MAX_CB_IN_A_BRANCH__ ) && ( cb_new_counter >= 2 ) ) |
klauss | 89:0fe315117b00 | 884 | || force_alive ){ |
klauss | 84:b64f0e3b283e | 885 | external_wdt = EXTERN_WDT_IDLE; |
klauss | 84:b64f0e3b283e | 886 | } |
klauss | 83:b8a1d8fdeaeb | 887 | }else if( !( strncmp( wake_msg, "reset", 5 ) ) ){ |
klauss | 83:b8a1d8fdeaeb | 888 | external_wdt = 0; |
klauss | 83:b8a1d8fdeaeb | 889 | |
klauss | 83:b8a1d8fdeaeb | 890 | sprintf( wake_msg, "rst:%u:", uptime ); |
klauss | 89:0fe315117b00 | 891 | int sent = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 83:b8a1d8fdeaeb | 892 | |
klauss | 83:b8a1d8fdeaeb | 893 | if( wdt_show ) send_msg( "Sent %d bytes in response", sent ); |
klauss | 82:f55d13babca0 | 894 | } |
klauss | 82:f55d13babca0 | 895 | } |
klauss | 83:b8a1d8fdeaeb | 896 | if( wdt_show ) if( read < 0 ) debug_msg( "some's wrong ... some's wrong" ); |
klauss | 82:f55d13babca0 | 897 | |
klauss | 81:3656f00ab3db | 898 | wdt_timer.reset(); |
klauss | 81:3656f00ab3db | 899 | |
klauss | 81:3656f00ab3db | 900 | if( wdt_show ) debug_wdt = true; |
klauss | 81:3656f00ab3db | 901 | |
klauss | 81:3656f00ab3db | 902 | if( external_wdt ) external_wdt--; |
klauss | 81:3656f00ab3db | 903 | if( pkg_wdt ) pkg_wdt--; |
klauss | 81:3656f00ab3db | 904 | if( eth_wdt ) eth_wdt--; |
klauss | 81:3656f00ab3db | 905 | |
klauss | 89:0fe315117b00 | 906 | if( ( eth_wdt && external_wdt && pkg_wdt ) || force_alive ){ |
klauss | 81:3656f00ab3db | 907 | wdt.kick(); |
klauss | 81:3656f00ab3db | 908 | } |
klauss | 81:3656f00ab3db | 909 | } |
klauss | 81:3656f00ab3db | 910 | |
klauss | 81:3656f00ab3db | 911 | if( debug_wdt ){ |
klauss | 87:679ee0d594a9 | 912 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 913 | lpc_low_level_input_counter = 0; |
klauss | 85:b6f2dc1d0f4f | 914 | |
klauss | 81:3656f00ab3db | 915 | debug_wdt = false; |
klauss | 81:3656f00ab3db | 916 | if( eth_status == 0 ){ |
klauss | 82:f55d13babca0 | 917 | send_msg( "Wdt last reset: %s - status_eth :: Connected - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )", |
klauss | 81:3656f00ab3db | 918 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 81:3656f00ab3db | 919 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 82:f55d13babca0 | 920 | EXTERN_WDT_IDLE, |
klauss | 82:f55d13babca0 | 921 | RX_CB_IDLE - pkg_wdt, |
klauss | 82:f55d13babca0 | 922 | RX_CB_IDLE |
klauss | 81:3656f00ab3db | 923 | ); |
klauss | 81:3656f00ab3db | 924 | }else{ |
klauss | 82:f55d13babca0 | 925 | send_msg( "Wdt last reset: %s - status_eth :: Disconnected :: since %3d sec - Extern Wdt idle for :: %3d sec ( %3d ) - Rx from CBx idle for :: %3d sec ( %3d )", |
klauss | 81:3656f00ab3db | 926 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 81:3656f00ab3db | 927 | ETH_CONNECT_TIMEOUT - eth_wdt, |
klauss | 82:f55d13babca0 | 928 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 82:f55d13babca0 | 929 | EXTERN_WDT_IDLE, |
klauss | 82:f55d13babca0 | 930 | RX_CB_IDLE - pkg_wdt, |
klauss | 82:f55d13babca0 | 931 | RX_CB_IDLE |
klauss | 81:3656f00ab3db | 932 | ); |
klauss | 81:3656f00ab3db | 933 | } |
klauss | 81:3656f00ab3db | 934 | } |
klauss | 86:bf7b0d4c3232 | 935 | /* |
klauss | 86:bf7b0d4c3232 | 936 | { |
klauss | 86:bf7b0d4c3232 | 937 | char eth_msg[ ETH_MSG_SIZE ]; |
klauss | 86:bf7b0d4c3232 | 938 | for( register int i = 0; i < NUM_SOCK; i++ ) |
klauss | 86:bf7b0d4c3232 | 939 | { |
klauss | 86:bf7b0d4c3232 | 940 | int rcv = sock[ i ].receiveFrom( server[ i ], eth_msg, sizeof ( eth_msg ) ); |
klauss | 86:bf7b0d4c3232 | 941 | if( rcv > 0 ) |
klauss | 86:bf7b0d4c3232 | 942 | { |
klauss | 86:bf7b0d4c3232 | 943 | int sent = sock[ i ].sendTo( server[ i ], eth_msg, rcv ); |
klauss | 86:bf7b0d4c3232 | 944 | |
klauss | 86:bf7b0d4c3232 | 945 | if( sent < 0 ) send_msg("Sent -1"); |
klauss | 86:bf7b0d4c3232 | 946 | } |
klauss | 86:bf7b0d4c3232 | 947 | } |
klauss | 86:bf7b0d4c3232 | 948 | } |
klauss | 86:bf7b0d4c3232 | 949 | */ |
klauss | 0:4d17cd9c8f9d | 950 | } |
klauss | 0:4d17cd9c8f9d | 951 | } |