Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
16:744ce85aede2
Parent:
15:f2569d8e4176
Child:
18:55f1581f2ee4
--- a/SnCommWin.cpp	Fri Aug 31 02:09:09 2012 +0000
+++ b/SnCommWin.cpp	Wed Sep 12 04:47:22 2012 +0000
@@ -6,14 +6,29 @@
 #include "SnPowerFrame.h"
 #include "SnStatusFrame.h"
 #include "SnSDUtils.h"
+#include "SnConstants.h"
+
+//#define DEBUG
+
+uint32_t SnCommWin::GetConnectTimeout() const { return kConnectTimeout; }
+uint32_t SnCommWin::GetListenTimeout() const { return kListenTimeout; }
 
 bool SnCommWin::IsTimedOut(const uint32_t timeout_clock) const {
-    if ( timeout_clock > 0 ) {
-        if (time(0)>timeout_clock) {
+    if (timeout_clock==0) {
+        // for not obeying timeout option
+        return false;
+    } else {
+        const uint32_t ct = time(0);
+        if ( (ct==0) ||
+             (abs(static_cast<double>(timeout_clock-ct))>kSecsPerDay) ) {
+            // clock problems!
+            // timeout now. hope the clock problems
+            // get fixed in the next comm window
             return true;
+        } else {
+            return (ct>timeout_clock);
         }
     }
-    return false;
 }
 
 SnCommWin::ECommWinResult SnCommWin::SendData(SnConfigFrame& conf,
@@ -49,7 +64,7 @@
                                       conf.GetCommSendData() // send N events
                                       : 0u; // send all events in last file
 #ifdef DEBUG
-                printf("calling SendData. f=%x, nev=%u\r\n",SnSDUtils::GetCurFile(), nev);
+                printf("calling SendData. f=%s, nev=%u\r\n",SnSDUtils::GetCurFileName(), nev);
 #endif
                 res = SendData(SnSDUtils::GetCurFile(), SnSDUtils::GetCurFileName(),
                                conf, evt, pow, genBuf, bsize, nev, timeout, handshakeTimeout);
@@ -84,6 +99,7 @@
 #ifdef DEBUG
         printf("sending file name %s\r\n",infn);
 #endif
+
         // send the file name
         res = SendFilename(infn, genBuf, timeout_clock);
         if (res>kAllFails) {
@@ -91,6 +107,7 @@
 #ifdef DEBUG
                 printf("calling send file contents\r\n");
 #endif
+
                 // send the contents
                 res = SendFileContents(inf, curConf, evt, pow, genBuf,
                                        nevts, timeout_clock);
@@ -180,7 +197,7 @@
 #endif
             if (mcode==SnHeaderFrame::kNoConfigCode) {
                 // no config to get
-                res = SnCommWin::kOkWithMsg;
+                res = SnCommWin::kOkWthMsgNoConf;
             } else if (mcode!=SnHeaderFrame::kConfigCode) {
                 res = SnCommWin::kUnexpectedRec;
             } else {
@@ -189,13 +206,13 @@
                 if (clen>0 && static_cast<uint32_t>(clen)==mlen) {
                     b = confBuf;
                     conf.ReadFrom(b);
-                    res = SnCommWin::kOkWthMsgNoConf;
+                    res = SnCommWin::kOkWithMsg;
                 } else {
                     res = SnCommWin::kUnexpectedRec;
                 }
             }
         } else {
-            res = SnCommWin::kUnexpectedRec;
+            res = SnCommWin::kOkNoMsg;
         }
     }
     return res;
@@ -239,6 +256,9 @@
                        conf.GetWvLoseLSB(), conf.GetWvLoseMSB()));
         evt.WriteTo(b, conf.GetWvLoseLSB(), conf.GetWvLoseMSB(),
                     conf.GetWvBaseline());
+#ifdef DEBUG
+        printf("sending event\r\n");
+#endif        
         return SnCommWin::kOkMsgSent;
     }
     return SnCommWin::kFailPartSent;
@@ -250,6 +270,7 @@
 #ifdef DEBUG
     printf("SnCommWin::SendFilename %s\r\n",inf);
 #endif
+
     // remove the directory
     const char* fn = strrchr(inf, '/');
     if (fn==0) {