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
Child:
14:6cbe8366d587
--- a/VarStore.h	Tue Aug 26 08:20:02 2014 +0000
+++ b/VarStore.h	Tue Aug 26 09:09:01 2014 +0000
@@ -1,105 +1,151 @@
 #ifndef VARSTORE_H
 #define VARSTORE_H
-
 #include "mbed.h"
-
-
-
 #include "VarItems.h"
 
-#define SZ 20
 #define STR_OK ""
 
+/** VarStore Class
+*  Used for reading/modifying program variables
+*  from the console at runtime. Helpful for
+*  debugging.
+*  It has a facility as well to reset the mbed
+*  from the serial console without pressing  
+*  any button.
+*  It does not block the serial/input channel
+*  in case it is needed for other stuff
+*  
+* Example:
+* @code
+
+* #include "mbed.h"
+* #include "rtos.h"
+* #include "VarStore.h"
+*
+* #include <RawSerial.h>
+*
+* RawSerial  pc(USBTX,USBRX);  // Be aware !!!! need rawserial. No printf for you anymore !! 
+*                              // no malloc nither as this works in ISR
+*
+* VarStore Store(&pc,20);      // create storage for 20 variables/arrays attach to serial pc
+* 
+* DigitalOut led1(LED1);
+* DigitalOut led2(LED2);
+* 
+* void led2_thread(void const *args) {
+*    
+*    int wait2=1000;
+*    Store.Load("wait2",&wait2,T_int);   // load variable wait2 in Store
+*    
+*    while (true) {
+*        led2 = !led2;
+*        Thread::wait(wait2);  // remember, no WAIT, STOPS CPU FROM RUNNING WHOLE PROGRAM.
+                               // use Thread::wait to stop just your path of execution.
+*    }
+* }
+* 
+* int main() {
+*    
+*    int wait1=500;
+*    Store.Load("wait1",&wait1,T_int);  // Load variable wait1 in Store
+*    Thread VS_thread(VarStore::Worker,&Store,osPriorityNormal,DEFAULT_STACK_SIZE,NULL); // launch VarStore Thread
+*    
+*    Thread thread(led2_thread);
+*    
+*    while (true) {
+*        led1 = !led1;
+*        Thread::wait(wait1); // remember, no WAIT, STOPS CPU FROM RUNNING WHOLE PROGRAM.
+*                              // use Thread::wait to stop just your path of execution.
+*    }
+* }
+*
+* @endcode
+*
+*
+*
+*
+*/
 class VarStore
 {
     
  
 // friend    void Worker2();
 public:
-    /*******************************
-    *
-    *Constructor
-    ********************************/
-
+    /*
+    * Constructor        
+    */
     VarStore(   RawSerial *ser, int sz);
-    /*******************************
-    *
-    *Destructor
-    ********************************/
-
+    
+    /*
+    * destr        
+    */
     virtual ~VarStore();
-    /*******************************
-    *
-    *asigna valor a una variable/array o retorna ERR
-    ********************************/
-
+    
+    /* assigns (a) value(s) to a variable or array        
+    */
     char * Set(char *Input);
 
-    /*******************************
-    *
-    *devuelve en un string el contenido de una variable
-    ********************************/
-
+    /*Get contents of a variable as a string
+    */
     char*  Get(char *Name);
 
-    /*******************************
-    *carga en el store una variable
+    /** Load a variable on VarStore
     *
-    ********************************/
-
+    * @param Name string that will be used to query/set the value of the variable/array
+    * @param VarPtr pointer to variable 
+    * @param VarType enumerated type indicating int/float ( only supported currently) enum VarTypes {T_int,T_float};
+    *
+    * @returns ERR on error / NULL on success
+    */
     int Load(char *Name, void *VarPtr,VarTypes VarType );
 
-    /*******************************
+    /** Load an array on VarStore
     *
-    *carga en el store una variable/array
-    ********************************/
-
+    * @param Name string that will be used to query/set the value of the variable/array
+    * @param VarPtr pointer to base of array
+    * @param VarType enumerated type indicating int/float ( only supported currently) enum VarTypes {T_int,T_float};
+    * @param Size number of elements in the array
+    *
+    * @returns ERR on error / NULL on success
+    */
     int Load(char *Name, void *VarPtr,VarTypes VarType, int Size );
 
-    /*******************************
-    * Proceso que less del un serial para modificar
-    * los valores de las variables.
+
+
+   /** Thread that will manage the concole interaction. Main role is to remain sleeping 
+    * and only awakening to fire worker2 to deal with console input
     *
-    ********************************/
-
- //   static    void Worker(void const *args);
- static    void Worker(void const *args);
+    * @param args pointer to the VarStore Object that will be managing.
+    *
+    * @returns ERR on error / NULL on success
+    */
+    static  void Worker(void const *args);
    
 
 protected:
 
 private:
-    /*******************************
-    * Busca una variable con nombre name.
-    *
-    ********************************/
-
+    /* Get variable item by name
+    */
     VarItem *GetVar(char *name);
 
-    /*******************************
-    * Llamado por worker para
-    * llevar a cabo la acción
-    *
-    ********************************/
+    /* do stuff with console input
+    */
     char  *Do(char *str);
     
-    /*******************************
-    *Para hacer gestión via interrupciones.
-    *
-    ********************************/
+    /* manages console input
+    */
     static void Worker2();
     
-    /*******************************
-    *
-    *
-    ********************************/
+   
     VarItem *Store;
     int sz;         // number of varibales to store / array size
     int VarCounter;
     RawSerial  *pc;
 
     static VarStore *MyThis;   // used by the workers reading the terminal
-
+                               // instantiation via a static fucntion so need to record
+                               // who am I 
 };