![](/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@104:62646ef786a3, 2015-02-25 (annotated)
- Committer:
- klauss
- Date:
- Wed Feb 25 18:44:11 2015 +0000
- Revision:
- 104:62646ef786a3
- Parent:
- 100:09a23fcd3bdf
- Child:
- 105:a930035b6556
- Remo??o do implementado para bootloader cbx.; - Remo??o do implementado para telemetria.; - Remo??o do implementado ( comentado ) em file_system_manager.cpp; - BUGFIX perda de conex?o serial quando recebido um comando via eth;
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 | 99:e80850c51106 | 83 | void set_fw_ip( char * new_fw_ip ){ |
klauss | 99:e80850c51106 | 84 | FILE * ffwip = fopen("/qspi/fw_ip.txt", "w" ); |
klauss | 99:e80850c51106 | 85 | fprintf(ffwip,"%s\n\r", new_fw_ip ); |
klauss | 99:e80850c51106 | 86 | fclose( ffwip ); |
klauss | 99:e80850c51106 | 87 | } |
klauss | 99:e80850c51106 | 88 | |
klauss | 99:e80850c51106 | 89 | void set_fw_port( int new_fw_port ){ |
klauss | 99:e80850c51106 | 90 | FILE * ffwport = fopen("/qspi/fw_port.txt", "w" ); |
klauss | 99:e80850c51106 | 91 | fprintf(ffwport,"%i\n\r", new_fw_port ); |
klauss | 99:e80850c51106 | 92 | fclose( ffwport ); |
klauss | 99:e80850c51106 | 93 | } |
klauss | 99:e80850c51106 | 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 | 99:e80850c51106 | 97 | if( fmex ){ |
klauss | 99:e80850c51106 | 98 | fprintf( fmex, "%i\n\r", new_max_ext ); |
klauss | 100:09a23fcd3bdf | 99 | //debug_msg(""); |
klauss | 99:e80850c51106 | 100 | fclose( fmex ); |
klauss | 100:09a23fcd3bdf | 101 | //debug_msg(""); |
klauss | 99:e80850c51106 | 102 | } |
klauss | 81:3656f00ab3db | 103 | } |
klauss | 81:3656f00ab3db | 104 | |
klauss | 81:3656f00ab3db | 105 | void set_min_ext( int new_min_ext ){ |
klauss | 81:3656f00ab3db | 106 | FILE * fmin = fopen( "/qspi/minext.txt", "w" ); |
klauss | 99:e80850c51106 | 107 | if( fmin ){ |
klauss | 99:e80850c51106 | 108 | fprintf( fmin, "%i\n\r", new_min_ext ); |
klauss | 99:e80850c51106 | 109 | fclose( fmin ); |
klauss | 99:e80850c51106 | 110 | } |
klauss | 81:3656f00ab3db | 111 | } |
klauss | 81:3656f00ab3db | 112 | |
klauss | 81:3656f00ab3db | 113 | // Print the content of a given file |
klauss | 81:3656f00ab3db | 114 | void cat(const char * fname){ |
klauss | 81:3656f00ab3db | 115 | char buff[513]; |
klauss | 81:3656f00ab3db | 116 | int num; |
klauss | 81:3656f00ab3db | 117 | |
klauss | 81:3656f00ab3db | 118 | FILE *fp = fopen(fname, "r"); |
klauss | 81:3656f00ab3db | 119 | if (fp == NULL) { |
klauss | 104:62646ef786a3 | 120 | if( debug_file ) if( debug_uart3 && !( from_eth ) ) pc.printf( "Failed to open %s", fname); |
klauss | 81:3656f00ab3db | 121 | return; |
klauss | 81:3656f00ab3db | 122 | } |
klauss | 81:3656f00ab3db | 123 | |
klauss | 81:3656f00ab3db | 124 | while( ( num = fread( buff, 1, 512, fp ) ) > 0 ){ |
klauss | 81:3656f00ab3db | 125 | buff[ num ] = '\0'; |
klauss | 104:62646ef786a3 | 126 | if( debug_uart3 && !( from_eth ) ) pc.printf( buff ); |
klauss | 81:3656f00ab3db | 127 | if( from_eth ){ |
klauss | 81:3656f00ab3db | 128 | if( tcp_session ) while( !( tcp_client.send_all( buff, strlen( buff ) ) ) ); |
klauss | 81:3656f00ab3db | 129 | |
klauss | 81:3656f00ab3db | 130 | else if( udp_request ){ |
klauss | 104:62646ef786a3 | 131 | int send = udp_server.sendTo( udp_client, buff, strlen( buff ) ); |
klauss | 104:62646ef786a3 | 132 | if( send != strlen( buff ) ) |
klauss | 104:62646ef786a3 | 133 | { |
klauss | 104:62646ef786a3 | 134 | if( debug_reconnect ) |
klauss | 104:62646ef786a3 | 135 | { |
klauss | 104:62646ef786a3 | 136 | send_msg("Reconnect UDP_request client"); |
klauss | 104:62646ef786a3 | 137 | } |
klauss | 104:62646ef786a3 | 138 | |
klauss | 104:62646ef786a3 | 139 | reconnect_prompt_udp_socket(); |
klauss | 104:62646ef786a3 | 140 | miss_prompt_udp_send_pkg++; |
klauss | 104:62646ef786a3 | 141 | } |
klauss | 81:3656f00ab3db | 142 | } |
klauss | 81:3656f00ab3db | 143 | } |
klauss | 81:3656f00ab3db | 144 | } |
klauss | 81:3656f00ab3db | 145 | fclose(fp); |
klauss | 104:62646ef786a3 | 146 | } |