Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: call_box.cpp
- Revision:
- 78:1353744f01e1
- Parent:
- 77:e8c0253b57bc
- Child:
- 81:3656f00ab3db
diff -r e8c0253b57bc -r 1353744f01e1 call_box.cpp --- a/call_box.cpp Tue Nov 25 18:43:01 2014 +0000 +++ b/call_box.cpp Tue Dec 16 12:13:01 2014 +0000 @@ -6,14 +6,31 @@ t.start(); remaining_attempts = __MAX_ATTEMPTS__; timeout = __TIMEOUT__; - //sip.set_ext( this->ext ); - //sip.set_port( this->port ); msg_id = 0x10; timeslice = 0x00; status = cb_idle; - //Sip sip( ext, port ); - //sip = NULL; sip = new Sip( ext, port ); + + next_aging_type = __CYCLES__; + seconds.start(); +} + +int Call_Box::get_status( void ){ return this->status; } + +void Call_Box::cb_set_status( uint8_t status ){ this->status = status; } + +int Call_Box::get_sip_status( void ){ + if( sip == NULL ) return -1; + + else return this->sip->get_status(); +} + +int Call_Box::set_sip_status( uint8_t status ){ + if( sip == NULL ) return( -1 ); + + sip->sip_set_status( status ); + + return( 0 ); } Call_Box::~Call_Box( void ){ @@ -27,31 +44,33 @@ void Call_Box::reset_elapsed_time( void ){ this->t.reset(); - remaining_attempts = __MAX_ATTEMPTS__; -// timeout = __TIMEOUT__; + timeout = __TIMEOUT__; + next_aging_type = __CYCLES__; } bool Call_Box::is_timeout( void ){ - return( t.read() > timeout ) ? true : false; + if( seconds.read() > __RESQUEST_TIME__ ){ + seconds.reset(); + return( t.read() > __TIME_TO_REGISTER__ ) ? true : false; + }else return false; } -uint8_t Call_Box::reconfigure_timeout( void ){ - //static int count = 1; - //if( timeout != __MAX_TIMEOUT__ ) timeout = __STEP__ * count++; - t.reset(); - return( remaining_attempts-- ); +bool Call_Box::has_next_try( void ){ + return( ( t.read() < __TIMEOUT__ ) ? true : false ); } void Call_Box::registry( void ){ if( this->sip == NULL ){ this->sip = new Sip( ext, port ); - sip->registry(); - + if( sip->registry() > 0x00 ) reset_elapsed_time(); + if( debug_aging ) debug_msg( "%d Registered", ext ); + delete( sip ); this->sip = NULL; }else{ - sip->registry(); + if( sip->registry() > 0x00 ) reset_elapsed_time(); + if( debug_aging ) debug_msg( "%d Registered", ext ); } } @@ -110,7 +129,7 @@ } void Call_Box::set_msg_id( uint8_t msg_id ){ - this->msg_id = msg_id; + this->msg_id = ( msg_id > 0x10 ) ? msg_id : 0x11; } uint8_t Call_Box::get_msg_id( void ){ return( this->msg_id ); } @@ -146,10 +165,20 @@ if( this->sip != NULL ){ this->sip->status = status; }else{ - if( debug_cb) debug_msg("Sem objeto sip vinculado"); + if( debug_cb) debug_msg("Sip equals NULL o.O"); } } void Call_Box::re_start_timer( void ){ t.start(); +} + +int8_t Call_Box::get_next_aging_type( void ){ + next_aging_type--; + + if( ( next_aging_type % 2 ) == 0 || ( next_aging_type > __CYCLES__ - 15 ) ) return( REQUEST_REGISTRY ); + + else if( ( next_aging_type % 7 ) == 0 ) return( REQUEST_PEND ); + + else return( REQUEST_PING ); } \ No newline at end of file