![](/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@119:ee6a53069455, 2015-04-30 (annotated)
- Committer:
- klauss
- Date:
- Thu Apr 30 15:42:41 2015 +0000
- Revision:
- 119:ee6a53069455
- Parent:
- 117:e9facba9db27
- Child:
- 121:ee02790d00b7
funcionalidade - clock "ogro" - implementada
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 | 119:ee6a53069455 | 9 | this->rtp_server.set_address( SERVER_IP, rtp_server_port ); |
klauss | 114:472502b31a12 | 10 | rtp_sock.set_blocking( false, 0 ); |
klauss | 114:472502b31a12 | 11 | this->rtp_sock.bind( cb_port ); // rtp port |
klauss | 114:472502b31a12 | 12 | this->rtp_sock.init(); |
klauss | 0:4d17cd9c8f9d | 13 | this->rtp = new RTP( this->cb_ext ); |
klauss | 0:4d17cd9c8f9d | 14 | |
klauss | 89:0fe315117b00 | 15 | if( rtp == NULL ) |
klauss | 89:0fe315117b00 | 16 | { |
klauss | 89:0fe315117b00 | 17 | memory_is_over = true; |
klauss | 119:ee6a53069455 | 18 | if( debug_memory ) debug_msg("[%d] Call_Box cb allocation fail", this->cb_ext ); |
klauss | 89:0fe315117b00 | 19 | } |
klauss | 87:679ee0d594a9 | 20 | |
klauss | 0:4d17cd9c8f9d | 21 | t.start(); |
klauss | 0:4d17cd9c8f9d | 22 | finish.start(); |
klauss | 0:4d17cd9c8f9d | 23 | rtpbuf_clear( &( this->rtpbuf ) ); |
klauss | 91:c2a86b1f8aaa | 24 | call_new_counter++; |
klauss | 0:4d17cd9c8f9d | 25 | } |
klauss | 0:4d17cd9c8f9d | 26 | |
klauss | 0:4d17cd9c8f9d | 27 | VZ_call::~VZ_call(){ |
klauss | 0:4d17cd9c8f9d | 28 | rtp_sock.close(); |
klauss | 0:4d17cd9c8f9d | 29 | delete( this->rtp ); |
klauss | 91:c2a86b1f8aaa | 30 | call_delete_counter++; |
klauss | 0:4d17cd9c8f9d | 31 | } |
klauss | 0:4d17cd9c8f9d | 32 | |
klauss | 0:4d17cd9c8f9d | 33 | char * VZ_call::get_eth_message( int * length ){ |
klauss | 0:4d17cd9c8f9d | 34 | uint8_t * pkg; |
klauss | 119:ee6a53069455 | 35 | Endpoint rtp_from; |
klauss | 119:ee6a53069455 | 36 | |
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 | 119:ee6a53069455 | 57 | int VZ_call::send_message ( char * buffer ) |
klauss | 119:ee6a53069455 | 58 | { |
klauss | 119:ee6a53069455 | 59 | this->t.reset(); |
klauss | 119:ee6a53069455 | 60 | int send = this->rtp_sock.sendTo( this->rtp_server, buffer, CB_AUDIO_DATA_SIZE + this->rtp->header_size() ); |
klauss | 119:ee6a53069455 | 61 | if( send != CB_AUDIO_DATA_SIZE + this->rtp->header_size() ) |
klauss | 119:ee6a53069455 | 62 | { |
klauss | 119:ee6a53069455 | 63 | if( debug_reconnect ) |
klauss | 119:ee6a53069455 | 64 | { |
klauss | 119:ee6a53069455 | 65 | send_msg("[%d] Reconnect RTP", this->cb_ext ); |
klauss | 119:ee6a53069455 | 66 | miss_ftp_udp_send_pkg++; |
klauss | 119:ee6a53069455 | 67 | } |
klauss | 119:ee6a53069455 | 68 | reconnect(); |
klauss | 119:ee6a53069455 | 69 | } |
klauss | 119:ee6a53069455 | 70 | return( send ); |
klauss | 114:472502b31a12 | 71 | } |
klauss | 0:4d17cd9c8f9d | 72 | |
klauss | 0:4d17cd9c8f9d | 73 | char * VZ_call::build_eth_package( uint8_t * buffer ){ |
klauss | 0:4d17cd9c8f9d | 74 | return this->rtp->build_eth_package( ( char * )buffer ); |
klauss | 0:4d17cd9c8f9d | 75 | } |
klauss | 0:4d17cd9c8f9d | 76 | |
klauss | 119:ee6a53069455 | 77 | int VZ_call::get_cb_ext () |
klauss | 119:ee6a53069455 | 78 | { |
klauss | 119:ee6a53069455 | 79 | return this->cb_ext; |
klauss | 119:ee6a53069455 | 80 | } |
klauss | 119:ee6a53069455 | 81 | |
klauss | 119:ee6a53069455 | 82 | int VZ_call::get_cb_port () |
klauss | 119:ee6a53069455 | 83 | { |
klauss | 119:ee6a53069455 | 84 | return this->cb_port; |
klauss | 119:ee6a53069455 | 85 | } |
klauss | 0:4d17cd9c8f9d | 86 | |
klauss | 0:4d17cd9c8f9d | 87 | int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; } |
klauss | 0:4d17cd9c8f9d | 88 | int VZ_call::get_rtp_server_port(){ return rtp_server_port; } |
klauss | 119:ee6a53069455 | 89 | |
klauss | 0:4d17cd9c8f9d | 90 | uint8_t * VZ_call::get_cb2server_buffer(){ return cb2server; } |
klauss | 0:4d17cd9c8f9d | 91 | char * VZ_call::get_server2cb_buffer(){ return server2cb; } |
klauss | 0:4d17cd9c8f9d | 92 | inline uint8_t * VZ_call::get_buffer(){ return buffer; } |
klauss | 0:4d17cd9c8f9d | 93 | |
klauss | 0:4d17cd9c8f9d | 94 | bool VZ_call::is_timeout( void ){ |
klauss | 0:4d17cd9c8f9d | 95 | return ( t.read() > __CALL_MAX_IDLE_TIME__ ) ? true : false; |
klauss | 0:4d17cd9c8f9d | 96 | } |
klauss | 0:4d17cd9c8f9d | 97 | |
klauss | 0:4d17cd9c8f9d | 98 | bool VZ_call::is_timetofinish( void ){ |
klauss | 0:4d17cd9c8f9d | 99 | return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false; |
klauss | 92:92df17f538a8 | 100 | } |
klauss | 92:92df17f538a8 | 101 | |
klauss | 119:ee6a53069455 | 102 | uint16_t VZ_call::get_elapsed_time( void ){ |
klauss | 92:92df17f538a8 | 103 | return ( finish.read_ms() ); |
klauss | 92:92df17f538a8 | 104 | } |
klauss | 92:92df17f538a8 | 105 | |
klauss | 92:92df17f538a8 | 106 | void VZ_call::cbx_pkg_idle_timer_reset( void ){ |
klauss | 92:92df17f538a8 | 107 | cbx_pkg_idle_timer.reset(); |
klauss | 92:92df17f538a8 | 108 | } |
klauss | 92:92df17f538a8 | 109 | |
klauss | 92:92df17f538a8 | 110 | bool VZ_call::cbx_pkg_is_idle( void ){ |
klauss | 92:92df17f538a8 | 111 | return ( cbx_pkg_idle_timer.read() > CBX_PKG_IDLE_MAX_TIME ) ? true : false; |
klauss | 92:92df17f538a8 | 112 | } |
klauss | 92:92df17f538a8 | 113 | |
klauss | 92:92df17f538a8 | 114 | void VZ_call::init_cbx_pkg_idle_timer(){ |
klauss | 92:92df17f538a8 | 115 | cbx_pkg_idle_timer.start(); |
klauss | 104:62646ef786a3 | 116 | } |
klauss | 104:62646ef786a3 | 117 | |
klauss | 109:a5b8264ffbbc | 118 | int VZ_call::print_yourself ( void ) |
klauss | 104:62646ef786a3 | 119 | { |
klauss | 109:a5b8264ffbbc | 120 | send_msg("t :: %d", ( int ) t.read () ); |
klauss | 109:a5b8264ffbbc | 121 | send_msg("finish :: %d", ( int ) finish.read () ); |
klauss | 109:a5b8264ffbbc | 122 | send_msg("cbx_pkg_idle_timer :: %d", ( int ) cbx_pkg_idle_timer.read () ); |
klauss | 109:a5b8264ffbbc | 123 | send_msg("cb_port :: %d", cb_port ); |
klauss | 109:a5b8264ffbbc | 124 | send_msg("cb2server :: %p", ( void * ) cb2server ); |
klauss | 109:a5b8264ffbbc | 125 | send_msg("server2cb :: %p", ( void * ) server2cb ); |
klauss | 109:a5b8264ffbbc | 126 | send_msg("buffer :: %p", ( void * ) buffer ); |
klauss | 109:a5b8264ffbbc | 127 | send_msg("rtp_sock :: %p", ( void * )&rtp_sock ); |
klauss | 109:a5b8264ffbbc | 128 | send_msg("rtp_server_ext :: %d", rtp_server_ext ); |
klauss | 109:a5b8264ffbbc | 129 | send_msg("rtp_server_port :: %d", rtp_server_port ); |
klauss | 109:a5b8264ffbbc | 130 | send_msg("rtp_server :: %p", &rtp_server ); |
klauss | 109:a5b8264ffbbc | 131 | send_msg("rtp :: %p", ( void * ) rtp ); |
klauss | 109:a5b8264ffbbc | 132 | send_msg("rtpbuf :: %p", ( void * ) &rtpbuf ); |
klauss | 109:a5b8264ffbbc | 133 | return ( sizeof( VZ_call ) ); |
klauss | 109:a5b8264ffbbc | 134 | } |
klauss | 109:a5b8264ffbbc | 135 | |
klauss | 109:a5b8264ffbbc | 136 | void * VZ_call::check_rtp ( void ) { return rtp; } |
klauss | 109:a5b8264ffbbc | 137 | |
klauss | 109:a5b8264ffbbc | 138 | int VZ_call::rtp_print_yourself ( void ) |
klauss | 109:a5b8264ffbbc | 139 | { |
klauss | 109:a5b8264ffbbc | 140 | return rtp -> print_yourself (); |
klauss | 119:ee6a53069455 | 141 | } |
klauss | 119:ee6a53069455 | 142 | |
klauss | 119:ee6a53069455 | 143 | void VZ_call::reconnect ( void ) |
klauss | 119:ee6a53069455 | 144 | { |
klauss | 119:ee6a53069455 | 145 | this->rtp_sock.close(); |
klauss | 119:ee6a53069455 | 146 | this->rtp_sock.set_blocking( false, 0 ); |
klauss | 119:ee6a53069455 | 147 | this->rtp_sock.bind( cb_port ); |
klauss | 0:4d17cd9c8f9d | 148 | } |