![](/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
- Committer:
- klauss
- Date:
- 2015-05-13
- Revision:
- 125:8ff4dc96ad58
- Parent:
- 124:c1b6c893e1c3
- Child:
- 132:05cd37f7e007
File content as of revision 125:8ff4dc96ad58:
#include "eth.h" EthernetInterface eth; /* int __init_eth__ ( void ) { static bool initialized = false; char buff_ip [ 16 ] = ""; char buff_msk [ 16 ] = ""; char buff_gtw [ 16 ] = ""; if( debug_uart3 ) pc.printf("\n\r"); int ip_return_value = get_ip ( buff_ip, sizeof ( buff_ip ) - 1 ); if ( ip_return_value < 0 ) { set_ip( MY_IP ); strncpy ( buff_ip, MY_IP, sizeof ( buff_ip ) - 1 ); if ( debug_file ) debug_msg ("Load default header_ip -- %s", buff_ip ); } buff_ip [ sizeof ( buff_ip ) - 1 ] = 0; int mask_return_value = get_ip ( buff_msk, sizeof ( buff_msk ) - 1 ); if ( mask_return_value < 0 ) { set_mask( MY_MSK ); strncpy ( buff_msk, MY_MSK, sizeof ( buff_msk ) - 1 ); if ( debug_file ) debug_msg ("Load default eth_mask -- %s", buff_msk ); } buff_msk [ sizeof ( buff_msk ) - 1 ] = 0; int gw_return_value = get_gateway ( buff_gtw, sizeof ( buff_gtw ) - 1 ); if ( gw_return_value < 0 ) { set_gateway( MY_GTW ); strncpy ( buff_gtw, MY_MSK, sizeof ( buff_gtw ) - 1 ); if ( debug_file ) debug_msg ("Load default eth_gateway -- %s", buff_gtw ); } buff_gtw [ sizeof ( buff_gtw ) - 1 ] = 0; if( !initialized ) { eth.init( buff_ip, buff_msk, buff_gtw ); initialized = true; return eth.connect(); } if( !eth.disconnect() ){ return eth.connect(); } else{ return eth.connect(); } } */ int __init_eth__ ( void ) { static bool initialized = false; char buff_ip[ 16 ] = ""; char buff_msk[ 16 ] = ""; char buff_gtw[ 16 ] = ""; if( debug_uart3 ) pc.printf("\n\r"); FILE * fip = fopen( "/qspi/myip.txt", "r"); if( fip == NULL ){ if( debug_file ) debug_msg("Failed to open /qspi/myip.txt" ); strncpy( buff_ip, MY_IP, 20 ); }else{ int read = fread( buff_ip, 1, 512, fip ); if( read > 0 ){ for( int i = 0; i < read; i++ ) if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){ buff_ip[ i ] = '\0'; break; } if( debug_file ) debug_msg("Eth ip %s", buff_ip ); }else{ if( debug_file ) debug_msg("Failed to read /qspi/myip.txt" ); strncpy( buff_ip, MY_IP, 20 ); } } if ( fip ) fclose( fip ); buff_ip [ 15 ] = 0; FILE * fmask = fopen( "/qspi/mymask.txt", "r"); if( fmask == NULL ){ if( debug_file ) debug_msg("Failed to open /qspi/mymask.txt" ); strncpy( buff_msk, MY_MSK, 20 ); }else{ int read = fread( buff_msk, 1, 512, fmask ); if( read > 0 ){ for( int i = 0; i < read; i++ ) if( buff_msk[ i ] == '\n' || buff_msk[ i ] == '\r' ){ buff_msk[ i ] = '\0'; break; } if( debug_file ) debug_msg("mascara de rede Eth %s", buff_msk ); }else{ if( debug_file ) debug_msg("Failed to read /qspi/mymask.txt" ); strncpy( buff_msk, MY_MSK, 20 ); } } if ( fmask ) fclose ( fmask ); buff_msk [ 15 ] = 0; FILE * fgate = fopen( "/qspi/mygateway.txt", "r"); if( fgate == NULL ){ if( debug_file ) debug_msg("Failed to open /qspi/mygateway.txt" ); strncpy( buff_gtw, MY_GTW, 20 ); }else{ int read = fread( buff_gtw, 1, 512, fgate ); if( read > 0 ){ for( int i = 0; i < read; i++ ) if( buff_gtw[ i ] == '\n' || buff_gtw[ i ] == '\r' ){ buff_gtw[ i ] = '\0'; break; } if( debug_file ) debug_msg("Ip Gateway Eth %s", buff_gtw ); }else{ if( debug_file ) debug_msg("Failed to read /qspi/mygateway.txt" ); strncpy( buff_gtw, MY_GTW, 20 ); } } if ( fgate ) fclose( fgate ); buff_gtw [ 15 ] = 0; if( !initialized ){ //eth.init( buff_ip, buff_msk, buff_gtw ); eth.init( buff_ip, buff_msk, buff_gtw ); initialized = true; return eth.connect(); } if( !eth.disconnect() ){ return eth.connect(); } else{ return eth.connect(); } } void __reconnect ( void ) { eth.disconnect (); __init_eth__ (); }