Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
58:af7e8788f106
Parent:
57:78f7191a8b69
Child:
59:e1e300880d2d
--- a/prompt.cpp	Thu Oct 23 17:18:58 2014 +0000
+++ b/prompt.cpp	Thu Oct 23 19:58:09 2014 +0000
@@ -35,9 +35,10 @@
 uint8_t test_debug = 1;
 #define PVERSION 4          // Sempre atualizar a versao do prompt
 
-#define DEBUGBUFSIZE 50
-char __debug_buf__[DEBUGBUFSIZE];
+char __debug_buf__[ DEBUGBUFSIZE ];
 char * debug_buf = __debug_buf__;
+char last_cmd[ DEBUGBUFSIZE ];
+char tmp_cmd[ DEBUGBUFSIZE ] = "help";
 char last_debug_buf[ DEBUGBUFSIZE ] = "help";
 FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext, *fudpport, *ftcpport, *ftip, *ftport;
 uint8_t debug_prompt = 0;
@@ -264,6 +265,7 @@
         }
         cat("/qspi/telemetry_port.txt");
         
+        strcpy( last_cmd, tmp_cmd );
         debug_buf[ 0 ] = 0;
         bufptr = 0;
         if( tcp_session ) tcp_client.send_all( "\n\r>" , strlen( "\n\r>" ) );
@@ -414,6 +416,8 @@
             
         set_telemetry_port( __TELEMETRY_SERVER_PORT__ );
         
+        strcpy( last_cmd, tmp_cmd );
+        
         pc.printf("\n\rDefault configurations set!\n\r");
         if( from_eth ){
             snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\n\rDefault configurations set!\n\r");
@@ -601,13 +605,16 @@
     }
         
     // Prompt commands here
-    if ( bufret == 1 ) {     
+    if ( bufret == 1 ) {
         static unsigned int promptcb_last_ext = 0;                                                                                                                                
         static unsigned int promptcb_last_port = 0;  
         static char promptcb_last_cmd[ 300 ];
+        
+        strcpy( tmp_cmd, debug_buf );
         if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) ".",1 )) {
             miss_match = false;
-            strcpy( debug_buf, last_debug_buf );
+            strcpy( debug_buf, last_cmd );
+            strcpy( tmp_cmd, debug_buf );
         }
         
         //tratamento dos enters
@@ -975,12 +982,12 @@
             
             if( from_eth ){
                 snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\r\next=%d port=%d\r\ncmd=%s\r\n\n\rComando enviado\n\r", ext, port, cmd );
-                debug_buf[ strlen( debug_buf ) - 1 ] = '\0';
+                //debug_buf[ strlen( debug_buf ) - 1 ] = '\0';
             }
             
             debug_buf = ref;
-            bufptr = 0;
-            debug_buf[ 0 ] = 0;
+            //bufptr = 0;
+            //debug_buf[ 0 ] = 0;
             
             /*
 
@@ -1034,17 +1041,17 @@
             }
         }
         */
-        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) {
+        else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "cks",3 )) {
             miss_match = false;
             pcks_s = 1;
         }
 
-        if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) {
+        else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "showcb",6 )) {
             miss_match = false;
             pshowcb = 1;
         }
         
-        if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_main ", 11 )) {
+        else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_main ", 11 )) {
             if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) {
                 miss_match = false;
                 pc.printf("\r\nDebug Main ON");
@@ -1065,7 +1072,7 @@
             }
         }
         
-        if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) {
+        else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_cb_rx ", 12 )) {
             if (xmemmatch( (uint8_t*)( debug_buf + 12 ), (uint8_t*) "on",2 )) {
                 miss_match = false;
                 pc.printf("\tDebug Cbx Rx ON");
@@ -1086,7 +1093,7 @@
             }
         }
         
-        if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_file ", 11 )) {
+        else if (xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "debug_file ", 11 )) {
             if (xmemmatch( (uint8_t*)( debug_buf + 11 ), (uint8_t*) "on",2 )) {
                 miss_match = false;
                 pc.printf("\tDebug File ON");
@@ -1107,7 +1114,7 @@
             }
         }
         
-        if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) {
+        else if( xstrmatch( (uint8_t*)debug_buf, (uint8_t*) "help" )) {
             miss_match = false;
             pc.printf("\n\r****************************PROMPT HELP******************\n\r");
             if( from_eth ){
@@ -1334,7 +1341,7 @@
             if( from_eth ) snprintf( debug_buf,__PROMPT_ETH_BUFFER_SIZE__, "PROMPT VERSION: V%d\n\r",PVERSION);
         }
         
-        if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )){
+        else if( xmemmatch( (uint8_t*)debug_buf, (uint8_t*) "callme ", 7 )){
             miss_match = false;
             static uint8_t id_msg = 0x10;
             uint8_t write_buffer[ 300 ];
@@ -1355,7 +1362,7 @@
             
             pc.printf("\r\next=%d port=%d\r\ncmd=%s\r\n", ext, port, cmd );
             __send_to_cb__( __build_cb_package__( ext, port, __PROMPT__, cmd, id_msg++, __CB_BUFFER_SIZE__ - __VZ_HEADER_OFFSET__, write_buffer ) );
-            pc.printf("\n\rComando enviado\n\r");
+            pc.printf("Comando enviado\n\r");
             
             if( from_eth ){
                 snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "\r\next=%d port=%d\r\ncmd=%s\r\n\n\rComando enviado\n\r", ext, port, cmd );
@@ -1370,11 +1377,13 @@
             pc.printf("\n\r> %s: command not found\n\r", debug_buf );
             if( from_eth ){
                 snprintf( debug_buf, __PROMPT_ETH_BUFFER_SIZE__, "> %s: command not found\n ", debug_buf );
-                debug_buf[ strlen( debug_buf ) - 1 ] = '\0';
+                //debug_buf[ strlen( debug_buf ) - 1 ] = '\0';
             }
         }
         else{
-            if( ( b != 0x0D ) && ( bufptr != 0 ) ) strcpy( last_debug_buf, debug_buf );
+            if( from_eth && strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd );
+            
+            else if( strlen( debug_buf ) > 2 ) strcpy( last_cmd, tmp_cmd );
         }
     }      
     if( b == 0x0D || bufret == 1 || bufptr > DEBUGBUFSIZE ){
@@ -1401,9 +1410,7 @@
             bufptr = last_bufptr;
         }else{
             bufptr = 0;
-            for (uint8_t i =0; i < DEBUGBUFSIZE; i++) {
-                debug_buf[i] = 0;
-            }
+            for( uint8_t i = 0; i < DEBUGBUFSIZE; i++ ) debug_buf[ i ] = 0;
         }
         pc.putc(0x0A);
         pc.putc(0x0D);