![](/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: file_system_manager.cpp
- Revision:
- 114:472502b31a12
- Parent:
- 113:db67ae00550e
- Child:
- 116:39a41ebb675c
diff -r db67ae00550e -r 472502b31a12 file_system_manager.cpp --- a/file_system_manager.cpp Thu Apr 16 12:57:13 2015 +0000 +++ b/file_system_manager.cpp Mon Apr 20 14:40:09 2015 +0000 @@ -9,8 +9,11 @@ qspifs.format(); send_msg("\n\rFile system configured!!\n\r"); } + debug_msg(""); files('i'); // check if the files are created + debug_msg(""); //files('c'); + debug_msg(""); send_msg("\n\r*******File System Ready*******\n\r"); } @@ -18,117 +21,96 @@ void set_ip( char * new_header_ip ){ FILE * fip = fopen("/qspi/myip.txt", "w"); - if( fip ) - { - fprintf( fip, "%s\n\r", new_header_ip ); - fclose( fip ); - } + fprintf( fip, "%s\n\r", new_header_ip ); + fclose( fip ); } void set_header_ext( int new_header_ext ){ FILE * fext = fopen( "/qspi/myext.txt", "w" ); - if( fext ) - { - fprintf( fext, "%i\n\r", new_header_ext ); - fclose( fext ); - } + fprintf( fext, "%i\n\r", new_header_ext ); + fclose( fext ); } void set_header_sip_port( int new_header_sip_port ){ FILE * fport = fopen("/qspi/mysipport.txt", "w"); - if( fport ) - { - fprintf( fport,"%i\n\r", new_header_sip_port ); - fclose( fport ); - } + fprintf( fport,"%i\n\r", new_header_sip_port ); + fclose( fport ); } void set_server_ip( char * new_server_ip ){ FILE * fsip = fopen("/qspi/serverip.txt", "w"); - if( fsip ) - { - fprintf( fsip,"%s\n\r", new_server_ip ); - fclose( fsip ); - } + fprintf( fsip,"%s\n\r", new_server_ip ); + fclose( fsip ); } void set_server_ext( int new_server_ext ){ FILE * fserext = fopen("/qspi/peerext.txt", "w"); - if( fserext ) - { - fprintf( fserext , "%i\n\r", new_server_ext ); - fclose( fserext ); - } + fprintf( fserext , "%i\n\r", new_server_ext ); + fclose( fserext ); } void set_server_port( int new_server_port ){ FILE * fsport = fopen("/qspi/serverport.txt", "w"); - if( fsport ) - { - fprintf(fsport,"%i\n\r", new_server_port ); - fclose( fsport ); - } + fprintf(fsport,"%i\n\r", new_server_port ); + fclose( fsport ); } void set_mask( char * new_mask ){ FILE * fmask = fopen("/qspi/mymask.txt", "w"); - if( fmask ) - { - fprintf(fmask,"%s\n\r",new_mask ); - fclose( fmask ); - } + fprintf(fmask,"%s\n\r",new_mask ); + fclose( fmask ); } void set_gateway( char * new_gateway ){ + //fgate = fopen("/qspi/mygateway.txt", "w"); FILE * fgate = fopen("/qspi/mygateway.txt", "w"); - if( fgate ) - { - fprintf(fgate,"%s\n\r", new_gateway ); - fclose( fgate ); - } + fprintf(fgate,"%s\n\r", new_gateway ); + fclose( fgate ); } void set_udp_port_listener( int new_udp_port_listener ){ FILE * fudpport = fopen( "/qspi/udpport.txt", "w" ); - if( fudpport ) - { - fprintf( fudpport, "%i\n\r",new_udp_port_listener ); - fclose( fudpport ); - } + fprintf( fudpport, "%i\n\r",new_udp_port_listener ); + fclose( fudpport ); } void set_tcp_port_listener( int new_tcp_port_listener ){ FILE * ftcpport = fopen( "/qspi/tcpport.txt", "w" ); - if( ftcpport ) - { - fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); - fclose( ftcpport ); - } + fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); + fclose( ftcpport ); +} + +void set_telemetry_ip( char * new_telemetry_ip ){ + FILE * ftip = fopen("/qspi/telemetry_ip.txt", "w" ); + fprintf(ftip,"%s\n\r", new_telemetry_ip ); + fclose( ftip ); +} + +void set_telemetry_port( int new_telemetry_port ){ + FILE * ftport = fopen("/qspi/telemetry_port.txt", "w" ); + fprintf(ftport,"%i\n\r", new_telemetry_port ); + fclose( ftport ); } void set_fw_ip( char * new_fw_ip ){ FILE * ffwip = fopen("/qspi/fw_ip.txt", "w" ); - if( ffwip ) - { - fprintf(ffwip,"%s\n\r", new_fw_ip ); - fclose( ffwip ); - } + fprintf(ffwip,"%s\n\r", new_fw_ip ); + fclose( ffwip ); } void set_fw_port( int new_fw_port ){ FILE * ffwport = fopen("/qspi/fw_port.txt", "w" ); - if( ffwport ) - { - fprintf(ffwport,"%i\n\r", new_fw_port ); - fclose( ffwport ); - } + fprintf(ffwport,"%i\n\r", new_fw_port ); + fclose( ffwport ); } void set_max_ext( int new_max_ext ){ FILE * fmex = fopen( "/qspi/maxext.txt", "w" ); if( fmex ){ fprintf( fmex, "%i\n\r", new_max_ext ); + //debug_msg(""); fclose( fmex ); + //debug_msg(""); } } @@ -140,41 +122,386 @@ } } -void set_shift_port( int new_shift_port ){ - FILE * shift_port = fopen("/qspi/shift_port.txt", "w" ); - if( shift_port ) - { - fprintf( shift_port,"%i\n\r", new_shift_port ); - fclose( shift_port ); - if( debug_file ) debug_msg("Set /qspi/shift_port.txt"); - } - else - { - if( debug_file ) debug_msg("Cannot open /qspi/shift_port.txt"); - } -} - // Print the content of a given file -void cat( const char * fname ){ +void cat(const char * fname){ char buff[513]; int num; - FILE *fp = fopen( fname, "r" ); + FILE *fp = fopen(fname, "r"); if (fp == NULL) { - if( debug_file ) if( debug_uart3 && !( from_eth ) ) pc.printf( "Failed to open %s", fname); + if( debug_file ) if( debug_uart3 ) pc.printf( "Failed to open %s", fname); return; } while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ buff[ num ] = '\0'; - if( debug_uart3 && !( from_eth ) ) pc.printf( buff ); + if( debug_uart3 ) pc.printf( buff ); if( from_eth ){ - if( tcp_session && !udp_query ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); + if( tcp_session ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); - else if( udp_query ){ - udp_query_send_msg( buff ); + else if( udp_request ){ + udp_server.sendTo( udp_client, buff, strlen( buff ) ); } } } fclose(fp); -} \ No newline at end of file +} + +/* +//operantion with the system config files +void files( const char type ){ + FILE *fip = NULL, + *fmask = NULL, + *fgate = NULL, + *fport = NULL, + *fsip = NULL, + *fsport = NULL, + *fext = NULL, + *fserext = NULL, + *fudpport = NULL, + *ftcpport = NULL, + *ftip = NULL, + *ftport = NULL; + + //fixme mudar o nome dessa variable + + //#define MIN_EXT 5100 + //#define MAX_EXT 5139 + char string_msg[ 1024 ]; + // show files + switch( type ){ + case 's' : { + if( debug_uart3 ) pc.printf("Header IP " ); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Header IP " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/myip.txt"); + + if( debug_uart3 ) pc.printf("Header ext "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Header ext " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/myext.txt"); + + if( debug_uart3 ) pc.printf("Header port "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Header port " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/mysipport.txt"); + + if( debug_uart3 ) pc.printf("Server IP "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Server IP " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/serverip.txt"); + + if( debug_uart3 ) pc.printf("Server ext "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Server ext " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/peerext.txt"); + + if( debug_uart3 ) pc.printf("Server port "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Server port " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + cat("/qspi/serverport.txt"); + + if( debug_uart3 ) pc.printf("Mascara de rede "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Mascara de rede " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + cat("/qspi/mymask.txt"); + + if( debug_uart3 ) pc.printf("Gateway IP "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Gateway IP " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + cat("/qspi/mygateway.txt"); + + if( debug_uart3 ) pc.printf("UDP Port "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "UDP Port " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/udpport.txt"); + + if( debug_uart3 ) pc.printf("TCP Port "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "TCP Port " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/tcpport.txt"); + + if( debug_uart3 ) pc.printf("Telemetry Server IP "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server IP " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/telemetry_ip.txt"); + + if( debug_uart3 ) pc.printf("Telemetry Server Port "); + if( from_eth ){ + snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server Port " ); + if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); + + else if( udp_request ){ + udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); + } + } + + cat("/qspi/telemetry_port.txt"); + break; + } + + case 'c' : { + // close all files + debug_msg(""); + if( fip != NULL ) fclose( fip ); + if( fmask != NULL ) fclose( fmask ); + if( fgate != NULL ) fclose( fgate ); + if( fport != NULL ) fclose( fport ); + if( fsip != NULL ) fclose( fsip ); + if( fsport != NULL ) fclose( fsport ); + if( fext != NULL ) fclose( fext ); + if( fserext != NULL ) fclose( fserext ); + if( fudpport != NULL ) fclose( fudpport ); + if( ftcpport != NULL ) fclose( ftcpport ); + debug_msg(""); + break; + } + + case 'i' : { + // Check if files exist, if not create the files + //fixme criar um bool pra cada file + bool exists = true; + + debug_msg(""); + fip = fopen("/qspi/myip.txt", "r"); + if( fip == NULL){ + set_ip( __MY_IP__ ); + exists = false; + } + debug_msg(""); + fserext = fopen("/qspi/myext.txt", "r"); + if( fserext == NULL ){ + set_header_ext( __MY_EXT__ ); + exists = false; + } + debug_msg(""); + fport = fopen("/qspi/mysipport.txt", "r"); + if (fport == NULL){ + set_header_sip_port( __MY_PORT__ ); + exists = false; + } + debug_msg(""); + fsip = fopen("/qspi/serverip.txt", "r"); + if (fsip == NULL){ + set_server_ip( __SERVER_IP__ ); + exists = false; + } + debug_msg(""); + fext = fopen("/qspi/peerext.txt", "r"); + if ( fext == NULL ){ + set_server_ext( __PEER_EXT__ ); + exists = false; + } + debug_msg(""); + fsport = fopen("/qspi/serverport.txt", "r"); + if (fsport == NULL){ + set_server_port( __SERVER_PORT__ ); + exists = false; + } + debug_msg(""); + fmask = fopen("/qspi/mymask.txt", "r"); + if (fmask == NULL){ + set_mask( __MY_MSK__ ); + exists = false; + } + debug_msg(""); + fgate = fopen("/qspi/mygateway.txt", "r"); + if (fgate == NULL){ + set_gateway( __MY_GTW__ ); + exists = false; + } + debug_msg(""); + fudpport = fopen("/qspi/udpport.txt", "r" ); + if( fudpport == NULL ){ + set_udp_port_listener( UDP_PORT_LISTENER ); + exists = false; + } + debug_msg(""); + ftcpport = fopen("/qspi/tcpport.txt", "r" ); + if( ftcpport == NULL ){ + set_tcp_port_listener( TCP_PORT_LISTENER ); + exists = false; + } + debug_msg(""); + ftip = fopen("/qspi/telemetry_ip.txt", "r" ); + if( ftip == NULL ){ + set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); + exists = false; + } + debug_msg(""); + ftport = fopen("/qspi/telemetry_port.txt", "r" ); + if( ftport == NULL ){ + set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); + exists = false; + } + debug_msg(""); + if( !exists ){ + send_msg("\n\rDefault configurations set!\n\r"); + } + debug_msg(""); + break; + } + + case 'r' : { + // Just open for read + fip = fopen("/qspi/myip.txt", "r"); + fmask = fopen("/qspi/mymask.txt", "r"); + fgate = fopen("/qspi/mygateway.txt", "r"); + fport = fopen("/qspi/mysipport.txt", "r"); + fsip = fopen("/qspi/serverip.txt", "r"); + fsport = fopen("/qspi/serverport.txt", "r"); + fext = fopen( "/qspi/myext.txt", "r" ); + fserext = fopen( "/qspi/peerext.txt", "r" ); + fudpport = fopen( "/qspi/udpport.txt", "r" ); + ftcpport = fopen( "/qspi/tcpport.txt", "r" ); + ftip = fopen("/qspi/telemetry_ip.txt", "r" ); + ftport = fopen("/qspi/telemetry_port.txt", "r" ); + break; + } + + case 'w' : { + // Create and write the default configs + + set_ip( __MY_IP__ ); + + set_header_sip_port( __MY_PORT__ ); + + set_header_ext( __MY_EXT__ ); + + set_server_ip( __SERVER_IP__ ); + + set_server_ext( __PEER_EXT__ ); + + set_server_port( __SERVER_PORT__ ); + + set_mask( __MY_MSK__ ); + + set_gateway( __MY_GTW__ ); + + set_udp_port_listener( UDP_PORT_LISTENER ); + + set_tcp_port_listener( TCP_PORT_LISTENER ); + + set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); + + set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); + + send_msg( "Default configurations set!" ); + break; + } + + case 'e' : { + //Erase configs + fip = fopen("/qspi/myip.txt", "w"); + fmask = fopen("/qspi/mymask.txt", "w"); + fgate = fopen("/qspi/mygateway.txt", "w"); + fport = fopen("/qspi/mysipport.txt", "w"); + fsip = fopen("/qspi/serverip.txt", "w"); + fsport = fopen("/qspi/serverport.txt", "w"); + fext = fopen( "/qspi/myext.txt", "w" ); + fserext = fopen( "/qspi/peerext.txt", "w" ); + fudpport = fopen( "/qspi/udpport.txt", "w" ); + ftcpport = fopen( "/qspi/tcpport.txt", "w" ); + ftip = fopen("/qspi/telemetry_ip.txt", "w" ); + ftport = fopen("/qspi/telemetry_port.txt", "w" ); + + //FIXME verificar se deveria colocar tudo para %s + fprintf( fip, "%s\n\r", "" ); + fprintf( fport, "%i\n\r", 0 ); + fprintf( fext, "%i\n\r", 0 ); + + fprintf( fsip, "%s\n\r", "" ); + fprintf( fserext, "%i\n\r", 0 ); + fprintf( fsport, "%i\n\r", 0 ); + + fprintf( fmask, "%s\n\r","" ); + fprintf( fgate, "%s\n\r", "" ); + + fprintf( fudpport, "%i\n\r", 0 ); + fprintf( ftcpport, "%i\n\r", 0 ); + + fprintf( ftip, "%s\n\r","" ); + fprintf( ftport, "%i\n\r",0 ); + + files('c'); + + send_msg("\n\rErased configurations set!\n\r"); + break; + } + } +} +*/ \ No newline at end of file