![](/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.cpp
- Revision:
- 121:ee02790d00b7
- Parent:
- 119:ee6a53069455
- Child:
- 122:480c44b0e205
--- a/eth.cpp Mon May 04 17:25:29 2015 +0000 +++ b/eth.cpp Fri May 08 04:15:23 2015 +0000 @@ -1,34 +1,21 @@ -#include "eth.h" +#include "header_app_includes.h" EthernetInterface eth; -int __init_eth__(){ +int __init_eth__ ( void ) +{ + debug_msg(""); 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"); + debug_msg(""); + + // ler o ip aqui + + + FILE * 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 ); @@ -46,8 +33,10 @@ strncpy( buff_msk, MY_MSK, 20 ); } } - fclose( fp ); + if ( fp ) fclose( fp ); buff_msk[ 15 ] = 0; + + debug_msg(""); fp = fopen( "/qspi/mygateway.txt", "r"); if( fp == NULL ){ if( debug_file ) debug_msg("Failed to open /qspi/mygateway.txt" ); @@ -66,14 +55,23 @@ strncpy( buff_gtw, MY_GTW, 20 ); } } - fclose( fp ); + if ( fp ) fclose( fp ); buff_gtw[ 15 ] = 0; - if( !initialized ){ - //eth.init( buff_ip, buff_msk, buff_gtw ); - eth.init( buff_ip, buff_msk, MY_GTW ); + + debug_msg(""); + + if( !initialized ) + { + debug_msg("buff_ip :: %s -- buff_msk :: %s -- buff_gtw :: %s", buff_ip, buff_msk, buff_gtw ); + eth.init( buff_ip, buff_msk, buff_gtw ); + debug_msg(""); initialized = true; + debug_msg(""); return eth.connect(); } + + debug_msg(""); + if( !eth.disconnect() ){ return eth.connect(); }