xrocusOS_ADXL355 version

Dependencies:   mbed SDFileSystem

Revision:
16:602bc04e3cb5
Parent:
10:db2be22bc2f9
--- a/common/SDDataStore.cpp	Mon May 27 08:17:29 2019 +0000
+++ b/common/SDDataStore.cpp	Thu May 30 03:00:15 2019 +0000
@@ -1,4 +1,5 @@
 #include "SDDataStore.h"
+#include "global.h"
 
 /* constructor, pSD, TimeManager */
 SDDataStore::SDDataStore(TimeManager *pSetTM)
@@ -64,11 +65,12 @@
     sprintf(filePath, "/sd/%s", fname);
     pathTermination(filePath);
     
-    fp = fopen(filePath, "w");
+    fp = fopen(filePath, "a+");
     if (fp == NULL) {
         return false;
     }
     fpCurrent = fp;
+    dbgprintf("SDDataStore::openFile(%p) as %s\n", fpCurrent, filePath);
     sprintf(fnameCurrent, "%s", fname);
     return true;
 }
@@ -88,14 +90,27 @@
 /* close file with this Class  */
 void SDDataStore::syncFile(void)
 {
+    FILE *fp;
+    char filePath[MaxPathLength];
+    sprintf(filePath, "/sd/%s", getFileName());
+    
+    dbgprintf("SDDataStore::syncFile(%p) as %s\n", fpCurrent, filePath);
     if (fpCurrent != NULL) {
-        fflush(fpCurrent);
+        /* fflush is not working on SDFileSystem :p */
+        fclose(fpCurrent);
+        fp = fopen(filePath, "a+");
+        if (fp == NULL) {
+            dbgprintf("SDDataStore::syncFile(CRITICAL) in fopen\n");
+            return;
+        }
+        fpCurrent = fp;
     }
 }
 
 /* close file with this Class  */
 void SDDataStore::closeFile(void)
 {
+    dbgprintf("SDDataStore::closeFile(%p)\n", fpCurrent);
     if (fpCurrent != NULL) {
         fclose(fpCurrent);
         fpCurrent = NULL;