Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
main.cpp@112:6ae726539ab9, 2015-04-13 (annotated)
- Committer:
- klauss
- Date:
- Mon Apr 13 12:16:21 2015 +0000
- Revision:
- 112:6ae726539ab9
- Parent:
- 111:c0833f2455ed
- Child:
- 113:db67ae00550e
colinas - ramo 3 - 2014 - 04 - 11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 109:a5b8264ffbbc | 1 | #include "telemetry.h" |
klauss | 109:a5b8264ffbbc | 2 | #include "eth.h" |
klauss | 109:a5b8264ffbbc | 3 | #include "bits.h" |
klauss | 109:a5b8264ffbbc | 4 | #include "UART3Interrupt.h" // for RXBuffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 109:a5b8264ffbbc | 5 | #include "utils.h" |
klauss | 109:a5b8264ffbbc | 6 | #include "parallelcpld.h" |
klauss | 109:a5b8264ffbbc | 7 | #include "debug.h" |
klauss | 109:a5b8264ffbbc | 8 | #include "flood.h" |
klauss | 109:a5b8264ffbbc | 9 | #include "bootloader_cbx.h" |
klauss | 109:a5b8264ffbbc | 10 | #include "call_manager.h" |
klauss | 109:a5b8264ffbbc | 11 | #include "call_box_manager.h" |
klauss | 109:a5b8264ffbbc | 12 | #include "sip_manager.h" |
klauss | 109:a5b8264ffbbc | 13 | #include "shared_variables.h" |
klauss | 109:a5b8264ffbbc | 14 | #include "prompt.h" |
klauss | 109:a5b8264ffbbc | 15 | #include "configs.h" |
klauss | 109:a5b8264ffbbc | 16 | #include "sdram.h" |
klauss | 109:a5b8264ffbbc | 17 | #include "fw.h" |
klauss | 111:c0833f2455ed | 18 | #include "bootloader.h" |
klauss | 87:679ee0d594a9 | 19 | volatile u16_t lpc_low_level_input_counter = 0; |
klauss | 85:b6f2dc1d0f4f | 20 | |
klauss | 91:c2a86b1f8aaa | 21 | int main() |
klauss | 109:a5b8264ffbbc | 22 | { |
klauss | 81:3656f00ab3db | 23 | init_wdt(); |
klauss | 91:c2a86b1f8aaa | 24 | |
klauss | 81:3656f00ab3db | 25 | config_lpc(); |
klauss | 91:c2a86b1f8aaa | 26 | |
klauss | 0:4d17cd9c8f9d | 27 | start_cpld(); |
klauss | 91:c2a86b1f8aaa | 28 | |
klauss | 100:09a23fcd3bdf | 29 | debug_uart3 = true; |
klauss | 91:c2a86b1f8aaa | 30 | if( sdram_init() == 1 ) { |
klauss | 109:a5b8264ffbbc | 31 | send_msg("******* Failed to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 32 | return 1; |
klauss | 89:0fe315117b00 | 33 | } else { |
klauss | 109:a5b8264ffbbc | 34 | send_msg("******* Success to initialize SDRAM *******"); |
klauss | 87:679ee0d594a9 | 35 | } |
klauss | 91:c2a86b1f8aaa | 36 | |
klauss | 43:455522f98de5 | 37 | init_fsystem(); |
klauss | 91:c2a86b1f8aaa | 38 | |
klauss | 89:0fe315117b00 | 39 | { |
klauss | 89:0fe315117b00 | 40 | char s[ 32 ]; |
klauss | 89:0fe315117b00 | 41 | mbed_mac_address( s ); |
klauss | 109:a5b8264ffbbc | 42 | send_msg( "::Mac::%02x:%02x:%02x:%02x:%02x:%02x:: ", s[0],s[1],s[2],s[3],s[4],s[5] ); |
klauss | 89:0fe315117b00 | 43 | } |
klauss | 91:c2a86b1f8aaa | 44 | |
klauss | 78:1353744f01e1 | 45 | short int eth_status = __init_eth__(); |
klauss | 91:c2a86b1f8aaa | 46 | if( eth_status ) { |
klauss | 109:a5b8264ffbbc | 47 | send_msg("******* Cannot connect to eth *******"); |
klauss | 91:c2a86b1f8aaa | 48 | } else { |
klauss | 109:a5b8264ffbbc | 49 | send_msg("******* Connection eth - ok *******"); |
klauss | 78:1353744f01e1 | 50 | init_prompt_eth(); |
klauss | 111:c0833f2455ed | 51 | init_external_wdt(); |
klauss | 111:c0833f2455ed | 52 | init_bl(); |
klauss | 8:e3bfe62a477e | 53 | } |
klauss | 91:c2a86b1f8aaa | 54 | |
klauss | 78:1353744f01e1 | 55 | Timer sync_timer, led_sync_timer; |
klauss | 109:a5b8264ffbbc | 56 | sync_timer.start(), led_sync_timer.start(); |
klauss | 91:c2a86b1f8aaa | 57 | |
klauss | 109:a5b8264ffbbc | 58 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 59 | int ext = 0; |
klauss | 91:c2a86b1f8aaa | 60 | |
klauss | 109:a5b8264ffbbc | 61 | /* representa porta do call box */ |
klauss | 78:1353744f01e1 | 62 | int port = 0; |
klauss | 91:c2a86b1f8aaa | 63 | |
klauss | 109:a5b8264ffbbc | 64 | /* buffer para onde se copia os dados vindos do cb para tratameno interno */ |
klauss | 109:a5b8264ffbbc | 65 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 91:c2a86b1f8aaa | 66 | |
klauss | 109:a5b8264ffbbc | 67 | /* buffer de escrita do pacote de saida que sera enviado pro cb / servidor */ |
klauss | 109:a5b8264ffbbc | 68 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 91:c2a86b1f8aaa | 69 | |
klauss | 109:a5b8264ffbbc | 70 | /* ponteiro que aponta para os dados vindo do CPLD */ |
klauss | 0:4d17cd9c8f9d | 71 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 91:c2a86b1f8aaa | 72 | |
klauss | 109:a5b8264ffbbc | 73 | /* Armazena o ultimo pacote recebido dos CBx */ |
klauss | 109:a5b8264ffbbc | 74 | uint8_t cb_rx_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 91:c2a86b1f8aaa | 75 | |
klauss | 109:a5b8264ffbbc | 76 | /* referencia para os dados contidos no pacote, sem o header */ |
klauss | 0:4d17cd9c8f9d | 77 | uint8_t * data = NULL; |
klauss | 91:c2a86b1f8aaa | 78 | |
klauss | 109:a5b8264ffbbc | 79 | /* gerencia o tipo do pacote para providenciar tratamento adequado */ |
klauss | 0:4d17cd9c8f9d | 80 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 91:c2a86b1f8aaa | 81 | |
klauss | 109:a5b8264ffbbc | 82 | /* representa a lista dos Call Boxes atualmente recfonhecidos pela cabeceira */ |
klauss | 0:4d17cd9c8f9d | 83 | Vector * v_cb = new Vector(); |
klauss | 91:c2a86b1f8aaa | 84 | |
klauss | 109:a5b8264ffbbc | 85 | /* representa a lista de ligacoes ativas na cabeceira */ |
klauss | 0:4d17cd9c8f9d | 86 | Vector * v_call = new Vector(); |
klauss | 91:c2a86b1f8aaa | 87 | |
klauss | 109:a5b8264ffbbc | 88 | /* gerencia a distribuicao de timeslice para os call boxes */ |
klauss | 0:4d17cd9c8f9d | 89 | Timeslice * ts = new Timeslice(); |
klauss | 91:c2a86b1f8aaa | 90 | if( ts == NULL ) { |
klauss | 89:0fe315117b00 | 91 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 92 | if( debug_memory ) debug_msg("TS allocation fail"); |
klauss | 89:0fe315117b00 | 93 | } |
klauss | 91:c2a86b1f8aaa | 94 | |
klauss | 109:a5b8264ffbbc | 95 | /* instancia o vetor de call boxes // calls */ |
klauss | 91:c2a86b1f8aaa | 96 | if( v_cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 97 | while( v_cb == NULL ) { |
klauss | 0:4d17cd9c8f9d | 98 | Vector * v_cb = new Vector(); |
klauss | 91:c2a86b1f8aaa | 99 | if( sync_timer.read() > 5 ) { |
klauss | 48:195c97f12e8e | 100 | send_msg("Erro ao alocar o vetor de CBx"); |
klauss | 78:1353744f01e1 | 101 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 102 | } |
klauss | 0:4d17cd9c8f9d | 103 | } |
klauss | 109:a5b8264ffbbc | 104 | } else 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 | 109:a5b8264ffbbc | 124 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) { |
klauss | 63:0d95da692bb4 | 125 | cb_rx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 126 | cb_tx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 127 | } |
klauss | 91:c2a86b1f8aaa | 128 | |
klauss | 0:4d17cd9c8f9d | 129 | reset_leds(); |
klauss | 91:c2a86b1f8aaa | 130 | |
klauss | 33:735fd60e96d8 | 131 | udp_timer.start(); |
klauss | 109:a5b8264ffbbc | 132 | |
klauss | 109:a5b8264ffbbc | 133 | init_telemetry_handler(); |
klauss | 99:e80850c51106 | 134 | |
klauss | 109:a5b8264ffbbc | 135 | //debug_msg(""); |
klauss | 99:e80850c51106 | 136 | init_fw_handler(); |
klauss | 109:a5b8264ffbbc | 137 | //debug_msg(""); |
klauss | 99:e80850c51106 | 138 | |
klauss | 99:e80850c51106 | 139 | led2 = 0; |
klauss | 81:3656f00ab3db | 140 | init_ranges(); |
klauss | 109:a5b8264ffbbc | 141 | |
klauss | 80:61d61c9eb75c | 142 | init_refresh(); |
klauss | 91:c2a86b1f8aaa | 143 | |
klauss | 78:1353744f01e1 | 144 | init_aging(); |
klauss | 91:c2a86b1f8aaa | 145 | |
klauss | 89:0fe315117b00 | 146 | init_sync_refresh(); |
klauss | 91:c2a86b1f8aaa | 147 | |
klauss | 109:a5b8264ffbbc | 148 | //init_invite_pgk_retry_manager(); |
klauss | 109:a5b8264ffbbc | 149 | |
klauss | 109:a5b8264ffbbc | 150 | //void init_bye_pgk_retry_manager(); |
klauss | 109:a5b8264ffbbc | 151 | |
klauss | 62:07e5bdc9f8f7 | 152 | static uint8_t count = 0; |
klauss | 91:c2a86b1f8aaa | 153 | |
klauss | 109:a5b8264ffbbc | 154 | //short int bl_ret = init_bl_handler(); |
klauss | 109:a5b8264ffbbc | 155 | //if( dbl ) send_msg("Valor de retorno do bl_habdler = %d", bl_ret ); |
klauss | 109:a5b8264ffbbc | 156 | |
klauss | 78:1353744f01e1 | 157 | uint8_t max_registered_cbx = 0; |
klauss | 91:c2a86b1f8aaa | 158 | |
klauss | 81:3656f00ab3db | 159 | bool wake_all = false; |
klauss | 91:c2a86b1f8aaa | 160 | |
klauss | 81:3656f00ab3db | 161 | uint16_t pkg_wdt = RX_CB_IDLE; |
klauss | 81:3656f00ab3db | 162 | uint16_t eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 109:a5b8264ffbbc | 163 | uint32_t uptime = 0; |
klauss | 109:a5b8264ffbbc | 164 | led1 = 0; |
klauss | 109:a5b8264ffbbc | 165 | send_msg("Ready"); |
klauss | 109:a5b8264ffbbc | 166 | |
klauss | 109:a5b8264ffbbc | 167 | //bool registry_test = false; |
klauss | 109:a5b8264ffbbc | 168 | //static int next_value = 5002; |
klauss | 109:a5b8264ffbbc | 169 | //static int nex_test_registry = next_value; |
klauss | 105:a930035b6556 | 170 | |
klauss | 109:a5b8264ffbbc | 171 | //bool invite_retry_time = false; |
klauss | 99:e80850c51106 | 172 | Timer invite_retry_timer; |
klauss | 99:e80850c51106 | 173 | invite_retry_timer.start(); |
klauss | 109:a5b8264ffbbc | 174 | debug_uart3 = false; |
klauss | 105:a930035b6556 | 175 | |
klauss | 109:a5b8264ffbbc | 176 | Timer test_timer; |
klauss | 91:c2a86b1f8aaa | 177 | |
klauss | 78:1353744f01e1 | 178 | /*------------------------------------------ main loop ---------------------------------------------------------------*/ |
klauss | 91:c2a86b1f8aaa | 179 | while( true ) { |
klauss | 109:a5b8264ffbbc | 180 | reset_leds(); |
klauss | 109:a5b8264ffbbc | 181 | // need be removed; |
klauss | 99:e80850c51106 | 182 | |
klauss | 78:1353744f01e1 | 183 | if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 184 | |
klauss | 91:c2a86b1f8aaa | 185 | if( sync_timer.read() > 5 ) { |
klauss | 78:1353744f01e1 | 186 | sync_timer.reset(); |
klauss | 91:c2a86b1f8aaa | 187 | |
klauss | 91:c2a86b1f8aaa | 188 | if( debug_cks == true ) { |
klauss | 81:3656f00ab3db | 189 | pcks_s = true; |
klauss | 78:1353744f01e1 | 190 | } |
klauss | 91:c2a86b1f8aaa | 191 | |
klauss | 91:c2a86b1f8aaa | 192 | if( debug_alive == true ) { |
klauss | 81:3656f00ab3db | 193 | pshowcb = true; |
klauss | 78:1353744f01e1 | 194 | } |
klauss | 100:09a23fcd3bdf | 195 | |
klauss | 109:a5b8264ffbbc | 196 | |
klauss | 105:a930035b6556 | 197 | { |
klauss | 109:a5b8264ffbbc | 198 | // debug_msg("Enviei"); |
klauss | 109:a5b8264ffbbc | 199 | // send2callboxes( __build_cb_package__( 5000, 5000, __INVITE__, |
klauss | 109:a5b8264ffbbc | 200 | // ( char * )buffer, 0x12, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 109:a5b8264ffbbc | 201 | // v_cb -> add ( new Call_Box ( 5010, 5010 ) ); |
klauss | 105:a930035b6556 | 202 | } |
klauss | 105:a930035b6556 | 203 | |
klauss | 109:a5b8264ffbbc | 204 | if( !( ++count % 15 ) ) { |
klauss | 91:c2a86b1f8aaa | 205 | if( eth_status ) { |
klauss | 78:1353744f01e1 | 206 | eth_status = __init_eth__(); |
klauss | 91:c2a86b1f8aaa | 207 | if( eth_status ) { |
klauss | 109:a5b8264ffbbc | 208 | if( debug_main ) debug_msg("Cannot connect to eth"); |
klauss | 91:c2a86b1f8aaa | 209 | } else { |
klauss | 109:a5b8264ffbbc | 210 | if( debug_main ) debug_msg("Connection eth - ok"); |
klauss | 78:1353744f01e1 | 211 | init_prompt_eth(); |
klauss | 111:c0833f2455ed | 212 | init_external_wdt(); |
klauss | 111:c0833f2455ed | 213 | init_bl(); |
klauss | 78:1353744f01e1 | 214 | } |
klauss | 78:1353744f01e1 | 215 | } |
klauss | 78:1353744f01e1 | 216 | } |
klauss | 100:09a23fcd3bdf | 217 | |
klauss | 109:a5b8264ffbbc | 218 | //35 sec. |
klauss | 91:c2a86b1f8aaa | 219 | if( ( count > 7 ) && ( wake_all == false ) ) { |
klauss | 81:3656f00ab3db | 220 | wake_all = true; |
klauss | 78:1353744f01e1 | 221 | if( debug_wake == true ) send_msg( "Time to wake" ); |
klauss | 78:1353744f01e1 | 222 | } |
klauss | 109:a5b8264ffbbc | 223 | } |
klauss | 91:c2a86b1f8aaa | 224 | |
klauss | 109:a5b8264ffbbc | 225 | //FIXMEj colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ... |
klauss | 109:a5b8264ffbbc | 226 | prompt_process( NULL ); |
klauss | 109:a5b8264ffbbc | 227 | |
klauss | 91:c2a86b1f8aaa | 228 | if( r_stats ) { |
klauss | 91:c2a86b1f8aaa | 229 | boot_counter = 0; |
klauss | 91:c2a86b1f8aaa | 230 | registry_counter = 0; |
klauss | 91:c2a86b1f8aaa | 231 | invite_counter = 0; |
klauss | 91:c2a86b1f8aaa | 232 | audio_counter = 0; |
klauss | 91:c2a86b1f8aaa | 233 | telemetry_counter = 0; |
klauss | 91:c2a86b1f8aaa | 234 | cb_bye_counter = 0; |
klauss | 91:c2a86b1f8aaa | 235 | prompt_counter = 0; |
klauss | 91:c2a86b1f8aaa | 236 | flood_counter = 0; |
klauss | 67:cdedc64d9921 | 237 | bootloader_cbx_counter = 0; |
klauss | 99:e80850c51106 | 238 | cb_stats_counter = 0; |
klauss | 63:0d95da692bb4 | 239 | r_stats = false; |
klauss | 63:0d95da692bb4 | 240 | stats = true; |
klauss | 63:0d95da692bb4 | 241 | } |
klauss | 91:c2a86b1f8aaa | 242 | |
klauss | 91:c2a86b1f8aaa | 243 | if( stats ) { |
klauss | 63:0d95da692bb4 | 244 | char str[ 200 ]; |
klauss | 109:a5b8264ffbbc | 245 | snprintf( str, 200, "\n\rReceived 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", |
klauss | 109:a5b8264ffbbc | 246 | boot_counter, registry_counter, invite_counter, audio_counter, telemetry_counter, cb_stats_counter, cb_bye_counter, prompt_counter, flood_counter, bootloader_cbx_counter ); |
klauss | 63:0d95da692bb4 | 247 | send_msg( str ); |
klauss | 63:0d95da692bb4 | 248 | stats =false; |
klauss | 63:0d95da692bb4 | 249 | } |
klauss | 109:a5b8264ffbbc | 250 | |
klauss | 109:a5b8264ffbbc | 251 | if( list ) { |
klauss | 78:1353744f01e1 | 252 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 253 | |
klauss | 78:1353744f01e1 | 254 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 255 | |
klauss | 78:1353744f01e1 | 256 | if( min_ext % 2 ) missed_cb++; |
klauss | 91:c2a86b1f8aaa | 257 | |
klauss | 78:1353744f01e1 | 258 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 91:c2a86b1f8aaa | 259 | |
klauss | 78:1353744f01e1 | 260 | 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 | 261 | if( v_cb->size() == 1 ) { |
klauss | 78:1353744f01e1 | 262 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 91:c2a86b1f8aaa | 263 | } else if( v_cb->size() > 1 ) { |
klauss | 62:07e5bdc9f8f7 | 264 | char str[ 1024 ]; |
klauss | 78:1353744f01e1 | 265 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 62:07e5bdc9f8f7 | 266 | register int i = 0; |
klauss | 91:c2a86b1f8aaa | 267 | for( ; i < v_cb->size(); i++ ) { |
klauss | 78:1353744f01e1 | 268 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 62:07e5bdc9f8f7 | 269 | } |
klauss | 91:c2a86b1f8aaa | 270 | |
klauss | 62:07e5bdc9f8f7 | 271 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 91:c2a86b1f8aaa | 272 | |
klauss | 62:07e5bdc9f8f7 | 273 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 274 | strcpy( str, "\r\n> " ); |
klauss | 91:c2a86b1f8aaa | 275 | for( i = 0; i < v_cb->size() - 1; i++ ) { |
klauss | 62:07e5bdc9f8f7 | 276 | sprintf( aux, "%i, ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 277 | strcat( str, aux ); |
klauss | 78:1353744f01e1 | 278 | if( ( i != 0 ) && !( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 279 | } |
klauss | 62:07e5bdc9f8f7 | 280 | sprintf( aux, "%i ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 281 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 282 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 283 | } |
klauss | 91:c2a86b1f8aaa | 284 | list = false; |
klauss | 109:a5b8264ffbbc | 285 | } |
klauss | 109:a5b8264ffbbc | 286 | |
klauss | 106:a34fcf9f0e02 | 287 | if( long_list ) |
klauss | 106:a34fcf9f0e02 | 288 | { |
klauss | 106:a34fcf9f0e02 | 289 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 91:c2a86b1f8aaa | 290 | |
klauss | 106:a34fcf9f0e02 | 291 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 106:a34fcf9f0e02 | 292 | |
klauss | 106:a34fcf9f0e02 | 293 | if( min_ext % 2 ) missed_cb++; |
klauss | 106:a34fcf9f0e02 | 294 | |
klauss | 106:a34fcf9f0e02 | 295 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 106:a34fcf9f0e02 | 296 | |
klauss | 106:a34fcf9f0e02 | 297 | { |
klauss | 106:a34fcf9f0e02 | 298 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 106:a34fcf9f0e02 | 299 | |
klauss | 106:a34fcf9f0e02 | 300 | if( v_cb->size() >= 1 ) { |
klauss | 106:a34fcf9f0e02 | 301 | for( register int i = 0; i < v_cb->size(); i++ ) |
klauss | 106:a34fcf9f0e02 | 302 | { |
klauss | 106:a34fcf9f0e02 | 303 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 106:a34fcf9f0e02 | 304 | } |
klauss | 106:a34fcf9f0e02 | 305 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 106:a34fcf9f0e02 | 306 | } |
klauss | 106:a34fcf9f0e02 | 307 | |
klauss | 106:a34fcf9f0e02 | 308 | 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 | 106:a34fcf9f0e02 | 309 | |
klauss | 106:a34fcf9f0e02 | 310 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 106:a34fcf9f0e02 | 311 | |
klauss | 106:a34fcf9f0e02 | 312 | Call_Box * cb = __find_CB__( v_cb, ext_list[ i ] ); |
klauss | 106:a34fcf9f0e02 | 313 | |
klauss | 106:a34fcf9f0e02 | 314 | if( cb != NULL ) |
klauss | 106:a34fcf9f0e02 | 315 | { |
klauss | 106:a34fcf9f0e02 | 316 | char cb_status[ 32 ]; |
klauss | 106:a34fcf9f0e02 | 317 | char cb_sip_status[ 32 ]; |
klauss | 106:a34fcf9f0e02 | 318 | switch( cb->status ) { |
klauss | 106:a34fcf9f0e02 | 319 | case cb_idle : { |
klauss | 106:a34fcf9f0e02 | 320 | strcpy( cb_status, "cb_idle" ); |
klauss | 106:a34fcf9f0e02 | 321 | break; |
klauss | 106:a34fcf9f0e02 | 322 | } |
klauss | 106:a34fcf9f0e02 | 323 | case cb_ringing : { |
klauss | 106:a34fcf9f0e02 | 324 | strcpy( cb_status, "cb_ringing" ); |
klauss | 106:a34fcf9f0e02 | 325 | break; |
klauss | 106:a34fcf9f0e02 | 326 | } |
klauss | 106:a34fcf9f0e02 | 327 | case cb_trying : { |
klauss | 106:a34fcf9f0e02 | 328 | strcpy( cb_status,"cb_trying" ); |
klauss | 106:a34fcf9f0e02 | 329 | break; |
klauss | 106:a34fcf9f0e02 | 330 | } |
klauss | 106:a34fcf9f0e02 | 331 | case cb_on_call : { |
klauss | 106:a34fcf9f0e02 | 332 | strcpy( cb_status, "cb_on_call" ); |
klauss | 106:a34fcf9f0e02 | 333 | break; |
klauss | 106:a34fcf9f0e02 | 334 | } |
klauss | 106:a34fcf9f0e02 | 335 | case cb_busy : { |
klauss | 106:a34fcf9f0e02 | 336 | strcpy( cb_status, "cb_busy" ); |
klauss | 106:a34fcf9f0e02 | 337 | break; |
klauss | 106:a34fcf9f0e02 | 338 | } |
klauss | 106:a34fcf9f0e02 | 339 | case cb_denied : { |
klauss | 106:a34fcf9f0e02 | 340 | strcpy( cb_status, "cb_denied" ); |
klauss | 106:a34fcf9f0e02 | 341 | break; |
klauss | 106:a34fcf9f0e02 | 342 | } |
klauss | 106:a34fcf9f0e02 | 343 | } |
klauss | 106:a34fcf9f0e02 | 344 | switch( cb->sip->status ) { |
klauss | 106:a34fcf9f0e02 | 345 | case sip_idle : { |
klauss | 106:a34fcf9f0e02 | 346 | strcpy( cb_sip_status, "sip_idle" ); |
klauss | 106:a34fcf9f0e02 | 347 | break; |
klauss | 106:a34fcf9f0e02 | 348 | } |
klauss | 106:a34fcf9f0e02 | 349 | case sip_waiting_trying : { |
klauss | 106:a34fcf9f0e02 | 350 | strcpy( cb_sip_status, "sip_waiting_trying" ); |
klauss | 106:a34fcf9f0e02 | 351 | break; |
klauss | 106:a34fcf9f0e02 | 352 | } |
klauss | 106:a34fcf9f0e02 | 353 | case sip_trying : { |
klauss | 106:a34fcf9f0e02 | 354 | strcpy( cb_sip_status, "sip_trying" ); |
klauss | 106:a34fcf9f0e02 | 355 | break; |
klauss | 106:a34fcf9f0e02 | 356 | } |
klauss | 106:a34fcf9f0e02 | 357 | case sip_ringing : { |
klauss | 106:a34fcf9f0e02 | 358 | strcpy( cb_sip_status, "sip_ringing" ); |
klauss | 106:a34fcf9f0e02 | 359 | break; |
klauss | 106:a34fcf9f0e02 | 360 | } |
klauss | 106:a34fcf9f0e02 | 361 | case sip_busy : { |
klauss | 106:a34fcf9f0e02 | 362 | strcpy( cb_sip_status, "sip_busy" ); |
klauss | 106:a34fcf9f0e02 | 363 | break; |
klauss | 106:a34fcf9f0e02 | 364 | } |
klauss | 106:a34fcf9f0e02 | 365 | case sip_ok : { |
klauss | 106:a34fcf9f0e02 | 366 | strcpy( cb_sip_status, "sip_ok" ); |
klauss | 106:a34fcf9f0e02 | 367 | break; |
klauss | 106:a34fcf9f0e02 | 368 | } |
klauss | 106:a34fcf9f0e02 | 369 | case sip_on_call : { |
klauss | 106:a34fcf9f0e02 | 370 | strcpy( cb_sip_status, "sip_on_call" ); |
klauss | 106:a34fcf9f0e02 | 371 | break; |
klauss | 106:a34fcf9f0e02 | 372 | } |
klauss | 106:a34fcf9f0e02 | 373 | case sip_denied : { |
klauss | 106:a34fcf9f0e02 | 374 | strcpy( cb_sip_status, "sip_denied" ); |
klauss | 106:a34fcf9f0e02 | 375 | break; |
klauss | 106:a34fcf9f0e02 | 376 | } |
klauss | 106:a34fcf9f0e02 | 377 | } |
klauss | 106:a34fcf9f0e02 | 378 | char cbx_to_string[ 254 ]; |
klauss | 106:a34fcf9f0e02 | 379 | char aux[ 16 ]; |
klauss | 106:a34fcf9f0e02 | 380 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 106:a34fcf9f0e02 | 381 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 106:a34fcf9f0e02 | 382 | strcat( cbx_to_string, aux ); |
klauss | 106:a34fcf9f0e02 | 383 | strcat( cbx_to_string, " :: Port :: " ); |
klauss | 106:a34fcf9f0e02 | 384 | itoa( cb->get_port(), aux , 10 ); |
klauss | 106:a34fcf9f0e02 | 385 | strcat( cbx_to_string, aux ); |
klauss | 106:a34fcf9f0e02 | 386 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 106:a34fcf9f0e02 | 387 | strcat( cbx_to_string, cb_status ); |
klauss | 106:a34fcf9f0e02 | 388 | strcat( cbx_to_string, " - " ); |
klauss | 106:a34fcf9f0e02 | 389 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 106:a34fcf9f0e02 | 390 | if( cb->get_timeslice() != 0 ) { |
klauss | 106:a34fcf9f0e02 | 391 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 106:a34fcf9f0e02 | 392 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 106:a34fcf9f0e02 | 393 | strcat( cbx_to_string, aux ); |
klauss | 106:a34fcf9f0e02 | 394 | } |
klauss | 106:a34fcf9f0e02 | 395 | send_msg( cbx_to_string ); |
klauss | 106:a34fcf9f0e02 | 396 | } |
klauss | 106:a34fcf9f0e02 | 397 | } |
klauss | 106:a34fcf9f0e02 | 398 | |
klauss | 106:a34fcf9f0e02 | 399 | } |
klauss | 91:c2a86b1f8aaa | 400 | long_list = false; |
klauss | 52:12930cef17c4 | 401 | } |
klauss | 91:c2a86b1f8aaa | 402 | |
klauss | 109:a5b8264ffbbc | 403 | if( pshowcb == true ) { |
klauss | 78:1353744f01e1 | 404 | 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 | 405 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 30:8dfb6d8de53d | 406 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 407 | char cb_status[ 32 ]; |
klauss | 78:1353744f01e1 | 408 | char cb_sip_status[ 32 ]; |
klauss | 91:c2a86b1f8aaa | 409 | switch( cb->status ) { |
klauss | 91:c2a86b1f8aaa | 410 | case cb_idle : { |
klauss | 91:c2a86b1f8aaa | 411 | strcpy( cb_status, "cb_idle" ); |
klauss | 91:c2a86b1f8aaa | 412 | break; |
klauss | 91:c2a86b1f8aaa | 413 | } |
klauss | 91:c2a86b1f8aaa | 414 | case cb_ringing : { |
klauss | 91:c2a86b1f8aaa | 415 | strcpy( cb_status, "cb_ringing" ); |
klauss | 91:c2a86b1f8aaa | 416 | break; |
klauss | 91:c2a86b1f8aaa | 417 | } |
klauss | 91:c2a86b1f8aaa | 418 | case cb_trying : { |
klauss | 91:c2a86b1f8aaa | 419 | strcpy( cb_status,"cb_trying" ); |
klauss | 91:c2a86b1f8aaa | 420 | break; |
klauss | 91:c2a86b1f8aaa | 421 | } |
klauss | 91:c2a86b1f8aaa | 422 | case cb_on_call : { |
klauss | 91:c2a86b1f8aaa | 423 | strcpy( cb_status, "cb_on_call" ); |
klauss | 91:c2a86b1f8aaa | 424 | break; |
klauss | 91:c2a86b1f8aaa | 425 | } |
klauss | 91:c2a86b1f8aaa | 426 | case cb_busy : { |
klauss | 91:c2a86b1f8aaa | 427 | strcpy( cb_status, "cb_busy" ); |
klauss | 91:c2a86b1f8aaa | 428 | break; |
klauss | 91:c2a86b1f8aaa | 429 | } |
klauss | 91:c2a86b1f8aaa | 430 | case cb_denied : { |
klauss | 91:c2a86b1f8aaa | 431 | strcpy( cb_status, "cb_denied" ); |
klauss | 91:c2a86b1f8aaa | 432 | break; |
klauss | 91:c2a86b1f8aaa | 433 | } |
klauss | 78:1353744f01e1 | 434 | } |
klauss | 91:c2a86b1f8aaa | 435 | switch( cb->sip->status ) { |
klauss | 91:c2a86b1f8aaa | 436 | case sip_idle : { |
klauss | 91:c2a86b1f8aaa | 437 | strcpy( cb_sip_status, "sip_idle" ); |
klauss | 91:c2a86b1f8aaa | 438 | break; |
klauss | 91:c2a86b1f8aaa | 439 | } |
klauss | 91:c2a86b1f8aaa | 440 | case sip_waiting_trying : { |
klauss | 91:c2a86b1f8aaa | 441 | strcpy( cb_sip_status, "sip_waiting_trying" ); |
klauss | 91:c2a86b1f8aaa | 442 | break; |
klauss | 91:c2a86b1f8aaa | 443 | } |
klauss | 91:c2a86b1f8aaa | 444 | case sip_trying : { |
klauss | 91:c2a86b1f8aaa | 445 | strcpy( cb_sip_status, "sip_trying" ); |
klauss | 91:c2a86b1f8aaa | 446 | break; |
klauss | 91:c2a86b1f8aaa | 447 | } |
klauss | 91:c2a86b1f8aaa | 448 | case sip_ringing : { |
klauss | 91:c2a86b1f8aaa | 449 | strcpy( cb_sip_status, "sip_ringing" ); |
klauss | 91:c2a86b1f8aaa | 450 | break; |
klauss | 91:c2a86b1f8aaa | 451 | } |
klauss | 91:c2a86b1f8aaa | 452 | case sip_busy : { |
klauss | 91:c2a86b1f8aaa | 453 | strcpy( cb_sip_status, "sip_busy" ); |
klauss | 91:c2a86b1f8aaa | 454 | break; |
klauss | 91:c2a86b1f8aaa | 455 | } |
klauss | 91:c2a86b1f8aaa | 456 | case sip_ok : { |
klauss | 91:c2a86b1f8aaa | 457 | strcpy( cb_sip_status, "sip_ok" ); |
klauss | 91:c2a86b1f8aaa | 458 | break; |
klauss | 91:c2a86b1f8aaa | 459 | } |
klauss | 91:c2a86b1f8aaa | 460 | case sip_on_call : { |
klauss | 91:c2a86b1f8aaa | 461 | strcpy( cb_sip_status, "sip_on_call" ); |
klauss | 91:c2a86b1f8aaa | 462 | break; |
klauss | 91:c2a86b1f8aaa | 463 | } |
klauss | 91:c2a86b1f8aaa | 464 | case sip_denied : { |
klauss | 91:c2a86b1f8aaa | 465 | strcpy( cb_sip_status, "sip_denied" ); |
klauss | 91:c2a86b1f8aaa | 466 | break; |
klauss | 91:c2a86b1f8aaa | 467 | } |
klauss | 78:1353744f01e1 | 468 | } |
klauss | 78:1353744f01e1 | 469 | char cbx_to_string[ 254 ]; |
klauss | 78:1353744f01e1 | 470 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 471 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 78:1353744f01e1 | 472 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 98:43b45f26b430 | 473 | strcat( cbx_to_string, aux ); |
klauss | 97:8985817e8847 | 474 | strcat( cbx_to_string, " :: Port :: " ); |
klauss | 97:8985817e8847 | 475 | itoa( cb->get_port(), aux , 10 ); |
klauss | 78:1353744f01e1 | 476 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 477 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 78:1353744f01e1 | 478 | strcat( cbx_to_string, cb_status ); |
klauss | 78:1353744f01e1 | 479 | strcat( cbx_to_string, " - " ); |
klauss | 78:1353744f01e1 | 480 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 91:c2a86b1f8aaa | 481 | if( cb->get_timeslice() != 0 ) { |
klauss | 78:1353744f01e1 | 482 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 78:1353744f01e1 | 483 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 78:1353744f01e1 | 484 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 485 | } |
klauss | 78:1353744f01e1 | 486 | send_msg( cbx_to_string ); |
klauss | 48:195c97f12e8e | 487 | } |
klauss | 78:1353744f01e1 | 488 | pshowcb = false; |
klauss | 48:195c97f12e8e | 489 | } |
klauss | 97:8985817e8847 | 490 | |
klauss | 97:8985817e8847 | 491 | if( show_sip == true ){ |
klauss | 97:8985817e8847 | 492 | show_sip = false; |
klauss | 99:e80850c51106 | 493 | send_msg(":: Sip :: %u", v_cb->size() ); |
klauss | 97:8985817e8847 | 494 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 97:8985817e8847 | 495 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 109:a5b8264ffbbc | 496 | send_msg("ext :: %d -- port :: %d -- timer %d", cb->get_sip_ext(), cb->get_sip_port(), cb->get_timer() ); |
klauss | 97:8985817e8847 | 497 | } |
klauss | 97:8985817e8847 | 498 | } |
klauss | 91:c2a86b1f8aaa | 499 | |
klauss | 81:3656f00ab3db | 500 | if( pflood == true ) flood(); |
klauss | 91:c2a86b1f8aaa | 501 | |
klauss | 91:c2a86b1f8aaa | 502 | if( debug_eth ) { |
klauss | 81:3656f00ab3db | 503 | debug_eth = false; |
klauss | 81:3656f00ab3db | 504 | send_msg("Eth status %s", ( eth_status == 0 ) ? "Connected" : "Disconnected" ); |
klauss | 81:3656f00ab3db | 505 | } |
klauss | 91:c2a86b1f8aaa | 506 | |
klauss | 91:c2a86b1f8aaa | 507 | if( status != __WAITING__ ) { |
klauss | 81:3656f00ab3db | 508 | pkg_wdt = RX_CB_IDLE; |
klauss | 109:a5b8264ffbbc | 509 | xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 510 | status = __WAITING__; |
klauss | 81:3656f00ab3db | 511 | missed_pkg--; |
klauss | 109:a5b8264ffbbc | 512 | xmemcpy( buffer, cb_rx_buffer, __CB_BUFFER_SIZE__ ); |
klauss | 109:a5b8264ffbbc | 513 | |
klauss | 109:a5b8264ffbbc | 514 | /* |
klauss | 109:a5b8264ffbbc | 515 | { |
klauss | 109:a5b8264ffbbc | 516 | uint16_t e, p; |
klauss | 109:a5b8264ffbbc | 517 | e = buffer[0]; |
klauss | 109:a5b8264ffbbc | 518 | e <<= 8; |
klauss | 109:a5b8264ffbbc | 519 | e |= buffer[1]; |
klauss | 109:a5b8264ffbbc | 520 | p = buffer[2]; |
klauss | 109:a5b8264ffbbc | 521 | p <<= 8; |
klauss | 109:a5b8264ffbbc | 522 | p |= buffer[3]; |
klauss | 109:a5b8264ffbbc | 523 | //if (e != (p+100)) { |
klauss | 109:a5b8264ffbbc | 524 | if( ( buffer[0] == 0x14 ) && ( buffer[1] == 0x0a ) ) { |
klauss | 109:a5b8264ffbbc | 525 | int i; |
klauss | 109:a5b8264ffbbc | 526 | char s[400], ss[4];; |
klauss | 109:a5b8264ffbbc | 527 | strcpy(s,"OPS-PKG:"); |
klauss | 109:a5b8264ffbbc | 528 | for (i=0; i<40; i++) { |
klauss | 109:a5b8264ffbbc | 529 | sprintf(ss," %02x",buffer[i]); |
klauss | 109:a5b8264ffbbc | 530 | strcat(s,ss); |
klauss | 109:a5b8264ffbbc | 531 | } |
klauss | 109:a5b8264ffbbc | 532 | debug_msg( s ); |
klauss | 109:a5b8264ffbbc | 533 | } |
klauss | 109:a5b8264ffbbc | 534 | } |
klauss | 109:a5b8264ffbbc | 535 | */ |
klauss | 109:a5b8264ffbbc | 536 | |
klauss | 109:a5b8264ffbbc | 537 | if( debug_cpld ) { |
klauss | 109:a5b8264ffbbc | 538 | rx = true; |
klauss | 109:a5b8264ffbbc | 539 | tx = true; |
klauss | 109:a5b8264ffbbc | 540 | } |
klauss | 91:c2a86b1f8aaa | 541 | |
klauss | 91:c2a86b1f8aaa | 542 | if( rx ) { |
klauss | 81:3656f00ab3db | 543 | char str[ 1024 ]; |
klauss | 81:3656f00ab3db | 544 | strcpy( str, "RX :: \n\r " ); |
klauss | 109:a5b8264ffbbc | 545 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ) { |
klauss | 81:3656f00ab3db | 546 | char tmp[ 16 ]; |
klauss | 81:3656f00ab3db | 547 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 81:3656f00ab3db | 548 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 91:c2a86b1f8aaa | 549 | |
klauss | 81:3656f00ab3db | 550 | else strcat( str, " " ); |
klauss | 81:3656f00ab3db | 551 | } |
klauss | 81:3656f00ab3db | 552 | send_msg( "%s", str ); |
klauss | 91:c2a86b1f8aaa | 553 | rx = false; |
klauss | 81:3656f00ab3db | 554 | } |
klauss | 91:c2a86b1f8aaa | 555 | |
klauss | 109:a5b8264ffbbc | 556 | data = __parse_vz_pkg__( &ext, &port, &type, buffer ); |
klauss | 109:a5b8264ffbbc | 557 | |
klauss | 91:c2a86b1f8aaa | 558 | if( data != NULL ) { |
klauss | 78:1353744f01e1 | 559 | if( min_ext == 0 ) min_ext = ext; |
klauss | 91:c2a86b1f8aaa | 560 | |
klauss | 78:1353744f01e1 | 561 | if( ext > max_ext ) max_ext = ext; |
klauss | 91:c2a86b1f8aaa | 562 | |
klauss | 78:1353744f01e1 | 563 | if( ext < min_ext ) min_ext = ext; |
klauss | 99:e80850c51106 | 564 | |
klauss | 99:e80850c51106 | 565 | if( debug_fw ){ |
klauss | 99:e80850c51106 | 566 | fw_cbx_pkg( ext, port, ( char *)buffer ); |
klauss | 99:e80850c51106 | 567 | } |
klauss | 99:e80850c51106 | 568 | |
klauss | 109:a5b8264ffbbc | 569 | if( type == __TELEMETRY__ ) telemetry_counter++; |
klauss | 109:a5b8264ffbbc | 570 | |
klauss | 109:a5b8264ffbbc | 571 | if( type != __AUDIO__ ) { |
klauss | 99:e80850c51106 | 572 | if( |
klauss | 99:e80850c51106 | 573 | type == __TELEMETRY__ || |
klauss | 99:e80850c51106 | 574 | type == __CB_STATS__ || |
klauss | 99:e80850c51106 | 575 | type == __FW1__ || |
klauss | 99:e80850c51106 | 576 | type == __FW2__ || |
klauss | 99:e80850c51106 | 577 | type == __FW3__ || |
klauss | 99:e80850c51106 | 578 | type == __FW4__ || |
klauss | 99:e80850c51106 | 579 | type == __FW5__ || |
klauss | 99:e80850c51106 | 580 | type == __FW6__ |
klauss | 99:e80850c51106 | 581 | ) type = __FW__; |
klauss | 99:e80850c51106 | 582 | |
klauss | 99:e80850c51106 | 583 | if( debug_cb_rx == true ){ |
klauss | 99:e80850c51106 | 584 | send_msg("Pkg from CBx :: ( %d, %d ) -- Type :: %d", ext, port, type ); |
klauss | 99:e80850c51106 | 585 | } |
klauss | 99:e80850c51106 | 586 | |
klauss | 0:4d17cd9c8f9d | 587 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 588 | if( cb != NULL ) { |
klauss | 92:92df17f538a8 | 589 | if( data[ 0 ] & BIT7 ) { |
klauss | 91:c2a86b1f8aaa | 590 | if( type == __BOOT__ ) { |
klauss | 109:a5b8264ffbbc | 591 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 109:a5b8264ffbbc | 592 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 92:92df17f538a8 | 593 | } else { |
klauss | 81:3656f00ab3db | 594 | if( debug_main ) debug_msg("Received ack pkg with seq_num %d", data[ 0 ] ); |
klauss | 91:c2a86b1f8aaa | 595 | |
klauss | 91:c2a86b1f8aaa | 596 | switch( type ) { |
klauss | 81:3656f00ab3db | 597 | case __INVITE__ : { |
klauss | 81:3656f00ab3db | 598 | if( debug_main || debug_invite ) debug_msg("Invite Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 109:a5b8264ffbbc | 599 | //cb->first_invite_response_ok(); |
klauss | 91:c2a86b1f8aaa | 600 | break; |
klauss | 81:3656f00ab3db | 601 | } |
klauss | 81:3656f00ab3db | 602 | case __CB_BYE__ : { |
klauss | 81:3656f00ab3db | 603 | if( debug_main || debug_invite ) debug_msg("BYE Ack from %d on msg_id %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 604 | cb->set_bye_response_ok(); |
klauss | 91:c2a86b1f8aaa | 605 | break; |
klauss | 81:3656f00ab3db | 606 | } |
klauss | 81:3656f00ab3db | 607 | case __REGISTRY__ : { |
klauss | 81:3656f00ab3db | 608 | if( debug_main || debug_aging ) debug_msg("Registry ACK from %d in pkg :: %d", ext, cb->get_msg_id() ); |
klauss | 81:3656f00ab3db | 609 | break; |
klauss | 81:3656f00ab3db | 610 | } |
klauss | 81:3656f00ab3db | 611 | default : { |
klauss | 91:c2a86b1f8aaa | 612 | if( debug_main || debug_aging ) debug_msg("ACK from %d in pkg :: %d :: type %d", ext, cb->get_msg_id(), type ); |
klauss | 91:c2a86b1f8aaa | 613 | } |
klauss | 81:3656f00ab3db | 614 | } |
klauss | 92:92df17f538a8 | 615 | if( type != __REGISTRY__ && type != __CB_BYE__ ) type = __DO_NOTHING__; |
klauss | 92:92df17f538a8 | 616 | if( type == __CB_BYE__ ){ |
klauss | 92:92df17f538a8 | 617 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 92:92df17f538a8 | 618 | if( call != NULL ){ |
klauss | 92:92df17f538a8 | 619 | if( call->get_elapsed_time() < 120000 ){ |
klauss | 92:92df17f538a8 | 620 | if( debug_invite ) debug_msg("%d ack bye ignored", ext ); |
klauss | 92:92df17f538a8 | 621 | type = __DO_NOTHING__; |
klauss | 92:92df17f538a8 | 622 | } |
klauss | 92:92df17f538a8 | 623 | } |
klauss | 92:92df17f538a8 | 624 | } |
klauss | 0:4d17cd9c8f9d | 625 | } |
klauss | 0:4d17cd9c8f9d | 626 | } |
klauss | 0:4d17cd9c8f9d | 627 | } |
klauss | 0:4d17cd9c8f9d | 628 | } |
klauss | 91:c2a86b1f8aaa | 629 | } else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 630 | } |
klauss | 91:c2a86b1f8aaa | 631 | |
klauss | 109:a5b8264ffbbc | 632 | if( main_test == true ) { |
klauss | 109:a5b8264ffbbc | 633 | main_test = false; |
klauss | 85:b6f2dc1d0f4f | 634 | send_msg("CB_New (%u) -- CB_Delete (%u)", cb_new_counter, cb_delete_counter ); |
klauss | 85:b6f2dc1d0f4f | 635 | send_msg("SIP_New (%u) -- SIP_Delete (%u)", sip_new_counter, sip_delete_counter ); |
klauss | 87:679ee0d594a9 | 636 | send_msg("RTP_header_New (%u) -- RTP_header_Delete (%u)", rtp_header_new_counter, rtp_header_delete_counter ); |
klauss | 87:679ee0d594a9 | 637 | send_msg("RTP_body_New (%u) -- RTP_body_Delete (%u)", rtp_body_new_counter, rtp_body_delete_counter ); |
klauss | 109:a5b8264ffbbc | 638 | send_msg("Call_New (%u) -- Call_Delete (%u)", call_new_counter, call_delete_counter ); |
klauss | 87:679ee0d594a9 | 639 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 640 | send_msg("Memory is %s", ( memory_is_over ) ? "Over" : "Ok" ); |
klauss | 81:3656f00ab3db | 641 | send_msg("Missed_Pkg :: %d ::", missed_pkg ); |
klauss | 87:679ee0d594a9 | 642 | send_msg("Sizeof Sip :: %u", sizeof( Sip ) ); |
klauss | 87:679ee0d594a9 | 643 | send_msg("Sizeof VZ_call :: %u", sizeof( VZ_call ) ); |
klauss | 87:679ee0d594a9 | 644 | send_msg("Sizeof RTP :: %u", sizeof( RTP ) ); |
klauss | 87:679ee0d594a9 | 645 | send_msg("Sizeof RTP_Header :: %u", sizeof( RTP_Header ) ); |
klauss | 87:679ee0d594a9 | 646 | send_msg("Sizeof RTP_Body :: %u", sizeof( RTP_Body ) ); |
klauss | 87:679ee0d594a9 | 647 | send_msg("Sizeof Vector :: %u", sizeof( Vector ) ); |
klauss | 87:679ee0d594a9 | 648 | send_msg("Sizeof Timeslice :: %u", sizeof( Timeslice ) ); |
klauss | 87:679ee0d594a9 | 649 | send_msg("Sizeof Watchdog :: %u", sizeof( Watchdog ) ); |
klauss | 112:6ae726539ab9 | 650 | //VZ_call * call = new VZ_call( 1234, 9876, 413, 12093 ); |
klauss | 112:6ae726539ab9 | 651 | //v_call -> add ( call ); |
klauss | 109:a5b8264ffbbc | 652 | } |
klauss | 109:a5b8264ffbbc | 653 | |
klauss | 109:a5b8264ffbbc | 654 | //static int wdt_count = 0; |
klauss | 109:a5b8264ffbbc | 655 | /* |
klauss | 109:a5b8264ffbbc | 656 | if( registry_test == true ) { |
klauss | 109:a5b8264ffbbc | 657 | registry_test = false; |
klauss | 109:a5b8264ffbbc | 658 | |
klauss | 109:a5b8264ffbbc | 659 | if( wdt_count++ > 5 || v_cb->size() < 66 ) { |
klauss | 109:a5b8264ffbbc | 660 | wdt_count = 0; |
klauss | 109:a5b8264ffbbc | 661 | |
klauss | 109:a5b8264ffbbc | 662 | if( type == __DO_NOTHING__ ) { |
klauss | 109:a5b8264ffbbc | 663 | if( next_value < ( 5002 + __MAX_CB_IN_A_BRANCH__ - 2 ) ) { |
klauss | 109:a5b8264ffbbc | 664 | //type = __REGISTRY__; |
klauss | 109:a5b8264ffbbc | 665 | data = buffer; |
klauss | 109:a5b8264ffbbc | 666 | ext = next_value; |
klauss | 109:a5b8264ffbbc | 667 | port = next_value++; |
klauss | 109:a5b8264ffbbc | 668 | } else { |
klauss | 109:a5b8264ffbbc | 669 | if( nex_test_registry > ( 5002 + __MAX_CB_IN_A_BRANCH__ - 1 - 2 ) ) nex_test_registry = 5002; |
klauss | 109:a5b8264ffbbc | 670 | //type = __REGISTRY__; |
klauss | 109:a5b8264ffbbc | 671 | data = buffer; |
klauss | 109:a5b8264ffbbc | 672 | ext = nex_test_registry; |
klauss | 109:a5b8264ffbbc | 673 | port = nex_test_registry++; |
klauss | 109:a5b8264ffbbc | 674 | } |
klauss | 109:a5b8264ffbbc | 675 | } |
klauss | 109:a5b8264ffbbc | 676 | } |
klauss | 109:a5b8264ffbbc | 677 | } |
klauss | 109:a5b8264ffbbc | 678 | */ |
klauss | 109:a5b8264ffbbc | 679 | |
klauss | 112:6ae726539ab9 | 680 | if ( registra ) |
klauss | 112:6ae726539ab9 | 681 | { |
klauss | 112:6ae726539ab9 | 682 | int internal_ext = 8000; |
klauss | 112:6ae726539ab9 | 683 | registra = false; |
klauss | 112:6ae726539ab9 | 684 | for( register uint8_t i = 0; i < 4; i++ ) { |
klauss | 112:6ae726539ab9 | 685 | v_cb -> add ( new Call_Box ( internal_ext, internal_ext++ ) ); |
klauss | 112:6ae726539ab9 | 686 | } |
klauss | 112:6ae726539ab9 | 687 | } |
klauss | 112:6ae726539ab9 | 688 | |
klauss | 109:a5b8264ffbbc | 689 | { |
klauss | 109:a5b8264ffbbc | 690 | fd_set fdSet; |
klauss | 109:a5b8264ffbbc | 691 | FD_ZERO(&fdSet); |
klauss | 109:a5b8264ffbbc | 692 | |
klauss | 109:a5b8264ffbbc | 693 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 109:a5b8264ffbbc | 694 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 109:a5b8264ffbbc | 695 | FD_SET( cb->get_sip_socket_fd(), &fdSet); |
klauss | 109:a5b8264ffbbc | 696 | } |
klauss | 109:a5b8264ffbbc | 697 | |
klauss | 109:a5b8264ffbbc | 698 | FD_SET( udp_wdt_client.get_fd(), &fdSet); |
klauss | 109:a5b8264ffbbc | 699 | |
klauss | 109:a5b8264ffbbc | 700 | struct timeval t; |
klauss | 109:a5b8264ffbbc | 701 | t.tv_sec = 0; |
klauss | 109:a5b8264ffbbc | 702 | t.tv_usec = 0; |
klauss | 109:a5b8264ffbbc | 703 | int ret = lwip_select( FD_SETSIZE, &fdSet, NULL, NULL, &t ); |
klauss | 109:a5b8264ffbbc | 704 | |
klauss | 109:a5b8264ffbbc | 705 | if(ret > 0 ) { |
klauss | 109:a5b8264ffbbc | 706 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 109:a5b8264ffbbc | 707 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 109:a5b8264ffbbc | 708 | int fd = cb->get_sip_socket_fd(); |
klauss | 109:a5b8264ffbbc | 709 | if( FD_ISSET( fd, &fdSet ) ) { |
klauss | 109:a5b8264ffbbc | 710 | int rcv = cb->sip_udp_incomming_pkg(); |
klauss | 109:a5b8264ffbbc | 711 | } |
klauss | 109:a5b8264ffbbc | 712 | } |
klauss | 109:a5b8264ffbbc | 713 | if( FD_ISSET( udp_wdt_client.get_fd(), &fdSet ) ) { |
klauss | 109:a5b8264ffbbc | 714 | char wake_msg[ 768 ]; |
klauss | 109:a5b8264ffbbc | 715 | Endpoint udp_wdt_server; |
klauss | 109:a5b8264ffbbc | 716 | |
klauss | 109:a5b8264ffbbc | 717 | if( udp_wdt_client.receiveFrom( udp_wdt_server, wake_msg, sizeof( wake_msg ) ) > 0 ){ |
klauss | 109:a5b8264ffbbc | 718 | if( !( strncmp( wake_msg, "alive", 5 ) ) ) { |
klauss | 109:a5b8264ffbbc | 719 | // Just ckeck but not set 'alive?' |
klauss | 109:a5b8264ffbbc | 720 | // 'alive*' - force wdt tick right now |
klauss | 109:a5b8264ffbbc | 721 | // Ckecking and set 'alive' |
klauss | 109:a5b8264ffbbc | 722 | bool question_alive = ( wake_msg[ 5 ] == '?' ); |
klauss | 109:a5b8264ffbbc | 723 | if( wake_msg[ 5 ] == '*' ) wdt.kick(); |
klauss | 109:a5b8264ffbbc | 724 | |
klauss | 109:a5b8264ffbbc | 725 | /* |
klauss | 109:a5b8264ffbbc | 726 | uint8_t registered_cbx = v_cb->size(); |
klauss | 109:a5b8264ffbbc | 727 | for( register int i = 0; i < v_cb->size(); i++ ){ |
klauss | 109:a5b8264ffbbc | 728 | Call_Box * cb = (Call_Box * )v_cb->get_element( i ); |
klauss | 109:a5b8264ffbbc | 729 | if( cb->is_timeout() ){ if( registered_cbx ) registered_cbx--; } |
klauss | 109:a5b8264ffbbc | 730 | } |
klauss | 109:a5b8264ffbbc | 731 | */ |
klauss | 109:a5b8264ffbbc | 732 | |
klauss | 109:a5b8264ffbbc | 733 | snprintf( wake_msg, 48,"wdt:%u,%u,%u,%c,%u,%u,%u,%u,%u:", |
klauss | 109:a5b8264ffbbc | 734 | uptime, |
klauss | 109:a5b8264ffbbc | 735 | invite_counter, |
klauss | 109:a5b8264ffbbc | 736 | external_wdt, |
klauss | 109:a5b8264ffbbc | 737 | ( wdt.WatchdogCausedReset() ) ? '1' : '0', |
klauss | 109:a5b8264ffbbc | 738 | cb_new_counter, |
klauss | 109:a5b8264ffbbc | 739 | v_cb->size(), |
klauss | 109:a5b8264ffbbc | 740 | ts->remain_timeslices(), |
klauss | 109:a5b8264ffbbc | 741 | sip_socket_send_failure, |
klauss | 109:a5b8264ffbbc | 742 | v_call->size() |
klauss | 109:a5b8264ffbbc | 743 | // registered_cbx |
klauss | 109:a5b8264ffbbc | 744 | ); |
klauss | 109:a5b8264ffbbc | 745 | wake_msg[ 768 - 1 ] = 0; |
klauss | 109:a5b8264ffbbc | 746 | udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 109:a5b8264ffbbc | 747 | |
klauss | 109:a5b8264ffbbc | 748 | if( ( (!question_alive) && ( cb_new_counter <= __MAX_CB_IN_A_BRANCH__ ) && ( cb_new_counter >= 2 ) ) ) { |
klauss | 109:a5b8264ffbbc | 749 | external_wdt = EXTERN_WDT_IDLE; |
klauss | 109:a5b8264ffbbc | 750 | } |
klauss | 109:a5b8264ffbbc | 751 | } else if( !( strncmp( wake_msg, "reset", 5 ) ) ) { |
klauss | 109:a5b8264ffbbc | 752 | external_wdt = 0; |
klauss | 109:a5b8264ffbbc | 753 | |
klauss | 109:a5b8264ffbbc | 754 | sprintf( wake_msg, "rst:%u:", uptime ); |
klauss | 109:a5b8264ffbbc | 755 | udp_wdt_client.sendTo( udp_wdt_server, wake_msg, strlen( wake_msg ) ); |
klauss | 109:a5b8264ffbbc | 756 | } |
klauss | 109:a5b8264ffbbc | 757 | } |
klauss | 109:a5b8264ffbbc | 758 | } |
klauss | 109:a5b8264ffbbc | 759 | } |
klauss | 109:a5b8264ffbbc | 760 | } |
klauss | 109:a5b8264ffbbc | 761 | |
klauss | 112:6ae726539ab9 | 762 | if ( cogumelo ) |
klauss | 112:6ae726539ab9 | 763 | { |
klauss | 112:6ae726539ab9 | 764 | cogumelo = false; |
klauss | 112:6ae726539ab9 | 765 | for( register int i = 0; i < v_cb->size(); i++ ) |
klauss | 112:6ae726539ab9 | 766 | { |
klauss | 112:6ae726539ab9 | 767 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 112:6ae726539ab9 | 768 | if ( cb ) |
klauss | 112:6ae726539ab9 | 769 | { |
klauss | 112:6ae726539ab9 | 770 | set_status( cb->status, cb_on_call ); |
klauss | 112:6ae726539ab9 | 771 | set_status( cb->sip->status, sip_on_call ); |
klauss | 112:6ae726539ab9 | 772 | } |
klauss | 112:6ae726539ab9 | 773 | else |
klauss | 112:6ae726539ab9 | 774 | { |
klauss | 112:6ae726539ab9 | 775 | debug_msg("%d congumelo missed", i ); |
klauss | 112:6ae726539ab9 | 776 | } |
klauss | 112:6ae726539ab9 | 777 | } |
klauss | 112:6ae726539ab9 | 778 | |
klauss | 112:6ae726539ab9 | 779 | } |
klauss | 112:6ae726539ab9 | 780 | |
klauss | 112:6ae726539ab9 | 781 | if ( gnomo ) |
klauss | 112:6ae726539ab9 | 782 | { |
klauss | 112:6ae726539ab9 | 783 | gnomo = false; |
klauss | 112:6ae726539ab9 | 784 | for( register int i = 0; i < v_cb->size(); i++ ) |
klauss | 112:6ae726539ab9 | 785 | { |
klauss | 112:6ae726539ab9 | 786 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 112:6ae726539ab9 | 787 | if ( cb ) |
klauss | 112:6ae726539ab9 | 788 | { |
klauss | 112:6ae726539ab9 | 789 | set_status( cb->status, cb_idle ); |
klauss | 112:6ae726539ab9 | 790 | set_status( cb->sip->status, sip_idle ); |
klauss | 112:6ae726539ab9 | 791 | } |
klauss | 112:6ae726539ab9 | 792 | else |
klauss | 112:6ae726539ab9 | 793 | { |
klauss | 112:6ae726539ab9 | 794 | debug_msg("%d gnomo missed", i ); |
klauss | 112:6ae726539ab9 | 795 | } |
klauss | 112:6ae726539ab9 | 796 | } |
klauss | 112:6ae726539ab9 | 797 | |
klauss | 112:6ae726539ab9 | 798 | } |
klauss | 112:6ae726539ab9 | 799 | |
klauss | 112:6ae726539ab9 | 800 | |
klauss | 109:a5b8264ffbbc | 801 | if( dshow_rtp == true ){ |
klauss | 109:a5b8264ffbbc | 802 | dshow_rtp = false; |
klauss | 109:a5b8264ffbbc | 803 | send_msg(":: RTP :: %u", v_cb->size() ); |
klauss | 109:a5b8264ffbbc | 804 | |
klauss | 109:a5b8264ffbbc | 805 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 109:a5b8264ffbbc | 806 | |
klauss | 109:a5b8264ffbbc | 807 | if( v_cb->size() >= 1 ) { |
klauss | 109:a5b8264ffbbc | 808 | for( register int i = 0; i < v_cb->size(); i++ ) |
klauss | 109:a5b8264ffbbc | 809 | { |
klauss | 109:a5b8264ffbbc | 810 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 109:a5b8264ffbbc | 811 | } |
klauss | 109:a5b8264ffbbc | 812 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 109:a5b8264ffbbc | 813 | } |
klauss | 109:a5b8264ffbbc | 814 | |
klauss | 109:a5b8264ffbbc | 815 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 109:a5b8264ffbbc | 816 | { |
klauss | 109:a5b8264ffbbc | 817 | Call_Box * cb = __find_CB__( v_cb, ext_list[ i ] ); |
klauss | 109:a5b8264ffbbc | 818 | if( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 819 | { |
klauss | 109:a5b8264ffbbc | 820 | send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", |
klauss | 109:a5b8264ffbbc | 821 | cb -> get_ext (), |
klauss | 109:a5b8264ffbbc | 822 | cb -> get_port (), |
klauss | 109:a5b8264ffbbc | 823 | cb -> get_sip_ext (), |
klauss | 109:a5b8264ffbbc | 824 | cb -> get_sip_port (), |
klauss | 109:a5b8264ffbbc | 825 | cb -> get_rtp_port () |
klauss | 109:a5b8264ffbbc | 826 | ); |
klauss | 109:a5b8264ffbbc | 827 | } |
klauss | 109:a5b8264ffbbc | 828 | } |
klauss | 109:a5b8264ffbbc | 829 | } |
klauss | 109:a5b8264ffbbc | 830 | |
klauss | 109:a5b8264ffbbc | 831 | if( malasia ) |
klauss | 109:a5b8264ffbbc | 832 | { |
klauss | 109:a5b8264ffbbc | 833 | malasia = false; |
klauss | 109:a5b8264ffbbc | 834 | // conclusao, mudar o nro nao impala, talvez mudar o nro no pacote ... |
klauss | 109:a5b8264ffbbc | 835 | Call_Box * cb = __find_CB__( v_cb, 5016 ); |
klauss | 109:a5b8264ffbbc | 836 | if( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 837 | { |
klauss | 109:a5b8264ffbbc | 838 | cb -> set_rtp_port ( cb -> get_rtp_port () * 10 + 1 ); |
klauss | 109:a5b8264ffbbc | 839 | send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", |
klauss | 109:a5b8264ffbbc | 840 | cb -> get_ext (), |
klauss | 109:a5b8264ffbbc | 841 | cb -> get_port (), |
klauss | 109:a5b8264ffbbc | 842 | cb -> get_sip_ext (), |
klauss | 109:a5b8264ffbbc | 843 | cb -> get_sip_port (), |
klauss | 109:a5b8264ffbbc | 844 | cb -> get_rtp_port () |
klauss | 109:a5b8264ffbbc | 845 | ); |
klauss | 109:a5b8264ffbbc | 846 | } |
klauss | 109:a5b8264ffbbc | 847 | } |
klauss | 109:a5b8264ffbbc | 848 | |
klauss | 109:a5b8264ffbbc | 849 | if( york ) |
klauss | 109:a5b8264ffbbc | 850 | { |
klauss | 109:a5b8264ffbbc | 851 | york = false; |
klauss | 109:a5b8264ffbbc | 852 | Call_Box * cb = __find_CB__( v_cb, 5016 ); |
klauss | 109:a5b8264ffbbc | 853 | if( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 854 | { |
klauss | 109:a5b8264ffbbc | 855 | cb -> set_rtp_port ( 80 ); |
klauss | 109:a5b8264ffbbc | 856 | send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", |
klauss | 109:a5b8264ffbbc | 857 | cb -> get_ext (), |
klauss | 109:a5b8264ffbbc | 858 | cb -> get_port (), |
klauss | 109:a5b8264ffbbc | 859 | cb -> get_sip_ext (), |
klauss | 109:a5b8264ffbbc | 860 | cb -> get_sip_port (), |
klauss | 109:a5b8264ffbbc | 861 | cb -> get_rtp_port () |
klauss | 109:a5b8264ffbbc | 862 | ); |
klauss | 109:a5b8264ffbbc | 863 | } |
klauss | 109:a5b8264ffbbc | 864 | } |
klauss | 109:a5b8264ffbbc | 865 | |
klauss | 109:a5b8264ffbbc | 866 | if ( frtp ) |
klauss | 109:a5b8264ffbbc | 867 | { |
klauss | 109:a5b8264ffbbc | 868 | frtp = false; |
klauss | 109:a5b8264ffbbc | 869 | Call_Box * cb = __find_CB__( v_cb, frtp_target ); |
klauss | 109:a5b8264ffbbc | 870 | if ( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 871 | { |
klauss | 109:a5b8264ffbbc | 872 | cb -> set_rtp_port ( -1008789032 ); |
klauss | 109:a5b8264ffbbc | 873 | } |
klauss | 109:a5b8264ffbbc | 874 | else |
klauss | 109:a5b8264ffbbc | 875 | { |
klauss | 109:a5b8264ffbbc | 876 | debug_msg("frtp fail"); |
klauss | 109:a5b8264ffbbc | 877 | } |
klauss | 109:a5b8264ffbbc | 878 | |
klauss | 109:a5b8264ffbbc | 879 | } |
klauss | 109:a5b8264ffbbc | 880 | |
klauss | 109:a5b8264ffbbc | 881 | if ( rescue_rtp ) |
klauss | 109:a5b8264ffbbc | 882 | { |
klauss | 109:a5b8264ffbbc | 883 | rescue_rtp = false; |
klauss | 109:a5b8264ffbbc | 884 | Call_Box * cb = __find_CB__( v_cb, rescue_rtp_target ); |
klauss | 109:a5b8264ffbbc | 885 | if ( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 886 | { |
klauss | 109:a5b8264ffbbc | 887 | cb -> set_rtp_port ( rescue_rtp_value ); |
klauss | 109:a5b8264ffbbc | 888 | } |
klauss | 109:a5b8264ffbbc | 889 | else |
klauss | 109:a5b8264ffbbc | 890 | { |
klauss | 109:a5b8264ffbbc | 891 | debug_msg("rescue rtp fail"); |
klauss | 109:a5b8264ffbbc | 892 | } |
klauss | 109:a5b8264ffbbc | 893 | |
klauss | 109:a5b8264ffbbc | 894 | } |
klauss | 109:a5b8264ffbbc | 895 | |
klauss | 109:a5b8264ffbbc | 896 | if( america ) |
klauss | 109:a5b8264ffbbc | 897 | { |
klauss | 109:a5b8264ffbbc | 898 | america = false; |
klauss | 109:a5b8264ffbbc | 899 | Call_Box * cb = __find_CB__( v_cb, 5016 ); |
klauss | 109:a5b8264ffbbc | 900 | if( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 901 | { |
klauss | 109:a5b8264ffbbc | 902 | cb -> set_rtp_port ( 8929415 ); |
klauss | 109:a5b8264ffbbc | 903 | send_msg("CBX ( %d, %d ) - SIP ( %d, %d ) - RTP ( %d )", |
klauss | 109:a5b8264ffbbc | 904 | cb -> get_ext (), |
klauss | 109:a5b8264ffbbc | 905 | cb -> get_port (), |
klauss | 109:a5b8264ffbbc | 906 | cb -> get_sip_ext (), |
klauss | 109:a5b8264ffbbc | 907 | cb -> get_sip_port (), |
klauss | 109:a5b8264ffbbc | 908 | cb -> get_rtp_port () |
klauss | 109:a5b8264ffbbc | 909 | ); |
klauss | 109:a5b8264ffbbc | 910 | } |
klauss | 109:a5b8264ffbbc | 911 | } |
klauss | 109:a5b8264ffbbc | 912 | |
klauss | 109:a5b8264ffbbc | 913 | //begin debug_print |
klauss | 109:a5b8264ffbbc | 914 | if ( print_v_cb ) |
klauss | 109:a5b8264ffbbc | 915 | { |
klauss | 109:a5b8264ffbbc | 916 | print_v_cb = false; |
klauss | 109:a5b8264ffbbc | 917 | v_cb->print_yourself (); |
klauss | 109:a5b8264ffbbc | 918 | } |
klauss | 109:a5b8264ffbbc | 919 | |
klauss | 109:a5b8264ffbbc | 920 | if ( print_v_call ) |
klauss | 109:a5b8264ffbbc | 921 | { |
klauss | 109:a5b8264ffbbc | 922 | print_v_call = false; |
klauss | 109:a5b8264ffbbc | 923 | v_call->print_yourself (); |
klauss | 109:a5b8264ffbbc | 924 | } |
klauss | 109:a5b8264ffbbc | 925 | |
klauss | 109:a5b8264ffbbc | 926 | if ( print_cb_var ) |
klauss | 109:a5b8264ffbbc | 927 | { |
klauss | 109:a5b8264ffbbc | 928 | print_cb_var = false; |
klauss | 109:a5b8264ffbbc | 929 | Call_Box * cb = __find_CB__ ( v_cb, print_this_cb ); |
klauss | 109:a5b8264ffbbc | 930 | if ( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 931 | { |
klauss | 109:a5b8264ffbbc | 932 | cb -> print_yourself (); |
klauss | 109:a5b8264ffbbc | 933 | } |
klauss | 109:a5b8264ffbbc | 934 | else |
klauss | 109:a5b8264ffbbc | 935 | { |
klauss | 109:a5b8264ffbbc | 936 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 937 | { |
klauss | 109:a5b8264ffbbc | 938 | debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 109:a5b8264ffbbc | 939 | } |
klauss | 109:a5b8264ffbbc | 940 | else |
klauss | 109:a5b8264ffbbc | 941 | { |
klauss | 109:a5b8264ffbbc | 942 | send_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 109:a5b8264ffbbc | 943 | } |
klauss | 109:a5b8264ffbbc | 944 | } |
klauss | 109:a5b8264ffbbc | 945 | } |
klauss | 109:a5b8264ffbbc | 946 | |
klauss | 109:a5b8264ffbbc | 947 | if ( print_cb_all ) |
klauss | 109:a5b8264ffbbc | 948 | { |
klauss | 109:a5b8264ffbbc | 949 | print_cb_all = false; |
klauss | 109:a5b8264ffbbc | 950 | |
klauss | 109:a5b8264ffbbc | 951 | if ( v_cb -> size () == 0 ) |
klauss | 109:a5b8264ffbbc | 952 | { |
klauss | 109:a5b8264ffbbc | 953 | send_msg("known CBx :: 0"); |
klauss | 109:a5b8264ffbbc | 954 | } |
klauss | 109:a5b8264ffbbc | 955 | |
klauss | 109:a5b8264ffbbc | 956 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 109:a5b8264ffbbc | 957 | { |
klauss | 109:a5b8264ffbbc | 958 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 109:a5b8264ffbbc | 959 | |
klauss | 109:a5b8264ffbbc | 960 | if ( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 961 | { |
klauss | 109:a5b8264ffbbc | 962 | cb -> print_yourself (); |
klauss | 109:a5b8264ffbbc | 963 | } |
klauss | 109:a5b8264ffbbc | 964 | else |
klauss | 109:a5b8264ffbbc | 965 | { |
klauss | 109:a5b8264ffbbc | 966 | if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", i ); |
klauss | 109:a5b8264ffbbc | 967 | } |
klauss | 109:a5b8264ffbbc | 968 | } |
klauss | 109:a5b8264ffbbc | 969 | } |
klauss | 109:a5b8264ffbbc | 970 | |
klauss | 109:a5b8264ffbbc | 971 | if ( print_hex_cb_var ) |
klauss | 109:a5b8264ffbbc | 972 | { |
klauss | 109:a5b8264ffbbc | 973 | print_hex_cb_var = false; |
klauss | 109:a5b8264ffbbc | 974 | uint8_t * ptr = ( uint8_t * ) __find_CB__ ( v_cb, print_hex_this_cb ); |
klauss | 109:a5b8264ffbbc | 975 | |
klauss | 109:a5b8264ffbbc | 976 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 977 | { |
klauss | 109:a5b8264ffbbc | 978 | send_msg ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 109:a5b8264ffbbc | 979 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 109:a5b8264ffbbc | 980 | { |
klauss | 109:a5b8264ffbbc | 981 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 982 | |
klauss | 109:a5b8264ffbbc | 983 | if ( ( i % 32 ) == 0 ) |
klauss | 109:a5b8264ffbbc | 984 | { |
klauss | 109:a5b8264ffbbc | 985 | if( i != 0 ) |
klauss | 109:a5b8264ffbbc | 986 | { |
klauss | 109:a5b8264ffbbc | 987 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 988 | } |
klauss | 109:a5b8264ffbbc | 989 | else |
klauss | 109:a5b8264ffbbc | 990 | { |
klauss | 109:a5b8264ffbbc | 991 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 992 | } |
klauss | 109:a5b8264ffbbc | 993 | } |
klauss | 109:a5b8264ffbbc | 994 | else |
klauss | 109:a5b8264ffbbc | 995 | { |
klauss | 109:a5b8264ffbbc | 996 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 997 | } |
klauss | 109:a5b8264ffbbc | 998 | } |
klauss | 109:a5b8264ffbbc | 999 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1000 | |
klauss | 109:a5b8264ffbbc | 1001 | if ( tcp_session ) { |
klauss | 109:a5b8264ffbbc | 1002 | char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; |
klauss | 109:a5b8264ffbbc | 1003 | |
klauss | 109:a5b8264ffbbc | 1004 | for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; |
klauss | 109:a5b8264ffbbc | 1005 | |
klauss | 109:a5b8264ffbbc | 1006 | uint8_t * ptr = ( uint8_t * ) __find_CB__ ( v_cb, print_hex_this_cb ); |
klauss | 109:a5b8264ffbbc | 1007 | |
klauss | 109:a5b8264ffbbc | 1008 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 109:a5b8264ffbbc | 1009 | { |
klauss | 109:a5b8264ffbbc | 1010 | char tmp[ 16 ]; |
klauss | 109:a5b8264ffbbc | 1011 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1012 | strcat( aux, tmp ); |
klauss | 109:a5b8264ffbbc | 1013 | } |
klauss | 109:a5b8264ffbbc | 1014 | |
klauss | 109:a5b8264ffbbc | 1015 | strcat( aux, "\n\r\0" ); |
klauss | 109:a5b8264ffbbc | 1016 | tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 109:a5b8264ffbbc | 1017 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 109:a5b8264ffbbc | 1018 | } |
klauss | 109:a5b8264ffbbc | 1019 | } |
klauss | 109:a5b8264ffbbc | 1020 | else |
klauss | 109:a5b8264ffbbc | 1021 | { |
klauss | 109:a5b8264ffbbc | 1022 | if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 109:a5b8264ffbbc | 1023 | } |
klauss | 81:3656f00ab3db | 1024 | } |
klauss | 106:a34fcf9f0e02 | 1025 | |
klauss | 109:a5b8264ffbbc | 1026 | if ( print_hex_cb_all ) |
klauss | 109:a5b8264ffbbc | 1027 | { |
klauss | 109:a5b8264ffbbc | 1028 | print_hex_cb_all = false; |
klauss | 109:a5b8264ffbbc | 1029 | |
klauss | 109:a5b8264ffbbc | 1030 | if ( v_cb -> size () == 0 ) |
klauss | 109:a5b8264ffbbc | 1031 | { |
klauss | 109:a5b8264ffbbc | 1032 | send_msg("known CBx :: 0"); |
klauss | 109:a5b8264ffbbc | 1033 | } |
klauss | 109:a5b8264ffbbc | 1034 | |
klauss | 109:a5b8264ffbbc | 1035 | for ( register uint8_t j = 0; j < v_cb->size(); j++ ) |
klauss | 109:a5b8264ffbbc | 1036 | { |
klauss | 109:a5b8264ffbbc | 1037 | uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); |
klauss | 109:a5b8264ffbbc | 1038 | |
klauss | 109:a5b8264ffbbc | 1039 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1040 | { |
klauss | 109:a5b8264ffbbc | 1041 | send_msg ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 109:a5b8264ffbbc | 1042 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 109:a5b8264ffbbc | 1043 | { |
klauss | 109:a5b8264ffbbc | 1044 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1045 | |
klauss | 109:a5b8264ffbbc | 1046 | if ( ( i % 32 ) == 0 ) |
klauss | 109:a5b8264ffbbc | 1047 | { |
klauss | 109:a5b8264ffbbc | 1048 | if( i != 0 ) |
klauss | 109:a5b8264ffbbc | 1049 | { |
klauss | 109:a5b8264ffbbc | 1050 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1051 | } |
klauss | 109:a5b8264ffbbc | 1052 | else |
klauss | 109:a5b8264ffbbc | 1053 | { |
klauss | 109:a5b8264ffbbc | 1054 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1055 | } |
klauss | 109:a5b8264ffbbc | 1056 | } |
klauss | 109:a5b8264ffbbc | 1057 | else |
klauss | 109:a5b8264ffbbc | 1058 | { |
klauss | 109:a5b8264ffbbc | 1059 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1060 | } |
klauss | 109:a5b8264ffbbc | 1061 | } |
klauss | 109:a5b8264ffbbc | 1062 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1063 | |
klauss | 109:a5b8264ffbbc | 1064 | if ( tcp_session ) { |
klauss | 109:a5b8264ffbbc | 1065 | char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; |
klauss | 109:a5b8264ffbbc | 1066 | |
klauss | 109:a5b8264ffbbc | 1067 | for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; |
klauss | 109:a5b8264ffbbc | 1068 | |
klauss | 109:a5b8264ffbbc | 1069 | uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); |
klauss | 109:a5b8264ffbbc | 1070 | |
klauss | 109:a5b8264ffbbc | 1071 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 109:a5b8264ffbbc | 1072 | { |
klauss | 109:a5b8264ffbbc | 1073 | char tmp[ 16 ]; |
klauss | 109:a5b8264ffbbc | 1074 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1075 | strcat( aux, tmp ); |
klauss | 109:a5b8264ffbbc | 1076 | } |
klauss | 109:a5b8264ffbbc | 1077 | |
klauss | 109:a5b8264ffbbc | 1078 | strcat( aux, "\n\r\0" ); |
klauss | 109:a5b8264ffbbc | 1079 | tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 109:a5b8264ffbbc | 1080 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 109:a5b8264ffbbc | 1081 | } |
klauss | 109:a5b8264ffbbc | 1082 | } |
klauss | 109:a5b8264ffbbc | 1083 | else |
klauss | 109:a5b8264ffbbc | 1084 | { |
klauss | 109:a5b8264ffbbc | 1085 | if ( print_values ) |
klauss | 109:a5b8264ffbbc | 1086 | { |
klauss | 109:a5b8264ffbbc | 1087 | debug_msg ("Objeto CBx ( %d ) nao encontrado", j ); |
klauss | 109:a5b8264ffbbc | 1088 | } |
klauss | 109:a5b8264ffbbc | 1089 | else |
klauss | 109:a5b8264ffbbc | 1090 | { |
klauss | 109:a5b8264ffbbc | 1091 | send_msg ("Objeto CBx ( %d ) nao encontrado", j ); |
klauss | 109:a5b8264ffbbc | 1092 | } |
klauss | 109:a5b8264ffbbc | 1093 | } |
klauss | 109:a5b8264ffbbc | 1094 | } |
klauss | 109:a5b8264ffbbc | 1095 | } |
klauss | 106:a34fcf9f0e02 | 1096 | |
klauss | 109:a5b8264ffbbc | 1097 | //begin Sip debug print |
klauss | 109:a5b8264ffbbc | 1098 | { |
klauss | 109:a5b8264ffbbc | 1099 | if ( print_sip_var ) |
klauss | 109:a5b8264ffbbc | 1100 | { |
klauss | 109:a5b8264ffbbc | 1101 | print_sip_var = false; |
klauss | 109:a5b8264ffbbc | 1102 | Call_Box * cb = __find_CB__ ( v_cb, print_this_sip ); |
klauss | 109:a5b8264ffbbc | 1103 | if ( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 1104 | { |
klauss | 109:a5b8264ffbbc | 1105 | if( ( cb -> sip ) != NULL ) |
klauss | 109:a5b8264ffbbc | 1106 | { |
klauss | 109:a5b8264ffbbc | 1107 | cb -> sip -> print_yourself (); |
klauss | 109:a5b8264ffbbc | 1108 | } |
klauss | 109:a5b8264ffbbc | 1109 | else |
klauss | 109:a5b8264ffbbc | 1110 | { |
klauss | 109:a5b8264ffbbc | 1111 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1112 | { |
klauss | 109:a5b8264ffbbc | 1113 | debug_msg("Sip param of %d equals NULL", print_this_sip ); |
klauss | 109:a5b8264ffbbc | 1114 | } |
klauss | 109:a5b8264ffbbc | 1115 | else |
klauss | 109:a5b8264ffbbc | 1116 | { |
klauss | 109:a5b8264ffbbc | 1117 | send_msg("Sip param of %d equals NULL", print_this_sip ); |
klauss | 109:a5b8264ffbbc | 1118 | } |
klauss | 109:a5b8264ffbbc | 1119 | } |
klauss | 109:a5b8264ffbbc | 1120 | } |
klauss | 109:a5b8264ffbbc | 1121 | else |
klauss | 109:a5b8264ffbbc | 1122 | { |
klauss | 109:a5b8264ffbbc | 1123 | if ( print_values ) |
klauss | 109:a5b8264ffbbc | 1124 | { |
klauss | 109:a5b8264ffbbc | 1125 | debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 109:a5b8264ffbbc | 1126 | } |
klauss | 109:a5b8264ffbbc | 1127 | else |
klauss | 109:a5b8264ffbbc | 1128 | { |
klauss | 109:a5b8264ffbbc | 1129 | send_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 109:a5b8264ffbbc | 1130 | } } |
klauss | 109:a5b8264ffbbc | 1131 | } |
klauss | 109:a5b8264ffbbc | 1132 | |
klauss | 109:a5b8264ffbbc | 1133 | if ( print_sip_all ) |
klauss | 109:a5b8264ffbbc | 1134 | { |
klauss | 109:a5b8264ffbbc | 1135 | print_sip_all = false; |
klauss | 109:a5b8264ffbbc | 1136 | |
klauss | 109:a5b8264ffbbc | 1137 | if ( v_cb -> size () == 0 ) |
klauss | 109:a5b8264ffbbc | 1138 | { |
klauss | 109:a5b8264ffbbc | 1139 | send_msg("known CBx :: 0"); |
klauss | 109:a5b8264ffbbc | 1140 | } |
klauss | 109:a5b8264ffbbc | 1141 | |
klauss | 109:a5b8264ffbbc | 1142 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 109:a5b8264ffbbc | 1143 | { |
klauss | 109:a5b8264ffbbc | 1144 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 109:a5b8264ffbbc | 1145 | |
klauss | 109:a5b8264ffbbc | 1146 | if ( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 1147 | { |
klauss | 109:a5b8264ffbbc | 1148 | if( ( cb -> sip ) != NULL ) |
klauss | 109:a5b8264ffbbc | 1149 | { |
klauss | 109:a5b8264ffbbc | 1150 | cb -> sip -> print_yourself (); |
klauss | 109:a5b8264ffbbc | 1151 | } |
klauss | 109:a5b8264ffbbc | 1152 | else |
klauss | 109:a5b8264ffbbc | 1153 | { |
klauss | 109:a5b8264ffbbc | 1154 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1155 | { |
klauss | 109:a5b8264ffbbc | 1156 | debug_msg("Sip param of %d equals NULL", print_this_sip ); |
klauss | 109:a5b8264ffbbc | 1157 | } |
klauss | 109:a5b8264ffbbc | 1158 | else |
klauss | 109:a5b8264ffbbc | 1159 | { |
klauss | 109:a5b8264ffbbc | 1160 | send_msg("Sip param of %d equals NULL", print_this_sip ); |
klauss | 109:a5b8264ffbbc | 1161 | } |
klauss | 109:a5b8264ffbbc | 1162 | } |
klauss | 109:a5b8264ffbbc | 1163 | } |
klauss | 109:a5b8264ffbbc | 1164 | else |
klauss | 109:a5b8264ffbbc | 1165 | { |
klauss | 109:a5b8264ffbbc | 1166 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1167 | { |
klauss | 109:a5b8264ffbbc | 1168 | debug_msg("CBx %d not found", print_this_sip ); |
klauss | 109:a5b8264ffbbc | 1169 | } |
klauss | 109:a5b8264ffbbc | 1170 | else |
klauss | 109:a5b8264ffbbc | 1171 | { |
klauss | 109:a5b8264ffbbc | 1172 | send_msg("CBx %d not found", print_this_sip ); |
klauss | 109:a5b8264ffbbc | 1173 | } |
klauss | 109:a5b8264ffbbc | 1174 | } |
klauss | 109:a5b8264ffbbc | 1175 | } |
klauss | 109:a5b8264ffbbc | 1176 | } |
klauss | 109:a5b8264ffbbc | 1177 | |
klauss | 109:a5b8264ffbbc | 1178 | if ( print_hex_sip_var ) |
klauss | 109:a5b8264ffbbc | 1179 | { |
klauss | 109:a5b8264ffbbc | 1180 | uint8_t * ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1181 | |
klauss | 109:a5b8264ffbbc | 1182 | print_hex_sip_var = false; |
klauss | 109:a5b8264ffbbc | 1183 | Call_Box * cb = __find_CB__ ( v_cb, print_hex_this_sip ); |
klauss | 109:a5b8264ffbbc | 1184 | if( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 1185 | { |
klauss | 109:a5b8264ffbbc | 1186 | if( ( cb -> sip ) != NULL ) |
klauss | 109:a5b8264ffbbc | 1187 | ptr = ( uint8_t * ) cb -> sip; |
klauss | 109:a5b8264ffbbc | 1188 | } |
klauss | 109:a5b8264ffbbc | 1189 | |
klauss | 109:a5b8264ffbbc | 1190 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1191 | { |
klauss | 109:a5b8264ffbbc | 1192 | send_msg ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 109:a5b8264ffbbc | 1193 | for ( register int i = 0; i < sizeof( Sip ); i++ ) |
klauss | 109:a5b8264ffbbc | 1194 | { |
klauss | 109:a5b8264ffbbc | 1195 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1196 | |
klauss | 109:a5b8264ffbbc | 1197 | if ( ( i % 32 ) == 0 ) |
klauss | 109:a5b8264ffbbc | 1198 | { |
klauss | 109:a5b8264ffbbc | 1199 | if( i != 0 ) |
klauss | 109:a5b8264ffbbc | 1200 | { |
klauss | 109:a5b8264ffbbc | 1201 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1202 | } |
klauss | 109:a5b8264ffbbc | 1203 | else |
klauss | 109:a5b8264ffbbc | 1204 | { |
klauss | 109:a5b8264ffbbc | 1205 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1206 | } |
klauss | 109:a5b8264ffbbc | 1207 | } |
klauss | 109:a5b8264ffbbc | 1208 | else |
klauss | 109:a5b8264ffbbc | 1209 | { |
klauss | 109:a5b8264ffbbc | 1210 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1211 | } |
klauss | 109:a5b8264ffbbc | 1212 | } |
klauss | 109:a5b8264ffbbc | 1213 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1214 | |
klauss | 109:a5b8264ffbbc | 1215 | if ( tcp_session ) { |
klauss | 109:a5b8264ffbbc | 1216 | char aux[ ( 32 * 3 ) + 5 ]; |
klauss | 109:a5b8264ffbbc | 1217 | |
klauss | 109:a5b8264ffbbc | 1218 | for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; |
klauss | 109:a5b8264ffbbc | 1219 | |
klauss | 109:a5b8264ffbbc | 1220 | ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1221 | |
klauss | 109:a5b8264ffbbc | 1222 | print_hex_sip_var = false; |
klauss | 109:a5b8264ffbbc | 1223 | Call_Box * cb = __find_CB__ ( v_cb, print_hex_this_sip ); |
klauss | 109:a5b8264ffbbc | 1224 | if( cb != NULL ) |
klauss | 109:a5b8264ffbbc | 1225 | { |
klauss | 109:a5b8264ffbbc | 1226 | if( ( cb -> sip ) != NULL ) |
klauss | 109:a5b8264ffbbc | 1227 | ptr = ( uint8_t * ) cb -> sip; |
klauss | 109:a5b8264ffbbc | 1228 | } |
klauss | 109:a5b8264ffbbc | 1229 | |
klauss | 109:a5b8264ffbbc | 1230 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1231 | { |
klauss | 109:a5b8264ffbbc | 1232 | bool finished = false; |
klauss | 109:a5b8264ffbbc | 1233 | volatile int i = 0; |
klauss | 109:a5b8264ffbbc | 1234 | int count = 0; |
klauss | 109:a5b8264ffbbc | 1235 | Timer dont_overwrite_tcp_buffer; |
klauss | 109:a5b8264ffbbc | 1236 | dont_overwrite_tcp_buffer.reset (); |
klauss | 109:a5b8264ffbbc | 1237 | dont_overwrite_tcp_buffer.start (); |
klauss | 109:a5b8264ffbbc | 1238 | |
klauss | 109:a5b8264ffbbc | 1239 | while ( !finished ) |
klauss | 109:a5b8264ffbbc | 1240 | { |
klauss | 109:a5b8264ffbbc | 1241 | if( dont_overwrite_tcp_buffer.read_ms () >= 500 ) |
klauss | 109:a5b8264ffbbc | 1242 | { |
klauss | 109:a5b8264ffbbc | 1243 | dont_overwrite_tcp_buffer.reset(); |
klauss | 109:a5b8264ffbbc | 1244 | for ( ; i < sizeof( Sip ); i++ ) |
klauss | 109:a5b8264ffbbc | 1245 | { |
klauss | 109:a5b8264ffbbc | 1246 | char tmp[ 16 ]; |
klauss | 109:a5b8264ffbbc | 1247 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1248 | strcat( aux, tmp ); |
klauss | 109:a5b8264ffbbc | 1249 | count++; |
klauss | 109:a5b8264ffbbc | 1250 | |
klauss | 109:a5b8264ffbbc | 1251 | if ( count >= 32 ) |
klauss | 109:a5b8264ffbbc | 1252 | { |
klauss | 109:a5b8264ffbbc | 1253 | count = 0; |
klauss | 109:a5b8264ffbbc | 1254 | i++; |
klauss | 109:a5b8264ffbbc | 1255 | break; |
klauss | 109:a5b8264ffbbc | 1256 | } |
klauss | 109:a5b8264ffbbc | 1257 | } |
klauss | 109:a5b8264ffbbc | 1258 | strcat ( aux, "\n\r\0" ); |
klauss | 109:a5b8264ffbbc | 1259 | tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 109:a5b8264ffbbc | 1260 | if ( i >= sizeof ( Sip ) ) finished = true; |
klauss | 109:a5b8264ffbbc | 1261 | strcpy ( aux, "\0" ); |
klauss | 109:a5b8264ffbbc | 1262 | } |
klauss | 109:a5b8264ffbbc | 1263 | } |
klauss | 109:a5b8264ffbbc | 1264 | dont_overwrite_tcp_buffer.reset(); |
klauss | 109:a5b8264ffbbc | 1265 | dont_overwrite_tcp_buffer.stop(); |
klauss | 109:a5b8264ffbbc | 1266 | tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 109:a5b8264ffbbc | 1267 | } |
klauss | 109:a5b8264ffbbc | 1268 | } |
klauss | 109:a5b8264ffbbc | 1269 | } |
klauss | 109:a5b8264ffbbc | 1270 | else |
klauss | 109:a5b8264ffbbc | 1271 | { |
klauss | 109:a5b8264ffbbc | 1272 | if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", print_this_cb ); |
klauss | 109:a5b8264ffbbc | 1273 | } |
klauss | 109:a5b8264ffbbc | 1274 | } |
klauss | 109:a5b8264ffbbc | 1275 | /* |
klauss | 109:a5b8264ffbbc | 1276 | if ( print_hex_cb_all ) |
klauss | 109:a5b8264ffbbc | 1277 | { |
klauss | 109:a5b8264ffbbc | 1278 | print_hex_cb_all = false; |
klauss | 109:a5b8264ffbbc | 1279 | |
klauss | 109:a5b8264ffbbc | 1280 | if ( v_cb -> size () == 0 ) |
klauss | 109:a5b8264ffbbc | 1281 | { |
klauss | 109:a5b8264ffbbc | 1282 | send_msg("known CBx :: 0"); |
klauss | 109:a5b8264ffbbc | 1283 | } |
klauss | 109:a5b8264ffbbc | 1284 | |
klauss | 109:a5b8264ffbbc | 1285 | for ( register uint8_t j = 0; j < v_cb->size(); j++ ) |
klauss | 109:a5b8264ffbbc | 1286 | { |
klauss | 109:a5b8264ffbbc | 1287 | uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); |
klauss | 109:a5b8264ffbbc | 1288 | |
klauss | 109:a5b8264ffbbc | 1289 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1290 | { |
klauss | 109:a5b8264ffbbc | 1291 | send_msg ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 109:a5b8264ffbbc | 1292 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 109:a5b8264ffbbc | 1293 | { |
klauss | 109:a5b8264ffbbc | 1294 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1295 | |
klauss | 109:a5b8264ffbbc | 1296 | if ( ( i % 32 ) == 0 ) |
klauss | 109:a5b8264ffbbc | 1297 | { |
klauss | 109:a5b8264ffbbc | 1298 | if( i != 0 ) |
klauss | 109:a5b8264ffbbc | 1299 | { |
klauss | 109:a5b8264ffbbc | 1300 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1301 | } |
klauss | 109:a5b8264ffbbc | 1302 | else |
klauss | 109:a5b8264ffbbc | 1303 | { |
klauss | 109:a5b8264ffbbc | 1304 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1305 | } |
klauss | 109:a5b8264ffbbc | 1306 | } |
klauss | 109:a5b8264ffbbc | 1307 | else |
klauss | 109:a5b8264ffbbc | 1308 | { |
klauss | 109:a5b8264ffbbc | 1309 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1310 | } |
klauss | 109:a5b8264ffbbc | 1311 | } |
klauss | 109:a5b8264ffbbc | 1312 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1313 | |
klauss | 109:a5b8264ffbbc | 1314 | if ( tcp_session ) { |
klauss | 109:a5b8264ffbbc | 1315 | char aux[ ( sizeof( Call_Box ) * 3 ) + 3 ]; |
klauss | 109:a5b8264ffbbc | 1316 | |
klauss | 109:a5b8264ffbbc | 1317 | for ( register int i = 0; i < ( sizeof( Call_Box ) * 3 ) + 3 ; i++ ) aux [ i ] = 0; |
klauss | 109:a5b8264ffbbc | 1318 | |
klauss | 109:a5b8264ffbbc | 1319 | uint8_t * ptr = ( uint8_t * ) v_cb->get_element( j ); |
klauss | 109:a5b8264ffbbc | 1320 | |
klauss | 109:a5b8264ffbbc | 1321 | for ( register int i = 0; i < sizeof( Call_Box ); i++ ) |
klauss | 109:a5b8264ffbbc | 1322 | { |
klauss | 109:a5b8264ffbbc | 1323 | char tmp[ 16 ]; |
klauss | 109:a5b8264ffbbc | 1324 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1325 | strcat( aux, tmp ); |
klauss | 109:a5b8264ffbbc | 1326 | } |
klauss | 109:a5b8264ffbbc | 1327 | |
klauss | 109:a5b8264ffbbc | 1328 | strcat( aux, "\n\r\0" ); |
klauss | 109:a5b8264ffbbc | 1329 | tcp_client.send_all( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 109:a5b8264ffbbc | 1330 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 109:a5b8264ffbbc | 1331 | } |
klauss | 109:a5b8264ffbbc | 1332 | } |
klauss | 109:a5b8264ffbbc | 1333 | else |
klauss | 109:a5b8264ffbbc | 1334 | { |
klauss | 109:a5b8264ffbbc | 1335 | if ( print_values ) debug_msg ("Objeto CBx ( %d ) nao encontrado", j ); |
klauss | 109:a5b8264ffbbc | 1336 | } |
klauss | 109:a5b8264ffbbc | 1337 | } |
klauss | 109:a5b8264ffbbc | 1338 | } |
klauss | 109:a5b8264ffbbc | 1339 | */ |
klauss | 109:a5b8264ffbbc | 1340 | }//end Sip debug print |
klauss | 109:a5b8264ffbbc | 1341 | |
klauss | 109:a5b8264ffbbc | 1342 | if( dcallshow_rtp == true ){ |
klauss | 109:a5b8264ffbbc | 1343 | dcallshow_rtp = false; |
klauss | 109:a5b8264ffbbc | 1344 | send_msg(":: CAll RTP :: %u", v_call->size() ); |
klauss | 109:a5b8264ffbbc | 1345 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 109:a5b8264ffbbc | 1346 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 109:a5b8264ffbbc | 1347 | if( call != NULL ) |
klauss | 109:a5b8264ffbbc | 1348 | { |
klauss | 109:a5b8264ffbbc | 1349 | send_msg("CBX ( %d, %d ) - Server ( %d, %d )", |
klauss | 109:a5b8264ffbbc | 1350 | call->get_cb_ext(), |
klauss | 109:a5b8264ffbbc | 1351 | call->get_cb_port(), |
klauss | 109:a5b8264ffbbc | 1352 | call->get_rtp_server_ext(), |
klauss | 109:a5b8264ffbbc | 1353 | call->get_rtp_server_port() |
klauss | 109:a5b8264ffbbc | 1354 | ); |
klauss | 109:a5b8264ffbbc | 1355 | } |
klauss | 109:a5b8264ffbbc | 1356 | } |
klauss | 109:a5b8264ffbbc | 1357 | } |
klauss | 109:a5b8264ffbbc | 1358 | |
klauss | 109:a5b8264ffbbc | 1359 | if ( print_call_var ) |
klauss | 109:a5b8264ffbbc | 1360 | { |
klauss | 109:a5b8264ffbbc | 1361 | print_call_var = false; |
klauss | 109:a5b8264ffbbc | 1362 | VZ_call * call = __find_Call__( v_call, print_this_call ); |
klauss | 109:a5b8264ffbbc | 1363 | if ( call != NULL ) |
klauss | 109:a5b8264ffbbc | 1364 | { |
klauss | 109:a5b8264ffbbc | 1365 | send_msg ("Values :: %p\r\n", ( void *) call ); |
klauss | 109:a5b8264ffbbc | 1366 | call -> print_yourself (); |
klauss | 109:a5b8264ffbbc | 1367 | } |
klauss | 109:a5b8264ffbbc | 1368 | else |
klauss | 109:a5b8264ffbbc | 1369 | { |
klauss | 109:a5b8264ffbbc | 1370 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1371 | { |
klauss | 109:a5b8264ffbbc | 1372 | debug_msg("Call %d not found", print_this_call ); |
klauss | 109:a5b8264ffbbc | 1373 | } |
klauss | 109:a5b8264ffbbc | 1374 | else |
klauss | 109:a5b8264ffbbc | 1375 | { |
klauss | 109:a5b8264ffbbc | 1376 | send_msg("Call %d not found", print_this_call ); |
klauss | 109:a5b8264ffbbc | 1377 | } |
klauss | 109:a5b8264ffbbc | 1378 | } |
klauss | 109:a5b8264ffbbc | 1379 | } |
klauss | 109:a5b8264ffbbc | 1380 | |
klauss | 109:a5b8264ffbbc | 1381 | if ( print_hex_call_var ) |
klauss | 109:a5b8264ffbbc | 1382 | { |
klauss | 109:a5b8264ffbbc | 1383 | print_hex_call_var = false; |
klauss | 109:a5b8264ffbbc | 1384 | VZ_call * call = __find_Call__( v_call, print_hex_this_call ); |
klauss | 109:a5b8264ffbbc | 1385 | |
klauss | 109:a5b8264ffbbc | 1386 | uint8_t * ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1387 | if( call != NULL ) |
klauss | 109:a5b8264ffbbc | 1388 | { |
klauss | 109:a5b8264ffbbc | 1389 | ptr = ( uint8_t * ) call; |
klauss | 109:a5b8264ffbbc | 1390 | } |
klauss | 109:a5b8264ffbbc | 1391 | |
klauss | 109:a5b8264ffbbc | 1392 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1393 | { |
klauss | 109:a5b8264ffbbc | 1394 | send_msg ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 109:a5b8264ffbbc | 1395 | for ( register int i = 0; i < sizeof( VZ_call ); i++ ) |
klauss | 109:a5b8264ffbbc | 1396 | { |
klauss | 109:a5b8264ffbbc | 1397 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1398 | |
klauss | 109:a5b8264ffbbc | 1399 | if ( ( i % 32 ) == 0 ) |
klauss | 109:a5b8264ffbbc | 1400 | { |
klauss | 109:a5b8264ffbbc | 1401 | if( i != 0 ) |
klauss | 109:a5b8264ffbbc | 1402 | { |
klauss | 109:a5b8264ffbbc | 1403 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1404 | } |
klauss | 109:a5b8264ffbbc | 1405 | else |
klauss | 109:a5b8264ffbbc | 1406 | { |
klauss | 109:a5b8264ffbbc | 1407 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1408 | } |
klauss | 109:a5b8264ffbbc | 1409 | } |
klauss | 109:a5b8264ffbbc | 1410 | else |
klauss | 109:a5b8264ffbbc | 1411 | { |
klauss | 109:a5b8264ffbbc | 1412 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1413 | } |
klauss | 109:a5b8264ffbbc | 1414 | } |
klauss | 109:a5b8264ffbbc | 1415 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1416 | |
klauss | 109:a5b8264ffbbc | 1417 | if ( tcp_session ) { |
klauss | 109:a5b8264ffbbc | 1418 | char aux[ ( 32 * 3 ) + 5 ]; |
klauss | 109:a5b8264ffbbc | 1419 | |
klauss | 109:a5b8264ffbbc | 1420 | for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; |
klauss | 109:a5b8264ffbbc | 1421 | |
klauss | 109:a5b8264ffbbc | 1422 | ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1423 | |
klauss | 109:a5b8264ffbbc | 1424 | VZ_call * call = __find_Call__( v_call, print_hex_this_call ); |
klauss | 109:a5b8264ffbbc | 1425 | |
klauss | 109:a5b8264ffbbc | 1426 | uint8_t * ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1427 | if( call != NULL ) |
klauss | 109:a5b8264ffbbc | 1428 | { |
klauss | 109:a5b8264ffbbc | 1429 | ptr = ( uint8_t * ) call; |
klauss | 109:a5b8264ffbbc | 1430 | } |
klauss | 109:a5b8264ffbbc | 1431 | |
klauss | 109:a5b8264ffbbc | 1432 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1433 | { |
klauss | 109:a5b8264ffbbc | 1434 | bool finished = false; |
klauss | 109:a5b8264ffbbc | 1435 | volatile int i = 0; |
klauss | 109:a5b8264ffbbc | 1436 | int count = 0; |
klauss | 109:a5b8264ffbbc | 1437 | Timer dont_overwrite_tcp_buffer; |
klauss | 109:a5b8264ffbbc | 1438 | dont_overwrite_tcp_buffer.reset (); |
klauss | 109:a5b8264ffbbc | 1439 | dont_overwrite_tcp_buffer.start (); |
klauss | 109:a5b8264ffbbc | 1440 | |
klauss | 109:a5b8264ffbbc | 1441 | while ( !finished ) |
klauss | 109:a5b8264ffbbc | 1442 | { |
klauss | 109:a5b8264ffbbc | 1443 | if( dont_overwrite_tcp_buffer.read_ms () >= 20 ) |
klauss | 109:a5b8264ffbbc | 1444 | { |
klauss | 109:a5b8264ffbbc | 1445 | dont_overwrite_tcp_buffer.reset(); |
klauss | 109:a5b8264ffbbc | 1446 | for ( ; i < sizeof( VZ_call ); i++ ) |
klauss | 109:a5b8264ffbbc | 1447 | { |
klauss | 109:a5b8264ffbbc | 1448 | char tmp[ 16 ]; |
klauss | 109:a5b8264ffbbc | 1449 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1450 | strcat( aux, tmp ); |
klauss | 109:a5b8264ffbbc | 1451 | count++; |
klauss | 109:a5b8264ffbbc | 1452 | |
klauss | 109:a5b8264ffbbc | 1453 | if ( count >= 32 ) |
klauss | 109:a5b8264ffbbc | 1454 | { |
klauss | 109:a5b8264ffbbc | 1455 | count = 0; |
klauss | 109:a5b8264ffbbc | 1456 | i++; |
klauss | 109:a5b8264ffbbc | 1457 | break; |
klauss | 109:a5b8264ffbbc | 1458 | } |
klauss | 109:a5b8264ffbbc | 1459 | } |
klauss | 109:a5b8264ffbbc | 1460 | strcat ( aux, "\n\r\0" ); |
klauss | 109:a5b8264ffbbc | 1461 | tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 109:a5b8264ffbbc | 1462 | if ( i >= sizeof ( VZ_call ) ) finished = true; |
klauss | 109:a5b8264ffbbc | 1463 | strcpy ( aux, "\0" ); |
klauss | 109:a5b8264ffbbc | 1464 | } |
klauss | 109:a5b8264ffbbc | 1465 | } |
klauss | 109:a5b8264ffbbc | 1466 | dont_overwrite_tcp_buffer.reset(); |
klauss | 109:a5b8264ffbbc | 1467 | dont_overwrite_tcp_buffer.stop(); |
klauss | 109:a5b8264ffbbc | 1468 | tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 109:a5b8264ffbbc | 1469 | } |
klauss | 109:a5b8264ffbbc | 1470 | } |
klauss | 109:a5b8264ffbbc | 1471 | } |
klauss | 109:a5b8264ffbbc | 1472 | else |
klauss | 109:a5b8264ffbbc | 1473 | { |
klauss | 109:a5b8264ffbbc | 1474 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1475 | { |
klauss | 109:a5b8264ffbbc | 1476 | debug_msg("Call %d not found", print_this_call ); |
klauss | 109:a5b8264ffbbc | 1477 | } |
klauss | 109:a5b8264ffbbc | 1478 | else |
klauss | 109:a5b8264ffbbc | 1479 | { |
klauss | 109:a5b8264ffbbc | 1480 | send_msg("Call %d not found", print_this_call ); |
klauss | 109:a5b8264ffbbc | 1481 | } |
klauss | 109:a5b8264ffbbc | 1482 | } |
klauss | 109:a5b8264ffbbc | 1483 | } |
klauss | 109:a5b8264ffbbc | 1484 | |
klauss | 109:a5b8264ffbbc | 1485 | |
klauss | 109:a5b8264ffbbc | 1486 | if ( print_hex_rtp_var ) |
klauss | 109:a5b8264ffbbc | 1487 | { |
klauss | 109:a5b8264ffbbc | 1488 | print_hex_rtp_var = false; |
klauss | 109:a5b8264ffbbc | 1489 | VZ_call * call = __find_Call__( v_call, print_hex_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1490 | |
klauss | 109:a5b8264ffbbc | 1491 | uint8_t * ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1492 | if( call != NULL ) |
klauss | 109:a5b8264ffbbc | 1493 | { |
klauss | 109:a5b8264ffbbc | 1494 | ptr = ( uint8_t * ) call -> check_rtp (); |
klauss | 109:a5b8264ffbbc | 1495 | } |
klauss | 109:a5b8264ffbbc | 1496 | |
klauss | 109:a5b8264ffbbc | 1497 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1498 | { |
klauss | 109:a5b8264ffbbc | 1499 | send_msg ("Values :: %p\r\n", ( void *) ptr ); |
klauss | 109:a5b8264ffbbc | 1500 | for ( register int i = 0; i < sizeof( RTP ); i++ ) |
klauss | 109:a5b8264ffbbc | 1501 | { |
klauss | 109:a5b8264ffbbc | 1502 | if( debug_uart3 ) pc.printf("%x", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1503 | |
klauss | 109:a5b8264ffbbc | 1504 | if ( ( i % 32 ) == 0 ) |
klauss | 109:a5b8264ffbbc | 1505 | { |
klauss | 109:a5b8264ffbbc | 1506 | if( i != 0 ) |
klauss | 109:a5b8264ffbbc | 1507 | { |
klauss | 109:a5b8264ffbbc | 1508 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1509 | } |
klauss | 109:a5b8264ffbbc | 1510 | else |
klauss | 109:a5b8264ffbbc | 1511 | { |
klauss | 109:a5b8264ffbbc | 1512 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1513 | } |
klauss | 109:a5b8264ffbbc | 1514 | } |
klauss | 109:a5b8264ffbbc | 1515 | else |
klauss | 109:a5b8264ffbbc | 1516 | { |
klauss | 109:a5b8264ffbbc | 1517 | if( debug_uart3 ) pc.printf(" "); |
klauss | 109:a5b8264ffbbc | 1518 | } |
klauss | 109:a5b8264ffbbc | 1519 | } |
klauss | 109:a5b8264ffbbc | 1520 | if ( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 109:a5b8264ffbbc | 1521 | |
klauss | 109:a5b8264ffbbc | 1522 | if ( tcp_session ) { |
klauss | 109:a5b8264ffbbc | 1523 | char aux[ ( 32 * 3 ) + 5 ]; |
klauss | 109:a5b8264ffbbc | 1524 | |
klauss | 109:a5b8264ffbbc | 1525 | for ( register int i = 0; i < ( 32 * 3 ) + 5 ; i++ ) aux [ i ] = 0; |
klauss | 109:a5b8264ffbbc | 1526 | |
klauss | 109:a5b8264ffbbc | 1527 | ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1528 | |
klauss | 109:a5b8264ffbbc | 1529 | VZ_call * call = __find_Call__( v_call, print_hex_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1530 | |
klauss | 109:a5b8264ffbbc | 1531 | uint8_t * ptr = NULL; |
klauss | 109:a5b8264ffbbc | 1532 | if( call != NULL ) |
klauss | 109:a5b8264ffbbc | 1533 | { |
klauss | 109:a5b8264ffbbc | 1534 | ptr = ( uint8_t * ) call -> check_rtp (); |
klauss | 109:a5b8264ffbbc | 1535 | } |
klauss | 109:a5b8264ffbbc | 1536 | |
klauss | 109:a5b8264ffbbc | 1537 | if ( ptr != NULL ) |
klauss | 109:a5b8264ffbbc | 1538 | { |
klauss | 109:a5b8264ffbbc | 1539 | bool finished = false; |
klauss | 109:a5b8264ffbbc | 1540 | volatile int i = 0; |
klauss | 109:a5b8264ffbbc | 1541 | int count = 0; |
klauss | 109:a5b8264ffbbc | 1542 | Timer dont_overwrite_tcp_buffer; |
klauss | 109:a5b8264ffbbc | 1543 | dont_overwrite_tcp_buffer.reset (); |
klauss | 109:a5b8264ffbbc | 1544 | dont_overwrite_tcp_buffer.start (); |
klauss | 109:a5b8264ffbbc | 1545 | |
klauss | 109:a5b8264ffbbc | 1546 | while ( !finished ) |
klauss | 109:a5b8264ffbbc | 1547 | { |
klauss | 109:a5b8264ffbbc | 1548 | if( dont_overwrite_tcp_buffer.read_ms () >= 20 ) |
klauss | 109:a5b8264ffbbc | 1549 | { |
klauss | 109:a5b8264ffbbc | 1550 | dont_overwrite_tcp_buffer.reset(); |
klauss | 109:a5b8264ffbbc | 1551 | for ( ; i < sizeof( RTP ); i++ ) |
klauss | 109:a5b8264ffbbc | 1552 | { |
klauss | 109:a5b8264ffbbc | 1553 | char tmp[ 16 ]; |
klauss | 109:a5b8264ffbbc | 1554 | sprintf( tmp, "%x ", *ptr++ ); |
klauss | 109:a5b8264ffbbc | 1555 | strcat( aux, tmp ); |
klauss | 109:a5b8264ffbbc | 1556 | count++; |
klauss | 109:a5b8264ffbbc | 1557 | |
klauss | 109:a5b8264ffbbc | 1558 | if ( count >= 32 ) |
klauss | 109:a5b8264ffbbc | 1559 | { |
klauss | 109:a5b8264ffbbc | 1560 | count = 0; |
klauss | 109:a5b8264ffbbc | 1561 | i++; |
klauss | 109:a5b8264ffbbc | 1562 | break; |
klauss | 109:a5b8264ffbbc | 1563 | } |
klauss | 109:a5b8264ffbbc | 1564 | } |
klauss | 109:a5b8264ffbbc | 1565 | strcat ( aux, "\n\r\0" ); |
klauss | 109:a5b8264ffbbc | 1566 | tcp_client.send_all ( ( char *)aux, strlen( (char * )aux ) ); |
klauss | 109:a5b8264ffbbc | 1567 | if ( i >= sizeof ( RTP ) ) finished = true; |
klauss | 109:a5b8264ffbbc | 1568 | strcpy ( aux, "\0" ); |
klauss | 109:a5b8264ffbbc | 1569 | } |
klauss | 109:a5b8264ffbbc | 1570 | } |
klauss | 109:a5b8264ffbbc | 1571 | dont_overwrite_tcp_buffer.reset(); |
klauss | 109:a5b8264ffbbc | 1572 | dont_overwrite_tcp_buffer.stop(); |
klauss | 109:a5b8264ffbbc | 1573 | tcp_client.send_all ( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 109:a5b8264ffbbc | 1574 | } |
klauss | 109:a5b8264ffbbc | 1575 | } |
klauss | 109:a5b8264ffbbc | 1576 | } |
klauss | 109:a5b8264ffbbc | 1577 | else |
klauss | 109:a5b8264ffbbc | 1578 | { |
klauss | 109:a5b8264ffbbc | 1579 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1580 | { |
klauss | 109:a5b8264ffbbc | 1581 | debug_msg("Call %d not found", print_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1582 | } |
klauss | 109:a5b8264ffbbc | 1583 | else |
klauss | 109:a5b8264ffbbc | 1584 | { |
klauss | 109:a5b8264ffbbc | 1585 | send_msg("Call %d not found", print_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1586 | } |
klauss | 109:a5b8264ffbbc | 1587 | } |
klauss | 109:a5b8264ffbbc | 1588 | } |
klauss | 109:a5b8264ffbbc | 1589 | |
klauss | 109:a5b8264ffbbc | 1590 | if ( print_rtp_var ) |
klauss | 109:a5b8264ffbbc | 1591 | { |
klauss | 109:a5b8264ffbbc | 1592 | print_rtp_var = false; |
klauss | 109:a5b8264ffbbc | 1593 | VZ_call * call = __find_Call__( v_call, print_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1594 | if ( call != NULL ) |
klauss | 109:a5b8264ffbbc | 1595 | { |
klauss | 109:a5b8264ffbbc | 1596 | if ( call -> check_rtp () != NULL ) |
klauss | 109:a5b8264ffbbc | 1597 | { |
klauss | 109:a5b8264ffbbc | 1598 | send_msg ("Values :: %p\r\n", ( void *) call -> check_rtp () ); |
klauss | 109:a5b8264ffbbc | 1599 | call -> rtp_print_yourself (); |
klauss | 109:a5b8264ffbbc | 1600 | } |
klauss | 109:a5b8264ffbbc | 1601 | else |
klauss | 109:a5b8264ffbbc | 1602 | { |
klauss | 109:a5b8264ffbbc | 1603 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1604 | { |
klauss | 109:a5b8264ffbbc | 1605 | debug_msg("Call->RTP %d not found", print_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1606 | } |
klauss | 109:a5b8264ffbbc | 1607 | else |
klauss | 109:a5b8264ffbbc | 1608 | { |
klauss | 109:a5b8264ffbbc | 1609 | send_msg("Call->RTP %d not found", print_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1610 | } |
klauss | 109:a5b8264ffbbc | 1611 | } |
klauss | 109:a5b8264ffbbc | 1612 | } |
klauss | 109:a5b8264ffbbc | 1613 | else |
klauss | 109:a5b8264ffbbc | 1614 | { |
klauss | 109:a5b8264ffbbc | 1615 | if( print_values ) |
klauss | 109:a5b8264ffbbc | 1616 | { |
klauss | 109:a5b8264ffbbc | 1617 | debug_msg("Call->RTP %d not found", print_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1618 | } |
klauss | 109:a5b8264ffbbc | 1619 | else |
klauss | 109:a5b8264ffbbc | 1620 | { |
klauss | 109:a5b8264ffbbc | 1621 | send_msg("Call->RTP %d not found", print_this_rtp ); |
klauss | 109:a5b8264ffbbc | 1622 | } |
klauss | 109:a5b8264ffbbc | 1623 | } |
klauss | 109:a5b8264ffbbc | 1624 | } |
klauss | 109:a5b8264ffbbc | 1625 | |
klauss | 109:a5b8264ffbbc | 1626 | //end debug_print |
klauss | 91:c2a86b1f8aaa | 1627 | |
klauss | 91:c2a86b1f8aaa | 1628 | if( reset_cks == true ) { |
klauss | 81:3656f00ab3db | 1629 | pkg_cksok = 0; |
klauss | 81:3656f00ab3db | 1630 | pkg_ckserr = 0; |
klauss | 99:e80850c51106 | 1631 | pkg_zero = 0; |
klauss | 81:3656f00ab3db | 1632 | reset_cks = false; |
klauss | 99:e80850c51106 | 1633 | out_of_range = 0; |
klauss | 99:e80850c51106 | 1634 | missed_pkg = 0; |
klauss | 100:09a23fcd3bdf | 1635 | delayed_pkg_to_cb = 0; |
klauss | 99:e80850c51106 | 1636 | cpld_pkg_tx_counter = 0; |
klauss | 99:e80850c51106 | 1637 | cpld_pkg_rx_counter = 0; |
klauss | 81:3656f00ab3db | 1638 | pcks_s = true; |
klauss | 81:3656f00ab3db | 1639 | } |
klauss | 91:c2a86b1f8aaa | 1640 | |
klauss | 91:c2a86b1f8aaa | 1641 | if( pcks_s == true ) { |
klauss | 109:a5b8264ffbbc | 1642 | send_msg("PKG_CKS OK: %d :: PKG_CKS ERR: %d :: PKG_0: %d :: Out_of_range: %d :: Miss_Pkg :: %d" |
klauss | 109:a5b8264ffbbc | 1643 | "\n\r> TX_delayed :: %d :: TX_Counter :: %d :: RX_Counter :: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range, missed_pkg, delayed_pkg_to_cb, cpld_pkg_tx_counter, cpld_pkg_rx_counter ); |
klauss | 81:3656f00ab3db | 1644 | pcks_s = false; |
klauss | 81:3656f00ab3db | 1645 | } |
klauss | 109:a5b8264ffbbc | 1646 | |
klauss | 100:09a23fcd3bdf | 1647 | if( flood_bug_pkg ){ |
klauss | 100:09a23fcd3bdf | 1648 | static int id = 0x10; |
klauss | 100:09a23fcd3bdf | 1649 | if( id < 10 ) id = 0x0b; |
klauss | 109:a5b8264ffbbc | 1650 | send2callboxes( __build_cb_package__( 5828, 5123, __REGISTRY__, |
klauss | 109:a5b8264ffbbc | 1651 | ( char * )buffer, id++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 100:09a23fcd3bdf | 1652 | } |
klauss | 100:09a23fcd3bdf | 1653 | |
klauss | 109:a5b8264ffbbc | 1654 | if( led_sync_timer.read() > 1 ) { |
klauss | 78:1353744f01e1 | 1655 | led_sync_timer.reset(); |
klauss | 78:1353744f01e1 | 1656 | led3 = !led3; |
klauss | 78:1353744f01e1 | 1657 | CAB_LED = !CAB_LED; |
klauss | 78:1353744f01e1 | 1658 | } |
klauss | 109:a5b8264ffbbc | 1659 | |
klauss | 109:a5b8264ffbbc | 1660 | static int test_ext = 5102; |
klauss | 109:a5b8264ffbbc | 1661 | static int test_port = 5102; |
klauss | 109:a5b8264ffbbc | 1662 | |
klauss | 109:a5b8264ffbbc | 1663 | if ( tango ) |
klauss | 109:a5b8264ffbbc | 1664 | { |
klauss | 109:a5b8264ffbbc | 1665 | if ( v_cb -> size () >= 27 ) |
klauss | 108:18a3702650f3 | 1666 | { |
klauss | 109:a5b8264ffbbc | 1667 | tango = false; |
klauss | 109:a5b8264ffbbc | 1668 | test_timer.start (); |
klauss | 109:a5b8264ffbbc | 1669 | } |
klauss | 109:a5b8264ffbbc | 1670 | |
klauss | 109:a5b8264ffbbc | 1671 | ext = test_ext++; |
klauss | 109:a5b8264ffbbc | 1672 | port = test_port++; |
klauss | 109:a5b8264ffbbc | 1673 | type = __REGISTRY__; |
klauss | 109:a5b8264ffbbc | 1674 | data = buffer; |
klauss | 105:a930035b6556 | 1675 | } |
klauss | 109:a5b8264ffbbc | 1676 | |
klauss | 109:a5b8264ffbbc | 1677 | if( v_cb -> size () >= 27 ) |
klauss | 109:a5b8264ffbbc | 1678 | { |
klauss | 109:a5b8264ffbbc | 1679 | if( ( test_timer.read_ms () > 500 ) && ( type == __DO_NOTHING__ ) ) |
klauss | 109:a5b8264ffbbc | 1680 | { |
klauss | 109:a5b8264ffbbc | 1681 | if( test_ext >= ( 5102 + 26 ) ) test_ext = 5102; |
klauss | 109:a5b8264ffbbc | 1682 | if( test_port >= ( 5102 + 26 ) ) test_port = 5102; |
klauss | 109:a5b8264ffbbc | 1683 | |
klauss | 109:a5b8264ffbbc | 1684 | ext = test_ext++; |
klauss | 109:a5b8264ffbbc | 1685 | port = test_port++; |
klauss | 109:a5b8264ffbbc | 1686 | type = __REGISTRY__; |
klauss | 109:a5b8264ffbbc | 1687 | data = buffer; |
klauss | 109:a5b8264ffbbc | 1688 | test_timer.reset (); |
klauss | 109:a5b8264ffbbc | 1689 | } |
klauss | 109:a5b8264ffbbc | 1690 | } |
klauss | 109:a5b8264ffbbc | 1691 | |
klauss | 91:c2a86b1f8aaa | 1692 | switch( type ) { |
klauss | 91:c2a86b1f8aaa | 1693 | case __DO_NOTHING__ : |
klauss | 91:c2a86b1f8aaa | 1694 | {} |
klauss | 91:c2a86b1f8aaa | 1695 | break; |
klauss | 91:c2a86b1f8aaa | 1696 | |
klauss | 0:4d17cd9c8f9d | 1697 | case __CB_BYE__ : { |
klauss | 63:0d95da692bb4 | 1698 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 1699 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 1700 | if( cb != NULL ) { |
klauss | 81:3656f00ab3db | 1701 | 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 | 1702 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 1703 | cb->set_msg_id( data[ 0 ] ); |
klauss | 81:3656f00ab3db | 1704 | if( debug_main || debug_invite ) debug_msg( "Request bye from CBx " ); |
klauss | 92:92df17f538a8 | 1705 | |
klauss | 81:3656f00ab3db | 1706 | bool already_removed = true; |
klauss | 91:c2a86b1f8aaa | 1707 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 0:4d17cd9c8f9d | 1708 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 1709 | if( call->get_cb_ext() == ext ) { |
klauss | 81:3656f00ab3db | 1710 | already_removed = false; |
klauss | 4:de46f0d9b14d | 1711 | cb->send_bye(); |
klauss | 91:c2a86b1f8aaa | 1712 | |
klauss | 0:4d17cd9c8f9d | 1713 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 1714 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 1715 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 91:c2a86b1f8aaa | 1716 | |
klauss | 0:4d17cd9c8f9d | 1717 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 1718 | set_status( cb->sip->status, sip_idle ); |
klauss | 91:c2a86b1f8aaa | 1719 | |
klauss | 81:3656f00ab3db | 1720 | v_call->remove_element( i ); |
klauss | 109:a5b8264ffbbc | 1721 | |
klauss | 109:a5b8264ffbbc | 1722 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 109:a5b8264ffbbc | 1723 | //cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 91:c2a86b1f8aaa | 1724 | |
klauss | 109:a5b8264ffbbc | 1725 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 109:a5b8264ffbbc | 1726 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 92:92df17f538a8 | 1727 | |
klauss | 92:92df17f538a8 | 1728 | // envia o ack bye depois atualiza o msg_id |
klauss | 92:92df17f538a8 | 1729 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 91:c2a86b1f8aaa | 1730 | |
klauss | 3:cd9148672e25 | 1731 | delete( call ); |
klauss | 109:a5b8264ffbbc | 1732 | //cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 1733 | } |
klauss | 0:4d17cd9c8f9d | 1734 | } |
klauss | 82:f55d13babca0 | 1735 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from vector call" ); |
klauss | 109:a5b8264ffbbc | 1736 | |
klauss | 109:a5b8264ffbbc | 1737 | //ok, mas nem sempre o cbx "entrou em call |
klauss | 82:f55d13babca0 | 1738 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 1739 | Call_Box * cb = (Call_Box *)v_cb->get_element( i ); |
klauss | 82:f55d13babca0 | 1740 | if( cb->get_ext() == ext ) { |
klauss | 82:f55d13babca0 | 1741 | already_removed = true; |
klauss | 82:f55d13babca0 | 1742 | if( cb->get_status() != cb_idle ) { |
klauss | 82:f55d13babca0 | 1743 | already_removed = false; |
klauss | 82:f55d13babca0 | 1744 | cb->send_bye(); |
klauss | 82:f55d13babca0 | 1745 | |
klauss | 82:f55d13babca0 | 1746 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 82:f55d13babca0 | 1747 | cb->set_timeslice( 0x00 ); |
klauss | 82:f55d13babca0 | 1748 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 82:f55d13babca0 | 1749 | |
klauss | 82:f55d13babca0 | 1750 | set_status( cb->status, cb_idle ); |
klauss | 82:f55d13babca0 | 1751 | set_status( cb->sip->status, sip_idle ); |
klauss | 82:f55d13babca0 | 1752 | |
klauss | 109:a5b8264ffbbc | 1753 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 109:a5b8264ffbbc | 1754 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 82:f55d13babca0 | 1755 | |
klauss | 109:a5b8264ffbbc | 1756 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 92:92df17f538a8 | 1757 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 109:a5b8264ffbbc | 1758 | |
klauss | 109:a5b8264ffbbc | 1759 | //cb->re_start_timer(); |
klauss | 82:f55d13babca0 | 1760 | } |
klauss | 82:f55d13babca0 | 1761 | } |
klauss | 82:f55d13babca0 | 1762 | } |
klauss | 91:c2a86b1f8aaa | 1763 | |
klauss | 82:f55d13babca0 | 1764 | if( already_removed ) if( debug_main || debug_invite ) debug_msg( "Already removed from inviting queue" ); |
klauss | 91:c2a86b1f8aaa | 1765 | |
klauss | 78:1353744f01e1 | 1766 | cb->registry(); |
klauss | 91:c2a86b1f8aaa | 1767 | } else if( debug_invite || debug_main ) debug_msg("Bye from who ? %d", ext ); |
klauss | 91:c2a86b1f8aaa | 1768 | } |
klauss | 91:c2a86b1f8aaa | 1769 | break; |
klauss | 91:c2a86b1f8aaa | 1770 | |
klauss | 0:4d17cd9c8f9d | 1771 | case __INVITE__ : { |
klauss | 109:a5b8264ffbbc | 1772 | if( drop_invite_pkg ){ |
klauss | 109:a5b8264ffbbc | 1773 | debug_msg("Dropando invite pck msg id :: %d", data[ 0 ] ); |
klauss | 109:a5b8264ffbbc | 1774 | break; |
klauss | 109:a5b8264ffbbc | 1775 | } |
klauss | 63:0d95da692bb4 | 1776 | invite_counter++; |
klauss | 78:1353744f01e1 | 1777 | if( debug_invite ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 0:4d17cd9c8f9d | 1778 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 1779 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 1780 | if( v_cb->size() < __MAX_CB_IN_A_BRANCH__ ) { |
klauss | 91:c2a86b1f8aaa | 1781 | if( debug_main ) debug_msg( "Adding CBx :: %i", ext ); |
klauss | 91:c2a86b1f8aaa | 1782 | cb = new Call_Box( ext, port ); |
klauss | 91:c2a86b1f8aaa | 1783 | |
klauss | 91:c2a86b1f8aaa | 1784 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 1785 | memory_is_over = true; |
klauss | 91:c2a86b1f8aaa | 1786 | if( debug_memory ) debug_msg("Invite allocation cb fail"); |
klauss | 91:c2a86b1f8aaa | 1787 | } else { |
klauss | 91:c2a86b1f8aaa | 1788 | v_cb->add( cb ); |
klauss | 91:c2a86b1f8aaa | 1789 | } |
klauss | 89:0fe315117b00 | 1790 | } |
klauss | 0:4d17cd9c8f9d | 1791 | } |
klauss | 91:c2a86b1f8aaa | 1792 | if( cb != NULL ) { |
klauss | 91:c2a86b1f8aaa | 1793 | cb->set_msg_id( data[ 0 ] ); |
klauss | 92:92df17f538a8 | 1794 | if( cb->status == cb_idle ){ |
klauss | 92:92df17f538a8 | 1795 | cb->set_invite_response_ok(); |
klauss | 92:92df17f538a8 | 1796 | cb->invite_retry_count_reset(); |
klauss | 92:92df17f538a8 | 1797 | } |
klauss | 87:679ee0d594a9 | 1798 | invite_handler( v_call, v_cb, ts, cb ); |
klauss | 87:679ee0d594a9 | 1799 | } |
klauss | 91:c2a86b1f8aaa | 1800 | } |
klauss | 91:c2a86b1f8aaa | 1801 | break; |
klauss | 4:de46f0d9b14d | 1802 | case __REGISTRY__ : { |
klauss | 63:0d95da692bb4 | 1803 | registry_counter++; |
klauss | 78:1353744f01e1 | 1804 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 1805 | if( v_cb->size() < __MAX_CB_IN_A_BRANCH__ ) { |
klauss | 91:c2a86b1f8aaa | 1806 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 1807 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 91:c2a86b1f8aaa | 1808 | cb = new Call_Box( ext, port ); |
klauss | 91:c2a86b1f8aaa | 1809 | |
klauss | 91:c2a86b1f8aaa | 1810 | if( cb == NULL ) { |
klauss | 91:c2a86b1f8aaa | 1811 | memory_is_over = true; |
klauss | 91:c2a86b1f8aaa | 1812 | if( debug_memory ) debug_msg("Registry cb allocation fail"); |
klauss | 91:c2a86b1f8aaa | 1813 | } else { |
klauss | 91:c2a86b1f8aaa | 1814 | v_cb->add( cb ); |
klauss | 91:c2a86b1f8aaa | 1815 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 91:c2a86b1f8aaa | 1816 | } |
klauss | 87:679ee0d594a9 | 1817 | } |
klauss | 0:4d17cd9c8f9d | 1818 | } |
klauss | 78:1353744f01e1 | 1819 | if( debug_main ) debug_msg("Registered %d - %d", ext, port ); |
klauss | 91:c2a86b1f8aaa | 1820 | |
klauss | 87:679ee0d594a9 | 1821 | if( cb != NULL ) cb->registry(); |
klauss | 109:a5b8264ffbbc | 1822 | |
klauss | 91:c2a86b1f8aaa | 1823 | } |
klauss | 91:c2a86b1f8aaa | 1824 | break; |
klauss | 4:de46f0d9b14d | 1825 | case __BOOT__ : { |
klauss | 63:0d95da692bb4 | 1826 | boot_counter++; |
klauss | 99:e80850c51106 | 1827 | if( debug_boot == true ){ |
klauss | 99:e80850c51106 | 1828 | send_msg("Rcv boot pkg from (%d, %d) pkg-id %d", ext, port, data[ 0 ] ); |
klauss | 99:e80850c51106 | 1829 | } |
klauss | 109:a5b8264ffbbc | 1830 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 109:a5b8264ffbbc | 1831 | ( char * )data, data[ 0 ] | BIT7, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 109:a5b8264ffbbc | 1832 | } |
klauss | 109:a5b8264ffbbc | 1833 | break; |
klauss | 109:a5b8264ffbbc | 1834 | |
klauss | 109:a5b8264ffbbc | 1835 | case __TELEMETRY__ : { |
klauss | 109:a5b8264ffbbc | 1836 | if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); |
klauss | 109:a5b8264ffbbc | 1837 | build_telemetry_report( ext, port, ( char *)data ); |
klauss | 91:c2a86b1f8aaa | 1838 | } |
klauss | 91:c2a86b1f8aaa | 1839 | break; |
klauss | 99:e80850c51106 | 1840 | |
klauss | 99:e80850c51106 | 1841 | case __FW__ : { |
klauss | 99:e80850c51106 | 1842 | if( debug_fw_print ) send_msg("::FW pkg from %d - %d::", ext, port ); |
klauss | 99:e80850c51106 | 1843 | fw_cbx_pkg( ext, port, ( char *)buffer ); |
klauss | 99:e80850c51106 | 1844 | } |
klauss | 99:e80850c51106 | 1845 | break; |
klauss | 91:c2a86b1f8aaa | 1846 | |
klauss | 67:cdedc64d9921 | 1847 | case __BOOTLOADER_CBX__ : { |
klauss | 67:cdedc64d9921 | 1848 | bootloader_cbx_counter++; |
klauss | 109:a5b8264ffbbc | 1849 | //int ret = bl_cbx_reply_to_eth( ext, ( char * )data ); |
klauss | 91:c2a86b1f8aaa | 1850 | } |
klauss | 91:c2a86b1f8aaa | 1851 | break; |
klauss | 91:c2a86b1f8aaa | 1852 | |
klauss | 109:a5b8264ffbbc | 1853 | case __PROMPT__ : { |
klauss | 78:1353744f01e1 | 1854 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 91:c2a86b1f8aaa | 1855 | |
klauss | 91:c2a86b1f8aaa | 1856 | if( cb == NULL ) { |
klauss | 112:6ae726539ab9 | 1857 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 112:6ae726539ab9 | 1858 | ( char * )data, ( ( data[ 0 ] & ~BIT7 ) + 1 ), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 109:a5b8264ffbbc | 1859 | |
klauss | 109:a5b8264ffbbc | 1860 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 109:a5b8264ffbbc | 1861 | cb = new Call_Box( ext, port ); |
klauss | 109:a5b8264ffbbc | 1862 | if( cb == NULL ){ |
klauss | 109:a5b8264ffbbc | 1863 | memory_is_over = true; |
klauss | 109:a5b8264ffbbc | 1864 | }else{ |
klauss | 109:a5b8264ffbbc | 1865 | v_cb->add( cb ); |
klauss | 109:a5b8264ffbbc | 1866 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 87:679ee0d594a9 | 1867 | } |
klauss | 48:195c97f12e8e | 1868 | } |
klauss | 91:c2a86b1f8aaa | 1869 | |
klauss | 92:92df17f538a8 | 1870 | if( cb!= NULL ) cb->registry(); |
klauss | 91:c2a86b1f8aaa | 1871 | |
klauss | 91:c2a86b1f8aaa | 1872 | if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ) { |
klauss | 78:1353744f01e1 | 1873 | if( debug_ping ) send_msg( "Prompt pkg from ( %i, %i ) :: Ping", ext, port ); |
klauss | 91:c2a86b1f8aaa | 1874 | } else { |
klauss | 78:1353744f01e1 | 1875 | prompt_counter++; |
klauss | 109:a5b8264ffbbc | 1876 | //fixme isso nao poderia ser resolvido com um sendmsg ? |
klauss | 78:1353744f01e1 | 1877 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 91:c2a86b1f8aaa | 1878 | for( register uint8_t i = 0; i < 32; i++ ) { |
klauss | 100:09a23fcd3bdf | 1879 | if( debug_uart3 ) pc.printf("%c", data[ i ] ); |
klauss | 100:09a23fcd3bdf | 1880 | if( i == 15 ) if( debug_uart3 ) pc.printf( "\r\n" ); |
klauss | 78:1353744f01e1 | 1881 | } |
klauss | 100:09a23fcd3bdf | 1882 | if( debug_uart3 ) pc.printf("\n\r> "); |
klauss | 91:c2a86b1f8aaa | 1883 | |
klauss | 109:a5b8264ffbbc | 1884 | if( tcp_session ) { |
klauss | 109:a5b8264ffbbc | 1885 | char aux[ __CB_BUFFER_SIZE__ + 3 ]; |
klauss | 109:a5b8264ffbbc | 1886 | strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); |
klauss | 78:1353744f01e1 | 1887 | strcat( aux, "\n\r\0" ); |
klauss | 78:1353744f01e1 | 1888 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 78:1353744f01e1 | 1889 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 78:1353744f01e1 | 1890 | } |
klauss | 48:195c97f12e8e | 1891 | } |
klauss | 91:c2a86b1f8aaa | 1892 | } |
klauss | 91:c2a86b1f8aaa | 1893 | break; |
klauss | 0:4d17cd9c8f9d | 1894 | case __AUDIO__ : { |
klauss | 63:0d95da692bb4 | 1895 | audio_counter++; |
klauss | 78:1353744f01e1 | 1896 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 91:c2a86b1f8aaa | 1897 | if( call != NULL ) { |
klauss | 109:a5b8264ffbbc | 1898 | if ( drop_rtp_from_cbx_pkg ) |
klauss | 109:a5b8264ffbbc | 1899 | { |
klauss | 109:a5b8264ffbbc | 1900 | led2 = !led2; |
klauss | 109:a5b8264ffbbc | 1901 | break; |
klauss | 109:a5b8264ffbbc | 1902 | } |
klauss | 112:6ae726539ab9 | 1903 | else |
klauss | 112:6ae726539ab9 | 1904 | { |
klauss | 112:6ae726539ab9 | 1905 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 112:6ae726539ab9 | 1906 | call->send_message( pkg ); |
klauss | 112:6ae726539ab9 | 1907 | call->cbx_pkg_idle_timer_reset(); |
klauss | 112:6ae726539ab9 | 1908 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 112:6ae726539ab9 | 1909 | if( cb != NULL ){ |
klauss | 112:6ae726539ab9 | 1910 | cb->set_invite_response_ok(); |
klauss | 112:6ae726539ab9 | 1911 | cb->invite_retry_count_reset(); |
klauss | 112:6ae726539ab9 | 1912 | } |
klauss | 112:6ae726539ab9 | 1913 | } |
klauss | 91:c2a86b1f8aaa | 1914 | } else { |
klauss | 78:1353744f01e1 | 1915 | if( debug_main ) debug_msg("received missed package from CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 1916 | } |
klauss | 91:c2a86b1f8aaa | 1917 | } |
klauss | 91:c2a86b1f8aaa | 1918 | break; |
klauss | 109:a5b8264ffbbc | 1919 | }// fim switch |
klauss | 105:a930035b6556 | 1920 | |
klauss | 99:e80850c51106 | 1921 | { // rajada |
klauss | 112:6ae726539ab9 | 1922 | if( invite_retry_timer.read_ms() > 30 ) |
klauss | 112:6ae726539ab9 | 1923 | { |
klauss | 99:e80850c51106 | 1924 | invite_retry_timer.reset(); |
klauss | 99:e80850c51106 | 1925 | |
klauss | 112:6ae726539ab9 | 1926 | static int retry_invite_pkg = 0; |
klauss | 112:6ae726539ab9 | 1927 | bool need_retry = false; |
klauss | 112:6ae726539ab9 | 1928 | Call_Box * cb = NULL; |
klauss | 112:6ae726539ab9 | 1929 | |
klauss | 112:6ae726539ab9 | 1930 | for ( register int i = 0; i < v_cb->size(); i++ ) |
klauss | 112:6ae726539ab9 | 1931 | { |
klauss | 112:6ae726539ab9 | 1932 | retry_invite_pkg++; |
klauss | 112:6ae726539ab9 | 1933 | if ( retry_invite_pkg >= v_cb->size() ) retry_invite_pkg = 0; |
klauss | 112:6ae726539ab9 | 1934 | |
klauss | 112:6ae726539ab9 | 1935 | cb = (Call_Box * )v_cb->get_element( i ); |
klauss | 112:6ae726539ab9 | 1936 | if ( cb != NULL ) |
klauss | 112:6ae726539ab9 | 1937 | { |
klauss | 112:6ae726539ab9 | 1938 | if ( ( cb->status == cb_ringing ) || ( cb->status == cb_trying ) || ( cb->status == cb_on_call ) ) |
klauss | 112:6ae726539ab9 | 1939 | { |
klauss | 112:6ae726539ab9 | 1940 | need_retry = true; |
klauss | 99:e80850c51106 | 1941 | break; |
klauss | 99:e80850c51106 | 1942 | } |
klauss | 92:92df17f538a8 | 1943 | } |
klauss | 99:e80850c51106 | 1944 | } |
klauss | 109:a5b8264ffbbc | 1945 | |
klauss | 112:6ae726539ab9 | 1946 | if ( need_retry ) |
klauss | 112:6ae726539ab9 | 1947 | { |
klauss | 112:6ae726539ab9 | 1948 | if( cb->get_invite_response() == false ) |
klauss | 112:6ae726539ab9 | 1949 | { |
klauss | 112:6ae726539ab9 | 1950 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 99:e80850c51106 | 1951 | |
klauss | 112:6ae726539ab9 | 1952 | buffer[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 112:6ae726539ab9 | 1953 | |
klauss | 112:6ae726539ab9 | 1954 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __INVITE__, ( char * )buffer, |
klauss | 112:6ae726539ab9 | 1955 | cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 109:a5b8264ffbbc | 1956 | |
klauss | 112:6ae726539ab9 | 1957 | if( debug_invite ) debug_msg("resend invite OK to Cbx : ( %d, %d )", cb->get_ext(), cb->get_port() ); |
klauss | 112:6ae726539ab9 | 1958 | } |
klauss | 112:6ae726539ab9 | 1959 | |
klauss | 112:6ae726539ab9 | 1960 | if( cb->get_invite_retry_count() == 0 ) |
klauss | 112:6ae726539ab9 | 1961 | { |
klauss | 112:6ae726539ab9 | 1962 | cb->send_bye(); |
klauss | 92:92df17f538a8 | 1963 | |
klauss | 112:6ae726539ab9 | 1964 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 112:6ae726539ab9 | 1965 | cb->set_timeslice( 0x00 ); |
klauss | 99:e80850c51106 | 1966 | |
klauss | 112:6ae726539ab9 | 1967 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 99:e80850c51106 | 1968 | |
klauss | 112:6ae726539ab9 | 1969 | for( register uint8_t i = 0; i < v_call->size(); i++ ) |
klauss | 112:6ae726539ab9 | 1970 | { |
klauss | 112:6ae726539ab9 | 1971 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 112:6ae726539ab9 | 1972 | if( call->get_cb_ext() == cb->get_ext() ) |
klauss | 112:6ae726539ab9 | 1973 | { |
klauss | 112:6ae726539ab9 | 1974 | v_call->remove_element( i ); |
klauss | 112:6ae726539ab9 | 1975 | if( call != NULL ) delete( call ); |
klauss | 112:6ae726539ab9 | 1976 | break; |
klauss | 92:92df17f538a8 | 1977 | } |
klauss | 112:6ae726539ab9 | 1978 | } |
klauss | 99:e80850c51106 | 1979 | |
klauss | 112:6ae726539ab9 | 1980 | if( debug_invite ) debug_msg( "-- No audio pkgs --" ); |
klauss | 112:6ae726539ab9 | 1981 | set_status( cb->status, cb_idle ); |
klauss | 112:6ae726539ab9 | 1982 | set_status( cb->sip->status, sip_idle ); |
klauss | 92:92df17f538a8 | 1983 | } |
klauss | 92:92df17f538a8 | 1984 | } |
klauss | 112:6ae726539ab9 | 1985 | } |
klauss | 109:a5b8264ffbbc | 1986 | } // fim rajada |
klauss | 109:a5b8264ffbbc | 1987 | |
klauss | 91:c2a86b1f8aaa | 1988 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 0:4d17cd9c8f9d | 1989 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 109:a5b8264ffbbc | 1990 | int length = 0; |
klauss | 109:a5b8264ffbbc | 1991 | char * tmp = call->get_eth_message( &length ); |
klauss | 109:a5b8264ffbbc | 1992 | if( tmp != NULL ) { |
klauss | 109:a5b8264ffbbc | 1993 | int cb_port = 0xffff; |
klauss | 109:a5b8264ffbbc | 1994 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 109:a5b8264ffbbc | 1995 | |
klauss | 109:a5b8264ffbbc | 1996 | if( cb != NULL ) { |
klauss | 109:a5b8264ffbbc | 1997 | cb_port = cb->get_port(); |
klauss | 109:a5b8264ffbbc | 1998 | |
klauss | 109:a5b8264ffbbc | 1999 | if ( drop_rtp_from_ast_pkg ) |
klauss | 109:a5b8264ffbbc | 2000 | { |
klauss | 109:a5b8264ffbbc | 2001 | led1 = !led1; |
klauss | 109:a5b8264ffbbc | 2002 | } |
klauss | 109:a5b8264ffbbc | 2003 | else |
klauss | 109:a5b8264ffbbc | 2004 | { |
klauss | 109:a5b8264ffbbc | 2005 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 108:18a3702650f3 | 2006 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 109:a5b8264ffbbc | 2007 | |
klauss | 108:18a3702650f3 | 2008 | send2callboxes( pkg2cb ); |
klauss | 109:a5b8264ffbbc | 2009 | } |
klauss | 109:a5b8264ffbbc | 2010 | |
klauss | 109:a5b8264ffbbc | 2011 | } else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 2012 | } |
klauss | 14:22a35f575502 | 2013 | } |
klauss | 109:a5b8264ffbbc | 2014 | |
klauss | 109:a5b8264ffbbc | 2015 | //if( v_call->size() == 0 ) refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 109:a5b8264ffbbc | 2016 | |
klauss | 109:a5b8264ffbbc | 2017 | if( timer_sync_refresh.read_ms() > 250 ) { |
klauss | 109:a5b8264ffbbc | 2018 | timer_sync_refresh.reset(); |
klauss | 106:a34fcf9f0e02 | 2019 | |
klauss | 109:a5b8264ffbbc | 2020 | static uint8_t mode = TIME_TO_REFRESH; |
klauss | 109:a5b8264ffbbc | 2021 | |
klauss | 109:a5b8264ffbbc | 2022 | if( mode == TIME_TO_REFRESH ) { |
klauss | 109:a5b8264ffbbc | 2023 | mode = TIME_TO_WAKE_UP; |
klauss | 109:a5b8264ffbbc | 2024 | refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 109:a5b8264ffbbc | 2025 | } else { |
klauss | 109:a5b8264ffbbc | 2026 | mode = TIME_TO_REFRESH; |
klauss | 109:a5b8264ffbbc | 2027 | if( wake_all ) if( v_call->size() == 0 ) wake_all_up( v_cb, buffer, write_buffer ); |
klauss | 89:0fe315117b00 | 2028 | } |
klauss | 89:0fe315117b00 | 2029 | } |
klauss | 108:18a3702650f3 | 2030 | |
klauss | 109:a5b8264ffbbc | 2031 | |
klauss | 109:a5b8264ffbbc | 2032 | //refresh( v_cb, buffer, write_buffer, NULL ); |
klauss | 109:a5b8264ffbbc | 2033 | |
klauss | 109:a5b8264ffbbc | 2034 | //Fixme pensar melhor nessa parte durante ligacoes, pode complicar com muitos cbx ... |
klauss | 109:a5b8264ffbbc | 2035 | //if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 109:a5b8264ffbbc | 2036 | |
klauss | 78:1353744f01e1 | 2037 | // check sip messages only for cbx in call ? |
klauss | 78:1353744f01e1 | 2038 | int ext_to__be_removed = sip_manager( v_cb ); |
klauss | 91:c2a86b1f8aaa | 2039 | if( ext_to__be_removed > 0x00 ) { |
klauss | 78:1353744f01e1 | 2040 | Call_Box * cb = __find_CB__( v_cb, ext_to__be_removed ); |
klauss | 91:c2a86b1f8aaa | 2041 | if( cb != NULL ) { |
klauss | 91:c2a86b1f8aaa | 2042 | if( cb->status == cb_on_call ) { |
klauss | 4:de46f0d9b14d | 2043 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 2044 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 2045 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 91:c2a86b1f8aaa | 2046 | |
klauss | 78:1353744f01e1 | 2047 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 2048 | set_status( cb->sip->status, sip_idle ); |
klauss | 91:c2a86b1f8aaa | 2049 | |
klauss | 91:c2a86b1f8aaa | 2050 | for( register uint8_t i = 0; i < v_call->size(); i++ ) { |
klauss | 4:de46f0d9b14d | 2051 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 91:c2a86b1f8aaa | 2052 | if( call->get_cb_ext() == ext_to__be_removed ) { |
klauss | 4:de46f0d9b14d | 2053 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 2054 | delete( call ); |
klauss | 4:de46f0d9b14d | 2055 | } |
klauss | 2:93bec7313ccc | 2056 | } |
klauss | 91:c2a86b1f8aaa | 2057 | |
klauss | 109:a5b8264ffbbc | 2058 | //cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 92:92df17f538a8 | 2059 | cb->set_msg_id( ( cb->get_msg_id() + 1 ) & ~BIT7 ); |
klauss | 109:a5b8264ffbbc | 2060 | |
klauss | 109:a5b8264ffbbc | 2061 | //debug_msg("msg_id -- %d", cb->get_msg_id() ); |
klauss | 91:c2a86b1f8aaa | 2062 | |
klauss | 109:a5b8264ffbbc | 2063 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 109:a5b8264ffbbc | 2064 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 91:c2a86b1f8aaa | 2065 | |
klauss | 91:c2a86b1f8aaa | 2066 | if( debug_invite ) debug_msg("Received Bye from *"); |
klauss | 109:a5b8264ffbbc | 2067 | //cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 2068 | } |
klauss | 91:c2a86b1f8aaa | 2069 | } else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d", ext ); |
klauss | 109:a5b8264ffbbc | 2070 | } |
klauss | 91:c2a86b1f8aaa | 2071 | |
klauss | 81:3656f00ab3db | 2072 | /* Verifica andamento de ligações para eventualmente encerra-las por timeout */ |
klauss | 109:a5b8264ffbbc | 2073 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 91:c2a86b1f8aaa | 2074 | |
klauss | 109:a5b8264ffbbc | 2075 | /* tratamento de pedidos de ligação */ |
klauss | 81:3656f00ab3db | 2076 | invite_handler( v_call, v_cb, ts, NULL ); |
klauss | 109:a5b8264ffbbc | 2077 | |
klauss | 81:3656f00ab3db | 2078 | /* rotina de verificação de TS's perdidos */ |
klauss | 91:c2a86b1f8aaa | 2079 | if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != __MAX_TIMESLICES__ ) ) { |
klauss | 91:c2a86b1f8aaa | 2080 | bool ts_reset = true; |
klauss | 91:c2a86b1f8aaa | 2081 | for( register uint8_t i = 0; i < v_cb->size(); i++ ) { |
klauss | 82:f55d13babca0 | 2082 | if ( ( ( Call_Box * )v_cb->get_element( i ) )->get_status() != cb_idle && |
klauss | 91:c2a86b1f8aaa | 2083 | ( ( Call_Box * )v_cb->get_element( i ) )->get_sip_status() != sip_idle ) { |
klauss | 78:1353744f01e1 | 2084 | ts_reset = false; |
klauss | 78:1353744f01e1 | 2085 | break; |
klauss | 78:1353744f01e1 | 2086 | } |
klauss | 91:c2a86b1f8aaa | 2087 | } |
klauss | 109:a5b8264ffbbc | 2088 | if( ts_reset ) { |
klauss | 109:a5b8264ffbbc | 2089 | if( debug_invite ) debug_msg("Resetando TS"); |
klauss | 109:a5b8264ffbbc | 2090 | ts->reset(); |
klauss | 78:1353744f01e1 | 2091 | } |
klauss | 0:4d17cd9c8f9d | 2092 | } |
klauss | 112:6ae726539ab9 | 2093 | |
klauss | 112:6ae726539ab9 | 2094 | /* rotina "zeradora" de portas RTP */ |
klauss | 112:6ae726539ab9 | 2095 | /* |
klauss | 112:6ae726539ab9 | 2096 | for ( register uint8_t i = 0; i < v_cb->size(); i++ ) |
klauss | 112:6ae726539ab9 | 2097 | { |
klauss | 112:6ae726539ab9 | 2098 | Call_Box * cb = (Call_Box *) v_cb->get_element (i); |
klauss | 112:6ae726539ab9 | 2099 | if ( cb != NULL ) |
klauss | 112:6ae726539ab9 | 2100 | { |
klauss | 112:6ae726539ab9 | 2101 | if ( ( cb->get_status () == cb_idle ) && ( cb->get_sip_status () == sip_idle ) && ( cb -> is_rtp_timer_timeout () ) ) |
klauss | 112:6ae726539ab9 | 2102 | { |
klauss | 112:6ae726539ab9 | 2103 | if ( debug_rtp ) debug_msg( "%d rtp reset", cb -> get_ext () ); |
klauss | 112:6ae726539ab9 | 2104 | set_status ( cb -> status, cb_idle ); |
klauss | 112:6ae726539ab9 | 2105 | set_status ( cb->sip->status, sip_idle ); |
klauss | 112:6ae726539ab9 | 2106 | cb -> reset_rtp_timer (); |
klauss | 112:6ae726539ab9 | 2107 | cb -> set_rtp_port ( 0 ); |
klauss | 112:6ae726539ab9 | 2108 | } |
klauss | 112:6ae726539ab9 | 2109 | } |
klauss | 112:6ae726539ab9 | 2110 | } |
klauss | 112:6ae726539ab9 | 2111 | */ |
klauss | 109:a5b8264ffbbc | 2112 | |
klauss | 109:a5b8264ffbbc | 2113 | //invite_pgk_retry_manager( v_call, v_cb, buffer, write_buffer ); |
klauss | 109:a5b8264ffbbc | 2114 | |
klauss | 109:a5b8264ffbbc | 2115 | /* escuta se existe algum procedimento de gravação de cbx */ |
klauss | 109:a5b8264ffbbc | 2116 | //bl_handler(); |
klauss | 109:a5b8264ffbbc | 2117 | |
klauss | 81:3656f00ab3db | 2118 | /* rotina que esvazia possiveis pacotes que não foram transmitidos para evitar conflito */ |
klauss | 72:895ca792c647 | 2119 | tx_buffer_ring_buffer_handler(); |
klauss | 91:c2a86b1f8aaa | 2120 | |
klauss | 30:8dfb6d8de53d | 2121 | type = __DO_NOTHING__; |
klauss | 109:a5b8264ffbbc | 2122 | |
klauss | 81:3656f00ab3db | 2123 | if( eth_status == 0 ) eth_wdt = ETH_CONNECT_TIMEOUT; |
klauss | 109:a5b8264ffbbc | 2124 | |
klauss | 91:c2a86b1f8aaa | 2125 | if( wdt_timer.read() >= 1 ) { |
klauss | 91:c2a86b1f8aaa | 2126 | //FIXME remove myself |
klauss | 109:a5b8264ffbbc | 2127 | //registry_test = true; |
klauss | 109:a5b8264ffbbc | 2128 | //invite_retry_time = true; |
klauss | 109:a5b8264ffbbc | 2129 | |
klauss | 83:b8a1d8fdeaeb | 2130 | uptime++; |
klauss | 91:c2a86b1f8aaa | 2131 | |
klauss | 81:3656f00ab3db | 2132 | wdt_timer.reset(); |
klauss | 91:c2a86b1f8aaa | 2133 | |
klauss | 81:3656f00ab3db | 2134 | if( wdt_show ) debug_wdt = true; |
klauss | 91:c2a86b1f8aaa | 2135 | |
klauss | 81:3656f00ab3db | 2136 | if( external_wdt ) external_wdt--; |
klauss | 81:3656f00ab3db | 2137 | if( pkg_wdt ) pkg_wdt--; |
klauss | 81:3656f00ab3db | 2138 | if( eth_wdt ) eth_wdt--; |
klauss | 91:c2a86b1f8aaa | 2139 | |
klauss | 91:c2a86b1f8aaa | 2140 | if( eth_wdt && external_wdt && pkg_wdt ){ |
klauss | 81:3656f00ab3db | 2141 | wdt.kick(); |
klauss | 81:3656f00ab3db | 2142 | } |
klauss | 109:a5b8264ffbbc | 2143 | } |
klauss | 109:a5b8264ffbbc | 2144 | |
klauss | 91:c2a86b1f8aaa | 2145 | if( debug_wdt ) { |
klauss | 87:679ee0d594a9 | 2146 | send_msg("lpc_low_level_input_counter :: %d", lpc_low_level_input_counter ); |
klauss | 87:679ee0d594a9 | 2147 | lpc_low_level_input_counter = 0; |
klauss | 91:c2a86b1f8aaa | 2148 | |
klauss | 81:3656f00ab3db | 2149 | debug_wdt = false; |
klauss | 91:c2a86b1f8aaa | 2150 | if( eth_status == 0 ) { |
klauss | 91:c2a86b1f8aaa | 2151 | 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 | 2152 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 91:c2a86b1f8aaa | 2153 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 91:c2a86b1f8aaa | 2154 | EXTERN_WDT_IDLE, |
klauss | 91:c2a86b1f8aaa | 2155 | RX_CB_IDLE - pkg_wdt, |
klauss | 91:c2a86b1f8aaa | 2156 | RX_CB_IDLE |
klauss | 91:c2a86b1f8aaa | 2157 | ); |
klauss | 91:c2a86b1f8aaa | 2158 | } else { |
klauss | 91:c2a86b1f8aaa | 2159 | 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 | 2160 | ( wdt.WatchdogCausedReset() ) ? "true" : "false", |
klauss | 91:c2a86b1f8aaa | 2161 | ETH_CONNECT_TIMEOUT - eth_wdt, |
klauss | 91:c2a86b1f8aaa | 2162 | EXTERN_WDT_IDLE - external_wdt, |
klauss | 91:c2a86b1f8aaa | 2163 | EXTERN_WDT_IDLE, |
klauss | 91:c2a86b1f8aaa | 2164 | RX_CB_IDLE - pkg_wdt, |
klauss | 91:c2a86b1f8aaa | 2165 | RX_CB_IDLE |
klauss | 91:c2a86b1f8aaa | 2166 | ); |
klauss | 81:3656f00ab3db | 2167 | } |
klauss | 109:a5b8264ffbbc | 2168 | } |
klauss | 109:a5b8264ffbbc | 2169 | } |
klauss | 0:4d17cd9c8f9d | 2170 | } |