![](/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
call_box.cpp@123:1d395b5a4cad, 2015-05-11 (annotated)
- Committer:
- klauss
- Date:
- Mon May 11 19:21:39 2015 +0000
- Revision:
- 123:1d395b5a4cad
- Parent:
- 122:480c44b0e205
- Child:
- 126:1f90756250fb
BUXFIX -- E00 - Limitar em 1500 o show_sip - Cria??o de rotina que atualiza timers de cada call_box para n?o ficar desatualizado.; -- Inclus?o da exibi??o do timer no comando "ls -lt" ou "ls -tl"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "call_box.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 121:ee02790d00b7 | 3 | Call_Box::Call_Box( const int ext, const int port ) |
klauss | 121:ee02790d00b7 | 4 | { |
klauss | 0:4d17cd9c8f9d | 5 | this->ext = ext; |
klauss | 0:4d17cd9c8f9d | 6 | this->port = port; |
klauss | 121:ee02790d00b7 | 7 | |
klauss | 121:ee02790d00b7 | 8 | t.start (); |
klauss | 4:de46f0d9b14d | 9 | msg_id = 0x10; |
klauss | 0:4d17cd9c8f9d | 10 | timeslice = 0x00; |
klauss | 0:4d17cd9c8f9d | 11 | status = cb_idle; |
klauss | 121:ee02790d00b7 | 12 | |
klauss | 121:ee02790d00b7 | 13 | { |
klauss | 121:ee02790d00b7 | 14 | shift_port = SHIFT_PORT; |
klauss | 121:ee02790d00b7 | 15 | |
klauss | 121:ee02790d00b7 | 16 | FILE * fp = NULL; |
klauss | 121:ee02790d00b7 | 17 | char inner_tmp[ 20 ]; |
klauss | 121:ee02790d00b7 | 18 | |
klauss | 121:ee02790d00b7 | 19 | fp = fopen( "/qspi/shift_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 20 | if( fp == NULL ) |
klauss | 121:ee02790d00b7 | 21 | { |
klauss | 121:ee02790d00b7 | 22 | if( debug_cb ) debug_msg("Failed to open /qspi/shift_port.txt" ); |
klauss | 121:ee02790d00b7 | 23 | shift_port = SHIFT_PORT; |
klauss | 121:ee02790d00b7 | 24 | }else{ |
klauss | 121:ee02790d00b7 | 25 | if( fread( (void *)inner_tmp, 1, 20, fp ) > 0 ){ |
klauss | 121:ee02790d00b7 | 26 | shift_port = atoi( inner_tmp ); |
klauss | 121:ee02790d00b7 | 27 | if( debug_cb ) debug_msg("Shift port %d", shift_port ); |
klauss | 121:ee02790d00b7 | 28 | }else{ |
klauss | 121:ee02790d00b7 | 29 | if( debug_cb ) debug_msg("Failed to read /qspi/shift_port.txt" ); |
klauss | 121:ee02790d00b7 | 30 | shift_port = SHIFT_PORT; |
klauss | 121:ee02790d00b7 | 31 | } |
klauss | 121:ee02790d00b7 | 32 | } |
klauss | 121:ee02790d00b7 | 33 | |
klauss | 121:ee02790d00b7 | 34 | fclose( fp ); |
klauss | 121:ee02790d00b7 | 35 | } |
klauss | 121:ee02790d00b7 | 36 | |
klauss | 121:ee02790d00b7 | 37 | sip = new Sip( ext, ext + shift_port ); |
klauss | 121:ee02790d00b7 | 38 | |
klauss | 121:ee02790d00b7 | 39 | if ( sip == NULL ) |
klauss | 89:0fe315117b00 | 40 | { |
klauss | 89:0fe315117b00 | 41 | memory_is_over = true; |
klauss | 121:ee02790d00b7 | 42 | if ( debug_memory ) debug_msg ("[%d] Sip allocation fail", this->ext ); |
klauss | 121:ee02790d00b7 | 43 | } else { |
klauss | 121:ee02790d00b7 | 44 | sip_socket_fd = sip->get_socket_fd (); |
klauss | 89:0fe315117b00 | 45 | } |
klauss | 87:679ee0d594a9 | 46 | |
klauss | 81:3656f00ab3db | 47 | invite_response = true; |
klauss | 81:3656f00ab3db | 48 | bye_response = true; |
klauss | 92:92df17f538a8 | 49 | invite_retry_count = MAX_INVITE_RETRY; |
klauss | 85:b6f2dc1d0f4f | 50 | cb_new_counter++; |
klauss | 119:ee6a53069455 | 51 | invite_try_number = 0; |
klauss | 121:ee02790d00b7 | 52 | overflow = false; |
klauss | 123:1d395b5a4cad | 53 | overflow_times = 0; |
klauss | 78:1353744f01e1 | 54 | } |
klauss | 78:1353744f01e1 | 55 | |
klauss | 121:ee02790d00b7 | 56 | int Call_Box::get_status ( void ) { return this->status; } |
klauss | 121:ee02790d00b7 | 57 | |
klauss | 121:ee02790d00b7 | 58 | void Call_Box::cb_set_status ( const uint8_t status ){ this->status = status; } |
klauss | 78:1353744f01e1 | 59 | |
klauss | 121:ee02790d00b7 | 60 | int Call_Box::get_sip_status ( void ) |
klauss | 121:ee02790d00b7 | 61 | { |
klauss | 121:ee02790d00b7 | 62 | if ( sip == NULL ) return ( -1 ); |
klauss | 78:1353744f01e1 | 63 | |
klauss | 121:ee02790d00b7 | 64 | return ( sip -> get_status () ); |
klauss | 0:4d17cd9c8f9d | 65 | } |
klauss | 0:4d17cd9c8f9d | 66 | |
klauss | 0:4d17cd9c8f9d | 67 | Call_Box::~Call_Box( void ){ |
klauss | 121:ee02790d00b7 | 68 | if ( sip != NULL ) delete ( sip ); |
klauss | 85:b6f2dc1d0f4f | 69 | cb_delete_counter++; |
klauss | 0:4d17cd9c8f9d | 70 | } |
klauss | 0:4d17cd9c8f9d | 71 | |
klauss | 121:ee02790d00b7 | 72 | int Call_Box::get_port ( void ) { return ( this->port ); } |
klauss | 119:ee6a53069455 | 73 | |
klauss | 121:ee02790d00b7 | 74 | int Call_Box::get_ext ( void ) { return ( this->ext ); } |
klauss | 0:4d17cd9c8f9d | 75 | |
klauss | 123:1d395b5a4cad | 76 | uint16_t Call_Box::get_elapsed_time ( void ) { return ( ( uint16_t ) this -> t.read_ms () ); } |
klauss | 0:4d17cd9c8f9d | 77 | |
klauss | 121:ee02790d00b7 | 78 | void Call_Box::reset_elapsed_time ( void ) |
klauss | 121:ee02790d00b7 | 79 | { |
klauss | 123:1d395b5a4cad | 80 | this -> t.stop (); |
klauss | 121:ee02790d00b7 | 81 | this -> t.reset (); |
klauss | 123:1d395b5a4cad | 82 | this -> t.start (); |
klauss | 123:1d395b5a4cad | 83 | overflow = false; |
klauss | 123:1d395b5a4cad | 84 | overflow_times = 0; |
klauss | 0:4d17cd9c8f9d | 85 | } |
klauss | 0:4d17cd9c8f9d | 86 | |
klauss | 121:ee02790d00b7 | 87 | void Call_Box::registry ( void ) |
klauss | 121:ee02790d00b7 | 88 | { |
klauss | 119:ee6a53069455 | 89 | if ( drop_registry_pkg ) |
klauss | 119:ee6a53069455 | 90 | { |
klauss | 121:ee02790d00b7 | 91 | send_msg ("[%d] Dropando registry pck", this->ext ); |
klauss | 119:ee6a53069455 | 92 | return; |
klauss | 119:ee6a53069455 | 93 | } |
klauss | 119:ee6a53069455 | 94 | |
klauss | 121:ee02790d00b7 | 95 | if ( this->sip != NULL ) |
klauss | 119:ee6a53069455 | 96 | { |
klauss | 121:ee02790d00b7 | 97 | if ( sip -> registry () > 0 ) |
klauss | 121:ee02790d00b7 | 98 | { |
klauss | 121:ee02790d00b7 | 99 | reset_elapsed_time (); |
klauss | 123:1d395b5a4cad | 100 | |
klauss | 121:ee02790d00b7 | 101 | } |
klauss | 123:1d395b5a4cad | 102 | if ( debug_aging ) send_msg ( "[%d] Registered", this->ext ); |
klauss | 119:ee6a53069455 | 103 | |
klauss | 119:ee6a53069455 | 104 | } else { |
klauss | 121:ee02790d00b7 | 105 | debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 106:a34fcf9f0e02 | 106 | deleted_sip++; |
klauss | 0:4d17cd9c8f9d | 107 | } |
klauss | 0:4d17cd9c8f9d | 108 | } |
klauss | 0:4d17cd9c8f9d | 109 | |
klauss | 119:ee6a53069455 | 110 | VZ_call * Call_Box::invite ( void ) |
klauss | 119:ee6a53069455 | 111 | { |
klauss | 29:7246460b73f8 | 112 | VZ_call * call = NULL; |
klauss | 29:7246460b73f8 | 113 | |
klauss | 121:ee02790d00b7 | 114 | if ( this->sip != NULL ) |
klauss | 119:ee6a53069455 | 115 | { |
klauss | 121:ee02790d00b7 | 116 | call = sip->invite (); |
klauss | 119:ee6a53069455 | 117 | } else { |
klauss | 121:ee02790d00b7 | 118 | debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 0:4d17cd9c8f9d | 119 | |
klauss | 119:ee6a53069455 | 120 | deleted_sip++; |
klauss | 0:4d17cd9c8f9d | 121 | } |
klauss | 29:7246460b73f8 | 122 | |
klauss | 121:ee02790d00b7 | 123 | if ( debug_cb ) send_msg ("[%d] Call returned value :: %p ", this->ext, ( void * ) call ); |
klauss | 123:1d395b5a4cad | 124 | |
klauss | 121:ee02790d00b7 | 125 | if ( call == NULL ) t.start (); |
klauss | 121:ee02790d00b7 | 126 | |
klauss | 121:ee02790d00b7 | 127 | return ( call ); |
klauss | 0:4d17cd9c8f9d | 128 | } |
klauss | 0:4d17cd9c8f9d | 129 | |
klauss | 0:4d17cd9c8f9d | 130 | /* Retorna |
klauss | 0:4d17cd9c8f9d | 131 | = 0 :: ok |
klauss | 0:4d17cd9c8f9d | 132 | < 0 :: tive problemas |
klauss | 0:4d17cd9c8f9d | 133 | > 0 :: devo remover essa call do vetor de calls |
klauss | 0:4d17cd9c8f9d | 134 | */ |
klauss | 121:ee02790d00b7 | 135 | int Call_Box::listen_SIP_server ( void ) |
klauss | 121:ee02790d00b7 | 136 | { |
klauss | 121:ee02790d00b7 | 137 | if ( this->sip == NULL ) |
klauss | 119:ee6a53069455 | 138 | { |
klauss | 121:ee02790d00b7 | 139 | debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 119:ee6a53069455 | 140 | |
klauss | 114:472502b31a12 | 141 | deleted_sip++; |
klauss | 119:ee6a53069455 | 142 | |
klauss | 119:ee6a53069455 | 143 | return ( -3 ); |
klauss | 119:ee6a53069455 | 144 | } else { |
klauss | 121:ee02790d00b7 | 145 | if ( status == cb_on_call || status == cb_idle ) |
klauss | 121:ee02790d00b7 | 146 | { |
klauss | 121:ee02790d00b7 | 147 | return ( sip -> listen_SIP_server () ); |
klauss | 119:ee6a53069455 | 148 | } else return ( 0 ); |
klauss | 0:4d17cd9c8f9d | 149 | } |
klauss | 0:4d17cd9c8f9d | 150 | } |
klauss | 0:4d17cd9c8f9d | 151 | |
klauss | 121:ee02790d00b7 | 152 | void Call_Box::set_msg_id ( const uint8_t msg_id ) { |
klauss | 78:1353744f01e1 | 153 | this->msg_id = ( msg_id > 0x10 ) ? msg_id : 0x11; |
klauss | 0:4d17cd9c8f9d | 154 | } |
klauss | 121:ee02790d00b7 | 155 | uint8_t Call_Box::get_msg_id ( void ) { return ( this->msg_id ); } |
klauss | 0:4d17cd9c8f9d | 156 | |
klauss | 121:ee02790d00b7 | 157 | void Call_Box::set_timeslice ( const uint8_t timeslice ) { |
klauss | 0:4d17cd9c8f9d | 158 | this->timeslice = timeslice; |
klauss | 0:4d17cd9c8f9d | 159 | } |
klauss | 121:ee02790d00b7 | 160 | |
klauss | 121:ee02790d00b7 | 161 | uint8_t Call_Box::get_timeslice ( void ) { return ( this->timeslice ); } |
klauss | 0:4d17cd9c8f9d | 162 | |
klauss | 121:ee02790d00b7 | 163 | void Call_Box::send_bye ( void ) |
klauss | 121:ee02790d00b7 | 164 | { |
klauss | 121:ee02790d00b7 | 165 | if ( this->sip == NULL ) |
klauss | 119:ee6a53069455 | 166 | { |
klauss | 121:ee02790d00b7 | 167 | debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 0:4d17cd9c8f9d | 168 | |
klauss | 119:ee6a53069455 | 169 | deleted_sip++; |
klauss | 119:ee6a53069455 | 170 | } else { |
klauss | 121:ee02790d00b7 | 171 | sip -> send_bye (); |
klauss | 0:4d17cd9c8f9d | 172 | } |
klauss | 1:a1758104fa1d | 173 | } |
klauss | 1:a1758104fa1d | 174 | |
klauss | 121:ee02790d00b7 | 175 | void Call_Box::reset_sip ( void ) |
klauss | 121:ee02790d00b7 | 176 | { |
klauss | 121:ee02790d00b7 | 177 | debug_msg ("[%d] reset_sip", this->ext ); |
klauss | 1:a1758104fa1d | 178 | |
klauss | 121:ee02790d00b7 | 179 | if ( this->sip != NULL ) |
klauss | 114:472502b31a12 | 180 | { |
klauss | 121:ee02790d00b7 | 181 | delete ( this->sip ); |
klauss | 121:ee02790d00b7 | 182 | debug_msg ("[%d] deletei", this->ext ); |
klauss | 114:472502b31a12 | 183 | } |
klauss | 114:472502b31a12 | 184 | |
klauss | 121:ee02790d00b7 | 185 | this->sip = new Sip ( ext, ext + shift_port ); |
klauss | 121:ee02790d00b7 | 186 | debug_msg ( "[%d ]sobrescrevi", this->ext ); |
klauss | 114:472502b31a12 | 187 | |
klauss | 106:a34fcf9f0e02 | 188 | deleted_sip++; |
klauss | 87:679ee0d594a9 | 189 | |
klauss | 121:ee02790d00b7 | 190 | if ( sip == NULL ) memory_is_over = true; |
klauss | 14:22a35f575502 | 191 | } |
klauss | 14:22a35f575502 | 192 | |
klauss | 121:ee02790d00b7 | 193 | void Call_Box::set_sip_status ( const uint8_t new_sip_status ) |
klauss | 121:ee02790d00b7 | 194 | { |
klauss | 121:ee02790d00b7 | 195 | if ( this->sip != NULL ) |
klauss | 121:ee02790d00b7 | 196 | { |
klauss | 121:ee02790d00b7 | 197 | this -> sip -> sip_set_status ( new_sip_status ); |
klauss | 121:ee02790d00b7 | 198 | } else |
klauss | 121:ee02790d00b7 | 199 | { |
klauss | 121:ee02790d00b7 | 200 | if ( debug_cb) debug_msg("[%d] Sip equals NULL o.O", this->ext ); |
klauss | 109:a5b8264ffbbc | 201 | deleted_sip++; |
klauss | 119:ee6a53069455 | 202 | debug_msg("[%d] Sip equals NULL o.O", this->ext ); |
klauss | 114:472502b31a12 | 203 | } |
klauss | 29:7246460b73f8 | 204 | } |
klauss | 29:7246460b73f8 | 205 | |
klauss | 119:ee6a53069455 | 206 | void Call_Box::set_invite_response_ok ( void ) |
klauss | 119:ee6a53069455 | 207 | { |
klauss | 121:ee02790d00b7 | 208 | this -> invite_response = true; |
klauss | 119:ee6a53069455 | 209 | if ( debug_invite ) send_msg ("[%d] Invite response :: ok", this->ext ); |
klauss | 81:3656f00ab3db | 210 | } |
klauss | 81:3656f00ab3db | 211 | |
klauss | 121:ee02790d00b7 | 212 | void Call_Box::set_invite_response_pending ( void ) { this->invite_response = false; } |
klauss | 117:e9facba9db27 | 213 | |
klauss | 121:ee02790d00b7 | 214 | bool Call_Box::get_invite_response ( void ) { return ( this->invite_response ); } |
klauss | 81:3656f00ab3db | 215 | |
klauss | 121:ee02790d00b7 | 216 | void Call_Box::invite_retry_count_reset ( void ) { invite_retry_count = MAX_INVITE_RETRY; } |
klauss | 117:e9facba9db27 | 217 | |
klauss | 119:ee6a53069455 | 218 | uint16_t Call_Box::get_invite_retry_count( void ){ |
klauss | 92:92df17f538a8 | 219 | return ( invite_retry_count ) ? invite_retry_count-- : 0; |
klauss | 92:92df17f538a8 | 220 | } |
klauss | 92:92df17f538a8 | 221 | |
klauss | 121:ee02790d00b7 | 222 | void Call_Box::set_bye_response_ok ( void ) { this->bye_response = true; } |
klauss | 119:ee6a53069455 | 223 | |
klauss | 121:ee02790d00b7 | 224 | void Call_Box::set_bye_response_pending ( void ) { this->bye_response = false; } |
klauss | 119:ee6a53069455 | 225 | |
klauss | 121:ee02790d00b7 | 226 | bool Call_Box::get_bye_response( void ) { return( this->bye_response ); } |
klauss | 89:0fe315117b00 | 227 | |
klauss | 89:0fe315117b00 | 228 | |
klauss | 121:ee02790d00b7 | 229 | int Call_Box::get_sip_socket_fd ( void ) { return ( sip_socket_fd ); } |
klauss | 89:0fe315117b00 | 230 | |
klauss | 121:ee02790d00b7 | 231 | int Call_Box::sip_udp_incomming_pkg ( void ) { |
klauss | 121:ee02790d00b7 | 232 | return sip -> udp_incomming_pkg (); |
klauss | 91:c2a86b1f8aaa | 233 | } |
klauss | 91:c2a86b1f8aaa | 234 | |
klauss | 119:ee6a53069455 | 235 | void Call_Box::reset_cb_status ( void ) { if( sip != NULL ) sip->reset_call(); } |
klauss | 97:8985817e8847 | 236 | |
klauss | 121:ee02790d00b7 | 237 | int Call_Box::get_sip_ext ( void ) { return this -> sip->get_ext (); } |
klauss | 119:ee6a53069455 | 238 | |
klauss | 121:ee02790d00b7 | 239 | int Call_Box::get_sip_port ( void ) { return this -> sip->get_port (); } |
klauss | 99:e80850c51106 | 240 | |
klauss | 119:ee6a53069455 | 241 | int Call_Box::get_timer ( void ) |
klauss | 119:ee6a53069455 | 242 | { |
klauss | 119:ee6a53069455 | 243 | int now = t.read (); |
klauss | 121:ee02790d00b7 | 244 | |
klauss | 123:1d395b5a4cad | 245 | if ( now >= 30 || now < 0 ) |
klauss | 123:1d395b5a4cad | 246 | //if ( now >= 1500 || now < 0 ) |
klauss | 123:1d395b5a4cad | 247 | { |
klauss | 123:1d395b5a4cad | 248 | this -> t.stop (); |
klauss | 123:1d395b5a4cad | 249 | this -> t.reset (); |
klauss | 123:1d395b5a4cad | 250 | this -> t.start (); |
klauss | 121:ee02790d00b7 | 251 | overflow = true; |
klauss | 123:1d395b5a4cad | 252 | //if ( overflow_times != 0xff ) overflow_times++; |
klauss | 123:1d395b5a4cad | 253 | if ( overflow_times != 0x05 ) overflow_times++; |
klauss | 121:ee02790d00b7 | 254 | } |
klauss | 121:ee02790d00b7 | 255 | |
klauss | 123:1d395b5a4cad | 256 | return ( now ); |
klauss | 119:ee6a53069455 | 257 | } |
klauss | 108:18a3702650f3 | 258 | |
klauss | 108:18a3702650f3 | 259 | int Call_Box::get_rtp_port ( void ) |
klauss | 108:18a3702650f3 | 260 | { |
klauss | 121:ee02790d00b7 | 261 | if ( this -> sip != NULL ) |
klauss | 121:ee02790d00b7 | 262 | { |
klauss | 121:ee02790d00b7 | 263 | return this -> sip -> get_sip_rtp_port (); |
klauss | 121:ee02790d00b7 | 264 | } else { |
klauss | 121:ee02790d00b7 | 265 | debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 119:ee6a53069455 | 266 | |
klauss | 109:a5b8264ffbbc | 267 | deleted_sip++; |
klauss | 119:ee6a53069455 | 268 | |
klauss | 108:18a3702650f3 | 269 | return -1; |
klauss | 108:18a3702650f3 | 270 | } |
klauss | 108:18a3702650f3 | 271 | } |
klauss | 108:18a3702650f3 | 272 | |
klauss | 121:ee02790d00b7 | 273 | void Call_Box::set_rtp_port ( const int new_rtp_port ) |
klauss | 108:18a3702650f3 | 274 | { |
klauss | 121:ee02790d00b7 | 275 | if ( this->sip != NULL ) |
klauss | 121:ee02790d00b7 | 276 | { |
klauss | 108:18a3702650f3 | 277 | this->sip->set_sip_rtp_port( new_rtp_port ); |
klauss | 114:472502b31a12 | 278 | }else{ |
klauss | 119:ee6a53069455 | 279 | debug_msg("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 119:ee6a53069455 | 280 | |
klauss | 109:a5b8264ffbbc | 281 | deleted_sip++; |
klauss | 114:472502b31a12 | 282 | } |
klauss | 108:18a3702650f3 | 283 | } |
klauss | 108:18a3702650f3 | 284 | |
klauss | 119:ee6a53069455 | 285 | void Call_Box::init_rtp_timer ( void ) |
klauss | 119:ee6a53069455 | 286 | { |
klauss | 121:ee02790d00b7 | 287 | this -> rtp_timer.start (); |
klauss | 119:ee6a53069455 | 288 | } |
klauss | 119:ee6a53069455 | 289 | |
klauss | 119:ee6a53069455 | 290 | void Call_Box::reset_rtp_timer ( void ) |
klauss | 119:ee6a53069455 | 291 | { |
klauss | 121:ee02790d00b7 | 292 | this -> rtp_timer.stop (); |
klauss | 121:ee02790d00b7 | 293 | this -> rtp_timer.reset (); |
klauss | 119:ee6a53069455 | 294 | } |
klauss | 119:ee6a53069455 | 295 | |
klauss | 119:ee6a53069455 | 296 | bool Call_Box::is_rtp_timer_timeout ( void ) |
klauss | 119:ee6a53069455 | 297 | { |
klauss | 119:ee6a53069455 | 298 | return ( rtp_timer.read () > RTP_REQUEST_PORT_TIMEOUT ) ? true : false; |
klauss | 119:ee6a53069455 | 299 | } |
klauss | 119:ee6a53069455 | 300 | |
klauss | 121:ee02790d00b7 | 301 | int Call_Box::get_rtp_timer ( void ) { return ( rtp_timer.read () ); } |
klauss | 119:ee6a53069455 | 302 | |
klauss | 109:a5b8264ffbbc | 303 | int Call_Box::print_yourself ( void ) |
klauss | 109:a5b8264ffbbc | 304 | { |
klauss | 109:a5b8264ffbbc | 305 | send_msg (""); |
klauss | 109:a5b8264ffbbc | 306 | send_msg ("Values ::\r\n"); |
klauss | 109:a5b8264ffbbc | 307 | switch( status ) { |
klauss | 109:a5b8264ffbbc | 308 | case cb_idle : { |
klauss | 109:a5b8264ffbbc | 309 | send_msg ("status :: cb_idle" ); |
klauss | 109:a5b8264ffbbc | 310 | break; |
klauss | 109:a5b8264ffbbc | 311 | } |
klauss | 109:a5b8264ffbbc | 312 | case cb_ringing : { |
klauss | 109:a5b8264ffbbc | 313 | send_msg ("status :: cb_ringing" ); |
klauss | 109:a5b8264ffbbc | 314 | break; |
klauss | 109:a5b8264ffbbc | 315 | } |
klauss | 109:a5b8264ffbbc | 316 | case cb_trying : { |
klauss | 109:a5b8264ffbbc | 317 | send_msg ("status :: cb_trying" ); |
klauss | 109:a5b8264ffbbc | 318 | break; |
klauss | 109:a5b8264ffbbc | 319 | } |
klauss | 109:a5b8264ffbbc | 320 | case cb_on_call : { |
klauss | 109:a5b8264ffbbc | 321 | send_msg ("status :: cb_on_call" ); |
klauss | 109:a5b8264ffbbc | 322 | break; |
klauss | 109:a5b8264ffbbc | 323 | } |
klauss | 109:a5b8264ffbbc | 324 | case cb_busy : { |
klauss | 109:a5b8264ffbbc | 325 | send_msg ("status :: cb_busy" ); |
klauss | 109:a5b8264ffbbc | 326 | break; |
klauss | 109:a5b8264ffbbc | 327 | } |
klauss | 109:a5b8264ffbbc | 328 | case cb_denied : { |
klauss | 109:a5b8264ffbbc | 329 | send_msg ("status :: cb_denied" ); |
klauss | 109:a5b8264ffbbc | 330 | break; |
klauss | 109:a5b8264ffbbc | 331 | } |
klauss | 109:a5b8264ffbbc | 332 | } |
klauss | 109:a5b8264ffbbc | 333 | send_msg ("ext :: %i", ext ); |
klauss | 109:a5b8264ffbbc | 334 | send_msg ("port :: %i", port ); |
klauss | 109:a5b8264ffbbc | 335 | send_msg ("Timer t :: %d", ( int )t.read () ); |
klauss | 123:1d395b5a4cad | 336 | send_msg ("overflow_times :: %u", overflow_times ); |
klauss | 109:a5b8264ffbbc | 337 | send_msg ("msg_id :: %d", msg_id ); |
klauss | 109:a5b8264ffbbc | 338 | send_msg ("timeslice :: %u", timeslice ); |
klauss | 109:a5b8264ffbbc | 339 | send_msg ("next_aging_type :: %u", next_aging_type ); |
klauss | 109:a5b8264ffbbc | 340 | send_msg ("invite_response :: %s", ( invite_response ) ? "true" : "false" ); |
klauss | 109:a5b8264ffbbc | 341 | send_msg ("invite_retry_count :: %u", invite_retry_count ); |
klauss | 109:a5b8264ffbbc | 342 | send_msg ("bye_response :: %s", ( bye_response ) ? "true" : "false" ); |
klauss | 109:a5b8264ffbbc | 343 | send_msg ("sip_socket_fd :: %d", sip_socket_fd ); |
klauss | 109:a5b8264ffbbc | 344 | send_msg (""); |
klauss | 109:a5b8264ffbbc | 345 | |
klauss | 109:a5b8264ffbbc | 346 | return ( sizeof( Call_Box ) ); |
klauss | 117:e9facba9db27 | 347 | } |
klauss | 119:ee6a53069455 | 348 | |
klauss | 121:ee02790d00b7 | 349 | int Call_Box::call_init ( const int timeslice ) |
klauss | 117:e9facba9db27 | 350 | { |
klauss | 119:ee6a53069455 | 351 | invite_timer.reset (); |
klauss | 117:e9facba9db27 | 352 | |
klauss | 119:ee6a53069455 | 353 | invite_timer.start (); |
klauss | 119:ee6a53069455 | 354 | |
klauss | 119:ee6a53069455 | 355 | this->timeslice = timeslice; |
klauss | 119:ee6a53069455 | 356 | |
klauss | 119:ee6a53069455 | 357 | this->status = cb_ringing; |
klauss | 119:ee6a53069455 | 358 | |
klauss | 119:ee6a53069455 | 359 | set_invite_response_pending (); |
klauss | 119:ee6a53069455 | 360 | |
klauss | 119:ee6a53069455 | 361 | invite_try_number = 0; |
klauss | 119:ee6a53069455 | 362 | |
klauss | 119:ee6a53069455 | 363 | msg_id_update (); |
klauss | 119:ee6a53069455 | 364 | |
klauss | 119:ee6a53069455 | 365 | return 0; |
klauss | 117:e9facba9db27 | 366 | } |
klauss | 119:ee6a53069455 | 367 | |
klauss | 121:ee02790d00b7 | 368 | int Call_Box::call_end ( const bool send_bye_to_ast ) |
klauss | 117:e9facba9db27 | 369 | { |
klauss | 119:ee6a53069455 | 370 | uint8_t timeslice = this->timeslice; |
klauss | 119:ee6a53069455 | 371 | |
klauss | 119:ee6a53069455 | 372 | this->timeslice = 0; |
klauss | 119:ee6a53069455 | 373 | |
klauss | 119:ee6a53069455 | 374 | this->status = cb_idle; |
klauss | 119:ee6a53069455 | 375 | |
klauss | 119:ee6a53069455 | 376 | if ( sip != NULL ) { |
klauss | 119:ee6a53069455 | 377 | sip -> sip_set_status ( sip_idle ); |
klauss | 119:ee6a53069455 | 378 | } else { |
klauss | 119:ee6a53069455 | 379 | if( debug_cb ) debug_msg("[%d] Sip equals NULL o.O", this->ext ); |
klauss | 119:ee6a53069455 | 380 | } |
klauss | 119:ee6a53069455 | 381 | |
klauss | 119:ee6a53069455 | 382 | set_rtp_port ( 0 ); |
klauss | 119:ee6a53069455 | 383 | |
klauss | 119:ee6a53069455 | 384 | reset_rtp_timer (); |
klauss | 119:ee6a53069455 | 385 | |
klauss | 119:ee6a53069455 | 386 | if ( send_bye_to_ast ) |
klauss | 119:ee6a53069455 | 387 | { |
klauss | 119:ee6a53069455 | 388 | if ( timeslice != 0 ) send_bye (); |
klauss | 119:ee6a53069455 | 389 | } |
klauss | 119:ee6a53069455 | 390 | |
klauss | 119:ee6a53069455 | 391 | reset_cb_status (); |
klauss | 119:ee6a53069455 | 392 | |
klauss | 119:ee6a53069455 | 393 | invite_timer.stop (); |
klauss | 119:ee6a53069455 | 394 | |
klauss | 119:ee6a53069455 | 395 | invite_timer.reset (); |
klauss | 119:ee6a53069455 | 396 | |
klauss | 119:ee6a53069455 | 397 | invite_try_number = 0; |
klauss | 119:ee6a53069455 | 398 | |
klauss | 119:ee6a53069455 | 399 | msg_id_update (); |
klauss | 119:ee6a53069455 | 400 | |
klauss | 119:ee6a53069455 | 401 | return timeslice; |
klauss | 117:e9facba9db27 | 402 | } |
klauss | 119:ee6a53069455 | 403 | |
klauss | 119:ee6a53069455 | 404 | int Call_Box::call_confirmed ( void ) |
klauss | 119:ee6a53069455 | 405 | { |
klauss | 119:ee6a53069455 | 406 | set_invite_response_pending (); |
klauss | 119:ee6a53069455 | 407 | |
klauss | 121:ee02790d00b7 | 408 | this -> status = cb_on_call; |
klauss | 119:ee6a53069455 | 409 | |
klauss | 119:ee6a53069455 | 410 | msg_id_update (); |
klauss | 119:ee6a53069455 | 411 | |
klauss | 119:ee6a53069455 | 412 | return 0; |
klauss | 119:ee6a53069455 | 413 | } |
klauss | 119:ee6a53069455 | 414 | |
klauss | 119:ee6a53069455 | 415 | uint8_t Call_Box::msg_id_update ( void ) |
klauss | 123:1d395b5a4cad | 416 | { |
klauss | 123:1d395b5a4cad | 417 | this->msg_id = ( ( ( this->msg_id + 1 ) & ~BIT7 ) > 0x10 ) ? ( ( this->msg_id + 1 ) & ~BIT7 ) : 0x11; |
klauss | 119:ee6a53069455 | 418 | |
klauss | 119:ee6a53069455 | 419 | return this->msg_id; |
klauss | 119:ee6a53069455 | 420 | } |
klauss | 119:ee6a53069455 | 421 | |
klauss | 119:ee6a53069455 | 422 | void Call_Box::call_config ( void ) |
klauss | 117:e9facba9db27 | 423 | { |
klauss | 119:ee6a53069455 | 424 | set_invite_response_ok (); |
klauss | 119:ee6a53069455 | 425 | reset_rtp_timer (); |
klauss | 119:ee6a53069455 | 426 | init_rtp_timer (); |
klauss | 119:ee6a53069455 | 427 | } |
klauss | 119:ee6a53069455 | 428 | |
klauss | 119:ee6a53069455 | 429 | bool Call_Box::time_to_retry ( void ) |
klauss | 119:ee6a53069455 | 430 | { |
klauss | 121:ee02790d00b7 | 431 | if ( invite_timer.read_ms () > 1000 ) |
klauss | 121:ee02790d00b7 | 432 | { |
klauss | 119:ee6a53069455 | 433 | invite_timer.reset (); |
klauss | 119:ee6a53069455 | 434 | return true; |
klauss | 119:ee6a53069455 | 435 | } else { |
klauss | 119:ee6a53069455 | 436 | return false; |
klauss | 119:ee6a53069455 | 437 | } |
klauss | 119:ee6a53069455 | 438 | } |
klauss | 119:ee6a53069455 | 439 | |
klauss | 119:ee6a53069455 | 440 | uint8_t Call_Box::get_invite_try_number ( void ) {return invite_try_number; } |
klauss | 119:ee6a53069455 | 441 | |
klauss | 119:ee6a53069455 | 442 | int Call_Box::retry_send_invite_pkg_to_ast ( void ) |
klauss | 119:ee6a53069455 | 443 | { |
klauss | 121:ee02790d00b7 | 444 | if ( this -> sip != NULL ) |
klauss | 119:ee6a53069455 | 445 | { |
klauss | 119:ee6a53069455 | 446 | invite_try_number++; |
klauss | 119:ee6a53069455 | 447 | return ( sip -> retry_send_last_invite_pkg_to_ast () ); |
klauss | 119:ee6a53069455 | 448 | } else { |
klauss | 121:ee02790d00b7 | 449 | debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 119:ee6a53069455 | 450 | |
klauss | 119:ee6a53069455 | 451 | deleted_sip++; |
klauss | 119:ee6a53069455 | 452 | |
klauss | 119:ee6a53069455 | 453 | return ( 0 ); |
klauss | 119:ee6a53069455 | 454 | } |
klauss | 121:ee02790d00b7 | 455 | } |
klauss | 121:ee02790d00b7 | 456 | |
klauss | 121:ee02790d00b7 | 457 | int Call_Box::sip_print_yourself ( void ) |
klauss | 121:ee02790d00b7 | 458 | { |
klauss | 121:ee02790d00b7 | 459 | if ( this -> sip != NULL ) |
klauss | 121:ee02790d00b7 | 460 | { |
klauss | 121:ee02790d00b7 | 461 | return sip -> print_yourself (); |
klauss | 121:ee02790d00b7 | 462 | } else { |
klauss | 121:ee02790d00b7 | 463 | debug_msg ("[%d] Eu definitivamente nao deveria estar aqui!!!", this->ext ); |
klauss | 121:ee02790d00b7 | 464 | |
klauss | 121:ee02790d00b7 | 465 | return ( -1 ); |
klauss | 121:ee02790d00b7 | 466 | } |
klauss | 121:ee02790d00b7 | 467 | |
klauss | 121:ee02790d00b7 | 468 | } |
klauss | 121:ee02790d00b7 | 469 | |
klauss | 121:ee02790d00b7 | 470 | Sip * Call_Box::get_sip ( void ) { return this -> sip ; } |
klauss | 121:ee02790d00b7 | 471 | |
klauss | 123:1d395b5a4cad | 472 | bool Call_Box::get_overflow_flag ( void ) { get_timer () ; return ( this -> overflow ); } |
klauss | 123:1d395b5a4cad | 473 | |
klauss | 123:1d395b5a4cad | 474 | uint8_t Call_Box::get_overflow_times ( void ) { return ( this -> overflow_times ); } |
klauss | 123:1d395b5a4cad | 475 | |
klauss | 123:1d395b5a4cad | 476 | |
klauss | 123:1d395b5a4cad | 477 | void Call_Box::update_time ( void ){ get_timer (); } |