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:
7:fafe81a95c08
Parent:
6:9848fdaf2ad9
Child:
8:934ec53fe2c0
--- a/VarStore.cpp	Mon Aug 25 15:38:31 2014 +0000
+++ b/VarStore.cpp	Mon Aug 25 17:55:39 2014 +0000
@@ -3,6 +3,7 @@
 #include  <stdio.h>
 #include "mbed.h"
 #include "rtos.h"
+#include "SerialBase.h"
 
 extern "C" void mbed_reset();
 
@@ -17,9 +18,7 @@
 VarStore::VarStore(Serial *ser)
 {
     VarCounter=0;
-    this->pc=ser;
-// doesn't work....  Thread thread(VarStore::Worker,this,osPriorityNormal,DEFAULT_STACK_SIZE,NULL);
- 
+    this->pc=ser; 
 }
 
 /*******************************
@@ -42,7 +41,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,":");
@@ -115,17 +114,24 @@
 *
 ********************************/
 
-void VarStore::Worker2()
+void Worker2();
+
+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';
 
-//   MyThis->pc->printf(" hi worker\n");
+   VarStore::MyThis->pc->printf(" hi worker 2\n");
+   
+ 
  //   while (1) {
         if(VarStore::MyThis->pc->readable()) {
             c=VarStore::MyThis->pc->getc();
@@ -139,7 +145,7 @@
                 if(c=='\r') {
                     Cs[ci_counter]='\0';
 //                    MyThis->pc->printf(" CI -%s- \n",Cs);
-                    ret=VarStore::MyThis->Do(Cs,MyThis);
+                    ret=VarStore::MyThis->Do(Cs);
                     ci_counter=0;
                     Cs[0]='\0';
                     //                 MyThis->pc->printf(" set variable (%d)\n",ret);
@@ -172,11 +178,16 @@
 void VarStore::Worker(void const *args)
 {
 
+    
+    
     VarStore::MyThis=(VarStore *)args;
 
-    VarStore::MyThis->pc->attach(VarStore::Worker2);
+    VarStore::MyThis->pc->printf(" hi worker 1\n");
+    
+    VarStore::MyThis->pc->attach(&Worker2);
 
     while(1) {
+        VarStore::MyThis->pc->printf(" hi worker 1\n");
         Thread::wait(1000);
     }
 
@@ -186,7 +197,7 @@
 *
 ********************************/
 
-char  *VarStore::Do(char *str, VarStore* MyThis)
+char  *VarStore::Do(char *str)
 {
     char *ret;
     if(str != NULL) {