![](/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@89:0fe315117b00, 2015-01-07 (annotated)
- Committer:
- klauss
- Date:
- Wed Jan 07 21:48:53 2015 +0000
- Revision:
- 89:0fe315117b00
- Parent:
- 87:679ee0d594a9
- Child:
- 91:c2a86b1f8aaa
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 | 89:0fe315117b00 | 10 | //rtp_sock.set_blocking( false, 3 ); |
klauss | 89:0fe315117b00 | 11 | rtp_sock.set_blocking( false, 0 ); |
klauss | 0:4d17cd9c8f9d | 12 | this->rtp_sock.bind( cb_port ); // rtp port |
klauss | 0:4d17cd9c8f9d | 13 | this->rtp_sock.init(); |
klauss | 0:4d17cd9c8f9d | 14 | this->rtp = new RTP( this->cb_ext ); |
klauss | 0:4d17cd9c8f9d | 15 | |
klauss | 89:0fe315117b00 | 16 | if( rtp == NULL ) |
klauss | 89:0fe315117b00 | 17 | { |
klauss | 89:0fe315117b00 | 18 | memory_is_over = true; |
klauss | 89:0fe315117b00 | 19 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
klauss | 89:0fe315117b00 | 20 | } |
klauss | 87:679ee0d594a9 | 21 | |
klauss | 0:4d17cd9c8f9d | 22 | t.start(); |
klauss | 0:4d17cd9c8f9d | 23 | finish.start(); |
klauss | 0:4d17cd9c8f9d | 24 | rtpbuf_clear( &( this->rtpbuf ) ); |
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 | 0:4d17cd9c8f9d | 30 | } |
klauss | 0:4d17cd9c8f9d | 31 | |
klauss | 0:4d17cd9c8f9d | 32 | char * VZ_call::get_eth_message( int * length ){ |
klauss | 0:4d17cd9c8f9d | 33 | uint8_t * pkg; |
klauss | 0:4d17cd9c8f9d | 34 | *length = rtp_sock.receiveFrom( rtp_server, server2cb, sizeof( server2cb ) ); |
klauss | 0:4d17cd9c8f9d | 35 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 36 | |
klauss | 0:4d17cd9c8f9d | 37 | rtpbuf_next( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 38 | |
klauss | 0:4d17cd9c8f9d | 39 | if( *length > 0 ){ |
klauss | 85:b6f2dc1d0f4f | 40 | eth_pkg_received++; |
klauss | 85:b6f2dc1d0f4f | 41 | |
klauss | 0:4d17cd9c8f9d | 42 | rtpbuf_put( &rtpbuf, *length - ( __RTP_HEADER_SIZE__ + ( server2cb[ 0 ] & 0xf ) ), |
klauss | 0:4d17cd9c8f9d | 43 | ( uint8_t * )server2cb + ( __RTP_HEADER_OFFSET__ + ( server2cb[ 0 ] & 0xf ) ) ); |
klauss | 0:4d17cd9c8f9d | 44 | } |
klauss | 0:4d17cd9c8f9d | 45 | |
klauss | 0:4d17cd9c8f9d | 46 | pkg = rtpbuf_get( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 47 | |
klauss | 0:4d17cd9c8f9d | 48 | if (pkg != NULL) { |
klauss | 0:4d17cd9c8f9d | 49 | *length = 240; |
klauss | 0:4d17cd9c8f9d | 50 | return (char *) pkg; |
klauss | 0:4d17cd9c8f9d | 51 | } |
klauss | 0:4d17cd9c8f9d | 52 | *length = 0; |
klauss | 0:4d17cd9c8f9d | 53 | return NULL; |
klauss | 0:4d17cd9c8f9d | 54 | } |
klauss | 0:4d17cd9c8f9d | 55 | |
klauss | 0:4d17cd9c8f9d | 56 | int VZ_call::send_message( char * buffer ){ |
klauss | 0:4d17cd9c8f9d | 57 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 58 | return( this->rtp_sock.sendTo( this->rtp_server, buffer, __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ) ); |
klauss | 81:3656f00ab3db | 59 | |
klauss | 81:3656f00ab3db | 60 | /* |
klauss | 81:3656f00ab3db | 61 | //FIXME verificar como fica se eu esperar o sendTo chegar em != 0 |
klauss | 81:3656f00ab3db | 62 | int8_t sent = 0; |
klauss | 81:3656f00ab3db | 63 | do{ |
klauss | 81:3656f00ab3db | 64 | sent = this->rtp_sock.sendTo( this->rtp_server, buffer, __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ) ); |
klauss | 81:3656f00ab3db | 65 | }while( sent == 0 ); |
klauss | 81:3656f00ab3db | 66 | return( sent ); |
klauss | 81:3656f00ab3db | 67 | */ |
klauss | 0:4d17cd9c8f9d | 68 | } |
klauss | 0:4d17cd9c8f9d | 69 | |
klauss | 0:4d17cd9c8f9d | 70 | uint8_t * VZ_call::build_cb_package( void ){ |
klauss | 0:4d17cd9c8f9d | 71 | // return __build_cb_package__( cb_ext, cb_port, __AUDIO__, server2cb, buffer ); |
klauss | 0:4d17cd9c8f9d | 72 | // colocar esta funcao novamente pra envio de msg, assim como encapsular melhor a funcao |
klauss | 0:4d17cd9c8f9d | 73 | // de criacao dos pacotes pro cb em algumas funcoes. |
klauss | 0:4d17cd9c8f9d | 74 | return 0x00; |
klauss | 0:4d17cd9c8f9d | 75 | } |
klauss | 0:4d17cd9c8f9d | 76 | |
klauss | 0:4d17cd9c8f9d | 77 | char * VZ_call::build_eth_package( uint8_t * buffer ){ |
klauss | 0:4d17cd9c8f9d | 78 | return this->rtp->build_eth_package( ( char * )buffer ); |
klauss | 0:4d17cd9c8f9d | 79 | } |
klauss | 0:4d17cd9c8f9d | 80 | |
klauss | 0:4d17cd9c8f9d | 81 | int VZ_call::get_cb_ext(){ return this->cb_ext; } |
klauss | 0:4d17cd9c8f9d | 82 | int VZ_call::get_cb_port(){ return this->cb_port; } |
klauss | 0:4d17cd9c8f9d | 83 | |
klauss | 0:4d17cd9c8f9d | 84 | int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; } |
klauss | 0:4d17cd9c8f9d | 85 | int VZ_call::get_rtp_server_port(){ return rtp_server_port; } |
klauss | 0:4d17cd9c8f9d | 86 | uint8_t * VZ_call::get_cb2server_buffer(){ return cb2server; } |
klauss | 0:4d17cd9c8f9d | 87 | char * VZ_call::get_server2cb_buffer(){ return server2cb; } |
klauss | 0:4d17cd9c8f9d | 88 | inline uint8_t * VZ_call::get_buffer(){ return buffer; } |
klauss | 0:4d17cd9c8f9d | 89 | |
klauss | 0:4d17cd9c8f9d | 90 | bool VZ_call::is_timeout( void ){ |
klauss | 0:4d17cd9c8f9d | 91 | return ( t.read() > __CALL_MAX_IDLE_TIME__ ) ? true : false; |
klauss | 0:4d17cd9c8f9d | 92 | } |
klauss | 0:4d17cd9c8f9d | 93 | |
klauss | 0:4d17cd9c8f9d | 94 | bool VZ_call::is_timetofinish( void ){ |
klauss | 0:4d17cd9c8f9d | 95 | return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false; |
klauss | 0:4d17cd9c8f9d | 96 | } |