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