voltando a versao de n aberturas e fechamentos de sockets
Dependencies: EthernetInterface NTPClient mbed-rtos_old mbed
Fork of header_main_public by
main.cpp@7:019b08223b87, 2014-09-13 (annotated)
- Committer:
- klauss
- Date:
- Sat Sep 13 19:21:48 2014 +0000
- Revision:
- 7:019b08223b87
- Parent:
- 6:a10de9926fbe
- Child:
- 8:e3bfe62a477e
testando estabilidade do embarcado
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" |
klauss | 0:4d17cd9c8f9d | 6 | |
klauss | 0:4d17cd9c8f9d | 7 | #include "debug.h" |
klauss | 0:4d17cd9c8f9d | 8 | #include "utils.h" |
klauss | 0:4d17cd9c8f9d | 9 | |
klauss | 7:019b08223b87 | 10 | //#define debug_telos |
klauss | 7:019b08223b87 | 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 | bool debug_bool = true; |
klauss | 0:4d17cd9c8f9d | 28 | |
klauss | 0:4d17cd9c8f9d | 29 | int main(){ |
klauss | 0:4d17cd9c8f9d | 30 | start_cpld(); |
klauss | 0:4d17cd9c8f9d | 31 | config_lpc(); |
klauss | 0:4d17cd9c8f9d | 32 | |
klauss | 0:4d17cd9c8f9d | 33 | /* referencia e inicio da conexao com a ethernet */ |
klauss | 0:4d17cd9c8f9d | 34 | EthernetInterface eth; |
klauss | 0:4d17cd9c8f9d | 35 | __init_eth__( ð ); |
klauss | 0:4d17cd9c8f9d | 36 | |
klauss | 0:4d17cd9c8f9d | 37 | /* debugs */ |
klauss | 2:93bec7313ccc | 38 | // debug_server.set_address( "192.168.120.144", 9897 ); |
klauss | 2:93bec7313ccc | 39 | // debug.bind( 72133 ); |
klauss | 2:93bec7313ccc | 40 | // debug.init(); |
klauss | 0:4d17cd9c8f9d | 41 | |
klauss | 0:4d17cd9c8f9d | 42 | Timer t; |
klauss | 0:4d17cd9c8f9d | 43 | t.start(); |
klauss | 0:4d17cd9c8f9d | 44 | |
klauss | 0:4d17cd9c8f9d | 45 | /* representa ramal do call box */ |
klauss | 0:4d17cd9c8f9d | 46 | int ext = 0; |
klauss | 0:4d17cd9c8f9d | 47 | |
klauss | 0:4d17cd9c8f9d | 48 | /* representa porta do call box */ |
klauss | 0:4d17cd9c8f9d | 49 | int port = 0; |
klauss | 0:4d17cd9c8f9d | 50 | |
klauss | 0:4d17cd9c8f9d | 51 | /* buffer para onde se copia os dados vindos do cb para tratameno interno */ |
klauss | 0:4d17cd9c8f9d | 52 | uint8_t buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 53 | |
klauss | 0:4d17cd9c8f9d | 54 | /* buffer de escrita do pacote de saida que sera enviado pro cb / servidor */ |
klauss | 0:4d17cd9c8f9d | 55 | uint8_t write_buffer[ __CB_BUFFER_SIZE__ ]; |
klauss | 0:4d17cd9c8f9d | 56 | |
klauss | 0:4d17cd9c8f9d | 57 | /* ponteiro que aponta para os dados vindo do CPLD */ |
klauss | 0:4d17cd9c8f9d | 58 | uint8_t * buffer_from_cb_ptr = ( uint8_t * )RXBuffer; |
klauss | 0:4d17cd9c8f9d | 59 | |
klauss | 0:4d17cd9c8f9d | 60 | /* referencia para os dados contidos no pacote, sem o header */ |
klauss | 0:4d17cd9c8f9d | 61 | uint8_t * data = NULL; |
klauss | 0:4d17cd9c8f9d | 62 | |
klauss | 0:4d17cd9c8f9d | 63 | /* gerencia o tipo do pacote para providenciar tratamento adequado */ |
klauss | 0:4d17cd9c8f9d | 64 | volatile uint8_t type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 65 | |
klauss | 0:4d17cd9c8f9d | 66 | /* representa a lista dos Call Boxes atualmente reconhecidos pela cabeceira */ |
klauss | 0:4d17cd9c8f9d | 67 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 68 | |
klauss | 0:4d17cd9c8f9d | 69 | /* representa a lista de ligacoes ativas na cabeceira */ |
klauss | 0:4d17cd9c8f9d | 70 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 71 | |
klauss | 0:4d17cd9c8f9d | 72 | /* gerencia a distribuicao de timeslice para os call boxes */ |
klauss | 0:4d17cd9c8f9d | 73 | Timeslice * ts = new Timeslice(); |
klauss | 0:4d17cd9c8f9d | 74 | |
klauss | 0:4d17cd9c8f9d | 75 | /* tenta instanciar o vetor de call boxes, acende o led 1 antes de encerrar o programa */ |
klauss | 0:4d17cd9c8f9d | 76 | reset_leds(); |
klauss | 0:4d17cd9c8f9d | 77 | if( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 78 | led1 = 0; |
klauss | 0:4d17cd9c8f9d | 79 | while( v_cb == NULL ){ |
klauss | 0:4d17cd9c8f9d | 80 | Vector * v_cb = new Vector(); |
klauss | 0:4d17cd9c8f9d | 81 | led1 = led1; |
klauss | 0:4d17cd9c8f9d | 82 | if( t.read() > 5 ){ |
klauss | 0:4d17cd9c8f9d | 83 | debug_msg("Erro ao alocar o vetor de CBx"); |
klauss | 0:4d17cd9c8f9d | 84 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 85 | } |
klauss | 0:4d17cd9c8f9d | 86 | } |
klauss | 0:4d17cd9c8f9d | 87 | }else if( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 88 | led2 = 0; |
klauss | 0:4d17cd9c8f9d | 89 | led1 = 1; |
klauss | 0:4d17cd9c8f9d | 90 | while( v_call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 91 | Vector * v_call = new Vector(); |
klauss | 0:4d17cd9c8f9d | 92 | led1 = led1; |
klauss | 0:4d17cd9c8f9d | 93 | if( t.read() > 5 ){ |
klauss | 0:4d17cd9c8f9d | 94 | debug_msg("Erro ao alocar o vetor de Calls"); |
klauss | 0:4d17cd9c8f9d | 95 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 96 | } |
klauss | 0:4d17cd9c8f9d | 97 | } |
klauss | 0:4d17cd9c8f9d | 98 | } |
klauss | 0:4d17cd9c8f9d | 99 | reset_leds(); |
klauss | 0:4d17cd9c8f9d | 100 | debug_msg( " Ready " ); |
klauss | 1:a1758104fa1d | 101 | while( true ){ |
klauss | 0:4d17cd9c8f9d | 102 | if( status != __WAITING__ ){ |
klauss | 0:4d17cd9c8f9d | 103 | __read_cb_buffer__( buffer, buffer_from_cb_ptr ); |
klauss | 0:4d17cd9c8f9d | 104 | status = __WAITING__; |
klauss | 0:4d17cd9c8f9d | 105 | |
klauss | 0:4d17cd9c8f9d | 106 | data = __parse_cb_buffer__( &ext, &port, &type, buffer ); |
klauss | 0:4d17cd9c8f9d | 107 | |
klauss | 3:cd9148672e25 | 108 | if( data != NULL ){ |
klauss | 7:019b08223b87 | 109 | //if( type == __CB_BYE__ ){ |
klauss | 7:019b08223b87 | 110 | // debug_msg("--> %s <--", buffer); |
klauss | 7:019b08223b87 | 111 | //} |
klauss | 7:019b08223b87 | 112 | //debug_msg("Procurando pelo CBx :: %d -- Type :: %d", ext, type ); |
klauss | 7:019b08223b87 | 113 | if( type != __AUDIO__ ){ |
klauss | 7:019b08223b87 | 114 | #ifdef debug_telos |
klauss | 7:019b08223b87 | 115 | debug_msg(""); |
klauss | 7:019b08223b87 | 116 | debug_32( data ); |
klauss | 7:019b08223b87 | 117 | debug_msg(""); |
klauss | 7:019b08223b87 | 118 | __send_to_cb__( buffer ); |
klauss | 7:019b08223b87 | 119 | debug_msg(""); |
klauss | 7:019b08223b87 | 120 | type = __DO_NOTHING__; |
klauss | 7:019b08223b87 | 121 | debug_msg(""); |
klauss | 7:019b08223b87 | 122 | continue; |
klauss | 7:019b08223b87 | 123 | debug_msg(""); |
klauss | 0:4d17cd9c8f9d | 124 | } |
klauss | 7:019b08223b87 | 125 | #endif |
klauss | 7:019b08223b87 | 126 | #ifndef debug_telos |
klauss | 0:4d17cd9c8f9d | 127 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 128 | if( cb != NULL ){ |
klauss | 3:cd9148672e25 | 129 | cb->reset_elapsed_time(); |
klauss | 0:4d17cd9c8f9d | 130 | if( ( data[ 0 ] ^ cb->get_msg_id() ) == BIT7 ){ |
klauss | 0:4d17cd9c8f9d | 131 | // some pkg reply |
klauss | 0:4d17cd9c8f9d | 132 | if( ( data[ 0 ] | BIT7 ) == cb->get_msg_id() ){ |
klauss | 7:019b08223b87 | 133 | if( type == __BOOT__ ) type = __REGISTRY__; |
klauss | 0:4d17cd9c8f9d | 134 | __send_to_cb__( __build_cb_package__( ext, port, type, |
klauss | 0:4d17cd9c8f9d | 135 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 136 | type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 137 | debug_msg("-- Renviado ultimo pkg --"); |
klauss | 0:4d17cd9c8f9d | 138 | }else if( data[ 0 ] == ( cb->get_msg_id() | BIT7 ) ){ |
klauss | 0:4d17cd9c8f9d | 139 | // ack from CBx |
klauss | 3:cd9148672e25 | 140 | debug_msg("-- ACK do meu pkg --"); |
klauss | 0:4d17cd9c8f9d | 141 | type = __DO_NOTHING__; |
klauss | 7:019b08223b87 | 142 | cb->reset_elapsed_time(); |
klauss | 7:019b08223b87 | 143 | if( type == __REGISTRY__ ) cb->set_msg_id( cb->get_msg_id() + 10 ); |
klauss | 0:4d17cd9c8f9d | 144 | } |
klauss | 0:4d17cd9c8f9d | 145 | } |
klauss | 0:4d17cd9c8f9d | 146 | } |
klauss | 0:4d17cd9c8f9d | 147 | } |
klauss | 7:019b08223b87 | 148 | #endif |
klauss | 0:4d17cd9c8f9d | 149 | }else type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 150 | } |
klauss | 2:93bec7313ccc | 151 | //---------------------- |
klauss | 0:4d17cd9c8f9d | 152 | if( t.read() > 5 ){ |
klauss | 0:4d17cd9c8f9d | 153 | for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 154 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 155 | 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 | 156 | } |
klauss | 0:4d17cd9c8f9d | 157 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 158 | led3 = !led3; |
klauss | 0:4d17cd9c8f9d | 159 | } |
klauss | 0:4d17cd9c8f9d | 160 | //---------------------- |
klauss | 0:4d17cd9c8f9d | 161 | switch( type ){ |
klauss | 0:4d17cd9c8f9d | 162 | case __DO_NOTHING__ :{} |
klauss | 0:4d17cd9c8f9d | 163 | break; |
klauss | 0:4d17cd9c8f9d | 164 | |
klauss | 0:4d17cd9c8f9d | 165 | case __CB_BYE__ : { |
klauss | 0:4d17cd9c8f9d | 166 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 167 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 168 | debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 169 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 170 | cb->set_msg_id( data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 171 | debug_msg( " Request bye from CBx " ); |
klauss | 0:4d17cd9c8f9d | 172 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 173 | VZ_call * call = (VZ_call *)v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 174 | if( call->get_cb_ext() == ext ){ |
klauss | 4:de46f0d9b14d | 175 | cb->send_bye(); |
klauss | 0:4d17cd9c8f9d | 176 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 177 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 178 | set_status( cb->status, cb_idle ); |
klauss | 4:de46f0d9b14d | 179 | v_call->remove_element( i ); |
klauss | 0:4d17cd9c8f9d | 180 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 181 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 182 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 183 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 184 | set_status( cb->sip->status, sip_idle ); |
klauss | 3:cd9148672e25 | 185 | delete( call ); |
klauss | 0:4d17cd9c8f9d | 186 | } |
klauss | 0:4d17cd9c8f9d | 187 | } |
klauss | 0:4d17cd9c8f9d | 188 | } |
klauss | 7:019b08223b87 | 189 | }break; |
klauss | 7:019b08223b87 | 190 | |
klauss | 0:4d17cd9c8f9d | 191 | case __INVITE__ : { |
klauss | 1:a1758104fa1d | 192 | debug_msg("ok -- recebido o invite pelo menos"); |
klauss | 0:4d17cd9c8f9d | 193 | Call_Box * cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 194 | if( cb == NULL ){ |
klauss | 4:de46f0d9b14d | 195 | debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 196 | cb = new Call_Box( ext, port ); |
klauss | 0:4d17cd9c8f9d | 197 | v_cb->add( cb ); |
klauss | 0:4d17cd9c8f9d | 198 | set_status( cb->status, cb_idle ); |
klauss | 0:4d17cd9c8f9d | 199 | cb->registry(); |
klauss | 0:4d17cd9c8f9d | 200 | } |
klauss | 0:4d17cd9c8f9d | 201 | cb->reset_elapsed_time(); |
klauss | 0:4d17cd9c8f9d | 202 | set_status( cb->status, cb_trying ); |
klauss | 0:4d17cd9c8f9d | 203 | debug_msg(" Ok temos um cbx encontrado com status :: %d", cb->status ); |
klauss | 0:4d17cd9c8f9d | 204 | switch( cb->status ){ |
klauss | 0:4d17cd9c8f9d | 205 | case cb_on_call : { |
klauss | 0:4d17cd9c8f9d | 206 | // a priori, nao fazer nada |
klauss | 0:4d17cd9c8f9d | 207 | //data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 208 | //__send_to_cb__( __build_cb_package__( ext, port, __BYE__, |
klauss | 0:4d17cd9c8f9d | 209 | // ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 210 | }break; |
klauss | 0:4d17cd9c8f9d | 211 | |
klauss | 0:4d17cd9c8f9d | 212 | case cb_ringing : { |
klauss | 0:4d17cd9c8f9d | 213 | // tratar sip 2 |
klauss | 0:4d17cd9c8f9d | 214 | }break; |
klauss | 0:4d17cd9c8f9d | 215 | |
klauss | 0:4d17cd9c8f9d | 216 | case cb_trying : { |
klauss | 0:4d17cd9c8f9d | 217 | data[ 0 ] |= BIT7; |
klauss | 0:4d17cd9c8f9d | 218 | cb->set_msg_id( data[ 0 ] ); |
klauss | 0:4d17cd9c8f9d | 219 | cb->set_timeslice( ts->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 220 | if( cb->get_timeslice() == 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 221 | //sem timeslice pra tratar com o * |
klauss | 0:4d17cd9c8f9d | 222 | set_status(cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 223 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 224 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 225 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 226 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 227 | debug_msg( "-- Trying -- Sem TS -- %s ", write_buffer ); |
klauss | 0:4d17cd9c8f9d | 228 | }else{ |
klauss | 0:4d17cd9c8f9d | 229 | set_status(cb->status,cb_busy); |
klauss | 0:4d17cd9c8f9d | 230 | data[ __TIMESLICE_PLACE__ ] = cb->get_timeslice(); |
klauss | 0:4d17cd9c8f9d | 231 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 232 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 233 | |
klauss | 0:4d17cd9c8f9d | 234 | debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 235 | |
klauss | 3:cd9148672e25 | 236 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 0:4d17cd9c8f9d | 237 | VZ_call * call = cb->invite(); |
klauss | 0:4d17cd9c8f9d | 238 | |
klauss | 0:4d17cd9c8f9d | 239 | if( call != NULL ){ |
klauss | 0:4d17cd9c8f9d | 240 | v_call->add( call ); |
klauss | 0:4d17cd9c8f9d | 241 | set_status(cb->status,cb_on_call); |
klauss | 0:4d17cd9c8f9d | 242 | |
klauss | 0:4d17cd9c8f9d | 243 | debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 244 | __send_to_cb__( __build_cb_package__( ext, port, __INVITE__, |
klauss | 0:4d17cd9c8f9d | 245 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 246 | debug_msg( "-- Trying -- aceitando pedido de invite -- %s ", write_buffer ); |
klauss | 0:4d17cd9c8f9d | 247 | //debug_pkg( 300, write_buffer ); |
klauss | 0:4d17cd9c8f9d | 248 | }else{ |
klauss | 4:de46f0d9b14d | 249 | set_status( cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 250 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 251 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 252 | data[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 0:4d17cd9c8f9d | 253 | debug_msg(" -- %d on %d -- ", cb->get_ext(), data[ __TIMESLICE_PLACE__ ] ); |
klauss | 0:4d17cd9c8f9d | 254 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 0:4d17cd9c8f9d | 255 | ( char * )data, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 0:4d17cd9c8f9d | 256 | debug_msg( "-- Trying -- Negando pedido de invite -- %s ", write_buffer ); |
klauss | 0:4d17cd9c8f9d | 257 | set_status( cb->sip->status, sip_idle); |
klauss | 0:4d17cd9c8f9d | 258 | } |
klauss | 0:4d17cd9c8f9d | 259 | } |
klauss | 4:de46f0d9b14d | 260 | }break; |
klauss | 0:4d17cd9c8f9d | 261 | case cb_busy : { |
klauss | 0:4d17cd9c8f9d | 262 | // tratar sip |
klauss | 0:4d17cd9c8f9d | 263 | }break; |
klauss | 0:4d17cd9c8f9d | 264 | } |
klauss | 0:4d17cd9c8f9d | 265 | }break; |
klauss | 4:de46f0d9b14d | 266 | case __REGISTRY__ : { |
klauss | 4:de46f0d9b14d | 267 | Call_Box * cb = NULL; |
klauss | 2:93bec7313ccc | 268 | |
klauss | 4:de46f0d9b14d | 269 | data[ 0 ] |= BIT7 ; |
klauss | 4:de46f0d9b14d | 270 | cb = __find_CB__( v_cb, ext ); |
klauss | 4:de46f0d9b14d | 271 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 272 | cb->reset_elapsed_time(); |
klauss | 4:de46f0d9b14d | 273 | debug_msg(" reset_elapsed_time CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 274 | }else{ |
klauss | 4:de46f0d9b14d | 275 | debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 4:de46f0d9b14d | 276 | cb = new Call_Box( ext, port ); |
klauss | 4:de46f0d9b14d | 277 | v_cb->add( cb ); |
klauss | 4:de46f0d9b14d | 278 | debug_msg(" Criado CBx -- %d", ext ); |
klauss | 0:4d17cd9c8f9d | 279 | } |
klauss | 4:de46f0d9b14d | 280 | debug_msg("::Registrado %d - %d::", ext, port ); |
klauss | 4:de46f0d9b14d | 281 | cb->registry(); |
klauss | 4:de46f0d9b14d | 282 | }break; |
klauss | 4:de46f0d9b14d | 283 | case __BOOT__ : { |
klauss | 4:de46f0d9b14d | 284 | __send_to_cb__( __build_cb_package__( ext, port, __REGISTRY__, |
klauss | 4:de46f0d9b14d | 285 | ( char * )data, data[ 0 ], __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 286 | }break; |
klauss | 4:de46f0d9b14d | 287 | case __TELEMETRY__ : { |
klauss | 4:de46f0d9b14d | 288 | debug_msg("Leitura da bateria :: ( Id : %x, MSB : %x, LSB : %x )", data[ 0 ], data[ 1 ], data[ 2 ] ); |
klauss | 4:de46f0d9b14d | 289 | }break; |
klauss | 0:4d17cd9c8f9d | 290 | case __AUDIO__ : { |
klauss | 0:4d17cd9c8f9d | 291 | Call_Box * cb; |
klauss | 0:4d17cd9c8f9d | 292 | VZ_call * call = NULL; |
klauss | 0:4d17cd9c8f9d | 293 | cb = NULL; |
klauss | 0:4d17cd9c8f9d | 294 | call = __find_Call__( v_call, ext ); |
klauss | 0:4d17cd9c8f9d | 295 | if( call != NULL ){ |
klauss | 0:4d17cd9c8f9d | 296 | //debug_( 240, data ); |
klauss | 0:4d17cd9c8f9d | 297 | //debug_pkg( 242, data ); |
klauss | 0:4d17cd9c8f9d | 298 | //char * pkg = call->build_eth_package( oitocentos ); |
klauss | 0:4d17cd9c8f9d | 299 | //char * pkg = call->build_eth_package( data ); |
klauss | 0:4d17cd9c8f9d | 300 | char * pkg = call->build_eth_package( data + 2 ); |
klauss | 0:4d17cd9c8f9d | 301 | call->send_message( pkg ); |
klauss | 0:4d17cd9c8f9d | 302 | cb = __find_CB__( v_cb, ext ); |
klauss | 0:4d17cd9c8f9d | 303 | if( cb != NULL ) cb->reset_elapsed_time(); |
klauss | 4:de46f0d9b14d | 304 | }else{ |
klauss | 4:de46f0d9b14d | 305 | debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 306 | } |
klauss | 0:4d17cd9c8f9d | 307 | }break; |
klauss | 0:4d17cd9c8f9d | 308 | }// fim switch |
klauss | 7:019b08223b87 | 309 | #ifndef debug_telos |
klauss | 0:4d17cd9c8f9d | 310 | for( register int i = 0; i < v_call->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 311 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 312 | int length = 0; |
klauss | 0:4d17cd9c8f9d | 313 | char * tmp = call->get_eth_message( &length ); |
klauss | 0:4d17cd9c8f9d | 314 | if( tmp != NULL ){ |
klauss | 0:4d17cd9c8f9d | 315 | Call_Box * cb = NULL; |
klauss | 0:4d17cd9c8f9d | 316 | int cb_port = 0xffff; |
klauss | 0:4d17cd9c8f9d | 317 | cb = __find_CB__( v_cb, call->get_cb_ext() ); |
klauss | 4:de46f0d9b14d | 318 | |
klauss | 4:de46f0d9b14d | 319 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 320 | cb_port = cb->get_port(); |
klauss | 4:de46f0d9b14d | 321 | }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 4:de46f0d9b14d | 322 | |
klauss | 0:4d17cd9c8f9d | 323 | uint8_t * pkg2cb = __build_cb_package__( call->get_cb_ext(), cb_port, __AUDIO__, |
klauss | 0:4d17cd9c8f9d | 324 | tmp, __AUDIO__, length, write_buffer ); |
klauss | 4:de46f0d9b14d | 325 | |
klauss | 0:4d17cd9c8f9d | 326 | __send_to_cb__( pkg2cb ); |
klauss | 0:4d17cd9c8f9d | 327 | } |
klauss | 0:4d17cd9c8f9d | 328 | } |
klauss | 7:019b08223b87 | 329 | #endif |
klauss | 0:4d17cd9c8f9d | 330 | //nessa funcao eu deveria me registar a cada 2 min por exemplo |
klauss | 0:4d17cd9c8f9d | 331 | registry_aging( v_cb, data, write_buffer ); |
klauss | 4:de46f0d9b14d | 332 | |
klauss | 0:4d17cd9c8f9d | 333 | int ret = sip_manager( v_cb, v_call, write_buffer ); |
klauss | 0:4d17cd9c8f9d | 334 | if( ret > 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 335 | Call_Box * cb = __find_CB__( v_cb, ret ); |
klauss | 4:de46f0d9b14d | 336 | if( cb != NULL ){ |
klauss | 4:de46f0d9b14d | 337 | if( cb->status == cb_on_call ){ |
klauss | 4:de46f0d9b14d | 338 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 4:de46f0d9b14d | 339 | cb->set_timeslice( 0x00 ); |
klauss | 4:de46f0d9b14d | 340 | set_status(cb->status,cb_idle); |
klauss | 4:de46f0d9b14d | 341 | buffer[ __TIMESLICE_PLACE__ ] = 0x00; |
klauss | 4:de46f0d9b14d | 342 | cb->set_msg_id( ( ( cb->get_msg_id() ) + 1 ) & ( BIT7 ^ 0xff ) ); |
klauss | 4:de46f0d9b14d | 343 | for( register uint8_t i = 0; i < v_call->size(); i++ ){ |
klauss | 4:de46f0d9b14d | 344 | VZ_call * call = ( VZ_call * )v_call->get_element( i ); |
klauss | 4:de46f0d9b14d | 345 | if( call->get_cb_ext() == ret ){ |
klauss | 4:de46f0d9b14d | 346 | v_call->remove_element( i ); |
klauss | 4:de46f0d9b14d | 347 | delete( call ); |
klauss | 4:de46f0d9b14d | 348 | } |
klauss | 2:93bec7313ccc | 349 | } |
klauss | 4:de46f0d9b14d | 350 | __send_to_cb__( __build_cb_package__( ext, port, __CB_BYE__, |
klauss | 4:de46f0d9b14d | 351 | ( char * )buffer, cb->get_msg_id(), __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) ); |
klauss | 4:de46f0d9b14d | 352 | cb->reset_sip(); |
klauss | 4:de46f0d9b14d | 353 | set_status( cb->sip->status, sip_idle ); |
klauss | 0:4d17cd9c8f9d | 354 | } |
klauss | 4:de46f0d9b14d | 355 | }else debug_msg("Nao encontrado CBx :: %d -- Type :: %d", ext, type ); |
klauss | 0:4d17cd9c8f9d | 356 | } |
klauss | 4:de46f0d9b14d | 357 | |
klauss | 0:4d17cd9c8f9d | 358 | call_manager( v_call, v_cb, data, write_buffer, ts ); |
klauss | 0:4d17cd9c8f9d | 359 | |
klauss | 0:4d17cd9c8f9d | 360 | static uint8_t flag = 0; |
klauss | 0:4d17cd9c8f9d | 361 | if( v_call->size() == 0 ){ |
klauss | 0:4d17cd9c8f9d | 362 | if (flag == 0) { flag = 1; } |
klauss | 0:4d17cd9c8f9d | 363 | ts->reset(); |
klauss | 0:4d17cd9c8f9d | 364 | }else { |
klauss | 0:4d17cd9c8f9d | 365 | if (flag == 1) { flag = 0; } |
klauss | 0:4d17cd9c8f9d | 366 | } |
klauss | 0:4d17cd9c8f9d | 367 | /* eu deveria tirar ts que nao constam em chamadas aqui */ |
klauss | 4:de46f0d9b14d | 368 | /* for( register uint8_t i = 0; i < v_cb->size(); i++ ){ |
klauss | 0:4d17cd9c8f9d | 369 | Call_Box * cb = ( Call_Box * )v_cb->get_element( i ); |
klauss | 0:4d17cd9c8f9d | 370 | if( cb->get_timeslice() != 0x00 ){ |
klauss | 0:4d17cd9c8f9d | 371 | VZ_call * call = __find_Call__( v_call, cb->get_ext() ); |
klauss | 0:4d17cd9c8f9d | 372 | if( call == NULL ){ |
klauss | 0:4d17cd9c8f9d | 373 | ts->return_timeslice( cb->get_timeslice() ); |
klauss | 0:4d17cd9c8f9d | 374 | cb->set_timeslice( 0x00 ); |
klauss | 0:4d17cd9c8f9d | 375 | set_status(cb->status,cb_idle); |
klauss | 0:4d17cd9c8f9d | 376 | } |
klauss | 0:4d17cd9c8f9d | 377 | } |
klauss | 0:4d17cd9c8f9d | 378 | } |
klauss | 4:de46f0d9b14d | 379 | */ type = __DO_NOTHING__; |
klauss | 0:4d17cd9c8f9d | 380 | } |
klauss | 0:4d17cd9c8f9d | 381 | } |