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