Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
main.cpp@63:0d95da692bb4, 2014-10-28 (annotated)
- Committer:
- klauss
- Date:
- Tue Oct 28 12:44:45 2014 +0000
- Revision:
- 63:0d95da692bb4
- Parent:
- 62:07e5bdc9f8f7
- Child:
- 64:5b011d5707d2
stats implementado, conta o nro de pacotes recebidos por determinado tipo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "bits.h" |
klauss | 0:4d17cd9c8f9d | 2 | #include "utils.h" |
klauss | 0:4d17cd9c8f9d | 3 | #include "configs.h" |
klauss | 0:4d17cd9c8f9d | 4 | #include "UART3Interrupt.h" |
klauss | 0:4d17cd9c8f9d | 5 | #include "parallelcpld.h" |
Cola | 21:0bd688722e81 | 6 | #include "prompt.h" |
klauss | 0:4d17cd9c8f9d | 7 | #include "debug.h" |
klauss | 0:4d17cd9c8f9d | 8 | #include "utils.h" |
Cola | 21:0bd688722e81 | 9 | #include "flood.h" |
klauss | 33:735fd60e96d8 | 10 | #include "eth.h" |
klauss | 0:4d17cd9c8f9d | 11 | |
klauss | 0:4d17cd9c8f9d | 12 | volatile uint8_t status = 0x00; |
klauss | 0:4d17cd9c8f9d | 13 | |
klauss | 0:4d17cd9c8f9d | 14 | int main(){ |
klauss | 48:195c97f12e8e | 15 | wdt.Configure( 40.0 ); |
klauss | 0:4d17cd9c8f9d | 16 | start_cpld(); |
klauss | 0:4d17cd9c8f9d | 17 | config_lpc(); |
klauss | 0:4d17cd9c8f9d | 18 | |
klauss | 43:455522f98de5 | 19 | init_fsystem(); |
klauss | 43:455522f98de5 | 20 | |
klauss | 43:455522f98de5 | 21 | // pensar melhor em como saber se estou conectado na eth |
klauss | 48:195c97f12e8e | 22 | //int eth_status = __init_eth__( ð ); |
klauss | 48:195c97f12e8e | 23 | int eth_status = __init_eth__(); |
klauss | 30:8dfb6d8de53d | 24 | |
klauss | 8:e3bfe62a477e | 25 | if( eth_status ){ |
klauss | 48:195c97f12e8e | 26 | send_msg("Cannot connect to eth\n\r"); |
klauss | 43:455522f98de5 | 27 | }else{ |
klauss | 48:195c97f12e8e | 28 | send_msg("Connection eth - ok"); |
klauss | 43:455522f98de5 | 29 | init_prompt(); |
klauss | 8:e3bfe62a477e | 30 | } |
klauss | 0:4d17cd9c8f9d | 31 | Timer t; |
klauss | 0:4d17cd9c8f9d | 32 | t.start(); |
klauss | 33:735fd60e96d8 | 33 | Timer udp_timer; |
klauss | 0:4d17cd9c8f9d | 34 | |
klauss | 0:4d17cd9c8f9d | 35 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 36 | int ext = 0; |
klauss | 0:4d17cd9c8f9d | 37 | |
klauss | 0:4d17cd9c8f9d | 38 | /* representa porta do call box */ |
klauss | 0:4d17cd9c8f9d | 39 | int port = 0; |
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 | 0:4d17cd9c8f9d | 66 | /* tenta instanciar o vetor de call boxes, acende o led 1 antes de encerrar o programa */ |
klauss | 0:4d17cd9c8f9d | 67 | reset_leds(); |
klauss | 0:4d17cd9c8f9d | 68 | if( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 69 | led1 = 0; |
klauss | 0:4d17cd9c8f9d | 70 | while( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 71 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 72 | led1 = led1; |
klauss | 0:4d17cd9c8f9d | 73 | if( t.read() > 5 ){ |
klauss | 48:195c97f12e8e | 74 | send_msg("Erro ao alocar o vetor de CBx"); |
klauss | 0:4d17cd9c8f9d | 75 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 76 | } |
klauss | 0:4d17cd9c8f9d | 77 | } |
klauss | 0:4d17cd9c8f9d | 78 | }else if( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 79 | led2 = 0; |
klauss | 0:4d17cd9c8f9d | 80 | led1 = 1; |
klauss | 0:4d17cd9c8f9d | 81 | while( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 82 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 83 | if( t.read() > 5 ){ |
klauss | 48:195c97f12e8e | 84 | send_msg("Erro ao alocar o vetor de Calls"); |
klauss | 0:4d17cd9c8f9d | 85 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 86 | } |
klauss | 0:4d17cd9c8f9d | 87 | } |
klauss | 0:4d17cd9c8f9d | 88 | } |
klauss | 63:0d95da692bb4 | 89 | |
klauss | 63:0d95da692bb4 | 90 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 63:0d95da692bb4 | 91 | cb_rx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 92 | cb_tx_buffer[ i ] = 0; |
klauss | 63:0d95da692bb4 | 93 | } |
klauss | 63:0d95da692bb4 | 94 | |
klauss | 0:4d17cd9c8f9d | 95 | reset_leds(); |
klauss | 33:735fd60e96d8 | 96 | udp_timer.start(); |
klauss | 48:195c97f12e8e | 97 | send_msg("Ready"); |
klauss | 57:78f7191a8b69 | 98 | uint8_t before = t.read(); |
klauss | 62:07e5bdc9f8f7 | 99 | static uint8_t count = 0; |
Cola | 21:0bd688722e81 | 100 | while( true ){ |
klauss | 49:4837ed2aad6b | 101 | //FIXME colocar uma condicao aqui |
klauss | 35:96885a7931f0 | 102 | prompt_process( NULL ); |
klauss | 33:735fd60e96d8 | 103 | wdt.kick(); |
klauss | 62:07e5bdc9f8f7 | 104 | |
klauss | 62:07e5bdc9f8f7 | 105 | if( rx ){ |
klauss | 62:07e5bdc9f8f7 | 106 | char str[ 1024 ]; |
klauss | 63:0d95da692bb4 | 107 | strcpy( str, "RX :: \n\r " ); |
klauss | 62:07e5bdc9f8f7 | 108 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 62:07e5bdc9f8f7 | 109 | char tmp[ 16 ]; |
klauss | 62:07e5bdc9f8f7 | 110 | strcat( str, itoa( cb_rx_buffer[ i ], tmp, 16 ) ); |
klauss | 63:0d95da692bb4 | 111 | if( ( i != 0 ) && !( ( i + 1 ) % 20 ) ) strcat( str, "\n\r " ); |
klauss | 62:07e5bdc9f8f7 | 112 | |
klauss | 62:07e5bdc9f8f7 | 113 | else strcat( str, " " ); |
klauss | 62:07e5bdc9f8f7 | 114 | } |
klauss | 62:07e5bdc9f8f7 | 115 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 116 | rx = false; |
klauss | 62:07e5bdc9f8f7 | 117 | } |
klauss | 62:07e5bdc9f8f7 | 118 | |
klauss | 63:0d95da692bb4 | 119 | if( tx ){ |
klauss | 63:0d95da692bb4 | 120 | char str[ 1024 ]; |
klauss | 63:0d95da692bb4 | 121 | strcpy( str, "TX :: \n\r " ); |
klauss | 63:0d95da692bb4 | 122 | for( register uint16_t i = 0; i < __CB_BUFFER_SIZE__; i++ ){ |
klauss | 63:0d95da692bb4 | 123 | char tmp[ 16 ]; |
klauss | 63:0d95da692bb4 | 124 | strcat( str, itoa( cb_tx_buffer[ i ], tmp, 16 ) ); |
klauss | 63:0d95da692bb4 | 125 | if( ( i != 0 ) && !( ( i + 1 ) % 20 ) ) strcat( str, "\n\r " ); |
klauss | 63:0d95da692bb4 | 126 | |
klauss | 63:0d95da692bb4 | 127 | else strcat( str, " " ); |
klauss | 63:0d95da692bb4 | 128 | } |
klauss | 63:0d95da692bb4 | 129 | send_msg( "%s", str ); |
klauss | 63:0d95da692bb4 | 130 | tx = false; |
klauss | 63:0d95da692bb4 | 131 | } |
klauss | 63:0d95da692bb4 | 132 | |
klauss | 63:0d95da692bb4 | 133 | if( r_stats ){ |
klauss | 63:0d95da692bb4 | 134 | boot_counter = 0; |
klauss | 63:0d95da692bb4 | 135 | registry_counter = 0; |
klauss | 63:0d95da692bb4 | 136 | invite_counter = 0; |
klauss | 63:0d95da692bb4 | 137 | audio_counter = 0; |
klauss | 63:0d95da692bb4 | 138 | telemetry_counter = 0; |
klauss | 63:0d95da692bb4 | 139 | cb_bye_counter = 0; |
klauss | 63:0d95da692bb4 | 140 | prompt_counter = 0; |
klauss | 63:0d95da692bb4 | 141 | flood_counter = 0; |
klauss | 63:0d95da692bb4 | 142 | r_stats = false; |
klauss | 63:0d95da692bb4 | 143 | stats = true; |
klauss | 63:0d95da692bb4 | 144 | } |
klauss | 63:0d95da692bb4 | 145 | if( stats ){ |
klauss | 63:0d95da692bb4 | 146 | char str[ 200 ]; |
klauss | 63:0d95da692bb4 | 147 | snprintf( str, 1024, "\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", |
klauss | 63:0d95da692bb4 | 148 | boot_counter, registry_counter, invite_counter, audio_counter, telemetry_counter, cb_bye_counter, prompt_counter, flood_counter ); |
klauss | 63:0d95da692bb4 | 149 | send_msg( str ); |
klauss | 63:0d95da692bb4 | 150 | stats =false; |
klauss | 63:0d95da692bb4 | 151 | } |
klauss | 63:0d95da692bb4 | 152 | |
klauss | 62:07e5bdc9f8f7 | 153 | if( list ){ |
klauss | 62:07e5bdc9f8f7 | 154 | send_msg("Registred %d CBx", v_cb->size() ); |
klauss | 62:07e5bdc9f8f7 | 155 | if( v_cb->size() == 0 ){ |
klauss | 62:07e5bdc9f8f7 | 156 | send_msg("{-/-}"); |
klauss | 62:07e5bdc9f8f7 | 157 | }else if( v_cb->size() == 1 ){ |
klauss | 62:07e5bdc9f8f7 | 158 | Call_Box * cb = ( Call_Box * )v_cb->get_element( 0 ); |
klauss | 62:07e5bdc9f8f7 | 159 | send_msg(" %d ", cb->get_ext() ); |
klauss | 62:07e5bdc9f8f7 | 160 | }else{ |
klauss | 62:07e5bdc9f8f7 | 161 | char str[ 1024 ]; |
klauss | 62:07e5bdc9f8f7 | 162 | int ext_list[ 128 ]; |
klauss | 62:07e5bdc9f8f7 | 163 | Call_Box * cb = NULL; |
klauss | 62:07e5bdc9f8f7 | 164 | register int i = 0; |
klauss | 62:07e5bdc9f8f7 | 165 | for( ; i < v_cb->size(); i++ ){ |
klauss | 62:07e5bdc9f8f7 | 166 | cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 62:07e5bdc9f8f7 | 167 | ext_list[ i ] = cb->get_ext(); |
klauss | 62:07e5bdc9f8f7 | 168 | } |
klauss | 62:07e5bdc9f8f7 | 169 | |
klauss | 62:07e5bdc9f8f7 | 170 | qsort( ext_list, v_cb->size(), sizeof( int ), ls_comp ); |
klauss | 62:07e5bdc9f8f7 | 171 | |
klauss | 62:07e5bdc9f8f7 | 172 | char aux[ 16 ]; |
klauss | 62:07e5bdc9f8f7 | 173 | strcpy( str, "\r\n " ); |
klauss | 62:07e5bdc9f8f7 | 174 | for( i = 0; i < v_cb->size() - 1; i++ ){ |
klauss | 62:07e5bdc9f8f7 | 175 | sprintf( aux, "%i, ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 176 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 177 | if( ( i != 0 ) && !( ( i + 1 ) % 8 ) ) strcat( str, "\r\n " ); |
klauss | 62:07e5bdc9f8f7 | 178 | } |
klauss | 62:07e5bdc9f8f7 | 179 | sprintf( aux, "%i ", ext_list[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 180 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 181 | send_msg( "%s", str ); |
klauss | 62:07e5bdc9f8f7 | 182 | } |
klauss | 62:07e5bdc9f8f7 | 183 | list = false; |
klauss | 62:07e5bdc9f8f7 | 184 | } |
klauss | 62:07e5bdc9f8f7 | 185 | |
Cola | 22:d2a4b5939115 | 186 | if (pcks_s == 1){ |
klauss | 48:195c97f12e8e | 187 | send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d", pkg_cksok, pkg_ckserr ); |
Cola | 24:270b436a1bb0 | 188 | pcks_s =0; |
Cola | 24:270b436a1bb0 | 189 | } |
Cola | 24:270b436a1bb0 | 190 | |
klauss | 52:12930cef17c4 | 191 | if( reset_cks ){ |
klauss | 52:12930cef17c4 | 192 | pkg_cksok = 0; |
klauss | 52:12930cef17c4 | 193 | pkg_ckserr = 0; |
klauss | 52:12930cef17c4 | 194 | send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d", pkg_cksok, pkg_ckserr ); |
klauss | 52:12930cef17c4 | 195 | reset_cks = false; |
klauss | 52:12930cef17c4 | 196 | } |
klauss | 52:12930cef17c4 | 197 | |
Cola | 24:270b436a1bb0 | 198 | if (pshowcb == 1){ |
klauss | 48:195c97f12e8e | 199 | send_msg("Registred %d CBx", v_cb->size() ); |
Cola | 24:270b436a1bb0 | 200 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 30:8dfb6d8de53d | 201 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 48:195c97f12e8e | 202 | send_msg("Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); |
klauss | 48:195c97f12e8e | 203 | } |
klauss | 48:195c97f12e8e | 204 | pshowcb = 0; |
klauss | 48:195c97f12e8e | 205 | } |
klauss | 63:0d95da692bb4 | 206 | /* |
klauss | 48:195c97f12e8e | 207 | if( cb_status ){ |
klauss | 48:195c97f12e8e | 208 | cb_status = false; |
klauss | 48:195c97f12e8e | 209 | send_msg("Registred %d CBx", v_cb->size() ); |
klauss | 48:195c97f12e8e | 210 | char str[ 1024 ]; |
klauss | 48:195c97f12e8e | 211 | |
klauss | 48:195c97f12e8e | 212 | if( v_cb->size() == 0 ){ |
klauss | 48:195c97f12e8e | 213 | send_msg("{-/-}"); |
klauss | 48:195c97f12e8e | 214 | }else if( v_cb->size() == 1 ){ |
klauss | 48:195c97f12e8e | 215 | Call_Box * cb = ( Call_Box * )v_cb->get_element( 0 ); |
klauss | 62:07e5bdc9f8f7 | 216 | send_msg(" %i ", cb->get_ext() ); |
klauss | 48:195c97f12e8e | 217 | }else{ |
klauss | 48:195c97f12e8e | 218 | register uint8_t i; |
klauss | 48:195c97f12e8e | 219 | char aux[ 16 ]; |
klauss | 48:195c97f12e8e | 220 | Call_Box * cb = NULL; |
klauss | 48:195c97f12e8e | 221 | for( i = 0; i < v_cb->size() - 1; i++ ){ |
klauss | 48:195c97f12e8e | 222 | cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 62:07e5bdc9f8f7 | 223 | sprintf( aux, "%i, ", cb->get_ext() ); |
klauss | 48:195c97f12e8e | 224 | strcat( str, aux ); |
klauss | 62:07e5bdc9f8f7 | 225 | if( ( i != 0 ) && !( ( i + 1 ) % 8 ) ) strcat( str, "\n\r " ); |
klauss | 48:195c97f12e8e | 226 | } |
klauss | 48:195c97f12e8e | 227 | cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 62:07e5bdc9f8f7 | 228 | sprintf( aux, "%i ", cb->get_ext() ); |
klauss | 48:195c97f12e8e | 229 | strcat( str, aux ); |
klauss | 48:195c97f12e8e | 230 | send_msg( "%s", str ); |
Cola | 24:270b436a1bb0 | 231 | } |
Cola | 22:d2a4b5939115 | 232 | } |
klauss | 63:0d95da692bb4 | 233 | */ |
Cola | 22:d2a4b5939115 | 234 | |
klauss | 30:8dfb6d8de53d | 235 | if( pflood == 1 ) flood(); |
klauss | 30:8dfb6d8de53d | 236 | |
klauss | 0:4d17cd9c8f9d | 237 | if( status != __WAITING__ ){ |
klauss | 62:07e5bdc9f8f7 | 238 | xmemcpy( cb_rx_buffer, buffer_from_cb_ptr, __CB_BUFFER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 239 | __read_cb_buffer__( buffer, buffer_from_cb_ptr ); |
klauss | 0:4d17cd9c8f9d | 240 | status = __WAITING__; |
klauss | 0:4d17cd9c8f9d | 241 | |
klauss | 34:f19d9735428e | 242 | data = __parse_vz_pkg__( &ext, &port, &type, buffer ); |
klauss | 0:4d17cd9c8f9d | 243 | |
klauss | 3:cd9148672e25 | 244 | if( data != NULL ){ |
klauss | 31:bb5fb28a77df | 245 | if( debug_alive == 1 && debug_cb_rx ) debug_msg("Pkg from CBx :: %d -- Type :: %d", ext, type ); |
klauss | 7:019b08223b87 | 246 | if( type != __AUDIO__ ){ |
klauss | 0:4d17cd9c8f9d | 247 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 248 | if( cb != NULL ){ |
klauss | 3:cd9148672e25 | 249 | cb->reset_elapsed_time(); |
klauss | 0:4d17cd9c8f9d | 250 | if( ( data[ 0 ] ^ cb->get_msg_id() ) == BIT7 ){ |
klauss | 0:4d17cd9c8f9d | 251 | // some pkg reply |
klauss | 0:4d17cd9c8f9d | 252 | if( ( data[ 0 ] | BIT7 ) == cb->get_msg_id() ){ |
klauss | 7:019b08223b87 | 253 | if( type == __BOOT__ ) type = __REGISTRY__; |
klauss | 0:4d17cd9c8f9d | 254 | __send_to_cb__( __build_cb_package__( ext, port, type, |
klauss | 0:4d17cd9c8f9d | 255 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 256 | type = __DO_NOTHING__; |
klauss | 30:8dfb6d8de53d | 257 | if( debug_main ) debug_msg("-- Renviado ultimo pkg --"); |
klauss | 0:4d17cd9c8f9d | 258 | }else if( data[ 0 ] == ( cb->get_msg_id() | BIT7 ) ){ |
klauss | 0:4d17cd9c8f9d | 259 | // ack from CBx |
klauss | 30:8dfb6d8de53d | 260 | if( debug_main ) debug_msg("-- ACK do meu pkg --"); |
klauss | 0:4d17cd9c8f9d | 261 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 262 | } |
klauss | 0:4d17cd9c8f9d | 263 | } |
klauss | 0:4d17cd9c8f9d | 264 | } |
klauss | 0:4d17cd9c8f9d | 265 | } |
klauss | 0:4d17cd9c8f9d | 266 | }else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 267 | } |
klauss | 2:93bec7313ccc | 268 | //---------------------- |
klauss | 57:78f7191a8b69 | 269 | uint8_t now = t.read(); |
klauss | 57:78f7191a8b69 | 270 | if( before != now ){ |
klauss | 57:78f7191a8b69 | 271 | led3 = !led3; |
klauss | 57:78f7191a8b69 | 272 | before = now; |
klauss | 57:78f7191a8b69 | 273 | } |
klauss | 57:78f7191a8b69 | 274 | |
klauss | 27:98f824719d1c | 275 | if( t.read() > 5 ){ |
klauss | 62:07e5bdc9f8f7 | 276 | static int test_ext = 5010; |
klauss | 62:07e5bdc9f8f7 | 277 | static int test_port = 5010; |
klauss | 48:195c97f12e8e | 278 | //send_msg("from_eth = %s - tcp_session = %s", ( from_eth ) ? "true" : "false", ( tcp_session ) ? "true" : "false" ); |
klauss | 48:195c97f12e8e | 279 | if( debug_alive ){ |
klauss | 48:195c97f12e8e | 280 | send_msg("Registred %d CBx", v_cb->size() ); |
klauss | 48:195c97f12e8e | 281 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 48:195c97f12e8e | 282 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 48:195c97f12e8e | 283 | send_msg("Type :: %d -- Ext :: %d -- TimeSlice :: %d -- remain_timeslices :: %d :: v_call->size() :: %d :: Status :: %d :: SIP Status %d", type , cb->get_ext(), cb->get_timeslice(), ts->remain_timeslices(), v_call->size(), cb->status, cb->sip->status ); |
klauss | 30:8dfb6d8de53d | 284 | } |
klauss | 33:735fd60e96d8 | 285 | } |
klauss | 48:195c97f12e8e | 286 | /* |
klauss | 30:8dfb6d8de53d | 287 | if( debug_alive == 1 ){ |
klauss | 48:195c97f12e8e | 288 | if( debug_main ) send_msg("Status - alive "); |
klauss | 30:8dfb6d8de53d | 289 | //uint32_t errper = 100*(pkg_ckserr/(pkg_ckserr + pkg_cksok)); |
klauss | 30:8dfb6d8de53d | 290 | //pc.printf("\n\r Error = %d", errper); |
Cola | 21:0bd688722e81 | 291 | } |
klauss | 48:195c97f12e8e | 292 | */ |
klauss | 0:4d17cd9c8f9d | 293 | t.reset(); |
Cola | 22:d2a4b5939115 | 294 | CAB_LED = !CAB_LED; |
klauss | 27:98f824719d1c | 295 | |
klauss | 48:195c97f12e8e | 296 | if( debug_cks ) send_msg("PKG_CSK OK: %d :: PKG_CSK ERR: %d", pkg_cksok, pkg_ckserr ); |
klauss | 40:990683572031 | 297 | |
klauss | 40:990683572031 | 298 | //<><><><><><><><><><> |
klauss | 43:455522f98de5 | 299 | count++; |
klauss | 49:4837ed2aad6b | 300 | if( !( count % 15 ) ){ |
klauss | 44:cc4996469404 | 301 | if( eth_status ){ |
klauss | 44:cc4996469404 | 302 | wdt.kick(); |
klauss | 48:195c97f12e8e | 303 | //eth_status = __init_eth__( ð ); |
klauss | 48:195c97f12e8e | 304 | eth_status = __init_eth__(); |
klauss | 44:cc4996469404 | 305 | if( eth_status ){ |
klauss | 44:cc4996469404 | 306 | if( debug_main ) debug_msg("Cannot connect to eth"); |
klauss | 44:cc4996469404 | 307 | }else{ |
klauss | 44:cc4996469404 | 308 | if( debug_main ) debug_msg("Connection eth - ok"); |
klauss | 44:cc4996469404 | 309 | init_prompt(); |
klauss | 44:cc4996469404 | 310 | } |
klauss | 44:cc4996469404 | 311 | } |
klauss | 44:cc4996469404 | 312 | } |
klauss | 53:bb492a8f115a | 313 | |
klauss | 54:448d57291be6 | 314 | if( main_test ){ |
klauss | 62:07e5bdc9f8f7 | 315 | data = buffer; |
klauss | 62:07e5bdc9f8f7 | 316 | ext = test_ext++ + ( ( test_ext % 2 ) ? 100 : 50 ); |
klauss | 62:07e5bdc9f8f7 | 317 | port = test_port++; |
klauss | 62:07e5bdc9f8f7 | 318 | type = __REGISTRY__; |
klauss | 46:a670f187a704 | 319 | } |
klauss | 53:bb492a8f115a | 320 | |
klauss | 48:195c97f12e8e | 321 | /* |
klauss | 46:a670f187a704 | 322 | if( count == 5 * 2 ){ |
klauss | 46:a670f187a704 | 323 | //debug_msg("Colocar simulacoes de cbx aqui"); |
klauss | 46:a670f187a704 | 324 | data = buffer; |
klauss | 46:a670f187a704 | 325 | ext = 891; |
klauss | 46:a670f187a704 | 326 | port = 5001; |
klauss | 46:a670f187a704 | 327 | type = __INVITE__; |
klauss | 46:a670f187a704 | 328 | debug_msg("registro enviado"); |
klauss | 45:c80574f24dc3 | 329 | }*/ |
klauss | 0:4d17cd9c8f9d | 330 | } |
klauss | 0:4d17cd9c8f9d | 331 | //---------------------- |
klauss | 0:4d17cd9c8f9d | 332 | switch( type ){ |
klauss | 0:4d17cd9c8f9d | 333 | case __DO_NOTHING__ :{} |
klauss | 0:4d17cd9c8f9d | 334 | break; |
klauss | 0:4d17cd9c8f9d | 335 | |
klauss | 0:4d17cd9c8f9d | 336 | case __CB_BYE__ : { |
klauss | 63:0d95da692bb4 | 337 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 338 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 339 | if( cb != NULL ){ |
klauss | 0:4d17cd9c8f9d | 340 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 341 | cb->set_msg_id( data[ 0 ] ); |
klauss | 30:8dfb6d8de53d | 342 | if( debug_main ) debug_msg( " Request bye from CBx " ); |
klauss | 0:4d17cd9c8f9d | 343 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 344 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 345 | if( call->get_cb_ext() == ext ){ |
klauss | 4:de46f0d9b14d | 346 | cb->send_bye(); |
klauss | 0:4d17cd9c8f9d | 347 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 348 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 349 | set_status( cb->status, cb_idle ); |
klauss | 13:ae278302dffe | 350 | v_call->remove_element( i ); |
klauss | 13:ae278302dffe | 351 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 352 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 353 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 354 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 13:ae278302dffe | 355 | set_status( cb->sip->status, sip_idle ); |
klauss | 3:cd9148672e25 | 356 | delete( call ); |
klauss | 29:7246460b73f8 | 357 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 358 | } |
klauss | 0:4d17cd9c8f9d | 359 | } |
klauss | 0:4d17cd9c8f9d | 360 | } |
klauss | 7:019b08223b87 | 361 | }break; |
klauss | 7:019b08223b87 | 362 | |
klauss | 0:4d17cd9c8f9d | 363 | case __INVITE__ : { |
klauss | 63:0d95da692bb4 | 364 | invite_counter++; |
klauss | 30:8dfb6d8de53d | 365 | if( debug_main ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 0:4d17cd9c8f9d | 366 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 367 | if( cb == NULL ){ |
klauss | 31:bb5fb28a77df | 368 | if( debug_main ) debug_msg("Adding CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 369 | cb = new Call_Box( ext, port ); |
klauss | 0:4d17cd9c8f9d | 370 | v_cb->add( cb ); |
klauss | 0:4d17cd9c8f9d | 371 | set_status( cb->status, cb_idle ); |
klauss | 0:4d17cd9c8f9d | 372 | cb->registry(); |
klauss | 0:4d17cd9c8f9d | 373 | } |
klauss | 13:ae278302dffe | 374 | cb->reset_elapsed_time(); |
klauss | 10:22da1a0ac1e1 | 375 | if( v_call->size() != 0 ){ |
klauss | 10:22da1a0ac1e1 | 376 | data[ 0 ] |= BIT7; |
klauss | 10:22da1a0ac1e1 | 377 | cb->set_msg_id( data[ 0 ] ); |
klauss | 10:22da1a0ac1e1 | 378 | set_status(cb->status,cb_idle); |
klauss | 10:22da1a0ac1e1 | 379 | cb->set_timeslice( 0x00 ); |
klauss | 10:22da1a0ac1e1 | 380 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 10:22da1a0ac1e1 | 381 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 10:22da1a0ac1e1 | 382 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 30:8dfb6d8de53d | 383 | if( debug_main ) debug_msg( "denying call - another call box on call" ); |
klauss | 10:22da1a0ac1e1 | 384 | break; |
klauss | 10:22da1a0ac1e1 | 385 | } |
klauss | 0:4d17cd9c8f9d | 386 | set_status( cb->status, cb_trying ); |
klauss | 30:8dfb6d8de53d | 387 | if( debug_main ) debug_msg("Request invite cbx status :: %d", cb->status ); |
klauss | 32:43041f5e27c4 | 388 | |
klauss | 32:43041f5e27c4 | 389 | //FIXME essa logica deve estar la embaixo, fora do switch maior, a ideia eh |
klauss | 32:43041f5e27c4 | 390 | // quando receber um pedido de invite, apenas manda o invite pro server |
klauss | 32:43041f5e27c4 | 391 | // dai rodar, ver se alguem mandou alguma coisa e voltar a tratar com o |
klauss | 32:43041f5e27c4 | 392 | // * ver se ja esta tudo ok, a ideia é fazer esse pedido de invite funcionar |
klauss | 32:43041f5e27c4 | 393 | // assincrono. |
klauss | 0:4d17cd9c8f9d | 394 | switch( cb->status ){ |
klauss | 0:4d17cd9c8f9d | 395 | case cb_on_call : { |
klauss | 0:4d17cd9c8f9d | 396 | // a priori, nao fazer nada |
klauss | 0:4d17cd9c8f9d | 397 | //data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 398 | //__send_to_cb__( __build_cb_package__( ext, port, __BYE__, |
klauss | 0:4d17cd9c8f9d | 399 | // ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 400 | }break; |
klauss | 0:4d17cd9c8f9d | 401 | |
klauss | 0:4d17cd9c8f9d | 402 | case cb_ringing : { |
klauss | 0:4d17cd9c8f9d | 403 | // tratar sip 2 |
klauss | 0:4d17cd9c8f9d | 404 | }break; |
klauss | 0:4d17cd9c8f9d | 405 | |
klauss | 0:4d17cd9c8f9d | 406 | case cb_trying : { |
klauss | 0:4d17cd9c8f9d | 407 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 408 | cb->set_msg_id( data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 409 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 410 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 411 | //sem timeslice pra tratar com o * |
klauss | 9:ffa64f38ef9c | 412 | set_status(cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 413 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 414 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 415 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 13:ae278302dffe | 416 | set_status( cb->sip->status, sip_idle); |
klauss | 31:bb5fb28a77df | 417 | if( debug_main ) debug_msg( "-- Trying -- without TS -- %s ", write_buffer ); |
klauss | 0:4d17cd9c8f9d | 418 | }else{ |
klauss | 0:4d17cd9c8f9d | 419 | set_status(cb->status,cb_busy); |
klauss | 0:4d17cd9c8f9d | 420 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 0:4d17cd9c8f9d | 421 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 422 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 423 | |
klauss | 31:bb5fb28a77df | 424 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 425 | |
klauss | 3:cd9148672e25 | 426 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 0:4d17cd9c8f9d | 427 | VZ_call * call = cb->invite(); |
klauss | 0:4d17cd9c8f9d | 428 | |
klauss | 0:4d17cd9c8f9d | 429 | if( call != NULL ){ |
klauss | 0:4d17cd9c8f9d | 430 | v_call->add( call ); |
klauss | 0:4d17cd9c8f9d | 431 | set_status(cb->status,cb_on_call); |
klauss | 0:4d17cd9c8f9d | 432 | |
klauss | 31:bb5fb28a77df | 433 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 434 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 435 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 31:bb5fb28a77df | 436 | if( debug_main ) debug_msg( "-- Trying -- accepting call request --" ); |
klauss | 0:4d17cd9c8f9d | 437 | }else{ |
klauss | 4:de46f0d9b14d | 438 | set_status( cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 439 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 440 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 441 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 31:bb5fb28a77df | 442 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 443 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 444 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 31:bb5fb28a77df | 445 | if( debug_main ) debug_msg( "-- Trying -- denying call request --" ); |
klauss | 13:ae278302dffe | 446 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 447 | } |
klauss | 0:4d17cd9c8f9d | 448 | } |
klauss | 4:de46f0d9b14d | 449 | }break; |
klauss | 0:4d17cd9c8f9d | 450 | case cb_busy : { |
klauss | 25:2cf5e8dd4035 | 451 | set_status( cb->status,cb_idle); |
klauss | 25:2cf5e8dd4035 | 452 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 25:2cf5e8dd4035 | 453 | cb->set_timeslice( 0x00 ); |
klauss | 25:2cf5e8dd4035 | 454 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 30:8dfb6d8de53d | 455 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 25:2cf5e8dd4035 | 456 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 25:2cf5e8dd4035 | 457 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 30:8dfb6d8de53d | 458 | if( debug_main ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" ); |
klauss | 25:2cf5e8dd4035 | 459 | set_status( cb->sip->status, sip_idle ); |
klauss | 0:4d17cd9c8f9d | 460 | }break; |
klauss | 0:4d17cd9c8f9d | 461 | } |
klauss | 0:4d17cd9c8f9d | 462 | }break; |
klauss | 4:de46f0d9b14d | 463 | case __REGISTRY__ : { |
klauss | 63:0d95da692bb4 | 464 | registry_counter++; |
klauss | 4:de46f0d9b14d | 465 | Call_Box * cb = NULL; |
klauss | 2:93bec7313ccc | 466 | |
klauss | 4:de46f0d9b14d | 467 | data[ 0 ] |= BIT7 ; |
klauss | 4:de46f0d9b14d | 468 | cb = __find_CB__( v_cb, ext ); |
klauss | 4:de46f0d9b14d | 469 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 470 | cb->reset_elapsed_time(); |
klauss | 30:8dfb6d8de53d | 471 | if( debug_main ) debug_msg(" reset_elapsed_time CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 472 | }else{ |
klauss | 30:8dfb6d8de53d | 473 | if( debug_main ) debug_msg("Adding Cbx :: %d -- Type :: %d", ext, type ); |
klauss | 4:de46f0d9b14d | 474 | cb = new Call_Box( ext, port ); |
klauss | 4:de46f0d9b14d | 475 | v_cb->add( cb ); |
klauss | 30:8dfb6d8de53d | 476 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 477 | } |
klauss | 30:8dfb6d8de53d | 478 | if( debug_main ) debug_msg("::registered %d - %d::", ext, port ); |
klauss | 4:de46f0d9b14d | 479 | cb->registry(); |
klauss | 4:de46f0d9b14d | 480 | }break; |
klauss | 4:de46f0d9b14d | 481 | case __BOOT__ : { |
klauss | 63:0d95da692bb4 | 482 | boot_counter++; |
klauss | 4:de46f0d9b14d | 483 | __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 4:de46f0d9b14d | 484 | ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 485 | }break; |
klauss | 4:de46f0d9b14d | 486 | case __TELEMETRY__ : { |
klauss | 63:0d95da692bb4 | 487 | telemetry_counter++; |
klauss | 53:bb492a8f115a | 488 | if( debug_telemetry ) send_msg("::telemetry from %d - %d::", ext, port ); |
klauss | 53:bb492a8f115a | 489 | build_telemetry_report( ext, port, ( char *)data ); |
klauss | 4:de46f0d9b14d | 490 | }break; |
klauss | 36:728498a78e1e | 491 | |
klauss | 36:728498a78e1e | 492 | case __PROMPT__ : { |
klauss | 63:0d95da692bb4 | 493 | prompt_counter++; |
klauss | 48:195c97f12e8e | 494 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 48:195c97f12e8e | 495 | /* |
klauss | 48:195c97f12e8e | 496 | if( tcp_session ){ // udp ? |
klauss | 48:195c97f12e8e | 497 | char tmp[ 255 ]; |
klauss | 48:195c97f12e8e | 498 | sprintf( tmp, "Prompt pkg from ( %i, %i ) :: ", ext, port ); |
klauss | 48:195c97f12e8e | 499 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 48:195c97f12e8e | 500 | } |
klauss | 48:195c97f12e8e | 501 | */ |
klauss | 62:07e5bdc9f8f7 | 502 | for( register int i = 0; i < 32; i++ ){ |
klauss | 36:728498a78e1e | 503 | pc.printf("%3i ", data[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 504 | if( i == 15 ) pc.printf( "\r\n" ); |
klauss | 48:195c97f12e8e | 505 | } |
klauss | 62:07e5bdc9f8f7 | 506 | pc.printf("\n\r> "); |
klauss | 48:195c97f12e8e | 507 | |
klauss | 48:195c97f12e8e | 508 | if( tcp_session ){ |
klauss | 48:195c97f12e8e | 509 | char aux[ __CB_BUFFER_SIZE__ + 3 ]; |
klauss | 48:195c97f12e8e | 510 | strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); |
klauss | 48:195c97f12e8e | 511 | strcat( aux, "\n\r\0" ); |
klauss | 48:195c97f12e8e | 512 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 62:07e5bdc9f8f7 | 513 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 48:195c97f12e8e | 514 | } |
klauss | 36:728498a78e1e | 515 | }break; |
klauss | 0:4d17cd9c8f9d | 516 | case __AUDIO__ : { |
klauss | 63:0d95da692bb4 | 517 | audio_counter++; |
klauss | 0:4d17cd9c8f9d | 518 | Call_Box * cb; |
klauss | 0:4d17cd9c8f9d | 519 | VZ_call * call = NULL; |
klauss | 0:4d17cd9c8f9d | 520 | cb = NULL; |
klauss | 0:4d17cd9c8f9d | 521 | 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 | 0:4d17cd9c8f9d | 525 | cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 526 | if( cb != NULL ) cb->reset_elapsed_time(); |
klauss | 18:01a93677e40c | 527 | }else{ |
klauss | 30:8dfb6d8de53d | 528 | if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 529 | } |
klauss | 0:4d17cd9c8f9d | 530 | }break; |
klauss | 9:ffa64f38ef9c | 531 | }// fim switch |
klauss | 0:4d17cd9c8f9d | 532 | for( register int 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 | Call_Box * cb = NULL; |
klauss | 0:4d17cd9c8f9d | 538 | int cb_port = 0xffff; |
klauss | 0:4d17cd9c8f9d | 539 | cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 4:de46f0d9b14d | 540 | |
klauss | 4:de46f0d9b14d | 541 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 542 | cb_port = cb->get_port(); |
klauss | 30:8dfb6d8de53d | 543 | }else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 4:de46f0d9b14d | 544 | |
klauss | 0:4d17cd9c8f9d | 545 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 0:4d17cd9c8f9d | 546 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 4:de46f0d9b14d | 547 | |
klauss | 0:4d17cd9c8f9d | 548 | __send_to_cb__( pkg2cb ); |
klauss | 0:4d17cd9c8f9d | 549 | } |
klauss | 14:22a35f575502 | 550 | } |
klauss | 28:94aec56c6329 | 551 | if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 4:de46f0d9b14d | 552 | |
klauss | 0:4d17cd9c8f9d | 553 | int ret = sip_manager( v_cb, v_call, write_buffer ); |
klauss | 0:4d17cd9c8f9d | 554 | if( ret > 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 555 | Call_Box * cb = __find_CB__( v_cb, ret ); |
klauss | 4:de46f0d9b14d | 556 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 557 | if( cb->status == cb_on_call ){ |
klauss | 4:de46f0d9b14d | 558 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 559 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 560 | set_status(cb->status,cb_idle); |
klauss | 4:de46f0d9b14d | 561 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 4:de46f0d9b14d | 562 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 4:de46f0d9b14d | 563 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 4:de46f0d9b14d | 564 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 4:de46f0d9b14d | 565 | if( call->get_cb_ext() == ret ){ |
klauss | 4:de46f0d9b14d | 566 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 567 | delete( call ); |
klauss | 4:de46f0d9b14d | 568 | } |
klauss | 2:93bec7313ccc | 569 | } |
klauss | 4:de46f0d9b14d | 570 | __send_to_cb__( __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 | 38:af5ecd6997ab | 572 | //FIXME talvez eu nao precise dessa linha mudar o set_status( cb->sip->status, sip_idle ); pra ver o que acontece |
klauss | 38:af5ecd6997ab | 573 | //cb->reset_sip(); |
klauss | 13:ae278302dffe | 574 | set_status( cb->sip->status, sip_idle ); |
klauss | 29:7246460b73f8 | 575 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 576 | } |
klauss | 30:8dfb6d8de53d | 577 | }else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 578 | } |
klauss | 13:ae278302dffe | 579 | |
klauss | 10:22da1a0ac1e1 | 580 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 0:4d17cd9c8f9d | 581 | |
klauss | 0:4d17cd9c8f9d | 582 | static uint8_t flag = 0; |
klauss | 0:4d17cd9c8f9d | 583 | if( v_call->size() == 0 ){ |
klauss | 0:4d17cd9c8f9d | 584 | if (flag == 0) { flag = 1; } |
klauss | 0:4d17cd9c8f9d | 585 | ts->reset(); |
klauss | 49:4837ed2aad6b | 586 | }else{ |
klauss | 0:4d17cd9c8f9d | 587 | if (flag == 1) { flag = 0; } |
klauss | 0:4d17cd9c8f9d | 588 | } |
klauss | 33:735fd60e96d8 | 589 | |
klauss | 45:c80574f24dc3 | 590 | /* |
klauss | 40:990683572031 | 591 | int length; |
klauss | 33:735fd60e96d8 | 592 | if( udp_timer.read() > 1 && !listen_udp ){ |
klauss | 40:990683572031 | 593 | data = (uint8_t *)listen_eth_udp( (char *)buffer, &length ); |
klauss | 33:735fd60e96d8 | 594 | if( length ){ |
klauss | 33:735fd60e96d8 | 595 | listen_udp = true; |
klauss | 33:735fd60e96d8 | 596 | debug_msg(""); |
klauss | 33:735fd60e96d8 | 597 | }else udp_timer.reset(); |
klauss | 33:735fd60e96d8 | 598 | } |
klauss | 33:735fd60e96d8 | 599 | if( listen_udp ){ |
klauss | 40:990683572031 | 600 | data = (uint8_t *)listen_eth_udp( (char *)buffer, &length ); |
klauss | 33:735fd60e96d8 | 601 | if( udp_timer.read() > 30 ){ |
klauss | 33:735fd60e96d8 | 602 | listen_udp = false; |
klauss | 33:735fd60e96d8 | 603 | udp_timer.reset(); |
klauss | 33:735fd60e96d8 | 604 | } |
klauss | 33:735fd60e96d8 | 605 | } |
klauss | 45:c80574f24dc3 | 606 | */ |
klauss | 30:8dfb6d8de53d | 607 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 608 | } |
klauss | 0:4d17cd9c8f9d | 609 | } |