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:
13:e1ba5bf9e51f
Parent:
12:e9c8d2d9ac71
--- a/VarStore.cpp	Tue Aug 26 08:20:02 2014 +0000
+++ b/VarStore.cpp	Tue Aug 26 09:09:01 2014 +0000
@@ -11,34 +11,26 @@
 
 #define CI_SZ 100
 
-/*******************************
-*
-*
-********************************/
+/* Constructor
+*/
 VarStore::VarStore(     RawSerial *ser, int sz)
 {
     VarCounter=0;
     this->pc=ser;
     this->sz=sz;
-    //Store=(VarItem *) malloc( sizeof(VarItem)*sz);
+    //Store=(VarItem *) malloc( sizeof(VarItem)*sz); doesn't work
     Store=new VarItem[sz];
 }
 
-/*******************************
-*
-*
-********************************/
-
+/* destructor
+*/
 VarStore::~VarStore()
 {
     //dtor
 }
 
-/*******************************
-*
-*
-********************************/
-
+/* destructor
+*/
 char *VarStore::Set(char *Input)
 {
     VarItem *V;
@@ -55,46 +47,40 @@
     return NULL;
 }
 
-/*******************************
-*
-*
-********************************/
 
-
+/*
+************************
+*/
 int VarStore::Load(char *Name, void *VarPtr,VarTypes VarType )
 {
     return Load(Name, VarPtr,VarType,0 );
 }
 
-/*******************************
-*
-*
-********************************/
-
+/*
+************************
+*/
 int VarStore::Load(char *Name, void *VarPtr,VarTypes VarType, int Size )
 {
-    pc->puts("Entro en Load \n");
+   
     if(GetVar(Name) ==NULL) {
-        pc->puts("variable no esta \n");
+        
         if(VarCounter < sz) {
-            pc->puts("incorporo variable a Store \n");
+           
             Store[VarCounter].SetVar(VarType,VarPtr);
             Store[VarCounter].SetVarName(Name);
             Store[VarCounter].SetVarArraySize(Size);
             VarCounter++;
-            pc->puts("salgo por NULL \n");
+          
             return NULL;
         }
     }
-    pc->puts("salgo por error \n");
+  
     return ERR;
 }
 
-/*******************************
-*
-*
-********************************/
-
+/*
+************************
+*/
 VarItem *VarStore::GetVar(char *Name)
 {
     for (int i=0; i<sz; i++)
@@ -104,6 +90,9 @@
     return NULL;
 }
 
+/*
+************************
+*/
 char*  VarStore::Get(char *Name)
 {
     VarItem *V;
@@ -114,12 +103,9 @@
         return NULL;
 }
 
-/*******************************
-*
-*
-********************************/
-
-
+/*
+************************
+*/
 void VarStore::Worker2()
 {
 
@@ -130,64 +116,60 @@
     if(VarStore::MyThis->pc->readable()) {
         c=VarStore::MyThis->pc->getc();
 
-        if(ci_counter >= CI_SZ-1) {   // RESET
+        if(ci_counter >= CI_SZ-1) {   // RESET too much input
             ci_counter=0;
             Cs[0]='\0';
         } else {
-            if(c=='\r') {
+            if(c=='\r') {             // got a command lets see whan can be done
                 Cs[ci_counter]='\0';
                 ret=VarStore::MyThis->Do(Cs);
                 ci_counter=0;
                 Cs[0]='\0';
-            } else {
+            } else {                 // no command yet, let's keep recording.
                 Cs[ci_counter]=c;
                 ci_counter++;
             }
         }
     }
 
-    if(ret==NULL) {
+    if(ret==NULL) {  // ups.....
         VarStore::MyThis->pc->puts(" error setting/getting var \n");
         ret=STR_OK;
     }
 
 }
 
-/*******************************
-*
-*
-********************************/
-
+/*
+** nuisances for mixing threads/static members etc
+*/
 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;
-
-//  cuidado puts VarStore::MyThis->pc->(" hi worker 1\n");
-
     VarStore::MyThis->pc->attach(&VarStore::Worker2);
-
     while(1) {
-        Thread::wait(1000);
+        Thread::wait(1000); // nothing to do here besides firing worker2 when input ready
     }
 
 }
-/*******************************
-*
-*
-********************************/
-
+/*
+************************
+*/
 char  *VarStore::Do(char *str)
 {
     char *ret;
     if(str != NULL) {
 
         switch(*str) {
-            case 's':
+            case 's':  /// command s  s:varname:value or s:arrayname:value1,value2,value3  assign values at runtime
                 return VarStore::MyThis->Set(str);
-            case 'd':
+            case 'd':  /// command d  d:variablename dumps content of variable to screen/console.
 
                 VarStore::MyThis->pc->puts(str);
                 VarStore::MyThis->pc->putc('\n');
@@ -203,10 +185,10 @@
                     return ret;
                 } else
                     return NULL;
-            case 'r':
+            case 'r':   /// command r resets the mbed. If you previously downloaded a new version fo code, it will run.
                 mbed_reset();
                 return NULL;
-            case 'w':
+            case 'w':   ///  command w   waits a number of miliseconds releasing the input console to be used for other stuff temporarily
                 strtok(str,":");
                 Thread::wait(atoi(strtok(NULL,":")));
                 return STR_OK;