![](/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@113:db67ae00550e, 2015-04-16 (annotated)
- Committer:
- klauss
- Date:
- Thu Apr 16 12:57:13 2015 +0000
- Revision:
- 113:db67ae00550e
- Parent:
- 109:a5b8264ffbbc
- Child:
- 114:472502b31a12
valide esse fw
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 | 113:db67ae00550e | 21 | if( fip ) |
klauss | 113:db67ae00550e | 22 | { |
klauss | 113:db67ae00550e | 23 | fprintf( fip, "%s\n\r", new_header_ip ); |
klauss | 113:db67ae00550e | 24 | fclose( fip ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 30 | if( fext ) |
klauss | 113:db67ae00550e | 31 | { |
klauss | 113:db67ae00550e | 32 | fprintf( fext, "%i\n\r", new_header_ext ); |
klauss | 113:db67ae00550e | 33 | fclose( fext ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 39 | if( fport ) |
klauss | 113:db67ae00550e | 40 | { |
klauss | 113:db67ae00550e | 41 | fprintf( fport,"%i\n\r", new_header_sip_port ); |
klauss | 113:db67ae00550e | 42 | fclose( fport ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 48 | if( fsip ) |
klauss | 113:db67ae00550e | 49 | { |
klauss | 113:db67ae00550e | 50 | fprintf( fsip,"%s\n\r", new_server_ip ); |
klauss | 113:db67ae00550e | 51 | fclose( fsip ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 57 | if( fserext ) |
klauss | 113:db67ae00550e | 58 | { |
klauss | 113:db67ae00550e | 59 | fprintf( fserext , "%i\n\r", new_server_ext ); |
klauss | 113:db67ae00550e | 60 | fclose( fserext ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 66 | if( fsport ) |
klauss | 113:db67ae00550e | 67 | { |
klauss | 113:db67ae00550e | 68 | fprintf(fsport,"%i\n\r", new_server_port ); |
klauss | 113:db67ae00550e | 69 | fclose( fsport ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 75 | if( fmask ) |
klauss | 113:db67ae00550e | 76 | { |
klauss | 113:db67ae00550e | 77 | fprintf(fmask,"%s\n\r",new_mask ); |
klauss | 113:db67ae00550e | 78 | fclose( fmask ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 84 | if( fgate ) |
klauss | 113:db67ae00550e | 85 | { |
klauss | 113:db67ae00550e | 86 | fprintf(fgate,"%s\n\r", new_gateway ); |
klauss | 113:db67ae00550e | 87 | fclose( fgate ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 93 | if( fudpport ) |
klauss | 113:db67ae00550e | 94 | { |
klauss | 113:db67ae00550e | 95 | fprintf( fudpport, "%i\n\r",new_udp_port_listener ); |
klauss | 113:db67ae00550e | 96 | fclose( fudpport ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 102 | if( ftcpport ) |
klauss | 113:db67ae00550e | 103 | { |
klauss | 113:db67ae00550e | 104 | fprintf( ftcpport, "%i\n\r",new_tcp_port_listener ); |
klauss | 113:db67ae00550e | 105 | fclose( ftcpport ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 111 | if( ffwip ) |
klauss | 113:db67ae00550e | 112 | { |
klauss | 113:db67ae00550e | 113 | fprintf(ffwip,"%s\n\r", new_fw_ip ); |
klauss | 113:db67ae00550e | 114 | fclose( ffwip ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 120 | if( ffwport ) |
klauss | 113:db67ae00550e | 121 | { |
klauss | 113:db67ae00550e | 122 | fprintf(ffwport,"%i\n\r", new_fw_port ); |
klauss | 113:db67ae00550e | 123 | fclose( ffwport ); |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 143 | void set_shift_port( int new_shift_port ){ |
klauss | 113:db67ae00550e | 144 | FILE * shift_port = fopen("/qspi/shift_port.txt", "w" ); |
klauss | 113:db67ae00550e | 145 | if( shift_port ) |
klauss | 113:db67ae00550e | 146 | { |
klauss | 113:db67ae00550e | 147 | fprintf( shift_port,"%i\n\r", new_shift_port ); |
klauss | 113:db67ae00550e | 148 | fclose( shift_port ); |
klauss | 113:db67ae00550e | 149 | if( debug_file ) debug_msg("Set /qspi/shift_port.txt"); |
klauss | 113:db67ae00550e | 150 | } |
klauss | 113:db67ae00550e | 151 | else |
klauss | 113:db67ae00550e | 152 | { |
klauss | 113:db67ae00550e | 153 | if( debug_file ) debug_msg("Cannot open /qspi/shift_port.txt"); |
klauss | 113:db67ae00550e | 154 | } |
klauss | 113:db67ae00550e | 155 | } |
klauss | 113:db67ae00550e | 156 | |
klauss | 81:3656f00ab3db | 157 | // Print the content of a given file |
klauss | 113:db67ae00550e | 158 | void cat( const char * fname ){ |
klauss | 81:3656f00ab3db | 159 | char buff[513]; |
klauss | 81:3656f00ab3db | 160 | int num; |
klauss | 81:3656f00ab3db | 161 | |
klauss | 113:db67ae00550e | 162 | FILE *fp = fopen( fname, "r" ); |
klauss | 81:3656f00ab3db | 163 | if (fp == NULL) { |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 170 | if( debug_uart3 && !( from_eth ) ) pc.printf( buff ); |
klauss | 81:3656f00ab3db | 171 | if( from_eth ){ |
klauss | 113:db67ae00550e | 172 | if( tcp_session && !udp_query ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); |
klauss | 81:3656f00ab3db | 173 | |
klauss | 113:db67ae00550e | 174 | else if( udp_query ){ |
klauss | 113:db67ae00550e | 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 | 113:db67ae00550e | 180 | } |