![](/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
Diff: eth.cpp
- Revision:
- 39:89e023ea5968
diff -r af5ecd6997ab -r 89e023ea5968 eth.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eth.cpp Thu Oct 02 12:38:42 2014 +0000 @@ -0,0 +1,52 @@ +#include "eth.h" + +vz_eth::vz_eth(){ + udp_server.set_blocking( false, 2 ); + udp_server.bind( UDP_PORT_LISTENER ); +} + + +char * vz_eth::listen_eth_udp( char * buffer, int *length ){ + // OBS sizeof( buffer ) == 4 ???? + //*length = server.receiveFrom( client, buffer, sizeof( buffer ) ); + *length = udp_server.receiveFrom( udp_client, buffer, __UDP_ETH_BUFFER_SIZE__ ); + + if( *length > 0 ){ + buffer[ *length ] = '\0'; + buffer[ strlen( buffer ) - 1 ] = '\0'; + debug_msg("Received UDP Pkg :: %s", buffer ); + return( buffer ); + }else return( NULL ); +} + +int vz_eth::is_start_pkg( uint8_t * data ){ + //seq_num must to be 0s + if( !data ) return -1; + + for( register int i = __VZ_HEADER_OFFSET__; i < __UDP_ETH_BUFFER_SIZE__; i++ ) if( data[ i ] ) return( 0 ); + + return( 1 ); +} + +int vz_eth::is_stop_pkg( uint8_t * data ){ + //seq_num must to be 0s + if( !data ) return -1; + + for( register int i = __VZ_HEADER_OFFSET__; i < __UDP_ETH_BUFFER_SIZE__; i++ ) if( data[ i ] ) return( 0 ); + + return( 1 ); +} + + +int vz_eth::is_time_to_stop( uint8_t * data ){ + static int count = 0; + if( !data ) return( 0 ); + + if( is_stop_pkg( data ) == 1 ) count++; + + else count = 0; + + if( count == 10 ) return( 1 ); + + else return( 0 ); +} \ No newline at end of file