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.

Files at this revision

API Documentation at this revision

Comitter:
julmbed
Date:
Mon Aug 25 19:54:12 2014 +0000
Parent:
7:fafe81a95c08
Child:
9:d081aa4e4418
Commit message:
con rawserial y sin avanzar en dump de las variables

Changed in this revision

VarItems.cpp Show annotated file Show diff for this revision Revisions of this file
VarItems.h Show annotated file Show diff for this revision Revisions of this file
VarStore.cpp Show annotated file Show diff for this revision Revisions of this file
VarStore.h Show annotated file Show diff for this revision Revisions of this file
--- a/VarItems.cpp	Mon Aug 25 17:55:39 2014 +0000
+++ b/VarItems.cpp	Mon Aug 25 19:54:12 2014 +0000
@@ -71,12 +71,6 @@
 
 }
 
-/******
-void   VarItem::SetVarType(VarTypes VarType)
-{
-    this->VarType=VarType;
-}
-*******/
 
 void VarItem::SetVarArraySize(int Size)
 {
@@ -93,7 +87,7 @@
 
 char *VarItem::Dump()
 {
-
+pc.puts(" 0 \n");
     static char *StrDump=NULL;
 
     unsigned int DumpSize=0;
@@ -106,6 +100,7 @@
     StrDump=(char *)malloc(DumpSize);
     memset(StrDump,0,DMP_SZ);
 
+pc.puts(" 1 \n");
     do {
         switch(VarType) {
             case T_int:
@@ -115,6 +110,7 @@
                 sprintf(Tmp,"%f,",*(ValFloat+ArrayCounter));
                 break;
         };
+pc.puts(" 2 \n");
         if(DumpCounter+strlen(Tmp) >= DumpSize) {
             char *d;
             DumpSize = DumpCounter+DMP_SZ;
@@ -123,6 +119,7 @@
             free(StrDump);
             StrDump=d;
         }
+pc.puts(" 3 \n");
         strcat(StrDump+DumpCounter,Tmp);
         DumpCounter+=strlen(Tmp);
         ArrayCounter++;
--- a/VarItems.h	Mon Aug 25 17:55:39 2014 +0000
+++ b/VarItems.h	Mon Aug 25 19:54:12 2014 +0000
@@ -24,8 +24,8 @@
     char *Dump();
     char *GetVarName();
 
-protected:
-private:
+//protected:
+//private:
 
     char VarName[VAR_NAME_LEN];
 
@@ -33,6 +33,9 @@
     float *ValFloat;
     VarTypes VarType;
     unsigned int ArraySize;
+
+protected:
+private:
 };
 
 #endif // VARITEMS_H
--- 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;
--- a/VarStore.h	Mon Aug 25 17:55:39 2014 +0000
+++ b/VarStore.h	Mon Aug 25 19:54:12 2014 +0000
@@ -2,9 +2,11 @@
 #define VARSTORE_H
 
 #include "mbed.h"
+
+
+
 #include "VarItems.h"
 
-
 #define SZ 10
 #define STR_OK ""
 
@@ -19,7 +21,7 @@
     *Constructor
     ********************************/
 
-    VarStore(Serial *ser);
+    VarStore(   RawSerial *ser);
     /*******************************
     *
     *Destructor
@@ -93,7 +95,7 @@
     ********************************/
     VarItem Store[SZ];
     int VarCounter;
-    Serial *pc;
+        RawSerial  *pc;
     
     static VarStore *MyThis;   // used by the workers reading the terminal