![](/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.h
- Revision:
- 40:990683572031
- Parent:
- 39:89e023ea5968
- Child:
- 42:480335bdde12
--- a/eth.h Thu Oct 02 12:38:42 2014 +0000 +++ b/eth.h Thu Oct 02 18:19:54 2014 +0000 @@ -1,47 +1,82 @@ #ifndef __ETH_H__ #define __ETH_H__ +#include "prompt.h" #include "debug.h" #include "vz_protocol.h" + #define udp_idle 0x00 #define udp_waiting_start_pkg 0x01 #define udp_listen 0x02 -class vz_eth{ - private : - UDPSocket udp_server; - Endpoint udp_client; - public : - vz_eth(); - int is_start_pkg( uint8_t * data ); - int is_stop_pkg( uint8_t * data ); - int is_time_to_stop( uint8_t * data ); - char * listen_eth_udp( char * buffer, int *length ); -}; -/* +int 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 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 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 ); +} + char * listen_eth_udp( char * buffer, int *length ){ static UDPSocket server; server.set_blocking( false, 2 ); server.bind( UDP_PORT_LISTENER ); Endpoint client; + bool valid_reboot = false; + uint8_t * data = NULL; + static int ext; + static int port; + static uint8_t type; + static Timer t; + static uint8_t status = udp_idle; + static uint8_t seq_num = 0; // OBS sizeof( buffer ) == 4 ???? - //length = server.receiveFrom( client, buffer, sizeof( buffer ) ); + + //*length = server.receiveFrom( client, buffer, sizeof( buffer ) ); *length = server.receiveFrom( client, buffer, __UDP_ETH_BUFFER_SIZE__ ); - if( *length > 0 ){ + if( *length > 0){ buffer[ *length ] = '\0'; buffer[ strlen( buffer ) - 1 ] = '\0'; + t.start(); - //debug_msg("%s", buffer ); - //buffer = prompt_process( buffer ); + debug_msg("%s", buffer ); + buffer = prompt_process( buffer ); - debug_msg("Received UDP Pkg :: %s", buffer ); - return( buffer ); - //int sent = server.sendTo( client, buffer, strlen( buffer ) ); - //debug_msg("Sent %d bytes", sent ); + if( buffer ){ + debug_msg("--%s--", buffer ); + //server.sendTo( client, buffer, sizeof( buffer ) ); + //int sent = server.sendTo( client, buffer, __UDP_ETH_BUFFER_SIZE__ ); + int sent = server.sendTo( client, buffer, strlen( buffer ) ); + debug_msg("Sent %d", sent ); + } - }else return( NULL ); + return( NULL ); + data = __parse_vz_pkg__( &ext, &port, &type, (uint8_t *)buffer ); if( !data ){ @@ -122,6 +157,5 @@ }else return( NULL ); return( NULL ); } -*/ #endif \ No newline at end of file