Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
21:ce51bb0ba4a5
Parent:
20:e5857b287b3b
Child:
22:f957c4f840ad
--- a/SnSDUtils.cpp	Wed Oct 03 00:22:27 2012 +0000
+++ b/SnSDUtils.cpp	Wed Oct 10 05:54:12 2012 +0000
@@ -2,6 +2,7 @@
 
 #include "mbed.h"
 #include "SDFileSystem.h"
+#include "FATDirHandle.h"
 #include <string.h>
 #include <string>
 
@@ -65,6 +66,7 @@
                               const uint32_t run) {
     // count the files having expected filename format
     
+    // fn points to a static buffer
     const char* fn = GetOutFileName(macadr, run, 0)
         + strlen(kSDsubDir) + 1; // take out dir and '/'s
     
@@ -86,10 +88,8 @@
                 // search for highest seq number and increase that
                 sscanf((dent->d_name)+ncomp,"s%hu.dat",&seq);
 #ifdef DEBUG
-                /*
                 printf("dn=%s, seq=%hu, __kMaxUShort=%hu\r\n",
                     dent->d_name, seq, __kMaxUShort);
-                */
 #endif
                 if (seq==__kMaxUShort) {
                     newseq = seq;
@@ -106,6 +106,9 @@
         closedir(d);
     }
 
+#ifdef DEBUG
+    printf("return newseq=%hu\r\n",newseq);
+#endif
     return newseq;
 }
 
@@ -169,6 +172,25 @@
     return fgCurFile;
 }
 
+void SnSDUtils::GetDirProps(const char* dirname,
+                            uint32_t& nfiles,
+                            float& totbytes) {
+    nfiles = 0;
+    totbytes = 0;
+    FATDirHandle* d = dynamic_cast<FATDirHandle*>( opendir(dirname) );
+    if (d!=0) {
+        while ( (readdir(d))!=NULL ) {
+            ++nfiles;
+            totbytes += d->filinfo()->fsize;
+        }
+        closedir(d);
+    }
+#ifdef DEBUG
+    printf("GetDirProps: %s :: nf=%u, tb=%u\r\n",
+        dirname, nfiles, totbytes);
+#endif
+}
+
 bool SnSDUtils::WriteEventTo(FILE* efile, char* const evtBuf,
                              const SnEventFrame& evt,
                              const SnConfigFrame& conf) {
@@ -195,7 +217,14 @@
 void SnSDUtils::DeleteFile(FILE*& f, const char* fname) {
     fclose(f);
     f=0;
-    remove(fname);
+    // make sure we're trying to delete a file off the SD card
+    std::string fn(fname);
+    if (strncmp(fname,kSDsubDir,strlen(kSDsubDir))!=0) {
+        fn  = kSDsubDir;
+        fn += "/";
+        fn += fname;
+    }
+    remove(fn.c_str());
 }
 
 SnCommWin::ECommWinResult SnSDUtils::SendAllFiles(SnCommWin* comm,
@@ -212,8 +241,6 @@
     
     SnCommWin::ECommWinResult rs  = SnCommWin::kOkMsgSent;
     
-    const bool doDelete = curConf.IsDeletingFiles();
-    
     if ( (d = opendir( kSDsubDir ))!=NULL ) {
         FILE* f;
         while ( (dent = readdir(d))!=NULL ) {