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 15:38:31 2014 +0000
Parent:
5:47b67a7c0bb7
Child:
7:fafe81a95c08
Commit message:
en modo gestion via interrupciones. Antes de hacer limpieza y preparar para publicacion

Changed in this revision

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/VarStore.cpp	Mon Aug 25 14:58:42 2014 +0000
+++ b/VarStore.cpp	Mon Aug 25 15:38:31 2014 +0000
@@ -19,7 +19,7 @@
     VarCounter=0;
     this->pc=ser;
 // doesn't work....  Thread thread(VarStore::Worker,this,osPriorityNormal,DEFAULT_STACK_SIZE,NULL);
-
+ 
 }
 
 /*******************************
@@ -42,7 +42,7 @@
     VarItem *V;
     char *Name;
 
-    pc->printf("VarStore Set %s\n",Input);
+  //  pc->printf("VarStore Set %s\n",Input);
     
     if(Input [0] == 's') {
         strtok(Input,":");
@@ -118,17 +118,17 @@
 void VarStore::Worker2()
 {
     
-    char c, *ret=STR_OK;// not NULL to start in no error state
+    static char c, *ret=STR_OK;// not NULL to start in no error state
     
-    int ci_counter=0;
-    char Cs[CI_SZ];
+    static int ci_counter=0;
+    static char Cs[CI_SZ];
 
 //    for(int i=0; i<CI_SZ; i++) Cs[i]='\0';
 
 //   MyThis->pc->printf(" hi worker\n");
-    while (1) {
-        if(MyThis->pc->readable()) {
-            c=MyThis->pc->getc();
+ //   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
                 ci_counter=0;
@@ -139,7 +139,7 @@
                 if(c=='\r') {
                     Cs[ci_counter]='\0';
 //                    MyThis->pc->printf(" CI -%s- \n",Cs);
-                    ret=MyThis->Do(Cs,MyThis);
+                    ret=VarStore::MyThis->Do(Cs,MyThis);
                     ci_counter=0;
                     Cs[0]='\0';
                     //                 MyThis->pc->printf(" set variable (%d)\n",ret);
@@ -155,17 +155,20 @@
         }
 
         if(ret==NULL) {
-            MyThis->pc->printf(" error setting/getting var \n");
+            VarStore::MyThis->pc->printf(" error setting/getting var \n");
             ret=STR_OK;
         }
         //Thread::wait(10);
-    } // While
+ //   } // While
 }
 
 /*******************************
 *
 *
 ********************************/
+
+ 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)
 {
 
@@ -174,7 +177,7 @@
     VarStore::MyThis->pc->attach(VarStore::Worker2);
 
     while(1) {
-        Thread::wait(10000);
+        Thread::wait(1000);
     }
 
 }
@@ -190,12 +193,12 @@
 
         switch(*str) {
             case 's':
-                return MyThis->Set(str);
+                return VarStore::MyThis->Set(str);
             case 'd':
                 strtok(str,":");
-                ret=MyThis->Get(strtok(NULL,":"));
+                ret=VarStore::MyThis->Get(strtok(NULL,":"));
                 if(ret!=NULL) {
-                    MyThis->pc->printf("%s (%s)\n",str,ret);
+                    VarStore::MyThis->pc->printf("%s (%s)\n",str,ret);
                     return ret;
                 } else
                     return NULL;
--- a/VarStore.h	Mon Aug 25 14:58:42 2014 +0000
+++ b/VarStore.h	Mon Aug 25 15:38:31 2014 +0000
@@ -59,7 +59,7 @@
 
     static    void Worker(void const *args);
 
-
+   
 
 protected:
 
@@ -91,9 +91,11 @@
     VarItem Store[SZ];
     int VarCounter;
     Serial *pc;
-    static VarStore *MyThis;   // used by the worker reading the terminal
-
+    
+    static VarStore *MyThis;   // used by the workers reading the terminal
 
 };
 
+
+
 #endif // VARSTORE_H