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