Modularizando o src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Revision:
35:96885a7931f0
Parent:
33:735fd60e96d8
Child:
36:728498a78e1e
--- a/prompt.cpp	Tue Sep 30 14:28:01 2014 +0000
+++ b/prompt.cpp	Tue Sep 30 18:15:08 2014 +0000
@@ -26,12 +26,14 @@
 #define PVERSION 1.1          // Sempre atualizar a versao do prompt
 
 #define DEBUGBUFSIZE 50
-char debug_buf[DEBUGBUFSIZE];
+char __debug_buf__[DEBUGBUFSIZE];
+char * debug_buf = __debug_buf__;
 char last_debug_buf[ DEBUGBUFSIZE ] = "help";
 FILE *fip, *fmask, *fgate, *fport, *fsip, *fsport, *fext, *fserext;
 uint8_t dog = 1;
 uint8_t debug_prompt = 0;
 uint8_t bufptr = 0;
+uint8_t last_bufptr = 0;
  
 uint8_t xmemmatch(const uint8_t * s1, const uint8_t * s2, uint16_t size) {      // presente da lib.h pode retirar da versao final
   while (size--) {
@@ -234,40 +236,45 @@
 }
 
 // main prompt process
-void prompt_process(){
+void prompt_process( char * ethernet_msg ){
     //FIXME dar flush na serial
     volatile char b = 0;
     static uint8_t bufret = 0;
     static Timer flood_timeout;
+    bool restore = false;
         
     if( flood_timeout.read() > 60 ){
         pflood = 0;
         flood_timeout.stop();
         flood_timeout.reset();
     }
-        
-    if ( pc.readable() ){
+    
+    if( ethernet_msg == NULL ){
+        if ( pc.readable() ){
             // imput do teclado
             b = pc.getc();
             
             if( b == 0x0D ){ // enter
                 bufret = 1;
             }else{
-                //FIXME como mudar o contador quando eu aperto backspace
                 pc.putc( b );
                 if( b == 0x08 || b == 0x7F ){ // BS | DEL
                     if( bufptr > 0 ) debug_buf[ --bufptr ] = 0;
-                    //bufptr--;
-                    //pc.printf(".");
                 }else if( b == 0x09 ){
                     // ignore tab
                 }else{  
                     debug_buf[bufptr] = b;
-                    //pc.printf("(%x)", (uint8_t)b );
                     bufptr++;
                 }
             }
         }
+    }else{
+        last_bufptr = bufptr;
+        bufptr = strlen( ethernet_msg );
+        debug_buf = ethernet_msg;
+        restore = true;
+        bufret = 1;
+    }
         
     // Prompt commands here
     if ( bufret == 1 ) {     
@@ -628,4 +635,10 @@
         pc.putc(0x0D);
         pc.printf("> ");
     }
+    if( restore ){
+        debug_buf = __debug_buf__;
+        bufptr = last_bufptr;
+        bufret = 0;
+        restore = false;
+    }
 }   
\ No newline at end of file