Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
6:6f002d202f59
Parent:
5:9cea89700c66
Child:
7:079617408fec
--- a/SnSDUtils.cpp	Fri Aug 03 00:04:34 2012 +0000
+++ b/SnSDUtils.cpp	Fri Aug 03 23:50:57 2012 +0000
@@ -54,14 +54,23 @@
     DIR* d;
     struct dirent* dent;
     
-    uint16_t seq=0;
+    uint16_t seq=0, newseq=0;
     if ( (d = opendir( kSDsubDir ))!=NULL ) {
         // don't compare seq#. don't use num of chars in case seq is >999
         const uint32_t ncomp = strrchr(fn, 's') - fn;
         while ( (dent = readdir(d))!=NULL ) {
             if (strncmp(dent->d_name, fn, ncomp)==0) {
-                seq++;
+                // allow for deleted files to make gaps.
+                // search for highest seq number and increase that
+                sscanf(fn+ncomp,"s%hu.dat",&seq);
                 if (seq==__kMaxUShort) {
+                    newseq = seq;
+                    break;
+                }
+                if (seq>=newseq) {
+                    newseq=seq+1;
+                }
+                if (newseq==__kMaxUShort) {
                     break;
                 }
             }
@@ -69,7 +78,7 @@
         closedir(d);
     }
     
-    return seq;
+    return newseq;
 }
 
 FILE* SnSDUtils::OpenExistingFile(const char* name, const bool setcurrent) {
@@ -138,7 +147,9 @@
                                                   const bool doDelete,
                                                   const uint32_t timeout,
                                                   char* const buf,
-                                                  const uint32_t bsize) {
+                                                  const uint32_t bsize,
+                                                  const SnConfigFrame& curConf,
+                                                  SnEventFrame& evt) {
     
     DIR* d;
     struct dirent* dent;
@@ -157,22 +168,9 @@
                 } else {
                     f = OpenExistingFile(dent->d_name, false);
                 }
-                // send the filename
-                rs = comm->SendFilename(dent->d_name, buf);
-                if (rs<SnCommWin::kAllFails) {
-                    // send the data from the file
-                    rs = comm->SendData(f);
-                    if (rs<SnCommWin::kAllFails) {
-                        break;
-                    } else {
-                        // wait for handshake before next file
-                        rs = comm->WaitHandshake(timeout, buf, bsize);
-                        if ((rs==SnCommWin::kOkWithMsg) 
-                             && doDelete && (isCurFile==false)) {
-                            DeleteFile(f, dent->d_name);
-                        }
-                    }
-                }
+                rs = comm->SendData(f, dent->d_name,
+                                    curConf, evt, buf, bsize,
+                                    0, timeout, 0);
                 if (isCurFile) {
                     // move (back) to the end of the file
                     // altho hopefully no writing will happen after this