![](/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.cpp@115:a1e1e2e60a2c, 2015-04-23 (annotated)
- Committer:
- klauss
- Date:
- Thu Apr 23 13:57:54 2015 +0000
- Revision:
- 115:a1e1e2e60a2c
- Parent:
- 114:472502b31a12
- Child:
- 116:39a41ebb675c
implementando retrys wip
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "call.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 0:4d17cd9c8f9d | 3 | VZ_call::VZ_call( int cb_ext, int cb_port, int rtp_server_ext, int rtp_server_port ){ |
klauss | 0:4d17cd9c8f9d | 4 | this->cb_ext = cb_ext; |
klauss | 0:4d17cd9c8f9d | 5 | this->cb_port = cb_port; |
klauss | 0:4d17cd9c8f9d | 6 | |
klauss | 0:4d17cd9c8f9d | 7 | this->rtp_server_ext = rtp_server_ext; |
klauss | 0:4d17cd9c8f9d | 8 | this->rtp_server_port = rtp_server_port; |
klauss | 69:65665afbad5d | 9 | this->rtp_server.set_address( __RTP_SEVER_IP__, rtp_server_port ); |
klauss | 114:472502b31a12 | 10 | rtp_sock.set_blocking( false, 0 ); |
klauss | 114:472502b31a12 | 11 | debug_msg("primeiro"); |
klauss | 114:472502b31a12 | 12 | this->rtp_sock.bind( cb_port ); // rtp port |
klauss | 114:472502b31a12 | 13 | debug_msg("segundo"); |
klauss | 114:472502b31a12 | 14 | this->rtp_sock.init(); |
klauss | 0:4d17cd9c8f9d | 15 | this->rtp = new RTP( this->cb_ext ); |
klauss | 0:4d17cd9c8f9d | 16 | |
klauss | 89:0fe315117b00 | 17 | if( rtp == NULL ) |
klauss | 89:0fe315117b00 | 18 | { |
klauss | 89:0fe315117b00 | 19 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 20 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
klauss | 89:0fe315117b00 | 21 | } |
klauss | 87:679ee0d594a9 | 22 | |
klauss | 0:4d17cd9c8f9d | 23 | t.start(); |
klauss | 0:4d17cd9c8f9d | 24 | finish.start(); |
klauss | 0:4d17cd9c8f9d | 25 | rtpbuf_clear( &( this->rtpbuf ) ); |
klauss | 91:c2a86b1f8aaa | 26 | call_new_counter++; |
klauss | 0:4d17cd9c8f9d | 27 | } |
klauss | 0:4d17cd9c8f9d | 28 | |
klauss | 0:4d17cd9c8f9d | 29 | VZ_call::~VZ_call(){ |
klauss | 0:4d17cd9c8f9d | 30 | rtp_sock.close(); |
klauss | 0:4d17cd9c8f9d | 31 | delete( this->rtp ); |
klauss | 91:c2a86b1f8aaa | 32 | call_delete_counter++; |
klauss | 0:4d17cd9c8f9d | 33 | } |
klauss | 0:4d17cd9c8f9d | 34 | |
klauss | 0:4d17cd9c8f9d | 35 | char * VZ_call::get_eth_message( int * length ){ |
klauss | 0:4d17cd9c8f9d | 36 | uint8_t * pkg; |
klauss | 114:472502b31a12 | 37 | *length = rtp_sock.receiveFrom( rtp_server, server2cb, sizeof( server2cb ) ); |
klauss | 0:4d17cd9c8f9d | 38 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 39 | |
klauss | 0:4d17cd9c8f9d | 40 | rtpbuf_next( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 41 | |
klauss | 0:4d17cd9c8f9d | 42 | if( *length > 0 ){ |
klauss | 0:4d17cd9c8f9d | 43 | rtpbuf_put( &rtpbuf, *length - ( __RTP_HEADER_SIZE__ + ( server2cb[ 0 ] & 0xf ) ), |
klauss | 0:4d17cd9c8f9d | 44 | ( uint8_t * )server2cb + ( __RTP_HEADER_OFFSET__ + ( server2cb[ 0 ] & 0xf ) ) ); |
klauss | 0:4d17cd9c8f9d | 45 | } |
klauss | 0:4d17cd9c8f9d | 46 | |
klauss | 0:4d17cd9c8f9d | 47 | pkg = rtpbuf_get( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 48 | |
klauss | 0:4d17cd9c8f9d | 49 | if (pkg != NULL) { |
klauss | 0:4d17cd9c8f9d | 50 | *length = 240; |
klauss | 0:4d17cd9c8f9d | 51 | return (char *) pkg; |
klauss | 0:4d17cd9c8f9d | 52 | } |
klauss | 0:4d17cd9c8f9d | 53 | *length = 0; |
klauss | 0:4d17cd9c8f9d | 54 | return NULL; |
klauss | 0:4d17cd9c8f9d | 55 | } |
klauss | 0:4d17cd9c8f9d | 56 | |
klauss | 0:4d17cd9c8f9d | 57 | int VZ_call::send_message( char * buffer ){ |
klauss | 0:4d17cd9c8f9d | 58 | t.reset(); |
klauss | 114:472502b31a12 | 59 | return( this->rtp_sock.sendTo( this->rtp_server, buffer, __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ) ); |
klauss | 114:472502b31a12 | 60 | |
klauss | 114:472502b31a12 | 61 | /* |
klauss | 114:472502b31a12 | 62 | //FIXME verificar como fica se eu esperar o sendTo chegar em != 0 |
klauss | 114:472502b31a12 | 63 | int8_t sent = 0; |
klauss | 114:472502b31a12 | 64 | do{ |
klauss | 114:472502b31a12 | 65 | sent = this->rtp_sock.sendTo( this->rtp_server, buffer, __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ) ); |
klauss | 114:472502b31a12 | 66 | }while( sent == 0 ); |
klauss | 114:472502b31a12 | 67 | return( sent ); |
klauss | 114:472502b31a12 | 68 | */ |
klauss | 0:4d17cd9c8f9d | 69 | } |
klauss | 0:4d17cd9c8f9d | 70 | |
klauss | 114:472502b31a12 | 71 | uint8_t * VZ_call::build_cb_package( void ){ |
klauss | 114:472502b31a12 | 72 | // return __build_cb_package__( cb_ext, cb_port, __AUDIO__, server2cb, buffer ); |
klauss | 0:4d17cd9c8f9d | 73 | // colocar esta funcao novamente pra envio de msg, assim como encapsular melhor a funcao |
klauss | 0:4d17cd9c8f9d | 74 | // de criacao dos pacotes pro cb em algumas funcoes. |
klauss | 114:472502b31a12 | 75 | return 0x00; |
klauss | 114:472502b31a12 | 76 | } |
klauss | 0:4d17cd9c8f9d | 77 | |
klauss | 0:4d17cd9c8f9d | 78 | char * VZ_call::build_eth_package( uint8_t * buffer ){ |
klauss | 0:4d17cd9c8f9d | 79 | return this->rtp->build_eth_package( ( char * )buffer ); |
klauss | 0:4d17cd9c8f9d | 80 | } |
klauss | 0:4d17cd9c8f9d | 81 | |
klauss | 0:4d17cd9c8f9d | 82 | int VZ_call::get_cb_ext(){ return this->cb_ext; } |
klauss | 0:4d17cd9c8f9d | 83 | int VZ_call::get_cb_port(){ return this->cb_port; } |
klauss | 0:4d17cd9c8f9d | 84 | |
klauss | 0:4d17cd9c8f9d | 85 | int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; } |
klauss | 0:4d17cd9c8f9d | 86 | int VZ_call::get_rtp_server_port(){ return rtp_server_port; } |
klauss | 0:4d17cd9c8f9d | 87 | uint8_t * VZ_call::get_cb2server_buffer(){ return cb2server; } |
klauss | 0:4d17cd9c8f9d | 88 | char * VZ_call::get_server2cb_buffer(){ return server2cb; } |
klauss | 0:4d17cd9c8f9d | 89 | inline uint8_t * VZ_call::get_buffer(){ return buffer; } |
klauss | 0:4d17cd9c8f9d | 90 | |
klauss | 0:4d17cd9c8f9d | 91 | bool VZ_call::is_timeout( void ){ |
klauss | 0:4d17cd9c8f9d | 92 | return ( t.read() > __CALL_MAX_IDLE_TIME__ ) ? true : false; |
klauss | 0:4d17cd9c8f9d | 93 | } |
klauss | 0:4d17cd9c8f9d | 94 | |
klauss | 0:4d17cd9c8f9d | 95 | bool VZ_call::is_timetofinish( void ){ |
klauss | 0:4d17cd9c8f9d | 96 | return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false; |
klauss | 92:92df17f538a8 | 97 | } |
klauss | 92:92df17f538a8 | 98 | |
klauss | 115:a1e1e2e60a2c | 99 | uint16_t VZ_call::get_elapsed_time( void ){ |
klauss | 92:92df17f538a8 | 100 | return ( finish.read_ms() ); |
klauss | 92:92df17f538a8 | 101 | } |
klauss | 92:92df17f538a8 | 102 | |
klauss | 92:92df17f538a8 | 103 | void VZ_call::cbx_pkg_idle_timer_reset( void ){ |
klauss | 92:92df17f538a8 | 104 | cbx_pkg_idle_timer.reset(); |
klauss | 92:92df17f538a8 | 105 | } |
klauss | 92:92df17f538a8 | 106 | |
klauss | 92:92df17f538a8 | 107 | bool VZ_call::cbx_pkg_is_idle( void ){ |
klauss | 92:92df17f538a8 | 108 | return ( cbx_pkg_idle_timer.read() > CBX_PKG_IDLE_MAX_TIME ) ? true : false; |
klauss | 92:92df17f538a8 | 109 | } |
klauss | 92:92df17f538a8 | 110 | |
klauss | 92:92df17f538a8 | 111 | void VZ_call::init_cbx_pkg_idle_timer(){ |
klauss | 92:92df17f538a8 | 112 | cbx_pkg_idle_timer.start(); |
klauss | 104:62646ef786a3 | 113 | } |
klauss | 104:62646ef786a3 | 114 | |
klauss | 114:472502b31a12 | 115 | |
klauss | 109:a5b8264ffbbc | 116 | int VZ_call::print_yourself ( void ) |
klauss | 104:62646ef786a3 | 117 | { |
klauss | 109:a5b8264ffbbc | 118 | send_msg("t :: %d", ( int ) t.read () ); |
klauss | 109:a5b8264ffbbc | 119 | send_msg("finish :: %d", ( int ) finish.read () ); |
klauss | 109:a5b8264ffbbc | 120 | send_msg("cbx_pkg_idle_timer :: %d", ( int ) cbx_pkg_idle_timer.read () ); |
klauss | 109:a5b8264ffbbc | 121 | send_msg("cb_port :: %d", cb_port ); |
klauss | 109:a5b8264ffbbc | 122 | send_msg("cb2server :: %p", ( void * ) cb2server ); |
klauss | 109:a5b8264ffbbc | 123 | send_msg("server2cb :: %p", ( void * ) server2cb ); |
klauss | 109:a5b8264ffbbc | 124 | send_msg("buffer :: %p", ( void * ) buffer ); |
klauss | 109:a5b8264ffbbc | 125 | send_msg("rtp_sock :: %p", ( void * )&rtp_sock ); |
klauss | 109:a5b8264ffbbc | 126 | send_msg("rtp_server_ext :: %d", rtp_server_ext ); |
klauss | 109:a5b8264ffbbc | 127 | send_msg("rtp_server_port :: %d", rtp_server_port ); |
klauss | 109:a5b8264ffbbc | 128 | send_msg("rtp_server :: %p", &rtp_server ); |
klauss | 109:a5b8264ffbbc | 129 | send_msg("rtp :: %p", ( void * ) rtp ); |
klauss | 109:a5b8264ffbbc | 130 | send_msg("rtpbuf :: %p", ( void * ) &rtpbuf ); |
klauss | 109:a5b8264ffbbc | 131 | return ( sizeof( VZ_call ) ); |
klauss | 109:a5b8264ffbbc | 132 | } |
klauss | 109:a5b8264ffbbc | 133 | |
klauss | 109:a5b8264ffbbc | 134 | void * VZ_call::check_rtp ( void ) { return rtp; } |
klauss | 109:a5b8264ffbbc | 135 | |
klauss | 109:a5b8264ffbbc | 136 | int VZ_call::rtp_print_yourself ( void ) |
klauss | 109:a5b8264ffbbc | 137 | { |
klauss | 109:a5b8264ffbbc | 138 | return rtp -> print_yourself (); |
klauss | 0:4d17cd9c8f9d | 139 | } |