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