![](/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@28:94aec56c6329, 2014-09-23 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 23 18:28:37 2014 +0000
- Revision:
- 28:94aec56c6329
- Parent:
- 27:98f824719d1c
- Child:
- 29:7246460b73f8
- peet ext and my ext setable from prompt
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 | 18:01a93677e40c | 7 | |
klauss | 0:4d17cd9c8f9d | 8 | #include "debug.h" |
klauss | 0:4d17cd9c8f9d | 9 | #include "utils.h" |
Cola | 21:0bd688722e81 | 10 | #include "flood.h" |
klauss | 0:4d17cd9c8f9d | 11 | |
klauss | 0:4d17cd9c8f9d | 12 | /* |
klauss | 0:4d17cd9c8f9d | 13 | #define set_status(a,b) _set_status(a,b) |
klauss | 0:4d17cd9c8f9d | 14 | #define _set_status(a,b) { \ |
klauss | 0:4d17cd9c8f9d | 15 | a = b; \ |
klauss | 0:4d17cd9c8f9d | 16 | sprintf( debug_msg, "-- State == %d -- Line %d", a, __LINE__ ); \ |
klauss | 0:4d17cd9c8f9d | 17 | debug.sendTo( debug_server, debug_msg, strlen( debug_msg ) ); \ |
klauss | 0:4d17cd9c8f9d | 18 | } |
klauss | 0:4d17cd9c8f9d | 19 | #define whereami() _whereami() |
klauss | 0:4d17cd9c8f9d | 20 | #define _whereami() { \ |
klauss | 0:4d17cd9c8f9d | 21 | sprintf( debug_msg, "-- whereami %d", __LINE__ ); \ |
klauss | 0:4d17cd9c8f9d | 22 | debug.sendTo( debug_server, debug_msg, strlen( debug_msg ) ); \ |
klauss | 0:4d17cd9c8f9d | 23 | } |
klauss | 0:4d17cd9c8f9d | 24 | */ |
klauss | 0:4d17cd9c8f9d | 25 | volatile uint8_t status = 0x00; |
klauss | 0:4d17cd9c8f9d | 26 | |
klauss | 0:4d17cd9c8f9d | 27 | int main(){ |
klauss | 0:4d17cd9c8f9d | 28 | start_cpld(); |
klauss | 0:4d17cd9c8f9d | 29 | config_lpc(); |
klauss | 0:4d17cd9c8f9d | 30 | |
klauss | 0:4d17cd9c8f9d | 31 | /* referencia e inicio da conexao com a ethernet */ |
klauss | 0:4d17cd9c8f9d | 32 | EthernetInterface eth; |
klauss | 13:ae278302dffe | 33 | |
klauss | 9:ffa64f38ef9c | 34 | int eth_status = __init_eth__( ð ); |
klauss | 9:ffa64f38ef9c | 35 | |
Cola | 20:2d6ab23956e5 | 36 | |
klauss | 8:e3bfe62a477e | 37 | if( eth_status ){ |
klauss | 18:01a93677e40c | 38 | debug_msg("Sem conexao eth"); |
klauss | 8:e3bfe62a477e | 39 | } |
klauss | 0:4d17cd9c8f9d | 40 | |
klauss | 0:4d17cd9c8f9d | 41 | /* debugs */ |
klauss | 2:93bec7313ccc | 42 | // debug_server.set_address( "192.168.120.144", 9897 ); |
klauss | 2:93bec7313ccc | 43 | // debug.bind( 72133 ); |
klauss | 2:93bec7313ccc | 44 | // debug.init(); |
klauss | 0:4d17cd9c8f9d | 45 | |
klauss | 0:4d17cd9c8f9d | 46 | Timer t; |
klauss | 0:4d17cd9c8f9d | 47 | t.start(); |
klauss | 0:4d17cd9c8f9d | 48 | |
klauss | 0:4d17cd9c8f9d | 49 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 50 | int ext = 0; |
klauss | 0:4d17cd9c8f9d | 51 | |
klauss | 0:4d17cd9c8f9d | 52 | /* representa porta do call box */ |
klauss | 0:4d17cd9c8f9d | 53 | int port = 0; |
klauss | 0:4d17cd9c8f9d | 54 | |
klauss | 0:4d17cd9c8f9d | 55 | /* buffer para onde se copia os dados vindos do cb para tratameno interno */ |
klauss | 0:4d17cd9c8f9d | 56 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 57 | |
klauss | 0:4d17cd9c8f9d | 58 | /* buffer de escrita do pacote de saida que sera enviado pro cb / servidor */ |
klauss | 0:4d17cd9c8f9d | 59 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 60 | |
klauss | 0:4d17cd9c8f9d | 61 | /* ponteiro que aponta para os dados vindo do CPLD */ |
klauss | 0:4d17cd9c8f9d | 62 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 0:4d17cd9c8f9d | 63 | |
klauss | 0:4d17cd9c8f9d | 64 | /* referencia para os dados contidos no pacote, sem o header */ |
klauss | 0:4d17cd9c8f9d | 65 | uint8_t * data = NULL; |
klauss | 0:4d17cd9c8f9d | 66 | |
klauss | 0:4d17cd9c8f9d | 67 | /* gerencia o tipo do pacote para providenciar tratamento adequado */ |
klauss | 0:4d17cd9c8f9d | 68 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 69 | |
klauss | 0:4d17cd9c8f9d | 70 | /* representa a lista dos Call Boxes atualmente reconhecidos pela cabeceira */ |
klauss | 0:4d17cd9c8f9d | 71 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 72 | |
klauss | 0:4d17cd9c8f9d | 73 | /* representa a lista de ligacoes ativas na cabeceira */ |
klauss | 0:4d17cd9c8f9d | 74 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 75 | |
klauss | 0:4d17cd9c8f9d | 76 | /* gerencia a distribuicao de timeslice para os call boxes */ |
klauss | 0:4d17cd9c8f9d | 77 | Timeslice * ts = new Timeslice(); |
klauss | 0:4d17cd9c8f9d | 78 | |
klauss | 0:4d17cd9c8f9d | 79 | /* tenta instanciar o vetor de call boxes, acende o led 1 antes de encerrar o programa */ |
klauss | 0:4d17cd9c8f9d | 80 | reset_leds(); |
klauss | 0:4d17cd9c8f9d | 81 | if( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 82 | led1 = 0; |
klauss | 0:4d17cd9c8f9d | 83 | while( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 84 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 85 | led1 = led1; |
klauss | 0:4d17cd9c8f9d | 86 | if( t.read() > 5 ){ |
klauss | 0:4d17cd9c8f9d | 87 | debug_msg("Erro ao alocar o vetor de CBx"); |
klauss | 0:4d17cd9c8f9d | 88 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 89 | } |
klauss | 0:4d17cd9c8f9d | 90 | } |
klauss | 0:4d17cd9c8f9d | 91 | }else if( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 92 | led2 = 0; |
klauss | 0:4d17cd9c8f9d | 93 | led1 = 1; |
klauss | 0:4d17cd9c8f9d | 94 | while( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 95 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 96 | led1 = led1; |
klauss | 0:4d17cd9c8f9d | 97 | if( t.read() > 5 ){ |
klauss | 0:4d17cd9c8f9d | 98 | debug_msg("Erro ao alocar o vetor de Calls"); |
klauss | 0:4d17cd9c8f9d | 99 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 100 | } |
klauss | 0:4d17cd9c8f9d | 101 | } |
klauss | 0:4d17cd9c8f9d | 102 | } |
klauss | 0:4d17cd9c8f9d | 103 | reset_leds(); |
klauss | 26:725cbbedadd5 | 104 | init_fsystem(); |
klauss | 0:4d17cd9c8f9d | 105 | debug_msg( " Ready " ); |
Cola | 21:0bd688722e81 | 106 | |
Cola | 21:0bd688722e81 | 107 | while( true ){ |
Cola | 21:0bd688722e81 | 108 | prompt_process(); |
Cola | 21:0bd688722e81 | 109 | |
Cola | 22:d2a4b5939115 | 110 | if (pcks_s == 1){ |
Cola | 24:270b436a1bb0 | 111 | pc.printf("\n\r PKG_CSK OK: %d", pkg_cksok); |
Cola | 24:270b436a1bb0 | 112 | pc.printf("\n\r PKG_CSK ERR: %d\n\r", pkg_ckserr); |
Cola | 24:270b436a1bb0 | 113 | pcks_s =0; |
Cola | 24:270b436a1bb0 | 114 | } |
Cola | 24:270b436a1bb0 | 115 | |
Cola | 24:270b436a1bb0 | 116 | if (pshowcb == 1){ |
Cola | 24:270b436a1bb0 | 117 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
Cola | 24:270b436a1bb0 | 118 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
Cola | 24:270b436a1bb0 | 119 | debug_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 ); |
Cola | 24:270b436a1bb0 | 120 | pshowcb = 0; |
Cola | 24:270b436a1bb0 | 121 | } |
Cola | 22:d2a4b5939115 | 122 | } |
Cola | 22:d2a4b5939115 | 123 | |
Cola | 21:0bd688722e81 | 124 | if (pflood == 1) flood(); |
Cola | 21:0bd688722e81 | 125 | |
Cola | 21:0bd688722e81 | 126 | |
klauss | 0:4d17cd9c8f9d | 127 | if( status != __WAITING__ ){ |
klauss | 0:4d17cd9c8f9d | 128 | __read_cb_buffer__( buffer, buffer_from_cb_ptr ); |
klauss | 0:4d17cd9c8f9d | 129 | status = __WAITING__; |
klauss | 0:4d17cd9c8f9d | 130 | |
klauss | 0:4d17cd9c8f9d | 131 | data = __parse_cb_buffer__( &ext, &port, &type, buffer ); |
klauss | 0:4d17cd9c8f9d | 132 | |
klauss | 3:cd9148672e25 | 133 | if( data != NULL ){ |
klauss | 25:2cf5e8dd4035 | 134 | if (debug_alive == 1) debug_msg("Pkg from CBx :: %d -- Type :: %d", ext, type ); |
klauss | 7:019b08223b87 | 135 | if( type != __AUDIO__ ){ |
klauss | 0:4d17cd9c8f9d | 136 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 137 | if( cb != NULL ){ |
klauss | 3:cd9148672e25 | 138 | cb->reset_elapsed_time(); |
klauss | 0:4d17cd9c8f9d | 139 | if( ( data[ 0 ] ^ cb->get_msg_id() ) == BIT7 ){ |
klauss | 0:4d17cd9c8f9d | 140 | // some pkg reply |
klauss | 0:4d17cd9c8f9d | 141 | if( ( data[ 0 ] | BIT7 ) == cb->get_msg_id() ){ |
klauss | 7:019b08223b87 | 142 | if( type == __BOOT__ ) type = __REGISTRY__; |
klauss | 0:4d17cd9c8f9d | 143 | __send_to_cb__( __build_cb_package__( ext, port, type, |
klauss | 0:4d17cd9c8f9d | 144 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 145 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 146 | debug_msg("-- Renviado ultimo pkg --"); |
klauss | 0:4d17cd9c8f9d | 147 | }else if( data[ 0 ] == ( cb->get_msg_id() | BIT7 ) ){ |
klauss | 0:4d17cd9c8f9d | 148 | // ack from CBx |
klauss | 3:cd9148672e25 | 149 | debug_msg("-- ACK do meu pkg --"); |
klauss | 0:4d17cd9c8f9d | 150 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 151 | } |
klauss | 0:4d17cd9c8f9d | 152 | } |
klauss | 0:4d17cd9c8f9d | 153 | } |
klauss | 0:4d17cd9c8f9d | 154 | } |
klauss | 0:4d17cd9c8f9d | 155 | }else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 156 | } |
klauss | 2:93bec7313ccc | 157 | //---------------------- |
klauss | 27:98f824719d1c | 158 | if( t.read() > 5 ){ |
klauss | 27:98f824719d1c | 159 | static int count = 0; |
klauss | 18:01a93677e40c | 160 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 18:01a93677e40c | 161 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
Cola | 21:0bd688722e81 | 162 | if (debug_alive){debug_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 | 0:4d17cd9c8f9d | 163 | } |
Cola | 22:d2a4b5939115 | 164 | |
Cola | 21:0bd688722e81 | 165 | if (debug_alive == 1){ |
Cola | 23:4a6d631a6298 | 166 | debug_msg("Status - alive "); |
Cola | 21:0bd688722e81 | 167 | //uint32_t errper = 100*(pkg_ckserr/(pkg_ckserr + pkg_cksok)); |
Cola | 21:0bd688722e81 | 168 | //pc.printf("\n\r Error = %d", errper); |
Cola | 21:0bd688722e81 | 169 | } |
klauss | 0:4d17cd9c8f9d | 170 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 171 | led3 = !led3; |
Cola | 22:d2a4b5939115 | 172 | CAB_LED = !CAB_LED; |
klauss | 27:98f824719d1c | 173 | |
klauss | 28:94aec56c6329 | 174 | if( test_debug ){ |
klauss | 28:94aec56c6329 | 175 | if( count == 8 ){ |
klauss | 28:94aec56c6329 | 176 | Call_Box * cb = new Call_Box( ext, port ); |
klauss | 28:94aec56c6329 | 177 | cb->registry(); |
klauss | 28:94aec56c6329 | 178 | } |
klauss | 28:94aec56c6329 | 179 | count++; |
klauss | 27:98f824719d1c | 180 | } |
klauss | 0:4d17cd9c8f9d | 181 | } |
klauss | 0:4d17cd9c8f9d | 182 | //---------------------- |
klauss | 0:4d17cd9c8f9d | 183 | switch( type ){ |
klauss | 0:4d17cd9c8f9d | 184 | case __DO_NOTHING__ :{} |
klauss | 0:4d17cd9c8f9d | 185 | break; |
klauss | 0:4d17cd9c8f9d | 186 | |
klauss | 0:4d17cd9c8f9d | 187 | case __CB_BYE__ : { |
klauss | 0:4d17cd9c8f9d | 188 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 189 | if( cb != NULL ){ |
klauss | 0:4d17cd9c8f9d | 190 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 191 | cb->set_msg_id( data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 192 | debug_msg( " Request bye from CBx " ); |
klauss | 0:4d17cd9c8f9d | 193 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 194 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 195 | if( call->get_cb_ext() == ext ){ |
klauss | 4:de46f0d9b14d | 196 | cb->send_bye(); |
klauss | 0:4d17cd9c8f9d | 197 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 198 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 199 | set_status( cb->status, cb_idle ); |
klauss | 13:ae278302dffe | 200 | v_call->remove_element( i ); |
klauss | 13:ae278302dffe | 201 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 202 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 203 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 204 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 13:ae278302dffe | 205 | set_status( cb->sip->status, sip_idle ); |
klauss | 3:cd9148672e25 | 206 | delete( call ); |
klauss | 0:4d17cd9c8f9d | 207 | } |
klauss | 0:4d17cd9c8f9d | 208 | } |
klauss | 0:4d17cd9c8f9d | 209 | } |
klauss | 7:019b08223b87 | 210 | }break; |
klauss | 7:019b08223b87 | 211 | |
klauss | 0:4d17cd9c8f9d | 212 | case __INVITE__ : { |
klauss | 13:ae278302dffe | 213 | debug_msg("ok -- recebido o invite pelo menos"); |
klauss | 0:4d17cd9c8f9d | 214 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 215 | if( cb == NULL ){ |
klauss | 18:01a93677e40c | 216 | debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 217 | cb = new Call_Box( ext, port ); |
klauss | 0:4d17cd9c8f9d | 218 | v_cb->add( cb ); |
klauss | 0:4d17cd9c8f9d | 219 | set_status( cb->status, cb_idle ); |
klauss | 0:4d17cd9c8f9d | 220 | cb->registry(); |
klauss | 0:4d17cd9c8f9d | 221 | } |
klauss | 13:ae278302dffe | 222 | cb->reset_elapsed_time(); |
klauss | 10:22da1a0ac1e1 | 223 | if( v_call->size() != 0 ){ |
klauss | 10:22da1a0ac1e1 | 224 | data[ 0 ] |= BIT7; |
klauss | 10:22da1a0ac1e1 | 225 | cb->set_msg_id( data[ 0 ] ); |
klauss | 10:22da1a0ac1e1 | 226 | set_status(cb->status,cb_idle); |
klauss | 10:22da1a0ac1e1 | 227 | cb->set_timeslice( 0x00 ); |
klauss | 10:22da1a0ac1e1 | 228 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 10:22da1a0ac1e1 | 229 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 10:22da1a0ac1e1 | 230 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 10:22da1a0ac1e1 | 231 | debug_msg( "-- Negando chamada, uma ja em andamento -- " ); |
klauss | 10:22da1a0ac1e1 | 232 | break; |
klauss | 10:22da1a0ac1e1 | 233 | } |
klauss | 0:4d17cd9c8f9d | 234 | set_status( cb->status, cb_trying ); |
klauss | 25:2cf5e8dd4035 | 235 | debug_msg("Request invite cbx status :: %d", cb->status ); |
klauss | 0:4d17cd9c8f9d | 236 | switch( cb->status ){ |
klauss | 0:4d17cd9c8f9d | 237 | case cb_on_call : { |
klauss | 0:4d17cd9c8f9d | 238 | // a priori, nao fazer nada |
klauss | 0:4d17cd9c8f9d | 239 | //data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 240 | //__send_to_cb__( __build_cb_package__( ext, port, __BYE__, |
klauss | 0:4d17cd9c8f9d | 241 | // ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 242 | }break; |
klauss | 0:4d17cd9c8f9d | 243 | |
klauss | 0:4d17cd9c8f9d | 244 | case cb_ringing : { |
klauss | 0:4d17cd9c8f9d | 245 | // tratar sip 2 |
klauss | 0:4d17cd9c8f9d | 246 | }break; |
klauss | 0:4d17cd9c8f9d | 247 | |
klauss | 0:4d17cd9c8f9d | 248 | case cb_trying : { |
klauss | 0:4d17cd9c8f9d | 249 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 250 | cb->set_msg_id( data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 251 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 252 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 253 | //sem timeslice pra tratar com o * |
klauss | 9:ffa64f38ef9c | 254 | set_status(cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 255 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 256 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 257 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 13:ae278302dffe | 258 | set_status( cb->sip->status, sip_idle); |
klauss | 13:ae278302dffe | 259 | debug_msg( "-- Trying -- Sem TS -- %s ", write_buffer ); |
klauss | 0:4d17cd9c8f9d | 260 | }else{ |
klauss | 0:4d17cd9c8f9d | 261 | set_status(cb->status,cb_busy); |
klauss | 0:4d17cd9c8f9d | 262 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 0:4d17cd9c8f9d | 263 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 264 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 265 | |
klauss | 0:4d17cd9c8f9d | 266 | debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 267 | |
klauss | 3:cd9148672e25 | 268 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 0:4d17cd9c8f9d | 269 | VZ_call * call = cb->invite(); |
klauss | 0:4d17cd9c8f9d | 270 | |
klauss | 0:4d17cd9c8f9d | 271 | if( call != NULL ){ |
klauss | 0:4d17cd9c8f9d | 272 | v_call->add( call ); |
klauss | 0:4d17cd9c8f9d | 273 | set_status(cb->status,cb_on_call); |
klauss | 0:4d17cd9c8f9d | 274 | |
klauss | 0:4d17cd9c8f9d | 275 | debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 276 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 277 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 18:01a93677e40c | 278 | debug_msg( "-- Trying -- aceitando pedido de invite -- %s ", write_buffer ); |
klauss | 0:4d17cd9c8f9d | 279 | //debug_pkg( 300, write_buffer ); |
klauss | 0:4d17cd9c8f9d | 280 | }else{ |
klauss | 4:de46f0d9b14d | 281 | set_status( cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 282 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 283 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 284 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 285 | debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 286 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 287 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 18:01a93677e40c | 288 | debug_msg( "-- Trying -- Negando pedido de invite -- %s ", write_buffer ); |
klauss | 13:ae278302dffe | 289 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 290 | } |
klauss | 0:4d17cd9c8f9d | 291 | } |
klauss | 4:de46f0d9b14d | 292 | }break; |
klauss | 0:4d17cd9c8f9d | 293 | case cb_busy : { |
klauss | 25:2cf5e8dd4035 | 294 | set_status( cb->status,cb_idle); |
klauss | 25:2cf5e8dd4035 | 295 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 25:2cf5e8dd4035 | 296 | cb->set_timeslice( 0x00 ); |
klauss | 25:2cf5e8dd4035 | 297 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 25:2cf5e8dd4035 | 298 | debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 25:2cf5e8dd4035 | 299 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 25:2cf5e8dd4035 | 300 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 25:2cf5e8dd4035 | 301 | debug_msg( "-- Trying -- Negando pedido de invite << Busy Here >> --" ); |
klauss | 25:2cf5e8dd4035 | 302 | set_status( cb->sip->status, sip_idle ); |
klauss | 0:4d17cd9c8f9d | 303 | }break; |
klauss | 0:4d17cd9c8f9d | 304 | } |
klauss | 0:4d17cd9c8f9d | 305 | }break; |
klauss | 4:de46f0d9b14d | 306 | case __REGISTRY__ : { |
klauss | 4:de46f0d9b14d | 307 | Call_Box * cb = NULL; |
klauss | 2:93bec7313ccc | 308 | |
klauss | 4:de46f0d9b14d | 309 | data[ 0 ] |= BIT7 ; |
klauss | 4:de46f0d9b14d | 310 | cb = __find_CB__( v_cb, ext ); |
klauss | 4:de46f0d9b14d | 311 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 312 | cb->reset_elapsed_time(); |
klauss | 4:de46f0d9b14d | 313 | debug_msg(" reset_elapsed_time CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 314 | }else{ |
klauss | 18:01a93677e40c | 315 | debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 4:de46f0d9b14d | 316 | cb = new Call_Box( ext, port ); |
klauss | 4:de46f0d9b14d | 317 | v_cb->add( cb ); |
klauss | 4:de46f0d9b14d | 318 | debug_msg(" Criado CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 319 | } |
klauss | 4:de46f0d9b14d | 320 | debug_msg("::Registrado %d - %d::", ext, port ); |
klauss | 4:de46f0d9b14d | 321 | cb->registry(); |
klauss | 4:de46f0d9b14d | 322 | }break; |
klauss | 4:de46f0d9b14d | 323 | case __BOOT__ : { |
klauss | 4:de46f0d9b14d | 324 | __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 4:de46f0d9b14d | 325 | ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 326 | }break; |
klauss | 4:de46f0d9b14d | 327 | case __TELEMETRY__ : { |
klauss | 28:94aec56c6329 | 328 | pc.printf("Telemetry pkg from %i\n\r", ext ); |
klauss | 28:94aec56c6329 | 329 | for( register int i = 0; i < __TELEMETRY_SIZE__; i++ ) |
klauss | 28:94aec56c6329 | 330 | pc.printf("%x ", data[ i ]); |
klauss | 28:94aec56c6329 | 331 | pc.printf("\n\r"); |
klauss | 4:de46f0d9b14d | 332 | }break; |
klauss | 0:4d17cd9c8f9d | 333 | case __AUDIO__ : { |
klauss | 0:4d17cd9c8f9d | 334 | Call_Box * cb; |
klauss | 0:4d17cd9c8f9d | 335 | VZ_call * call = NULL; |
klauss | 0:4d17cd9c8f9d | 336 | cb = NULL; |
klauss | 0:4d17cd9c8f9d | 337 | call = __find_Call__( v_call, ext ); |
klauss | 0:4d17cd9c8f9d | 338 | if( call != NULL ){ |
klauss | 28:94aec56c6329 | 339 | char * pkg = call->build_eth_package( data ); |
klauss | 0:4d17cd9c8f9d | 340 | call->send_message( pkg ); |
klauss | 0:4d17cd9c8f9d | 341 | cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 342 | if( cb != NULL ) cb->reset_elapsed_time(); |
klauss | 18:01a93677e40c | 343 | }else{ |
klauss | 28:94aec56c6329 | 344 | debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 0:4d17cd9c8f9d | 345 | } |
klauss | 0:4d17cd9c8f9d | 346 | }break; |
klauss | 9:ffa64f38ef9c | 347 | }// fim switch |
klauss | 0:4d17cd9c8f9d | 348 | for( register int 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 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 351 | char * tmp = call->get_eth_message( &length ); |
klauss | 0:4d17cd9c8f9d | 352 | if( tmp != NULL ){ |
klauss | 0:4d17cd9c8f9d | 353 | Call_Box * cb = NULL; |
klauss | 0:4d17cd9c8f9d | 354 | int cb_port = 0xffff; |
klauss | 0:4d17cd9c8f9d | 355 | cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 4:de46f0d9b14d | 356 | |
klauss | 4:de46f0d9b14d | 357 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 358 | cb_port = cb->get_port(); |
klauss | 28:94aec56c6329 | 359 | }else debug_msg("received missed package from CBx :: %i -- Type :: %i", ext, type ); |
klauss | 4:de46f0d9b14d | 360 | |
klauss | 0:4d17cd9c8f9d | 361 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 0:4d17cd9c8f9d | 362 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 4:de46f0d9b14d | 363 | |
klauss | 0:4d17cd9c8f9d | 364 | __send_to_cb__( pkg2cb ); |
klauss | 0:4d17cd9c8f9d | 365 | } |
klauss | 14:22a35f575502 | 366 | } |
klauss | 15:9c7456c1b6f4 | 367 | ///debug_msg(""); |
klauss | 28:94aec56c6329 | 368 | if( v_call->size() == 0 ) registry_aging( v_cb, buffer, write_buffer ); |
klauss | 4:de46f0d9b14d | 369 | |
klauss | 0:4d17cd9c8f9d | 370 | int ret = sip_manager( v_cb, v_call, write_buffer ); |
klauss | 0:4d17cd9c8f9d | 371 | if( ret > 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 372 | Call_Box * cb = __find_CB__( v_cb, ret ); |
klauss | 4:de46f0d9b14d | 373 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 374 | if( cb->status == cb_on_call ){ |
klauss | 4:de46f0d9b14d | 375 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 376 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 377 | set_status(cb->status,cb_idle); |
klauss | 4:de46f0d9b14d | 378 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 4:de46f0d9b14d | 379 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 4:de46f0d9b14d | 380 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 4:de46f0d9b14d | 381 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 4:de46f0d9b14d | 382 | if( call->get_cb_ext() == ret ){ |
klauss | 4:de46f0d9b14d | 383 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 384 | delete( call ); |
klauss | 4:de46f0d9b14d | 385 | } |
klauss | 2:93bec7313ccc | 386 | } |
klauss | 4:de46f0d9b14d | 387 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 4:de46f0d9b14d | 388 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 389 | cb->reset_sip(); |
klauss | 13:ae278302dffe | 390 | set_status( cb->sip->status, sip_idle ); |
klauss | 0:4d17cd9c8f9d | 391 | } |
klauss | 18:01a93677e40c | 392 | }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 393 | } |
klauss | 13:ae278302dffe | 394 | |
klauss | 10:22da1a0ac1e1 | 395 | call_manager( v_call, v_cb, buffer, write_buffer, ts ); |
klauss | 0:4d17cd9c8f9d | 396 | |
klauss | 0:4d17cd9c8f9d | 397 | static uint8_t flag = 0; |
klauss | 0:4d17cd9c8f9d | 398 | if( v_call->size() == 0 ){ |
klauss | 0:4d17cd9c8f9d | 399 | if (flag == 0) { flag = 1; } |
klauss | 0:4d17cd9c8f9d | 400 | ts->reset(); |
klauss | 0:4d17cd9c8f9d | 401 | }else { |
klauss | 0:4d17cd9c8f9d | 402 | if (flag == 1) { flag = 0; } |
klauss | 0:4d17cd9c8f9d | 403 | } |
klauss | 0:4d17cd9c8f9d | 404 | /* eu deveria tirar ts que nao constam em chamadas aqui */ |
klauss | 13:ae278302dffe | 405 | /* for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 406 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 407 | if( cb->get_timeslice() != 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 408 | VZ_call * call = __find_Call__( v_call, cb->get_ext() ); |
klauss | 0:4d17cd9c8f9d | 409 | if( call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 410 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 411 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 412 | set_status(cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 413 | } |
klauss | 0:4d17cd9c8f9d | 414 | } |
klauss | 0:4d17cd9c8f9d | 415 | } |
klauss | 4:de46f0d9b14d | 416 | */ type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 417 | } |
klauss | 0:4d17cd9c8f9d | 418 | } |