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