![](/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@106:a34fcf9f0e02, 2015-03-13 (annotated)
- Committer:
- klauss
- Date:
- Fri Mar 13 19:40:56 2015 +0000
- Revision:
- 106:a34fcf9f0e02
- Parent:
- 105:a930035b6556
- Child:
- 109:a5b8264ffbbc
bugfix do refresh/wake_all_up; agora o unico parametro passado ? o vetor de CBx, os dois buffers s?o locais
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 | files('i'); // check if the files are created |
klauss | 81:3656f00ab3db | 13 | //files('c'); |
klauss | 81:3656f00ab3db | 14 | send_msg("\n\r*******File System Ready*******\n\r"); |
klauss | 81:3656f00ab3db | 15 | } |
klauss | 81:3656f00ab3db | 16 | |
klauss | 81:3656f00ab3db | 17 | */ |
klauss | 81:3656f00ab3db | 18 | |
klauss | 81:3656f00ab3db | 19 | void set_ip( char * new_header_ip ){ |
klauss | 81:3656f00ab3db | 20 | FILE * fip = fopen("/qspi/myip.txt", "w"); |
klauss | 106:a34fcf9f0e02 | 21 | if( fip ) |
klauss | 106:a34fcf9f0e02 | 22 | { |
klauss | 106:a34fcf9f0e02 | 23 | fprintf( fip, "%s\n\r", new_header_ip ); |
klauss | 106:a34fcf9f0e02 | 24 | fclose( fip ); |
klauss | 106:a34fcf9f0e02 | 25 | } |
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 | 106:a34fcf9f0e02 | 30 | if( fext ) |
klauss | 106:a34fcf9f0e02 | 31 | { |
klauss | 106:a34fcf9f0e02 | 32 | fprintf( fext, "%i\n\r", new_header_ext ); |
klauss | 106:a34fcf9f0e02 | 33 | fclose( fext ); |
klauss | 106:a34fcf9f0e02 | 34 | } |
klauss | 81:3656f00ab3db | 35 | } |
klauss | 81:3656f00ab3db | 36 | |
klauss | 81:3656f00ab3db | 37 | void set_header_sip_port( int new_header_sip_port ){ |
klauss | 81:3656f00ab3db | 38 | FILE * fport = fopen("/qspi/mysipport.txt", "w"); |
klauss | 106:a34fcf9f0e02 | 39 | if( fport ) |
klauss | 106:a34fcf9f0e02 | 40 | { |
klauss | 106:a34fcf9f0e02 | 41 | fprintf( fport,"%i\n\r", new_header_sip_port ); |
klauss | 106:a34fcf9f0e02 | 42 | fclose( fport ); |
klauss | 106:a34fcf9f0e02 | 43 | } |
klauss | 81:3656f00ab3db | 44 | } |
klauss | 81:3656f00ab3db | 45 | |
klauss | 81:3656f00ab3db | 46 | void set_server_ip( char * new_server_ip ){ |
klauss | 81:3656f00ab3db | 47 | FILE * fsip = fopen("/qspi/serverip.txt", "w"); |
klauss | 106:a34fcf9f0e02 | 48 | if( fsip ) |
klauss | 106:a34fcf9f0e02 | 49 | { |
klauss | 106:a34fcf9f0e02 | 50 | fprintf( fsip,"%s\n\r", new_server_ip ); |
klauss | 106:a34fcf9f0e02 | 51 | fclose( fsip ); |
klauss | 106:a34fcf9f0e02 | 52 | } |
klauss | 81:3656f00ab3db | 53 | } |
klauss | 81:3656f00ab3db | 54 | |
klauss | 81:3656f00ab3db | 55 | void set_server_ext( int new_server_ext ){ |
klauss | 81:3656f00ab3db | 56 | FILE * fserext = fopen("/qspi/peerext.txt", "w"); |
klauss | 106:a34fcf9f0e02 | 57 | if( fserext ) |
klauss | 106:a34fcf9f0e02 | 58 | { |
klauss | 106:a34fcf9f0e02 | 59 | fprintf( fserext , "%i\n\r", new_server_ext ); |
klauss | 106:a34fcf9f0e02 | 60 | fclose( fserext ); |
klauss | 106:a34fcf9f0e02 | 61 | } |
klauss | 81:3656f00ab3db | 62 | } |
klauss | 81:3656f00ab3db | 63 | |
klauss | 81:3656f00ab3db | 64 | void set_server_port( int new_server_port ){ |
klauss | 81:3656f00ab3db | 65 | FILE * fsport = fopen("/qspi/serverport.txt", "w"); |
klauss | 106:a34fcf9f0e02 | 66 | if( fsport ) |
klauss | 106:a34fcf9f0e02 | 67 | { |
klauss | 106:a34fcf9f0e02 | 68 | fprintf(fsport,"%i\n\r", new_server_port ); |
klauss | 106:a34fcf9f0e02 | 69 | fclose( fsport ); |
klauss | 106:a34fcf9f0e02 | 70 | } |
klauss | 81:3656f00ab3db | 71 | } |
klauss | 81:3656f00ab3db | 72 | |
klauss | 81:3656f00ab3db | 73 | void set_mask( char * new_mask ){ |
klauss | 81:3656f00ab3db | 74 | FILE * fmask = fopen("/qspi/mymask.txt", "w"); |
klauss | 106:a34fcf9f0e02 | 75 | if( fmask ) |
klauss | 106:a34fcf9f0e02 | 76 | { |
klauss | 106:a34fcf9f0e02 | 77 | fprintf(fmask,"%s\n\r",new_mask ); |
klauss | 106:a34fcf9f0e02 | 78 | fclose( fmask ); |
klauss | 106:a34fcf9f0e02 | 79 | } |
klauss | 81:3656f00ab3db | 80 | } |
klauss | 81:3656f00ab3db | 81 | |
klauss | 81:3656f00ab3db | 82 | void set_gateway( char * new_gateway ){ |
klauss | 81:3656f00ab3db | 83 | FILE * fgate = fopen("/qspi/mygateway.txt", "w"); |
klauss | 106:a34fcf9f0e02 | 84 | if( fgate ) |
klauss | 106:a34fcf9f0e02 | 85 | { |
klauss | 106:a34fcf9f0e02 | 86 | fprintf(fgate,"%s\n\r", new_gateway ); |
klauss | 106:a34fcf9f0e02 | 87 | fclose( fgate ); |
klauss | 106:a34fcf9f0e02 | 88 | } |
klauss | 81:3656f00ab3db | 89 | } |
klauss | 81:3656f00ab3db | 90 | |
klauss | 81:3656f00ab3db | 91 | void set_udp_port_listener( int new_udp_port_listener ){ |
klauss | 81:3656f00ab3db | 92 | FILE * fudpport = fopen( "/qspi/udpport.txt", "w" ); |
klauss | 106:a34fcf9f0e02 | 93 | if( fudpport ) |
klauss | 106:a34fcf9f0e02 | 94 | { |
klauss | 106:a34fcf9f0e02 | 95 | fprintf( fudpport, "%i\n\r",new_udp_port_listener ); |
klauss | 106:a34fcf9f0e02 | 96 | fclose( fudpport ); |
klauss | 106:a34fcf9f0e02 | 97 | } |
klauss | 81:3656f00ab3db | 98 | } |
klauss | 81:3656f00ab3db | 99 | |
klauss | 81:3656f00ab3db | 100 | void set_tcp_port_listener( int new_tcp_port_listener ){ |
klauss | 81:3656f00ab3db | 101 | FILE * ftcpport = fopen( "/qspi/tcpport.txt", "w" ); |
klauss | 106:a34fcf9f0e02 | 102 | if( ftcpport ) |
klauss | 106:a34fcf9f0e02 | 103 | { |
klauss | 106:a34fcf9f0e02 | 104 | fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); |
klauss | 106:a34fcf9f0e02 | 105 | fclose( ftcpport ); |
klauss | 106:a34fcf9f0e02 | 106 | } |
klauss | 81:3656f00ab3db | 107 | } |
klauss | 81:3656f00ab3db | 108 | |
klauss | 99:e80850c51106 | 109 | void set_fw_ip( char * new_fw_ip ){ |
klauss | 99:e80850c51106 | 110 | FILE * ffwip = fopen("/qspi/fw_ip.txt", "w" ); |
klauss | 106:a34fcf9f0e02 | 111 | if( ffwip ) |
klauss | 106:a34fcf9f0e02 | 112 | { |
klauss | 106:a34fcf9f0e02 | 113 | fprintf(ffwip,"%s\n\r", new_fw_ip ); |
klauss | 106:a34fcf9f0e02 | 114 | fclose( ffwip ); |
klauss | 106:a34fcf9f0e02 | 115 | } |
klauss | 99:e80850c51106 | 116 | } |
klauss | 99:e80850c51106 | 117 | |
klauss | 99:e80850c51106 | 118 | void set_fw_port( int new_fw_port ){ |
klauss | 99:e80850c51106 | 119 | FILE * ffwport = fopen("/qspi/fw_port.txt", "w" ); |
klauss | 106:a34fcf9f0e02 | 120 | if( ffwport ) |
klauss | 106:a34fcf9f0e02 | 121 | { |
klauss | 106:a34fcf9f0e02 | 122 | fprintf(ffwport,"%i\n\r", new_fw_port ); |
klauss | 106:a34fcf9f0e02 | 123 | fclose( ffwport ); |
klauss | 106:a34fcf9f0e02 | 124 | } |
klauss | 99:e80850c51106 | 125 | } |
klauss | 99:e80850c51106 | 126 | |
klauss | 81:3656f00ab3db | 127 | void set_max_ext( int new_max_ext ){ |
klauss | 81:3656f00ab3db | 128 | FILE * fmex = fopen( "/qspi/maxext.txt", "w" ); |
klauss | 99:e80850c51106 | 129 | if( fmex ){ |
klauss | 99:e80850c51106 | 130 | fprintf( fmex, "%i\n\r", new_max_ext ); |
klauss | 99:e80850c51106 | 131 | fclose( fmex ); |
klauss | 99:e80850c51106 | 132 | } |
klauss | 81:3656f00ab3db | 133 | } |
klauss | 81:3656f00ab3db | 134 | |
klauss | 81:3656f00ab3db | 135 | void set_min_ext( int new_min_ext ){ |
klauss | 81:3656f00ab3db | 136 | FILE * fmin = fopen( "/qspi/minext.txt", "w" ); |
klauss | 99:e80850c51106 | 137 | if( fmin ){ |
klauss | 99:e80850c51106 | 138 | fprintf( fmin, "%i\n\r", new_min_ext ); |
klauss | 99:e80850c51106 | 139 | fclose( fmin ); |
klauss | 99:e80850c51106 | 140 | } |
klauss | 81:3656f00ab3db | 141 | } |
klauss | 81:3656f00ab3db | 142 | |
klauss | 106:a34fcf9f0e02 | 143 | void set_shift_port( int new_shift_port ){ |
klauss | 106:a34fcf9f0e02 | 144 | FILE * shift_port = fopen("/qspi/shift_port.txt", "w" ); |
klauss | 106:a34fcf9f0e02 | 145 | if( shift_port ) |
klauss | 106:a34fcf9f0e02 | 146 | { |
klauss | 106:a34fcf9f0e02 | 147 | fprintf( shift_port,"%i\n\r", new_shift_port ); |
klauss | 106:a34fcf9f0e02 | 148 | fclose( shift_port ); |
klauss | 106:a34fcf9f0e02 | 149 | if( debug_file ) debug_msg("Set /qspi/shift_port.txt"); |
klauss | 106:a34fcf9f0e02 | 150 | } |
klauss | 106:a34fcf9f0e02 | 151 | else |
klauss | 106:a34fcf9f0e02 | 152 | { |
klauss | 106:a34fcf9f0e02 | 153 | if( debug_file ) debug_msg("Cannot open /qspi/shift_port.txt"); |
klauss | 106:a34fcf9f0e02 | 154 | } |
klauss | 106:a34fcf9f0e02 | 155 | } |
klauss | 106:a34fcf9f0e02 | 156 | |
klauss | 81:3656f00ab3db | 157 | // Print the content of a given file |
klauss | 106:a34fcf9f0e02 | 158 | void cat( const char * fname ){ |
klauss | 81:3656f00ab3db | 159 | char buff[513]; |
klauss | 81:3656f00ab3db | 160 | int num; |
klauss | 81:3656f00ab3db | 161 | |
klauss | 106:a34fcf9f0e02 | 162 | FILE *fp = fopen( fname, "r" ); |
klauss | 81:3656f00ab3db | 163 | if (fp == NULL) { |
klauss | 104:62646ef786a3 | 164 | if( debug_file ) if( debug_uart3 && !( from_eth ) ) pc.printf( "Failed to open %s", fname); |
klauss | 81:3656f00ab3db | 165 | return; |
klauss | 81:3656f00ab3db | 166 | } |
klauss | 81:3656f00ab3db | 167 | |
klauss | 81:3656f00ab3db | 168 | while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ |
klauss | 81:3656f00ab3db | 169 | buff[ num ] = '\0'; |
klauss | 104:62646ef786a3 | 170 | if( debug_uart3 && !( from_eth ) ) pc.printf( buff ); |
klauss | 81:3656f00ab3db | 171 | if( from_eth ){ |
klauss | 105:a930035b6556 | 172 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); |
klauss | 81:3656f00ab3db | 173 | |
klauss | 105:a930035b6556 | 174 | else if( udp_query ){ |
klauss | 105:a930035b6556 | 175 | udp_query_send_msg( buff ); |
klauss | 81:3656f00ab3db | 176 | } |
klauss | 81:3656f00ab3db | 177 | } |
klauss | 81:3656f00ab3db | 178 | } |
klauss | 81:3656f00ab3db | 179 | fclose(fp); |
klauss | 104:62646ef786a3 | 180 | } |