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