![](/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.h@33:735fd60e96d8, 2014-09-30 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 30 11:37:31 2014 +0000
- Revision:
- 33:735fd60e96d8
- Child:
- 34:f19d9735428e
versao 1 do protocolo de comunicao udp pra comunicao externa com a header e consequentemente, criacao do bootloader
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 33:735fd60e96d8 | 1 | #ifndef __ETH_H__ |
klauss | 33:735fd60e96d8 | 2 | #define __ETH_H__ |
klauss | 33:735fd60e96d8 | 3 | |
klauss | 33:735fd60e96d8 | 4 | #include "prompt.h" |
klauss | 33:735fd60e96d8 | 5 | #include "debug.h" |
klauss | 33:735fd60e96d8 | 6 | |
klauss | 33:735fd60e96d8 | 7 | #define UDP_PORT_LISTENER 11406 |
klauss | 33:735fd60e96d8 | 8 | |
klauss | 33:735fd60e96d8 | 9 | char * listen_eth_udp( char * buffer, int *length ){ |
klauss | 33:735fd60e96d8 | 10 | UDPSocket server; |
klauss | 33:735fd60e96d8 | 11 | server.set_blocking( false, 1 ); |
klauss | 33:735fd60e96d8 | 12 | server.bind( UDP_PORT_LISTENER ); |
klauss | 33:735fd60e96d8 | 13 | Endpoint client; |
klauss | 33:735fd60e96d8 | 14 | static Timer t; |
klauss | 33:735fd60e96d8 | 15 | static int count = 0; |
klauss | 33:735fd60e96d8 | 16 | static int param = 100; |
klauss | 33:735fd60e96d8 | 17 | |
klauss | 33:735fd60e96d8 | 18 | *length = server.receiveFrom( client, buffer, sizeof(buffer ) ); |
klauss | 33:735fd60e96d8 | 19 | |
klauss | 33:735fd60e96d8 | 20 | if( *length > 0){ |
klauss | 33:735fd60e96d8 | 21 | buffer[ *length ] = '\0'; |
klauss | 33:735fd60e96d8 | 22 | t.start(); |
klauss | 33:735fd60e96d8 | 23 | if( count >= 0 ){ |
klauss | 33:735fd60e96d8 | 24 | if( count == 0 ); // enviar pacote de "entendi o request de volta" |
klauss | 33:735fd60e96d8 | 25 | |
klauss | 33:735fd60e96d8 | 26 | if( atoi( buffer ) == 0 ) count++; |
klauss | 33:735fd60e96d8 | 27 | |
klauss | 33:735fd60e96d8 | 28 | else count = 0; |
klauss | 33:735fd60e96d8 | 29 | } |
klauss | 33:735fd60e96d8 | 30 | if( count == param ){ |
klauss | 33:735fd60e96d8 | 31 | debug_msg( "Received start pkgs" ); |
klauss | 33:735fd60e96d8 | 32 | if( t.read() < 10 ){ |
klauss | 33:735fd60e96d8 | 33 | param = 1000; |
klauss | 33:735fd60e96d8 | 34 | server.set_blocking( true, 10 ); |
klauss | 33:735fd60e96d8 | 35 | t.reset(); |
klauss | 33:735fd60e96d8 | 36 | |
klauss | 33:735fd60e96d8 | 37 | count = 0; |
klauss | 33:735fd60e96d8 | 38 | while( atoi( buffer ) == 0 && t.read() < 10 ){ |
klauss | 33:735fd60e96d8 | 39 | *length = server.receiveFrom( client, buffer, sizeof( buffer ) ); |
klauss | 33:735fd60e96d8 | 40 | wdt.kick(); |
klauss | 33:735fd60e96d8 | 41 | } |
klauss | 33:735fd60e96d8 | 42 | |
klauss | 33:735fd60e96d8 | 43 | if( t.read() > 10 ) return( NULL ); |
klauss | 33:735fd60e96d8 | 44 | |
klauss | 33:735fd60e96d8 | 45 | else{ |
klauss | 33:735fd60e96d8 | 46 | //tratar o primeiro pkg depois dos zeros aqui |
klauss | 33:735fd60e96d8 | 47 | count++; |
klauss | 33:735fd60e96d8 | 48 | while( count < 6000 ){ |
klauss | 33:735fd60e96d8 | 49 | wdt.kick(); |
klauss | 33:735fd60e96d8 | 50 | *length = server.receiveFrom( client, buffer, sizeof( buffer ) ); |
klauss | 33:735fd60e96d8 | 51 | if( ++count == param ){ |
klauss | 33:735fd60e96d8 | 52 | debug_msg(" Received %04d - Sent %04d - Missed %04d - %.3f", count, atoi( buffer ), atoi( buffer ) - count, ( (float)count )/( atoi( buffer ) ) ); |
klauss | 33:735fd60e96d8 | 53 | param += 1000; |
klauss | 33:735fd60e96d8 | 54 | } |
klauss | 33:735fd60e96d8 | 55 | } |
klauss | 33:735fd60e96d8 | 56 | //pensar em como validar os pacotes recebidos, cks ... e o que mais ? |
klauss | 33:735fd60e96d8 | 57 | //se validado os pkgs, dar reset com os dados no arquivo bla, caso contrario, ignorar ... |
klauss | 33:735fd60e96d8 | 58 | bool valid_reboot = false; |
klauss | 33:735fd60e96d8 | 59 | if( valid_reboot ) NVIC_SystemReset(); |
klauss | 33:735fd60e96d8 | 60 | |
klauss | 33:735fd60e96d8 | 61 | else{ |
klauss | 33:735fd60e96d8 | 62 | count = 0; |
klauss | 33:735fd60e96d8 | 63 | param = 100; |
klauss | 33:735fd60e96d8 | 64 | server.set_blocking( false, 1 ); |
klauss | 33:735fd60e96d8 | 65 | t.stop(); |
klauss | 33:735fd60e96d8 | 66 | t.reset(); |
klauss | 33:735fd60e96d8 | 67 | debug_msg("Nao Resetando ... "); |
klauss | 33:735fd60e96d8 | 68 | } |
klauss | 33:735fd60e96d8 | 69 | |
klauss | 33:735fd60e96d8 | 70 | } |
klauss | 33:735fd60e96d8 | 71 | } |
klauss | 33:735fd60e96d8 | 72 | }else return( buffer ); |
klauss | 33:735fd60e96d8 | 73 | }else return( NULL ); |
klauss | 33:735fd60e96d8 | 74 | return( NULL ); |
klauss | 33:735fd60e96d8 | 75 | } |
klauss | 33:735fd60e96d8 | 76 | |
klauss | 33:735fd60e96d8 | 77 | #endif |