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