Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
call.cpp@137:32dd35a6dbc9, 2015-11-24 (annotated)
- Committer:
- klauss
- Date:
- Tue Nov 24 14:06:22 2015 +0000
- Revision:
- 137:32dd35a6dbc9
- Parent:
- 135:2f4290590e51
core source of the .bin (09/21/2015) in the field
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 | 132:05cd37f7e007 | 18 | if( debug_memory ) vz_debug ("[%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 | 132:05cd37f7e007 | 33 | char * |
klauss | 132:05cd37f7e007 | 34 | VZ_call::get_eth_message ( int * length ) |
klauss | 132:05cd37f7e007 | 35 | { |
klauss | 0:4d17cd9c8f9d | 36 | uint8_t * pkg; |
klauss | 119:ee6a53069455 | 37 | Endpoint rtp_from; |
klauss | 119:ee6a53069455 | 38 | |
klauss | 132:05cd37f7e007 | 39 | *length = rtp_sock.receiveFrom ( rtp_server, server2cb, sizeof( server2cb ) ); |
klauss | 0:4d17cd9c8f9d | 40 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 41 | |
klauss | 132:05cd37f7e007 | 42 | rtpbuf_next ( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 43 | |
klauss | 132:05cd37f7e007 | 44 | if ( *length > 0 ) |
klauss | 132:05cd37f7e007 | 45 | { |
klauss | 132:05cd37f7e007 | 46 | rtpbuf_put ( &rtpbuf, *length - ( RTP_HEADER_SIZE + ( server2cb [ 0 ] & 0xf ) ), |
klauss | 132:05cd37f7e007 | 47 | ( uint8_t * )server2cb + ( RTP_HEADER_OFFSET + ( server2cb [ 0 ] & 0xf ) ) ); |
klauss | 132:05cd37f7e007 | 48 | } |
klauss | 132:05cd37f7e007 | 49 | else if ( *length == -1 ) |
klauss | 132:05cd37f7e007 | 50 | { |
klauss | 132:05cd37f7e007 | 51 | miss_rtp_udp_rcv_pkg ++; |
klauss | 132:05cd37f7e007 | 52 | reconnect (); |
klauss | 0:4d17cd9c8f9d | 53 | } |
klauss | 0:4d17cd9c8f9d | 54 | |
klauss | 132:05cd37f7e007 | 55 | pkg = rtpbuf_get ( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 56 | |
klauss | 132:05cd37f7e007 | 57 | if ( pkg != NULL ) |
klauss | 132:05cd37f7e007 | 58 | { |
klauss | 0:4d17cd9c8f9d | 59 | *length = 240; |
klauss | 132:05cd37f7e007 | 60 | return (char *)pkg; |
klauss | 0:4d17cd9c8f9d | 61 | } |
klauss | 132:05cd37f7e007 | 62 | |
klauss | 0:4d17cd9c8f9d | 63 | *length = 0; |
klauss | 0:4d17cd9c8f9d | 64 | return NULL; |
klauss | 0:4d17cd9c8f9d | 65 | } |
klauss | 0:4d17cd9c8f9d | 66 | |
klauss | 132:05cd37f7e007 | 67 | int |
klauss | 132:05cd37f7e007 | 68 | VZ_call::send_message ( char * buffer ) |
klauss | 119:ee6a53069455 | 69 | { |
klauss | 132:05cd37f7e007 | 70 | this -> t.reset (); |
klauss | 132:05cd37f7e007 | 71 | const uint16_t SEND_MSG_SIZE = CB_AUDIO_DATA_SIZE + this -> rtp -> header_size (); |
klauss | 132:05cd37f7e007 | 72 | |
klauss | 132:05cd37f7e007 | 73 | int send = this -> rtp_sock.sendTo ( this -> rtp_server, buffer, SEND_MSG_SIZE ); |
klauss | 132:05cd37f7e007 | 74 | |
klauss | 132:05cd37f7e007 | 75 | if ( send not_eq SEND_MSG_SIZE ) |
klauss | 135:2f4290590e51 | 76 | { |
klauss | 132:05cd37f7e007 | 77 | miss_rtp_udp_send_pkg ++; |
klauss | 132:05cd37f7e007 | 78 | |
klauss | 132:05cd37f7e007 | 79 | reconnect (); |
klauss | 119:ee6a53069455 | 80 | } |
klauss | 132:05cd37f7e007 | 81 | |
klauss | 132:05cd37f7e007 | 82 | return ( send ); |
klauss | 114:472502b31a12 | 83 | } |
klauss | 0:4d17cd9c8f9d | 84 | |
klauss | 0:4d17cd9c8f9d | 85 | char * VZ_call::build_eth_package( uint8_t * buffer ){ |
klauss | 0:4d17cd9c8f9d | 86 | return this->rtp->build_eth_package( ( char * )buffer ); |
klauss | 0:4d17cd9c8f9d | 87 | } |
klauss | 0:4d17cd9c8f9d | 88 | |
klauss | 119:ee6a53069455 | 89 | int VZ_call::get_cb_ext () |
klauss | 119:ee6a53069455 | 90 | { |
klauss | 119:ee6a53069455 | 91 | return this->cb_ext; |
klauss | 119:ee6a53069455 | 92 | } |
klauss | 119:ee6a53069455 | 93 | |
klauss | 119:ee6a53069455 | 94 | int VZ_call::get_cb_port () |
klauss | 119:ee6a53069455 | 95 | { |
klauss | 119:ee6a53069455 | 96 | return this->cb_port; |
klauss | 119:ee6a53069455 | 97 | } |
klauss | 0:4d17cd9c8f9d | 98 | |
klauss | 0:4d17cd9c8f9d | 99 | int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; } |
klauss | 0:4d17cd9c8f9d | 100 | int VZ_call::get_rtp_server_port(){ return rtp_server_port; } |
klauss | 119:ee6a53069455 | 101 | |
klauss | 0:4d17cd9c8f9d | 102 | bool VZ_call::is_timetofinish( void ){ |
klauss | 0:4d17cd9c8f9d | 103 | return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false; |
klauss | 92:92df17f538a8 | 104 | } |
klauss | 92:92df17f538a8 | 105 | |
klauss | 119:ee6a53069455 | 106 | uint16_t VZ_call::get_elapsed_time( void ){ |
klauss | 92:92df17f538a8 | 107 | return ( finish.read_ms() ); |
klauss | 92:92df17f538a8 | 108 | } |
klauss | 92:92df17f538a8 | 109 | |
klauss | 132:05cd37f7e007 | 110 | void VZ_call::cbx_pkg_idle_timer_reset ( void ){ |
klauss | 92:92df17f538a8 | 111 | cbx_pkg_idle_timer.reset(); |
klauss | 92:92df17f538a8 | 112 | } |
klauss | 92:92df17f538a8 | 113 | |
klauss | 92:92df17f538a8 | 114 | bool VZ_call::cbx_pkg_is_idle( void ){ |
klauss | 92:92df17f538a8 | 115 | return ( cbx_pkg_idle_timer.read() > CBX_PKG_IDLE_MAX_TIME ) ? true : false; |
klauss | 92:92df17f538a8 | 116 | } |
klauss | 92:92df17f538a8 | 117 | |
klauss | 92:92df17f538a8 | 118 | void VZ_call::init_cbx_pkg_idle_timer(){ |
klauss | 92:92df17f538a8 | 119 | cbx_pkg_idle_timer.start(); |
klauss | 104:62646ef786a3 | 120 | } |
klauss | 104:62646ef786a3 | 121 | |
klauss | 109:a5b8264ffbbc | 122 | int VZ_call::print_yourself ( void ) |
klauss | 104:62646ef786a3 | 123 | { |
klauss | 132:05cd37f7e007 | 124 | vz_printf ("t :: %d", ( int ) t.read () ); |
klauss | 132:05cd37f7e007 | 125 | vz_printf ("finish :: %d", ( int ) finish.read () ); |
klauss | 132:05cd37f7e007 | 126 | vz_printf ("cbx_pkg_idle_timer :: %d", ( int ) cbx_pkg_idle_timer.read () ); |
klauss | 132:05cd37f7e007 | 127 | vz_printf ("cb_port :: %d", cb_port ); |
klauss | 132:05cd37f7e007 | 128 | vz_printf ("cb2server :: %p", ( void * ) cb2server ); |
klauss | 132:05cd37f7e007 | 129 | vz_printf ("server2cb :: %p", ( void * ) server2cb ); |
klauss | 132:05cd37f7e007 | 130 | vz_printf ("buffer :: %p", ( void * ) buffer ); |
klauss | 132:05cd37f7e007 | 131 | vz_printf ("rtp_sock :: %p", ( void * )&rtp_sock ); |
klauss | 132:05cd37f7e007 | 132 | vz_printf ("rtp_server_ext :: %d", rtp_server_ext ); |
klauss | 132:05cd37f7e007 | 133 | vz_printf ("rtp_server_port :: %d", rtp_server_port ); |
klauss | 132:05cd37f7e007 | 134 | vz_printf ("rtp_server :: %p", &rtp_server ); |
klauss | 132:05cd37f7e007 | 135 | vz_printf ("rtp :: %p", ( void * ) rtp ); |
klauss | 132:05cd37f7e007 | 136 | vz_printf ("rtpbuf :: %p", ( void * ) &rtpbuf ); |
klauss | 109:a5b8264ffbbc | 137 | return ( sizeof( VZ_call ) ); |
klauss | 109:a5b8264ffbbc | 138 | } |
klauss | 109:a5b8264ffbbc | 139 | |
klauss | 109:a5b8264ffbbc | 140 | void * VZ_call::check_rtp ( void ) { return rtp; } |
klauss | 109:a5b8264ffbbc | 141 | |
klauss | 109:a5b8264ffbbc | 142 | int VZ_call::rtp_print_yourself ( void ) |
klauss | 109:a5b8264ffbbc | 143 | { |
klauss | 109:a5b8264ffbbc | 144 | return rtp -> print_yourself (); |
klauss | 119:ee6a53069455 | 145 | } |
klauss | 119:ee6a53069455 | 146 | |
klauss | 132:05cd37f7e007 | 147 | void |
klauss | 132:05cd37f7e007 | 148 | VZ_call::reconnect ( void ) |
klauss | 119:ee6a53069455 | 149 | { |
klauss | 132:05cd37f7e007 | 150 | this -> rtp_sock.close (); |
klauss | 132:05cd37f7e007 | 151 | |
klauss | 132:05cd37f7e007 | 152 | this -> rtp_sock.bind ( cb_port ); |
klauss | 132:05cd37f7e007 | 153 | |
klauss | 132:05cd37f7e007 | 154 | this -> rtp_sock.set_blocking ( false, 0 ); |
klauss | 0:4d17cd9c8f9d | 155 | } |