library to modify and read program variable in runtime from a serial console. You can reset as well the mbed from the console without pushing buttons. Handy for debugging from the online compiler as you can change the behavior of the program without need to recompile each time.

Revision:
8:934ec53fe2c0
Parent:
7:fafe81a95c08
Child:
9:d081aa4e4418
--- a/VarStore.cpp	Mon Aug 25 17:55:39 2014 +0000
+++ b/VarStore.cpp	Mon Aug 25 19:54:12 2014 +0000
@@ -3,7 +3,7 @@
 #include  <stdio.h>
 #include "mbed.h"
 #include "rtos.h"
-#include "SerialBase.h"
+
 
 extern "C" void mbed_reset();
 
@@ -15,10 +15,10 @@
 *
 *
 ********************************/
-VarStore::VarStore(Serial *ser)
+VarStore::VarStore(     RawSerial *ser)
 {
     VarCounter=0;
-    this->pc=ser; 
+    this->pc=ser;
 }
 
 /*******************************
@@ -41,8 +41,8 @@
     VarItem *V;
     char *Name;
 
-    pc->printf("VarStore Set %s\n",Input);
-    
+   // beaware of puts  pc->printf("VarStore Set %s\n",Input);
+
     if(Input [0] == 's') {
         strtok(Input,":");
         Name=strtok(NULL,":");
@@ -90,7 +90,6 @@
 
 VarItem *VarStore::GetVar(char *Name)
 {
-
     for (int i=0; i<SZ; i++)
         if((strcmp(Name,Store[i].GetVarName()))==0)
             return &Store[i];
@@ -100,12 +99,25 @@
 
 char*  VarStore::Get(char *Name)
 {
-
+    char b[100];
     VarItem *V;
+    V=GetVar(Name);
+    VarStore::MyThis->pc->puts(" antes de dump ");
+    sprintf(b," %s %d %d %d \n",
+        V->VarName,*V->ValInt,V->VarType,V->ArraySize);
+       
+    VarStore::MyThis->pc->puts(b);
+     V->Dump();
+    
+  //  char VarName[VAR_NAME_LEN];
 
-    V=GetVar(Name);
-    if(V!=NULL) return V->Dump();
-    else
+  //  int   *ValInt;
+  //  float *ValFloat;
+  //  VarTypes VarType;
+  //  unsigned int ArraySize;
+ //   if(V!=NULL) return V->Dump();
+ //   else
+     VarStore::MyThis->pc->puts(" despues de dump ");
         return NULL;
 }
 
@@ -118,54 +130,35 @@
 
 void Worker2()
 {
-    
+
     static char c, *ret=STR_OK;// not NULL to start in no error state
-    
+
     static int ci_counter=0;
     static char Cs[CI_SZ];
-    
-    
-    
-
-//    for(int i=0; i<CI_SZ; i++) Cs[i]='\0';
+    if(VarStore::MyThis->pc->readable()) {
+        c=VarStore::MyThis->pc->getc();
 
-   VarStore::MyThis->pc->printf(" hi worker 2\n");
-   
- 
- //   while (1) {
-        if(VarStore::MyThis->pc->readable()) {
-            c=VarStore::MyThis->pc->getc();
-//           MyThis->pc->printf(" leo %c\n",c);
-            if(ci_counter >= CI_SZ-1) {   // RESET
+        if(ci_counter >= CI_SZ-1) {   // RESET
+            ci_counter=0;
+            Cs[0]='\0';
+        } else {
+            if(c=='\r') {
+                Cs[ci_counter]='\0';
+                ret=VarStore::MyThis->Do(Cs);
                 ci_counter=0;
                 Cs[0]='\0';
-//               MyThis->pc->printf(" reset\n");
-
             } else {
-                if(c=='\r') {
-                    Cs[ci_counter]='\0';
-//                    MyThis->pc->printf(" CI -%s- \n",Cs);
-                    ret=VarStore::MyThis->Do(Cs);
-                    ci_counter=0;
-                    Cs[0]='\0';
-                    //                 MyThis->pc->printf(" set variable (%d)\n",ret);
-                    //                  MyThis->pc->printf(" Get offset -%s- \n",MyThis->Get("offset"));
-                } else {
-//                  MyThis->pc->printf(" CI -%s- -%c- -%d- \n",Cs,c,ci_counter);
-
-                    Cs[ci_counter]=c;
-                    ci_counter++;
-//                  MyThis->pc->printf(" parcial CI -%s- -%c-(%c) -%d- \n",Cs,c,Cs[ci_counter],ci_counter);
-                }
+                Cs[ci_counter]=c;
+                ci_counter++;
             }
         }
+    }
 
-        if(ret==NULL) {
-            VarStore::MyThis->pc->printf(" error setting/getting var \n");
-            ret=STR_OK;
-        }
-        //Thread::wait(10);
- //   } // While
+    if(ret==NULL) {
+        VarStore::MyThis->pc->puts(" error setting/getting var \n");
+        ret=STR_OK;
+    }
+
 }
 
 /*******************************
@@ -173,21 +166,18 @@
 *
 ********************************/
 
- VarStore *VarStore::MyThis=NULL;   // used by the worker reading the terminal. Need to be initilized this way to avoid
-                                    // compiling errors
+VarStore *VarStore::MyThis=NULL;   // used by the worker reading the terminal. Need to be initilized this way to avoid
+// compiling errors
 void VarStore::Worker(void const *args)
 {
 
-    
-    
     VarStore::MyThis=(VarStore *)args;
 
-    VarStore::MyThis->pc->printf(" hi worker 1\n");
-    
+//  cuidado puts VarStore::MyThis->pc->(" hi worker 1\n");
+
     VarStore::MyThis->pc->attach(&Worker2);
 
     while(1) {
-        VarStore::MyThis->pc->printf(" hi worker 1\n");
         Thread::wait(1000);
     }
 
@@ -206,10 +196,15 @@
             case 's':
                 return VarStore::MyThis->Set(str);
             case 'd':
-                strtok(str,":");
-                ret=VarStore::MyThis->Get(strtok(NULL,":"));
+
+                ret=strtok(str,":");
+                ret=strtok(NULL,":");
+                
+                ret=VarStore::MyThis->Get(ret);
+             
                 if(ret!=NULL) {
-                    VarStore::MyThis->pc->printf("%s (%s)\n",str,ret);
+                  //  cuidado puts VarStore::MyThis->pc->printf("%s (%s)\n",str,ret);
+                  VarStore::MyThis->pc->puts("el del mostrar variable");
                     return ret;
                 } else
                     return NULL;