![](/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@114:472502b31a12, 2015-04-20 (annotated)
- Committer:
- klauss
- Date:
- Mon Apr 20 14:40:09 2015 +0000
- Revision:
- 114:472502b31a12
- Parent:
- 113:db67ae00550e
- Child:
- 116:39a41ebb675c
antes de implementar os retrys da header -> cbx
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 | 81:3656f00ab3db | 5 | /* |
klauss | 81:3656f00ab3db | 6 | void init_fsystem(){ |
klauss | 81:3656f00ab3db | 7 | // init file system and check if files exist |
klauss | 81:3656f00ab3db | 8 | if (!qspifs.isformatted()) { |
klauss | 81:3656f00ab3db | 9 | qspifs.format(); |
klauss | 81:3656f00ab3db | 10 | send_msg("\n\rFile system configured!!\n\r"); |
klauss | 81:3656f00ab3db | 11 | } |
klauss | 114:472502b31a12 | 12 | debug_msg(""); |
klauss | 81:3656f00ab3db | 13 | files('i'); // check if the files are created |
klauss | 114:472502b31a12 | 14 | debug_msg(""); |
klauss | 81:3656f00ab3db | 15 | //files('c'); |
klauss | 114:472502b31a12 | 16 | debug_msg(""); |
klauss | 81:3656f00ab3db | 17 | send_msg("\n\r*******File System Ready*******\n\r"); |
klauss | 81:3656f00ab3db | 18 | } |
klauss | 81:3656f00ab3db | 19 | |
klauss | 81:3656f00ab3db | 20 | */ |
klauss | 81:3656f00ab3db | 21 | |
klauss | 81:3656f00ab3db | 22 | void set_ip( char * new_header_ip ){ |
klauss | 81:3656f00ab3db | 23 | FILE * fip = fopen("/qspi/myip.txt", "w"); |
klauss | 114:472502b31a12 | 24 | fprintf( fip, "%s\n\r", new_header_ip ); |
klauss | 114:472502b31a12 | 25 | fclose( fip ); |
klauss | 81:3656f00ab3db | 26 | } |
klauss | 81:3656f00ab3db | 27 | |
klauss | 81:3656f00ab3db | 28 | void set_header_ext( int new_header_ext ){ |
klauss | 81:3656f00ab3db | 29 | FILE * fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 114:472502b31a12 | 30 | fprintf( fext, "%i\n\r", new_header_ext ); |
klauss | 114:472502b31a12 | 31 | fclose( fext ); |
klauss | 81:3656f00ab3db | 32 | } |
klauss | 81:3656f00ab3db | 33 | |
klauss | 81:3656f00ab3db | 34 | void set_header_sip_port( int new_header_sip_port ){ |
klauss | 81:3656f00ab3db | 35 | FILE * fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 114:472502b31a12 | 36 | fprintf( fport,"%i\n\r", new_header_sip_port ); |
klauss | 114:472502b31a12 | 37 | fclose( fport ); |
klauss | 81:3656f00ab3db | 38 | } |
klauss | 81:3656f00ab3db | 39 | |
klauss | 81:3656f00ab3db | 40 | void set_server_ip( char * new_server_ip ){ |
klauss | 81:3656f00ab3db | 41 | FILE * fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 114:472502b31a12 | 42 | fprintf( fsip,"%s\n\r", new_server_ip ); |
klauss | 114:472502b31a12 | 43 | fclose( fsip ); |
klauss | 81:3656f00ab3db | 44 | } |
klauss | 81:3656f00ab3db | 45 | |
klauss | 81:3656f00ab3db | 46 | void set_server_ext( int new_server_ext ){ |
klauss | 81:3656f00ab3db | 47 | FILE * fserext = fopen("/qspi/peerext.txt", "w"); |
klauss | 114:472502b31a12 | 48 | fprintf( fserext , "%i\n\r", new_server_ext ); |
klauss | 114:472502b31a12 | 49 | fclose( fserext ); |
klauss | 81:3656f00ab3db | 50 | } |
klauss | 81:3656f00ab3db | 51 | |
klauss | 81:3656f00ab3db | 52 | void set_server_port( int new_server_port ){ |
klauss | 81:3656f00ab3db | 53 | FILE * fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 114:472502b31a12 | 54 | fprintf(fsport,"%i\n\r", new_server_port ); |
klauss | 114:472502b31a12 | 55 | fclose( fsport ); |
klauss | 81:3656f00ab3db | 56 | } |
klauss | 81:3656f00ab3db | 57 | |
klauss | 81:3656f00ab3db | 58 | void set_mask( char * new_mask ){ |
klauss | 81:3656f00ab3db | 59 | FILE * fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 114:472502b31a12 | 60 | fprintf(fmask,"%s\n\r",new_mask ); |
klauss | 114:472502b31a12 | 61 | fclose( fmask ); |
klauss | 81:3656f00ab3db | 62 | } |
klauss | 81:3656f00ab3db | 63 | |
klauss | 81:3656f00ab3db | 64 | void set_gateway( char * new_gateway ){ |
klauss | 114:472502b31a12 | 65 | //fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 81:3656f00ab3db | 66 | FILE * fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 114:472502b31a12 | 67 | fprintf(fgate,"%s\n\r", new_gateway ); |
klauss | 114:472502b31a12 | 68 | fclose( fgate ); |
klauss | 81:3656f00ab3db | 69 | } |
klauss | 81:3656f00ab3db | 70 | |
klauss | 81:3656f00ab3db | 71 | void set_udp_port_listener( int new_udp_port_listener ){ |
klauss | 81:3656f00ab3db | 72 | FILE * fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 114:472502b31a12 | 73 | fprintf( fudpport, "%i\n\r",new_udp_port_listener ); |
klauss | 114:472502b31a12 | 74 | fclose( fudpport ); |
klauss | 81:3656f00ab3db | 75 | } |
klauss | 81:3656f00ab3db | 76 | |
klauss | 81:3656f00ab3db | 77 | void set_tcp_port_listener( int new_tcp_port_listener ){ |
klauss | 81:3656f00ab3db | 78 | FILE * ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 114:472502b31a12 | 79 | fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); |
klauss | 114:472502b31a12 | 80 | fclose( ftcpport ); |
klauss | 114:472502b31a12 | 81 | } |
klauss | 114:472502b31a12 | 82 | |
klauss | 114:472502b31a12 | 83 | void set_telemetry_ip( char * new_telemetry_ip ){ |
klauss | 114:472502b31a12 | 84 | FILE * ftip = fopen("/qspi/telemetry_ip.txt", "w" ); |
klauss | 114:472502b31a12 | 85 | fprintf(ftip,"%s\n\r", new_telemetry_ip ); |
klauss | 114:472502b31a12 | 86 | fclose( ftip ); |
klauss | 114:472502b31a12 | 87 | } |
klauss | 114:472502b31a12 | 88 | |
klauss | 114:472502b31a12 | 89 | void set_telemetry_port( int new_telemetry_port ){ |
klauss | 114:472502b31a12 | 90 | FILE * ftport = fopen("/qspi/telemetry_port.txt", "w" ); |
klauss | 114:472502b31a12 | 91 | fprintf(ftport,"%i\n\r", new_telemetry_port ); |
klauss | 114:472502b31a12 | 92 | fclose( ftport ); |
klauss | 81:3656f00ab3db | 93 | } |
klauss | 81:3656f00ab3db | 94 | |
klauss | 99:e80850c51106 | 95 | void set_fw_ip( char * new_fw_ip ){ |
klauss | 99:e80850c51106 | 96 | FILE * ffwip = fopen("/qspi/fw_ip.txt", "w" ); |
klauss | 114:472502b31a12 | 97 | fprintf(ffwip,"%s\n\r", new_fw_ip ); |
klauss | 114:472502b31a12 | 98 | fclose( ffwip ); |
klauss | 99:e80850c51106 | 99 | } |
klauss | 99:e80850c51106 | 100 | |
klauss | 99:e80850c51106 | 101 | void set_fw_port( int new_fw_port ){ |
klauss | 99:e80850c51106 | 102 | FILE * ffwport = fopen("/qspi/fw_port.txt", "w" ); |
klauss | 114:472502b31a12 | 103 | fprintf(ffwport,"%i\n\r", new_fw_port ); |
klauss | 114:472502b31a12 | 104 | fclose( ffwport ); |
klauss | 99:e80850c51106 | 105 | } |
klauss | 99:e80850c51106 | 106 | |
klauss | 81:3656f00ab3db | 107 | void set_max_ext( int new_max_ext ){ |
klauss | 81:3656f00ab3db | 108 | FILE * fmex = fopen( "/qspi/maxext.txt", "w" ); |
klauss | 99:e80850c51106 | 109 | if( fmex ){ |
klauss | 99:e80850c51106 | 110 | fprintf( fmex, "%i\n\r", new_max_ext ); |
klauss | 114:472502b31a12 | 111 | //debug_msg(""); |
klauss | 99:e80850c51106 | 112 | fclose( fmex ); |
klauss | 114:472502b31a12 | 113 | //debug_msg(""); |
klauss | 99:e80850c51106 | 114 | } |
klauss | 81:3656f00ab3db | 115 | } |
klauss | 81:3656f00ab3db | 116 | |
klauss | 81:3656f00ab3db | 117 | void set_min_ext( int new_min_ext ){ |
klauss | 81:3656f00ab3db | 118 | FILE * fmin = fopen( "/qspi/minext.txt", "w" ); |
klauss | 99:e80850c51106 | 119 | if( fmin ){ |
klauss | 99:e80850c51106 | 120 | fprintf( fmin, "%i\n\r", new_min_ext ); |
klauss | 99:e80850c51106 | 121 | fclose( fmin ); |
klauss | 99:e80850c51106 | 122 | } |
klauss | 81:3656f00ab3db | 123 | } |
klauss | 81:3656f00ab3db | 124 | |
klauss | 81:3656f00ab3db | 125 | // Print the content of a given file |
klauss | 114:472502b31a12 | 126 | void cat(const char * fname){ |
klauss | 81:3656f00ab3db | 127 | char buff[513]; |
klauss | 81:3656f00ab3db | 128 | int num; |
klauss | 81:3656f00ab3db | 129 | |
klauss | 114:472502b31a12 | 130 | FILE *fp = fopen(fname, "r"); |
klauss | 81:3656f00ab3db | 131 | if (fp == NULL) { |
klauss | 114:472502b31a12 | 132 | if( debug_file ) if( debug_uart3 ) pc.printf( "Failed to open %s", fname); |
klauss | 81:3656f00ab3db | 133 | return; |
klauss | 81:3656f00ab3db | 134 | } |
klauss | 81:3656f00ab3db | 135 | |
klauss | 81:3656f00ab3db | 136 | while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ |
klauss | 81:3656f00ab3db | 137 | buff[ num ] = '\0'; |
klauss | 114:472502b31a12 | 138 | if( debug_uart3 ) pc.printf( buff ); |
klauss | 81:3656f00ab3db | 139 | if( from_eth ){ |
klauss | 114:472502b31a12 | 140 | if( tcp_session ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); |
klauss | 81:3656f00ab3db | 141 | |
klauss | 114:472502b31a12 | 142 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 143 | udp_server.sendTo( udp_client, buff, strlen( buff ) ); |
klauss | 81:3656f00ab3db | 144 | } |
klauss | 81:3656f00ab3db | 145 | } |
klauss | 81:3656f00ab3db | 146 | } |
klauss | 81:3656f00ab3db | 147 | fclose(fp); |
klauss | 114:472502b31a12 | 148 | } |
klauss | 114:472502b31a12 | 149 | |
klauss | 114:472502b31a12 | 150 | /* |
klauss | 114:472502b31a12 | 151 | //operantion with the system config files |
klauss | 114:472502b31a12 | 152 | void files( const char type ){ |
klauss | 114:472502b31a12 | 153 | FILE *fip = NULL, |
klauss | 114:472502b31a12 | 154 | *fmask = NULL, |
klauss | 114:472502b31a12 | 155 | *fgate = NULL, |
klauss | 114:472502b31a12 | 156 | *fport = NULL, |
klauss | 114:472502b31a12 | 157 | *fsip = NULL, |
klauss | 114:472502b31a12 | 158 | *fsport = NULL, |
klauss | 114:472502b31a12 | 159 | *fext = NULL, |
klauss | 114:472502b31a12 | 160 | *fserext = NULL, |
klauss | 114:472502b31a12 | 161 | *fudpport = NULL, |
klauss | 114:472502b31a12 | 162 | *ftcpport = NULL, |
klauss | 114:472502b31a12 | 163 | *ftip = NULL, |
klauss | 114:472502b31a12 | 164 | *ftport = NULL; |
klauss | 114:472502b31a12 | 165 | |
klauss | 114:472502b31a12 | 166 | //fixme mudar o nome dessa variable |
klauss | 114:472502b31a12 | 167 | |
klauss | 114:472502b31a12 | 168 | //#define MIN_EXT 5100 |
klauss | 114:472502b31a12 | 169 | //#define MAX_EXT 5139 |
klauss | 114:472502b31a12 | 170 | char string_msg[ 1024 ]; |
klauss | 114:472502b31a12 | 171 | // show files |
klauss | 114:472502b31a12 | 172 | switch( type ){ |
klauss | 114:472502b31a12 | 173 | case 's' : { |
klauss | 114:472502b31a12 | 174 | if( debug_uart3 ) pc.printf("Header IP " ); |
klauss | 114:472502b31a12 | 175 | if( from_eth ){ |
klauss | 114:472502b31a12 | 176 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Header IP " ); |
klauss | 114:472502b31a12 | 177 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 178 | |
klauss | 114:472502b31a12 | 179 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 180 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 181 | } |
klauss | 114:472502b31a12 | 182 | } |
klauss | 114:472502b31a12 | 183 | |
klauss | 114:472502b31a12 | 184 | cat("/qspi/myip.txt"); |
klauss | 114:472502b31a12 | 185 | |
klauss | 114:472502b31a12 | 186 | if( debug_uart3 ) pc.printf("Header ext "); |
klauss | 114:472502b31a12 | 187 | if( from_eth ){ |
klauss | 114:472502b31a12 | 188 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Header ext " ); |
klauss | 114:472502b31a12 | 189 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 190 | |
klauss | 114:472502b31a12 | 191 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 192 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 193 | } |
klauss | 114:472502b31a12 | 194 | } |
klauss | 114:472502b31a12 | 195 | |
klauss | 114:472502b31a12 | 196 | cat("/qspi/myext.txt"); |
klauss | 114:472502b31a12 | 197 | |
klauss | 114:472502b31a12 | 198 | if( debug_uart3 ) pc.printf("Header port "); |
klauss | 114:472502b31a12 | 199 | if( from_eth ){ |
klauss | 114:472502b31a12 | 200 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Header port " ); |
klauss | 114:472502b31a12 | 201 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 202 | |
klauss | 114:472502b31a12 | 203 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 204 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 205 | } |
klauss | 114:472502b31a12 | 206 | } |
klauss | 114:472502b31a12 | 207 | |
klauss | 114:472502b31a12 | 208 | cat("/qspi/mysipport.txt"); |
klauss | 114:472502b31a12 | 209 | |
klauss | 114:472502b31a12 | 210 | if( debug_uart3 ) pc.printf("Server IP "); |
klauss | 114:472502b31a12 | 211 | if( from_eth ){ |
klauss | 114:472502b31a12 | 212 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Server IP " ); |
klauss | 114:472502b31a12 | 213 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 214 | |
klauss | 114:472502b31a12 | 215 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 216 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 217 | } |
klauss | 114:472502b31a12 | 218 | } |
klauss | 114:472502b31a12 | 219 | |
klauss | 114:472502b31a12 | 220 | cat("/qspi/serverip.txt"); |
klauss | 114:472502b31a12 | 221 | |
klauss | 114:472502b31a12 | 222 | if( debug_uart3 ) pc.printf("Server ext "); |
klauss | 114:472502b31a12 | 223 | if( from_eth ){ |
klauss | 114:472502b31a12 | 224 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Server ext " ); |
klauss | 114:472502b31a12 | 225 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 226 | |
klauss | 114:472502b31a12 | 227 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 228 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 229 | } |
klauss | 114:472502b31a12 | 230 | } |
klauss | 114:472502b31a12 | 231 | |
klauss | 114:472502b31a12 | 232 | cat("/qspi/peerext.txt"); |
klauss | 114:472502b31a12 | 233 | |
klauss | 114:472502b31a12 | 234 | if( debug_uart3 ) pc.printf("Server port "); |
klauss | 114:472502b31a12 | 235 | if( from_eth ){ |
klauss | 114:472502b31a12 | 236 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Server port " ); |
klauss | 114:472502b31a12 | 237 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 238 | |
klauss | 114:472502b31a12 | 239 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 240 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 241 | } |
klauss | 114:472502b31a12 | 242 | } |
klauss | 114:472502b31a12 | 243 | cat("/qspi/serverport.txt"); |
klauss | 114:472502b31a12 | 244 | |
klauss | 114:472502b31a12 | 245 | if( debug_uart3 ) pc.printf("Mascara de rede "); |
klauss | 114:472502b31a12 | 246 | if( from_eth ){ |
klauss | 114:472502b31a12 | 247 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Mascara de rede " ); |
klauss | 114:472502b31a12 | 248 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 249 | |
klauss | 114:472502b31a12 | 250 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 251 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 252 | } |
klauss | 114:472502b31a12 | 253 | } |
klauss | 114:472502b31a12 | 254 | cat("/qspi/mymask.txt"); |
klauss | 114:472502b31a12 | 255 | |
klauss | 114:472502b31a12 | 256 | if( debug_uart3 ) pc.printf("Gateway IP "); |
klauss | 114:472502b31a12 | 257 | if( from_eth ){ |
klauss | 114:472502b31a12 | 258 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Gateway IP " ); |
klauss | 114:472502b31a12 | 259 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 260 | |
klauss | 114:472502b31a12 | 261 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 262 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 263 | } |
klauss | 114:472502b31a12 | 264 | } |
klauss | 114:472502b31a12 | 265 | cat("/qspi/mygateway.txt"); |
klauss | 114:472502b31a12 | 266 | |
klauss | 114:472502b31a12 | 267 | if( debug_uart3 ) pc.printf("UDP Port "); |
klauss | 114:472502b31a12 | 268 | if( from_eth ){ |
klauss | 114:472502b31a12 | 269 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "UDP Port " ); |
klauss | 114:472502b31a12 | 270 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 271 | |
klauss | 114:472502b31a12 | 272 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 273 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 274 | } |
klauss | 114:472502b31a12 | 275 | } |
klauss | 114:472502b31a12 | 276 | |
klauss | 114:472502b31a12 | 277 | cat("/qspi/udpport.txt"); |
klauss | 114:472502b31a12 | 278 | |
klauss | 114:472502b31a12 | 279 | if( debug_uart3 ) pc.printf("TCP Port "); |
klauss | 114:472502b31a12 | 280 | if( from_eth ){ |
klauss | 114:472502b31a12 | 281 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "TCP Port " ); |
klauss | 114:472502b31a12 | 282 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 283 | |
klauss | 114:472502b31a12 | 284 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 285 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 286 | } |
klauss | 114:472502b31a12 | 287 | } |
klauss | 114:472502b31a12 | 288 | |
klauss | 114:472502b31a12 | 289 | cat("/qspi/tcpport.txt"); |
klauss | 114:472502b31a12 | 290 | |
klauss | 114:472502b31a12 | 291 | if( debug_uart3 ) pc.printf("Telemetry Server IP "); |
klauss | 114:472502b31a12 | 292 | if( from_eth ){ |
klauss | 114:472502b31a12 | 293 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server IP " ); |
klauss | 114:472502b31a12 | 294 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 295 | |
klauss | 114:472502b31a12 | 296 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 297 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 298 | } |
klauss | 114:472502b31a12 | 299 | } |
klauss | 114:472502b31a12 | 300 | |
klauss | 114:472502b31a12 | 301 | cat("/qspi/telemetry_ip.txt"); |
klauss | 114:472502b31a12 | 302 | |
klauss | 114:472502b31a12 | 303 | if( debug_uart3 ) pc.printf("Telemetry Server Port "); |
klauss | 114:472502b31a12 | 304 | if( from_eth ){ |
klauss | 114:472502b31a12 | 305 | snprintf( string_msg, __PROMPT_ETH_BUFFER_SIZE__, "Telemetry Server Port " ); |
klauss | 114:472502b31a12 | 306 | if( tcp_session ) while( !( tcp_client.send_all( string_msg, strlen( string_msg ) ) ) ); |
klauss | 114:472502b31a12 | 307 | |
klauss | 114:472502b31a12 | 308 | else if( udp_request ){ |
klauss | 114:472502b31a12 | 309 | udp_server.sendTo( udp_client, string_msg, strlen( string_msg ) ); |
klauss | 114:472502b31a12 | 310 | } |
klauss | 114:472502b31a12 | 311 | } |
klauss | 114:472502b31a12 | 312 | |
klauss | 114:472502b31a12 | 313 | cat("/qspi/telemetry_port.txt"); |
klauss | 114:472502b31a12 | 314 | break; |
klauss | 114:472502b31a12 | 315 | } |
klauss | 114:472502b31a12 | 316 | |
klauss | 114:472502b31a12 | 317 | case 'c' : { |
klauss | 114:472502b31a12 | 318 | // close all files |
klauss | 114:472502b31a12 | 319 | debug_msg(""); |
klauss | 114:472502b31a12 | 320 | if( fip != NULL ) fclose( fip ); |
klauss | 114:472502b31a12 | 321 | if( fmask != NULL ) fclose( fmask ); |
klauss | 114:472502b31a12 | 322 | if( fgate != NULL ) fclose( fgate ); |
klauss | 114:472502b31a12 | 323 | if( fport != NULL ) fclose( fport ); |
klauss | 114:472502b31a12 | 324 | if( fsip != NULL ) fclose( fsip ); |
klauss | 114:472502b31a12 | 325 | if( fsport != NULL ) fclose( fsport ); |
klauss | 114:472502b31a12 | 326 | if( fext != NULL ) fclose( fext ); |
klauss | 114:472502b31a12 | 327 | if( fserext != NULL ) fclose( fserext ); |
klauss | 114:472502b31a12 | 328 | if( fudpport != NULL ) fclose( fudpport ); |
klauss | 114:472502b31a12 | 329 | if( ftcpport != NULL ) fclose( ftcpport ); |
klauss | 114:472502b31a12 | 330 | debug_msg(""); |
klauss | 114:472502b31a12 | 331 | break; |
klauss | 114:472502b31a12 | 332 | } |
klauss | 114:472502b31a12 | 333 | |
klauss | 114:472502b31a12 | 334 | case 'i' : { |
klauss | 114:472502b31a12 | 335 | // Check if files exist, if not create the files |
klauss | 114:472502b31a12 | 336 | //fixme criar um bool pra cada file |
klauss | 114:472502b31a12 | 337 | bool exists = true; |
klauss | 114:472502b31a12 | 338 | |
klauss | 114:472502b31a12 | 339 | debug_msg(""); |
klauss | 114:472502b31a12 | 340 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 114:472502b31a12 | 341 | if( fip == NULL){ |
klauss | 114:472502b31a12 | 342 | set_ip( __MY_IP__ ); |
klauss | 114:472502b31a12 | 343 | exists = false; |
klauss | 114:472502b31a12 | 344 | } |
klauss | 114:472502b31a12 | 345 | debug_msg(""); |
klauss | 114:472502b31a12 | 346 | fserext = fopen("/qspi/myext.txt", "r"); |
klauss | 114:472502b31a12 | 347 | if( fserext == NULL ){ |
klauss | 114:472502b31a12 | 348 | set_header_ext( __MY_EXT__ ); |
klauss | 114:472502b31a12 | 349 | exists = false; |
klauss | 114:472502b31a12 | 350 | } |
klauss | 114:472502b31a12 | 351 | debug_msg(""); |
klauss | 114:472502b31a12 | 352 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 114:472502b31a12 | 353 | if (fport == NULL){ |
klauss | 114:472502b31a12 | 354 | set_header_sip_port( __MY_PORT__ ); |
klauss | 114:472502b31a12 | 355 | exists = false; |
klauss | 114:472502b31a12 | 356 | } |
klauss | 114:472502b31a12 | 357 | debug_msg(""); |
klauss | 114:472502b31a12 | 358 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 114:472502b31a12 | 359 | if (fsip == NULL){ |
klauss | 114:472502b31a12 | 360 | set_server_ip( __SERVER_IP__ ); |
klauss | 114:472502b31a12 | 361 | exists = false; |
klauss | 114:472502b31a12 | 362 | } |
klauss | 114:472502b31a12 | 363 | debug_msg(""); |
klauss | 114:472502b31a12 | 364 | fext = fopen("/qspi/peerext.txt", "r"); |
klauss | 114:472502b31a12 | 365 | if ( fext == NULL ){ |
klauss | 114:472502b31a12 | 366 | set_server_ext( __PEER_EXT__ ); |
klauss | 114:472502b31a12 | 367 | exists = false; |
klauss | 114:472502b31a12 | 368 | } |
klauss | 114:472502b31a12 | 369 | debug_msg(""); |
klauss | 114:472502b31a12 | 370 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 114:472502b31a12 | 371 | if (fsport == NULL){ |
klauss | 114:472502b31a12 | 372 | set_server_port( __SERVER_PORT__ ); |
klauss | 114:472502b31a12 | 373 | exists = false; |
klauss | 114:472502b31a12 | 374 | } |
klauss | 114:472502b31a12 | 375 | debug_msg(""); |
klauss | 114:472502b31a12 | 376 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 114:472502b31a12 | 377 | if (fmask == NULL){ |
klauss | 114:472502b31a12 | 378 | set_mask( __MY_MSK__ ); |
klauss | 114:472502b31a12 | 379 | exists = false; |
klauss | 114:472502b31a12 | 380 | } |
klauss | 114:472502b31a12 | 381 | debug_msg(""); |
klauss | 114:472502b31a12 | 382 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 114:472502b31a12 | 383 | if (fgate == NULL){ |
klauss | 114:472502b31a12 | 384 | set_gateway( __MY_GTW__ ); |
klauss | 114:472502b31a12 | 385 | exists = false; |
klauss | 114:472502b31a12 | 386 | } |
klauss | 114:472502b31a12 | 387 | debug_msg(""); |
klauss | 114:472502b31a12 | 388 | fudpport = fopen("/qspi/udpport.txt", "r" ); |
klauss | 114:472502b31a12 | 389 | if( fudpport == NULL ){ |
klauss | 114:472502b31a12 | 390 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 114:472502b31a12 | 391 | exists = false; |
klauss | 114:472502b31a12 | 392 | } |
klauss | 114:472502b31a12 | 393 | debug_msg(""); |
klauss | 114:472502b31a12 | 394 | ftcpport = fopen("/qspi/tcpport.txt", "r" ); |
klauss | 114:472502b31a12 | 395 | if( ftcpport == NULL ){ |
klauss | 114:472502b31a12 | 396 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 114:472502b31a12 | 397 | exists = false; |
klauss | 114:472502b31a12 | 398 | } |
klauss | 114:472502b31a12 | 399 | debug_msg(""); |
klauss | 114:472502b31a12 | 400 | ftip = fopen("/qspi/telemetry_ip.txt", "r" ); |
klauss | 114:472502b31a12 | 401 | if( ftip == NULL ){ |
klauss | 114:472502b31a12 | 402 | set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); |
klauss | 114:472502b31a12 | 403 | exists = false; |
klauss | 114:472502b31a12 | 404 | } |
klauss | 114:472502b31a12 | 405 | debug_msg(""); |
klauss | 114:472502b31a12 | 406 | ftport = fopen("/qspi/telemetry_port.txt", "r" ); |
klauss | 114:472502b31a12 | 407 | if( ftport == NULL ){ |
klauss | 114:472502b31a12 | 408 | set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); |
klauss | 114:472502b31a12 | 409 | exists = false; |
klauss | 114:472502b31a12 | 410 | } |
klauss | 114:472502b31a12 | 411 | debug_msg(""); |
klauss | 114:472502b31a12 | 412 | if( !exists ){ |
klauss | 114:472502b31a12 | 413 | send_msg("\n\rDefault configurations set!\n\r"); |
klauss | 114:472502b31a12 | 414 | } |
klauss | 114:472502b31a12 | 415 | debug_msg(""); |
klauss | 114:472502b31a12 | 416 | break; |
klauss | 114:472502b31a12 | 417 | } |
klauss | 114:472502b31a12 | 418 | |
klauss | 114:472502b31a12 | 419 | case 'r' : { |
klauss | 114:472502b31a12 | 420 | // Just open for read |
klauss | 114:472502b31a12 | 421 | fip = fopen("/qspi/myip.txt", "r"); |
klauss | 114:472502b31a12 | 422 | fmask = fopen("/qspi/mymask.txt", "r"); |
klauss | 114:472502b31a12 | 423 | fgate = fopen("/qspi/mygateway.txt", "r"); |
klauss | 114:472502b31a12 | 424 | fport = fopen("/qspi/mysipport.txt", "r"); |
klauss | 114:472502b31a12 | 425 | fsip = fopen("/qspi/serverip.txt", "r"); |
klauss | 114:472502b31a12 | 426 | fsport = fopen("/qspi/serverport.txt", "r"); |
klauss | 114:472502b31a12 | 427 | fext = fopen( "/qspi/myext.txt", "r" ); |
klauss | 114:472502b31a12 | 428 | fserext = fopen( "/qspi/peerext.txt", "r" ); |
klauss | 114:472502b31a12 | 429 | fudpport = fopen( "/qspi/udpport.txt", "r" ); |
klauss | 114:472502b31a12 | 430 | ftcpport = fopen( "/qspi/tcpport.txt", "r" ); |
klauss | 114:472502b31a12 | 431 | ftip = fopen("/qspi/telemetry_ip.txt", "r" ); |
klauss | 114:472502b31a12 | 432 | ftport = fopen("/qspi/telemetry_port.txt", "r" ); |
klauss | 114:472502b31a12 | 433 | break; |
klauss | 114:472502b31a12 | 434 | } |
klauss | 114:472502b31a12 | 435 | |
klauss | 114:472502b31a12 | 436 | case 'w' : { |
klauss | 114:472502b31a12 | 437 | // Create and write the default configs |
klauss | 114:472502b31a12 | 438 | |
klauss | 114:472502b31a12 | 439 | set_ip( __MY_IP__ ); |
klauss | 114:472502b31a12 | 440 | |
klauss | 114:472502b31a12 | 441 | set_header_sip_port( __MY_PORT__ ); |
klauss | 114:472502b31a12 | 442 | |
klauss | 114:472502b31a12 | 443 | set_header_ext( __MY_EXT__ ); |
klauss | 114:472502b31a12 | 444 | |
klauss | 114:472502b31a12 | 445 | set_server_ip( __SERVER_IP__ ); |
klauss | 114:472502b31a12 | 446 | |
klauss | 114:472502b31a12 | 447 | set_server_ext( __PEER_EXT__ ); |
klauss | 114:472502b31a12 | 448 | |
klauss | 114:472502b31a12 | 449 | set_server_port( __SERVER_PORT__ ); |
klauss | 114:472502b31a12 | 450 | |
klauss | 114:472502b31a12 | 451 | set_mask( __MY_MSK__ ); |
klauss | 114:472502b31a12 | 452 | |
klauss | 114:472502b31a12 | 453 | set_gateway( __MY_GTW__ ); |
klauss | 114:472502b31a12 | 454 | |
klauss | 114:472502b31a12 | 455 | set_udp_port_listener( UDP_PORT_LISTENER ); |
klauss | 114:472502b31a12 | 456 | |
klauss | 114:472502b31a12 | 457 | set_tcp_port_listener( TCP_PORT_LISTENER ); |
klauss | 114:472502b31a12 | 458 | |
klauss | 114:472502b31a12 | 459 | set_telemetry_ip( __TELEMETRY_SERVER_IP__ ); |
klauss | 114:472502b31a12 | 460 | |
klauss | 114:472502b31a12 | 461 | set_telemetry_port( __TELEMETRY_SERVER_PORT__ ); |
klauss | 114:472502b31a12 | 462 | |
klauss | 114:472502b31a12 | 463 | send_msg( "Default configurations set!" ); |
klauss | 114:472502b31a12 | 464 | break; |
klauss | 114:472502b31a12 | 465 | } |
klauss | 114:472502b31a12 | 466 | |
klauss | 114:472502b31a12 | 467 | case 'e' : { |
klauss | 114:472502b31a12 | 468 | //Erase configs |
klauss | 114:472502b31a12 | 469 | fip = fopen("/qspi/myip.txt", "w"); |
klauss | 114:472502b31a12 | 470 | fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 114:472502b31a12 | 471 | fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 114:472502b31a12 | 472 | fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 114:472502b31a12 | 473 | fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 114:472502b31a12 | 474 | fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 114:472502b31a12 | 475 | fext = fopen( "/qspi/myext.txt", "w" ); |
klauss | 114:472502b31a12 | 476 | fserext = fopen( "/qspi/peerext.txt", "w" ); |
klauss | 114:472502b31a12 | 477 | fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 114:472502b31a12 | 478 | ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 114:472502b31a12 | 479 | ftip = fopen("/qspi/telemetry_ip.txt", "w" ); |
klauss | 114:472502b31a12 | 480 | ftport = fopen("/qspi/telemetry_port.txt", "w" ); |
klauss | 114:472502b31a12 | 481 | |
klauss | 114:472502b31a12 | 482 | //FIXME verificar se deveria colocar tudo para %s |
klauss | 114:472502b31a12 | 483 | fprintf( fip, "%s\n\r", "" ); |
klauss | 114:472502b31a12 | 484 | fprintf( fport, "%i\n\r", 0 ); |
klauss | 114:472502b31a12 | 485 | fprintf( fext, "%i\n\r", 0 ); |
klauss | 114:472502b31a12 | 486 | |
klauss | 114:472502b31a12 | 487 | fprintf( fsip, "%s\n\r", "" ); |
klauss | 114:472502b31a12 | 488 | fprintf( fserext, "%i\n\r", 0 ); |
klauss | 114:472502b31a12 | 489 | fprintf( fsport, "%i\n\r", 0 ); |
klauss | 114:472502b31a12 | 490 | |
klauss | 114:472502b31a12 | 491 | fprintf( fmask, "%s\n\r","" ); |
klauss | 114:472502b31a12 | 492 | fprintf( fgate, "%s\n\r", "" ); |
klauss | 114:472502b31a12 | 493 | |
klauss | 114:472502b31a12 | 494 | fprintf( fudpport, "%i\n\r", 0 ); |
klauss | 114:472502b31a12 | 495 | fprintf( ftcpport, "%i\n\r", 0 ); |
klauss | 114:472502b31a12 | 496 | |
klauss | 114:472502b31a12 | 497 | fprintf( ftip, "%s\n\r","" ); |
klauss | 114:472502b31a12 | 498 | fprintf( ftport, "%i\n\r",0 ); |
klauss | 114:472502b31a12 | 499 | |
klauss | 114:472502b31a12 | 500 | files('c'); |
klauss | 114:472502b31a12 | 501 | |
klauss | 114:472502b31a12 | 502 | send_msg("\n\rErased configurations set!\n\r"); |
klauss | 114:472502b31a12 | 503 | break; |
klauss | 114:472502b31a12 | 504 | } |
klauss | 114:472502b31a12 | 505 | } |
klauss | 114:472502b31a12 | 506 | } |
klauss | 114:472502b31a12 | 507 | */ |