![](/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@105:a930035b6556, 2015-03-10 (annotated)
- Committer:
- klauss
- Date:
- Tue Mar 10 18:10:57 2015 +0000
- Revision:
- 105:a930035b6556
- Parent:
- 104:62646ef786a3
- Child:
- 106:a34fcf9f0e02
sprint 0;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 105:a930035b6556 | 1 | #include "main_includes.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 105:a930035b6556 | 3 | // Contador low-level de pacotes recebifos na interface eth da embarcada, extern de lpc17_emac.c |
klauss | 87:679ee0d594a9 | 4 | volatile u16_t lpc_low_level_input_counter = 0; |
klauss | 85:b6f2dc1d0f4f | 5 | |
klauss | 91:c2a86b1f8aaa | 6 | int main() |
klauss | 91:c2a86b1f8aaa | 7 | { |
klauss | 105:a930035b6556 | 8 | // configura e inicia o wdt |
klauss | 81:3656f00ab3db | 9 | init_wdt(); |
klauss | 91:c2a86b1f8aaa | 10 | |
klauss | 105:a930035b6556 | 11 | // configs de sistema, irqs, I/O bounds |
klauss | 81:3656f00ab3db | 12 | config_lpc(); |
klauss | 91:c2a86b1f8aaa | 13 | |
klauss | 105:a930035b6556 | 14 | // inicializa a comunicacao com a laser |
klauss | 0:4d17cd9c8f9d | 15 | start_cpld(); |
klauss | 91:c2a86b1f8aaa | 16 | |
klauss | 105:a930035b6556 | 17 | // habilita a impressao de caracteres na interface UART3 |
klauss | 100:09a23fcd3bdf | 18 | debug_uart3 = true; |
klauss | 105:a930035b6556 | 19 | |
klauss | 105:a930035b6556 | 20 | // rotina de verificacao do uso do sistema de memoria |
klauss | 91:c2a86b1f8aaa | 21 | if( sdram_init() == 1 ) { |
klauss | 105:a930035b6556 | 22 | pc.printf("\r\n******* Failed to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 23 | return 1; |
klauss | 89:0fe315117b00 | 24 | } else { |
klauss | 105:a930035b6556 | 25 | pc.printf("\r\n******* Success to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 26 | } |
klauss | 91:c2a86b1f8aaa | 27 | |
klauss | 105:a930035b6556 | 28 | // inicializa o sistema de arquivo para uso |
klauss | 43:455522f98de5 | 29 | init_fsystem(); |
klauss | 91:c2a86b1f8aaa | 30 | |
klauss | 105:a930035b6556 | 31 | // exibe endereco MAC da lpc |
klauss | 89:0fe315117b00 | 32 | { |
klauss | 89:0fe315117b00 | 33 | char s[ 32 ]; |
klauss | 89:0fe315117b00 | 34 | mbed_mac_address( s ); |
klauss | 105:a930035b6556 | 35 | pc.printf( "\r\n******* ::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: *******", s[0],s[1],s[2],s[3],s[4],s[5] ); |
klauss | 89:0fe315117b00 | 36 | } |
klauss | 91:c2a86b1f8aaa | 37 | |
klauss | 105:a930035b6556 | 38 | // rotina de inicializacao da interface ETH |
klauss | 78:1353744f01e1 | 39 | short int eth_status = __init_eth__(); |
klauss | 91:c2a86b1f8aaa | 40 | if( eth_status ) { |
klauss | 105:a930035b6556 | 41 | pc.printf("\r\n******* Cannot connect to eth *******\r\n"); |
klauss | 91:c2a86b1f8aaa | 42 | } else { |
klauss | 105:a930035b6556 | 43 | pc.printf("\r\n******* Connection eth - ok *******"); |
klauss | 78:1353744f01e1 | 44 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 45 | init_external_wdt() |
klauss | 8:e3bfe62a477e | 46 | } |
klauss | 91:c2a86b1f8aaa | 47 | |
klauss | 105:a930035b6556 | 48 | // sync_timer : usado para sincronizar eventos a cada x unidades de tempo, usualmente em debugs |
klauss | 105:a930035b6556 | 49 | // led_sync_timer : usado para controlar a taxa de toggle do led de debug |
klauss | 78:1353744f01e1 | 50 | Timer sync_timer, led_sync_timer; |
klauss | 105:a930035b6556 | 51 | |
klauss | 105:a930035b6556 | 52 | sync_timer.start(); |
klauss | 105:a930035b6556 | 53 | led_sync_timer.start(); |
klauss | 91:c2a86b1f8aaa | 54 | |
klauss | 105:a930035b6556 | 55 | // representa ramal do call box |
klauss | 0:4d17cd9c8f9d | 56 | int ext = 0; |
klauss | 91:c2a86b1f8aaa | 57 | |
klauss | 105:a930035b6556 | 58 | // representa porta do call box |
klauss | 78:1353744f01e1 | 59 | int port = 0; |
klauss | 91:c2a86b1f8aaa | 60 | |
klauss | 105:a930035b6556 | 61 | // buffer para onde se copia os dados vindos do cb para tratameno interno |
klauss | 105:a930035b6556 | 62 | uint8_t buffer[ CB_BUFFER_SIZE ]; |
klauss | 91:c2a86b1f8aaa | 63 | |
klauss | 105:a930035b6556 | 64 | // buffer de escrita do pacote de saida que sera enviado pro cb / servidor |
klauss | 105:a930035b6556 | 65 | uint8_t write_buffer[ CB_BUFFER_SIZE ]; |
klauss | 91:c2a86b1f8aaa | 66 | |
klauss | 105:a930035b6556 | 67 | // ponteiro que aponta para os dados vindo do CPLD |
klauss | 0:4d17cd9c8f9d | 68 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 91:c2a86b1f8aaa | 69 | |
klauss | 105:a930035b6556 | 70 | // Armazena o ultimo pacote recebido dos CBx |
klauss | 105:a930035b6556 | 71 | uint8_t cb_rx_buffer[ CB_BUFFER_SIZE ]; |
klauss | 91:c2a86b1f8aaa | 72 | |
klauss | 105:a930035b6556 | 73 | // referencia para os dados contidos no pacote, sem o header |
klauss | 0:4d17cd9c8f9d | 74 | uint8_t * data = NULL; |
klauss | 91:c2a86b1f8aaa | 75 | |
klauss | 105:a930035b6556 | 76 | // gerencia o tipo do pacote para providenciar tratamento adequado |
klauss | 0:4d17cd9c8f9d | 77 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 91:c2a86b1f8aaa | 78 | |
klauss | 105:a930035b6556 | 79 | // representa a lista dos Call Boxes atualmente recfonhecidos pela cabeceira |
klauss | 0:4d17cd9c8f9d | 80 | Vector * v_cb = new Vector(); |
klauss | 91:c2a86b1f8aaa | 81 | |
klauss | 105:a930035b6556 | 82 | // representa a lista de ligacoes ativas na cabeceira |
klauss | 0:4d17cd9c8f9d | 83 | Vector * v_call = new Vector(); |
klauss | 91:c2a86b1f8aaa | 84 | |
klauss | 105:a930035b6556 | 85 | // gerencia a distribuicao de timeslice para os call boxes |
klauss | 0:4d17cd9c8f9d | 86 | Timeslice * ts = new Timeslice(); |
klauss | 91:c2a86b1f8aaa | 87 | if( ts == NULL ) { |
klauss | 89:0fe315117b00 | 88 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 89 | if( debug_memory ) debug_msg("TS allocation fail"); |
klauss | 89:0fe315117b00 | 90 | } |
klauss | 91:c2a86b1f8aaa | 91 | |
klauss | 105:a930035b6556 | 92 | // aloca o vetor de call boxes |
klauss | 91:c2a86b1f8aaa | 93 | if( v_cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 94 | while( v_cb == NULL ) { |
klauss | 0:4d17cd9c8f9d | 95 | Vector * v_cb = new Vector(); |
klauss | 91:c2a86b1f8aaa | 96 | if( sync_timer.read() > 5 ) { |
klauss | 48:195c97f12e8e | 97 | send_msg("Erro ao alocar o vetor de CBx"); |
klauss | 78:1353744f01e1 | 98 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 99 | } |
klauss | 0:4d17cd9c8f9d | 100 | } |
klauss | 105:a930035b6556 | 101 | } |
klauss | 105:a930035b6556 | 102 | |
klauss | 105:a930035b6556 | 103 | // aloca o vetor de calls |
klauss | 105:a930035b6556 | 104 | if( v_call == NULL ) { |
klauss | 91:c2a86b1f8aaa | 105 | while( v_call == NULL ) { |
klauss | 0:4d17cd9c8f9d | 106 | Vector * v_call = new Vector(); |
klauss | 91:c2a86b1f8aaa | 107 | if( sync_timer.read() > 5 ) { |
klauss | 48:195c97f12e8e | 108 | send_msg("Erro ao alocar o vetor de Calls"); |
klauss | 78:1353744f01e1 | 109 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 110 | } |
klauss | 0:4d17cd9c8f9d | 111 | } |
klauss | 0:4d17cd9c8f9d | 112 | } |
klauss | 91:c2a86b1f8aaa | 113 | |
klauss | 91:c2a86b1f8aaa | 114 | if( v_cb == NULL ) { |
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 | 91:c2a86b1f8aaa | 118 | |
klauss | 91:c2a86b1f8aaa | 119 | if( v_call == NULL ) { |
klauss | 89:0fe315117b00 | 120 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 121 | if( debug_memory ) debug_msg("Call vector allocation fail"); |
klauss | 89:0fe315117b00 | 122 | } |
klauss | 91:c2a86b1f8aaa | 123 | |
klauss | 105:a930035b6556 | 124 | // inicializa buffers de armazenamento temporario de I/O com o CBx |
klauss | 105:a930035b6556 | 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 | 91:c2a86b1f8aaa | 129 | |
klauss | 105:a930035b6556 | 130 | // apagar os leds do lpc |
klauss | 0:4d17cd9c8f9d | 131 | reset_leds(); |
klauss | 91:c2a86b1f8aaa | 132 | |
klauss | 105:a930035b6556 | 133 | //FIXME remover caso compravado desuso |
klauss | 33:735fd60e96d8 | 134 | udp_timer.start(); |
klauss | 99:e80850c51106 | 135 | |
klauss | 105:a930035b6556 | 136 | // inicializa o sistema para envio de pacotes do tipo __FW?__ e __TELEMETRY__ para servidor ( ip, porta ) previamente configurado. |
klauss | 99:e80850c51106 | 137 | init_fw_handler(); |
klauss | 99:e80850c51106 | 138 | |
klauss | 99:e80850c51106 | 139 | led2 = 0; |
klauss | 105:a930035b6556 | 140 | |
klauss | 105:a930035b6556 | 141 | // le do sistema de arquivos valores previamente configurados de primeiro e ultimo ramal de um determinado ramo. |
klauss | 81:3656f00ab3db | 142 | init_ranges(); |
klauss | 105:a930035b6556 | 143 | |
klauss | 105:a930035b6556 | 144 | // inicializa o timer de refresh dos cbx |
klauss | 80:61d61c9eb75c | 145 | init_refresh(); |
klauss | 91:c2a86b1f8aaa | 146 | |
klauss | 105:a930035b6556 | 147 | // inicializa o time de envelhecimento do CBx |
klauss | 78:1353744f01e1 | 148 | init_aging(); |
klauss | 91:c2a86b1f8aaa | 149 | |
klauss | 105:a930035b6556 | 150 | // inicislizs o yimrt para sincronizar as rotinas de wake_all_up e refresh |
klauss | 89:0fe315117b00 | 151 | init_sync_refresh(); |
klauss | 91:c2a86b1f8aaa | 152 | |
klauss | 105:a930035b6556 | 153 | // usada para delay na ativacao de algumas funcoes, wake_all_up e tentativa de eth reconnect |
klauss | 62:07e5bdc9f8f7 | 154 | static uint8_t count = 0; |
klauss | 91:c2a86b1f8aaa | 155 | |
klauss | 105:a930035b6556 | 156 | // contador usado para indicar quantos cbx foram registrados na logica |
klauss | 78:1353744f01e1 | 157 | uint8_t max_registered_cbx = 0; |
klauss | 91:c2a86b1f8aaa | 158 | |
klauss | 105:a930035b6556 | 159 | // inicia dizendo que a rotina nao deve rodar agora ( 35 sec. nas versoes originais ) |
klauss | 81:3656f00ab3db | 160 | bool wake_all = false; |
klauss | 91:c2a86b1f8aaa | 161 | |
klauss | 105:a930035b6556 | 162 | // inico das variaveis controladoras do extern wdt |
klauss | 105:a930035b6556 | 163 | |
klauss | 105:a930035b6556 | 164 | // atribui valor maximo ao countdown que verifica comunicao com os CBx |
klauss | 81:3656f00ab3db | 165 | uint16_t pkg_wdt = RX_CB_IDLE; |
klauss | 105:a930035b6556 | 166 | |
klauss | 105:a930035b6556 | 167 | // atribi falor maximo ao countdown que verifica conexao eth |
klauss | 81:3656f00ab3db | 168 | uint16_t eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 105:a930035b6556 | 169 | |
klauss | 105:a930035b6556 | 170 | // inicializa o contador de uptime da header |
klauss | 83:b8a1d8fdeaeb | 171 | uint32_t uptime = 0; |
klauss | 105:a930035b6556 | 172 | |
klauss | 99:e80850c51106 | 173 | led1 = 0; |
klauss | 104:62646ef786a3 | 174 | |
klauss | 105:a930035b6556 | 175 | send_msg("\r\nReady"); |
klauss | 92:92df17f538a8 | 176 | |
klauss | 105:a930035b6556 | 177 | // inicializa o timer de retry dos pacotes de invite, necessario para o comportamento "metralhadora" da header. |
klauss | 99:e80850c51106 | 178 | Timer invite_retry_timer; |
klauss | 99:e80850c51106 | 179 | invite_retry_timer.start(); |
klauss | 105:a930035b6556 | 180 | |
klauss | 105:a930035b6556 | 181 | // desabilita a impressao de caracteres na interface UART3 |
klauss | 105:a930035b6556 | 182 | //debug_uart3 = false; |
klauss | 91:c2a86b1f8aaa | 183 | |
klauss | 78:1353744f01e1 | 184 | /*------------------------------------------ main loop ---------------------------------------------------------------*/ |
klauss | 91:c2a86b1f8aaa | 185 | while( true ) { |
klauss | 99:e80850c51106 | 186 | reset_leds(); |
klauss | 105:a930035b6556 | 187 | |
klauss | 105:a930035b6556 | 188 | // inicializa o loop afirmando que nao existe comando externo para ser processado pelo prompt. |
klauss | 105:a930035b6556 | 189 | udp_query = false; |
klauss | 105:a930035b6556 | 190 | from_eth = false; |
klauss | 105:a930035b6556 | 191 | |
klauss | 105:a930035b6556 | 192 | // chama rotina de processamento de entrada serial para o prompt |
klauss | 105:a930035b6556 | 193 | prompt_process( NULL, 0 ); |
klauss | 99:e80850c51106 | 194 | |
klauss | 105:a930035b6556 | 195 | //begin verificacao e tratamento dos pacotes recebidos via UDP-ETH |
klauss | 105:a930035b6556 | 196 | { |
klauss | 105:a930035b6556 | 197 | fd_set fdSet; |
klauss | 105:a930035b6556 | 198 | FD_ZERO(&fdSet); |
klauss | 105:a930035b6556 | 199 | |
klauss | 105:a930035b6556 | 200 | // coloca o socket SIP de todos os CBx |
klauss | 105:a930035b6556 | 201 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 105:a930035b6556 | 202 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 105:a930035b6556 | 203 | FD_SET( cb->get_sip_socket_fd(), &fdSet ); |
klauss | 105:a930035b6556 | 204 | } |
klauss | 105:a930035b6556 | 205 | |
klauss | 105:a930035b6556 | 206 | // adiciona o socket do watchdog |
klauss | 105:a930035b6556 | 207 | FD_SET( udp_wdt_client.get_fd(), &fdSet ); |
klauss | 105:a930035b6556 | 208 | |
klauss | 105:a930035b6556 | 209 | // adiciona o socket de comandos prompt-UDP-ETH |
klauss | 105:a930035b6556 | 210 | FD_SET( udp_client.get_fd(), &fdSet ); |
klauss | 105:a930035b6556 | 211 | |
klauss | 105:a930035b6556 | 212 | struct timeval t; |
klauss | 105:a930035b6556 | 213 | t.tv_sec = 0; |
klauss | 105:a930035b6556 | 214 | t.tv_usec = 0; |
klauss | 105:a930035b6556 | 215 | // verifica se existe algo pendente para ser tratado |
klauss | 105:a930035b6556 | 216 | int ret = lwip_select( FD_SETSIZE, &fdSet, NULL, NULL, &t ); |
klauss | 105:a930035b6556 | 217 | |
klauss | 105:a930035b6556 | 218 | if(ret > 0 ) { |
klauss | 105:a930035b6556 | 219 | // existe algo na fila UDP pendente. |
klauss | 105:a930035b6556 | 220 | // verigica o socket SIP de cada CBx |
klauss | 105:a930035b6556 | 221 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 105:a930035b6556 | 222 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 105:a930035b6556 | 223 | int fd = cb->get_sip_socket_fd(); |
klauss | 105:a930035b6556 | 224 | if( FD_ISSET( fd, &fdSet ) ) { |
klauss | 105:a930035b6556 | 225 | int rcv = cb->sip_udp_incomming_pkg(); |
klauss | 105:a930035b6556 | 226 | } |
klauss | 105:a930035b6556 | 227 | } |
klauss | 105:a930035b6556 | 228 | |
klauss | 105:a930035b6556 | 229 | // verifica o socket do prompt-UDP-ETH |
klauss | 105:a930035b6556 | 230 | if( FD_ISSET( udp_client.get_fd(), &fdSet ) ) { |
klauss | 105:a930035b6556 | 231 | char to_prompt_process[ PROMPT_UDP_COMMAND_SIZE ]; |
klauss | 105:a930035b6556 | 232 | //for( register int i = 0; i < PROMPT_UDP_COMMAND_SIZE; i++ ) to_prompt_process[ i ] = 0; |
klauss | 105:a930035b6556 | 233 | |
klauss | 105:a930035b6556 | 234 | int prompt_process_msg_rcv = udp_client.receiveFrom( udp_server, to_prompt_process, ( sizeof( to_prompt_process ) - 1 ) ); |
klauss | 105:a930035b6556 | 235 | |
klauss | 105:a930035b6556 | 236 | to_prompt_process[ prompt_process_msg_rcv ] = 0; |
klauss | 105:a930035b6556 | 237 | if( prompt_process_msg_rcv == -1 ) |
klauss | 105:a930035b6556 | 238 | { |
klauss | 105:a930035b6556 | 239 | if( debug_reconnect ) send_msg("Reconnect Prompt Process"); |
klauss | 105:a930035b6556 | 240 | reconnect_udp_prompt_process(); |
klauss | 105:a930035b6556 | 241 | miss_prompt_udp_rcv_pkg++; |
klauss | 105:a930035b6556 | 242 | } |
klauss | 105:a930035b6556 | 243 | else if( prompt_process_msg_rcv > 0 ) |
klauss | 105:a930035b6556 | 244 | { |
klauss | 105:a930035b6556 | 245 | udp_query = true; |
klauss | 105:a930035b6556 | 246 | prompt_process( to_prompt_process, prompt_process_msg_rcv ); |
klauss | 105:a930035b6556 | 247 | } |
klauss | 105:a930035b6556 | 248 | } |
klauss | 105:a930035b6556 | 249 | |
klauss | 105:a930035b6556 | 250 | // verifica o socket do watchdog |
klauss | 105:a930035b6556 | 251 | if( FD_ISSET( udp_wdt_client.get_fd(), &fdSet ) ) { |
klauss | 105:a930035b6556 | 252 | char wake_msg[ 768 ]; |
klauss | 105:a930035b6556 | 253 | Endpoint udp_wdt_server; |
klauss | 105:a930035b6556 | 254 | |
klauss | 105:a930035b6556 | 255 | int wake_msg_rcv = udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ); |
klauss | 105:a930035b6556 | 256 | |
klauss | 105:a930035b6556 | 257 | if( wake_msg_rcv == -1 ) |
klauss | 105:a930035b6556 | 258 | { |
klauss | 105:a930035b6556 | 259 | if( debug_reconnect ) send_msg("Reconnect Extern wdt"); |
klauss | 105:a930035b6556 | 260 | reconnect_extern_wdt_socket(); |
klauss | 105:a930035b6556 | 261 | miss_wdt_send_pkg++; |
klauss | 105:a930035b6556 | 262 | } |
klauss | 105:a930035b6556 | 263 | else if( wake_msg_rcv > 0 ) |
klauss | 105:a930035b6556 | 264 | { |
klauss | 105:a930035b6556 | 265 | if( !( strncmp( wake_msg, "alive", 5 ) ) ) { |
klauss | 105:a930035b6556 | 266 | // Just ckeck but not set 'alive?' |
klauss | 105:a930035b6556 | 267 | // 'alive*' - force wdt tick right now |
klauss | 105:a930035b6556 | 268 | // Ckecking and set 'alive' |
klauss | 105:a930035b6556 | 269 | bool question_alive = ( wake_msg[ 5 ] == '?' ); |
klauss | 105:a930035b6556 | 270 | if( wake_msg[ 5 ] == '*' ) wdt.kick(); |
klauss | 105:a930035b6556 | 271 | |
klauss | 105:a930035b6556 | 272 | snprintf( wake_msg, 48,"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u:", |
klauss | 105:a930035b6556 | 273 | uptime, |
klauss | 105:a930035b6556 | 274 | invite_counter, |
klauss | 105:a930035b6556 | 275 | external_wdt, |
klauss | 105:a930035b6556 | 276 | ( wdt.WatchdogCausedReset() ) ? '1' : '0', |
klauss | 105:a930035b6556 | 277 | cb_new_counter, |
klauss | 105:a930035b6556 | 278 | v_cb->size(), |
klauss | 105:a930035b6556 | 279 | ts->remain_timeslices(), |
klauss | 105:a930035b6556 | 280 | sip_socket_send_failure, |
klauss | 105:a930035b6556 | 281 | v_call->size() |
klauss | 105:a930035b6556 | 282 | ); |
klauss | 105:a930035b6556 | 283 | wake_msg[ 768 - 1 ] = 0; |
klauss | 105:a930035b6556 | 284 | int send = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 105:a930035b6556 | 285 | if( send != strlen( wake_msg ) ) |
klauss | 105:a930035b6556 | 286 | { |
klauss | 105:a930035b6556 | 287 | if( debug_reconnect ) debug_msg("Reconnect Extern wdt (%d, %d)", send, strlen( wake_msg ) ); |
klauss | 105:a930035b6556 | 288 | reconnect_extern_wdt_socket(); |
klauss | 105:a930035b6556 | 289 | miss_wdt_send_pkg++; |
klauss | 105:a930035b6556 | 290 | } |
klauss | 105:a930035b6556 | 291 | |
klauss | 105:a930035b6556 | 292 | if( ( (!question_alive) && ( cb_new_counter <= __MAX_CB_IN_A_BRANCH__ ) && ( cb_new_counter >= 2 ) ) ) { |
klauss | 105:a930035b6556 | 293 | external_wdt = EXTERN_WDT_IDLE; |
klauss | 105:a930035b6556 | 294 | } |
klauss | 105:a930035b6556 | 295 | } else if( !( strncmp( wake_msg, "reset", 5 ) ) ) { |
klauss | 105:a930035b6556 | 296 | external_wdt = 0; |
klauss | 105:a930035b6556 | 297 | |
klauss | 105:a930035b6556 | 298 | sprintf( wake_msg, "rst:%u:", uptime ); |
klauss | 105:a930035b6556 | 299 | int send = udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 105:a930035b6556 | 300 | if( send != strlen( wake_msg ) ) |
klauss | 105:a930035b6556 | 301 | { |
klauss | 105:a930035b6556 | 302 | if( debug_reconnect ) send_msg("Reconnect Extern wdt"); |
klauss | 105:a930035b6556 | 303 | reconnect_extern_wdt_socket(); |
klauss | 105:a930035b6556 | 304 | miss_wdt_send_pkg++; |
klauss | 105:a930035b6556 | 305 | } |
klauss | 105:a930035b6556 | 306 | } |
klauss | 105:a930035b6556 | 307 | } |
klauss | 105:a930035b6556 | 308 | } |
klauss | 105:a930035b6556 | 309 | } |
klauss | 105:a930035b6556 | 310 | }//end verificacao e tratamento dos pacotes recebidos via UDP-ETH |
klauss | 105:a930035b6556 | 311 | |
klauss | 105:a930035b6556 | 312 | // atualiza o valor do contador max_registered_cbx |
klauss | 78:1353744f01e1 | 313 | if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 314 | |
klauss | 105:a930035b6556 | 315 | // executa a cada 5 segundos comandos e verificacoes ( principalmente debugs ) |
klauss | 91:c2a86b1f8aaa | 316 | if( sync_timer.read() > 5 ) { |
klauss | 78:1353744f01e1 | 317 | sync_timer.reset(); |
klauss | 105:a930035b6556 | 318 | |
klauss | 105:a930035b6556 | 319 | // atualiza valor da variavel de delay |
klauss | 105:a930035b6556 | 320 | count++; |
klauss | 91:c2a86b1f8aaa | 321 | |
klauss | 105:a930035b6556 | 322 | // enable na variavel que exibe estatisticas de cks dos pacotes recebidos pela header |
klauss | 91:c2a86b1f8aaa | 323 | if( debug_cks == true ) { |
klauss | 81:3656f00ab3db | 324 | pcks_s = true; |
klauss | 78:1353744f01e1 | 325 | } |
klauss | 91:c2a86b1f8aaa | 326 | |
klauss | 105:a930035b6556 | 327 | // enable na variavel que exibe uma lista ( por ordem de pedido de registro ) dos cbx |
klauss | 91:c2a86b1f8aaa | 328 | if( debug_alive == true ) { |
klauss | 81:3656f00ab3db | 329 | pshowcb = true; |
klauss | 78:1353744f01e1 | 330 | } |
klauss | 100:09a23fcd3bdf | 331 | |
klauss | 105:a930035b6556 | 332 | // enable na variavel que exibe lista com estatisticas de pacotes que falharam ao serem enviados via interface eth |
klauss | 105:a930035b6556 | 333 | if( debug_missed ) |
klauss | 105:a930035b6556 | 334 | { |
klauss | 105:a930035b6556 | 335 | missed_send_udp_pkg = true; |
klauss | 105:a930035b6556 | 336 | } |
klauss | 105:a930035b6556 | 337 | |
klauss | 105:a930035b6556 | 338 | // verifica status da conexao eth, em caso de falha na inicializacao anterior, tenta conectar periodicamente a cada 75 sec. |
klauss | 105:a930035b6556 | 339 | // nas implementacoes inicias |
klauss | 105:a930035b6556 | 340 | if( !( count % 15 ) ) { |
klauss | 91:c2a86b1f8aaa | 341 | if( eth_status ) { |
klauss | 78:1353744f01e1 | 342 | eth_status = __init_eth__(); |
klauss | 91:c2a86b1f8aaa | 343 | if( eth_status ) { |
klauss | 105:a930035b6556 | 344 | if( debug_main ) pc.printf("\r\nCannot connect to eth\r\n"); |
klauss | 91:c2a86b1f8aaa | 345 | } else { |
klauss | 105:a930035b6556 | 346 | if( debug_main ) pc.printf("\r\nConnection eth - ok"); |
klauss | 78:1353744f01e1 | 347 | init_prompt_eth(); |
klauss | 82:f55d13babca0 | 348 | init_external_wdt() |
klauss | 78:1353744f01e1 | 349 | } |
klauss | 78:1353744f01e1 | 350 | } |
klauss | 78:1353744f01e1 | 351 | } |
klauss | 100:09a23fcd3bdf | 352 | |
klauss | 105:a930035b6556 | 353 | // inicializa rotina de verificacao de "pares" de CBx apos 35 sec. nas implementacoes iniciais |
klauss | 91:c2a86b1f8aaa | 354 | if( ( count > 7 ) && ( wake_all == false ) ) { |
klauss | 81:3656f00ab3db | 355 | wake_all = true; |
klauss | 78:1353744f01e1 | 356 | if( debug_wake == true ) send_msg( "Time to wake" ); |
klauss | 78:1353744f01e1 | 357 | } |
klauss | 78:1353744f01e1 | 358 | } |
klauss | 91:c2a86b1f8aaa | 359 | |
klauss | 105:a930035b6556 | 360 | // zera os contadores de pacotes recebidos na interface CBx->Header |
klauss | 91:c2a86b1f8aaa | 361 | if( r_stats ) { |
klauss | 91:c2a86b1f8aaa | 362 | boot_counter = 0; |
klauss | 91:c2a86b1f8aaa | 363 | registry_counter = 0; |
klauss | 91:c2a86b1f8aaa | 364 | invite_counter = 0; |
klauss | 91:c2a86b1f8aaa | 365 | audio_counter = 0; |
klauss | 91:c2a86b1f8aaa | 366 | telemetry_counter = 0; |
klauss | 91:c2a86b1f8aaa | 367 | cb_bye_counter = 0; |
klauss | 91:c2a86b1f8aaa | 368 | prompt_counter = 0; |
klauss | 91:c2a86b1f8aaa | 369 | flood_counter = 0; |
klauss | 67:cdedc64d9921 | 370 | bootloader_cbx_counter = 0; |
klauss | 99:e80850c51106 | 371 | cb_stats_counter = 0; |
klauss | 105:a930035b6556 | 372 | fw_counter = 0; |
klauss | 63:0d95da692bb4 | 373 | r_stats = false; |
klauss | 63:0d95da692bb4 | 374 | stats = true; |
klauss | 63:0d95da692bb4 | 375 | } |
klauss | 91:c2a86b1f8aaa | 376 | |
klauss | 105:a930035b6556 | 377 | // exibe o valor dos contadores de pacotes recebidos na interfacao CBx->ETH |
klauss | 91:c2a86b1f8aaa | 378 | if( stats ) { |
klauss | 63:0d95da692bb4 | 379 | char str[ 200 ]; |
klauss | 105:a930035b6556 | 380 | snprintf( str, 200, "\n\r Received Pkgs ::\n\r Boot :: %u\n\r Registry :: %u\n\r Invite :: %u\n\r Audio :: %u\n\r Telemetry :: %u\n\r CB_stats :: %u\n\r CB_bye :: %u\n\r Prompt :: %u\n\r Flood :: %u\n\r Bootloader_cbx :: %u\n\r Fw :: %u\n\r", |
klauss | 105:a930035b6556 | 381 | boot_counter, registry_counter, invite_counter, audio_counter, telemetry_counter, cb_stats_counter, cb_bye_counter, prompt_counter, flood_counter, bootloader_cbx_counter, fw_counter ); |
klauss | 63:0d95da692bb4 | 382 | send_msg( str ); |
klauss | 63:0d95da692bb4 | 383 | stats =false; |
klauss | 63:0d95da692bb4 | 384 | } |
klauss | 91:c2a86b1f8aaa | 385 | |
klauss | 105:a930035b6556 | 386 | // exibe uma lista ( em ordem crescente e por ramais ) dos cbx que ja se registraram ao menos uma vez |
klauss | 91:c2a86b1f8aaa | 387 | if( list ) { |
klauss | 78:1353744f01e1 | 388 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 389 | |
klauss | 78:1353744f01e1 | 390 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 391 | |
klauss | 78:1353744f01e1 | 392 | if( min_ext % 2 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 393 | |
klauss | 78:1353744f01e1 | 394 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 91:c2a86b1f8aaa | 395 | |
klauss | 78:1353744f01e1 | 396 | 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 | 91:c2a86b1f8aaa | 397 | if( v_cb->size() == 1 ) { |
klauss | 78:1353744f01e1 | 398 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 91:c2a86b1f8aaa | 399 | } else if( v_cb->size() > 1 ) { |
klauss | 62:07e5bdc9f8f7 | 400 | char str[ 1024 ]; |
klauss | 78:1353744f01e1 | 401 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 62:07e5bdc9f8f7 | 402 | register int i = 0; |
klauss | 91:c2a86b1f8aaa | 403 | for( ; i < v_cb->size(); i++ ) { |
klauss | 78:1353744f01e1 | 404 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 62:07e5bdc9f8f7 | 405 | } |
klauss | 91:c2a86b1f8aaa | 406 | |
klauss | 62:07e5bdc9f8f7 | 407 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 91:c2a86b1f8aaa | 408 | |
klauss | 62:07e5bdc9f8f7 | 409 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 410 | strcpy( str, "\r\n> " ); |
klauss | 91:c2a86b1f8aaa | 411 | for( i = 0; i < v_cb->size() - 1; i++ ) { |
klauss | 62:07e5bdc9f8f7 | 412 | sprintf( aux, "%i, ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 413 | strcat( str, aux ); |
klauss | 78:1353744f01e1 | 414 | if( ( i != 0 ) && !( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 415 | } |
klauss | 62:07e5bdc9f8f7 | 416 | sprintf( aux, "%i ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 417 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 418 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 419 | } |
klauss | 91:c2a86b1f8aaa | 420 | list = false; |
klauss | 62:07e5bdc9f8f7 | 421 | } |
klauss | 91:c2a86b1f8aaa | 422 | |
klauss | 105:a930035b6556 | 423 | //TODO implementar um showcb ordenado crescentemente por ext e com o timeout pra cada tupla |
klauss | 91:c2a86b1f8aaa | 424 | if( long_list ) { |
klauss | 91:c2a86b1f8aaa | 425 | long_list = false; |
klauss | 52:12930cef17c4 | 426 | } |
klauss | 91:c2a86b1f8aaa | 427 | |
klauss | 105:a930035b6556 | 428 | // exibe uma lista de cbx por ordem de registro contendo status do cbx e do sip vinculado nesse cbx |
klauss | 91:c2a86b1f8aaa | 429 | if( pshowcb == true ) { |
klauss | 78:1353744f01e1 | 430 | 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() ); |
klauss | 91:c2a86b1f8aaa | 431 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 30:8dfb6d8de53d | 432 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 433 | char cb_status[ 32 ]; |
klauss | 78:1353744f01e1 | 434 | char cb_sip_status[ 32 ]; |
klauss | 91:c2a86b1f8aaa | 435 | switch( cb->status ) { |
klauss | 91:c2a86b1f8aaa | 436 | case cb_idle : { |
klauss | 91:c2a86b1f8aaa | 437 | strcpy( cb_status, "cb_idle" ); |
klauss | 91:c2a86b1f8aaa | 438 | break; |
klauss | 91:c2a86b1f8aaa | 439 | } |
klauss | 91:c2a86b1f8aaa | 440 | case cb_ringing : { |
klauss | 91:c2a86b1f8aaa | 441 | strcpy( cb_status, "cb_ringing" ); |
klauss | 91:c2a86b1f8aaa | 442 | break; |
klauss | 91:c2a86b1f8aaa | 443 | } |
klauss | 91:c2a86b1f8aaa | 444 | case cb_trying : { |
klauss | 91:c2a86b1f8aaa | 445 | strcpy( cb_status,"cb_trying" ); |
klauss | 91:c2a86b1f8aaa | 446 | break; |
klauss | 91:c2a86b1f8aaa | 447 | } |
klauss | 91:c2a86b1f8aaa | 448 | case cb_on_call : { |
klauss | 91:c2a86b1f8aaa | 449 | strcpy( cb_status, "cb_on_call" ); |
klauss | 91:c2a86b1f8aaa | 450 | break; |
klauss | 91:c2a86b1f8aaa | 451 | } |
klauss | 91:c2a86b1f8aaa | 452 | case cb_busy : { |
klauss | 91:c2a86b1f8aaa | 453 | strcpy( cb_status, "cb_busy" ); |
klauss | 91:c2a86b1f8aaa | 454 | break; |
klauss | 91:c2a86b1f8aaa | 455 | } |
klauss | 91:c2a86b1f8aaa | 456 | case cb_denied : { |
klauss | 91:c2a86b1f8aaa | 457 | strcpy( cb_status, "cb_denied" ); |
klauss | 91:c2a86b1f8aaa | 458 | break; |
klauss | 91:c2a86b1f8aaa | 459 | } |
klauss | 78:1353744f01e1 | 460 | } |
klauss | 91:c2a86b1f8aaa | 461 | switch( cb->sip->status ) { |
klauss | 91:c2a86b1f8aaa | 462 | case sip_idle : { |
klauss | 91:c2a86b1f8aaa | 463 | strcpy( cb_sip_status, "sip_idle" ); |
klauss | 91:c2a86b1f8aaa | 464 | break; |
klauss | 91:c2a86b1f8aaa | 465 | } |
klauss | 91:c2a86b1f8aaa | 466 | case sip_waiting_trying : { |
klauss | 91:c2a86b1f8aaa | 467 | strcpy( cb_sip_status, "sip_waiting_trying" ); |
klauss | 91:c2a86b1f8aaa | 468 | break; |
klauss | 91:c2a86b1f8aaa | 469 | } |
klauss | 91:c2a86b1f8aaa | 470 | case sip_trying : { |
klauss | 91:c2a86b1f8aaa | 471 | strcpy( cb_sip_status, "sip_trying" ); |
klauss | 91:c2a86b1f8aaa | 472 | break; |
klauss | 91:c2a86b1f8aaa | 473 | } |
klauss | 91:c2a86b1f8aaa | 474 | case sip_ringing : { |
klauss | 91:c2a86b1f8aaa | 475 | strcpy( cb_sip_status, "sip_ringing" ); |
klauss | 91:c2a86b1f8aaa | 476 | break; |
klauss | 91:c2a86b1f8aaa | 477 | } |
klauss | 91:c2a86b1f8aaa | 478 | case sip_busy : { |
klauss | 91:c2a86b1f8aaa | 479 | strcpy( cb_sip_status, "sip_busy" ); |
klauss | 91:c2a86b1f8aaa | 480 | break; |
klauss | 91:c2a86b1f8aaa | 481 | } |
klauss | 91:c2a86b1f8aaa | 482 | case sip_ok : { |
klauss | 91:c2a86b1f8aaa | 483 | strcpy( cb_sip_status, "sip_ok" ); |
klauss | 91:c2a86b1f8aaa | 484 | break; |
klauss | 91:c2a86b1f8aaa | 485 | } |
klauss | 91:c2a86b1f8aaa | 486 | case sip_on_call : { |
klauss | 91:c2a86b1f8aaa | 487 | strcpy( cb_sip_status, "sip_on_call" ); |
klauss | 91:c2a86b1f8aaa | 488 | break; |
klauss | 91:c2a86b1f8aaa | 489 | } |
klauss | 91:c2a86b1f8aaa | 490 | case sip_denied : { |
klauss | 91:c2a86b1f8aaa | 491 | strcpy( cb_sip_status, "sip_denied" ); |
klauss | 91:c2a86b1f8aaa | 492 | break; |
klauss | 91:c2a86b1f8aaa | 493 | } |
klauss | 78:1353744f01e1 | 494 | } |
klauss | 78:1353744f01e1 | 495 | char cbx_to_string[ 254 ]; |
klauss | 78:1353744f01e1 | 496 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 497 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 78:1353744f01e1 | 498 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 98:43b45f26b430 | 499 | strcat( cbx_to_string, aux ); |
klauss | 97:8985817e8847 | 500 | strcat( cbx_to_string, " :: Port :: " ); |
klauss | 97:8985817e8847 | 501 | itoa( cb->get_port(), aux , 10 ); |
klauss | 78:1353744f01e1 | 502 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 503 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 78:1353744f01e1 | 504 | strcat( cbx_to_string, cb_status ); |
klauss | 78:1353744f01e1 | 505 | strcat( cbx_to_string, " - " ); |
klauss | 78:1353744f01e1 | 506 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 91:c2a86b1f8aaa | 507 | if( cb->get_timeslice() != 0 ) { |
klauss | 78:1353744f01e1 | 508 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 78:1353744f01e1 | 509 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 78:1353744f01e1 | 510 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 511 | } |
klauss | 78:1353744f01e1 | 512 | send_msg( cbx_to_string ); |
klauss | 48:195c97f12e8e | 513 | } |
klauss | 78:1353744f01e1 | 514 | pshowcb = false; |
klauss | 48:195c97f12e8e | 515 | } |
klauss | 97:8985817e8847 | 516 | |
klauss | 105:a930035b6556 | 517 | // exibe Ramal e Porta do objeto SIP associado a cada cbx |
klauss | 105:a930035b6556 | 518 | // assim como exibe um timer crescente em segundos, desde o ultimo pacote recebido deste cbx respondendo registro. |
klauss | 97:8985817e8847 | 519 | if( show_sip == true ){ |
klauss | 97:8985817e8847 | 520 | show_sip = false; |
klauss | 99:e80850c51106 | 521 | send_msg(":: Sip :: %u", v_cb->size() ); |
klauss | 97:8985817e8847 | 522 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 97:8985817e8847 | 523 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 99:e80850c51106 | 524 | send_msg("ext :: %d -- port :: %d -- timer %d", cb->get_sip_ext(), cb->get_sip_port(), cb->get_timer() ); |
klauss | 97:8985817e8847 | 525 | } |
klauss | 97:8985817e8847 | 526 | } |
klauss | 91:c2a86b1f8aaa | 527 | |
klauss | 105:a930035b6556 | 528 | // aciona rotina de envio de pacote de flood |
klauss | 81:3656f00ab3db | 529 | if( pflood == true ) flood(); |
klauss | 91:c2a86b1f8aaa | 530 | |
klauss | 105:a930035b6556 | 531 | // exibe status de conexao ETH |
klauss | 91:c2a86b1f8aaa | 532 | if( debug_eth ) { |
klauss | 81:3656f00ab3db | 533 | debug_eth = false; |
klauss | 81:3656f00ab3db | 534 | send_msg("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); |
klauss | 81:3656f00ab3db | 535 | } |
klauss | 91:c2a86b1f8aaa | 536 | |
klauss | 105:a930035b6556 | 537 | // testa se existe um pacote recebido pela interface CBx->Header pendente para ser processado. |
klauss | 91:c2a86b1f8aaa | 538 | if( status != __WAITING__ ) { |
klauss | 81:3656f00ab3db | 539 | pkg_wdt = RX_CB_IDLE; |
klauss | 105:a930035b6556 | 540 | xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, CB_BUFFER_SIZE ); |
klauss | 0:4d17cd9c8f9d | 541 | status = __WAITING__; |
klauss | 81:3656f00ab3db | 542 | missed_pkg--; |
klauss | 105:a930035b6556 | 543 | xmemcpy( buffer, cb_rx_buffer, CB_BUFFER_SIZE ); |
klauss | 91:c2a86b1f8aaa | 544 | |
klauss | 105:a930035b6556 | 545 | // exibe esta pacote caso seja solicitado |
klauss | 105:a930035b6556 | 546 | // TODO implementar um debug que exibe somente, todos os pacotes recebidos |
klauss | 91:c2a86b1f8aaa | 547 | if( rx ) { |
klauss | 81:3656f00ab3db | 548 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 549 | strcpy( str, "RX :: \n\r " ); |
klauss | 105:a930035b6556 | 550 | for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) { |
klauss | 81:3656f00ab3db | 551 | char tmp[ 16 ]; |
klauss | 81:3656f00ab3db | 552 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 81:3656f00ab3db | 553 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 91:c2a86b1f8aaa | 554 | |
klauss | 81:3656f00ab3db | 555 | else strcat( str, " " ); |
klauss | 81:3656f00ab3db | 556 | } |
klauss | 81:3656f00ab3db | 557 | send_msg( "%s", str ); |
klauss | 91:c2a86b1f8aaa | 558 | rx = false; |
klauss | 81:3656f00ab3db | 559 | } |
klauss | 105:a930035b6556 | 560 | |
klauss | 105:a930035b6556 | 561 | // chama rotina para interpretar e validar o pacote recebido |
klauss | 105:a930035b6556 | 562 | data = parse_vz_pkg( &ext, &port, &type, buffer ); |
klauss | 91:c2a86b1f8aaa | 563 | |
klauss | 105:a930035b6556 | 564 | // caso parse_vz_pkg tenha retorno diferente de NULL, trata-se de um pacote valido para ser processado |
klauss | 91:c2a86b1f8aaa | 565 | if( data != NULL ) { |
klauss | 105:a930035b6556 | 566 | // atualiza referencias de menor e maior ramal conhecidos ate o momento |
klauss | 78:1353744f01e1 | 567 | if( min_ext == 0 ) min_ext = ext; |
klauss | 91:c2a86b1f8aaa | 568 | |
klauss | 78:1353744f01e1 | 569 | if( ext > max_ext ) max_ext = ext; |
klauss | 91:c2a86b1f8aaa | 570 | |
klauss | 78:1353744f01e1 | 571 | if( ext < min_ext ) min_ext = ext; |
klauss | 99:e80850c51106 | 572 | |
klauss | 105:a930035b6556 | 573 | // verifica se precisa "exportar" esse pacote para debug externo |
klauss | 99:e80850c51106 | 574 | if( debug_fw ){ |
klauss | 99:e80850c51106 | 575 | fw_cbx_pkg( ext, port, ( char *)buffer ); |
klauss | 99:e80850c51106 | 576 | } |
klauss | 99:e80850c51106 | 577 | |
klauss | 105:a930035b6556 | 578 | // por decisao de projeto, todos os pacote de telemetria sao exportados para parse no servidor |
klauss | 104:62646ef786a3 | 579 | if( type == __TELEMETRY__ ) |
klauss | 104:62646ef786a3 | 580 | { |
klauss | 104:62646ef786a3 | 581 | telemetry_counter++; |
klauss | 104:62646ef786a3 | 582 | //FIXME colocar o dtelos aqui |
klauss | 104:62646ef786a3 | 583 | } |
klauss | 105:a930035b6556 | 584 | |
klauss | 105:a930035b6556 | 585 | // alguns tratamentos adicionais que sao pertinentes em caso de pacotes diferentes do tipo __AUDIO__ |
klauss | 105:a930035b6556 | 586 | if( type != __AUDIO__ ) |
klauss | 105:a930035b6556 | 587 | { |
klauss | 105:a930035b6556 | 588 | // vefifica quais pacotes precisam ser exportados para o servidor e faz a substituicao do typo para __FW__ sem com isso |
klauss | 105:a930035b6556 | 589 | // alterar o pacote de origem. |
klauss | 99:e80850c51106 | 590 | if( |
klauss | 99:e80850c51106 | 591 | type == __TELEMETRY__ || |
klauss | 99:e80850c51106 | 592 | type == __CB_STATS__ || |
klauss | 99:e80850c51106 | 593 | type == __FW1__ || |
klauss | 99:e80850c51106 | 594 | type == __FW2__ || |
klauss | 99:e80850c51106 | 595 | type == __FW3__ || |
klauss | 99:e80850c51106 | 596 | type == __FW4__ || |
klauss | 99:e80850c51106 | 597 | type == __FW5__ || |
klauss | 99:e80850c51106 | 598 | type == __FW6__ |
klauss | 99:e80850c51106 | 599 | ) type = __FW__; |
klauss | 99:e80850c51106 | 600 | |
klauss | 105:a930035b6556 | 601 | // exibe que o pacote foi recebido porem sem exibir o conteudo do pacote, apenas ramal e porta do remetente e tipo do pkg |
klauss | 99:e80850c51106 | 602 | if( debug_cb_rx == true ){ |
klauss | 99:e80850c51106 | 603 | send_msg("Pkg from CBx :: ( %d, %d ) -- Type :: %d", ext, port, type ); |
klauss | 99:e80850c51106 | 604 | } |
klauss | 105:a930035b6556 | 605 | |
klauss | 105:a930035b6556 | 606 | // exibe o pacote recebido propriamente |
klauss | 105:a930035b6556 | 607 | if( debug_show_cpld ) |
klauss | 105:a930035b6556 | 608 | { |
klauss | 105:a930035b6556 | 609 | char str[ 1024 ]; |
klauss | 105:a930035b6556 | 610 | strcpy( str, "RX :: \n\r " ); |
klauss | 105:a930035b6556 | 611 | for( register uint16_t i = 0; i < CB_BUFFER_SIZE; i++ ) { |
klauss | 105:a930035b6556 | 612 | char tmp[ 16 ]; |
klauss | 105:a930035b6556 | 613 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 105:a930035b6556 | 614 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 105:a930035b6556 | 615 | |
klauss | 105:a930035b6556 | 616 | else strcat( str, " " ); |
klauss | 105:a930035b6556 | 617 | } |
klauss | 105:a930035b6556 | 618 | send_msg( "%s", str ); |
klauss | 105:a930035b6556 | 619 | } |
klauss | 99:e80850c51106 | 620 | |
klauss | 105:a930035b6556 | 621 | // verificacoes de ACKS |
klauss | 0:4d17cd9c8f9d | 622 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 623 | if( cb != NULL ) { |
klauss | 92:92df17f538a8 | 624 | if( data[ 0 ] & BIT7 ) { |
klauss | 91:c2a86b1f8aaa | 625 | if( type == __BOOT__ ) { |
klauss | 105:a930035b6556 | 626 | send2callboxes( build_cb_package( ext, port, __REGISTRY__, |
klauss | 105:a930035b6556 | 627 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 92:92df17f538a8 | 628 | } else { |
klauss | 81:3656f00ab3db | 629 | if( debug_main ) debug_msg("Received ack pkg with seq_num %d", data[ 0 ] ); |
klauss | 91:c2a86b1f8aaa | 630 | |
klauss | 91:c2a86b1f8aaa | 631 | switch( type ) { |
klauss | 81:3656f00ab3db | 632 | case __INVITE__ : { |
klauss | 81:3656f00ab3db | 633 | if( debug_main || debug_invite ) debug_msg("Invite Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 91:c2a86b1f8aaa | 634 | break; |
klauss | 81:3656f00ab3db | 635 | } |
klauss | 81:3656f00ab3db | 636 | case __CB_BYE__ : { |
klauss | 81:3656f00ab3db | 637 | if( debug_main || debug_invite ) debug_msg("BYE Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 638 | cb->set_bye_response_ok(); |
klauss | 91:c2a86b1f8aaa | 639 | break; |
klauss | 81:3656f00ab3db | 640 | } |
klauss | 81:3656f00ab3db | 641 | case __REGISTRY__ : { |
klauss | 81:3656f00ab3db | 642 | if( debug_main || debug_aging ) debug_msg("Registry ACK from %d in pkg :: %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 643 | break; |
klauss | 81:3656f00ab3db | 644 | } |
klauss | 81:3656f00ab3db | 645 | default : { |
klauss | 91:c2a86b1f8aaa | 646 | if( debug_main || debug_aging ) debug_msg("ACK from %d in pkg :: %d :: type %d", ext, cb->get_msg_id(), type ); |
klauss | 91:c2a86b1f8aaa | 647 | } |
klauss | 81:3656f00ab3db | 648 | } |
klauss | 92:92df17f538a8 | 649 | if( type != __REGISTRY__ && type != __CB_BYE__ ) type = __DO_NOTHING__; |
klauss | 92:92df17f538a8 | 650 | if( type == __CB_BYE__ ){ |
klauss | 92:92df17f538a8 | 651 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 92:92df17f538a8 | 652 | if( call != NULL ){ |
klauss | 92:92df17f538a8 | 653 | if( call->get_elapsed_time() < 120000 ){ |
klauss | 105:a930035b6556 | 654 | // devido a um bug na implementacao do protocolo, eventualmente o cbx envia |
klauss | 105:a930035b6556 | 655 | // um pacote de bye nao intencional que encerrava ligacoes precocemente |
klauss | 105:a930035b6556 | 656 | // solucao encontrada, colocado um timer de controle. |
klauss | 92:92df17f538a8 | 657 | if( debug_invite ) debug_msg("%d ack bye ignored", ext ); |
klauss | 92:92df17f538a8 | 658 | type = __DO_NOTHING__; |
klauss | 92:92df17f538a8 | 659 | } |
klauss | 92:92df17f538a8 | 660 | } |
klauss | 92:92df17f538a8 | 661 | } |
klauss | 0:4d17cd9c8f9d | 662 | } |
klauss | 0:4d17cd9c8f9d | 663 | } |
klauss | 0:4d17cd9c8f9d | 664 | } |
klauss | 0:4d17cd9c8f9d | 665 | } |
klauss | 91:c2a86b1f8aaa | 666 | } else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 667 | } |
klauss | 105:a930035b6556 | 668 | |
klauss | 105:a930035b6556 | 669 | // exibe uptime atual |
klauss | 105:a930035b6556 | 670 | if( show_uptime ) |
klauss | 105:a930035b6556 | 671 | { |
klauss | 105:a930035b6556 | 672 | show_uptime = false; |
klauss | 105:a930035b6556 | 673 | send_msg("Uptime: %d", uptime ); |
klauss | 105:a930035b6556 | 674 | } |
klauss | 91:c2a86b1f8aaa | 675 | |
klauss | 105:a930035b6556 | 676 | // exibe algumas informacoes pertinentes sobre quantidade de variaveis alocadas e tamanho de alguns objetos. |
klauss | 104:62646ef786a3 | 677 | if( sizes == true ) { |
klauss | 104:62646ef786a3 | 678 | sizes = false; |
klauss | 85:b6f2dc1d0f4f | 679 | send_msg("CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter ); |
klauss | 85:b6f2dc1d0f4f | 680 | send_msg("SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter ); |
klauss | 87:679ee0d594a9 | 681 | send_msg("RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter ); |
klauss | 87:679ee0d594a9 | 682 | send_msg("RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter ); |
klauss | 91:c2a86b1f8aaa | 683 | send_msg("Call_New (%u) -- Call_Delete (%u)", call_new_counter, call_delete_counter ); |
klauss | 87:679ee0d594a9 | 684 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 685 | send_msg("Memory is %s", ( memory_is_over ) ? "Over" : "Ok" ); |
klauss | 81:3656f00ab3db | 686 | send_msg("Missed_Pkg :: %d ::", missed_pkg ); |
klauss | 87:679ee0d594a9 | 687 | send_msg("Sizeof Sip :: %u", sizeof( Sip ) ); |
klauss | 87:679ee0d594a9 | 688 | send_msg("Sizeof Call_Box :: %u", sizeof( Call_Box ) ); |
klauss | 87:679ee0d594a9 | 689 | send_msg("Sizeof VZ_call :: %u", sizeof( VZ_call ) ); |
klauss | 87:679ee0d594a9 | 690 | send_msg("Sizeof RTP :: %u", sizeof( RTP ) ); |
klauss | 87:679ee0d594a9 | 691 | send_msg("Sizeof RTP_Header :: %u", sizeof( RTP_Header ) ); |
klauss | 87:679ee0d594a9 | 692 | send_msg("Sizeof RTP_Body :: %u", sizeof( RTP_Body ) ); |
klauss | 87:679ee0d594a9 | 693 | send_msg("Sizeof Vector :: %u", sizeof( Vector ) ); |
klauss | 87:679ee0d594a9 | 694 | send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) ); |
klauss | 87:679ee0d594a9 | 695 | send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) ); |
klauss | 81:3656f00ab3db | 696 | } |
klauss | 91:c2a86b1f8aaa | 697 | |
klauss | 105:a930035b6556 | 698 | // zera os contadores de cks de pacotes recebidos na interface CBx->Header, e outros contadores relacionados |
klauss | 91:c2a86b1f8aaa | 699 | if( reset_cks == true ) { |
klauss | 81:3656f00ab3db | 700 | pkg_cksok = 0; |
klauss | 81:3656f00ab3db | 701 | pkg_ckserr = 0; |
klauss | 99:e80850c51106 | 702 | pkg_zero = 0; |
klauss | 81:3656f00ab3db | 703 | reset_cks = false; |
klauss | 99:e80850c51106 | 704 | out_of_range = 0; |
klauss | 99:e80850c51106 | 705 | missed_pkg = 0; |
klauss | 100:09a23fcd3bdf | 706 | delayed_pkg_to_cb = 0; |
klauss | 99:e80850c51106 | 707 | cpld_pkg_tx_counter = 0; |
klauss | 99:e80850c51106 | 708 | cpld_pkg_rx_counter = 0; |
klauss | 81:3656f00ab3db | 709 | pcks_s = true; |
klauss | 81:3656f00ab3db | 710 | } |
klauss | 91:c2a86b1f8aaa | 711 | |
klauss | 105:a930035b6556 | 712 | // exibe os contadores de cks de pacotes recebidos na interface CBx->Header, e outros contadores relacionados |
klauss | 91:c2a86b1f8aaa | 713 | if( pcks_s == true ) { |
klauss | 105:a930035b6556 | 714 | send_msg( |
klauss | 105:a930035b6556 | 715 | "\r\n" |
klauss | 105:a930035b6556 | 716 | " PKG_CKS OK: %d ( %003.2f )\r\n" |
klauss | 105:a930035b6556 | 717 | " PKG_CKS ERR: %d ( %003.2f )\r\n" |
klauss | 105:a930035b6556 | 718 | " PKG_0: %d ( %003.2f )\r\n" |
klauss | 105:a930035b6556 | 719 | " Out_of_range: %d ( %003.2f )\r\n" |
klauss | 105:a930035b6556 | 720 | " Miss_Pkg: %d\r\n" |
klauss | 105:a930035b6556 | 721 | " TX_delayed: %d\n\r" |
klauss | 105:a930035b6556 | 722 | " TX_Counter: %d\n\r" |
klauss | 105:a930035b6556 | 723 | " RX_Counter: %d\r\n", |
klauss | 105:a930035b6556 | 724 | pkg_cksok, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_cksok / cpld_pkg_rx_counter ) * 100, |
klauss | 105:a930035b6556 | 725 | pkg_ckserr, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_ckserr / cpld_pkg_rx_counter ) * 100, |
klauss | 105:a930035b6556 | 726 | pkg_zero, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) pkg_zero / cpld_pkg_rx_counter ) * 100, |
klauss | 105:a930035b6556 | 727 | out_of_range, ( cpld_pkg_rx_counter == 0 ) ? 0.00 : ( ( double ) out_of_range / cpld_pkg_rx_counter ) * 100, |
klauss | 105:a930035b6556 | 728 | missed_pkg, |
klauss | 105:a930035b6556 | 729 | delayed_pkg_to_cb, |
klauss | 105:a930035b6556 | 730 | cpld_pkg_tx_counter, |
klauss | 105:a930035b6556 | 731 | cpld_pkg_rx_counter |
klauss | 105:a930035b6556 | 732 | ); |
klauss | 81:3656f00ab3db | 733 | pcks_s = false; |
klauss | 81:3656f00ab3db | 734 | } |
klauss | 105:a930035b6556 | 735 | |
klauss | 105:a930035b6556 | 736 | // zera os contadores de pacotes que resultaram em falha de envio vio ETH |
klauss | 105:a930035b6556 | 737 | if( reset_missed_send_udp_pkg ){ |
klauss | 105:a930035b6556 | 738 | miss_fw_send_pkg = 0; |
klauss | 105:a930035b6556 | 739 | miss_prompt_udp_send_pkg = 0; |
klauss | 105:a930035b6556 | 740 | miss_sip_registry_send_pkg = 0; |
klauss | 105:a930035b6556 | 741 | miss_sip_invite_send_pkg = 0; |
klauss | 105:a930035b6556 | 742 | miss_sip_bye_send_pkg = 0; |
klauss | 105:a930035b6556 | 743 | miss_sip_unregistry_send_pkg = 0; |
klauss | 105:a930035b6556 | 744 | miss_sip_ok_send_pkg = 0; |
klauss | 105:a930035b6556 | 745 | miss_sip_rcv_bye_send_pkg = 0; |
klauss | 105:a930035b6556 | 746 | miss_wdt_send_pkg = 0; |
klauss | 105:a930035b6556 | 747 | miss_prompt_udp_send_pkg = 0; |
klauss | 105:a930035b6556 | 748 | miss_ftp_udp_send_pkg = 0; |
klauss | 105:a930035b6556 | 749 | miss_prompt_udp_rcv_pkg = 0; |
klauss | 105:a930035b6556 | 750 | reset_missed_send_udp_pkg = false; |
klauss | 105:a930035b6556 | 751 | missed_send_udp_pkg = true; |
klauss | 105:a930035b6556 | 752 | } |
klauss | 105:a930035b6556 | 753 | |
klauss | 105:a930035b6556 | 754 | // exibe estatisticas de pacotes que resultaram em falha de envio na interface ETH |
klauss | 105:a930035b6556 | 755 | if( missed_send_udp_pkg ) |
klauss | 105:a930035b6556 | 756 | { |
klauss | 105:a930035b6556 | 757 | send_msg( "\r\nMissed pkgs ::\r\n " |
klauss | 105:a930035b6556 | 758 | "FW: %d\r\n " |
klauss | 105:a930035b6556 | 759 | "Prompt UDP %d\r\n " |
klauss | 105:a930035b6556 | 760 | "Registry %d\r\n " |
klauss | 105:a930035b6556 | 761 | "Invite %d\r\n " |
klauss | 105:a930035b6556 | 762 | "Bye %d\r\n " |
klauss | 105:a930035b6556 | 763 | "Unregistry %d\r\n " |
klauss | 105:a930035b6556 | 764 | "UDP incoming ( invite ans ) %d\r\n " |
klauss | 105:a930035b6556 | 765 | "UDP incoming ( bye from * ) %d\r\n " |
klauss | 105:a930035b6556 | 766 | "Wdt [ alive | rst ] %d\r\n " |
klauss | 105:a930035b6556 | 767 | "Rcv prompt %d\r\n " |
klauss | 105:a930035b6556 | 768 | "[ debug | send ]_msg %d\r\n " |
klauss | 105:a930035b6556 | 769 | "RTP %d\r\n", |
klauss | 105:a930035b6556 | 770 | miss_fw_send_pkg, |
klauss | 105:a930035b6556 | 771 | miss_prompt_udp_send_pkg, |
klauss | 105:a930035b6556 | 772 | miss_sip_registry_send_pkg, |
klauss | 105:a930035b6556 | 773 | miss_sip_invite_send_pkg, |
klauss | 105:a930035b6556 | 774 | miss_sip_bye_send_pkg, |
klauss | 105:a930035b6556 | 775 | miss_sip_unregistry_send_pkg, |
klauss | 105:a930035b6556 | 776 | miss_sip_ok_send_pkg, |
klauss | 105:a930035b6556 | 777 | miss_sip_rcv_bye_send_pkg, |
klauss | 105:a930035b6556 | 778 | miss_wdt_send_pkg, |
klauss | 105:a930035b6556 | 779 | miss_prompt_udp_send_pkg, |
klauss | 105:a930035b6556 | 780 | miss_prompt_udp_rcv_pkg, |
klauss | 105:a930035b6556 | 781 | miss_ftp_udp_send_pkg |
klauss | 105:a930035b6556 | 782 | ); |
klauss | 105:a930035b6556 | 783 | |
klauss | 105:a930035b6556 | 784 | missed_send_udp_pkg = false; |
klauss | 105:a930035b6556 | 785 | } |
klauss | 105:a930035b6556 | 786 | |
klauss | 105:a930035b6556 | 787 | // rotina de teste para sobrecarga do processamento do cbx. |
klauss | 100:09a23fcd3bdf | 788 | if( flood_bug_pkg ){ |
klauss | 100:09a23fcd3bdf | 789 | static int id = 0x10; |
klauss | 100:09a23fcd3bdf | 790 | if( id < 10 ) id = 0x0b; |
klauss | 105:a930035b6556 | 791 | send2callboxes( build_cb_package( 5828, 5123, __REGISTRY__, |
klauss | 105:a930035b6556 | 792 | ( char * )buffer, id++, CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 100:09a23fcd3bdf | 793 | } |
klauss | 100:09a23fcd3bdf | 794 | |
klauss | 105:a930035b6556 | 795 | // toggle nos leds de debug da header. |
klauss | 104:62646ef786a3 | 796 | if( led_sync_timer.read() >= 1 ) { |
klauss | 78:1353744f01e1 | 797 | led_sync_timer.reset(); |
klauss | 78:1353744f01e1 | 798 | led3 = !led3; |
klauss | 78:1353744f01e1 | 799 | CAB_LED = !CAB_LED; |
klauss | 78:1353744f01e1 | 800 | } |
klauss | 105:a930035b6556 | 801 | |
klauss | 105:a930035b6556 | 802 | // rotina de teste ( usados durante desenvolvimento |
klauss | 105:a930035b6556 | 803 | if( main_test ) |
klauss | 105:a930035b6556 | 804 | { |
klauss | 105:a930035b6556 | 805 | static int next_ext = 1314; |
klauss | 105:a930035b6556 | 806 | static int next_port = 1923; |
klauss | 105:a930035b6556 | 807 | |
klauss | 105:a930035b6556 | 808 | main_test = false; |
klauss | 105:a930035b6556 | 809 | data = buffer; |
klauss | 105:a930035b6556 | 810 | ext = next_ext++; |
klauss | 105:a930035b6556 | 811 | port = next_port++; |
klauss | 105:a930035b6556 | 812 | type = __INVITE__; |
klauss | 105:a930035b6556 | 813 | } |
klauss | 105:a930035b6556 | 814 | |
klauss | 105:a930035b6556 | 815 | // begin switch para tratemento de pacote baseado no type |
klauss | 91:c2a86b1f8aaa | 816 | switch( type ) { |
klauss | 91:c2a86b1f8aaa | 817 | case __DO_NOTHING__ : |
klauss | 91:c2a86b1f8aaa | 818 | {} |
klauss | 91:c2a86b1f8aaa | 819 | break; |
klauss | 91:c2a86b1f8aaa | 820 | |
klauss | 0:4d17cd9c8f9d | 821 | case __CB_BYE__ : { |
klauss | 105:a930035b6556 | 822 | /*** |
klauss | 105:a930035b6556 | 823 | -- Fluxo -- |
klauss | 105:a930035b6556 | 824 | [ Principio ] |
klauss | 105:a930035b6556 | 825 | -- Receber um pedido de bye |
klauss | 105:a930035b6556 | 826 | -- procurar e encerrar a ligacao |
klauss | 105:a930035b6556 | 827 | |
klauss | 105:a930035b6556 | 828 | - Incrementa o contador de pacotes recebidos |
klauss | 105:a930035b6556 | 829 | - Procura por este cbx no vetor logico de CBx. |
klauss | 105:a930035b6556 | 830 | - Em caso de nao localizacao - Nao executa tratamento e exibe mensagem informando, caso seja habilitado degub |
klauss | 105:a930035b6556 | 831 | - Em caso de localizacao do cbx |
klauss | 105:a930035b6556 | 832 | - Seta o BIT7 para ACK |
klauss | 105:a930035b6556 | 833 | - assume que esta ligacao já foi removida |
klauss | 105:a930035b6556 | 834 | - procura por essa call no vetor logico de calls |
klauss | 105:a930035b6556 | 835 | - Em caso de nao localizacao |
klauss | 105:a930035b6556 | 836 | - Executa Busca no vetor logico de CBX |
klauss | 105:a930035b6556 | 837 | - Em caso de localizacao |
klauss | 105:a930035b6556 | 838 | - assume que esta ligacao já foi removida |
klauss | 105:a930035b6556 | 839 | - Confirma que a ligacao nao tinha sido removida |
klauss | 105:a930035b6556 | 840 | - Envia pacote de BYE para o servidor asterisk ( * ) |
klauss | 105:a930035b6556 | 841 | - Recupera o TimeSlice ( ts ) usado nesta call |
klauss | 105:a930035b6556 | 842 | - Atribui o TS 0 neste cbx |
klauss | 105:a930035b6556 | 843 | - Preenche a posição do TS com 0 |
klauss | 105:a930035b6556 | 844 | - Retorna o status do CBx e do SIP deste CBx para idle |
klauss | 105:a930035b6556 | 845 | - Remove a call do vetor |
klauss | 105:a930035b6556 | 846 | - Envia pacote de ack para o CBx |
klauss | 105:a930035b6556 | 847 | - Atualiza o id da próxima msg que sera enviada para este CBx |
klauss | 105:a930035b6556 | 848 | - Em caso de nao localizacao |
klauss | 105:a930035b6556 | 849 | Exibe mensagem informando que exta call ja tinha sido removida, caso habilitado debug |
klauss | 105:a930035b6556 | 850 | - Em caso de localizacao |
klauss | 105:a930035b6556 | 851 | - Confirma que a ligacao nao tinha sido removida |
klauss | 105:a930035b6556 | 852 | - Envia pacote de BYE para o servidor asterisk ( * ) |
klauss | 105:a930035b6556 | 853 | - Recupera o TimeSlice ( ts ) usado nesta call |
klauss | 105:a930035b6556 | 854 | - Atribui o TS 0 neste cbx |
klauss | 105:a930035b6556 | 855 | - Preenche a posição do TS com 0 |
klauss | 105:a930035b6556 | 856 | - Retorna o status do CBx e do SIP deste CBx para idle |
klauss | 105:a930035b6556 | 857 | - Remove a call do vetor |
klauss | 105:a930035b6556 | 858 | - Envia pacote de ack para o CBx |
klauss | 105:a930035b6556 | 859 | - Atualiza o id da próxima msg que sera enviada para este CBx |
klauss | 105:a930035b6556 | 860 | - Deleta o objeto call. |
klauss | 105:a930035b6556 | 861 | - Em caso de nao localizacao |
klauss | 105:a930035b6556 | 862 | Exibe mensagem informando que exta call ja tinha sido removida, caso habilitado debug |
klauss | 105:a930035b6556 | 863 | ***/ |
klauss | 105:a930035b6556 | 864 | |
klauss | 63:0d95da692bb4 | 865 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 866 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 867 | if( cb != NULL ) { |
klauss | 81:3656f00ab3db | 868 | 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 | 869 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 870 | cb->set_msg_id( data[ 0 ] ); |
klauss | 81:3656f00ab3db | 871 | if( debug_main || debug_invite ) debug_msg( "Request bye from CBx " ); |
klauss | 92:92df17f538a8 | 872 | |
klauss | 81:3656f00ab3db | 873 | bool already_removed = true; |
klauss | 91:c2a86b1f8aaa | 874 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 0:4d17cd9c8f9d | 875 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 876 | if( call->get_cb_ext() == ext ) { |
klauss | 81:3656f00ab3db | 877 | already_removed = false; |
klauss | 4:de46f0d9b14d | 878 | cb->send_bye(); |
klauss | 91:c2a86b1f8aaa | 879 | |
klauss | 0:4d17cd9c8f9d | 880 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 881 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 882 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 91:c2a86b1f8aaa | 883 | |
klauss | 0:4d17cd9c8f9d | 884 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 885 | set_status( cb->sip->status, sip_idle ); |
klauss | 91:c2a86b1f8aaa | 886 | |
klauss | 81:3656f00ab3db | 887 | v_call->remove_element( i ); |
klauss | 91:c2a86b1f8aaa | 888 | |
klauss | 105:a930035b6556 | 889 | send2callboxes( build_cb_package( ext, port, __CB_BYE__, |
klauss | 105:a930035b6556 | 890 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 92:92df17f538a8 | 891 | |
klauss | 92:92df17f538a8 | 892 | // envia o ack bye depois atualiza o msg_id |
klauss | 92:92df17f538a8 | 893 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 91:c2a86b1f8aaa | 894 | |
klauss | 3:cd9148672e25 | 895 | delete( call ); |
klauss | 0:4d17cd9c8f9d | 896 | } |
klauss | 0:4d17cd9c8f9d | 897 | } |
klauss | 105:a930035b6556 | 898 | |
klauss | 82:f55d13babca0 | 899 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from vector call" ); |
klauss | 105:a930035b6556 | 900 | |
klauss | 105:a930035b6556 | 901 | // ok, mas nem sempre o cbx "entrou" em call |
klauss | 105:a930035b6556 | 902 | // Faz-se agora a busca no vetor logico de CBx e nao no de calls como acima |
klauss | 82:f55d13babca0 | 903 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 904 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 82:f55d13babca0 | 905 | if( cb->get_ext() == ext ) { |
klauss | 82:f55d13babca0 | 906 | already_removed = true; |
klauss | 105:a930035b6556 | 907 | // nao entra nesse if caso tenha sido removido no for de cima. |
klauss | 82:f55d13babca0 | 908 | if( cb->get_status() != cb_idle ) { |
klauss | 82:f55d13babca0 | 909 | already_removed = false; |
klauss | 82:f55d13babca0 | 910 | cb->send_bye(); |
klauss | 82:f55d13babca0 | 911 | |
klauss | 82:f55d13babca0 | 912 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 82:f55d13babca0 | 913 | cb->set_timeslice( 0x00 ); |
klauss | 82:f55d13babca0 | 914 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 82:f55d13babca0 | 915 | |
klauss | 82:f55d13babca0 | 916 | set_status( cb->status, cb_idle ); |
klauss | 82:f55d13babca0 | 917 | set_status( cb->sip->status, sip_idle ); |
klauss | 82:f55d13babca0 | 918 | |
klauss | 105:a930035b6556 | 919 | send2callboxes( build_cb_package( ext, port, __CB_BYE__, |
klauss | 105:a930035b6556 | 920 | ( char * )data, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 82:f55d13babca0 | 921 | |
klauss | 92:92df17f538a8 | 922 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 82:f55d13babca0 | 923 | } |
klauss | 82:f55d13babca0 | 924 | } |
klauss | 82:f55d13babca0 | 925 | } |
klauss | 91:c2a86b1f8aaa | 926 | |
klauss | 82:f55d13babca0 | 927 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from inviting queue" ); |
klauss | 91:c2a86b1f8aaa | 928 | |
klauss | 78:1353744f01e1 | 929 | cb->registry(); |
klauss | 91:c2a86b1f8aaa | 930 | } else if( debug_invite || debug_main ) debug_msg("Bye from who ? %d", ext ); |
klauss | 91:c2a86b1f8aaa | 931 | } |
klauss | 91:c2a86b1f8aaa | 932 | break; |
klauss | 91:c2a86b1f8aaa | 933 | |
klauss | 0:4d17cd9c8f9d | 934 | case __INVITE__ : { |
klauss | 105:a930035b6556 | 935 | /*** |
klauss | 105:a930035b6556 | 936 | [ Principio ] |
klauss | 105:a930035b6556 | 937 | -- Receber um pedido de chamada |
klauss | 105:a930035b6556 | 938 | -- tratar com o cbx o andamento da negociacao SIP ( informando disponibilidade de TS ) |
klauss | 105:a930035b6556 | 939 | -- tratar com o * a negociacao SIP |
klauss | 105:a930035b6556 | 940 | |
klauss | 105:a930035b6556 | 941 | -- Fluxo -- |
klauss | 105:a930035b6556 | 942 | - Incrementa o contador de pacotes de pedido de chamada ( invite ) enviados. |
klauss | 105:a930035b6556 | 943 | - Procura por este CBx no vetor logico de CBX |
klauss | 105:a930035b6556 | 944 | - Em caso de nao localizacao |
klauss | 105:a930035b6556 | 945 | - Verifica se nao existem mais cbx criados do que o permitido por definicao de projeto |
klauss | 105:a930035b6556 | 946 | - Tenta criar o objeto CBx |
klauss | 105:a930035b6556 | 947 | - Caso consiga criar : adiciona o novo elemento no vetor logico de CBx |
klauss | 105:a930035b6556 | 948 | - Caso nao consiga criar : Exibe msg de erro condicionada a debuf e seta variavel indicando ausencia de memoria |
klauss | 105:a930035b6556 | 949 | - Em caso de localizacao ( ou tenha conseguido criar no caso acima ) |
klauss | 105:a930035b6556 | 950 | - Atribui o valor recebido no pacote na posicao ID como sendo o id da proxima msg |
klauss | 105:a930035b6556 | 951 | - Verifica o status do CBx |
klauss | 105:a930035b6556 | 952 | - Caso status idle, inicia timer de tratamento de envio de ACK pro CBx |
klauss | 105:a930035b6556 | 953 | - Invoca rotina de tratamento SIP deste pedido de chamada. |
klauss | 105:a930035b6556 | 954 | ***/ |
klauss | 105:a930035b6556 | 955 | |
klauss | 63:0d95da692bb4 | 956 | invite_counter++; |
klauss | 78:1353744f01e1 | 957 | if( debug_invite ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 0:4d17cd9c8f9d | 958 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 959 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 960 | if( v_cb->size() < __MAX_CB_IN_A_BRANCH__ ) { |
klauss | 91:c2a86b1f8aaa | 961 | if( debug_main ) debug_msg( "Adding CBx :: %i", ext ); |
klauss | 91:c2a86b1f8aaa | 962 | cb = new Call_Box( ext, port ); |
klauss | 91:c2a86b1f8aaa | 963 | |
klauss | 91:c2a86b1f8aaa | 964 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 965 | memory_is_over = true; |
klauss | 91:c2a86b1f8aaa | 966 | if( debug_memory ) debug_msg("Invite allocation cb fail"); |
klauss | 91:c2a86b1f8aaa | 967 | } else { |
klauss | 91:c2a86b1f8aaa | 968 | v_cb->add( cb ); |
klauss | 91:c2a86b1f8aaa | 969 | } |
klauss | 89:0fe315117b00 | 970 | } |
klauss | 0:4d17cd9c8f9d | 971 | } |
klauss | 91:c2a86b1f8aaa | 972 | if( cb != NULL ) { |
klauss | 91:c2a86b1f8aaa | 973 | cb->set_msg_id( data[ 0 ] ); |
klauss | 92:92df17f538a8 | 974 | if( cb->status == cb_idle ){ |
klauss | 92:92df17f538a8 | 975 | cb->set_invite_response_ok(); |
klauss | 92:92df17f538a8 | 976 | cb->invite_retry_count_reset(); |
klauss | 92:92df17f538a8 | 977 | } |
klauss | 87:679ee0d594a9 | 978 | invite_handler( v_call, v_cb, ts, cb ); |
klauss | 87:679ee0d594a9 | 979 | } |
klauss | 91:c2a86b1f8aaa | 980 | } |
klauss | 91:c2a86b1f8aaa | 981 | break; |
klauss | 4:de46f0d9b14d | 982 | case __REGISTRY__ : { |
klauss | 105:a930035b6556 | 983 | /*** |
klauss | 105:a930035b6556 | 984 | [ Principio ] |
klauss | 105:a930035b6556 | 985 | -- Receber um pacote de registro |
klauss | 105:a930035b6556 | 986 | -- Encaminhar para o * |
klauss | 105:a930035b6556 | 987 | |
klauss | 105:a930035b6556 | 988 | -- Fluxo -- |
klauss | 105:a930035b6556 | 989 | - incrementa o contador de pacotes de registro recebidos |
klauss | 105:a930035b6556 | 990 | - Procura por este cbx no vetor logico de CBx. |
klauss | 105:a930035b6556 | 991 | - Verifica se nao existem mais cbx criados do que o permitido por definicao de projeto |
klauss | 105:a930035b6556 | 992 | - Caso nao exista |
klauss | 105:a930035b6556 | 993 | - Verifica se o CBx foi encontrado no vetor |
klauss | 105:a930035b6556 | 994 | - Caso nao tenha sido |
klauss | 105:a930035b6556 | 995 | - Tentar criar este elemento |
klauss | 105:a930035b6556 | 996 | - Verifica criacao bem sucedida |
klauss | 105:a930035b6556 | 997 | - Caso tenha criado o elemento |
klauss | 105:a930035b6556 | 998 | - Adiciona o mesmo no vetor logico de CBX |
klauss | 105:a930035b6556 | 999 | - Caso nao tenha criado o elemento |
klauss | 105:a930035b6556 | 1000 | - seta variavel de erro |
klauss | 105:a930035b6556 | 1001 | - exibe mensagem de erro condicionada a debug. |
klauss | 105:a930035b6556 | 1002 | - Caso o CBx tenha sido encontrado ( ou criado acima ) |
klauss | 105:a930035b6556 | 1003 | - Envia pacote de registro para o * |
klauss | 105:a930035b6556 | 1004 | ***/ |
klauss | 63:0d95da692bb4 | 1005 | registry_counter++; |
klauss | 78:1353744f01e1 | 1006 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 1007 | if( v_cb->size() < __MAX_CB_IN_A_BRANCH__ ) { |
klauss | 91:c2a86b1f8aaa | 1008 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 1009 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 91:c2a86b1f8aaa | 1010 | cb = new Call_Box( ext, port ); |
klauss | 91:c2a86b1f8aaa | 1011 | |
klauss | 91:c2a86b1f8aaa | 1012 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 1013 | memory_is_over = true; |
klauss | 91:c2a86b1f8aaa | 1014 | if( debug_memory ) debug_msg("Registry cb allocation fail"); |
klauss | 91:c2a86b1f8aaa | 1015 | } else { |
klauss | 91:c2a86b1f8aaa | 1016 | v_cb->add( cb ); |
klauss | 91:c2a86b1f8aaa | 1017 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 91:c2a86b1f8aaa | 1018 | } |
klauss | 87:679ee0d594a9 | 1019 | } |
klauss | 0:4d17cd9c8f9d | 1020 | } |
klauss | 78:1353744f01e1 | 1021 | if( debug_main ) debug_msg("Registered %d - %d", ext, port ); |
klauss | 91:c2a86b1f8aaa | 1022 | |
klauss | 87:679ee0d594a9 | 1023 | if( cb != NULL ) cb->registry(); |
klauss | 91:c2a86b1f8aaa | 1024 | } |
klauss | 91:c2a86b1f8aaa | 1025 | break; |
klauss | 4:de46f0d9b14d | 1026 | case __BOOT__ : { |
klauss | 105:a930035b6556 | 1027 | /*** |
klauss | 105:a930035b6556 | 1028 | [ Principio ] |
klauss | 105:a930035b6556 | 1029 | -- Receber um pacote de boot do CBx |
klauss | 105:a930035b6556 | 1030 | -- Encaminhar um pacote do tipo "Registro" para o CBx |
klauss | 105:a930035b6556 | 1031 | [ NOTA ] Por decisao de projeto, o CBx responde pacotes do tipo __REGISTRY__ pendindo pra se registrar. |
klauss | 105:a930035b6556 | 1032 | |
klauss | 105:a930035b6556 | 1033 | -- Fluxo -- |
klauss | 105:a930035b6556 | 1034 | - Incrementa o contador de pacotes de boot recebidos |
klauss | 105:a930035b6556 | 1035 | - Envia para o CBx remetendo o mesmo pacote, contendo o tipo __REGISTRY__ e o id como sendo o id recebido "OR" BIT7 |
klauss | 105:a930035b6556 | 1036 | |
klauss | 105:a930035b6556 | 1037 | ***/ |
klauss | 63:0d95da692bb4 | 1038 | boot_counter++; |
klauss | 99:e80850c51106 | 1039 | if( debug_boot == true ){ |
klauss | 99:e80850c51106 | 1040 | send_msg("Rcv boot pkg from (%d, %d) pkg-id %d", ext, port, data[ 0 ] ); |
klauss | 99:e80850c51106 | 1041 | } |
klauss | 105:a930035b6556 | 1042 | send2callboxes( build_cb_package( ext, port, __REGISTRY__, |
klauss | 105:a930035b6556 | 1043 | ( char * )data, data[ 0 ] | BIT7, CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 91:c2a86b1f8aaa | 1044 | } |
klauss | 91:c2a86b1f8aaa | 1045 | break; |
klauss | 99:e80850c51106 | 1046 | |
klauss | 99:e80850c51106 | 1047 | case __FW__ : { |
klauss | 105:a930035b6556 | 1048 | /*** |
klauss | 105:a930035b6556 | 1049 | [ Principio ] |
klauss | 105:a930035b6556 | 1050 | -- Encaminhar para o servidor predeterminado todo pacote do tipo __FW__ |
klauss | 105:a930035b6556 | 1051 | |
klauss | 105:a930035b6556 | 1052 | -- Fluxo -- |
klauss | 105:a930035b6556 | 1053 | - Incrementa o contador de pacotes de __FW__ recebidos |
klauss | 105:a930035b6556 | 1054 | - invoca rotina que exporta este pacote para o servidor |
klauss | 105:a930035b6556 | 1055 | ***/ |
klauss | 105:a930035b6556 | 1056 | fw_counter++; |
klauss | 99:e80850c51106 | 1057 | if( debug_fw_print ) send_msg("::FW pkg from %d - %d::", ext, port ); |
klauss | 99:e80850c51106 | 1058 | fw_cbx_pkg( ext, port, ( char *)buffer ); |
klauss | 99:e80850c51106 | 1059 | } |
klauss | 99:e80850c51106 | 1060 | break; |
klauss | 91:c2a86b1f8aaa | 1061 | |
klauss | 67:cdedc64d9921 | 1062 | case __BOOTLOADER_CBX__ : { |
klauss | 105:a930035b6556 | 1063 | /*** |
klauss | 105:a930035b6556 | 1064 | [ Principio ] |
klauss | 105:a930035b6556 | 1065 | -- A definir, a priori a header seria um bypass responsavel apenas por gerenciar um TS. |
klauss | 105:a930035b6556 | 1066 | -- Fluxo -- |
klauss | 105:a930035b6556 | 1067 | - incrementa o contador de pacote de bootloader CBx recebidos |
klauss | 105:a930035b6556 | 1068 | - ??? |
klauss | 105:a930035b6556 | 1069 | ***/ |
klauss | 67:cdedc64d9921 | 1070 | bootloader_cbx_counter++; |
klauss | 91:c2a86b1f8aaa | 1071 | } |
klauss | 91:c2a86b1f8aaa | 1072 | break; |
klauss | 91:c2a86b1f8aaa | 1073 | |
klauss | 105:a930035b6556 | 1074 | case __PROMPT__ : { |
klauss | 105:a930035b6556 | 1075 | /*** |
klauss | 105:a930035b6556 | 1076 | [ Principio ] |
klauss | 105:a930035b6556 | 1077 | -- Receber um pacote do CBx |
klauss | 105:a930035b6556 | 1078 | -- Criar, adicionar e registrar o CBx remetente |
klauss | 105:a930035b6556 | 1079 | -- Exibir na tela possiveis comandos/saidas do CBx de interesse. |
klauss | 105:a930035b6556 | 1080 | -- Fluxo -- |
klauss | 105:a930035b6556 | 1081 | - Procura por este cbx no vetor logico de CBx. |
klauss | 105:a930035b6556 | 1082 | - Verifica se o CBx foi encontrado no vetor |
klauss | 105:a930035b6556 | 1083 | - Caso nao tenha sido encontrado |
klauss | 105:a930035b6556 | 1084 | - Verifica se nao existem mais cbx criados do que o permitido por definicao de projeto |
klauss | 105:a930035b6556 | 1085 | - Caso nao exista |
klauss | 105:a930035b6556 | 1086 | - Tentar criar este elemento |
klauss | 105:a930035b6556 | 1087 | - Verifica criacao bem sucedida |
klauss | 105:a930035b6556 | 1088 | - Caso nao tenha criado o elemento |
klauss | 105:a930035b6556 | 1089 | - seta variavel de erro |
klauss | 105:a930035b6556 | 1090 | - Caso tenha criado o elemento |
klauss | 105:a930035b6556 | 1091 | - Adiciona o mesmo no vetor logico de CBX |
klauss | 105:a930035b6556 | 1092 | - Caso tenha sido encontrado ( ou criado no caso acima ) |
klauss | 105:a930035b6556 | 1093 | - Encaminha pedido de registro para o * |
klauss | 105:a930035b6556 | 1094 | - Verifica se o pacote recebido possui como conteudo "ping" |
klauss | 105:a930035b6556 | 1095 | - em caso positivo |
klauss | 105:a930035b6556 | 1096 | - exibe msg indicativa condicionada a debug |
klauss | 105:a930035b6556 | 1097 | - em caso negativo |
klauss | 105:a930035b6556 | 1098 | - Incrementa o contador de pacotes recebidos |
klauss | 105:a930035b6556 | 1099 | - Exibe conteudo de pacote ( 32 primeiros bytes ) condicionado a debug |
klauss | 105:a930035b6556 | 1100 | ***/ |
klauss | 105:a930035b6556 | 1101 | |
klauss | 78:1353744f01e1 | 1102 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 1103 | |
klauss | 91:c2a86b1f8aaa | 1104 | if( cb == NULL ) { |
klauss | 105:a930035b6556 | 1105 | if( v_cb->size() < __MAX_CB_IN_A_BRANCH__ ) { |
klauss | 105:a930035b6556 | 1106 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 105:a930035b6556 | 1107 | cb = new Call_Box( ext, port ); |
klauss | 105:a930035b6556 | 1108 | if( cb == NULL ) { |
klauss | 105:a930035b6556 | 1109 | memory_is_over = true; |
klauss | 105:a930035b6556 | 1110 | } else { |
klauss | 105:a930035b6556 | 1111 | v_cb->add( cb ); |
klauss | 105:a930035b6556 | 1112 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 105:a930035b6556 | 1113 | } |
klauss | 87:679ee0d594a9 | 1114 | } |
klauss | 48:195c97f12e8e | 1115 | } |
klauss | 91:c2a86b1f8aaa | 1116 | |
klauss | 92:92df17f538a8 | 1117 | if( cb!= NULL ) cb->registry(); |
klauss | 91:c2a86b1f8aaa | 1118 | |
klauss | 91:c2a86b1f8aaa | 1119 | if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ) { |
klauss | 78:1353744f01e1 | 1120 | if( debug_ping ) send_msg( "Prompt pkg from ( %i, %i ) :: Ping", ext, port ); |
klauss | 91:c2a86b1f8aaa | 1121 | } else { |
klauss | 78:1353744f01e1 | 1122 | prompt_counter++; |
klauss | 105:a930035b6556 | 1123 | //FIXME acumular a string e mandar via send_msg |
klauss | 78:1353744f01e1 | 1124 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 91:c2a86b1f8aaa | 1125 | for( register uint8_t i = 0; i < 32; i++ ) { |
klauss | 100:09a23fcd3bdf | 1126 | if( debug_uart3 ) pc.printf("%c", data[ i ] ); |
klauss | 100:09a23fcd3bdf | 1127 | if( i == 15 ) if( debug_uart3 ) pc.printf( "\r\n" ); |
klauss | 78:1353744f01e1 | 1128 | } |
klauss | 100:09a23fcd3bdf | 1129 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 91:c2a86b1f8aaa | 1130 | |
klauss | 105:a930035b6556 | 1131 | if( tcp_session && !udp_query ) { |
klauss | 105:a930035b6556 | 1132 | char aux[ CB_BUFFER_SIZE + 3 ]; |
klauss | 105:a930035b6556 | 1133 | strncpy( aux, (char * )data, CB_BUFFER_SIZE ); |
klauss | 78:1353744f01e1 | 1134 | strcat( aux, "\n\r\0" ); |
klauss | 78:1353744f01e1 | 1135 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 78:1353744f01e1 | 1136 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 78:1353744f01e1 | 1137 | } |
klauss | 105:a930035b6556 | 1138 | else if( udp_query ) |
klauss | 105:a930035b6556 | 1139 | { |
klauss | 105:a930035b6556 | 1140 | char aux[ CB_BUFFER_SIZE + 3 ]; |
klauss | 105:a930035b6556 | 1141 | strncpy( aux, (char * )data, CB_BUFFER_SIZE ); |
klauss | 105:a930035b6556 | 1142 | strcat( aux, "\n\r\0" ); |
klauss | 105:a930035b6556 | 1143 | udp_query_send_msg( ( char *)data ); |
klauss | 105:a930035b6556 | 1144 | udp_query_send_msg( "\r\n> " ); |
klauss | 105:a930035b6556 | 1145 | } |
klauss | 48:195c97f12e8e | 1146 | } |
klauss | 91:c2a86b1f8aaa | 1147 | } |
klauss | 91:c2a86b1f8aaa | 1148 | break; |
klauss | 0:4d17cd9c8f9d | 1149 | case __AUDIO__ : { |
klauss | 105:a930035b6556 | 1150 | /*** |
klauss | 105:a930035b6556 | 1151 | [ Principio ] |
klauss | 105:a930035b6556 | 1152 | -- Receber pacote de audio do CBx |
klauss | 105:a930035b6556 | 1153 | -- Encaminhar para o * |
klauss | 105:a930035b6556 | 1154 | -- Fluxo -- |
klauss | 105:a930035b6556 | 1155 | - Incrementa o contador de pacotes recebidos |
klauss | 105:a930035b6556 | 1156 | - Procura por este cbx no vetor logico de calls. |
klauss | 105:a930035b6556 | 1157 | - Caso nao encontre |
klauss | 105:a930035b6556 | 1158 | - Exibe mensagem de erro condicionada a debug |
klauss | 105:a930035b6556 | 1159 | - Caso encontre |
klauss | 105:a930035b6556 | 1160 | - Encaminha o pacote para o servidor |
klauss | 105:a930035b6556 | 1161 | - Reseta o timer de idle desta ligacao |
klauss | 105:a930035b6556 | 1162 | - Busca pelo CBX no vetor logico de CBx |
klauss | 105:a930035b6556 | 1163 | - Caso encontre |
klauss | 105:a930035b6556 | 1164 | - Informa que esta tendo comunicacao CBx->Header |
klauss | 105:a930035b6556 | 1165 | ***/ |
klauss | 63:0d95da692bb4 | 1166 | audio_counter++; |
klauss | 78:1353744f01e1 | 1167 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 91:c2a86b1f8aaa | 1168 | if( call != NULL ) { |
klauss | 105:a930035b6556 | 1169 | // Por definicao de projeto, os dados de audio comecam no data + 2 |
klauss | 105:a930035b6556 | 1170 | // esses 2 bytes foram usados para id de debug durante o desenvolvimento |
klauss | 91:c2a86b1f8aaa | 1171 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 0:4d17cd9c8f9d | 1172 | call->send_message( pkg ); |
klauss | 92:92df17f538a8 | 1173 | call->cbx_pkg_idle_timer_reset(); |
klauss | 78:1353744f01e1 | 1174 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 105:a930035b6556 | 1175 | if( cb != NULL ){ |
klauss | 92:92df17f538a8 | 1176 | cb->set_invite_response_ok(); |
klauss | 92:92df17f538a8 | 1177 | cb->invite_retry_count_reset(); |
klauss | 92:92df17f538a8 | 1178 | } |
klauss | 91:c2a86b1f8aaa | 1179 | } else { |
klauss | 78:1353744f01e1 | 1180 | if( debug_main ) debug_msg("received missed package from CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 1181 | } |
klauss | 91:c2a86b1f8aaa | 1182 | } |
klauss | 91:c2a86b1f8aaa | 1183 | break; |
klauss | 105:a930035b6556 | 1184 | }//end switch para tratemento de pacote baseado no type |
klauss | 105:a930035b6556 | 1185 | |
klauss | 92:92df17f538a8 | 1186 | |
klauss | 99:e80850c51106 | 1187 | { // rajada |
klauss | 105:a930035b6556 | 1188 | /*** |
klauss | 105:a930035b6556 | 1189 | [ Principio ] |
klauss | 105:a930035b6556 | 1190 | -- Verifica se existem CBx em ligaçao |
klauss | 105:a930035b6556 | 1191 | -- Verifica se os mesmos estao enviando pacotes de audio |
klauss | 105:a930035b6556 | 1192 | -- Re-envio o pacote avisando que o CBx pode entrar no status "on_call" |
klauss | 105:a930035b6556 | 1193 | ***/ |
klauss | 99:e80850c51106 | 1194 | if( invite_retry_timer.read_ms() > 30 ) { |
klauss | 99:e80850c51106 | 1195 | invite_retry_timer.reset(); |
klauss | 92:92df17f538a8 | 1196 | static int retry_invite_pkg = 0; |
klauss | 99:e80850c51106 | 1197 | |
klauss | 92:92df17f538a8 | 1198 | if( retry_invite_pkg >= v_cb->size() ) retry_invite_pkg = 0; |
klauss | 99:e80850c51106 | 1199 | |
klauss | 105:a930035b6556 | 1200 | // procura por CBx em ligaçao sequencialmente |
klauss | 99:e80850c51106 | 1201 | register int i = 0; |
klauss | 99:e80850c51106 | 1202 | for( ; i < v_cb->size(); i++ ) { |
klauss | 99:e80850c51106 | 1203 | Call_Box * cb = (Call_Box * )v_cb->get_element( i ); |
klauss | 99:e80850c51106 | 1204 | if( ( cb->status == cb_ringing ) || ( cb->status == cb_trying ) || ( cb->status == cb_on_call ) ) { |
klauss | 99:e80850c51106 | 1205 | if( i > retry_invite_pkg ) { |
klauss | 99:e80850c51106 | 1206 | retry_invite_pkg = i; |
klauss | 99:e80850c51106 | 1207 | break; |
klauss | 99:e80850c51106 | 1208 | } |
klauss | 92:92df17f538a8 | 1209 | } |
klauss | 99:e80850c51106 | 1210 | } |
klauss | 99:e80850c51106 | 1211 | |
klauss | 99:e80850c51106 | 1212 | if( i != v_cb->size() ){ |
klauss | 99:e80850c51106 | 1213 | Call_Box * cb = (Call_Box *)v_cb->get_element( retry_invite_pkg++ ); |
klauss | 105:a930035b6556 | 1214 | |
klauss | 99:e80850c51106 | 1215 | if( ( cb->status == cb_ringing ) || ( cb->status == cb_trying ) || ( cb->status == cb_on_call ) ) { |
klauss | 99:e80850c51106 | 1216 | if( cb->get_invite_response() == false ) { |
klauss | 99:e80850c51106 | 1217 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 99:e80850c51106 | 1218 | |
klauss | 99:e80850c51106 | 1219 | buffer[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 105:a930035b6556 | 1220 | |
klauss | 105:a930035b6556 | 1221 | // re-envia pacote confirmando que ligacao esta ok, CBx pode ligar o mic. e o speaker |
klauss | 105:a930035b6556 | 1222 | send2callboxes( build_cb_package( cb->get_ext(), cb->get_port(), __INVITE__, ( char * )buffer, |
klauss | 105:a930035b6556 | 1223 | cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 105:a930035b6556 | 1224 | |
klauss | 99:e80850c51106 | 1225 | if( debug_invite ) debug_msg("resend invite OK to Cbx : ( %d, %d )", cb->get_ext(), cb->get_port() ); |
klauss | 99:e80850c51106 | 1226 | } |
klauss | 105:a930035b6556 | 1227 | |
klauss | 105:a930035b6556 | 1228 | // fim das tentativas |
klauss | 99:e80850c51106 | 1229 | if( cb->get_invite_retry_count() == 0 ) { |
klauss | 99:e80850c51106 | 1230 | cb->send_bye(); |
klauss | 92:92df17f538a8 | 1231 | |
klauss | 99:e80850c51106 | 1232 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 99:e80850c51106 | 1233 | cb->set_timeslice( 0x00 ); |
klauss | 99:e80850c51106 | 1234 | |
klauss | 99:e80850c51106 | 1235 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 99:e80850c51106 | 1236 | |
klauss | 99:e80850c51106 | 1237 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 99:e80850c51106 | 1238 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 99:e80850c51106 | 1239 | if( call->get_cb_ext() == cb->get_ext() ) { |
klauss | 99:e80850c51106 | 1240 | v_call->remove_element( i ); |
klauss | 99:e80850c51106 | 1241 | if( call != NULL ) delete( call ); |
klauss | 99:e80850c51106 | 1242 | break; |
klauss | 99:e80850c51106 | 1243 | } |
klauss | 92:92df17f538a8 | 1244 | } |
klauss | 99:e80850c51106 | 1245 | |
klauss | 99:e80850c51106 | 1246 | if( debug_invite ) debug_msg( "-- No audio pkgs --" ); |
klauss | 99:e80850c51106 | 1247 | set_status( cb->status, cb_idle ); |
klauss | 99:e80850c51106 | 1248 | set_status( cb->sip->status, sip_idle ); |
klauss | 92:92df17f538a8 | 1249 | } |
klauss | 92:92df17f538a8 | 1250 | } |
klauss | 92:92df17f538a8 | 1251 | } |
klauss | 92:92df17f538a8 | 1252 | } |
klauss | 92:92df17f538a8 | 1253 | } |
klauss | 91:c2a86b1f8aaa | 1254 | |
klauss | 105:a930035b6556 | 1255 | /*** |
klauss | 105:a930035b6556 | 1256 | [ Principio ] |
klauss | 105:a930035b6556 | 1257 | -- Para cada CBx em ligaçao |
klauss | 105:a930035b6556 | 1258 | -- Verificar e encaminhar pacotes recebidos da interface ETH-Header-CBx |
klauss | 105:a930035b6556 | 1259 | -- Fluxo -- |
klauss | 105:a930035b6556 | 1260 | - Para cada elemento do vetor call |
klauss | 105:a930035b6556 | 1261 | - Verificar se consta algo pendente para processamento no sentido ETH->Header->Cbx |
klauss | 105:a930035b6556 | 1262 | - Caso existe |
klauss | 105:a930035b6556 | 1263 | - Procurar por este CBx no vetor lógico de CBx |
klauss | 105:a930035b6556 | 1264 | - Caso seja encontrado |
klauss | 105:a930035b6556 | 1265 | - Enviar pacote recebido para este CBx |
klauss | 105:a930035b6556 | 1266 | - Caso nao seja encontrado |
klauss | 105:a930035b6556 | 1267 | - Exibe msg de erro condicionado a debug |
klauss | 105:a930035b6556 | 1268 | ***/ |
klauss | 91:c2a86b1f8aaa | 1269 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 0:4d17cd9c8f9d | 1270 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 1271 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 1272 | char * tmp = call->get_eth_message( &length ); |
klauss | 91:c2a86b1f8aaa | 1273 | if( tmp != NULL ) { |
klauss | 0:4d17cd9c8f9d | 1274 | int cb_port = 0xffff; |
klauss | 78:1353744f01e1 | 1275 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 91:c2a86b1f8aaa | 1276 | |
klauss | 91:c2a86b1f8aaa | 1277 | if( cb != NULL ) { |
klauss | 4:de46f0d9b14d | 1278 | cb_port = cb->get_port(); |
klauss | 91:c2a86b1f8aaa | 1279 | |
klauss | 105:a930035b6556 | 1280 | uint8_t * pkg2cb = build_cb_package( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 100:09a23fcd3bdf | 1281 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 99:e80850c51106 | 1282 | |
klauss | 100:09a23fcd3bdf | 1283 | send2callboxes( pkg2cb ); |
klauss | 99:e80850c51106 | 1284 | |
klauss | 91:c2a86b1f8aaa | 1285 | } else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 1286 | } |
klauss | 14:22a35f575502 | 1287 | } |
klauss | 91:c2a86b1f8aaa | 1288 | |
klauss | 105:a930035b6556 | 1289 | /*** |
klauss | 105:a930035b6556 | 1290 | [ Principio ] |
klauss | 105:a930035b6556 | 1291 | -- Verificar se já se passou determinada unidade de tempo |
klauss | 105:a930035b6556 | 1292 | -- Baseado nisso, chamar a funcao [ 1 ] refresh ou [ 2 ] wake_all_up |
klauss | 105:a930035b6556 | 1293 | [ 1 ] -- Encaminha periodicamente um pacote de __REGISTRY__ para cada CBx, um por vez. |
klauss | 105:a930035b6556 | 1294 | [ 2 ] -- Busca por elementos que constem sem seus pares registrados e manda um __PROMPT__ ping para cada um, um por vez. |
klauss | 105:a930035b6556 | 1295 | ***/ |
klauss | 105:a930035b6556 | 1296 | |
klauss | 99:e80850c51106 | 1297 | if( timer_sync_refresh.read_ms() > 250 ) { |
klauss | 89:0fe315117b00 | 1298 | timer_sync_refresh.reset(); |
klauss | 91:c2a86b1f8aaa | 1299 | |
klauss | 89:0fe315117b00 | 1300 | static uint8_t mode = TIME_TO_REFRESH; |
klauss | 104:62646ef786a3 | 1301 | |
klauss | 91:c2a86b1f8aaa | 1302 | if( mode == TIME_TO_REFRESH ) { |
klauss | 89:0fe315117b00 | 1303 | mode = TIME_TO_WAKE_UP; |
klauss | 89:0fe315117b00 | 1304 | refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 91:c2a86b1f8aaa | 1305 | } else { |
klauss | 89:0fe315117b00 | 1306 | mode = TIME_TO_REFRESH; |
klauss | 105:a930035b6556 | 1307 | if( wake_all ) if( v_call->size() == 0 ) wake_all_up( v_cb, buffer, write_buffer ); |
klauss | 89:0fe315117b00 | 1308 | } |
klauss | 89:0fe315117b00 | 1309 | } |
klauss | 91:c2a86b1f8aaa | 1310 | |
klauss | 78:1353744f01e1 | 1311 | // check sip messages only for cbx in call ? |
klauss | 78:1353744f01e1 | 1312 | int ext_to__be_removed = sip_manager( v_cb ); |
klauss | 91:c2a86b1f8aaa | 1313 | if( ext_to__be_removed > 0x00 ) { |
klauss | 78:1353744f01e1 | 1314 | Call_Box * cb = __find_CB__( v_cb, ext_to__be_removed ); |
klauss | 91:c2a86b1f8aaa | 1315 | if( cb != NULL ) { |
klauss | 91:c2a86b1f8aaa | 1316 | if( cb->status == cb_on_call ) { |
klauss | 4:de46f0d9b14d | 1317 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 1318 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 1319 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 91:c2a86b1f8aaa | 1320 | |
klauss | 78:1353744f01e1 | 1321 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 1322 | set_status( cb->sip->status, sip_idle ); |
klauss | 91:c2a86b1f8aaa | 1323 | |
klauss | 91:c2a86b1f8aaa | 1324 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 4:de46f0d9b14d | 1325 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 1326 | if( call->get_cb_ext() == ext_to__be_removed ) { |
klauss | 4:de46f0d9b14d | 1327 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 1328 | delete( call ); |
klauss | 4:de46f0d9b14d | 1329 | } |
klauss | 2:93bec7313ccc | 1330 | } |
klauss | 91:c2a86b1f8aaa | 1331 | |
klauss | 92:92df17f538a8 | 1332 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 91:c2a86b1f8aaa | 1333 | |
klauss | 105:a930035b6556 | 1334 | send2callboxes( build_cb_package( ext, port, __CB_BYE__, |
klauss | 105:a930035b6556 | 1335 | ( char * )buffer, cb->get_msg_id(), CB_BUFFER_SIZE - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 91:c2a86b1f8aaa | 1336 | |
klauss | 91:c2a86b1f8aaa | 1337 | if( debug_invite ) debug_msg("Received Bye from *"); |
klauss | 0:4d17cd9c8f9d | 1338 | } |
klauss | 91:c2a86b1f8aaa | 1339 | } else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d", ext ); |
klauss | 0:4d17cd9c8f9d | 1340 | } |
klauss | 91:c2a86b1f8aaa | 1341 | |
klauss | 81:3656f00ab3db | 1342 | /* Verifica andamento de ligações para eventualmente encerra-las por timeout */ |
klauss | 10:22da1a0ac1e1 | 1343 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 91:c2a86b1f8aaa | 1344 | |
klauss | 105:a930035b6556 | 1345 | /* tratamento de pedidos de ligação já em andamento com o * */ |
klauss | 81:3656f00ab3db | 1346 | invite_handler( v_call, v_cb, ts, NULL ); |
klauss | 91:c2a86b1f8aaa | 1347 | |
klauss | 81:3656f00ab3db | 1348 | /* rotina de verificação de TS's perdidos */ |
klauss | 91:c2a86b1f8aaa | 1349 | if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != __MAX_TIMESLICES__ ) ) { |
klauss | 91:c2a86b1f8aaa | 1350 | bool ts_reset = true; |
klauss | 91:c2a86b1f8aaa | 1351 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 1352 | if ( ( ( Call_Box * )v_cb->get_element( i ) )->get_status() != cb_idle && |
klauss | 91:c2a86b1f8aaa | 1353 | ( ( Call_Box * )v_cb->get_element( i ) )->get_sip_status() != sip_idle ) { |
klauss | 78:1353744f01e1 | 1354 | ts_reset = false; |
klauss | 78:1353744f01e1 | 1355 | break; |
klauss | 78:1353744f01e1 | 1356 | } |
klauss | 91:c2a86b1f8aaa | 1357 | } |
klauss | 91:c2a86b1f8aaa | 1358 | if( ts_reset ) { |
klauss | 81:3656f00ab3db | 1359 | if( debug_invite ) debug_msg("Resetando TS"); |
klauss | 78:1353744f01e1 | 1360 | ts->reset(); |
klauss | 78:1353744f01e1 | 1361 | } |
klauss | 0:4d17cd9c8f9d | 1362 | } |
klauss | 91:c2a86b1f8aaa | 1363 | |
klauss | 81:3656f00ab3db | 1364 | /* rotina que esvazia possiveis pacotes que não foram transmitidos para evitar conflito */ |
klauss | 72:895ca792c647 | 1365 | tx_buffer_ring_buffer_handler(); |
klauss | 91:c2a86b1f8aaa | 1366 | |
klauss | 105:a930035b6556 | 1367 | // atribui o valor default para a variavel type |
klauss | 30:8dfb6d8de53d | 1368 | type = __DO_NOTHING__; |
klauss | 91:c2a86b1f8aaa | 1369 | |
klauss | 105:a930035b6556 | 1370 | // verifica o status da conexao ETH, caso exteja conectado ( == 0 ) atribui o valor maximo ao contador de controle |
klauss | 81:3656f00ab3db | 1371 | if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 91:c2a86b1f8aaa | 1372 | |
klauss | 105:a930035b6556 | 1373 | // responsavel por atualizar os contadores de controle utilizados para tickar o wdt |
klauss | 105:a930035b6556 | 1374 | // e tickar o wdt |
klauss | 91:c2a86b1f8aaa | 1375 | if( wdt_timer.read() >= 1 ) { |
klauss | 91:c2a86b1f8aaa | 1376 | //FIXME remove myself |
klauss | 83:b8a1d8fdeaeb | 1377 | uptime++; |
klauss | 91:c2a86b1f8aaa | 1378 | |
klauss | 81:3656f00ab3db | 1379 | wdt_timer.reset(); |
klauss | 91:c2a86b1f8aaa | 1380 | |
klauss | 81:3656f00ab3db | 1381 | if( wdt_show ) debug_wdt = true; |
klauss | 91:c2a86b1f8aaa | 1382 | |
klauss | 81:3656f00ab3db | 1383 | if( external_wdt ) external_wdt--; |
klauss | 81:3656f00ab3db | 1384 | if( pkg_wdt ) pkg_wdt--; |
klauss | 81:3656f00ab3db | 1385 | if( eth_wdt ) eth_wdt--; |
klauss | 91:c2a86b1f8aaa | 1386 | |
klauss | 91:c2a86b1f8aaa | 1387 | if( eth_wdt && external_wdt && pkg_wdt ){ |
klauss | 81:3656f00ab3db | 1388 | wdt.kick(); |
klauss | 81:3656f00ab3db | 1389 | } |
klauss | 81:3656f00ab3db | 1390 | } |
klauss | 105:a930035b6556 | 1391 | |
klauss | 105:a930035b6556 | 1392 | // exibe informacoes referentes ao wdt, ultimo reset, status da eth, tempo em segundos desde o ultimo tick dowdt externo, |
klauss | 105:a930035b6556 | 1393 | // tempo em segundos desde o ultimo pacote recebido da interface fibra |
klauss | 91:c2a86b1f8aaa | 1394 | if( debug_wdt ) { |
klauss | 87:679ee0d594a9 | 1395 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 1396 | lpc_low_level_input_counter = 0; |
klauss | 91:c2a86b1f8aaa | 1397 | |
klauss | 81:3656f00ab3db | 1398 | debug_wdt = false; |
klauss | 91:c2a86b1f8aaa | 1399 | if( eth_status == 0 ) { |
klauss | 91:c2a86b1f8aaa | 1400 | 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 | 91:c2a86b1f8aaa | 1401 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 91:c2a86b1f8aaa | 1402 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 91:c2a86b1f8aaa | 1403 | EXTERN_WDT_IDLE, |
klauss | 91:c2a86b1f8aaa | 1404 | RX_CB_IDLE - pkg_wdt, |
klauss | 91:c2a86b1f8aaa | 1405 | RX_CB_IDLE |
klauss | 91:c2a86b1f8aaa | 1406 | ); |
klauss | 91:c2a86b1f8aaa | 1407 | } else { |
klauss | 91:c2a86b1f8aaa | 1408 | 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 | 91:c2a86b1f8aaa | 1409 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 91:c2a86b1f8aaa | 1410 | ETH_CONNECT_TIMEOUT - eth_wdt, |
klauss | 91:c2a86b1f8aaa | 1411 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 91:c2a86b1f8aaa | 1412 | EXTERN_WDT_IDLE, |
klauss | 91:c2a86b1f8aaa | 1413 | RX_CB_IDLE - pkg_wdt, |
klauss | 91:c2a86b1f8aaa | 1414 | RX_CB_IDLE |
klauss | 91:c2a86b1f8aaa | 1415 | ); |
klauss | 81:3656f00ab3db | 1416 | } |
klauss | 81:3656f00ab3db | 1417 | } |
klauss | 105:a930035b6556 | 1418 | |
klauss | 105:a930035b6556 | 1419 | // atribui o valor default ao ponteiro de dados |
klauss | 105:a930035b6556 | 1420 | data = NULL; |
klauss | 105:a930035b6556 | 1421 | }//fim while ( main loop ) |
klauss | 0:4d17cd9c8f9d | 1422 | } |