![](/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
Diff: prompt.cpp
- Revision:
- 106:a34fcf9f0e02
- Parent:
- 105:a930035b6556
- Child:
- 107:cf1e43414adb
diff -r a930035b6556 -r a34fcf9f0e02 prompt.cpp --- a/prompt.cpp Tue Mar 10 18:10:57 2015 +0000 +++ b/prompt.cpp Fri Mar 13 19:40:56 2015 +0000 @@ -16,7 +16,7 @@ char eth_buffer[ __PROMPT_ETH_BUFFER_SIZE__ ]; char gp_buff[ DEBUGBUFSIZE ]; -FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport, *ffwip, *ffwport, *fmax, *fmin; +FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport, *ffwip, *ffwport, *fmax, *fmin, *fshift_port; uint8_t bufptr = 0; uint8_t last_bufptr = 0; @@ -25,12 +25,12 @@ { int udp_bind = udp_client.bind( UDP_PORT_LISTENER ); udp_client.set_blocking( false, 0 ); - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\n******* Prompt eth UDP Ready [ %d ] *******", udp_bind ); + if( debug_uart3 && !( from_eth ) ) pc.printf("\r\n******* Prompt eth UDP Ready [ %d ] *******\r\n", udp_bind ); int tcp_bind = tcp_server.bind( TCP_PORT_LISTENER ); tcp_server.set_blocking( false, 0 ); int tcp_listen = tcp_server.listen(); - if( debug_uart3 && !( from_eth ) ) pc.printf("\r\n******* Prompt eth TCP Ready [ %d, %d ] *******", tcp_bind, tcp_listen ); + if( debug_uart3 && !( from_eth ) ) pc.printf("\r\n******* Prompt eth TCP Ready [ %d, %d ] *******\r\n", tcp_bind, tcp_listen ); } // main prompt process @@ -258,6 +258,8 @@ miss_match = false; if( debug_uart3 && !( from_eth ) ) pc.printf("\n\r"); files('s'); + for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; + bufptr = 0; } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "rx" ) ) { @@ -371,6 +373,12 @@ set_fw_port( atoi( debug_buf + 8 ) ); files('s'); } + + else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "shift_port ", 11 ) ) { + miss_match = false; + set_shift_port( atoi( debug_buf + 11 ) ); + files('s'); + } else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "dconfig" ) ) { miss_match = false; @@ -415,6 +423,11 @@ debug_msg("Test something"); } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "deleted" ) ) { + miss_match = false; + send_msg("::%d::", deleted_sip ); + } + else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "missed" ) ) { miss_match = false; missed_send_udp_pkg = true; @@ -2185,24 +2198,35 @@ if( from_eth ) { - if( debug_buf[ strlen( debug_buf ) - 1 ] == '\r' || debug_buf[ strlen( debug_buf ) - 1 ] == '\n' ) + if( strlen( debug_buf ) > 0 ) { - //strcat( debug_buf, "> " ); - strcpy( debug_buf, "> " ); - } else { - //strcat( debug_buf, "\n\r> " ); - strcpy( debug_buf, "\n\r> " ); + + if( debug_buf[ strlen( debug_buf ) - 1 ] == '\r' || debug_buf[ strlen( debug_buf ) - 1 ] == '\n' ) + { + //strcat( debug_buf, "> " ); + strcpy( debug_buf, "> " ); + } else { + //strcat( debug_buf, "\n\r> " ); + strcpy( debug_buf, "\n\r> " ); + } + }else{ + } if( tcp_session && !udp_query ) { tcp_client.send_all( debug_buf, strlen( debug_buf ) ); } else if( udp_query ) { - udp_query_send_msg( debug_buf ); + + udp_query_send_msg( debug_buf ); + } for( register uint16_t i = 0; i < __PROMPT_ETH_BUFFER_SIZE__; i++ ) eth_buffer[ i ] = 0; + debug_buf = __debug_buf__; + bufptr = last_bufptr; + } else { @@ -2220,6 +2244,7 @@ { // show files if (type == 's' ) { + if( debug_uart3 && !( from_eth ) ) pc.printf("Header IP " ); if( from_eth ) { snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Header IP " ); @@ -2384,18 +2409,33 @@ } cat("/qspi/minext.txt"); + + if( debug_uart3 && !( from_eth ) ) pc.printf("Shift Port "); + if( from_eth ) { + snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "Shift Port " ); + if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); + else if( udp_query ) { + udp_query_send_msg( debug_buf ); + } + } + + cat("/qspi/shift_port.txt"); + + //*------------ formatando a saida ----------------*// strcpy( last_cmd, tmp_cmd ); bufptr = 0; for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; if( from_eth ) { + if( tcp_session && !udp_query ) { snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "> " ); if( tcp_session && !udp_query ) while( !( tcp_client.send_all( debug_buf, strlen( debug_buf ) ) ) ); } else if( udp_query ) { udp_query_send_msg( "> " ); + } } } @@ -2416,9 +2456,11 @@ if( fmin ) fclose( fmin ); if( ffwip ) fclose( ffwip ); if( ffwport) fclose( ffwport ); + if( fshift_port ) fclose ( fshift_port ); } if (type == 'i' ) { + // Check if files exist, if not create the files //fixme criar um bool pra cada file bool exists = true; @@ -2503,10 +2545,19 @@ fmin = fopen("/qspi/minext.txt", "r" ); if( fmin == NULL ) { + if( debug_file ) debug_msg("Don't exist /qspi/minext.txt"); set_min_ext( MIN_EXT ); exists = false; } - + + fshift_port = fopen("/qspi/shift_port.txt", "r" ); + if( fshift_port == NULL ) + { + if( debug_file ) debug_msg("Don't exist /qspi/shift_port.txt"); + set_shift_port( SHIFT_PORT ); + exists = false; + } + if( !exists ) { if( debug_uart3 && !( from_eth ) ) pc.printf("\n\rDefault configurations set!\n\r"); if( from_eth ) { @@ -2524,6 +2575,7 @@ if (type == 'r' ) { // Just open for read + fip = fopen("/qspi/myip.txt", "r"); fmask = fopen("/qspi/mymask.txt", "r"); fgate = fopen("/qspi/mygateway.txt", "r"); @@ -2538,9 +2590,12 @@ ffwport = fopen("/qspi/fw_port.txt", "r" ); fmax = fopen("/qspi/maxext.txt", "r" ); fmin = fopen("/qspi/minext.txt", "r" ); + fshift_port = fopen("/qspi/shift_port.txt", "r" ); + } if( type == 'w') { + // Create and write the default configs set_ip( __MY_IP__ ); @@ -2569,6 +2624,8 @@ set_max_ext( MAX_EXT ); set_min_ext( MIN_EXT ); + + set_shift_port( SHIFT_PORT ); strcpy( last_cmd, tmp_cmd ); @@ -2584,10 +2641,12 @@ bufptr = 0; for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } + } - if (type == 'e') { - //Erase configs + if (type == 'e') + { + //Erase configs fip = fopen("/qspi/myip.txt", "w"); fmask = fopen("/qspi/mymask.txt", "w"); fgate = fopen("/qspi/mygateway.txt", "w"); @@ -2602,27 +2661,29 @@ ffwport = fopen("/qspi/fw_port.txt", "w" ); fmax = fopen("/qspi/maxext.txt", "w" ); fmin = fopen("/qspi/minext.txt", "w" ); + fshift_port = fopen("/qspi/shift_port.txt", "w" ); - //FIXME verificar se deveria colocar tudo para %s - fprintf( fip, "%s\n\r", "" ); - fprintf( fport, "%i\n\r", 0 ); - fprintf( fext, "%i\n\r", 0 ); + if( fip ) fprintf( fip, "%s\n\r", "" ); + if( fport ) fprintf( fport, "%i\n\r", 0 ); + if( fext ) fprintf( fext, "%i\n\r", 0 ); - fprintf( fsip, "%s\n\r", "" ); - fprintf( fserext, "%i\n\r", 0 ); - fprintf( fsport, "%i\n\r", 0 ); + if( fsip ) fprintf( fsip, "%s\n\r", "" ); + if( fserext ) fprintf( fserext, "%i\n\r", 0 ); + if( fsport ) fprintf( fsport, "%i\n\r", 0 ); - fprintf( fmask, "%s\n\r","" ); - fprintf( fgate, "%s\n\r", "" ); + if( fmask ) fprintf( fmask, "%s\n\r","" ); + if( fgate ) fprintf( fgate, "%s\n\r", "" ); - fprintf( fudpport, "%i\n\r", 0 ); - fprintf( ftcpport, "%i\n\r", 0 ); + if( fudpport ) fprintf( fudpport, "%i\n\r", 0 ); + if( ftcpport ) fprintf( ftcpport, "%i\n\r", 0 ); - fprintf( ffwip, "%s\n\r","" ); - fprintf( ffwport, "%i\n\r",0 ); + if( ffwip ) fprintf( ffwip, "%s\n\r","" ); + if( ffwport ) fprintf( ffwport, "%i\n\r",0 ); - fprintf( fmax, "%i\n\r", 0 ); - fprintf( fmin, "%i\n\r", 0 ); + if( fmax ) fprintf( fmax, "%i\n\r", 0 ); + if( fmin ) fprintf( fmin, "%i\n\r", 0 ); + + if( fshift_port ) fprintf( fshift_port, "%i\n\r", 0 ); files('c'); @@ -2638,6 +2699,7 @@ bufptr = 0; for( register int i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0; } + } } @@ -2651,7 +2713,8 @@ // check if the files are created files('i'); files('c'); - pc.printf("\r\n******* File System Ready *******"); + pc.printf("\r\n******* File System Ready *******\r\n"); + debug_file = false; } int str2uint ( char * s, unsigned int * val )