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