![](/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@72:895ca792c647, 2014-11-19 (annotated)
- Committer:
- klauss
- Date:
- Wed Nov 19 13:36:33 2014 +0000
- Revision:
- 72:895ca792c647
- Parent:
- 71:757fa1ef37c6
- Child:
- 74:81c47fff88a5
send_to_cbx | send2callbox under development -- antes de modularizar melhor o src.
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 | 71:757fa1ef37c6 | 286 | static int test_ext = 5010; |
klauss | 71:757fa1ef37c6 | 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 | 71:757fa1ef37c6 | 326 | ext = test_ext++; |
klauss | 71:757fa1ef37c6 | 327 | port = test_port++; |
klauss | 68:b54993674190 | 328 | //type = __REGISTRY__; |
klauss | 71:757fa1ef37c6 | 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 | 71:757fa1ef37c6 | 340 | main_test = false;*/ |
klauss | 71:757fa1ef37c6 | 341 | Call_Box * cb = new Call_Box( ext, port ); |
klauss | 71:757fa1ef37c6 | 342 | if( cb != NULL ){ |
klauss | 71:757fa1ef37c6 | 343 | v_cb->add( cb ); |
klauss | 71:757fa1ef37c6 | 344 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 71:757fa1ef37c6 | 345 | VZ_call * call = new VZ_call( ext, port, 913, 10112 ); |
klauss | 71:757fa1ef37c6 | 346 | v_call->add( call ); |
klauss | 71:757fa1ef37c6 | 347 | } |
klauss | 46:a670f187a704 | 348 | } |
klauss | 53:bb492a8f115a | 349 | |
klauss | 48:195c97f12e8e | 350 | /* |
klauss | 46:a670f187a704 | 351 | if( count == 5 * 2 ){ |
klauss | 46:a670f187a704 | 352 | //debug_msg("Colocar simulacoes de cbx aqui"); |
klauss | 46:a670f187a704 | 353 | data = buffer; |
klauss | 46:a670f187a704 | 354 | ext = 891; |
klauss | 46:a670f187a704 | 355 | port = 5001; |
klauss | 46:a670f187a704 | 356 | type = __INVITE__; |
klauss | 46:a670f187a704 | 357 | debug_msg("registro enviado"); |
klauss | 45:c80574f24dc3 | 358 | }*/ |
klauss | 0:4d17cd9c8f9d | 359 | } |
klauss | 0:4d17cd9c8f9d | 360 | //---------------------- |
klauss | 0:4d17cd9c8f9d | 361 | switch( type ){ |
klauss | 0:4d17cd9c8f9d | 362 | case __DO_NOTHING__ :{} |
klauss | 0:4d17cd9c8f9d | 363 | break; |
klauss | 0:4d17cd9c8f9d | 364 | |
klauss | 0:4d17cd9c8f9d | 365 | case __CB_BYE__ : { |
klauss | 63:0d95da692bb4 | 366 | cb_bye_counter++; |
klauss | 0:4d17cd9c8f9d | 367 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 368 | if( cb != NULL ){ |
klauss | 0:4d17cd9c8f9d | 369 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 370 | cb->set_msg_id( data[ 0 ] ); |
klauss | 30:8dfb6d8de53d | 371 | if( debug_main ) debug_msg( " Request bye from CBx " ); |
klauss | 0:4d17cd9c8f9d | 372 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 373 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 374 | if( call->get_cb_ext() == ext ){ |
klauss | 4:de46f0d9b14d | 375 | cb->send_bye(); |
klauss | 0:4d17cd9c8f9d | 376 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 377 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 378 | set_status( cb->status, cb_idle ); |
klauss | 13:ae278302dffe | 379 | v_call->remove_element( i ); |
klauss | 13:ae278302dffe | 380 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 381 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 382 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 383 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 13:ae278302dffe | 384 | set_status( cb->sip->status, sip_idle ); |
klauss | 3:cd9148672e25 | 385 | delete( call ); |
klauss | 29:7246460b73f8 | 386 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 387 | } |
klauss | 0:4d17cd9c8f9d | 388 | } |
klauss | 0:4d17cd9c8f9d | 389 | } |
klauss | 7:019b08223b87 | 390 | }break; |
klauss | 7:019b08223b87 | 391 | |
klauss | 0:4d17cd9c8f9d | 392 | case __INVITE__ : { |
klauss | 63:0d95da692bb4 | 393 | invite_counter++; |
klauss | 30:8dfb6d8de53d | 394 | if( debug_main ) debug_msg("Request Invite received from Cbx %i", ext); |
klauss | 71:757fa1ef37c6 | 395 | /*procura pelo cbx usando como chave o ramal( ext ) - caso nao encontre, cria o objeto e coloca na logica*/ |
klauss | 0:4d17cd9c8f9d | 396 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 397 | if( cb == NULL ){ |
klauss | 31:bb5fb28a77df | 398 | if( debug_main ) debug_msg("Adding CBx :: %i", ext ); |
klauss | 0:4d17cd9c8f9d | 399 | cb = new Call_Box( ext, port ); |
klauss | 0:4d17cd9c8f9d | 400 | v_cb->add( cb ); |
klauss | 0:4d17cd9c8f9d | 401 | set_status( cb->status, cb_idle ); |
klauss | 0:4d17cd9c8f9d | 402 | cb->registry(); |
klauss | 0:4d17cd9c8f9d | 403 | } |
klauss | 13:ae278302dffe | 404 | cb->reset_elapsed_time(); |
klauss | 71:757fa1ef37c6 | 405 | /* restricao de que so podemos fazer 1 call por vez */ |
klauss | 71:757fa1ef37c6 | 406 | /* |
klauss | 71:757fa1ef37c6 | 407 | if( v_call->size() != 0 ){ |
klauss | 10:22da1a0ac1e1 | 408 | data[ 0 ] |= BIT7; |
klauss | 10:22da1a0ac1e1 | 409 | cb->set_msg_id( data[ 0 ] ); |
klauss | 10:22da1a0ac1e1 | 410 | set_status(cb->status,cb_idle); |
klauss | 10:22da1a0ac1e1 | 411 | cb->set_timeslice( 0x00 ); |
klauss | 10:22da1a0ac1e1 | 412 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 10:22da1a0ac1e1 | 413 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 10:22da1a0ac1e1 | 414 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 30:8dfb6d8de53d | 415 | if( debug_main ) debug_msg( "denying call - another call box on call" ); |
klauss | 10:22da1a0ac1e1 | 416 | break; |
klauss | 10:22da1a0ac1e1 | 417 | } |
klauss | 71:757fa1ef37c6 | 418 | */ |
klauss | 0:4d17cd9c8f9d | 419 | set_status( cb->status, cb_trying ); |
klauss | 30:8dfb6d8de53d | 420 | if( debug_main ) debug_msg("Request invite cbx status :: %d", cb->status ); |
klauss | 68:b54993674190 | 421 | //FIXMEj essa logica deve estar la embaixo, fora do switch maior, a ideia eh |
klauss | 32:43041f5e27c4 | 422 | // quando receber um pedido de invite, apenas manda o invite pro server |
klauss | 32:43041f5e27c4 | 423 | // dai rodar, ver se alguem mandou alguma coisa e voltar a tratar com o |
klauss | 32:43041f5e27c4 | 424 | // * ver se ja esta tudo ok, a ideia é fazer esse pedido de invite funcionar |
klauss | 32:43041f5e27c4 | 425 | // assincrono. |
klauss | 0:4d17cd9c8f9d | 426 | switch( cb->status ){ |
klauss | 0:4d17cd9c8f9d | 427 | case cb_on_call : { |
klauss | 0:4d17cd9c8f9d | 428 | // a priori, nao fazer nada |
klauss | 0:4d17cd9c8f9d | 429 | //data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 430 | //__send_to_cb__( __build_cb_package__( ext, port, __BYE__, |
klauss | 0:4d17cd9c8f9d | 431 | // ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 432 | }break; |
klauss | 0:4d17cd9c8f9d | 433 | |
klauss | 0:4d17cd9c8f9d | 434 | case cb_ringing : { |
klauss | 0:4d17cd9c8f9d | 435 | // tratar sip 2 |
klauss | 0:4d17cd9c8f9d | 436 | }break; |
klauss | 0:4d17cd9c8f9d | 437 | |
klauss | 0:4d17cd9c8f9d | 438 | case cb_trying : { |
klauss | 0:4d17cd9c8f9d | 439 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 440 | cb->set_msg_id( data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 441 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 442 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 443 | //sem timeslice pra tratar com o * |
klauss | 9:ffa64f38ef9c | 444 | set_status(cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 445 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 446 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 447 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 71:757fa1ef37c6 | 448 | set_status( cb->sip->status, sip_idle ); |
klauss | 31:bb5fb28a77df | 449 | if( debug_main ) debug_msg( "-- Trying -- without TS -- %s ", write_buffer ); |
klauss | 0:4d17cd9c8f9d | 450 | }else{ |
klauss | 0:4d17cd9c8f9d | 451 | set_status(cb->status,cb_busy); |
klauss | 0:4d17cd9c8f9d | 452 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 0:4d17cd9c8f9d | 453 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 454 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 455 | |
klauss | 31:bb5fb28a77df | 456 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 457 | |
klauss | 3:cd9148672e25 | 458 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 71:757fa1ef37c6 | 459 | |
klauss | 0:4d17cd9c8f9d | 460 | VZ_call * call = cb->invite(); |
klauss | 0:4d17cd9c8f9d | 461 | |
klauss | 0:4d17cd9c8f9d | 462 | if( call != NULL ){ |
klauss | 0:4d17cd9c8f9d | 463 | v_call->add( call ); |
klauss | 0:4d17cd9c8f9d | 464 | set_status(cb->status,cb_on_call); |
klauss | 0:4d17cd9c8f9d | 465 | |
klauss | 31:bb5fb28a77df | 466 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 467 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 468 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 31:bb5fb28a77df | 469 | if( debug_main ) debug_msg( "-- Trying -- accepting call request --" ); |
klauss | 0:4d17cd9c8f9d | 470 | }else{ |
klauss | 4:de46f0d9b14d | 471 | set_status( cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 472 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 473 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 474 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 31:bb5fb28a77df | 475 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 476 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 477 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 31:bb5fb28a77df | 478 | if( debug_main ) debug_msg( "-- Trying -- denying call request --" ); |
klauss | 13:ae278302dffe | 479 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 480 | } |
klauss | 0:4d17cd9c8f9d | 481 | } |
klauss | 4:de46f0d9b14d | 482 | }break; |
klauss | 0:4d17cd9c8f9d | 483 | case cb_busy : { |
klauss | 25:2cf5e8dd4035 | 484 | set_status( cb->status,cb_idle); |
klauss | 25:2cf5e8dd4035 | 485 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 25:2cf5e8dd4035 | 486 | cb->set_timeslice( 0x00 ); |
klauss | 25:2cf5e8dd4035 | 487 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 30:8dfb6d8de53d | 488 | if( debug_main ) debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 25:2cf5e8dd4035 | 489 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 25:2cf5e8dd4035 | 490 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 30:8dfb6d8de53d | 491 | if( debug_main ) debug_msg( "-- Trying -- denying call request << Busy Here >> --" ); |
klauss | 25:2cf5e8dd4035 | 492 | set_status( cb->sip->status, sip_idle ); |
klauss | 0:4d17cd9c8f9d | 493 | }break; |
klauss | 0:4d17cd9c8f9d | 494 | } |
klauss | 0:4d17cd9c8f9d | 495 | }break; |
klauss | 4:de46f0d9b14d | 496 | case __REGISTRY__ : { |
klauss | 63:0d95da692bb4 | 497 | registry_counter++; |
klauss | 4:de46f0d9b14d | 498 | Call_Box * cb = NULL; |
klauss | 2:93bec7313ccc | 499 | |
klauss | 4:de46f0d9b14d | 500 | data[ 0 ] |= BIT7 ; |
klauss | 4:de46f0d9b14d | 501 | cb = __find_CB__( v_cb, ext ); |
klauss | 4:de46f0d9b14d | 502 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 503 | cb->reset_elapsed_time(); |
klauss | 30:8dfb6d8de53d | 504 | if( debug_main ) debug_msg(" reset_elapsed_time CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 505 | }else{ |
klauss | 30:8dfb6d8de53d | 506 | if( debug_main ) debug_msg("Adding Cbx :: %d -- Type :: %d", ext, type ); |
klauss | 4:de46f0d9b14d | 507 | cb = new Call_Box( ext, port ); |
klauss | 4:de46f0d9b14d | 508 | v_cb->add( cb ); |
klauss | 30:8dfb6d8de53d | 509 | if( debug_main ) debug_msg("Added CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 510 | } |
klauss | 30:8dfb6d8de53d | 511 | if( debug_main ) debug_msg("::registered %d - %d::", ext, port ); |
klauss | 4:de46f0d9b14d | 512 | cb->registry(); |
klauss | 4:de46f0d9b14d | 513 | }break; |
klauss | 4:de46f0d9b14d | 514 | case __BOOT__ : { |
klauss | 63:0d95da692bb4 | 515 | boot_counter++; |
klauss | 4:de46f0d9b14d | 516 | __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 4:de46f0d9b14d | 517 | ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 518 | }break; |
klauss | 4:de46f0d9b14d | 519 | case __TELEMETRY__ : { |
klauss | 63:0d95da692bb4 | 520 | telemetry_counter++; |
klauss | 53:bb492a8f115a | 521 | if( debug_telemetry ) send_msg("::telemetry from %d - %d::", ext, port ); |
klauss | 53:bb492a8f115a | 522 | build_telemetry_report( ext, port, ( char *)data ); |
klauss | 4:de46f0d9b14d | 523 | }break; |
klauss | 36:728498a78e1e | 524 | |
klauss | 67:cdedc64d9921 | 525 | case __BOOTLOADER_CBX__ : { |
klauss | 67:cdedc64d9921 | 526 | bootloader_cbx_counter++; |
klauss | 67:cdedc64d9921 | 527 | int ret = bl_cbx_reply_to_eth( ext, ( char * )data ); |
klauss | 67:cdedc64d9921 | 528 | }break; |
klauss | 67:cdedc64d9921 | 529 | |
klauss | 36:728498a78e1e | 530 | case __PROMPT__ : { |
klauss | 63:0d95da692bb4 | 531 | prompt_counter++; |
klauss | 48:195c97f12e8e | 532 | send_msg( "Prompt pkg from ( %i, %i ) ::", ext, port ); |
klauss | 48:195c97f12e8e | 533 | /* |
klauss | 48:195c97f12e8e | 534 | if( tcp_session ){ // udp ? |
klauss | 48:195c97f12e8e | 535 | char tmp[ 255 ]; |
klauss | 48:195c97f12e8e | 536 | sprintf( tmp, "Prompt pkg from ( %i, %i ) :: ", ext, port ); |
klauss | 48:195c97f12e8e | 537 | tcp_client.send_all( tmp, strlen( tmp ) ); |
klauss | 48:195c97f12e8e | 538 | } |
klauss | 48:195c97f12e8e | 539 | */ |
klauss | 62:07e5bdc9f8f7 | 540 | for( register int i = 0; i < 32; i++ ){ |
klauss | 36:728498a78e1e | 541 | pc.printf("%3i ", data[ i ] ); |
klauss | 62:07e5bdc9f8f7 | 542 | if( i == 15 ) pc.printf( "\r\n" ); |
klauss | 48:195c97f12e8e | 543 | } |
klauss | 62:07e5bdc9f8f7 | 544 | pc.printf("\n\r> "); |
klauss | 48:195c97f12e8e | 545 | |
klauss | 48:195c97f12e8e | 546 | if( tcp_session ){ |
klauss | 48:195c97f12e8e | 547 | char aux[ __CB_BUFFER_SIZE__ + 3 ]; |
klauss | 48:195c97f12e8e | 548 | strncpy( aux, (char * )data, __CB_BUFFER_SIZE__ ); |
klauss | 48:195c97f12e8e | 549 | strcat( aux, "\n\r\0" ); |
klauss | 48:195c97f12e8e | 550 | tcp_client.send_all( ( char *)data, strlen( (char * )data ) ); |
klauss | 62:07e5bdc9f8f7 | 551 | tcp_client.send_all( "\r\n> ", strlen( "\r\n> " ) ); |
klauss | 48:195c97f12e8e | 552 | } |
klauss | 36:728498a78e1e | 553 | }break; |
klauss | 0:4d17cd9c8f9d | 554 | case __AUDIO__ : { |
klauss | 63:0d95da692bb4 | 555 | audio_counter++; |
klauss | 0:4d17cd9c8f9d | 556 | Call_Box * cb; |
klauss | 0:4d17cd9c8f9d | 557 | VZ_call * call = NULL; |
klauss | 0:4d17cd9c8f9d | 558 | cb = NULL; |
klauss | 0:4d17cd9c8f9d | 559 | call = __find_Call__( v_call, ext ); |
klauss | 0:4d17cd9c8f9d | 560 | if( call != NULL ){ |
klauss | 30:8dfb6d8de53d | 561 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 0:4d17cd9c8f9d | 562 | call->send_message( pkg ); |
klauss | 0:4d17cd9c8f9d | 563 | cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 564 | if( cb != NULL ) cb->reset_elapsed_time(); |
klauss | 18:01a93677e40c | 565 | }else{ |
klauss | 30:8dfb6d8de53d | 566 | if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 567 | } |
klauss | 0:4d17cd9c8f9d | 568 | }break; |
klauss | 9:ffa64f38ef9c | 569 | }// fim switch |
klauss | 0:4d17cd9c8f9d | 570 | for( register int i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 571 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 572 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 573 | char * tmp = call->get_eth_message( &length ); |
klauss | 0:4d17cd9c8f9d | 574 | if( tmp != NULL ){ |
klauss | 0:4d17cd9c8f9d | 575 | Call_Box * cb = NULL; |
klauss | 0:4d17cd9c8f9d | 576 | int cb_port = 0xffff; |
klauss | 0:4d17cd9c8f9d | 577 | cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 4:de46f0d9b14d | 578 | |
klauss | 4:de46f0d9b14d | 579 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 580 | cb_port = cb->get_port(); |
klauss | 30:8dfb6d8de53d | 581 | }else if( debug_main ) debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 4:de46f0d9b14d | 582 | |
klauss | 0:4d17cd9c8f9d | 583 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 0:4d17cd9c8f9d | 584 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 4:de46f0d9b14d | 585 | |
klauss | 0:4d17cd9c8f9d | 586 | __send_to_cb__( pkg2cb ); |
klauss | 0:4d17cd9c8f9d | 587 | } |
klauss | 14:22a35f575502 | 588 | } |
klauss | 28:94aec56c6329 | 589 | if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 4:de46f0d9b14d | 590 | |
klauss | 70:714c33487aae | 591 | int ret = sip_manager( v_cb ); |
klauss | 0:4d17cd9c8f9d | 592 | if( ret > 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 593 | Call_Box * cb = __find_CB__( v_cb, ret ); |
klauss | 4:de46f0d9b14d | 594 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 595 | if( cb->status == cb_on_call ){ |
klauss | 4:de46f0d9b14d | 596 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 597 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 598 | set_status(cb->status,cb_idle); |
klauss | 4:de46f0d9b14d | 599 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 4:de46f0d9b14d | 600 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 4:de46f0d9b14d | 601 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 4:de46f0d9b14d | 602 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 4:de46f0d9b14d | 603 | if( call->get_cb_ext() == ret ){ |
klauss | 4:de46f0d9b14d | 604 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 605 | delete( call ); |
klauss | 4:de46f0d9b14d | 606 | } |
klauss | 2:93bec7313ccc | 607 | } |
klauss | 4:de46f0d9b14d | 608 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 4:de46f0d9b14d | 609 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 68:b54993674190 | 610 | //FIXMEj talvez eu nao precise dessa linha mudar o set_status( cb->sip->status, sip_idle ); pra ver o que acontece |
klauss | 38:af5ecd6997ab | 611 | //cb->reset_sip(); |
klauss | 13:ae278302dffe | 612 | set_status( cb->sip->status, sip_idle ); |
klauss | 29:7246460b73f8 | 613 | cb->re_start_timer(); |
klauss | 0:4d17cd9c8f9d | 614 | } |
klauss | 30:8dfb6d8de53d | 615 | }else if( debug_main ) debug_msg("Missed bye request from * CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 616 | } |
klauss | 13:ae278302dffe | 617 | |
klauss | 10:22da1a0ac1e1 | 618 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 0:4d17cd9c8f9d | 619 | |
klauss | 71:757fa1ef37c6 | 620 | /* |
klauss | 0:4d17cd9c8f9d | 621 | static uint8_t flag = 0; |
klauss | 0:4d17cd9c8f9d | 622 | if( v_call->size() == 0 ){ |
klauss | 0:4d17cd9c8f9d | 623 | if (flag == 0) { flag = 1; } |
klauss | 0:4d17cd9c8f9d | 624 | ts->reset(); |
klauss | 49:4837ed2aad6b | 625 | }else{ |
klauss | 0:4d17cd9c8f9d | 626 | if (flag == 1) { flag = 0; } |
klauss | 0:4d17cd9c8f9d | 627 | } |
klauss | 71:757fa1ef37c6 | 628 | */ |
klauss | 67:cdedc64d9921 | 629 | |
klauss | 67:cdedc64d9921 | 630 | bl_handler(); |
klauss | 72:895ca792c647 | 631 | tx_buffer_ring_buffer_handler(); |
klauss | 33:735fd60e96d8 | 632 | |
klauss | 30:8dfb6d8de53d | 633 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 634 | } |
klauss | 0:4d17cd9c8f9d | 635 | } |