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