![](/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@74:81c47fff88a5, 2014-11-24 (annotated)
- Committer:
- klauss
- Date:
- Mon Nov 24 16:43:16 2014 +0000
- Revision:
- 74:81c47fff88a5
- Child:
- 78:1353744f01e1
validando organiza??o de arquivos | ainda em desenvolvimento.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 74:81c47fff88a5 | 1 | #include "eth.h" |
klauss | 74:81c47fff88a5 | 2 | |
klauss | 74:81c47fff88a5 | 3 | EthernetInterface eth; |
klauss | 74:81c47fff88a5 | 4 | |
klauss | 74:81c47fff88a5 | 5 | int __init_eth__(){ |
klauss | 74:81c47fff88a5 | 6 | static bool initialized = false; |
klauss | 74:81c47fff88a5 | 7 | char buff_ip[ 16 ] = ""; |
klauss | 74:81c47fff88a5 | 8 | char buff_msk[ 16 ] = ""; |
klauss | 74:81c47fff88a5 | 9 | char buff_gtw[ 16 ] = ""; |
klauss | 74:81c47fff88a5 | 10 | wdt.kick(); |
klauss | 74:81c47fff88a5 | 11 | pc.printf("\n\r"); |
klauss | 74:81c47fff88a5 | 12 | FILE *fp = fopen( "/qspi/myip.txt", "r"); |
klauss | 74:81c47fff88a5 | 13 | if( fp == NULL ){ |
klauss | 74:81c47fff88a5 | 14 | if( debug_file ) debug_msg("Failed to open /qspi/myip.txt" ); |
klauss | 74:81c47fff88a5 | 15 | strncpy( buff_ip, __MY_IP__, 20 ); |
klauss | 74:81c47fff88a5 | 16 | }else{ |
klauss | 74:81c47fff88a5 | 17 | int read = fread( buff_ip, 1, 512, fp ); |
klauss | 74:81c47fff88a5 | 18 | if( read > 0 ){ |
klauss | 74:81c47fff88a5 | 19 | for( int i = 0; i < read; i++ ) |
klauss | 74:81c47fff88a5 | 20 | if( buff_ip[ i ] == '\n' || buff_ip[ i ] == '\r' ){ |
klauss | 74:81c47fff88a5 | 21 | buff_ip[ i ] = '\0'; |
klauss | 74:81c47fff88a5 | 22 | break; |
klauss | 74:81c47fff88a5 | 23 | } |
klauss | 74:81c47fff88a5 | 24 | if( debug_file ) debug_msg("Eth ip %s", buff_ip ); |
klauss | 74:81c47fff88a5 | 25 | }else{ |
klauss | 74:81c47fff88a5 | 26 | if( debug_file ) debug_msg("Failed to read /qspi/myip.txt" ); |
klauss | 74:81c47fff88a5 | 27 | strncpy( buff_ip, __MY_IP__, 20 ); |
klauss | 74:81c47fff88a5 | 28 | } |
klauss | 74:81c47fff88a5 | 29 | } |
klauss | 74:81c47fff88a5 | 30 | fclose( fp ); |
klauss | 74:81c47fff88a5 | 31 | buff_ip[ 15 ] = 0; |
klauss | 74:81c47fff88a5 | 32 | |
klauss | 74:81c47fff88a5 | 33 | fp = fopen( "/qspi/mymask.txt", "r"); |
klauss | 74:81c47fff88a5 | 34 | if( fp == NULL ){ |
klauss | 74:81c47fff88a5 | 35 | if( debug_file ) debug_msg("Failed to open /qspi/mymask.txt" ); |
klauss | 74:81c47fff88a5 | 36 | strncpy( buff_msk, __MY_MSK__, 20 ); |
klauss | 74:81c47fff88a5 | 37 | }else{ |
klauss | 74:81c47fff88a5 | 38 | int read = fread( buff_msk, 1, 512, fp ); |
klauss | 74:81c47fff88a5 | 39 | if( read > 0 ){ |
klauss | 74:81c47fff88a5 | 40 | for( int i = 0; i < read; i++ ) |
klauss | 74:81c47fff88a5 | 41 | if( buff_msk[ i ] == '\n' || buff_msk[ i ] == '\r' ){ |
klauss | 74:81c47fff88a5 | 42 | buff_msk[ i ] = '\0'; |
klauss | 74:81c47fff88a5 | 43 | break; |
klauss | 74:81c47fff88a5 | 44 | } |
klauss | 74:81c47fff88a5 | 45 | if( debug_file ) debug_msg("mascara de rede Eth %s", buff_msk ); |
klauss | 74:81c47fff88a5 | 46 | }else{ |
klauss | 74:81c47fff88a5 | 47 | if( debug_file ) debug_msg("Failed to read /qspi/mymask.txt" ); |
klauss | 74:81c47fff88a5 | 48 | strncpy( buff_msk, __MY_MSK__, 20 ); |
klauss | 74:81c47fff88a5 | 49 | } |
klauss | 74:81c47fff88a5 | 50 | } |
klauss | 74:81c47fff88a5 | 51 | fclose( fp ); |
klauss | 74:81c47fff88a5 | 52 | buff_msk[ 15 ] = 0; |
klauss | 74:81c47fff88a5 | 53 | |
klauss | 74:81c47fff88a5 | 54 | fp = fopen( "/qspi/mygate.txt", "r"); |
klauss | 74:81c47fff88a5 | 55 | if( fp == NULL ){ |
klauss | 74:81c47fff88a5 | 56 | if( debug_file ) debug_msg("Failed to open /qspi/mygate.txt" ); |
klauss | 74:81c47fff88a5 | 57 | strncpy( buff_gtw, __MY_GTW__, 20 ); |
klauss | 74:81c47fff88a5 | 58 | }else{ |
klauss | 74:81c47fff88a5 | 59 | int read = fread( buff_gtw, 1, 512, fp ); |
klauss | 74:81c47fff88a5 | 60 | if( read > 0 ){ |
klauss | 74:81c47fff88a5 | 61 | for( int i = 0; i < read; i++ ) |
klauss | 74:81c47fff88a5 | 62 | if( buff_gtw[ i ] == '\n' || buff_gtw[ i ] == '\r' ){ |
klauss | 74:81c47fff88a5 | 63 | buff_gtw[ i ] = '\0'; |
klauss | 74:81c47fff88a5 | 64 | break; |
klauss | 74:81c47fff88a5 | 65 | } |
klauss | 74:81c47fff88a5 | 66 | if( debug_file ) debug_msg("Ip Gateway Eth %s", buff_gtw ); |
klauss | 74:81c47fff88a5 | 67 | }else{ |
klauss | 74:81c47fff88a5 | 68 | if( debug_file ) debug_msg("Failed to read /qspi/mygate.txt" ); |
klauss | 74:81c47fff88a5 | 69 | strncpy( buff_gtw, __MY_GTW__, 20 ); |
klauss | 74:81c47fff88a5 | 70 | } |
klauss | 74:81c47fff88a5 | 71 | } |
klauss | 74:81c47fff88a5 | 72 | fclose( fp ); |
klauss | 74:81c47fff88a5 | 73 | buff_gtw[ 15 ] = 0; |
klauss | 74:81c47fff88a5 | 74 | |
klauss | 74:81c47fff88a5 | 75 | if( !initialized ){ |
klauss | 74:81c47fff88a5 | 76 | //eth.init( buff_ip, buff_msk, buff_gtw ); |
klauss | 74:81c47fff88a5 | 77 | eth.init( buff_ip, buff_msk, __MY_GTW__ ); |
klauss | 74:81c47fff88a5 | 78 | initialized = true; |
klauss | 74:81c47fff88a5 | 79 | return eth.connect(); |
klauss | 74:81c47fff88a5 | 80 | } |
klauss | 74:81c47fff88a5 | 81 | |
klauss | 74:81c47fff88a5 | 82 | if( !eth.disconnect() ){ |
klauss | 74:81c47fff88a5 | 83 | return eth.connect(); |
klauss | 74:81c47fff88a5 | 84 | } |
klauss | 74:81c47fff88a5 | 85 | else{ |
klauss | 74:81c47fff88a5 | 86 | return eth.connect(); |
klauss | 74:81c47fff88a5 | 87 | } |
klauss | 74:81c47fff88a5 | 88 | } |