Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
18:55f1581f2ee4
Parent:
16:744ce85aede2
Child:
21:ce51bb0ba4a5
--- a/SnCommWin.cpp	Wed Sep 12 22:50:25 2012 +0000
+++ b/SnCommWin.cpp	Sat Sep 29 04:54:15 2012 +0000
@@ -238,6 +238,9 @@
         pow.SizeOf(SnPowerFrame::kIOvers));
     pow.WriteTo(b);
     int msiz = b-genBuf;
+#ifdef DEBUG
+    printf("calling SendAll\r\n");
+#endif
     int mlen = SendAll(genBuf, msiz, timeout_clock);
 #ifdef DEBUG
     printf("status frame:\r\n");
@@ -309,6 +312,11 @@
     printf("Sending block hc %02x, len=%u\r\n",blockHeaderCode,blockSize+SnHeaderFrame::SizeOf());
 #endif
     return SendAll(genBuf, blockSize+SnHeaderFrame::SizeOf(), timeout);
+    /*
+    const int rt = SendAll(genBuf, blockSize+SnHeaderFrame::SizeOf(), timeout);
+    wait_ms(10);
+    return rt;
+    */
 }                             
 
 SnCommWin::ECommWinResult SnCommWin::SendFileContents(FILE* inf,
@@ -365,17 +373,19 @@
         uint32_t evtsSent=0, powsSent=0;
 
         // now just loop through file and send each block
-        while (    ok
+        bool fok = true;
+        while (    fok
                 && (feof(inf)==0)
                 && (ferror(inf)==0)
                 && ((ftell(inf)+SnHeaderFrame::SizeOf())<=fend) ) {
             // read the header for the block
             SnSDUtils::ReadBlockHeader(inf, hcode, hlen);
+            fok &= (ftell(inf)+hlen)<=fend;
 #ifdef DEBUG
-            printf("new block: hc=%02x, hl=%u, ftell=%d, fend=%d\r\n",
-                hcode, hlen, ftell(inf), fend);
+            printf("new block: hc=%02x, hl=%u, ftell=%d, fend=%d, "
+                "ok=%d, fok=%d\r\n",
+                hcode, hlen, ftell(inf), fend, (int)ok, (int)fok);
 #endif
-            ok &= (ftell(inf)+hlen)<=fend;
             if (ok) {
                 // send the block
                 // TODO: repack events?
@@ -418,6 +428,10 @@
         msiz = b - genBuf;
         mlen = SendAll(genBuf, msiz, timeout_clock);
         ok &= msiz==mlen;
+
+#ifdef DEBUG
+        printf("ok=%d (msiz=%d, mlen=%d)\r\n", (int)ok, msiz, mlen);
+#endif
         
         // send number of power readings sent
 #ifdef DEBUG
@@ -430,6 +444,9 @@
         mlen = SendAll(genBuf, msiz, timeout_clock);
         ok &= msiz==mlen;
         
+#ifdef DEBUG
+        printf("ok=%d (msiz=%d, mlen=%d)\r\n", (int)ok, msiz, mlen);
+#endif
     }