![](/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
eth.cpp@39:89e023ea5968, 2014-10-02 (annotated)
- Committer:
- klauss
- Date:
- Thu Oct 02 12:38:42 2014 +0000
- Revision:
- 39:89e023ea5968
melhor estruturacao da classe eth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 39:89e023ea5968 | 1 | #include "eth.h" |
klauss | 39:89e023ea5968 | 2 | |
klauss | 39:89e023ea5968 | 3 | vz_eth::vz_eth(){ |
klauss | 39:89e023ea5968 | 4 | udp_server.set_blocking( false, 2 ); |
klauss | 39:89e023ea5968 | 5 | udp_server.bind( UDP_PORT_LISTENER ); |
klauss | 39:89e023ea5968 | 6 | } |
klauss | 39:89e023ea5968 | 7 | |
klauss | 39:89e023ea5968 | 8 | |
klauss | 39:89e023ea5968 | 9 | char * vz_eth::listen_eth_udp( char * buffer, int *length ){ |
klauss | 39:89e023ea5968 | 10 | // OBS sizeof( buffer ) == 4 ???? |
klauss | 39:89e023ea5968 | 11 | //*length = server.receiveFrom( client, buffer, sizeof( buffer ) ); |
klauss | 39:89e023ea5968 | 12 | *length = udp_server.receiveFrom( udp_client, buffer, __UDP_ETH_BUFFER_SIZE__ ); |
klauss | 39:89e023ea5968 | 13 | |
klauss | 39:89e023ea5968 | 14 | if( *length > 0 ){ |
klauss | 39:89e023ea5968 | 15 | buffer[ *length ] = '\0'; |
klauss | 39:89e023ea5968 | 16 | buffer[ strlen( buffer ) - 1 ] = '\0'; |
klauss | 39:89e023ea5968 | 17 | debug_msg("Received UDP Pkg :: %s", buffer ); |
klauss | 39:89e023ea5968 | 18 | return( buffer ); |
klauss | 39:89e023ea5968 | 19 | }else return( NULL ); |
klauss | 39:89e023ea5968 | 20 | } |
klauss | 39:89e023ea5968 | 21 | |
klauss | 39:89e023ea5968 | 22 | int vz_eth::is_start_pkg( uint8_t * data ){ |
klauss | 39:89e023ea5968 | 23 | //seq_num must to be 0s |
klauss | 39:89e023ea5968 | 24 | if( !data ) return -1; |
klauss | 39:89e023ea5968 | 25 | |
klauss | 39:89e023ea5968 | 26 | for( register int i = __VZ_HEADER_OFFSET__; i < __UDP_ETH_BUFFER_SIZE__; i++ ) if( data[ i ] ) return( 0 ); |
klauss | 39:89e023ea5968 | 27 | |
klauss | 39:89e023ea5968 | 28 | return( 1 ); |
klauss | 39:89e023ea5968 | 29 | } |
klauss | 39:89e023ea5968 | 30 | |
klauss | 39:89e023ea5968 | 31 | int vz_eth::is_stop_pkg( uint8_t * data ){ |
klauss | 39:89e023ea5968 | 32 | //seq_num must to be 0s |
klauss | 39:89e023ea5968 | 33 | if( !data ) return -1; |
klauss | 39:89e023ea5968 | 34 | |
klauss | 39:89e023ea5968 | 35 | for( register int i = __VZ_HEADER_OFFSET__; i < __UDP_ETH_BUFFER_SIZE__; i++ ) if( data[ i ] ) return( 0 ); |
klauss | 39:89e023ea5968 | 36 | |
klauss | 39:89e023ea5968 | 37 | return( 1 ); |
klauss | 39:89e023ea5968 | 38 | } |
klauss | 39:89e023ea5968 | 39 | |
klauss | 39:89e023ea5968 | 40 | |
klauss | 39:89e023ea5968 | 41 | int vz_eth::is_time_to_stop( uint8_t * data ){ |
klauss | 39:89e023ea5968 | 42 | static int count = 0; |
klauss | 39:89e023ea5968 | 43 | if( !data ) return( 0 ); |
klauss | 39:89e023ea5968 | 44 | |
klauss | 39:89e023ea5968 | 45 | if( is_stop_pkg( data ) == 1 ) count++; |
klauss | 39:89e023ea5968 | 46 | |
klauss | 39:89e023ea5968 | 47 | else count = 0; |
klauss | 39:89e023ea5968 | 48 | |
klauss | 39:89e023ea5968 | 49 | if( count == 10 ) return( 1 ); |
klauss | 39:89e023ea5968 | 50 | |
klauss | 39:89e023ea5968 | 51 | else return( 0 ); |
klauss | 39:89e023ea5968 | 52 | } |