Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: eth.h
- Revision:
- 33:735fd60e96d8
- Child:
- 34:f19d9735428e
diff -r 43041f5e27c4 -r 735fd60e96d8 eth.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eth.h Tue Sep 30 11:37:31 2014 +0000 @@ -0,0 +1,77 @@ +#ifndef __ETH_H__ +#define __ETH_H__ + +#include "prompt.h" +#include "debug.h" + +#define UDP_PORT_LISTENER 11406 + +char * listen_eth_udp( char * buffer, int *length ){ + UDPSocket server; + server.set_blocking( false, 1 ); + server.bind( UDP_PORT_LISTENER ); + Endpoint client; + static Timer t; + static int count = 0; + static int param = 100; + + *length = server.receiveFrom( client, buffer, sizeof(buffer ) ); + + if( *length > 0){ + buffer[ *length ] = '\0'; + t.start(); + if( count >= 0 ){ + if( count == 0 ); // enviar pacote de "entendi o request de volta" + + if( atoi( buffer ) == 0 ) count++; + + else count = 0; + } + if( count == param ){ + debug_msg( "Received start pkgs" ); + if( t.read() < 10 ){ + param = 1000; + server.set_blocking( true, 10 ); + t.reset(); + + count = 0; + while( atoi( buffer ) == 0 && t.read() < 10 ){ + *length = server.receiveFrom( client, buffer, sizeof( buffer ) ); + wdt.kick(); + } + + if( t.read() > 10 ) return( NULL ); + + else{ + //tratar o primeiro pkg depois dos zeros aqui + count++; + while( count < 6000 ){ + wdt.kick(); + *length = server.receiveFrom( client, buffer, sizeof( buffer ) ); + if( ++count == param ){ + debug_msg(" Received %04d - Sent %04d - Missed %04d - %.3f", count, atoi( buffer ), atoi( buffer ) - count, ( (float)count )/( atoi( buffer ) ) ); + param += 1000; + } + } + //pensar em como validar os pacotes recebidos, cks ... e o que mais ? + //se validado os pkgs, dar reset com os dados no arquivo bla, caso contrario, ignorar ... + bool valid_reboot = false; + if( valid_reboot ) NVIC_SystemReset(); + + else{ + count = 0; + param = 100; + server.set_blocking( false, 1 ); + t.stop(); + t.reset(); + debug_msg("Nao Resetando ... "); + } + + } + } + }else return( buffer ); + }else return( NULL ); + return( NULL ); +} + +#endif \ No newline at end of file