julian C / VarStore

Files at this revision

API Documentation at this revision

Comitter:
julmbed
Date:
Mon Aug 25 20:44:39 2014 +0000
Parent:
8:934ec53fe2c0
Child:
10:34d368966675
Commit message:
workin with rawserial and without malloc. dump string limited to 132 chars

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
--- a/VarItems.cpp	Mon Aug 25 19:54:12 2014 +0000
+++ b/VarItems.cpp	Mon Aug 25 20:44:39 2014 +0000
@@ -4,9 +4,9 @@
 #include <stdio.h>
 #include "mbed.h"
 
-extern Serial pc;
+extern RawSerial pc;
 
-#define DMP_SZ 100
+#define DMP_SZ 132
 
 
 VarItem::VarItem()
@@ -87,20 +87,13 @@
 
 char *VarItem::Dump()
 {
-pc.puts(" 0 \n");
-    static char *StrDump=NULL;
-
-    unsigned int DumpSize=0;
+    static char StrDump[DMP_SZ];
+    unsigned int DumpSize=DMP_SZ;
     unsigned int  DumpCounter=0, ArrayCounter=0;;
     char Tmp[16];
-
-    if(StrDump!=NULL) free(StrDump);
-
-    DumpSize=DMP_SZ;
-    StrDump=(char *)malloc(DumpSize);
+    
     memset(StrDump,0,DMP_SZ);
 
-pc.puts(" 1 \n");
     do {
         switch(VarType) {
             case T_int:
@@ -110,16 +103,17 @@
                 sprintf(Tmp,"%f,",*(ValFloat+ArrayCounter));
                 break;
         };
-pc.puts(" 2 \n");
         if(DumpCounter+strlen(Tmp) >= DumpSize) {
+            /*
             char *d;
             DumpSize = DumpCounter+DMP_SZ;
             d=(char *)malloc(DumpCounter+DMP_SZ);
             strcpy(d,StrDump);
             free(StrDump);
             StrDump=d;
+            */
+            break;
         }
-pc.puts(" 3 \n");
         strcat(StrDump+DumpCounter,Tmp);
         DumpCounter+=strlen(Tmp);
         ArrayCounter++;
--- a/VarItems.h	Mon Aug 25 19:54:12 2014 +0000
+++ b/VarItems.h	Mon Aug 25 20:44:39 2014 +0000
@@ -24,8 +24,8 @@
     char *Dump();
     char *GetVarName();
 
-//protected:
-//private:
+protected:
+private:
 
     char VarName[VAR_NAME_LEN];
 
@@ -34,8 +34,6 @@
     VarTypes VarType;
     unsigned int ArraySize;
 
-protected:
-private:
 };
 
 #endif // VARITEMS_H
--- a/VarStore.cpp	Mon Aug 25 19:54:12 2014 +0000
+++ b/VarStore.cpp	Mon Aug 25 20:44:39 2014 +0000
@@ -99,25 +99,11 @@
 
 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];
-
-  //  int   *ValInt;
-  //  float *ValFloat;
-  //  VarTypes VarType;
-  //  unsigned int ArraySize;
- //   if(V!=NULL) return V->Dump();
- //   else
-     VarStore::MyThis->pc->puts(" despues de dump ");
+    if(V!=NULL)
+     return V->Dump();
+    else
         return NULL;
 }
 
@@ -197,14 +183,17 @@
                 return VarStore::MyThis->Set(str);
             case 'd':
 
+                VarStore::MyThis->pc->puts(str);
+                VarStore::MyThis->pc->putc('\n');
+                
                 ret=strtok(str,":");
                 ret=strtok(NULL,":");
                 
                 ret=VarStore::MyThis->Get(ret);
              
                 if(ret!=NULL) {
-                  //  cuidado puts VarStore::MyThis->pc->printf("%s (%s)\n",str,ret);
-                  VarStore::MyThis->pc->puts("el del mostrar variable");
+                  VarStore::MyThis->pc->puts(ret);
+                  VarStore::MyThis->pc->putc('\n');
                     return ret;
                 } else
                     return NULL;