![](/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:
- 104:62646ef786a3
- Parent:
- 100:09a23fcd3bdf
- Child:
- 105:a930035b6556
--- a/file_system_manager.cpp Thu Feb 19 18:04:33 2015 +0000 +++ b/file_system_manager.cpp Wed Feb 25 18:44:11 2015 +0000 @@ -80,18 +80,6 @@ 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" ); fprintf(ffwip,"%s\n\r", new_fw_ip ); @@ -129,379 +117,30 @@ FILE *fp = fopen(fname, "r"); if (fp == NULL) { - if( debug_file ) if( debug_uart3 ) pc.printf( "Failed to open %s", fname); + if( debug_file ) if( debug_uart3 && !( from_eth ) ) pc.printf( "Failed to open %s", fname); return; } while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ buff[ num ] = '\0'; - if( debug_uart3 ) pc.printf( buff ); + if( debug_uart3 && !( from_eth ) ) pc.printf( buff ); if( from_eth ){ if( tcp_session ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); else if( udp_request ){ - udp_server.sendTo( udp_client, buff, strlen( buff ) ); + int send = udp_server.sendTo( udp_client, buff, strlen( buff ) ); + if( send != strlen( buff ) ) + { + if( debug_reconnect ) + { + send_msg("Reconnect UDP_request client"); + } + + reconnect_prompt_udp_socket(); + miss_prompt_udp_send_pkg++; + } } } } fclose(fp); -} - -/* -//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 +} \ No newline at end of file