Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: eth.cpp
- Revision:
- 124:c1b6c893e1c3
- Parent:
- 122:480c44b0e205
- Child:
- 125:8ff4dc96ad58
diff -r 1d395b5a4cad -r c1b6c893e1c3 eth.cpp --- a/eth.cpp Mon May 11 19:21:39 2015 +0000 +++ b/eth.cpp Wed May 13 14:25:57 2015 +0000 @@ -2,6 +2,8 @@ EthernetInterface eth; + +/* int __init_eth__ ( void ) { static bool initialized = false; @@ -64,4 +66,94 @@ 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 *fp = fopen( "/qspi/myip.txt", "r"); + if( fp == 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, fp ); + 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 ); + } + } + fclose( fp ); + buff_ip[ 15 ] = 0; + fp = fopen( "/qspi/mymask.txt", "r"); + if( fp == 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, fp ); + 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 ); + } + } + fclose( fp ); + buff_msk[ 15 ] = 0; + fp = fopen( "/qspi/mygateway.txt", "r"); + if( fp == 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, fp ); + 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 ); + } + } + fclose( fp ); + 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__ (); } \ No newline at end of file