![](/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
file_system_manager.cpp@121:ee02790d00b7, 2015-05-08 (annotated)
- Committer:
- klauss
- Date:
- Fri May 08 04:15:23 2015 +0000
- Revision:
- 121:ee02790d00b7
- Parent:
- 119:ee6a53069455
- Child:
- 122:480c44b0e205
compiling
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 74:81c47fff88a5 | 1 | #include "file_system_manager.h" |
klauss | 74:81c47fff88a5 | 2 | |
klauss | 81:3656f00ab3db | 3 | QSPIFileSystem qspifs("qspi"); |
klauss | 81:3656f00ab3db | 4 | |
klauss | 121:ee02790d00b7 | 5 | char file_buffer [ FILE_BUFFER_SIZE ]; |
klauss | 121:ee02790d00b7 | 6 | |
klauss | 121:ee02790d00b7 | 7 | void set_ip ( const char * new_header_ip ) |
klauss | 121:ee02790d00b7 | 8 | { |
klauss | 81:3656f00ab3db | 9 | FILE * fip = fopen("/qspi/myip.txt", "w"); |
klauss | 119:ee6a53069455 | 10 | if ( fip ) |
klauss | 119:ee6a53069455 | 11 | { |
klauss | 119:ee6a53069455 | 12 | fprintf( fip, "%s\n\r", new_header_ip ); |
klauss | 119:ee6a53069455 | 13 | fclose( fip ); |
klauss | 119:ee6a53069455 | 14 | } |
klauss | 81:3656f00ab3db | 15 | } |
klauss | 81:3656f00ab3db | 16 | |
klauss | 121:ee02790d00b7 | 17 | int get_ip ( char * header_ip, const size_t length ) |
klauss | 121:ee02790d00b7 | 18 | { |
klauss | 121:ee02790d00b7 | 19 | FILE * fip = fopen("/qspi/myip.txt", "r"); |
klauss | 121:ee02790d00b7 | 20 | if ( fip != NULL ) |
klauss | 121:ee02790d00b7 | 21 | { |
klauss | 121:ee02790d00b7 | 22 | int read = fread ( header_ip, 1, length, fip ); |
klauss | 121:ee02790d00b7 | 23 | if( read > 0 ) |
klauss | 121:ee02790d00b7 | 24 | { |
klauss | 121:ee02790d00b7 | 25 | for ( register int i = 0; i < read; i++ ) |
klauss | 121:ee02790d00b7 | 26 | { |
klauss | 121:ee02790d00b7 | 27 | if( header_ip [ i ] == '\n' || header_ip [ i ] == '\r' ) |
klauss | 121:ee02790d00b7 | 28 | { |
klauss | 121:ee02790d00b7 | 29 | header_ip [ i ] = '\0'; |
klauss | 121:ee02790d00b7 | 30 | break; |
klauss | 121:ee02790d00b7 | 31 | } |
klauss | 121:ee02790d00b7 | 32 | } |
klauss | 121:ee02790d00b7 | 33 | |
klauss | 121:ee02790d00b7 | 34 | if ( debug_file ) debug_msg ("Eth ip %s", header_ip ); |
klauss | 121:ee02790d00b7 | 35 | } else { |
klauss | 121:ee02790d00b7 | 36 | return ( -3 ); |
klauss | 121:ee02790d00b7 | 37 | } |
klauss | 121:ee02790d00b7 | 38 | |
klauss | 121:ee02790d00b7 | 39 | header_ip [ length ] = 0; |
klauss | 121:ee02790d00b7 | 40 | |
klauss | 121:ee02790d00b7 | 41 | fclose ( fip ); |
klauss | 121:ee02790d00b7 | 42 | |
klauss | 121:ee02790d00b7 | 43 | return ( read ); |
klauss | 121:ee02790d00b7 | 44 | } |
klauss | 121:ee02790d00b7 | 45 | |
klauss | 121:ee02790d00b7 | 46 | if ( debug_file ) debug_msg ("Failed to open /qspi/myip.txt" ); |
klauss | 121:ee02790d00b7 | 47 | |
klauss | 121:ee02790d00b7 | 48 | return ( -1 ); |
klauss | 121:ee02790d00b7 | 49 | } |
klauss | 121:ee02790d00b7 | 50 | |
klauss | 121:ee02790d00b7 | 51 | void set_header_ext ( const int new_header_ext ) |
klauss | 121:ee02790d00b7 | 52 | { |
klauss | 81:3656f00ab3db | 53 | FILE * fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 119:ee6a53069455 | 54 | if ( fext ) |
klauss | 119:ee6a53069455 | 55 | { |
klauss | 119:ee6a53069455 | 56 | fprintf( fext, "%i\n\r", new_header_ext ); |
klauss | 119:ee6a53069455 | 57 | fclose( fext ); |
klauss | 119:ee6a53069455 | 58 | } |
klauss | 81:3656f00ab3db | 59 | } |
klauss | 81:3656f00ab3db | 60 | |
klauss | 121:ee02790d00b7 | 61 | void set_header_sip_port ( const int new_header_sip_port ) |
klauss | 121:ee02790d00b7 | 62 | { |
klauss | 119:ee6a53069455 | 63 | FILE * fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 119:ee6a53069455 | 64 | if ( fport ) |
klauss | 119:ee6a53069455 | 65 | { |
klauss | 119:ee6a53069455 | 66 | fprintf( fport,"%i\n\r", new_header_sip_port ); |
klauss | 119:ee6a53069455 | 67 | fclose( fport ); |
klauss | 119:ee6a53069455 | 68 | } |
klauss | 117:e9facba9db27 | 69 | } |
klauss | 117:e9facba9db27 | 70 | |
klauss | 121:ee02790d00b7 | 71 | void set_server_ip ( const char * new_server_ip ) |
klauss | 121:ee02790d00b7 | 72 | { |
klauss | 119:ee6a53069455 | 73 | FILE * fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 119:ee6a53069455 | 74 | if ( fsip ) |
klauss | 119:ee6a53069455 | 75 | { |
klauss | 119:ee6a53069455 | 76 | fprintf( fsip,"%s\n\r", new_server_ip ); |
klauss | 119:ee6a53069455 | 77 | fclose( fsip ); |
klauss | 119:ee6a53069455 | 78 | } |
klauss | 81:3656f00ab3db | 79 | } |
klauss | 81:3656f00ab3db | 80 | |
klauss | 121:ee02790d00b7 | 81 | void set_server_ext ( const int new_server_ext ) |
klauss | 121:ee02790d00b7 | 82 | { |
klauss | 119:ee6a53069455 | 83 | FILE * fserext = fopen("/qspi/peerext.txt", "w"); |
klauss | 119:ee6a53069455 | 84 | if ( fserext ) |
klauss | 119:ee6a53069455 | 85 | { |
klauss | 119:ee6a53069455 | 86 | fprintf( fserext , "%i\n\r", new_server_ext ); |
klauss | 119:ee6a53069455 | 87 | fclose( fserext ); |
klauss | 119:ee6a53069455 | 88 | } |
klauss | 117:e9facba9db27 | 89 | } |
klauss | 117:e9facba9db27 | 90 | |
klauss | 121:ee02790d00b7 | 91 | void set_server_port ( const int new_server_port ) |
klauss | 121:ee02790d00b7 | 92 | { |
klauss | 119:ee6a53069455 | 93 | FILE * fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 119:ee6a53069455 | 94 | if ( fsport ) |
klauss | 119:ee6a53069455 | 95 | { |
klauss | 119:ee6a53069455 | 96 | fprintf(fsport,"%i\n\r", new_server_port ); |
klauss | 119:ee6a53069455 | 97 | fclose( fsport ); |
klauss | 99:e80850c51106 | 98 | } |
klauss | 81:3656f00ab3db | 99 | } |
klauss | 81:3656f00ab3db | 100 | |
klauss | 121:ee02790d00b7 | 101 | void set_mask ( const char * new_mask ) |
klauss | 121:ee02790d00b7 | 102 | { |
klauss | 119:ee6a53069455 | 103 | FILE * fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 119:ee6a53069455 | 104 | if ( fmask ) |
klauss | 119:ee6a53069455 | 105 | { |
klauss | 119:ee6a53069455 | 106 | fprintf(fmask,"%s\n\r",new_mask ); |
klauss | 119:ee6a53069455 | 107 | fclose( fmask ); |
klauss | 119:ee6a53069455 | 108 | } |
klauss | 119:ee6a53069455 | 109 | } |
klauss | 119:ee6a53069455 | 110 | |
klauss | 121:ee02790d00b7 | 111 | void set_gateway ( const char * new_gateway ) |
klauss | 121:ee02790d00b7 | 112 | { |
klauss | 119:ee6a53069455 | 113 | //fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 119:ee6a53069455 | 114 | FILE * fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 119:ee6a53069455 | 115 | if ( fgate ) |
klauss | 119:ee6a53069455 | 116 | { |
klauss | 119:ee6a53069455 | 117 | fprintf(fgate,"%s\n\r", new_gateway ); |
klauss | 119:ee6a53069455 | 118 | fclose( fgate ); |
klauss | 119:ee6a53069455 | 119 | } |
klauss | 119:ee6a53069455 | 120 | } |
klauss | 119:ee6a53069455 | 121 | |
klauss | 121:ee02790d00b7 | 122 | void set_udp_port_listener ( const int new_udp_port_listener ) |
klauss | 121:ee02790d00b7 | 123 | { |
klauss | 119:ee6a53069455 | 124 | FILE * fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 119:ee6a53069455 | 125 | if ( fudpport ) |
klauss | 119:ee6a53069455 | 126 | { |
klauss | 119:ee6a53069455 | 127 | fprintf( fudpport, "%i\n\r",new_udp_port_listener ); |
klauss | 119:ee6a53069455 | 128 | fclose( fudpport ); |
klauss | 119:ee6a53069455 | 129 | } |
klauss | 119:ee6a53069455 | 130 | } |
klauss | 119:ee6a53069455 | 131 | |
klauss | 121:ee02790d00b7 | 132 | void set_tcp_port_listener ( const int new_tcp_port_listener ) |
klauss | 121:ee02790d00b7 | 133 | { |
klauss | 119:ee6a53069455 | 134 | FILE * ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 119:ee6a53069455 | 135 | if ( ftcpport ) |
klauss | 119:ee6a53069455 | 136 | { |
klauss | 119:ee6a53069455 | 137 | fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); |
klauss | 119:ee6a53069455 | 138 | fclose( ftcpport ); |
klauss | 119:ee6a53069455 | 139 | } |
klauss | 119:ee6a53069455 | 140 | } |
klauss | 119:ee6a53069455 | 141 | |
klauss | 121:ee02790d00b7 | 142 | void set_fw_ip ( const char * new_fw_ip ) |
klauss | 121:ee02790d00b7 | 143 | { |
klauss | 119:ee6a53069455 | 144 | FILE * ffwip = fopen("/qspi/fw_ip.txt", "w" ); |
klauss | 119:ee6a53069455 | 145 | if ( ffwip ) |
klauss | 119:ee6a53069455 | 146 | { |
klauss | 119:ee6a53069455 | 147 | fprintf(ffwip,"%s\n\r", new_fw_ip ); |
klauss | 119:ee6a53069455 | 148 | fclose( ffwip ); |
klauss | 119:ee6a53069455 | 149 | } |
klauss | 119:ee6a53069455 | 150 | } |
klauss | 119:ee6a53069455 | 151 | |
klauss | 121:ee02790d00b7 | 152 | void set_fw_port ( const int new_fw_port ) |
klauss | 121:ee02790d00b7 | 153 | { |
klauss | 119:ee6a53069455 | 154 | FILE * ffwport = fopen("/qspi/fw_port.txt", "w" ); |
klauss | 119:ee6a53069455 | 155 | if ( ffwport ) |
klauss | 119:ee6a53069455 | 156 | { |
klauss | 119:ee6a53069455 | 157 | fprintf(ffwport,"%i\n\r", new_fw_port ); |
klauss | 119:ee6a53069455 | 158 | fclose( ffwport ); |
klauss | 119:ee6a53069455 | 159 | } |
klauss | 119:ee6a53069455 | 160 | } |
klauss | 119:ee6a53069455 | 161 | |
klauss | 121:ee02790d00b7 | 162 | void set_max_ext ( const int new_max_ext ) |
klauss | 121:ee02790d00b7 | 163 | { |
klauss | 119:ee6a53069455 | 164 | FILE * fmex = fopen( "/qspi/maxext.txt", "w" ); |
klauss | 119:ee6a53069455 | 165 | if ( fmex ){ |
klauss | 119:ee6a53069455 | 166 | fprintf( fmex, "%i\n\r", new_max_ext ); |
klauss | 119:ee6a53069455 | 167 | fclose( fmex ); |
klauss | 119:ee6a53069455 | 168 | } |
klauss | 119:ee6a53069455 | 169 | } |
klauss | 119:ee6a53069455 | 170 | |
klauss | 121:ee02790d00b7 | 171 | void set_min_ext ( const int new_min_ext ) |
klauss | 121:ee02790d00b7 | 172 | { |
klauss | 81:3656f00ab3db | 173 | FILE * fmin = fopen( "/qspi/minext.txt", "w" ); |
klauss | 119:ee6a53069455 | 174 | if ( fmin ){ |
klauss | 99:e80850c51106 | 175 | fprintf( fmin, "%i\n\r", new_min_ext ); |
klauss | 99:e80850c51106 | 176 | fclose( fmin ); |
klauss | 99:e80850c51106 | 177 | } |
klauss | 81:3656f00ab3db | 178 | } |
klauss | 81:3656f00ab3db | 179 | |
klauss | 81:3656f00ab3db | 180 | // Print the content of a given file |
klauss | 121:ee02790d00b7 | 181 | void cat ( const char * fname ) |
klauss | 121:ee02790d00b7 | 182 | { |
klauss | 81:3656f00ab3db | 183 | char buff[513]; |
klauss | 81:3656f00ab3db | 184 | int num; |
klauss | 81:3656f00ab3db | 185 | |
klauss | 119:ee6a53069455 | 186 | FILE *fp = fopen( fname, "r" ); |
klauss | 81:3656f00ab3db | 187 | if (fp == NULL) { |
klauss | 119:ee6a53069455 | 188 | if( debug_file ) if( debug_uart3 && !( from_eth ) ) pc.printf( "Failed to open %s", fname); |
klauss | 81:3656f00ab3db | 189 | return; |
klauss | 81:3656f00ab3db | 190 | } |
klauss | 81:3656f00ab3db | 191 | |
klauss | 81:3656f00ab3db | 192 | while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ |
klauss | 81:3656f00ab3db | 193 | buff[ num ] = '\0'; |
klauss | 119:ee6a53069455 | 194 | if( debug_uart3 && !( from_eth ) ) pc.printf( buff ); |
klauss | 81:3656f00ab3db | 195 | if( from_eth ){ |
klauss | 119:ee6a53069455 | 196 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); |
klauss | 81:3656f00ab3db | 197 | |
klauss | 119:ee6a53069455 | 198 | else if( udp_query ){ |
klauss | 119:ee6a53069455 | 199 | udp_query_send_msg( buff ); |
klauss | 81:3656f00ab3db | 200 | } |
klauss | 81:3656f00ab3db | 201 | } |
klauss | 81:3656f00ab3db | 202 | } |
klauss | 81:3656f00ab3db | 203 | fclose(fp); |
klauss | 114:472502b31a12 | 204 | } |
klauss | 114:472502b31a12 | 205 | |
klauss | 121:ee02790d00b7 | 206 | void set_shift_port( const int new_shift_port ) |
klauss | 121:ee02790d00b7 | 207 | { |
klauss | 119:ee6a53069455 | 208 | FILE * shift_port = fopen("/qspi/shift_port.txt", "w" ); |
klauss | 119:ee6a53069455 | 209 | if( shift_port ) |
klauss | 119:ee6a53069455 | 210 | { |
klauss | 119:ee6a53069455 | 211 | fprintf( shift_port,"%i\n\r", new_shift_port ); |
klauss | 119:ee6a53069455 | 212 | fclose( shift_port ); |
klauss | 119:ee6a53069455 | 213 | if( debug_file ) debug_msg("Set /qspi/shift_port.txt"); |
klauss | 114:472502b31a12 | 214 | } |
klauss | 119:ee6a53069455 | 215 | else |
klauss | 119:ee6a53069455 | 216 | { |
klauss | 119:ee6a53069455 | 217 | if( debug_file ) debug_msg("Cannot open /qspi/shift_port.txt"); |
klauss | 119:ee6a53069455 | 218 | } |
klauss | 121:ee02790d00b7 | 219 | } |
klauss | 121:ee02790d00b7 | 220 | |
klauss | 121:ee02790d00b7 | 221 | void files( const char type ) |
klauss | 121:ee02790d00b7 | 222 | { |
klauss | 121:ee02790d00b7 | 223 | FILE *fip = NULL; |
klauss | 121:ee02790d00b7 | 224 | FILE *fmask = NULL; |
klauss | 121:ee02790d00b7 | 225 | FILE *fgate = NULL; |
klauss | 121:ee02790d00b7 | 226 | FILE *fport = NULL; |
klauss | 121:ee02790d00b7 | 227 | FILE *fsip = NULL; |
klauss | 121:ee02790d00b7 | 228 | FILE *fsport = NULL; |
klauss | 121:ee02790d00b7 | 229 | FILE *fext = NULL; |
klauss | 121:ee02790d00b7 | 230 | FILE *fserext = NULL; |
klauss | 121:ee02790d00b7 | 231 | FILE *fudpport = NULL; |
klauss | 121:ee02790d00b7 | 232 | FILE *ftcpport = NULL; |
klauss | 121:ee02790d00b7 | 233 | FILE *ffwip = NULL; |
klauss | 121:ee02790d00b7 | 234 | FILE *ffwport = NULL; |
klauss | 121:ee02790d00b7 | 235 | FILE *fmax = NULL; |
klauss | 121:ee02790d00b7 | 236 | FILE *fmin = NULL; |
klauss | 121:ee02790d00b7 | 237 | FILE *fshift_port = NULL; |
klauss | 121:ee02790d00b7 | 238 | |
klauss | 121:ee02790d00b7 | 239 | // show files |
klauss | 121:ee02790d00b7 | 240 | if ( type == 's' ) { |
klauss | 121:ee02790d00b7 | 241 | |
klauss | 121:ee02790d00b7 | 242 | if( debug_uart3 && !( from_eth ) ) pc.printf("Header IP " ); |
klauss | 121:ee02790d00b7 | 243 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 244 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Header IP " ); |
klauss | 121:ee02790d00b7 | 245 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 246 | |
klauss | 121:ee02790d00b7 | 247 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 248 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 249 | } |
klauss | 121:ee02790d00b7 | 250 | } |
klauss | 121:ee02790d00b7 | 251 | |
klauss | 121:ee02790d00b7 | 252 | cat ("/qspi/myip.txt"); |
klauss | 121:ee02790d00b7 | 253 | |
klauss | 121:ee02790d00b7 | 254 | if( debug_uart3 && !( from_eth ) ) pc.printf("Header ext "); |
klauss | 121:ee02790d00b7 | 255 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 256 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Header ext " ); |
klauss | 121:ee02790d00b7 | 257 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 258 | |
klauss | 121:ee02790d00b7 | 259 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 260 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 261 | } |
klauss | 121:ee02790d00b7 | 262 | } |
klauss | 121:ee02790d00b7 | 263 | |
klauss | 121:ee02790d00b7 | 264 | cat("/qspi/myext.txt"); |
klauss | 121:ee02790d00b7 | 265 | |
klauss | 121:ee02790d00b7 | 266 | if( debug_uart3 && !( from_eth ) ) pc.printf("Header port "); |
klauss | 121:ee02790d00b7 | 267 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 268 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Header port " ); |
klauss | 121:ee02790d00b7 | 269 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 270 | |
klauss | 121:ee02790d00b7 | 271 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 272 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 273 | } |
klauss | 121:ee02790d00b7 | 274 | } |
klauss | 121:ee02790d00b7 | 275 | |
klauss | 121:ee02790d00b7 | 276 | cat("/qspi/mysipport.txt"); |
klauss | 121:ee02790d00b7 | 277 | |
klauss | 121:ee02790d00b7 | 278 | if( debug_uart3 && !( from_eth ) ) pc.printf("Server IP "); |
klauss | 121:ee02790d00b7 | 279 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 280 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Server IP " ); |
klauss | 121:ee02790d00b7 | 281 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 282 | |
klauss | 121:ee02790d00b7 | 283 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 284 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 285 | } |
klauss | 121:ee02790d00b7 | 286 | } |
klauss | 121:ee02790d00b7 | 287 | |
klauss | 121:ee02790d00b7 | 288 | cat("/qspi/serverip.txt"); |
klauss | 121:ee02790d00b7 | 289 | |
klauss | 121:ee02790d00b7 | 290 | if( debug_uart3 && !( from_eth ) ) pc.printf("Server ext "); |
klauss | 121:ee02790d00b7 | 291 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 292 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Server ext " ); |
klauss | 121:ee02790d00b7 | 293 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 294 | |
klauss | 121:ee02790d00b7 | 295 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 296 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 297 | } |
klauss | 121:ee02790d00b7 | 298 | } |
klauss | 121:ee02790d00b7 | 299 | |
klauss | 121:ee02790d00b7 | 300 | cat("/qspi/peerext.txt"); |
klauss | 121:ee02790d00b7 | 301 | |
klauss | 121:ee02790d00b7 | 302 | if( debug_uart3 && !( from_eth ) ) pc.printf("Server port "); |
klauss | 121:ee02790d00b7 | 303 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 304 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Server port " ); |
klauss | 121:ee02790d00b7 | 305 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 306 | |
klauss | 121:ee02790d00b7 | 307 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 308 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 309 | } |
klauss | 121:ee02790d00b7 | 310 | } |
klauss | 121:ee02790d00b7 | 311 | cat("/qspi/serverport.txt"); |
klauss | 121:ee02790d00b7 | 312 | |
klauss | 121:ee02790d00b7 | 313 | if( debug_uart3 && !( from_eth ) ) pc.printf("Mascara de rede "); |
klauss | 121:ee02790d00b7 | 314 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 315 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Mascara de rede " ); |
klauss | 121:ee02790d00b7 | 316 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 317 | |
klauss | 121:ee02790d00b7 | 318 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 319 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 320 | } |
klauss | 121:ee02790d00b7 | 321 | } |
klauss | 121:ee02790d00b7 | 322 | cat("/qspi/mymask.txt"); |
klauss | 121:ee02790d00b7 | 323 | |
klauss | 121:ee02790d00b7 | 324 | if( debug_uart3 && !( from_eth ) ) pc.printf("Gateway IP "); |
klauss | 121:ee02790d00b7 | 325 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 326 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Gateway IP " ); |
klauss | 121:ee02790d00b7 | 327 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 328 | |
klauss | 121:ee02790d00b7 | 329 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 330 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 331 | } |
klauss | 121:ee02790d00b7 | 332 | } |
klauss | 121:ee02790d00b7 | 333 | cat("/qspi/mygateway.txt"); |
klauss | 121:ee02790d00b7 | 334 | |
klauss | 121:ee02790d00b7 | 335 | if( debug_uart3 && !( from_eth ) ) pc.printf("UDP Port "); |
klauss | 121:ee02790d00b7 | 336 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 337 | snprintf( file_buffer, FILE_BUFFER_SIZE, "UDP Port " ); |
klauss | 121:ee02790d00b7 | 338 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 339 | |
klauss | 121:ee02790d00b7 | 340 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 341 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 342 | } |
klauss | 121:ee02790d00b7 | 343 | } |
klauss | 121:ee02790d00b7 | 344 | |
klauss | 121:ee02790d00b7 | 345 | cat("/qspi/udpport.txt"); |
klauss | 121:ee02790d00b7 | 346 | |
klauss | 121:ee02790d00b7 | 347 | if( debug_uart3 && !( from_eth ) ) pc.printf("TCP Port "); |
klauss | 121:ee02790d00b7 | 348 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 349 | snprintf( file_buffer, FILE_BUFFER_SIZE, "TCP Port " ); |
klauss | 121:ee02790d00b7 | 350 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 351 | |
klauss | 121:ee02790d00b7 | 352 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 353 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 354 | } |
klauss | 121:ee02790d00b7 | 355 | } |
klauss | 121:ee02790d00b7 | 356 | |
klauss | 121:ee02790d00b7 | 357 | cat("/qspi/tcpport.txt"); |
klauss | 121:ee02790d00b7 | 358 | |
klauss | 121:ee02790d00b7 | 359 | if( debug_uart3 && !( from_eth ) ) pc.printf("FW Server IP "); |
klauss | 121:ee02790d00b7 | 360 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 361 | snprintf( file_buffer, FILE_BUFFER_SIZE, "FW Server IP " ); |
klauss | 121:ee02790d00b7 | 362 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 363 | |
klauss | 121:ee02790d00b7 | 364 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 365 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 366 | } |
klauss | 121:ee02790d00b7 | 367 | } |
klauss | 121:ee02790d00b7 | 368 | |
klauss | 121:ee02790d00b7 | 369 | cat("/qspi/fw_ip.txt"); |
klauss | 121:ee02790d00b7 | 370 | |
klauss | 121:ee02790d00b7 | 371 | if( debug_uart3 && !( from_eth ) ) pc.printf("FW Server Port "); |
klauss | 121:ee02790d00b7 | 372 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 373 | snprintf( file_buffer, FILE_BUFFER_SIZE, "FW Server Port " ); |
klauss | 121:ee02790d00b7 | 374 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 375 | |
klauss | 121:ee02790d00b7 | 376 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 377 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 378 | } |
klauss | 121:ee02790d00b7 | 379 | } |
klauss | 121:ee02790d00b7 | 380 | |
klauss | 121:ee02790d00b7 | 381 | cat("/qspi/fw_port.txt"); |
klauss | 121:ee02790d00b7 | 382 | |
klauss | 121:ee02790d00b7 | 383 | if( debug_uart3 && !( from_eth ) ) pc.printf("Max Ext "); |
klauss | 121:ee02790d00b7 | 384 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 385 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Max Ext " ); |
klauss | 121:ee02790d00b7 | 386 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 387 | |
klauss | 121:ee02790d00b7 | 388 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 389 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 390 | } |
klauss | 121:ee02790d00b7 | 391 | } |
klauss | 121:ee02790d00b7 | 392 | |
klauss | 121:ee02790d00b7 | 393 | cat("/qspi/maxext.txt"); |
klauss | 121:ee02790d00b7 | 394 | |
klauss | 121:ee02790d00b7 | 395 | if( debug_uart3 && !( from_eth ) ) pc.printf("Min Ext "); |
klauss | 121:ee02790d00b7 | 396 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 397 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Min Ext " ); |
klauss | 121:ee02790d00b7 | 398 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 399 | |
klauss | 121:ee02790d00b7 | 400 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 401 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 402 | } |
klauss | 121:ee02790d00b7 | 403 | } |
klauss | 121:ee02790d00b7 | 404 | |
klauss | 121:ee02790d00b7 | 405 | cat("/qspi/minext.txt"); |
klauss | 121:ee02790d00b7 | 406 | |
klauss | 121:ee02790d00b7 | 407 | if( debug_uart3 && !( from_eth ) ) pc.printf("Shift Port "); |
klauss | 121:ee02790d00b7 | 408 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 409 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Shift Port " ); |
klauss | 121:ee02790d00b7 | 410 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 411 | |
klauss | 121:ee02790d00b7 | 412 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 413 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 414 | } |
klauss | 121:ee02790d00b7 | 415 | } |
klauss | 121:ee02790d00b7 | 416 | |
klauss | 121:ee02790d00b7 | 417 | cat("/qspi/shift_port.txt"); |
klauss | 121:ee02790d00b7 | 418 | |
klauss | 121:ee02790d00b7 | 419 | if( debug_uart3 && !( from_eth ) ) pc.printf("Clock Server IP "); |
klauss | 121:ee02790d00b7 | 420 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 421 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Clock Server IP " ); |
klauss | 121:ee02790d00b7 | 422 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 423 | |
klauss | 121:ee02790d00b7 | 424 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 425 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 426 | } |
klauss | 121:ee02790d00b7 | 427 | } |
klauss | 121:ee02790d00b7 | 428 | |
klauss | 121:ee02790d00b7 | 429 | cat("/qspi/serverip.txt"); |
klauss | 121:ee02790d00b7 | 430 | |
klauss | 121:ee02790d00b7 | 431 | if( debug_uart3 && !( from_eth ) ) pc.printf("Clock Server Port %d\r\n", CLOCK_SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 432 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 433 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Clock Server Port %d\r\n", CLOCK_SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 434 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 435 | |
klauss | 121:ee02790d00b7 | 436 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 437 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 438 | } |
klauss | 121:ee02790d00b7 | 439 | } |
klauss | 121:ee02790d00b7 | 440 | |
klauss | 121:ee02790d00b7 | 441 | if( debug_uart3 && !( from_eth ) ) pc.printf("Clock Header Port %d\r\n", CLOCK_HEADER_PORT ); |
klauss | 121:ee02790d00b7 | 442 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 443 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Clock Header Port %d\r\n", CLOCK_HEADER_PORT ); |
klauss | 121:ee02790d00b7 | 444 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 445 | |
klauss | 121:ee02790d00b7 | 446 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 447 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 448 | } |
klauss | 121:ee02790d00b7 | 449 | } |
klauss | 121:ee02790d00b7 | 450 | |
klauss | 121:ee02790d00b7 | 451 | if( debug_uart3 && !( from_eth ) ) pc.printf("Bootloader Port %d\r\n", BL_PORT ); |
klauss | 121:ee02790d00b7 | 452 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 453 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Bootloader Port %d\r\n", BL_PORT ); |
klauss | 121:ee02790d00b7 | 454 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 455 | |
klauss | 121:ee02790d00b7 | 456 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 457 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 458 | } |
klauss | 121:ee02790d00b7 | 459 | } |
klauss | 121:ee02790d00b7 | 460 | |
klauss | 121:ee02790d00b7 | 461 | //*------------ formatando a saida ----------------*// |
klauss | 121:ee02790d00b7 | 462 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 463 | |
klauss | 121:ee02790d00b7 | 464 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 465 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 466 | snprintf( file_buffer, FILE_BUFFER_SIZE, "> " ); |
klauss | 121:ee02790d00b7 | 467 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 468 | } else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 469 | udp_query_send_msg( "> " ); |
klauss | 121:ee02790d00b7 | 470 | |
klauss | 121:ee02790d00b7 | 471 | } |
klauss | 121:ee02790d00b7 | 472 | } |
klauss | 121:ee02790d00b7 | 473 | } |
klauss | 121:ee02790d00b7 | 474 | |
klauss | 121:ee02790d00b7 | 475 | if (type == 'c' ) { |
klauss | 121:ee02790d00b7 | 476 | // close all files |
klauss | 121:ee02790d00b7 | 477 | if( fip ) fclose( fip ); |
klauss | 121:ee02790d00b7 | 478 | if( fmask ) fclose( fmask ); |
klauss | 121:ee02790d00b7 | 479 | if( fgate ) fclose( fgate ); |
klauss | 121:ee02790d00b7 | 480 | if( fport )fclose( fport ); |
klauss | 121:ee02790d00b7 | 481 | if( fsip ) fclose( fsip ); |
klauss | 121:ee02790d00b7 | 482 | if( fsport ) fclose( fsport ); |
klauss | 121:ee02790d00b7 | 483 | if( fext ) fclose( fext ); |
klauss | 121:ee02790d00b7 | 484 | if( fserext ) fclose( fserext ); |
klauss | 121:ee02790d00b7 | 485 | if( fudpport ) fclose( fudpport ); |
klauss | 121:ee02790d00b7 | 486 | if( ftcpport ) fclose( ftcpport ); |
klauss | 121:ee02790d00b7 | 487 | if( fmax ) fclose( fmax ); |
klauss | 121:ee02790d00b7 | 488 | if( fmin ) fclose( fmin ); |
klauss | 121:ee02790d00b7 | 489 | if( ffwip ) fclose( ffwip ); |
klauss | 121:ee02790d00b7 | 490 | if( ffwport) fclose( ffwport ); |
klauss | 121:ee02790d00b7 | 491 | if( fshift_port ) fclose ( fshift_port ); |
klauss | 121:ee02790d00b7 | 492 | } |
klauss | 121:ee02790d00b7 | 493 | |
klauss | 121:ee02790d00b7 | 494 | |
klauss | 121:ee02790d00b7 | 495 | // Check if files exist, if not create the files |
klauss | 121:ee02790d00b7 | 496 | //fixme criar um bool pra cada file |
klauss | 121:ee02790d00b7 | 497 | if (type == 'i' ) |
klauss | 121:ee02790d00b7 | 498 | { |
klauss | 121:ee02790d00b7 | 499 | bool exists = true; |
klauss | 121:ee02790d00b7 | 500 | |
klauss | 121:ee02790d00b7 | 501 | fip = fopen ("/qspi/myip.txt", "r"); |
klauss | 121:ee02790d00b7 | 502 | if( fip == NULL) { |
klauss | 121:ee02790d00b7 | 503 | set_ip( MY_IP ); |
klauss | 121:ee02790d00b7 | 504 | exists = false; |
klauss | 121:ee02790d00b7 | 505 | } |
klauss | 121:ee02790d00b7 | 506 | if ( fip ) fclose ( fip ); |
klauss | 121:ee02790d00b7 | 507 | fip = NULL; |
klauss | 121:ee02790d00b7 | 508 | |
klauss | 121:ee02790d00b7 | 509 | fserext = fopen("/qspi/myext.txt", "r"); |
klauss | 121:ee02790d00b7 | 510 | if( fserext == NULL ) { |
klauss | 121:ee02790d00b7 | 511 | set_header_ext( MY_EXT ); |
klauss | 121:ee02790d00b7 | 512 | exists = false; |
klauss | 121:ee02790d00b7 | 513 | } |
klauss | 121:ee02790d00b7 | 514 | if ( fserext ) fclose ( fserext ); |
klauss | 121:ee02790d00b7 | 515 | fserext = NULL; |
klauss | 121:ee02790d00b7 | 516 | |
klauss | 121:ee02790d00b7 | 517 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 121:ee02790d00b7 | 518 | if (fport == NULL) { |
klauss | 121:ee02790d00b7 | 519 | set_header_sip_port( MY_PORT ); |
klauss | 121:ee02790d00b7 | 520 | exists = false; |
klauss | 121:ee02790d00b7 | 521 | } |
klauss | 121:ee02790d00b7 | 522 | if ( fport ) fclose ( fport ); |
klauss | 121:ee02790d00b7 | 523 | fport = NULL; |
klauss | 121:ee02790d00b7 | 524 | |
klauss | 121:ee02790d00b7 | 525 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 121:ee02790d00b7 | 526 | if (fsip == NULL) { |
klauss | 121:ee02790d00b7 | 527 | set_server_ip( SERVER_IP ); |
klauss | 121:ee02790d00b7 | 528 | exists = false; |
klauss | 121:ee02790d00b7 | 529 | } |
klauss | 121:ee02790d00b7 | 530 | if ( fsip ) fclose ( fsip ); |
klauss | 121:ee02790d00b7 | 531 | fsip = NULL; |
klauss | 121:ee02790d00b7 | 532 | |
klauss | 121:ee02790d00b7 | 533 | fext = fopen("/qspi/peerext.txt", "r"); |
klauss | 121:ee02790d00b7 | 534 | if ( fext == NULL ) { |
klauss | 121:ee02790d00b7 | 535 | set_server_ext( PEER_EXT ); |
klauss | 121:ee02790d00b7 | 536 | exists = false; |
klauss | 121:ee02790d00b7 | 537 | } |
klauss | 121:ee02790d00b7 | 538 | if ( fext ) fclose ( fext ); |
klauss | 121:ee02790d00b7 | 539 | fext = NULL; |
klauss | 121:ee02790d00b7 | 540 | |
klauss | 121:ee02790d00b7 | 541 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 121:ee02790d00b7 | 542 | if (fsport == NULL) { |
klauss | 121:ee02790d00b7 | 543 | set_server_port( SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 544 | exists = false; |
klauss | 121:ee02790d00b7 | 545 | } |
klauss | 121:ee02790d00b7 | 546 | if ( fsport ) fclose ( fsport ); |
klauss | 121:ee02790d00b7 | 547 | fsport = NULL; |
klauss | 121:ee02790d00b7 | 548 | |
klauss | 121:ee02790d00b7 | 549 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 121:ee02790d00b7 | 550 | if (fmask == NULL) { |
klauss | 121:ee02790d00b7 | 551 | set_mask( MY_MSK ); |
klauss | 121:ee02790d00b7 | 552 | exists = false; |
klauss | 121:ee02790d00b7 | 553 | } |
klauss | 121:ee02790d00b7 | 554 | if ( fmask ) fclose ( fmask ); |
klauss | 121:ee02790d00b7 | 555 | fmask = NULL; |
klauss | 121:ee02790d00b7 | 556 | |
klauss | 121:ee02790d00b7 | 557 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 121:ee02790d00b7 | 558 | if (fgate == NULL) { |
klauss | 121:ee02790d00b7 | 559 | set_gateway( MY_GTW ); |
klauss | 121:ee02790d00b7 | 560 | exists = false; |
klauss | 121:ee02790d00b7 | 561 | } |
klauss | 121:ee02790d00b7 | 562 | if ( fgate ) fclose ( fgate ); |
klauss | 121:ee02790d00b7 | 563 | fgate = NULL; |
klauss | 121:ee02790d00b7 | 564 | |
klauss | 121:ee02790d00b7 | 565 | fudpport = fopen("/qspi/udpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 566 | if( fudpport == NULL ) { |
klauss | 121:ee02790d00b7 | 567 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 568 | exists = false; |
klauss | 121:ee02790d00b7 | 569 | } |
klauss | 121:ee02790d00b7 | 570 | if ( fudpport ) fclose ( fudpport ); |
klauss | 121:ee02790d00b7 | 571 | fudpport = NULL; |
klauss | 121:ee02790d00b7 | 572 | |
klauss | 121:ee02790d00b7 | 573 | ftcpport = fopen("/qspi/tcpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 574 | if( ftcpport == NULL ) { |
klauss | 121:ee02790d00b7 | 575 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 576 | exists = false; |
klauss | 121:ee02790d00b7 | 577 | } |
klauss | 121:ee02790d00b7 | 578 | if ( ftcpport ) fclose ( ftcpport ); |
klauss | 121:ee02790d00b7 | 579 | ftcpport = NULL; |
klauss | 121:ee02790d00b7 | 580 | |
klauss | 121:ee02790d00b7 | 581 | ffwip = fopen("/qspi/fw_ip.txt", "r" ); |
klauss | 121:ee02790d00b7 | 582 | if( ffwip == NULL ) { |
klauss | 121:ee02790d00b7 | 583 | set_fw_ip( __FW_SERVER_IP__ ); |
klauss | 121:ee02790d00b7 | 584 | exists = false; |
klauss | 121:ee02790d00b7 | 585 | } |
klauss | 121:ee02790d00b7 | 586 | if ( ffwip ) fclose ( ffwip ); |
klauss | 121:ee02790d00b7 | 587 | ffwip = NULL; |
klauss | 121:ee02790d00b7 | 588 | |
klauss | 121:ee02790d00b7 | 589 | ffwport = fopen("/qspi/fw_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 590 | if( ffwport == NULL ) { |
klauss | 121:ee02790d00b7 | 591 | set_fw_port( __FW_SERVER_PORT__ ); |
klauss | 121:ee02790d00b7 | 592 | exists = false; |
klauss | 121:ee02790d00b7 | 593 | } |
klauss | 121:ee02790d00b7 | 594 | if ( ffwport ) fclose ( ffwport ); |
klauss | 121:ee02790d00b7 | 595 | ffwport = NULL; |
klauss | 121:ee02790d00b7 | 596 | |
klauss | 121:ee02790d00b7 | 597 | fmax = fopen("/qspi/maxext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 598 | if( fmax == NULL ) { |
klauss | 121:ee02790d00b7 | 599 | set_max_ext( MAX_EXT ); |
klauss | 121:ee02790d00b7 | 600 | exists = false; |
klauss | 121:ee02790d00b7 | 601 | } |
klauss | 121:ee02790d00b7 | 602 | if ( fmax ) fclose ( fmax ); |
klauss | 121:ee02790d00b7 | 603 | fmax = NULL; |
klauss | 121:ee02790d00b7 | 604 | |
klauss | 121:ee02790d00b7 | 605 | fmin = fopen("/qspi/minext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 606 | if( fmin == NULL ) { |
klauss | 121:ee02790d00b7 | 607 | if( debug_file ) debug_msg("Don't exist /qspi/minext.txt"); |
klauss | 121:ee02790d00b7 | 608 | set_min_ext( MIN_EXT ); |
klauss | 121:ee02790d00b7 | 609 | exists = false; |
klauss | 121:ee02790d00b7 | 610 | } |
klauss | 121:ee02790d00b7 | 611 | if ( fmin ) fclose ( fmin ); |
klauss | 121:ee02790d00b7 | 612 | fmin = NULL; |
klauss | 121:ee02790d00b7 | 613 | |
klauss | 121:ee02790d00b7 | 614 | fshift_port = fopen("/qspi/shift_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 615 | if( fshift_port == NULL ) |
klauss | 121:ee02790d00b7 | 616 | { |
klauss | 121:ee02790d00b7 | 617 | if( debug_file ) debug_msg("Don't exist /qspi/shift_port.txt"); |
klauss | 121:ee02790d00b7 | 618 | set_shift_port( SHIFT_PORT ); |
klauss | 121:ee02790d00b7 | 619 | exists = false; |
klauss | 121:ee02790d00b7 | 620 | } |
klauss | 121:ee02790d00b7 | 621 | if ( fshift_port ) fclose ( fshift_port ); |
klauss | 121:ee02790d00b7 | 622 | fshift_port = NULL; |
klauss | 121:ee02790d00b7 | 623 | |
klauss | 121:ee02790d00b7 | 624 | if( !exists ) { |
klauss | 121:ee02790d00b7 | 625 | if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 626 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 627 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Default configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 628 | file_buffer[ strlen( file_buffer ) - 1 ] = '\0'; |
klauss | 121:ee02790d00b7 | 629 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 630 | tcp_client.send_all( file_buffer, strlen( file_buffer ) ); |
klauss | 121:ee02790d00b7 | 631 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 632 | } |
klauss | 121:ee02790d00b7 | 633 | } |
klauss | 121:ee02790d00b7 | 634 | } |
klauss | 121:ee02790d00b7 | 635 | } |
klauss | 121:ee02790d00b7 | 636 | |
klauss | 121:ee02790d00b7 | 637 | if (type == 'r' ) { |
klauss | 121:ee02790d00b7 | 638 | // Just open for read |
klauss | 121:ee02790d00b7 | 639 | fip = fopen ("/qspi/myip.txt", "r"); |
klauss | 121:ee02790d00b7 | 640 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 121:ee02790d00b7 | 641 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 121:ee02790d00b7 | 642 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 121:ee02790d00b7 | 643 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 121:ee02790d00b7 | 644 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 121:ee02790d00b7 | 645 | fext = fopen( "/qspi/myext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 646 | fserext = fopen( "/qspi/peerext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 647 | fudpport = fopen( "/qspi/udpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 648 | ftcpport = fopen( "/qspi/tcpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 649 | ffwip = fopen("/qspi/fw_ip.txt", "r" ); |
klauss | 121:ee02790d00b7 | 650 | ffwport = fopen("/qspi/fw_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 651 | fmax = fopen("/qspi/maxext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 652 | fmin = fopen("/qspi/minext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 653 | fshift_port = fopen("/qspi/shift_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 654 | |
klauss | 121:ee02790d00b7 | 655 | } |
klauss | 121:ee02790d00b7 | 656 | |
klauss | 121:ee02790d00b7 | 657 | if( type == 'w') { |
klauss | 121:ee02790d00b7 | 658 | |
klauss | 121:ee02790d00b7 | 659 | // Create and write the default configs |
klauss | 121:ee02790d00b7 | 660 | set_ip( MY_IP ); |
klauss | 121:ee02790d00b7 | 661 | |
klauss | 121:ee02790d00b7 | 662 | set_header_sip_port( MY_PORT ); |
klauss | 121:ee02790d00b7 | 663 | |
klauss | 121:ee02790d00b7 | 664 | set_header_ext( MY_EXT ); |
klauss | 121:ee02790d00b7 | 665 | |
klauss | 121:ee02790d00b7 | 666 | set_server_ip( SERVER_IP ); |
klauss | 121:ee02790d00b7 | 667 | |
klauss | 121:ee02790d00b7 | 668 | set_server_ext( PEER_EXT ); |
klauss | 121:ee02790d00b7 | 669 | |
klauss | 121:ee02790d00b7 | 670 | set_server_port( SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 671 | |
klauss | 121:ee02790d00b7 | 672 | set_mask( MY_MSK ); |
klauss | 121:ee02790d00b7 | 673 | |
klauss | 121:ee02790d00b7 | 674 | set_gateway( MY_GTW ); |
klauss | 121:ee02790d00b7 | 675 | |
klauss | 121:ee02790d00b7 | 676 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 677 | |
klauss | 121:ee02790d00b7 | 678 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 679 | |
klauss | 121:ee02790d00b7 | 680 | set_fw_ip( __FW_SERVER_IP__ ); |
klauss | 121:ee02790d00b7 | 681 | |
klauss | 121:ee02790d00b7 | 682 | set_fw_port( __FW_SERVER_PORT__ ); |
klauss | 121:ee02790d00b7 | 683 | |
klauss | 121:ee02790d00b7 | 684 | set_max_ext( MAX_EXT ); |
klauss | 121:ee02790d00b7 | 685 | |
klauss | 121:ee02790d00b7 | 686 | set_min_ext( MIN_EXT ); |
klauss | 121:ee02790d00b7 | 687 | |
klauss | 121:ee02790d00b7 | 688 | set_shift_port( SHIFT_PORT ); |
klauss | 121:ee02790d00b7 | 689 | |
klauss | 121:ee02790d00b7 | 690 | if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 691 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 692 | snprintf( file_buffer, FILE_BUFFER_SIZE, "\n\rDefault configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 693 | file_buffer[ strlen( file_buffer ) - 1 ] = '\0'; |
klauss | 121:ee02790d00b7 | 694 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 695 | tcp_client.send_all( file_buffer, strlen( file_buffer ) ); |
klauss | 121:ee02790d00b7 | 696 | } else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 697 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 698 | } |
klauss | 121:ee02790d00b7 | 699 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 700 | } |
klauss | 121:ee02790d00b7 | 701 | |
klauss | 121:ee02790d00b7 | 702 | } |
klauss | 121:ee02790d00b7 | 703 | |
klauss | 121:ee02790d00b7 | 704 | if (type == 'e') |
klauss | 121:ee02790d00b7 | 705 | { |
klauss | 121:ee02790d00b7 | 706 | //Erase configs |
klauss | 121:ee02790d00b7 | 707 | fip = fopen ("/qspi/myip.txt", "w"); |
klauss | 121:ee02790d00b7 | 708 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 121:ee02790d00b7 | 709 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 121:ee02790d00b7 | 710 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 121:ee02790d00b7 | 711 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 121:ee02790d00b7 | 712 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 121:ee02790d00b7 | 713 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 714 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 715 | fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 121:ee02790d00b7 | 716 | ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 121:ee02790d00b7 | 717 | ffwip = fopen("/qspi/fw_ip.txt", "w" ); |
klauss | 121:ee02790d00b7 | 718 | ffwport = fopen("/qspi/fw_port.txt", "w" ); |
klauss | 121:ee02790d00b7 | 719 | fmax = fopen("/qspi/maxext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 720 | fmin = fopen("/qspi/minext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 721 | fshift_port = fopen("/qspi/shift_port.txt", "w" ); |
klauss | 121:ee02790d00b7 | 722 | |
klauss | 121:ee02790d00b7 | 723 | if( fip ) fprintf( fip, "%s\n\r", "" ); |
klauss | 121:ee02790d00b7 | 724 | if( fport ) fprintf( fport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 725 | if( fext ) fprintf( fext, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 726 | |
klauss | 121:ee02790d00b7 | 727 | if( fsip ) fprintf( fsip, "%s\n\r", "" ); |
klauss | 121:ee02790d00b7 | 728 | if( fserext ) fprintf( fserext, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 729 | if( fsport ) fprintf( fsport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 730 | |
klauss | 121:ee02790d00b7 | 731 | if( fmask ) fprintf( fmask, "%s\n\r","" ); |
klauss | 121:ee02790d00b7 | 732 | if( fgate ) fprintf( fgate, "%s\n\r", "" ); |
klauss | 121:ee02790d00b7 | 733 | |
klauss | 121:ee02790d00b7 | 734 | if( fudpport ) fprintf( fudpport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 735 | if( ftcpport ) fprintf( ftcpport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 736 | |
klauss | 121:ee02790d00b7 | 737 | if( ffwip ) fprintf( ffwip, "%s\n\r","" ); |
klauss | 121:ee02790d00b7 | 738 | if( ffwport ) fprintf( ffwport, "%i\n\r",0 ); |
klauss | 121:ee02790d00b7 | 739 | |
klauss | 121:ee02790d00b7 | 740 | if( fmax ) fprintf( fmax, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 741 | if( fmin ) fprintf( fmin, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 742 | |
klauss | 121:ee02790d00b7 | 743 | if( fshift_port ) fprintf( fshift_port, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 744 | |
klauss | 121:ee02790d00b7 | 745 | files('c'); |
klauss | 121:ee02790d00b7 | 746 | |
klauss | 121:ee02790d00b7 | 747 | if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rErased configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 748 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 749 | snprintf( file_buffer, FILE_BUFFER_SIZE, "\n\rErased configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 750 | file_buffer[ strlen( file_buffer ) - 1 ] = '\0'; |
klauss | 121:ee02790d00b7 | 751 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 752 | tcp_client.send_all( file_buffer, strlen( file_buffer ) ); |
klauss | 121:ee02790d00b7 | 753 | } else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 754 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 755 | } |
klauss | 121:ee02790d00b7 | 756 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 757 | } |
klauss | 121:ee02790d00b7 | 758 | |
klauss | 121:ee02790d00b7 | 759 | } |
klauss | 121:ee02790d00b7 | 760 | } |
klauss | 121:ee02790d00b7 | 761 | |
klauss | 121:ee02790d00b7 | 762 | int init_fsystem ( void ) |
klauss | 121:ee02790d00b7 | 763 | { |
klauss | 121:ee02790d00b7 | 764 | // init file system and check if files exist |
klauss | 121:ee02790d00b7 | 765 | int return_value = 0; |
klauss | 121:ee02790d00b7 | 766 | |
klauss | 121:ee02790d00b7 | 767 | if (!qspifs.isformatted()) { |
klauss | 121:ee02790d00b7 | 768 | qspifs.format(); |
klauss | 121:ee02790d00b7 | 769 | return_value |= BIT0; |
klauss | 121:ee02790d00b7 | 770 | } |
klauss | 121:ee02790d00b7 | 771 | // check if the files are created |
klauss | 121:ee02790d00b7 | 772 | files('i'); |
klauss | 121:ee02790d00b7 | 773 | files('c'); |
klauss | 121:ee02790d00b7 | 774 | |
klauss | 121:ee02790d00b7 | 775 | return ( return_value |= BIT1 ); |
klauss | 119:ee6a53069455 | 776 | } |