Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
122:480c44b0e205
Parent:
121:ee02790d00b7
Child:
124:c1b6c893e1c3
--- a/file_system_manager.cpp	Fri May 08 04:15:23 2015 +0000
+++ b/file_system_manager.cpp	Mon May 11 15:16:36 2015 +0000
@@ -16,7 +16,7 @@
 
 int get_ip ( char * header_ip, const size_t length )
 {
-    FILE * fip = fopen("/qspi/myip.txt", "r");
+    FILE * fip = fopen ("/qspi/myip.txt", "r" );
     if ( fip != NULL )
     {
         int read = fread ( header_ip, 1, length, fip );
@@ -33,20 +33,132 @@
  
             if ( debug_file ) debug_msg ("Eth ip %s", header_ip );
         } else {
+            if ( fip ) fclose ( fip );
             return ( -3 );
         }
         
         header_ip [ length ] = 0;
 
-        fclose ( fip );
+        if ( fip ) fclose ( fip );
         
         return ( read );
     } 
         
     if ( debug_file ) debug_msg ("Failed to open /qspi/myip.txt" );
     
+    return ( -1 );
+}
+
+int get_clock_server_ip ( char * clock_server_ip, const size_t length )
+{
+    return ( get_server_ip ( clock_server_ip, length ) );
+}
+
+int get_server_ip ( char * server_ip, const size_t length )
+{
+    FILE * fsip = fopen ("/qspi/serverip.txt", "r" );
+    if ( fsip != NULL )
+    {
+        int read = fread ( server_ip, 1, length, fsip );
+        if( read > 0 )
+        {
+            for ( register int i = 0; i < read; i++ )
+            {
+                if( server_ip [ i ] == '\n' || server_ip [ i ] == '\r' )
+                {
+                    server_ip [ i ] = '\0';
+                    break;
+                }
+            }
+ 
+            if ( debug_file ) debug_msg ("Eth ip %s", server_ip );
+        } else {
+            if ( fsip ) fclose ( fsip );
+            return ( -3 );
+        }
+        
+        server_ip [ length ] = 0;
+
+        fclose ( fsip );
+        
+        return ( read );
+    } 
+        
+    if ( debug_file ) debug_msg ("Failed to open /qspi/serverip.txt" );
+    
+    return ( -1 );
+}
+
+int get_mask ( char * eth_mask, const size_t length )
+{
+    FILE * fmsk = fopen("/qspi/mymask.txt", "r");
+    if ( fmsk != NULL )
+    {
+        int read = fread ( eth_mask, 1, length, fmsk );
+        if( read > 0 )
+        {
+            for ( register int i = 0; i < read; i++ )
+            {
+                if( eth_mask [ i ] == '\n' || eth_mask [ i ] == '\r' )
+                {
+                    eth_mask [ i ] = '\0';
+                    break;
+                }
+            }
+ 
+            if ( debug_file ) debug_msg ("Eth mask %s", eth_mask );
+        } else {
+            if ( fmsk ) fclose ( fmsk );
+            return ( -3 );
+        }
+        
+        eth_mask [ length ] = 0;
+
+        if ( fmsk ) fclose ( fmsk );
+        
+        return ( read );
+    } 
+        
+    if ( debug_file ) debug_msg ("Failed to open /qspi/mymask.txt" );
+    
     return ( -1 );    
 }
+int get_gateway ( char * eth_gw, const size_t length )
+{
+    FILE * fgw = fopen("/qspi/mygateway.txt", "r");
+    if ( fgw != NULL )
+    {
+        int read = fread ( eth_gw, 1, length, fgw );
+        if( read > 0 )
+        {
+            for ( register int i = 0; i < read; i++ )
+            {
+                if( eth_gw [ i ] == '\n' || eth_gw [ i ] == '\r' )
+                {
+                    eth_gw [ i ] = '\0';
+                    break;
+                }
+            }
+ 
+        if ( debug_file ) debug_msg ("Eth gateway %s", eth_gw );
+        } else { 
+            if ( fgw ) fclose ( fgw );
+            return ( -3 );
+        }
+        
+        eth_gw [ length ] = 0;
+
+        if ( fgw ) fclose ( fgw );
+        
+        return ( read );
+    } 
+        
+    if ( debug_file ) debug_msg ("Failed to open /qspi/mygateway.txt" );
+    
+    return ( -1 );        
+}
+
+void set_clock_server_ip ( const char * new_server_ip );
 
 void set_header_ext ( const int new_header_ext )
 {
@@ -58,6 +170,31 @@
     }
 }
 
+
+int get_header_ext ( void )
+{
+    char get_header_ext_buffer [ 32 ] = "";
+    
+    FILE * fext = fopen ( "/qspi/myext.txt", "r" );
+    if ( fext == NULL )
+    {
+        if( debug_file ) debug_msg ( "Failed to open /qspi/myext.txt" );
+        
+        return (  PEER_EXT );
+    } else {
+        if( fread ( ( void * ) get_header_ext_buffer, 1, sizeof ( get_header_ext_buffer ) - 1, fext ) > 0 )
+        {
+            if ( fext ) fclose ( fext );
+            return ( atoi ( get_header_ext_buffer ) );
+        } else {
+            if ( debug_file ) debug_msg ("Failed to read /qspi/myext.txt" );
+            
+            if ( fext ) fclose ( fext );
+            return ( PEER_EXT );
+        }
+    }
+}
+
 void set_header_sip_port ( const int new_header_sip_port )
 {
     FILE * fport = fopen("/qspi/mysipport.txt", "w");
@@ -68,6 +205,30 @@
     }
 }
 
+int get_header_sip_port ( void )
+{
+    char get_header_sip_port_buffer [ 32 ] = "";
+    
+    FILE * fport = fopen ( "/qspi/mysipport.txt", "r" );
+    if ( fport == NULL )
+    {
+        if( debug_file ) debug_msg ( "Failed to open /qspi/mysipport.txt" );
+        
+        return (  MY_PORT );
+    } else {
+        if( fread ( ( void * ) get_header_sip_port_buffer, 1, sizeof ( get_header_sip_port_buffer ) - 1, fport ) > 0 )
+        {
+            if ( fport ) fclose ( fport );
+            return ( atoi ( get_header_sip_port_buffer ) );
+        } else {
+            if ( debug_file ) debug_msg ("Failed to read /qspi/mysipport.txt" );
+            
+            if ( fport ) fclose ( fport );
+            return ( MY_PORT );
+        }
+    }
+}
+
 void set_server_ip ( const char * new_server_ip )
 {
     FILE * fsip = fopen("/qspi/serverip.txt", "w");
@@ -218,7 +379,7 @@
     }
 }
 
-void files( const char type )
+void files ( const char type )
 {
     FILE *fip = NULL;
     FILE *fmask = NULL;
@@ -428,6 +589,7 @@
 
         cat("/qspi/serverip.txt");
         
+        /*
         if( debug_uart3 && !( from_eth ) ) pc.printf("Clock Server Port %d\r\n", CLOCK_SERVER_PORT  );
         if( from_eth ) {
             snprintf( file_buffer, FILE_BUFFER_SIZE, "Clock Server Port %d\r\n", CLOCK_SERVER_PORT  );
@@ -457,6 +619,7 @@
                 udp_query_send_msg( file_buffer );
             }
         }
+        */
         
         //*------------ formatando a saida ----------------*//
         for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0;