![](/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@79:9bc12aa305a9, 2014-12-16 (annotated)
- Committer:
- klauss
- Date:
- Tue Dec 16 16:50:25 2014 +0000
- Revision:
- 79:9bc12aa305a9
- Parent:
- 78:1353744f01e1
- Child:
- 80:61d61c9eb75c
implementando as restricoes de range / wdt externo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 74:81c47fff88a5 | 1 | #include "telemetry.h" |
klauss | 74:81c47fff88a5 | 2 | #include "eth.h" |
klauss | 74:81c47fff88a5 | 3 | #include "bits.h" |
klauss | 74:81c47fff88a5 | 4 | #include "UART3Interrupt.h" // for RXBuffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 74:81c47fff88a5 | 5 | #include "utils.h" |
klauss | 74:81c47fff88a5 | 6 | #include "parallelcpld.h" |
klauss | 74:81c47fff88a5 | 7 | #include "debug.h" |
klauss | 74:81c47fff88a5 | 8 | #include "flood.h" |
klauss | 74:81c47fff88a5 | 9 | #include "bootloader_cbx.h" |
klauss | 74:81c47fff88a5 | 10 | #include "call_manager.h" |
klauss | 74:81c47fff88a5 | 11 | #include "call_box_manager.h" |
klauss | 74:81c47fff88a5 | 12 | #include "sip_manager.h" |
klauss | 74:81c47fff88a5 | 13 | #include "shared_variables.h" |
klauss | 74:81c47fff88a5 | 14 | #include "prompt.h" |
klauss | 0:4d17cd9c8f9d | 15 | #include "configs.h" |
klauss | 0:4d17cd9c8f9d | 16 | |
klauss | 0:4d17cd9c8f9d | 17 | int main(){ |
klauss | 79:9bc12aa305a9 | 18 | /* inicia o wdt interno */ |
klauss | 48:195c97f12e8e | 19 | wdt.Configure( 40.0 ); |
klauss | 79:9bc12aa305a9 | 20 | |
klauss | 79:9bc12aa305a9 | 21 | /*inicia o wdt externo */ |
klauss | 79:9bc12aa305a9 | 22 | init_tcp_wdt(); |
klauss | 79:9bc12aa305a9 | 23 | |
klauss | 0:4d17cd9c8f9d | 24 | start_cpld(); |
klauss | 79:9bc12aa305a9 | 25 | |
klauss | 0:4d17cd9c8f9d | 26 | config_lpc(); |
klauss | 79:9bc12aa305a9 | 27 | |
klauss | 43:455522f98de5 | 28 | init_fsystem(); |
klauss | 43:455522f98de5 | 29 | |
klauss | 78:1353744f01e1 | 30 | short int eth_status = __init_eth__(); |
klauss | 8:e3bfe62a477e | 31 | if( eth_status ){ |
klauss | 48:195c97f12e8e | 32 | send_msg("Cannot connect to eth\n\r"); |
klauss | 43:455522f98de5 | 33 | }else{ |
klauss | 48:195c97f12e8e | 34 | send_msg("Connection eth - ok"); |
klauss | 78:1353744f01e1 | 35 | init_prompt_eth(); |
klauss | 8:e3bfe62a477e | 36 | } |
klauss | 78:1353744f01e1 | 37 | |
klauss | 78:1353744f01e1 | 38 | Timer sync_timer, led_sync_timer; |
klauss | 78:1353744f01e1 | 39 | sync_timer.start(), led_sync_timer.start(); |
klauss | 0:4d17cd9c8f9d | 40 | |
klauss | 0:4d17cd9c8f9d | 41 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 42 | int ext = 0; |
klauss | 0:4d17cd9c8f9d | 43 | |
klauss | 0:4d17cd9c8f9d | 44 | /* representa porta do call box */ |
klauss | 78:1353744f01e1 | 45 | int port = 0; |
klauss | 78:1353744f01e1 | 46 | |
klauss | 0:4d17cd9c8f9d | 47 | /* buffer para onde se copia os dados vindos do cb para tratameno interno */ |
klauss | 0:4d17cd9c8f9d | 48 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 49 | |
klauss | 0:4d17cd9c8f9d | 50 | /* buffer de escrita do pacote de saida que sera enviado pro cb / servidor */ |
klauss | 0:4d17cd9c8f9d | 51 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 52 | |
klauss | 0:4d17cd9c8f9d | 53 | /* ponteiro que aponta para os dados vindo do CPLD */ |
klauss | 0:4d17cd9c8f9d | 54 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 0:4d17cd9c8f9d | 55 | |
klauss | 62:07e5bdc9f8f7 | 56 | /* Armazena o ultimo pacote recebido dos CBx */ |
klauss | 62:07e5bdc9f8f7 | 57 | uint8_t cb_rx_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 62:07e5bdc9f8f7 | 58 | |
klauss | 0:4d17cd9c8f9d | 59 | /* referencia para os dados contidos no pacote, sem o header */ |
klauss | 0:4d17cd9c8f9d | 60 | uint8_t * data = NULL; |
klauss | 0:4d17cd9c8f9d | 61 | |
klauss | 0:4d17cd9c8f9d | 62 | /* gerencia o tipo do pacote para providenciar tratamento adequado */ |
klauss | 0:4d17cd9c8f9d | 63 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 64 | |
klauss | 0:4d17cd9c8f9d | 65 | /* representa a lista dos Call Boxes atualmente reconhecidos pela cabeceira */ |
klauss | 0:4d17cd9c8f9d | 66 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 67 | |
klauss | 0:4d17cd9c8f9d | 68 | /* representa a lista de ligacoes ativas na cabeceira */ |
klauss | 0:4d17cd9c8f9d | 69 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 70 | |
klauss | 0:4d17cd9c8f9d | 71 | /* gerencia a distribuicao de timeslice para os call boxes */ |
klauss | 0:4d17cd9c8f9d | 72 | Timeslice * ts = new Timeslice(); |
klauss | 78:1353744f01e1 | 73 | |
klauss | 0:4d17cd9c8f9d | 74 | /* tenta instanciar o vetor de call boxes, acende o led 1 antes de encerrar o programa */ |
klauss | 0:4d17cd9c8f9d | 75 | if( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 76 | while( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 77 | Vector * v_cb = new Vector(); |
klauss | 78:1353744f01e1 | 78 | if( sync_timer.read() > 5 ){ |
klauss | 48:195c97f12e8e | 79 | send_msg("Erro ao alocar o vetor de CBx"); |
klauss | 78:1353744f01e1 | 80 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 81 | } |
klauss | 0:4d17cd9c8f9d | 82 | } |
klauss | 0:4d17cd9c8f9d | 83 | }else if( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 84 | while( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 85 | Vector * v_call = new Vector(); |
klauss | 78:1353744f01e1 | 86 | if( sync_timer.read() > 5 ){ |
klauss | 48:195c97f12e8e | 87 | send_msg("Erro ao alocar o vetor de Calls"); |
klauss | 78:1353744f01e1 | 88 | sync_timer.reset(); |
klauss | 0:4d17cd9c8f9d | 89 | } |
klauss | 0:4d17cd9c8f9d | 90 | } |
klauss | 0:4d17cd9c8f9d | 91 | } |
klauss | 63:0d95da692bb4 | 92 | |
klauss | 78:1353744f01e1 | 93 | reset_leds(); |
klauss | 78:1353744f01e1 | 94 | |
klauss | 63:0d95da692bb4 | 95 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 63:0d95da692bb4 | 96 | cb_rx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 97 | cb_tx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 98 | } |
klauss | 63:0d95da692bb4 | 99 | |
klauss | 0:4d17cd9c8f9d | 100 | reset_leds(); |
klauss | 78:1353744f01e1 | 101 | |
klauss | 33:735fd60e96d8 | 102 | udp_timer.start(); |
klauss | 68:b54993674190 | 103 | |
klauss | 68:b54993674190 | 104 | init_telemetry_handler(); |
klauss | 68:b54993674190 | 105 | |
klauss | 78:1353744f01e1 | 106 | init_aging(); |
klauss | 78:1353744f01e1 | 107 | |
klauss | 62:07e5bdc9f8f7 | 108 | static uint8_t count = 0; |
klauss | 78:1353744f01e1 | 109 | |
klauss | 78:1353744f01e1 | 110 | short int bl_ret = init_bl_handler(); |
klauss | 67:cdedc64d9921 | 111 | if( dbl ) send_msg("Valor de retorno do bl_habdler = %d", bl_ret ); |
klauss | 67:cdedc64d9921 | 112 | |
klauss | 78:1353744f01e1 | 113 | //uint8_t before = ( int ) sync_timer.read() % 2; |
klauss | 78:1353744f01e1 | 114 | |
klauss | 78:1353744f01e1 | 115 | uint8_t max_registered_cbx = 0; |
klauss | 78:1353744f01e1 | 116 | |
klauss | 78:1353744f01e1 | 117 | //bool wake_all = false; |
klauss | 68:b54993674190 | 118 | |
klauss | 68:b54993674190 | 119 | send_msg("Ready"); |
klauss | 68:b54993674190 | 120 | |
klauss | 78:1353744f01e1 | 121 | /*------------------------------------------ main loop ---------------------------------------------------------------*/ |
Cola | 21:0bd688722e81 | 122 | while( true ){ |
klauss | 78:1353744f01e1 | 123 | if( v_cb->size() > max_registered_cbx ) max_registered_cbx = v_cb->size(); |
klauss | 78:1353744f01e1 | 124 | |
klauss | 78:1353744f01e1 | 125 | if( sync_timer.read() > 5 ){ |
klauss | 78:1353744f01e1 | 126 | sync_timer.reset(); |
klauss | 78:1353744f01e1 | 127 | |
klauss | 78:1353744f01e1 | 128 | if( debug_cks == true ){ |
klauss | 79:9bc12aa305a9 | 129 | send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d :: PKG_ZERO: %d :: Out_of_range: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range ); |
klauss | 78:1353744f01e1 | 130 | } |
klauss | 78:1353744f01e1 | 131 | |
klauss | 78:1353744f01e1 | 132 | if( debug_alive == true ){ |
klauss | 78:1353744f01e1 | 133 | send_msg("Registered %d ( of %d ) CBx -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx , ts->remain_timeslices(), v_call->size() ); |
klauss | 78:1353744f01e1 | 134 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 78:1353744f01e1 | 135 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 136 | char cb_status[ 32 ]; |
klauss | 78:1353744f01e1 | 137 | char cb_sip_status[ 32 ]; |
klauss | 78:1353744f01e1 | 138 | switch( cb->status ){ |
klauss | 78:1353744f01e1 | 139 | case cb_idle : { strcpy( cb_status, "cb_idle" ); break; } |
klauss | 78:1353744f01e1 | 140 | case cb_ringing : { strcpy( cb_status, "cb_ringing" ); break; } |
klauss | 78:1353744f01e1 | 141 | case cb_trying : { strcpy( cb_status,"cb_trying" ); break; } |
klauss | 78:1353744f01e1 | 142 | case cb_on_call : { strcpy( cb_status, "cb_on_call" ); break; } |
klauss | 78:1353744f01e1 | 143 | case cb_busy : { strcpy( cb_status, "cb_busy" ); break; } |
klauss | 78:1353744f01e1 | 144 | case cb_denied : { strcpy( cb_status, "cb_denied" ); break; } |
klauss | 78:1353744f01e1 | 145 | } |
klauss | 78:1353744f01e1 | 146 | switch( cb->sip->status ){ |
klauss | 78:1353744f01e1 | 147 | case sip_idle : { strcpy( cb_sip_status, "sip_idle" ); break; } |
klauss | 78:1353744f01e1 | 148 | case sip_waiting_trying : { strcpy( cb_sip_status, "sip_waiting_trying" ); break; } |
klauss | 78:1353744f01e1 | 149 | case sip_trying : { strcpy( cb_sip_status, "sip_trying" ); break; } |
klauss | 78:1353744f01e1 | 150 | case sip_ringing : { strcpy( cb_sip_status, "sip_ringing" ); break; } |
klauss | 78:1353744f01e1 | 151 | case sip_busy : { strcpy( cb_sip_status, "sip_busy" ); break; } |
klauss | 78:1353744f01e1 | 152 | case sip_ok : { strcpy( cb_sip_status, "sip_ok" ); break; } |
klauss | 78:1353744f01e1 | 153 | case sip_on_call : { strcpy( cb_sip_status, "sip_on_call" ); break; } |
klauss | 78:1353744f01e1 | 154 | case sip_denied : { strcpy( cb_sip_status, "sip_denied" ); break; } |
klauss | 78:1353744f01e1 | 155 | } |
klauss | 78:1353744f01e1 | 156 | char cbx_to_string[ 254 ]; |
klauss | 78:1353744f01e1 | 157 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 158 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 78:1353744f01e1 | 159 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 78:1353744f01e1 | 160 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 161 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 78:1353744f01e1 | 162 | strcat( cbx_to_string, cb_status ); |
klauss | 78:1353744f01e1 | 163 | strcat( cbx_to_string, " - " ); |
klauss | 78:1353744f01e1 | 164 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 78:1353744f01e1 | 165 | if( cb->get_timeslice() != 0 ){ |
klauss | 78:1353744f01e1 | 166 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 78:1353744f01e1 | 167 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 78:1353744f01e1 | 168 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 169 | } |
klauss | 78:1353744f01e1 | 170 | send_msg( cbx_to_string ); |
klauss | 78:1353744f01e1 | 171 | } |
klauss | 78:1353744f01e1 | 172 | } |
klauss | 78:1353744f01e1 | 173 | |
klauss | 78:1353744f01e1 | 174 | count++; |
klauss | 78:1353744f01e1 | 175 | if( !( count % 15 ) ){ |
klauss | 78:1353744f01e1 | 176 | if( eth_status ){ |
klauss | 78:1353744f01e1 | 177 | wdt.kick(); |
klauss | 78:1353744f01e1 | 178 | eth_status = __init_eth__(); |
klauss | 78:1353744f01e1 | 179 | if( eth_status ){ |
klauss | 78:1353744f01e1 | 180 | if( debug_main ) debug_msg("Cannot connect to eth"); |
klauss | 78:1353744f01e1 | 181 | }else{ |
klauss | 78:1353744f01e1 | 182 | if( debug_main ) debug_msg("Connection eth - ok"); |
klauss | 78:1353744f01e1 | 183 | init_prompt_eth(); |
klauss | 78:1353744f01e1 | 184 | } |
klauss | 78:1353744f01e1 | 185 | } |
klauss | 78:1353744f01e1 | 186 | } |
klauss | 78:1353744f01e1 | 187 | if( !( count % 6 ) ){ |
klauss | 78:1353744f01e1 | 188 | //wake_all = true; |
klauss | 78:1353744f01e1 | 189 | if( debug_wake == true ) send_msg( "Time to wake" ); |
klauss | 78:1353744f01e1 | 190 | } |
klauss | 78:1353744f01e1 | 191 | |
klauss | 78:1353744f01e1 | 192 | //if( wake_all ) if( v_call->size() == 0 ) wake_all_up( v_cb, buffer, write_buffer ); |
klauss | 78:1353744f01e1 | 193 | } |
klauss | 78:1353744f01e1 | 194 | |
klauss | 78:1353744f01e1 | 195 | if( main_test == true ){ |
klauss | 78:1353744f01e1 | 196 | uint8_t test_data[ 1024 ]; |
klauss | 78:1353744f01e1 | 197 | Call_Box * cb = __find_CB__( v_cb, 5514 ); |
klauss | 78:1353744f01e1 | 198 | |
klauss | 78:1353744f01e1 | 199 | strcpy( ( char * )test_data, "ping\r\r\r\n" ); |
klauss | 78:1353744f01e1 | 200 | if( cb != NULL ){ |
klauss | 78:1353744f01e1 | 201 | send2callboxes( __build_cb_package__( cb->get_ext(), cb->get_port(), __PROMPT__, |
klauss | 78:1353744f01e1 | 202 | ( char * )test_data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 203 | debug_msg("test_ping"); |
klauss | 78:1353744f01e1 | 204 | } |
klauss | 78:1353744f01e1 | 205 | } |
klauss | 78:1353744f01e1 | 206 | |
klauss | 78:1353744f01e1 | 207 | |
klauss | 68:b54993674190 | 208 | //FIXMEj colocar uma condicao aqui caso necessario pra nao comprometer ligacoes ... |
klauss | 35:96885a7931f0 | 209 | prompt_process( NULL ); |
klauss | 33:735fd60e96d8 | 210 | wdt.kick(); |
klauss | 62:07e5bdc9f8f7 | 211 | |
klauss | 78:1353744f01e1 | 212 | if( debug_cpld ) rx = true; |
klauss | 78:1353744f01e1 | 213 | |
klauss | 62:07e5bdc9f8f7 | 214 | if( rx ){ |
klauss | 62:07e5bdc9f8f7 | 215 | char str[ 1024 ]; |
klauss | 63:0d95da692bb4 | 216 | strcpy( str, "RX :: \n\r " ); |
klauss | 62:07e5bdc9f8f7 | 217 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 62:07e5bdc9f8f7 | 218 | char tmp[ 16 ]; |
klauss | 62:07e5bdc9f8f7 | 219 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 78:1353744f01e1 | 220 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 62:07e5bdc9f8f7 | 221 | |
klauss | 62:07e5bdc9f8f7 | 222 | else strcat( str, " " ); |
klauss | 62:07e5bdc9f8f7 | 223 | } |
klauss | 62:07e5bdc9f8f7 | 224 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 225 | rx = false; |
klauss | 62:07e5bdc9f8f7 | 226 | } |
klauss | 62:07e5bdc9f8f7 | 227 | |
klauss | 63:0d95da692bb4 | 228 | if( tx ){ |
klauss | 63:0d95da692bb4 | 229 | char str[ 1024 ]; |
klauss | 63:0d95da692bb4 | 230 | strcpy( str, "TX :: \n\r " ); |
klauss | 63:0d95da692bb4 | 231 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 63:0d95da692bb4 | 232 | char tmp[ 16 ]; |
klauss | 63:0d95da692bb4 | 233 | strcat( str, itoa( cb_tx_buffer[ i ], tmp, 16 ) ); |
klauss | 78:1353744f01e1 | 234 | if( ( i != 0 ) && !( ( i + 1 ) % 50 ) ) strcat( str, "\n\r " ); |
klauss | 63:0d95da692bb4 | 235 | |
klauss | 63:0d95da692bb4 | 236 | else strcat( str, " " ); |
klauss | 63:0d95da692bb4 | 237 | } |
klauss | 63:0d95da692bb4 | 238 | send_msg( "%s", str ); |
klauss | 63:0d95da692bb4 | 239 | tx = false; |
klauss | 63:0d95da692bb4 | 240 | } |
klauss | 63:0d95da692bb4 | 241 | |
klauss | 63:0d95da692bb4 | 242 | if( r_stats ){ |
klauss | 63:0d95da692bb4 | 243 | boot_counter = 0; |
klauss | 63:0d95da692bb4 | 244 | registry_counter = 0; |
klauss | 63:0d95da692bb4 | 245 | invite_counter = 0; |
klauss | 63:0d95da692bb4 | 246 | audio_counter = 0; |
klauss | 63:0d95da692bb4 | 247 | telemetry_counter = 0; |
klauss | 63:0d95da692bb4 | 248 | cb_bye_counter = 0; |
klauss | 63:0d95da692bb4 | 249 | prompt_counter = 0; |
klauss | 63:0d95da692bb4 | 250 | flood_counter = 0; |
klauss | 67:cdedc64d9921 | 251 | bootloader_cbx_counter = 0; |
klauss | 63:0d95da692bb4 | 252 | r_stats = false; |
klauss | 63:0d95da692bb4 | 253 | stats = true; |
klauss | 63:0d95da692bb4 | 254 | } |
klauss | 63:0d95da692bb4 | 255 | if( stats ){ |
klauss | 63:0d95da692bb4 | 256 | char str[ 200 ]; |
klauss | 67:cdedc64d9921 | 257 | snprintf( str, 200, "\n\rReceived Pkgs::\n\r Boot :: %u\n\r Registry :: %u\n\r Ivite :: %u\n\r Audio :: %u\n\r Telemetry :: %u\n\r Cb_by :: %u\n\r Prompt :: %u\n\r Flood :: %u\n\r Bootloader_cbx :: %u\n\r", |
klauss | 67:cdedc64d9921 | 258 | boot_counter, registry_counter, invite_counter, audio_counter, telemetry_counter, cb_bye_counter, prompt_counter, flood_counter, bootloader_cbx_counter ); |
klauss | 63:0d95da692bb4 | 259 | send_msg( str ); |
klauss | 63:0d95da692bb4 | 260 | stats =false; |
klauss | 63:0d95da692bb4 | 261 | } |
klauss | 63:0d95da692bb4 | 262 | |
klauss | 62:07e5bdc9f8f7 | 263 | if( list ){ |
klauss | 78:1353744f01e1 | 264 | uint8_t missed_cb = ( ( max_ext - min_ext ) + 1 ) - v_cb->size(); |
klauss | 78:1353744f01e1 | 265 | |
klauss | 78:1353744f01e1 | 266 | if( ( max_ext % 2 ) == 0 ) missed_cb++; |
klauss | 78:1353744f01e1 | 267 | |
klauss | 78:1353744f01e1 | 268 | if( min_ext % 2 ) missed_cb++; |
klauss | 78:1353744f01e1 | 269 | |
klauss | 78:1353744f01e1 | 270 | if( min_ext == 0 && max_ext == 0 ) missed_cb = 0; |
klauss | 78:1353744f01e1 | 271 | |
klauss | 78:1353744f01e1 | 272 | send_msg("Registered %d[ %d ] CBx ( %d - %d ) - Missed %d -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, missed_cb, ts->remain_timeslices(), v_call->size() ); |
klauss | 78:1353744f01e1 | 273 | if( v_cb->size() == 1 ){ |
klauss | 78:1353744f01e1 | 274 | send_msg(" %d ", ( ( Call_Box * )v_cb->get_element( 0 ) )->get_ext() ); |
klauss | 78:1353744f01e1 | 275 | }else if( v_cb->size() > 1 ){ |
klauss | 62:07e5bdc9f8f7 | 276 | char str[ 1024 ]; |
klauss | 78:1353744f01e1 | 277 | int ext_list[ __MAX_CB_IN_A_BRANCH__ ]; |
klauss | 62:07e5bdc9f8f7 | 278 | register int i = 0; |
klauss | 62:07e5bdc9f8f7 | 279 | for( ; i < v_cb->size(); i++ ){ |
klauss | 78:1353744f01e1 | 280 | ext_list[ i ] = ( ( Call_Box * )v_cb->get_element( i ) )->get_ext(); |
klauss | 62:07e5bdc9f8f7 | 281 | } |
klauss | 62:07e5bdc9f8f7 | 282 | |
klauss | 62:07e5bdc9f8f7 | 283 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 62:07e5bdc9f8f7 | 284 | |
klauss | 62:07e5bdc9f8f7 | 285 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 286 | strcpy( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 287 | for( i = 0; i < v_cb->size() - 1; i++ ){ |
klauss | 62:07e5bdc9f8f7 | 288 | sprintf( aux, "%i, ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 289 | strcat( str, aux ); |
klauss | 78:1353744f01e1 | 290 | if( ( i != 0 ) && !( ( i + 1 ) % 16 ) ) strcat( str, "\r\n> " ); |
klauss | 62:07e5bdc9f8f7 | 291 | } |
klauss | 62:07e5bdc9f8f7 | 292 | sprintf( aux, "%i ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 293 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 294 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 295 | } |
klauss | 62:07e5bdc9f8f7 | 296 | list = false; |
klauss | 62:07e5bdc9f8f7 | 297 | } |
klauss | 62:07e5bdc9f8f7 | 298 | |
klauss | 78:1353744f01e1 | 299 | if( reset_cks == true ){ |
klauss | 78:1353744f01e1 | 300 | pkg_cksok = 0; |
klauss | 78:1353744f01e1 | 301 | pkg_ckserr = 0; |
klauss | 78:1353744f01e1 | 302 | reset_cks = false; |
klauss | 78:1353744f01e1 | 303 | pcks_s = true; |
Cola | 24:270b436a1bb0 | 304 | } |
Cola | 24:270b436a1bb0 | 305 | |
klauss | 78:1353744f01e1 | 306 | if( pcks_s == true ){ |
klauss | 79:9bc12aa305a9 | 307 | send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d :: PKG_ZERO: %d :: Out_of_range: %d", pkg_cksok, pkg_ckserr, pkg_zero, out_of_range ); |
klauss | 78:1353744f01e1 | 308 | pcks_s = false; |
klauss | 52:12930cef17c4 | 309 | } |
klauss | 52:12930cef17c4 | 310 | |
klauss | 78:1353744f01e1 | 311 | if( pshowcb == true ){ |
klauss | 78:1353744f01e1 | 312 | // por que nao posso colocar isso como list on ? |
klauss | 78:1353744f01e1 | 313 | send_msg("Registered %d ( of %d ) CBx ( %d - %d ) -- Remain_timeslices :: %d :: v_call->size() :: %d", v_cb->size(), max_registered_cbx, min_ext, max_ext, ts->remain_timeslices(), v_call->size() ); |
Cola | 24:270b436a1bb0 | 314 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 30:8dfb6d8de53d | 315 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 78:1353744f01e1 | 316 | char cb_status[ 32 ]; |
klauss | 78:1353744f01e1 | 317 | char cb_sip_status[ 32 ]; |
klauss | 78:1353744f01e1 | 318 | switch( cb->status ){ |
klauss | 78:1353744f01e1 | 319 | case cb_idle : { strcpy( cb_status, "cb_idle" ); break; } |
klauss | 78:1353744f01e1 | 320 | case cb_ringing : { strcpy( cb_status, "cb_ringing" ); break; } |
klauss | 78:1353744f01e1 | 321 | case cb_trying : { strcpy( cb_status,"cb_trying" ); break; } |
klauss | 78:1353744f01e1 | 322 | case cb_on_call : { strcpy( cb_status, "cb_on_call" ); break; } |
klauss | 78:1353744f01e1 | 323 | case cb_busy : { strcpy( cb_status, "cb_busy" ); break; } |
klauss | 78:1353744f01e1 | 324 | case cb_denied : { strcpy( cb_status, "cb_denied" ); break; } |
klauss | 78:1353744f01e1 | 325 | } |
klauss | 78:1353744f01e1 | 326 | switch( cb->sip->status ){ |
klauss | 78:1353744f01e1 | 327 | case sip_idle : { strcpy( cb_sip_status, "sip_idle" ); break; } |
klauss | 78:1353744f01e1 | 328 | case sip_waiting_trying : { strcpy( cb_sip_status, "sip_waiting_trying" ); break; } |
klauss | 78:1353744f01e1 | 329 | case sip_trying : { strcpy( cb_sip_status, "sip_trying" ); break; } |
klauss | 78:1353744f01e1 | 330 | case sip_ringing : { strcpy( cb_sip_status, "sip_ringing" ); break; } |
klauss | 78:1353744f01e1 | 331 | case sip_busy : { strcpy( cb_sip_status, "sip_busy" ); break; } |
klauss | 78:1353744f01e1 | 332 | case sip_ok : { strcpy( cb_sip_status, "sip_ok" ); break; } |
klauss | 78:1353744f01e1 | 333 | case sip_on_call : { strcpy( cb_sip_status, "sip_on_call" ); break; } |
klauss | 78:1353744f01e1 | 334 | case sip_denied : { strcpy( cb_sip_status, "sip_denied" ); break; } |
klauss | 78:1353744f01e1 | 335 | } |
klauss | 78:1353744f01e1 | 336 | char cbx_to_string[ 254 ]; |
klauss | 78:1353744f01e1 | 337 | char aux[ 16 ]; |
klauss | 78:1353744f01e1 | 338 | strcpy( cbx_to_string, "Ext :: " ); |
klauss | 78:1353744f01e1 | 339 | itoa( cb->get_ext(), aux , 10 ); |
klauss | 78:1353744f01e1 | 340 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 341 | strcat( cbx_to_string, " :: Status -- " ); |
klauss | 78:1353744f01e1 | 342 | strcat( cbx_to_string, cb_status ); |
klauss | 78:1353744f01e1 | 343 | strcat( cbx_to_string, " - " ); |
klauss | 78:1353744f01e1 | 344 | strcat( cbx_to_string, cb_sip_status ); |
klauss | 78:1353744f01e1 | 345 | if( cb->get_timeslice() != 0 ){ |
klauss | 78:1353744f01e1 | 346 | strcat( cbx_to_string, " -- on TimeSlice :: " ); |
klauss | 78:1353744f01e1 | 347 | itoa( cb->get_timeslice(), aux , 10 ); |
klauss | 78:1353744f01e1 | 348 | strcat( cbx_to_string, aux ); |
klauss | 78:1353744f01e1 | 349 | } |
klauss | 78:1353744f01e1 | 350 | send_msg( cbx_to_string ); |
klauss | 48:195c97f12e8e | 351 | } |
klauss | 78:1353744f01e1 | 352 | pshowcb = false; |
klauss | 48:195c97f12e8e | 353 | } |
Cola | 22:d2a4b5939115 | 354 | |
klauss | 78:1353744f01e1 | 355 | if( pflood == true ) flood(); |
klauss | 30:8dfb6d8de53d | 356 | |
klauss | 0:4d17cd9c8f9d | 357 | if( status != __WAITING__ ){ |
klauss | 74:81c47fff88a5 | 358 | xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 359 | status = __WAITING__; |
klauss | 78:1353744f01e1 | 360 | xmemcpy( buffer, cb_rx_buffer, __CB_BUFFER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 361 | |
klauss | 34:f19d9735428e | 362 | data = __parse_vz_pkg__( &ext, &port, &type, buffer ); |
klauss | 0:4d17cd9c8f9d | 363 | |
klauss | 78:1353744f01e1 | 364 | if( data != NULL ){ |
klauss | 78:1353744f01e1 | 365 | if( min_ext == 0 ) min_ext = ext; |
klauss | 78:1353744f01e1 | 366 | |
klauss | 78:1353744f01e1 | 367 | if( ext > max_ext ) max_ext = ext; |
klauss | 78:1353744f01e1 | 368 | |
klauss | 78:1353744f01e1 | 369 | if( ext < min_ext ) min_ext = ext; |
klauss | 78:1353744f01e1 | 370 | |
klauss | 78:1353744f01e1 | 371 | if( debug_cb_rx == true ) debug_msg("Pkg from CBx :: %d -- Type :: %d", ext, type ); |
klauss | 78:1353744f01e1 | 372 | |
klauss | 7:019b08223b87 | 373 | if( type != __AUDIO__ ){ |
klauss | 0:4d17cd9c8f9d | 374 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 375 | if( cb != NULL ){ |
klauss | 78:1353744f01e1 | 376 | if( ( data[ 0 ] & BIT7 ) >= BIT7 ){ |
klauss | 78:1353744f01e1 | 377 | if( type == __BOOT__ ){ |
klauss | 78:1353744f01e1 | 378 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 78:1353744f01e1 | 379 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 380 | }else if( ( data[ 0 ] & BIT7 ) == ( cb->get_msg_id() ^ BIT7 ) ){ |
klauss | 0:4d17cd9c8f9d | 381 | // ack from CBx |
klauss | 30:8dfb6d8de53d | 382 | if( debug_main ) debug_msg("-- ACK do meu pkg --"); |
klauss | 0:4d17cd9c8f9d | 383 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 384 | } |
klauss | 0:4d17cd9c8f9d | 385 | } |
klauss | 0:4d17cd9c8f9d | 386 | } |
klauss | 0:4d17cd9c8f9d | 387 | } |
klauss | 0:4d17cd9c8f9d | 388 | }else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 389 | } |
klauss | 78:1353744f01e1 | 390 | |
klauss | 78:1353744f01e1 | 391 | if( led_sync_timer.read() > 1 ){ |
klauss | 78:1353744f01e1 | 392 | led_sync_timer.reset(); |
klauss | 78:1353744f01e1 | 393 | led3 = !led3; |
klauss | 78:1353744f01e1 | 394 | CAB_LED = !CAB_LED; |
klauss | 78:1353744f01e1 | 395 | } |
klauss | 78:1353744f01e1 | 396 | |
klauss | 0:4d17cd9c8f9d | 397 | switch( type ){ |
klauss | 0:4d17cd9c8f9d | 398 | case __DO_NOTHING__ :{} |
klauss | 0:4d17cd9c8f9d | 399 | break; |
klauss | 0:4d17cd9c8f9d | 400 | |
klauss | 0:4d17cd9c8f9d | 401 | case __CB_BYE__ : { |
klauss | 63:0d95da692bb4 | 402 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 403 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 404 | if( cb != NULL ){ |
klauss | 0:4d17cd9c8f9d | 405 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 406 | cb->set_msg_id( data[ 0 ] ); |
klauss | 30:8dfb6d8de53d | 407 | if( debug_main ) debug_msg( " Request bye from CBx " ); |
klauss | 0:4d17cd9c8f9d | 408 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 409 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 410 | if( call->get_cb_ext() == ext ){ |
klauss | 4:de46f0d9b14d | 411 | cb->send_bye(); |
klauss | 78:1353744f01e1 | 412 | |
klauss | 0:4d17cd9c8f9d | 413 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 414 | cb->set_timeslice( 0x00 ); |
klauss | 78:1353744f01e1 | 415 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 416 | |
klauss | 0:4d17cd9c8f9d | 417 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 418 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 419 | |
klauss | 13:ae278302dffe | 420 | v_call->remove_element( i ); |
klauss | 78:1353744f01e1 | 421 | |
klauss | 74:81c47fff88a5 | 422 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 423 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 424 | |
klauss | 78:1353744f01e1 | 425 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 426 | |
klauss | 3:cd9148672e25 | 427 | delete( call ); |
klauss | 29:7246460b73f8 | 428 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 429 | } |
klauss | 0:4d17cd9c8f9d | 430 | } |
klauss | 78:1353744f01e1 | 431 | cb->registry(); |
klauss | 0:4d17cd9c8f9d | 432 | } |
klauss | 7:019b08223b87 | 433 | }break; |
klauss | 7:019b08223b87 | 434 | |
klauss | 0:4d17cd9c8f9d | 435 | case __INVITE__ : { |
klauss | 63:0d95da692bb4 | 436 | invite_counter++; |
klauss | 78:1353744f01e1 | 437 | if( debug_invite ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 0:4d17cd9c8f9d | 438 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 439 | if( cb == NULL ){ |
klauss | 78:1353744f01e1 | 440 | if( debug_main ) debug_msg( "Adding CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 441 | cb = new Call_Box( ext, port ); |
klauss | 0:4d17cd9c8f9d | 442 | v_cb->add( cb ); |
klauss | 0:4d17cd9c8f9d | 443 | } |
klauss | 78:1353744f01e1 | 444 | cb->registry(); |
klauss | 78:1353744f01e1 | 445 | cb->set_msg_id( data[ 0 ] ); |
klauss | 78:1353744f01e1 | 446 | invite_handler( v_call, v_cb, ts, cb ); |
klauss | 0:4d17cd9c8f9d | 447 | }break; |
klauss | 4:de46f0d9b14d | 448 | case __REGISTRY__ : { |
klauss | 63:0d95da692bb4 | 449 | registry_counter++; |
klauss | 78:1353744f01e1 | 450 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 2:93bec7313ccc | 451 | |
klauss | 78:1353744f01e1 | 452 | if( cb == NULL ){ |
klauss | 78:1353744f01e1 | 453 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 4:de46f0d9b14d | 454 | cb = new Call_Box( ext, port ); |
klauss | 4:de46f0d9b14d | 455 | v_cb->add( cb ); |
klauss | 30:8dfb6d8de53d | 456 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 457 | } |
klauss | 78:1353744f01e1 | 458 | if( debug_main ) debug_msg("Registered %d - %d", ext, port ); |
klauss | 78:1353744f01e1 | 459 | |
klauss | 4:de46f0d9b14d | 460 | cb->registry(); |
klauss | 78:1353744f01e1 | 461 | |
klauss | 4:de46f0d9b14d | 462 | }break; |
klauss | 4:de46f0d9b14d | 463 | case __BOOT__ : { |
klauss | 63:0d95da692bb4 | 464 | boot_counter++; |
klauss | 74:81c47fff88a5 | 465 | send2callboxes( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 78:1353744f01e1 | 466 | ( char * )data, data[ 0 ] | BIT7, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 467 | }break; |
klauss | 4:de46f0d9b14d | 468 | case __TELEMETRY__ : { |
klauss | 78:1353744f01e1 | 469 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 78:1353744f01e1 | 470 | if( cb == NULL ){ |
klauss | 78:1353744f01e1 | 471 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 78:1353744f01e1 | 472 | cb = new Call_Box( ext, port ); |
klauss | 78:1353744f01e1 | 473 | v_cb->add( cb ); |
klauss | 78:1353744f01e1 | 474 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 78:1353744f01e1 | 475 | } |
klauss | 78:1353744f01e1 | 476 | cb->registry(); |
klauss | 63:0d95da692bb4 | 477 | telemetry_counter++; |
klauss | 78:1353744f01e1 | 478 | if( debug_telemetry ) send_msg("::Telemetry from %d - %d::", ext, port ); |
klauss | 53:bb492a8f115a | 479 | build_telemetry_report( ext, port, ( char *)data ); |
klauss | 4:de46f0d9b14d | 480 | }break; |
klauss | 36:728498a78e1e | 481 | |
klauss | 67:cdedc64d9921 | 482 | case __BOOTLOADER_CBX__ : { |
klauss | 67:cdedc64d9921 | 483 | bootloader_cbx_counter++; |
klauss | 67:cdedc64d9921 | 484 | int ret = bl_cbx_reply_to_eth( ext, ( char * )data ); |
klauss | 67:cdedc64d9921 | 485 | }break; |
klauss | 67:cdedc64d9921 | 486 | |
klauss | 36:728498a78e1e | 487 | case __PROMPT__ : { |
klauss | 78:1353744f01e1 | 488 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 78:1353744f01e1 | 489 | if( cb == NULL ){ |
klauss | 78:1353744f01e1 | 490 | if( debug_main ) debug_msg("Adding Cbx :: %d", ext ); |
klauss | 78:1353744f01e1 | 491 | cb = new Call_Box( ext, port ); |
klauss | 78:1353744f01e1 | 492 | v_cb->add( cb ); |
klauss | 78:1353744f01e1 | 493 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 48:195c97f12e8e | 494 | } |
klauss | 78:1353744f01e1 | 495 | |
klauss | 78:1353744f01e1 | 496 | cb->registry(); |
klauss | 48:195c97f12e8e | 497 | |
klauss | 78:1353744f01e1 | 498 | if( xstrmatch( ( uint8_t * )data, ( uint8_t * )"ping" ) ){ |
klauss | 78:1353744f01e1 | 499 | if( debug_ping ) send_msg( "Prompt pkg from ( %i, %i ) :: Ping", ext, port ); |
klauss | 78:1353744f01e1 | 500 | }else{ |
klauss | 78:1353744f01e1 | 501 | prompt_counter++; |
klauss | 78:1353744f01e1 | 502 | //fixme isso nao poderia ser resolvido com um sendmsg ? |
klauss | 78:1353744f01e1 | 503 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 78:1353744f01e1 | 504 | for( register uint8_t i = 0; i < 32; i++ ){ |
klauss | 78:1353744f01e1 | 505 | pc.printf("%c", data[ i ] ); |
klauss | 78:1353744f01e1 | 506 | if( i == 15 ) pc.printf( "\r\n" ); |
klauss | 78:1353744f01e1 | 507 | } |
klauss | 78:1353744f01e1 | 508 | pc.printf("\n\r> "); |
klauss | 78:1353744f01e1 | 509 | |
klauss | 78:1353744f01e1 | 510 | if( tcp_session ){ |
klauss | 78:1353744f01e1 | 511 | char aux[ __CB_BUFFER_SIZE__ + 3 ]; |
klauss | 78:1353744f01e1 | 512 | strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); |
klauss | 78:1353744f01e1 | 513 | strcat( aux, "\n\r\0" ); |
klauss | 78:1353744f01e1 | 514 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 78:1353744f01e1 | 515 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 78:1353744f01e1 | 516 | } |
klauss | 48:195c97f12e8e | 517 | } |
klauss | 36:728498a78e1e | 518 | }break; |
klauss | 0:4d17cd9c8f9d | 519 | case __AUDIO__ : { |
klauss | 63:0d95da692bb4 | 520 | audio_counter++; |
klauss | 78:1353744f01e1 | 521 | VZ_call * call = __find_Call__( v_call, ext ); |
klauss | 0:4d17cd9c8f9d | 522 | if( call != NULL ){ |
klauss | 30:8dfb6d8de53d | 523 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 0:4d17cd9c8f9d | 524 | call->send_message( pkg ); |
klauss | 78:1353744f01e1 | 525 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 526 | if( cb != NULL ) cb->reset_elapsed_time(); |
klauss | 18:01a93677e40c | 527 | }else{ |
klauss | 78:1353744f01e1 | 528 | if( debug_main ) debug_msg("received missed package from CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 529 | } |
klauss | 0:4d17cd9c8f9d | 530 | }break; |
klauss | 9:ffa64f38ef9c | 531 | }// fim switch |
klauss | 78:1353744f01e1 | 532 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 533 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 534 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 535 | char * tmp = call->get_eth_message( &length ); |
klauss | 0:4d17cd9c8f9d | 536 | if( tmp != NULL ){ |
klauss | 0:4d17cd9c8f9d | 537 | int cb_port = 0xffff; |
klauss | 78:1353744f01e1 | 538 | Call_Box * cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 4:de46f0d9b14d | 539 | |
klauss | 4:de46f0d9b14d | 540 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 541 | cb_port = cb->get_port(); |
klauss | 78:1353744f01e1 | 542 | |
klauss | 78:1353744f01e1 | 543 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 0:4d17cd9c8f9d | 544 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 4:de46f0d9b14d | 545 | |
klauss | 78:1353744f01e1 | 546 | send2callboxes( pkg2cb ); |
klauss | 78:1353744f01e1 | 547 | }else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 548 | } |
klauss | 14:22a35f575502 | 549 | } |
klauss | 78:1353744f01e1 | 550 | //if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 78:1353744f01e1 | 551 | |
klauss | 78:1353744f01e1 | 552 | //Fixme pensar melhor nessa parte durante ligacoes, pode complicar com muitos cbx ... |
klauss | 78:1353744f01e1 | 553 | //testar sem os debugs em on, pode fazer a diferenca |
klauss | 28:94aec56c6329 | 554 | if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 4:de46f0d9b14d | 555 | |
klauss | 78:1353744f01e1 | 556 | // check sip messages only for cbx in call ? |
klauss | 78:1353744f01e1 | 557 | int ext_to__be_removed = sip_manager( v_cb ); |
klauss | 78:1353744f01e1 | 558 | if( ext_to__be_removed > 0x00 ){ |
klauss | 78:1353744f01e1 | 559 | Call_Box * cb = __find_CB__( v_cb, ext_to__be_removed ); |
klauss | 4:de46f0d9b14d | 560 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 561 | if( cb->status == cb_on_call ){ |
klauss | 4:de46f0d9b14d | 562 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 563 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 564 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 78:1353744f01e1 | 565 | |
klauss | 78:1353744f01e1 | 566 | set_status( cb->status, cb_idle ); |
klauss | 78:1353744f01e1 | 567 | set_status( cb->sip->status, sip_idle ); |
klauss | 78:1353744f01e1 | 568 | |
klauss | 4:de46f0d9b14d | 569 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 4:de46f0d9b14d | 570 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 78:1353744f01e1 | 571 | if( call->get_cb_ext() == ext_to__be_removed ){ |
klauss | 4:de46f0d9b14d | 572 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 573 | delete( call ); |
klauss | 4:de46f0d9b14d | 574 | } |
klauss | 2:93bec7313ccc | 575 | } |
klauss | 78:1353744f01e1 | 576 | |
klauss | 74:81c47fff88a5 | 577 | send2callboxes( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 4:de46f0d9b14d | 578 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 78:1353744f01e1 | 579 | cb->set_msg_id( ( cb->get_msg_id() & ~BIT7 ) + 1 ); |
klauss | 78:1353744f01e1 | 580 | |
klauss | 29:7246460b73f8 | 581 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 582 | } |
klauss | 78:1353744f01e1 | 583 | }else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d", ext ); |
klauss | 0:4d17cd9c8f9d | 584 | } |
klauss | 13:ae278302dffe | 585 | |
klauss | 10:22da1a0ac1e1 | 586 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 0:4d17cd9c8f9d | 587 | |
klauss | 78:1353744f01e1 | 588 | invite_handler( v_call, v_cb, ts, NULL ); |
klauss | 78:1353744f01e1 | 589 | |
klauss | 78:1353744f01e1 | 590 | if( ( v_call->size() == 0 ) && ( ts->remain_timeslices() != __MAX_TIMESLICES__ ) ){ |
klauss | 78:1353744f01e1 | 591 | bool ts_reset = true; |
klauss | 78:1353744f01e1 | 592 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 78:1353744f01e1 | 593 | if ( ( ( Call_Box * )v_cb->get_element( i ) )->get_status() != cb_idle ){ |
klauss | 78:1353744f01e1 | 594 | ts_reset = false; |
klauss | 78:1353744f01e1 | 595 | break; |
klauss | 78:1353744f01e1 | 596 | } |
klauss | 78:1353744f01e1 | 597 | } |
klauss | 78:1353744f01e1 | 598 | if( ts_reset ){ |
klauss | 78:1353744f01e1 | 599 | debug_msg(""); |
klauss | 78:1353744f01e1 | 600 | ts->reset(); |
klauss | 78:1353744f01e1 | 601 | } |
klauss | 0:4d17cd9c8f9d | 602 | } |
klauss | 78:1353744f01e1 | 603 | |
klauss | 67:cdedc64d9921 | 604 | bl_handler(); |
klauss | 78:1353744f01e1 | 605 | |
klauss | 72:895ca792c647 | 606 | tx_buffer_ring_buffer_handler(); |
klauss | 33:735fd60e96d8 | 607 | |
klauss | 30:8dfb6d8de53d | 608 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 609 | } |
klauss | 0:4d17cd9c8f9d | 610 | } |