![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Versao com problema no socket rx
Dependencies: EthernetInterface NTPClient mbed-rtos mbed
call_box.cpp@0:4d17cd9c8f9d, 2014-09-09 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 09 20:01:24 2014 +0000
- Revision:
- 0:4d17cd9c8f9d
- Child:
- 1:a1758104fa1d
20140726 copy
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 | 0:4d17cd9c8f9d | 3 | Call_Box::Call_Box( int ext, int port ){ |
klauss | 0:4d17cd9c8f9d | 4 | this->ext = ext; |
klauss | 0:4d17cd9c8f9d | 5 | this->port = port; |
klauss | 0:4d17cd9c8f9d | 6 | t.start(); |
klauss | 0:4d17cd9c8f9d | 7 | remaining_attempts = __MAX_ATTEMPTS__; |
klauss | 0:4d17cd9c8f9d | 8 | timeout = __TIMEOUT__; |
klauss | 0:4d17cd9c8f9d | 9 | //sip.set_ext( this->ext ); |
klauss | 0:4d17cd9c8f9d | 10 | //sip.set_port( this->port ); |
klauss | 0:4d17cd9c8f9d | 11 | msg_id = 0x00; |
klauss | 0:4d17cd9c8f9d | 12 | timeslice = 0x00; |
klauss | 0:4d17cd9c8f9d | 13 | status = cb_idle; |
klauss | 0:4d17cd9c8f9d | 14 | //Sip sip( ext, port ); |
klauss | 0:4d17cd9c8f9d | 15 | //sip = NULL; |
klauss | 0:4d17cd9c8f9d | 16 | sip = new Sip( ext, port ); |
klauss | 0:4d17cd9c8f9d | 17 | } |
klauss | 0:4d17cd9c8f9d | 18 | |
klauss | 0:4d17cd9c8f9d | 19 | Call_Box::~Call_Box( void ){ |
klauss | 0:4d17cd9c8f9d | 20 | if( sip != NULL ) delete( sip ); |
klauss | 0:4d17cd9c8f9d | 21 | } |
klauss | 0:4d17cd9c8f9d | 22 | |
klauss | 0:4d17cd9c8f9d | 23 | int Call_Box::get_port( void ){ return( this->port ); } |
klauss | 0:4d17cd9c8f9d | 24 | int Call_Box::get_ext( void ){ return( this->ext ); } |
klauss | 0:4d17cd9c8f9d | 25 | |
klauss | 0:4d17cd9c8f9d | 26 | float Call_Box::get_elapsed_time( void ){ return( this->t.read_ms() ); } |
klauss | 0:4d17cd9c8f9d | 27 | |
klauss | 0:4d17cd9c8f9d | 28 | void Call_Box::reset_elapsed_time( void ){ |
klauss | 0:4d17cd9c8f9d | 29 | this->t.reset(); |
klauss | 0:4d17cd9c8f9d | 30 | remaining_attempts = __MAX_ATTEMPTS__; |
klauss | 0:4d17cd9c8f9d | 31 | timeout = __TIMEOUT__; |
klauss | 0:4d17cd9c8f9d | 32 | } |
klauss | 0:4d17cd9c8f9d | 33 | |
klauss | 0:4d17cd9c8f9d | 34 | bool Call_Box::is_timeout( void ){ |
klauss | 0:4d17cd9c8f9d | 35 | return( t.read() > timeout ) ? true : false; |
klauss | 0:4d17cd9c8f9d | 36 | } |
klauss | 0:4d17cd9c8f9d | 37 | |
klauss | 0:4d17cd9c8f9d | 38 | uint8_t Call_Box::reconfigure_timeout( void ){ |
klauss | 0:4d17cd9c8f9d | 39 | static int count = 1; |
klauss | 0:4d17cd9c8f9d | 40 | if( timeout != __MAX_TIMEOUT__ ) timeout = __STEP__ * count++; |
klauss | 0:4d17cd9c8f9d | 41 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 42 | return( remaining_attempts-- ); |
klauss | 0:4d17cd9c8f9d | 43 | } |
klauss | 0:4d17cd9c8f9d | 44 | |
klauss | 0:4d17cd9c8f9d | 45 | void Call_Box::registry( void ){ |
klauss | 0:4d17cd9c8f9d | 46 | if( this->sip == NULL ){ |
klauss | 0:4d17cd9c8f9d | 47 | this->sip = new Sip( ext, port ); |
klauss | 0:4d17cd9c8f9d | 48 | |
klauss | 0:4d17cd9c8f9d | 49 | sip->registry(); |
klauss | 0:4d17cd9c8f9d | 50 | |
klauss | 0:4d17cd9c8f9d | 51 | delete( sip ); |
klauss | 0:4d17cd9c8f9d | 52 | this->sip = NULL; |
klauss | 0:4d17cd9c8f9d | 53 | }else{ |
klauss | 0:4d17cd9c8f9d | 54 | sip->registry(); |
klauss | 0:4d17cd9c8f9d | 55 | } |
klauss | 0:4d17cd9c8f9d | 56 | } |
klauss | 0:4d17cd9c8f9d | 57 | |
klauss | 0:4d17cd9c8f9d | 58 | void Call_Box::unregistry( void ){ |
klauss | 0:4d17cd9c8f9d | 59 | if( this->sip == NULL ){ |
klauss | 0:4d17cd9c8f9d | 60 | this->sip = new Sip( ext, port ); |
klauss | 0:4d17cd9c8f9d | 61 | |
klauss | 0:4d17cd9c8f9d | 62 | sip->send_unregistry_pkg(); |
klauss | 0:4d17cd9c8f9d | 63 | |
klauss | 0:4d17cd9c8f9d | 64 | delete( sip ); |
klauss | 0:4d17cd9c8f9d | 65 | this->sip = NULL; |
klauss | 0:4d17cd9c8f9d | 66 | }else{ |
klauss | 0:4d17cd9c8f9d | 67 | sip->send_unregistry_pkg(); |
klauss | 0:4d17cd9c8f9d | 68 | } |
klauss | 0:4d17cd9c8f9d | 69 | } |
klauss | 0:4d17cd9c8f9d | 70 | |
klauss | 0:4d17cd9c8f9d | 71 | VZ_call * Call_Box::invite( void ){ |
klauss | 0:4d17cd9c8f9d | 72 | if( this->sip == NULL ){ |
klauss | 0:4d17cd9c8f9d | 73 | debug_msg("entrei no invite"); |
klauss | 0:4d17cd9c8f9d | 74 | this->sip = new Sip( ext, port ); |
klauss | 0:4d17cd9c8f9d | 75 | |
klauss | 0:4d17cd9c8f9d | 76 | VZ_call * call = sip->invite(); |
klauss | 0:4d17cd9c8f9d | 77 | |
klauss | 0:4d17cd9c8f9d | 78 | delete( sip ); |
klauss | 0:4d17cd9c8f9d | 79 | this->sip = NULL; |
klauss | 0:4d17cd9c8f9d | 80 | |
klauss | 0:4d17cd9c8f9d | 81 | debug_msg("Valor do retorno do invite :: %p ", call ); |
klauss | 0:4d17cd9c8f9d | 82 | return( call ); |
klauss | 0:4d17cd9c8f9d | 83 | }else{ |
klauss | 0:4d17cd9c8f9d | 84 | debug_msg("entrei no invite persistente"); |
klauss | 0:4d17cd9c8f9d | 85 | |
klauss | 0:4d17cd9c8f9d | 86 | VZ_call * call = sip->invite(); |
klauss | 0:4d17cd9c8f9d | 87 | |
klauss | 0:4d17cd9c8f9d | 88 | debug_msg("Valor do retorno do invite persistente :: %p ", call ); |
klauss | 0:4d17cd9c8f9d | 89 | return( call ); |
klauss | 0:4d17cd9c8f9d | 90 | } |
klauss | 0:4d17cd9c8f9d | 91 | } |
klauss | 0:4d17cd9c8f9d | 92 | |
klauss | 0:4d17cd9c8f9d | 93 | /* Retorna |
klauss | 0:4d17cd9c8f9d | 94 | = 0 :: ok |
klauss | 0:4d17cd9c8f9d | 95 | < 0 :: tive problemas |
klauss | 0:4d17cd9c8f9d | 96 | > 0 :: devo remover essa call do vetor de calls |
klauss | 0:4d17cd9c8f9d | 97 | */ |
klauss | 0:4d17cd9c8f9d | 98 | int Call_Box::listen_SIP_server( void ){ |
klauss | 0:4d17cd9c8f9d | 99 | if( this->sip == NULL ){ |
klauss | 0:4d17cd9c8f9d | 100 | if( status == cb_on_call || status == cb_idle ){ |
klauss | 0:4d17cd9c8f9d | 101 | this->sip = new Sip( ext, port ); |
klauss | 0:4d17cd9c8f9d | 102 | int out_read = sip->listen_SIP_server(); |
klauss | 0:4d17cd9c8f9d | 103 | delete( sip ); |
klauss | 0:4d17cd9c8f9d | 104 | this->sip = NULL; |
klauss | 0:4d17cd9c8f9d | 105 | return( out_read ); |
klauss | 0:4d17cd9c8f9d | 106 | }else return( 0 ); |
klauss | 0:4d17cd9c8f9d | 107 | }else{ |
klauss | 0:4d17cd9c8f9d | 108 | if( status == cb_on_call || status == cb_idle ){ |
klauss | 0:4d17cd9c8f9d | 109 | return ( sip->listen_SIP_server() ); |
klauss | 0:4d17cd9c8f9d | 110 | } else return( 0 ); |
klauss | 0:4d17cd9c8f9d | 111 | } |
klauss | 0:4d17cd9c8f9d | 112 | } |
klauss | 0:4d17cd9c8f9d | 113 | |
klauss | 0:4d17cd9c8f9d | 114 | void Call_Box::set_msg_id( uint8_t msg_id ){ |
klauss | 0:4d17cd9c8f9d | 115 | this->msg_id = msg_id; |
klauss | 0:4d17cd9c8f9d | 116 | } |
klauss | 0:4d17cd9c8f9d | 117 | uint8_t Call_Box::get_msg_id( void ){ return( this->msg_id ); } |
klauss | 0:4d17cd9c8f9d | 118 | |
klauss | 0:4d17cd9c8f9d | 119 | void Call_Box::set_timeslice( uint8_t timeslice ){ |
klauss | 0:4d17cd9c8f9d | 120 | this->timeslice = timeslice; |
klauss | 0:4d17cd9c8f9d | 121 | } |
klauss | 0:4d17cd9c8f9d | 122 | uint8_t Call_Box::get_timeslice( void ){ return( this->timeslice ); } |
klauss | 0:4d17cd9c8f9d | 123 | |
klauss | 0:4d17cd9c8f9d | 124 | //void Call_Box::set_sip( Sip * sip ){ |
klauss | 0:4d17cd9c8f9d | 125 | // this->sip = sip; |
klauss | 0:4d17cd9c8f9d | 126 | //} |
klauss | 0:4d17cd9c8f9d | 127 | |
klauss | 0:4d17cd9c8f9d | 128 | void Call_Box::send_bye( void ){ |
klauss | 0:4d17cd9c8f9d | 129 | if( this->sip == NULL ){ |
klauss | 0:4d17cd9c8f9d | 130 | this->sip = new Sip( ext, port ); |
klauss | 0:4d17cd9c8f9d | 131 | |
klauss | 0:4d17cd9c8f9d | 132 | sip->send_bye(); |
klauss | 0:4d17cd9c8f9d | 133 | |
klauss | 0:4d17cd9c8f9d | 134 | delete( sip ); |
klauss | 0:4d17cd9c8f9d | 135 | |
klauss | 0:4d17cd9c8f9d | 136 | sip = NULL; |
klauss | 0:4d17cd9c8f9d | 137 | }else{ |
klauss | 0:4d17cd9c8f9d | 138 | sip->send_bye(); |
klauss | 0:4d17cd9c8f9d | 139 | } |
klauss | 0:4d17cd9c8f9d | 140 | } |