![](/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@122:480c44b0e205, 2015-05-11 (annotated)
- Committer:
- klauss
- Date:
- Mon May 11 15:16:36 2015 +0000
- Revision:
- 122:480c44b0e205
- Parent:
- 121:ee02790d00b7
- Child:
- 124:c1b6c893e1c3
E00 - Limitar em 1500 o show_sip
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 | 122:480c44b0e205 | 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 | 122:480c44b0e205 | 36 | if ( fip ) fclose ( fip ); |
klauss | 121:ee02790d00b7 | 37 | return ( -3 ); |
klauss | 121:ee02790d00b7 | 38 | } |
klauss | 121:ee02790d00b7 | 39 | |
klauss | 121:ee02790d00b7 | 40 | header_ip [ length ] = 0; |
klauss | 121:ee02790d00b7 | 41 | |
klauss | 122:480c44b0e205 | 42 | if ( fip ) fclose ( fip ); |
klauss | 121:ee02790d00b7 | 43 | |
klauss | 121:ee02790d00b7 | 44 | return ( read ); |
klauss | 121:ee02790d00b7 | 45 | } |
klauss | 121:ee02790d00b7 | 46 | |
klauss | 121:ee02790d00b7 | 47 | if ( debug_file ) debug_msg ("Failed to open /qspi/myip.txt" ); |
klauss | 121:ee02790d00b7 | 48 | |
klauss | 122:480c44b0e205 | 49 | return ( -1 ); |
klauss | 122:480c44b0e205 | 50 | } |
klauss | 122:480c44b0e205 | 51 | |
klauss | 122:480c44b0e205 | 52 | int get_clock_server_ip ( char * clock_server_ip, const size_t length ) |
klauss | 122:480c44b0e205 | 53 | { |
klauss | 122:480c44b0e205 | 54 | return ( get_server_ip ( clock_server_ip, length ) ); |
klauss | 122:480c44b0e205 | 55 | } |
klauss | 122:480c44b0e205 | 56 | |
klauss | 122:480c44b0e205 | 57 | int get_server_ip ( char * server_ip, const size_t length ) |
klauss | 122:480c44b0e205 | 58 | { |
klauss | 122:480c44b0e205 | 59 | FILE * fsip = fopen ("/qspi/serverip.txt", "r" ); |
klauss | 122:480c44b0e205 | 60 | if ( fsip != NULL ) |
klauss | 122:480c44b0e205 | 61 | { |
klauss | 122:480c44b0e205 | 62 | int read = fread ( server_ip, 1, length, fsip ); |
klauss | 122:480c44b0e205 | 63 | if( read > 0 ) |
klauss | 122:480c44b0e205 | 64 | { |
klauss | 122:480c44b0e205 | 65 | for ( register int i = 0; i < read; i++ ) |
klauss | 122:480c44b0e205 | 66 | { |
klauss | 122:480c44b0e205 | 67 | if( server_ip [ i ] == '\n' || server_ip [ i ] == '\r' ) |
klauss | 122:480c44b0e205 | 68 | { |
klauss | 122:480c44b0e205 | 69 | server_ip [ i ] = '\0'; |
klauss | 122:480c44b0e205 | 70 | break; |
klauss | 122:480c44b0e205 | 71 | } |
klauss | 122:480c44b0e205 | 72 | } |
klauss | 122:480c44b0e205 | 73 | |
klauss | 122:480c44b0e205 | 74 | if ( debug_file ) debug_msg ("Eth ip %s", server_ip ); |
klauss | 122:480c44b0e205 | 75 | } else { |
klauss | 122:480c44b0e205 | 76 | if ( fsip ) fclose ( fsip ); |
klauss | 122:480c44b0e205 | 77 | return ( -3 ); |
klauss | 122:480c44b0e205 | 78 | } |
klauss | 122:480c44b0e205 | 79 | |
klauss | 122:480c44b0e205 | 80 | server_ip [ length ] = 0; |
klauss | 122:480c44b0e205 | 81 | |
klauss | 122:480c44b0e205 | 82 | fclose ( fsip ); |
klauss | 122:480c44b0e205 | 83 | |
klauss | 122:480c44b0e205 | 84 | return ( read ); |
klauss | 122:480c44b0e205 | 85 | } |
klauss | 122:480c44b0e205 | 86 | |
klauss | 122:480c44b0e205 | 87 | if ( debug_file ) debug_msg ("Failed to open /qspi/serverip.txt" ); |
klauss | 122:480c44b0e205 | 88 | |
klauss | 122:480c44b0e205 | 89 | return ( -1 ); |
klauss | 122:480c44b0e205 | 90 | } |
klauss | 122:480c44b0e205 | 91 | |
klauss | 122:480c44b0e205 | 92 | int get_mask ( char * eth_mask, const size_t length ) |
klauss | 122:480c44b0e205 | 93 | { |
klauss | 122:480c44b0e205 | 94 | FILE * fmsk = fopen("/qspi/mymask.txt", "r"); |
klauss | 122:480c44b0e205 | 95 | if ( fmsk != NULL ) |
klauss | 122:480c44b0e205 | 96 | { |
klauss | 122:480c44b0e205 | 97 | int read = fread ( eth_mask, 1, length, fmsk ); |
klauss | 122:480c44b0e205 | 98 | if( read > 0 ) |
klauss | 122:480c44b0e205 | 99 | { |
klauss | 122:480c44b0e205 | 100 | for ( register int i = 0; i < read; i++ ) |
klauss | 122:480c44b0e205 | 101 | { |
klauss | 122:480c44b0e205 | 102 | if( eth_mask [ i ] == '\n' || eth_mask [ i ] == '\r' ) |
klauss | 122:480c44b0e205 | 103 | { |
klauss | 122:480c44b0e205 | 104 | eth_mask [ i ] = '\0'; |
klauss | 122:480c44b0e205 | 105 | break; |
klauss | 122:480c44b0e205 | 106 | } |
klauss | 122:480c44b0e205 | 107 | } |
klauss | 122:480c44b0e205 | 108 | |
klauss | 122:480c44b0e205 | 109 | if ( debug_file ) debug_msg ("Eth mask %s", eth_mask ); |
klauss | 122:480c44b0e205 | 110 | } else { |
klauss | 122:480c44b0e205 | 111 | if ( fmsk ) fclose ( fmsk ); |
klauss | 122:480c44b0e205 | 112 | return ( -3 ); |
klauss | 122:480c44b0e205 | 113 | } |
klauss | 122:480c44b0e205 | 114 | |
klauss | 122:480c44b0e205 | 115 | eth_mask [ length ] = 0; |
klauss | 122:480c44b0e205 | 116 | |
klauss | 122:480c44b0e205 | 117 | if ( fmsk ) fclose ( fmsk ); |
klauss | 122:480c44b0e205 | 118 | |
klauss | 122:480c44b0e205 | 119 | return ( read ); |
klauss | 122:480c44b0e205 | 120 | } |
klauss | 122:480c44b0e205 | 121 | |
klauss | 122:480c44b0e205 | 122 | if ( debug_file ) debug_msg ("Failed to open /qspi/mymask.txt" ); |
klauss | 122:480c44b0e205 | 123 | |
klauss | 121:ee02790d00b7 | 124 | return ( -1 ); |
klauss | 121:ee02790d00b7 | 125 | } |
klauss | 122:480c44b0e205 | 126 | int get_gateway ( char * eth_gw, const size_t length ) |
klauss | 122:480c44b0e205 | 127 | { |
klauss | 122:480c44b0e205 | 128 | FILE * fgw = fopen("/qspi/mygateway.txt", "r"); |
klauss | 122:480c44b0e205 | 129 | if ( fgw != NULL ) |
klauss | 122:480c44b0e205 | 130 | { |
klauss | 122:480c44b0e205 | 131 | int read = fread ( eth_gw, 1, length, fgw ); |
klauss | 122:480c44b0e205 | 132 | if( read > 0 ) |
klauss | 122:480c44b0e205 | 133 | { |
klauss | 122:480c44b0e205 | 134 | for ( register int i = 0; i < read; i++ ) |
klauss | 122:480c44b0e205 | 135 | { |
klauss | 122:480c44b0e205 | 136 | if( eth_gw [ i ] == '\n' || eth_gw [ i ] == '\r' ) |
klauss | 122:480c44b0e205 | 137 | { |
klauss | 122:480c44b0e205 | 138 | eth_gw [ i ] = '\0'; |
klauss | 122:480c44b0e205 | 139 | break; |
klauss | 122:480c44b0e205 | 140 | } |
klauss | 122:480c44b0e205 | 141 | } |
klauss | 122:480c44b0e205 | 142 | |
klauss | 122:480c44b0e205 | 143 | if ( debug_file ) debug_msg ("Eth gateway %s", eth_gw ); |
klauss | 122:480c44b0e205 | 144 | } else { |
klauss | 122:480c44b0e205 | 145 | if ( fgw ) fclose ( fgw ); |
klauss | 122:480c44b0e205 | 146 | return ( -3 ); |
klauss | 122:480c44b0e205 | 147 | } |
klauss | 122:480c44b0e205 | 148 | |
klauss | 122:480c44b0e205 | 149 | eth_gw [ length ] = 0; |
klauss | 122:480c44b0e205 | 150 | |
klauss | 122:480c44b0e205 | 151 | if ( fgw ) fclose ( fgw ); |
klauss | 122:480c44b0e205 | 152 | |
klauss | 122:480c44b0e205 | 153 | return ( read ); |
klauss | 122:480c44b0e205 | 154 | } |
klauss | 122:480c44b0e205 | 155 | |
klauss | 122:480c44b0e205 | 156 | if ( debug_file ) debug_msg ("Failed to open /qspi/mygateway.txt" ); |
klauss | 122:480c44b0e205 | 157 | |
klauss | 122:480c44b0e205 | 158 | return ( -1 ); |
klauss | 122:480c44b0e205 | 159 | } |
klauss | 122:480c44b0e205 | 160 | |
klauss | 122:480c44b0e205 | 161 | void set_clock_server_ip ( const char * new_server_ip ); |
klauss | 121:ee02790d00b7 | 162 | |
klauss | 121:ee02790d00b7 | 163 | void set_header_ext ( const int new_header_ext ) |
klauss | 121:ee02790d00b7 | 164 | { |
klauss | 81:3656f00ab3db | 165 | FILE * fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 119:ee6a53069455 | 166 | if ( fext ) |
klauss | 119:ee6a53069455 | 167 | { |
klauss | 119:ee6a53069455 | 168 | fprintf( fext, "%i\n\r", new_header_ext ); |
klauss | 119:ee6a53069455 | 169 | fclose( fext ); |
klauss | 119:ee6a53069455 | 170 | } |
klauss | 81:3656f00ab3db | 171 | } |
klauss | 81:3656f00ab3db | 172 | |
klauss | 122:480c44b0e205 | 173 | |
klauss | 122:480c44b0e205 | 174 | int get_header_ext ( void ) |
klauss | 122:480c44b0e205 | 175 | { |
klauss | 122:480c44b0e205 | 176 | char get_header_ext_buffer [ 32 ] = ""; |
klauss | 122:480c44b0e205 | 177 | |
klauss | 122:480c44b0e205 | 178 | FILE * fext = fopen ( "/qspi/myext.txt", "r" ); |
klauss | 122:480c44b0e205 | 179 | if ( fext == NULL ) |
klauss | 122:480c44b0e205 | 180 | { |
klauss | 122:480c44b0e205 | 181 | if( debug_file ) debug_msg ( "Failed to open /qspi/myext.txt" ); |
klauss | 122:480c44b0e205 | 182 | |
klauss | 122:480c44b0e205 | 183 | return ( PEER_EXT ); |
klauss | 122:480c44b0e205 | 184 | } else { |
klauss | 122:480c44b0e205 | 185 | if( fread ( ( void * ) get_header_ext_buffer, 1, sizeof ( get_header_ext_buffer ) - 1, fext ) > 0 ) |
klauss | 122:480c44b0e205 | 186 | { |
klauss | 122:480c44b0e205 | 187 | if ( fext ) fclose ( fext ); |
klauss | 122:480c44b0e205 | 188 | return ( atoi ( get_header_ext_buffer ) ); |
klauss | 122:480c44b0e205 | 189 | } else { |
klauss | 122:480c44b0e205 | 190 | if ( debug_file ) debug_msg ("Failed to read /qspi/myext.txt" ); |
klauss | 122:480c44b0e205 | 191 | |
klauss | 122:480c44b0e205 | 192 | if ( fext ) fclose ( fext ); |
klauss | 122:480c44b0e205 | 193 | return ( PEER_EXT ); |
klauss | 122:480c44b0e205 | 194 | } |
klauss | 122:480c44b0e205 | 195 | } |
klauss | 122:480c44b0e205 | 196 | } |
klauss | 122:480c44b0e205 | 197 | |
klauss | 121:ee02790d00b7 | 198 | void set_header_sip_port ( const int new_header_sip_port ) |
klauss | 121:ee02790d00b7 | 199 | { |
klauss | 119:ee6a53069455 | 200 | FILE * fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 119:ee6a53069455 | 201 | if ( fport ) |
klauss | 119:ee6a53069455 | 202 | { |
klauss | 119:ee6a53069455 | 203 | fprintf( fport,"%i\n\r", new_header_sip_port ); |
klauss | 119:ee6a53069455 | 204 | fclose( fport ); |
klauss | 119:ee6a53069455 | 205 | } |
klauss | 117:e9facba9db27 | 206 | } |
klauss | 117:e9facba9db27 | 207 | |
klauss | 122:480c44b0e205 | 208 | int get_header_sip_port ( void ) |
klauss | 122:480c44b0e205 | 209 | { |
klauss | 122:480c44b0e205 | 210 | char get_header_sip_port_buffer [ 32 ] = ""; |
klauss | 122:480c44b0e205 | 211 | |
klauss | 122:480c44b0e205 | 212 | FILE * fport = fopen ( "/qspi/mysipport.txt", "r" ); |
klauss | 122:480c44b0e205 | 213 | if ( fport == NULL ) |
klauss | 122:480c44b0e205 | 214 | { |
klauss | 122:480c44b0e205 | 215 | if( debug_file ) debug_msg ( "Failed to open /qspi/mysipport.txt" ); |
klauss | 122:480c44b0e205 | 216 | |
klauss | 122:480c44b0e205 | 217 | return ( MY_PORT ); |
klauss | 122:480c44b0e205 | 218 | } else { |
klauss | 122:480c44b0e205 | 219 | if( fread ( ( void * ) get_header_sip_port_buffer, 1, sizeof ( get_header_sip_port_buffer ) - 1, fport ) > 0 ) |
klauss | 122:480c44b0e205 | 220 | { |
klauss | 122:480c44b0e205 | 221 | if ( fport ) fclose ( fport ); |
klauss | 122:480c44b0e205 | 222 | return ( atoi ( get_header_sip_port_buffer ) ); |
klauss | 122:480c44b0e205 | 223 | } else { |
klauss | 122:480c44b0e205 | 224 | if ( debug_file ) debug_msg ("Failed to read /qspi/mysipport.txt" ); |
klauss | 122:480c44b0e205 | 225 | |
klauss | 122:480c44b0e205 | 226 | if ( fport ) fclose ( fport ); |
klauss | 122:480c44b0e205 | 227 | return ( MY_PORT ); |
klauss | 122:480c44b0e205 | 228 | } |
klauss | 122:480c44b0e205 | 229 | } |
klauss | 122:480c44b0e205 | 230 | } |
klauss | 122:480c44b0e205 | 231 | |
klauss | 121:ee02790d00b7 | 232 | void set_server_ip ( const char * new_server_ip ) |
klauss | 121:ee02790d00b7 | 233 | { |
klauss | 119:ee6a53069455 | 234 | FILE * fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 119:ee6a53069455 | 235 | if ( fsip ) |
klauss | 119:ee6a53069455 | 236 | { |
klauss | 119:ee6a53069455 | 237 | fprintf( fsip,"%s\n\r", new_server_ip ); |
klauss | 119:ee6a53069455 | 238 | fclose( fsip ); |
klauss | 119:ee6a53069455 | 239 | } |
klauss | 81:3656f00ab3db | 240 | } |
klauss | 81:3656f00ab3db | 241 | |
klauss | 121:ee02790d00b7 | 242 | void set_server_ext ( const int new_server_ext ) |
klauss | 121:ee02790d00b7 | 243 | { |
klauss | 119:ee6a53069455 | 244 | FILE * fserext = fopen("/qspi/peerext.txt", "w"); |
klauss | 119:ee6a53069455 | 245 | if ( fserext ) |
klauss | 119:ee6a53069455 | 246 | { |
klauss | 119:ee6a53069455 | 247 | fprintf( fserext , "%i\n\r", new_server_ext ); |
klauss | 119:ee6a53069455 | 248 | fclose( fserext ); |
klauss | 119:ee6a53069455 | 249 | } |
klauss | 117:e9facba9db27 | 250 | } |
klauss | 117:e9facba9db27 | 251 | |
klauss | 121:ee02790d00b7 | 252 | void set_server_port ( const int new_server_port ) |
klauss | 121:ee02790d00b7 | 253 | { |
klauss | 119:ee6a53069455 | 254 | FILE * fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 119:ee6a53069455 | 255 | if ( fsport ) |
klauss | 119:ee6a53069455 | 256 | { |
klauss | 119:ee6a53069455 | 257 | fprintf(fsport,"%i\n\r", new_server_port ); |
klauss | 119:ee6a53069455 | 258 | fclose( fsport ); |
klauss | 99:e80850c51106 | 259 | } |
klauss | 81:3656f00ab3db | 260 | } |
klauss | 81:3656f00ab3db | 261 | |
klauss | 121:ee02790d00b7 | 262 | void set_mask ( const char * new_mask ) |
klauss | 121:ee02790d00b7 | 263 | { |
klauss | 119:ee6a53069455 | 264 | FILE * fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 119:ee6a53069455 | 265 | if ( fmask ) |
klauss | 119:ee6a53069455 | 266 | { |
klauss | 119:ee6a53069455 | 267 | fprintf(fmask,"%s\n\r",new_mask ); |
klauss | 119:ee6a53069455 | 268 | fclose( fmask ); |
klauss | 119:ee6a53069455 | 269 | } |
klauss | 119:ee6a53069455 | 270 | } |
klauss | 119:ee6a53069455 | 271 | |
klauss | 121:ee02790d00b7 | 272 | void set_gateway ( const char * new_gateway ) |
klauss | 121:ee02790d00b7 | 273 | { |
klauss | 119:ee6a53069455 | 274 | //fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 119:ee6a53069455 | 275 | FILE * fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 119:ee6a53069455 | 276 | if ( fgate ) |
klauss | 119:ee6a53069455 | 277 | { |
klauss | 119:ee6a53069455 | 278 | fprintf(fgate,"%s\n\r", new_gateway ); |
klauss | 119:ee6a53069455 | 279 | fclose( fgate ); |
klauss | 119:ee6a53069455 | 280 | } |
klauss | 119:ee6a53069455 | 281 | } |
klauss | 119:ee6a53069455 | 282 | |
klauss | 121:ee02790d00b7 | 283 | void set_udp_port_listener ( const int new_udp_port_listener ) |
klauss | 121:ee02790d00b7 | 284 | { |
klauss | 119:ee6a53069455 | 285 | FILE * fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 119:ee6a53069455 | 286 | if ( fudpport ) |
klauss | 119:ee6a53069455 | 287 | { |
klauss | 119:ee6a53069455 | 288 | fprintf( fudpport, "%i\n\r",new_udp_port_listener ); |
klauss | 119:ee6a53069455 | 289 | fclose( fudpport ); |
klauss | 119:ee6a53069455 | 290 | } |
klauss | 119:ee6a53069455 | 291 | } |
klauss | 119:ee6a53069455 | 292 | |
klauss | 121:ee02790d00b7 | 293 | void set_tcp_port_listener ( const int new_tcp_port_listener ) |
klauss | 121:ee02790d00b7 | 294 | { |
klauss | 119:ee6a53069455 | 295 | FILE * ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 119:ee6a53069455 | 296 | if ( ftcpport ) |
klauss | 119:ee6a53069455 | 297 | { |
klauss | 119:ee6a53069455 | 298 | fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); |
klauss | 119:ee6a53069455 | 299 | fclose( ftcpport ); |
klauss | 119:ee6a53069455 | 300 | } |
klauss | 119:ee6a53069455 | 301 | } |
klauss | 119:ee6a53069455 | 302 | |
klauss | 121:ee02790d00b7 | 303 | void set_fw_ip ( const char * new_fw_ip ) |
klauss | 121:ee02790d00b7 | 304 | { |
klauss | 119:ee6a53069455 | 305 | FILE * ffwip = fopen("/qspi/fw_ip.txt", "w" ); |
klauss | 119:ee6a53069455 | 306 | if ( ffwip ) |
klauss | 119:ee6a53069455 | 307 | { |
klauss | 119:ee6a53069455 | 308 | fprintf(ffwip,"%s\n\r", new_fw_ip ); |
klauss | 119:ee6a53069455 | 309 | fclose( ffwip ); |
klauss | 119:ee6a53069455 | 310 | } |
klauss | 119:ee6a53069455 | 311 | } |
klauss | 119:ee6a53069455 | 312 | |
klauss | 121:ee02790d00b7 | 313 | void set_fw_port ( const int new_fw_port ) |
klauss | 121:ee02790d00b7 | 314 | { |
klauss | 119:ee6a53069455 | 315 | FILE * ffwport = fopen("/qspi/fw_port.txt", "w" ); |
klauss | 119:ee6a53069455 | 316 | if ( ffwport ) |
klauss | 119:ee6a53069455 | 317 | { |
klauss | 119:ee6a53069455 | 318 | fprintf(ffwport,"%i\n\r", new_fw_port ); |
klauss | 119:ee6a53069455 | 319 | fclose( ffwport ); |
klauss | 119:ee6a53069455 | 320 | } |
klauss | 119:ee6a53069455 | 321 | } |
klauss | 119:ee6a53069455 | 322 | |
klauss | 121:ee02790d00b7 | 323 | void set_max_ext ( const int new_max_ext ) |
klauss | 121:ee02790d00b7 | 324 | { |
klauss | 119:ee6a53069455 | 325 | FILE * fmex = fopen( "/qspi/maxext.txt", "w" ); |
klauss | 119:ee6a53069455 | 326 | if ( fmex ){ |
klauss | 119:ee6a53069455 | 327 | fprintf( fmex, "%i\n\r", new_max_ext ); |
klauss | 119:ee6a53069455 | 328 | fclose( fmex ); |
klauss | 119:ee6a53069455 | 329 | } |
klauss | 119:ee6a53069455 | 330 | } |
klauss | 119:ee6a53069455 | 331 | |
klauss | 121:ee02790d00b7 | 332 | void set_min_ext ( const int new_min_ext ) |
klauss | 121:ee02790d00b7 | 333 | { |
klauss | 81:3656f00ab3db | 334 | FILE * fmin = fopen( "/qspi/minext.txt", "w" ); |
klauss | 119:ee6a53069455 | 335 | if ( fmin ){ |
klauss | 99:e80850c51106 | 336 | fprintf( fmin, "%i\n\r", new_min_ext ); |
klauss | 99:e80850c51106 | 337 | fclose( fmin ); |
klauss | 99:e80850c51106 | 338 | } |
klauss | 81:3656f00ab3db | 339 | } |
klauss | 81:3656f00ab3db | 340 | |
klauss | 81:3656f00ab3db | 341 | // Print the content of a given file |
klauss | 121:ee02790d00b7 | 342 | void cat ( const char * fname ) |
klauss | 121:ee02790d00b7 | 343 | { |
klauss | 81:3656f00ab3db | 344 | char buff[513]; |
klauss | 81:3656f00ab3db | 345 | int num; |
klauss | 81:3656f00ab3db | 346 | |
klauss | 119:ee6a53069455 | 347 | FILE *fp = fopen( fname, "r" ); |
klauss | 81:3656f00ab3db | 348 | if (fp == NULL) { |
klauss | 119:ee6a53069455 | 349 | if( debug_file ) if( debug_uart3 && !( from_eth ) ) pc.printf( "Failed to open %s", fname); |
klauss | 81:3656f00ab3db | 350 | return; |
klauss | 81:3656f00ab3db | 351 | } |
klauss | 81:3656f00ab3db | 352 | |
klauss | 81:3656f00ab3db | 353 | while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ |
klauss | 81:3656f00ab3db | 354 | buff[ num ] = '\0'; |
klauss | 119:ee6a53069455 | 355 | if( debug_uart3 && !( from_eth ) ) pc.printf( buff ); |
klauss | 81:3656f00ab3db | 356 | if( from_eth ){ |
klauss | 119:ee6a53069455 | 357 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); |
klauss | 81:3656f00ab3db | 358 | |
klauss | 119:ee6a53069455 | 359 | else if( udp_query ){ |
klauss | 119:ee6a53069455 | 360 | udp_query_send_msg( buff ); |
klauss | 81:3656f00ab3db | 361 | } |
klauss | 81:3656f00ab3db | 362 | } |
klauss | 81:3656f00ab3db | 363 | } |
klauss | 81:3656f00ab3db | 364 | fclose(fp); |
klauss | 114:472502b31a12 | 365 | } |
klauss | 114:472502b31a12 | 366 | |
klauss | 121:ee02790d00b7 | 367 | void set_shift_port( const int new_shift_port ) |
klauss | 121:ee02790d00b7 | 368 | { |
klauss | 119:ee6a53069455 | 369 | FILE * shift_port = fopen("/qspi/shift_port.txt", "w" ); |
klauss | 119:ee6a53069455 | 370 | if( shift_port ) |
klauss | 119:ee6a53069455 | 371 | { |
klauss | 119:ee6a53069455 | 372 | fprintf( shift_port,"%i\n\r", new_shift_port ); |
klauss | 119:ee6a53069455 | 373 | fclose( shift_port ); |
klauss | 119:ee6a53069455 | 374 | if( debug_file ) debug_msg("Set /qspi/shift_port.txt"); |
klauss | 114:472502b31a12 | 375 | } |
klauss | 119:ee6a53069455 | 376 | else |
klauss | 119:ee6a53069455 | 377 | { |
klauss | 119:ee6a53069455 | 378 | if( debug_file ) debug_msg("Cannot open /qspi/shift_port.txt"); |
klauss | 119:ee6a53069455 | 379 | } |
klauss | 121:ee02790d00b7 | 380 | } |
klauss | 121:ee02790d00b7 | 381 | |
klauss | 122:480c44b0e205 | 382 | void files ( const char type ) |
klauss | 121:ee02790d00b7 | 383 | { |
klauss | 121:ee02790d00b7 | 384 | FILE *fip = NULL; |
klauss | 121:ee02790d00b7 | 385 | FILE *fmask = NULL; |
klauss | 121:ee02790d00b7 | 386 | FILE *fgate = NULL; |
klauss | 121:ee02790d00b7 | 387 | FILE *fport = NULL; |
klauss | 121:ee02790d00b7 | 388 | FILE *fsip = NULL; |
klauss | 121:ee02790d00b7 | 389 | FILE *fsport = NULL; |
klauss | 121:ee02790d00b7 | 390 | FILE *fext = NULL; |
klauss | 121:ee02790d00b7 | 391 | FILE *fserext = NULL; |
klauss | 121:ee02790d00b7 | 392 | FILE *fudpport = NULL; |
klauss | 121:ee02790d00b7 | 393 | FILE *ftcpport = NULL; |
klauss | 121:ee02790d00b7 | 394 | FILE *ffwip = NULL; |
klauss | 121:ee02790d00b7 | 395 | FILE *ffwport = NULL; |
klauss | 121:ee02790d00b7 | 396 | FILE *fmax = NULL; |
klauss | 121:ee02790d00b7 | 397 | FILE *fmin = NULL; |
klauss | 121:ee02790d00b7 | 398 | FILE *fshift_port = NULL; |
klauss | 121:ee02790d00b7 | 399 | |
klauss | 121:ee02790d00b7 | 400 | // show files |
klauss | 121:ee02790d00b7 | 401 | if ( type == 's' ) { |
klauss | 121:ee02790d00b7 | 402 | |
klauss | 121:ee02790d00b7 | 403 | if( debug_uart3 && !( from_eth ) ) pc.printf("Header IP " ); |
klauss | 121:ee02790d00b7 | 404 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 405 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Header IP " ); |
klauss | 121:ee02790d00b7 | 406 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 407 | |
klauss | 121:ee02790d00b7 | 408 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 409 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 410 | } |
klauss | 121:ee02790d00b7 | 411 | } |
klauss | 121:ee02790d00b7 | 412 | |
klauss | 121:ee02790d00b7 | 413 | cat ("/qspi/myip.txt"); |
klauss | 121:ee02790d00b7 | 414 | |
klauss | 121:ee02790d00b7 | 415 | if( debug_uart3 && !( from_eth ) ) pc.printf("Header ext "); |
klauss | 121:ee02790d00b7 | 416 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 417 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Header ext " ); |
klauss | 121:ee02790d00b7 | 418 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 419 | |
klauss | 121:ee02790d00b7 | 420 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 421 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 422 | } |
klauss | 121:ee02790d00b7 | 423 | } |
klauss | 121:ee02790d00b7 | 424 | |
klauss | 121:ee02790d00b7 | 425 | cat("/qspi/myext.txt"); |
klauss | 121:ee02790d00b7 | 426 | |
klauss | 121:ee02790d00b7 | 427 | if( debug_uart3 && !( from_eth ) ) pc.printf("Header port "); |
klauss | 121:ee02790d00b7 | 428 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 429 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Header port " ); |
klauss | 121:ee02790d00b7 | 430 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 431 | |
klauss | 121:ee02790d00b7 | 432 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 433 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 434 | } |
klauss | 121:ee02790d00b7 | 435 | } |
klauss | 121:ee02790d00b7 | 436 | |
klauss | 121:ee02790d00b7 | 437 | cat("/qspi/mysipport.txt"); |
klauss | 121:ee02790d00b7 | 438 | |
klauss | 121:ee02790d00b7 | 439 | if( debug_uart3 && !( from_eth ) ) pc.printf("Server IP "); |
klauss | 121:ee02790d00b7 | 440 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 441 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Server IP " ); |
klauss | 121:ee02790d00b7 | 442 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 443 | |
klauss | 121:ee02790d00b7 | 444 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 445 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 446 | } |
klauss | 121:ee02790d00b7 | 447 | } |
klauss | 121:ee02790d00b7 | 448 | |
klauss | 121:ee02790d00b7 | 449 | cat("/qspi/serverip.txt"); |
klauss | 121:ee02790d00b7 | 450 | |
klauss | 121:ee02790d00b7 | 451 | if( debug_uart3 && !( from_eth ) ) pc.printf("Server ext "); |
klauss | 121:ee02790d00b7 | 452 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 453 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Server ext " ); |
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 | cat("/qspi/peerext.txt"); |
klauss | 121:ee02790d00b7 | 462 | |
klauss | 121:ee02790d00b7 | 463 | if( debug_uart3 && !( from_eth ) ) pc.printf("Server port "); |
klauss | 121:ee02790d00b7 | 464 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 465 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Server port " ); |
klauss | 121:ee02790d00b7 | 466 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 467 | |
klauss | 121:ee02790d00b7 | 468 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 469 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 470 | } |
klauss | 121:ee02790d00b7 | 471 | } |
klauss | 121:ee02790d00b7 | 472 | cat("/qspi/serverport.txt"); |
klauss | 121:ee02790d00b7 | 473 | |
klauss | 121:ee02790d00b7 | 474 | if( debug_uart3 && !( from_eth ) ) pc.printf("Mascara de rede "); |
klauss | 121:ee02790d00b7 | 475 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 476 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Mascara de rede " ); |
klauss | 121:ee02790d00b7 | 477 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 478 | |
klauss | 121:ee02790d00b7 | 479 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 480 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 481 | } |
klauss | 121:ee02790d00b7 | 482 | } |
klauss | 121:ee02790d00b7 | 483 | cat("/qspi/mymask.txt"); |
klauss | 121:ee02790d00b7 | 484 | |
klauss | 121:ee02790d00b7 | 485 | if( debug_uart3 && !( from_eth ) ) pc.printf("Gateway IP "); |
klauss | 121:ee02790d00b7 | 486 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 487 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Gateway IP " ); |
klauss | 121:ee02790d00b7 | 488 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 489 | |
klauss | 121:ee02790d00b7 | 490 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 491 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 492 | } |
klauss | 121:ee02790d00b7 | 493 | } |
klauss | 121:ee02790d00b7 | 494 | cat("/qspi/mygateway.txt"); |
klauss | 121:ee02790d00b7 | 495 | |
klauss | 121:ee02790d00b7 | 496 | if( debug_uart3 && !( from_eth ) ) pc.printf("UDP Port "); |
klauss | 121:ee02790d00b7 | 497 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 498 | snprintf( file_buffer, FILE_BUFFER_SIZE, "UDP Port " ); |
klauss | 121:ee02790d00b7 | 499 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 500 | |
klauss | 121:ee02790d00b7 | 501 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 502 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 503 | } |
klauss | 121:ee02790d00b7 | 504 | } |
klauss | 121:ee02790d00b7 | 505 | |
klauss | 121:ee02790d00b7 | 506 | cat("/qspi/udpport.txt"); |
klauss | 121:ee02790d00b7 | 507 | |
klauss | 121:ee02790d00b7 | 508 | if( debug_uart3 && !( from_eth ) ) pc.printf("TCP Port "); |
klauss | 121:ee02790d00b7 | 509 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 510 | snprintf( file_buffer, FILE_BUFFER_SIZE, "TCP Port " ); |
klauss | 121:ee02790d00b7 | 511 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 512 | |
klauss | 121:ee02790d00b7 | 513 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 514 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 515 | } |
klauss | 121:ee02790d00b7 | 516 | } |
klauss | 121:ee02790d00b7 | 517 | |
klauss | 121:ee02790d00b7 | 518 | cat("/qspi/tcpport.txt"); |
klauss | 121:ee02790d00b7 | 519 | |
klauss | 121:ee02790d00b7 | 520 | if( debug_uart3 && !( from_eth ) ) pc.printf("FW Server IP "); |
klauss | 121:ee02790d00b7 | 521 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 522 | snprintf( file_buffer, FILE_BUFFER_SIZE, "FW Server IP " ); |
klauss | 121:ee02790d00b7 | 523 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 524 | |
klauss | 121:ee02790d00b7 | 525 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 526 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 527 | } |
klauss | 121:ee02790d00b7 | 528 | } |
klauss | 121:ee02790d00b7 | 529 | |
klauss | 121:ee02790d00b7 | 530 | cat("/qspi/fw_ip.txt"); |
klauss | 121:ee02790d00b7 | 531 | |
klauss | 121:ee02790d00b7 | 532 | if( debug_uart3 && !( from_eth ) ) pc.printf("FW Server Port "); |
klauss | 121:ee02790d00b7 | 533 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 534 | snprintf( file_buffer, FILE_BUFFER_SIZE, "FW Server Port " ); |
klauss | 121:ee02790d00b7 | 535 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 536 | |
klauss | 121:ee02790d00b7 | 537 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 538 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 539 | } |
klauss | 121:ee02790d00b7 | 540 | } |
klauss | 121:ee02790d00b7 | 541 | |
klauss | 121:ee02790d00b7 | 542 | cat("/qspi/fw_port.txt"); |
klauss | 121:ee02790d00b7 | 543 | |
klauss | 121:ee02790d00b7 | 544 | if( debug_uart3 && !( from_eth ) ) pc.printf("Max Ext "); |
klauss | 121:ee02790d00b7 | 545 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 546 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Max Ext " ); |
klauss | 121:ee02790d00b7 | 547 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 548 | |
klauss | 121:ee02790d00b7 | 549 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 550 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 551 | } |
klauss | 121:ee02790d00b7 | 552 | } |
klauss | 121:ee02790d00b7 | 553 | |
klauss | 121:ee02790d00b7 | 554 | cat("/qspi/maxext.txt"); |
klauss | 121:ee02790d00b7 | 555 | |
klauss | 121:ee02790d00b7 | 556 | if( debug_uart3 && !( from_eth ) ) pc.printf("Min Ext "); |
klauss | 121:ee02790d00b7 | 557 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 558 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Min Ext " ); |
klauss | 121:ee02790d00b7 | 559 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 560 | |
klauss | 121:ee02790d00b7 | 561 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 562 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 563 | } |
klauss | 121:ee02790d00b7 | 564 | } |
klauss | 121:ee02790d00b7 | 565 | |
klauss | 121:ee02790d00b7 | 566 | cat("/qspi/minext.txt"); |
klauss | 121:ee02790d00b7 | 567 | |
klauss | 121:ee02790d00b7 | 568 | if( debug_uart3 && !( from_eth ) ) pc.printf("Shift Port "); |
klauss | 121:ee02790d00b7 | 569 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 570 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Shift Port " ); |
klauss | 121:ee02790d00b7 | 571 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 572 | |
klauss | 121:ee02790d00b7 | 573 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 574 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 575 | } |
klauss | 121:ee02790d00b7 | 576 | } |
klauss | 121:ee02790d00b7 | 577 | |
klauss | 121:ee02790d00b7 | 578 | cat("/qspi/shift_port.txt"); |
klauss | 121:ee02790d00b7 | 579 | |
klauss | 121:ee02790d00b7 | 580 | if( debug_uart3 && !( from_eth ) ) pc.printf("Clock Server IP "); |
klauss | 121:ee02790d00b7 | 581 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 582 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Clock Server IP " ); |
klauss | 121:ee02790d00b7 | 583 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 584 | |
klauss | 121:ee02790d00b7 | 585 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 586 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 587 | } |
klauss | 121:ee02790d00b7 | 588 | } |
klauss | 121:ee02790d00b7 | 589 | |
klauss | 121:ee02790d00b7 | 590 | cat("/qspi/serverip.txt"); |
klauss | 121:ee02790d00b7 | 591 | |
klauss | 122:480c44b0e205 | 592 | /* |
klauss | 121:ee02790d00b7 | 593 | if( debug_uart3 && !( from_eth ) ) pc.printf("Clock Server Port %d\r\n", CLOCK_SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 594 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 595 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Clock Server Port %d\r\n", CLOCK_SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 596 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 597 | |
klauss | 121:ee02790d00b7 | 598 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 599 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 600 | } |
klauss | 121:ee02790d00b7 | 601 | } |
klauss | 121:ee02790d00b7 | 602 | |
klauss | 121:ee02790d00b7 | 603 | if( debug_uart3 && !( from_eth ) ) pc.printf("Clock Header Port %d\r\n", CLOCK_HEADER_PORT ); |
klauss | 121:ee02790d00b7 | 604 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 605 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Clock Header Port %d\r\n", CLOCK_HEADER_PORT ); |
klauss | 121:ee02790d00b7 | 606 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 607 | |
klauss | 121:ee02790d00b7 | 608 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 609 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 610 | } |
klauss | 121:ee02790d00b7 | 611 | } |
klauss | 121:ee02790d00b7 | 612 | |
klauss | 121:ee02790d00b7 | 613 | if( debug_uart3 && !( from_eth ) ) pc.printf("Bootloader Port %d\r\n", BL_PORT ); |
klauss | 121:ee02790d00b7 | 614 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 615 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Bootloader Port %d\r\n", BL_PORT ); |
klauss | 121:ee02790d00b7 | 616 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 617 | |
klauss | 121:ee02790d00b7 | 618 | else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 619 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 620 | } |
klauss | 121:ee02790d00b7 | 621 | } |
klauss | 122:480c44b0e205 | 622 | */ |
klauss | 121:ee02790d00b7 | 623 | |
klauss | 121:ee02790d00b7 | 624 | //*------------ formatando a saida ----------------*// |
klauss | 121:ee02790d00b7 | 625 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 626 | |
klauss | 121:ee02790d00b7 | 627 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 628 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 629 | snprintf( file_buffer, FILE_BUFFER_SIZE, "> " ); |
klauss | 121:ee02790d00b7 | 630 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( file_buffer, strlen( file_buffer ) ) ) ); |
klauss | 121:ee02790d00b7 | 631 | } else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 632 | udp_query_send_msg( "> " ); |
klauss | 121:ee02790d00b7 | 633 | |
klauss | 121:ee02790d00b7 | 634 | } |
klauss | 121:ee02790d00b7 | 635 | } |
klauss | 121:ee02790d00b7 | 636 | } |
klauss | 121:ee02790d00b7 | 637 | |
klauss | 121:ee02790d00b7 | 638 | if (type == 'c' ) { |
klauss | 121:ee02790d00b7 | 639 | // close all files |
klauss | 121:ee02790d00b7 | 640 | if( fip ) fclose( fip ); |
klauss | 121:ee02790d00b7 | 641 | if( fmask ) fclose( fmask ); |
klauss | 121:ee02790d00b7 | 642 | if( fgate ) fclose( fgate ); |
klauss | 121:ee02790d00b7 | 643 | if( fport )fclose( fport ); |
klauss | 121:ee02790d00b7 | 644 | if( fsip ) fclose( fsip ); |
klauss | 121:ee02790d00b7 | 645 | if( fsport ) fclose( fsport ); |
klauss | 121:ee02790d00b7 | 646 | if( fext ) fclose( fext ); |
klauss | 121:ee02790d00b7 | 647 | if( fserext ) fclose( fserext ); |
klauss | 121:ee02790d00b7 | 648 | if( fudpport ) fclose( fudpport ); |
klauss | 121:ee02790d00b7 | 649 | if( ftcpport ) fclose( ftcpport ); |
klauss | 121:ee02790d00b7 | 650 | if( fmax ) fclose( fmax ); |
klauss | 121:ee02790d00b7 | 651 | if( fmin ) fclose( fmin ); |
klauss | 121:ee02790d00b7 | 652 | if( ffwip ) fclose( ffwip ); |
klauss | 121:ee02790d00b7 | 653 | if( ffwport) fclose( ffwport ); |
klauss | 121:ee02790d00b7 | 654 | if( fshift_port ) fclose ( fshift_port ); |
klauss | 121:ee02790d00b7 | 655 | } |
klauss | 121:ee02790d00b7 | 656 | |
klauss | 121:ee02790d00b7 | 657 | |
klauss | 121:ee02790d00b7 | 658 | // Check if files exist, if not create the files |
klauss | 121:ee02790d00b7 | 659 | //fixme criar um bool pra cada file |
klauss | 121:ee02790d00b7 | 660 | if (type == 'i' ) |
klauss | 121:ee02790d00b7 | 661 | { |
klauss | 121:ee02790d00b7 | 662 | bool exists = true; |
klauss | 121:ee02790d00b7 | 663 | |
klauss | 121:ee02790d00b7 | 664 | fip = fopen ("/qspi/myip.txt", "r"); |
klauss | 121:ee02790d00b7 | 665 | if( fip == NULL) { |
klauss | 121:ee02790d00b7 | 666 | set_ip( MY_IP ); |
klauss | 121:ee02790d00b7 | 667 | exists = false; |
klauss | 121:ee02790d00b7 | 668 | } |
klauss | 121:ee02790d00b7 | 669 | if ( fip ) fclose ( fip ); |
klauss | 121:ee02790d00b7 | 670 | fip = NULL; |
klauss | 121:ee02790d00b7 | 671 | |
klauss | 121:ee02790d00b7 | 672 | fserext = fopen("/qspi/myext.txt", "r"); |
klauss | 121:ee02790d00b7 | 673 | if( fserext == NULL ) { |
klauss | 121:ee02790d00b7 | 674 | set_header_ext( MY_EXT ); |
klauss | 121:ee02790d00b7 | 675 | exists = false; |
klauss | 121:ee02790d00b7 | 676 | } |
klauss | 121:ee02790d00b7 | 677 | if ( fserext ) fclose ( fserext ); |
klauss | 121:ee02790d00b7 | 678 | fserext = NULL; |
klauss | 121:ee02790d00b7 | 679 | |
klauss | 121:ee02790d00b7 | 680 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 121:ee02790d00b7 | 681 | if (fport == NULL) { |
klauss | 121:ee02790d00b7 | 682 | set_header_sip_port( MY_PORT ); |
klauss | 121:ee02790d00b7 | 683 | exists = false; |
klauss | 121:ee02790d00b7 | 684 | } |
klauss | 121:ee02790d00b7 | 685 | if ( fport ) fclose ( fport ); |
klauss | 121:ee02790d00b7 | 686 | fport = NULL; |
klauss | 121:ee02790d00b7 | 687 | |
klauss | 121:ee02790d00b7 | 688 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 121:ee02790d00b7 | 689 | if (fsip == NULL) { |
klauss | 121:ee02790d00b7 | 690 | set_server_ip( SERVER_IP ); |
klauss | 121:ee02790d00b7 | 691 | exists = false; |
klauss | 121:ee02790d00b7 | 692 | } |
klauss | 121:ee02790d00b7 | 693 | if ( fsip ) fclose ( fsip ); |
klauss | 121:ee02790d00b7 | 694 | fsip = NULL; |
klauss | 121:ee02790d00b7 | 695 | |
klauss | 121:ee02790d00b7 | 696 | fext = fopen("/qspi/peerext.txt", "r"); |
klauss | 121:ee02790d00b7 | 697 | if ( fext == NULL ) { |
klauss | 121:ee02790d00b7 | 698 | set_server_ext( PEER_EXT ); |
klauss | 121:ee02790d00b7 | 699 | exists = false; |
klauss | 121:ee02790d00b7 | 700 | } |
klauss | 121:ee02790d00b7 | 701 | if ( fext ) fclose ( fext ); |
klauss | 121:ee02790d00b7 | 702 | fext = NULL; |
klauss | 121:ee02790d00b7 | 703 | |
klauss | 121:ee02790d00b7 | 704 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 121:ee02790d00b7 | 705 | if (fsport == NULL) { |
klauss | 121:ee02790d00b7 | 706 | set_server_port( SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 707 | exists = false; |
klauss | 121:ee02790d00b7 | 708 | } |
klauss | 121:ee02790d00b7 | 709 | if ( fsport ) fclose ( fsport ); |
klauss | 121:ee02790d00b7 | 710 | fsport = NULL; |
klauss | 121:ee02790d00b7 | 711 | |
klauss | 121:ee02790d00b7 | 712 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 121:ee02790d00b7 | 713 | if (fmask == NULL) { |
klauss | 121:ee02790d00b7 | 714 | set_mask( MY_MSK ); |
klauss | 121:ee02790d00b7 | 715 | exists = false; |
klauss | 121:ee02790d00b7 | 716 | } |
klauss | 121:ee02790d00b7 | 717 | if ( fmask ) fclose ( fmask ); |
klauss | 121:ee02790d00b7 | 718 | fmask = NULL; |
klauss | 121:ee02790d00b7 | 719 | |
klauss | 121:ee02790d00b7 | 720 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 121:ee02790d00b7 | 721 | if (fgate == NULL) { |
klauss | 121:ee02790d00b7 | 722 | set_gateway( MY_GTW ); |
klauss | 121:ee02790d00b7 | 723 | exists = false; |
klauss | 121:ee02790d00b7 | 724 | } |
klauss | 121:ee02790d00b7 | 725 | if ( fgate ) fclose ( fgate ); |
klauss | 121:ee02790d00b7 | 726 | fgate = NULL; |
klauss | 121:ee02790d00b7 | 727 | |
klauss | 121:ee02790d00b7 | 728 | fudpport = fopen("/qspi/udpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 729 | if( fudpport == NULL ) { |
klauss | 121:ee02790d00b7 | 730 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 731 | exists = false; |
klauss | 121:ee02790d00b7 | 732 | } |
klauss | 121:ee02790d00b7 | 733 | if ( fudpport ) fclose ( fudpport ); |
klauss | 121:ee02790d00b7 | 734 | fudpport = NULL; |
klauss | 121:ee02790d00b7 | 735 | |
klauss | 121:ee02790d00b7 | 736 | ftcpport = fopen("/qspi/tcpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 737 | if( ftcpport == NULL ) { |
klauss | 121:ee02790d00b7 | 738 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 739 | exists = false; |
klauss | 121:ee02790d00b7 | 740 | } |
klauss | 121:ee02790d00b7 | 741 | if ( ftcpport ) fclose ( ftcpport ); |
klauss | 121:ee02790d00b7 | 742 | ftcpport = NULL; |
klauss | 121:ee02790d00b7 | 743 | |
klauss | 121:ee02790d00b7 | 744 | ffwip = fopen("/qspi/fw_ip.txt", "r" ); |
klauss | 121:ee02790d00b7 | 745 | if( ffwip == NULL ) { |
klauss | 121:ee02790d00b7 | 746 | set_fw_ip( __FW_SERVER_IP__ ); |
klauss | 121:ee02790d00b7 | 747 | exists = false; |
klauss | 121:ee02790d00b7 | 748 | } |
klauss | 121:ee02790d00b7 | 749 | if ( ffwip ) fclose ( ffwip ); |
klauss | 121:ee02790d00b7 | 750 | ffwip = NULL; |
klauss | 121:ee02790d00b7 | 751 | |
klauss | 121:ee02790d00b7 | 752 | ffwport = fopen("/qspi/fw_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 753 | if( ffwport == NULL ) { |
klauss | 121:ee02790d00b7 | 754 | set_fw_port( __FW_SERVER_PORT__ ); |
klauss | 121:ee02790d00b7 | 755 | exists = false; |
klauss | 121:ee02790d00b7 | 756 | } |
klauss | 121:ee02790d00b7 | 757 | if ( ffwport ) fclose ( ffwport ); |
klauss | 121:ee02790d00b7 | 758 | ffwport = NULL; |
klauss | 121:ee02790d00b7 | 759 | |
klauss | 121:ee02790d00b7 | 760 | fmax = fopen("/qspi/maxext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 761 | if( fmax == NULL ) { |
klauss | 121:ee02790d00b7 | 762 | set_max_ext( MAX_EXT ); |
klauss | 121:ee02790d00b7 | 763 | exists = false; |
klauss | 121:ee02790d00b7 | 764 | } |
klauss | 121:ee02790d00b7 | 765 | if ( fmax ) fclose ( fmax ); |
klauss | 121:ee02790d00b7 | 766 | fmax = NULL; |
klauss | 121:ee02790d00b7 | 767 | |
klauss | 121:ee02790d00b7 | 768 | fmin = fopen("/qspi/minext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 769 | if( fmin == NULL ) { |
klauss | 121:ee02790d00b7 | 770 | if( debug_file ) debug_msg("Don't exist /qspi/minext.txt"); |
klauss | 121:ee02790d00b7 | 771 | set_min_ext( MIN_EXT ); |
klauss | 121:ee02790d00b7 | 772 | exists = false; |
klauss | 121:ee02790d00b7 | 773 | } |
klauss | 121:ee02790d00b7 | 774 | if ( fmin ) fclose ( fmin ); |
klauss | 121:ee02790d00b7 | 775 | fmin = NULL; |
klauss | 121:ee02790d00b7 | 776 | |
klauss | 121:ee02790d00b7 | 777 | fshift_port = fopen("/qspi/shift_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 778 | if( fshift_port == NULL ) |
klauss | 121:ee02790d00b7 | 779 | { |
klauss | 121:ee02790d00b7 | 780 | if( debug_file ) debug_msg("Don't exist /qspi/shift_port.txt"); |
klauss | 121:ee02790d00b7 | 781 | set_shift_port( SHIFT_PORT ); |
klauss | 121:ee02790d00b7 | 782 | exists = false; |
klauss | 121:ee02790d00b7 | 783 | } |
klauss | 121:ee02790d00b7 | 784 | if ( fshift_port ) fclose ( fshift_port ); |
klauss | 121:ee02790d00b7 | 785 | fshift_port = NULL; |
klauss | 121:ee02790d00b7 | 786 | |
klauss | 121:ee02790d00b7 | 787 | if( !exists ) { |
klauss | 121:ee02790d00b7 | 788 | if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 789 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 790 | snprintf( file_buffer, FILE_BUFFER_SIZE, "Default configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 791 | file_buffer[ strlen( file_buffer ) - 1 ] = '\0'; |
klauss | 121:ee02790d00b7 | 792 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 793 | tcp_client.send_all( file_buffer, strlen( file_buffer ) ); |
klauss | 121:ee02790d00b7 | 794 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 795 | } |
klauss | 121:ee02790d00b7 | 796 | } |
klauss | 121:ee02790d00b7 | 797 | } |
klauss | 121:ee02790d00b7 | 798 | } |
klauss | 121:ee02790d00b7 | 799 | |
klauss | 121:ee02790d00b7 | 800 | if (type == 'r' ) { |
klauss | 121:ee02790d00b7 | 801 | // Just open for read |
klauss | 121:ee02790d00b7 | 802 | fip = fopen ("/qspi/myip.txt", "r"); |
klauss | 121:ee02790d00b7 | 803 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 121:ee02790d00b7 | 804 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 121:ee02790d00b7 | 805 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 121:ee02790d00b7 | 806 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 121:ee02790d00b7 | 807 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 121:ee02790d00b7 | 808 | fext = fopen( "/qspi/myext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 809 | fserext = fopen( "/qspi/peerext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 810 | fudpport = fopen( "/qspi/udpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 811 | ftcpport = fopen( "/qspi/tcpport.txt", "r" ); |
klauss | 121:ee02790d00b7 | 812 | ffwip = fopen("/qspi/fw_ip.txt", "r" ); |
klauss | 121:ee02790d00b7 | 813 | ffwport = fopen("/qspi/fw_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 814 | fmax = fopen("/qspi/maxext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 815 | fmin = fopen("/qspi/minext.txt", "r" ); |
klauss | 121:ee02790d00b7 | 816 | fshift_port = fopen("/qspi/shift_port.txt", "r" ); |
klauss | 121:ee02790d00b7 | 817 | |
klauss | 121:ee02790d00b7 | 818 | } |
klauss | 121:ee02790d00b7 | 819 | |
klauss | 121:ee02790d00b7 | 820 | if( type == 'w') { |
klauss | 121:ee02790d00b7 | 821 | |
klauss | 121:ee02790d00b7 | 822 | // Create and write the default configs |
klauss | 121:ee02790d00b7 | 823 | set_ip( MY_IP ); |
klauss | 121:ee02790d00b7 | 824 | |
klauss | 121:ee02790d00b7 | 825 | set_header_sip_port( MY_PORT ); |
klauss | 121:ee02790d00b7 | 826 | |
klauss | 121:ee02790d00b7 | 827 | set_header_ext( MY_EXT ); |
klauss | 121:ee02790d00b7 | 828 | |
klauss | 121:ee02790d00b7 | 829 | set_server_ip( SERVER_IP ); |
klauss | 121:ee02790d00b7 | 830 | |
klauss | 121:ee02790d00b7 | 831 | set_server_ext( PEER_EXT ); |
klauss | 121:ee02790d00b7 | 832 | |
klauss | 121:ee02790d00b7 | 833 | set_server_port( SERVER_PORT ); |
klauss | 121:ee02790d00b7 | 834 | |
klauss | 121:ee02790d00b7 | 835 | set_mask( MY_MSK ); |
klauss | 121:ee02790d00b7 | 836 | |
klauss | 121:ee02790d00b7 | 837 | set_gateway( MY_GTW ); |
klauss | 121:ee02790d00b7 | 838 | |
klauss | 121:ee02790d00b7 | 839 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 840 | |
klauss | 121:ee02790d00b7 | 841 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 121:ee02790d00b7 | 842 | |
klauss | 121:ee02790d00b7 | 843 | set_fw_ip( __FW_SERVER_IP__ ); |
klauss | 121:ee02790d00b7 | 844 | |
klauss | 121:ee02790d00b7 | 845 | set_fw_port( __FW_SERVER_PORT__ ); |
klauss | 121:ee02790d00b7 | 846 | |
klauss | 121:ee02790d00b7 | 847 | set_max_ext( MAX_EXT ); |
klauss | 121:ee02790d00b7 | 848 | |
klauss | 121:ee02790d00b7 | 849 | set_min_ext( MIN_EXT ); |
klauss | 121:ee02790d00b7 | 850 | |
klauss | 121:ee02790d00b7 | 851 | set_shift_port( SHIFT_PORT ); |
klauss | 121:ee02790d00b7 | 852 | |
klauss | 121:ee02790d00b7 | 853 | if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDefault configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 854 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 855 | snprintf( file_buffer, FILE_BUFFER_SIZE, "\n\rDefault configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 856 | file_buffer[ strlen( file_buffer ) - 1 ] = '\0'; |
klauss | 121:ee02790d00b7 | 857 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 858 | tcp_client.send_all( file_buffer, strlen( file_buffer ) ); |
klauss | 121:ee02790d00b7 | 859 | } else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 860 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 861 | } |
klauss | 121:ee02790d00b7 | 862 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 863 | } |
klauss | 121:ee02790d00b7 | 864 | |
klauss | 121:ee02790d00b7 | 865 | } |
klauss | 121:ee02790d00b7 | 866 | |
klauss | 121:ee02790d00b7 | 867 | if (type == 'e') |
klauss | 121:ee02790d00b7 | 868 | { |
klauss | 121:ee02790d00b7 | 869 | //Erase configs |
klauss | 121:ee02790d00b7 | 870 | fip = fopen ("/qspi/myip.txt", "w"); |
klauss | 121:ee02790d00b7 | 871 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 121:ee02790d00b7 | 872 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 121:ee02790d00b7 | 873 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 121:ee02790d00b7 | 874 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 121:ee02790d00b7 | 875 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 121:ee02790d00b7 | 876 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 877 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 878 | fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 121:ee02790d00b7 | 879 | ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 121:ee02790d00b7 | 880 | ffwip = fopen("/qspi/fw_ip.txt", "w" ); |
klauss | 121:ee02790d00b7 | 881 | ffwport = fopen("/qspi/fw_port.txt", "w" ); |
klauss | 121:ee02790d00b7 | 882 | fmax = fopen("/qspi/maxext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 883 | fmin = fopen("/qspi/minext.txt", "w" ); |
klauss | 121:ee02790d00b7 | 884 | fshift_port = fopen("/qspi/shift_port.txt", "w" ); |
klauss | 121:ee02790d00b7 | 885 | |
klauss | 121:ee02790d00b7 | 886 | if( fip ) fprintf( fip, "%s\n\r", "" ); |
klauss | 121:ee02790d00b7 | 887 | if( fport ) fprintf( fport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 888 | if( fext ) fprintf( fext, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 889 | |
klauss | 121:ee02790d00b7 | 890 | if( fsip ) fprintf( fsip, "%s\n\r", "" ); |
klauss | 121:ee02790d00b7 | 891 | if( fserext ) fprintf( fserext, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 892 | if( fsport ) fprintf( fsport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 893 | |
klauss | 121:ee02790d00b7 | 894 | if( fmask ) fprintf( fmask, "%s\n\r","" ); |
klauss | 121:ee02790d00b7 | 895 | if( fgate ) fprintf( fgate, "%s\n\r", "" ); |
klauss | 121:ee02790d00b7 | 896 | |
klauss | 121:ee02790d00b7 | 897 | if( fudpport ) fprintf( fudpport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 898 | if( ftcpport ) fprintf( ftcpport, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 899 | |
klauss | 121:ee02790d00b7 | 900 | if( ffwip ) fprintf( ffwip, "%s\n\r","" ); |
klauss | 121:ee02790d00b7 | 901 | if( ffwport ) fprintf( ffwport, "%i\n\r",0 ); |
klauss | 121:ee02790d00b7 | 902 | |
klauss | 121:ee02790d00b7 | 903 | if( fmax ) fprintf( fmax, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 904 | if( fmin ) fprintf( fmin, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 905 | |
klauss | 121:ee02790d00b7 | 906 | if( fshift_port ) fprintf( fshift_port, "%i\n\r", 0 ); |
klauss | 121:ee02790d00b7 | 907 | |
klauss | 121:ee02790d00b7 | 908 | files('c'); |
klauss | 121:ee02790d00b7 | 909 | |
klauss | 121:ee02790d00b7 | 910 | if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rErased configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 911 | if( from_eth ) { |
klauss | 121:ee02790d00b7 | 912 | snprintf( file_buffer, FILE_BUFFER_SIZE, "\n\rErased configurations set!\n\r"); |
klauss | 121:ee02790d00b7 | 913 | file_buffer[ strlen( file_buffer ) - 1 ] = '\0'; |
klauss | 121:ee02790d00b7 | 914 | if( tcp_session && !udp_query ) { |
klauss | 121:ee02790d00b7 | 915 | tcp_client.send_all( file_buffer, strlen( file_buffer ) ); |
klauss | 121:ee02790d00b7 | 916 | } else if( udp_query ) { |
klauss | 121:ee02790d00b7 | 917 | udp_query_send_msg( file_buffer ); |
klauss | 121:ee02790d00b7 | 918 | } |
klauss | 121:ee02790d00b7 | 919 | for( register int i = 0; i < FILE_BUFFER_SIZE; i++ ) file_buffer[ i ] = 0; |
klauss | 121:ee02790d00b7 | 920 | } |
klauss | 121:ee02790d00b7 | 921 | |
klauss | 121:ee02790d00b7 | 922 | } |
klauss | 121:ee02790d00b7 | 923 | } |
klauss | 121:ee02790d00b7 | 924 | |
klauss | 121:ee02790d00b7 | 925 | int init_fsystem ( void ) |
klauss | 121:ee02790d00b7 | 926 | { |
klauss | 121:ee02790d00b7 | 927 | // init file system and check if files exist |
klauss | 121:ee02790d00b7 | 928 | int return_value = 0; |
klauss | 121:ee02790d00b7 | 929 | |
klauss | 121:ee02790d00b7 | 930 | if (!qspifs.isformatted()) { |
klauss | 121:ee02790d00b7 | 931 | qspifs.format(); |
klauss | 121:ee02790d00b7 | 932 | return_value |= BIT0; |
klauss | 121:ee02790d00b7 | 933 | } |
klauss | 121:ee02790d00b7 | 934 | // check if the files are created |
klauss | 121:ee02790d00b7 | 935 | files('i'); |
klauss | 121:ee02790d00b7 | 936 | files('c'); |
klauss | 121:ee02790d00b7 | 937 | |
klauss | 121:ee02790d00b7 | 938 | return ( return_value |= BIT1 ); |
klauss | 119:ee6a53069455 | 939 | } |