Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
116:8099b754fbb4
Parent:
98:ce72ef143b9b
Child:
122:c1b5023eac69
--- a/SnCommWin.cpp	Fri Dec 04 02:57:12 2015 +0000
+++ b/SnCommWin.cpp	Tue May 03 02:01:35 2016 +0000
@@ -46,9 +46,25 @@
     return (fComm!=0) ? (fComm->Connect(timeout)) : false;
 }
 
-bool SnCommWin::CloseConn(const uint32_t timeout) {
+bool SnCommWin::CloseConn(const uint32_t timeout,
+                          char* const genBuf/*=0*/,
+                          const bool sendCloseSignal/*=false*/) {
     Watchdog::kick(); // don't reset
-    return (fComm!=0) ? (fComm->CloseConn(timeout)) : false;
+    bool closeOk = false;
+    if (fComm!=0) {
+        if (sendCloseSignal && (genBuf!=0)) {
+            char* b = genBuf;
+            SnHeaderFrame::WriteTo(b, SnHeaderFrame::kCommSignOffCode, 0);
+            const uint32_t bytesToBeSent = b-genBuf;
+            const int32_t mlen = fComm->SendAll(genBuf, bytesToBeSent, timeout);
+            const int32_t flen = fComm->FinishSending(timeout);
+            closeOk = (bytesToBeSent==(mlen+flen));
+        } else {
+            closeOk = true;
+        }
+        closeOk &= fComm->CloseConn(timeout);
+    }
+    return closeOk;
 }
 
 bool SnCommWin::PowerDown(const uint32_t timeout) {
@@ -815,8 +831,9 @@
                                                 const SnPowerFrame& pow, // com win power
                                                 const SnEventFrame& stEvent,
                                                 const uint16_t seq,
-                                                const float thmrate,
-                                                const float evtrate,
+                                                const uint32_t numThmTrigs,
+                                                const uint32_t numSavedEvts, 
+                                                const float    seqlive,
                                                 const uint32_t powerOnTime,
                                                 const SnTempFrame& temper, // com win temp
                                                 char* const genBuf,
@@ -835,7 +852,8 @@
     const uint32_t ssize = SnStatusFrame::SizeOf(SnStatusFrame::kIOVers, conf);
     char* b = genBuf;
     SnHeaderFrame::WriteTo(b, SnHeaderFrame::kStatusCode, ssize);
-    SnStatusFrame::WriteTo(b, conf, stEvent, genBuf, seq, thmrate, evtrate, 
+    SnStatusFrame::WriteTo(b, conf, seq,
+                           numThmTrigs, numSavedEvts, seqlive,
                            powerOnTime, temper,
                            loseLSB, loseMSB, wvBase);
     SnHeaderFrame::WriteTo(b, SnHeaderFrame::kPowerCode, 
@@ -1061,10 +1079,15 @@
         sendNow   = b-genBuf;
         toBeSent += sendNow;
 #ifdef DEBUG
-        printf("calling SendAll (status update done)\r\n");
+        printf("calling SendAll (status pak done)\r\n");
+        printf("timed out = %s\r\n", (fComm->IsTimedOut(timeout_clock) ? "true" : "false"));
+        printf("time(0)=%u, timeout_clock=%u\r\n", time(0), timeout_clock);
 #endif
         byteSent += fComm->SendAll(genBuf, sendNow, timeout_clock);
         
+#ifdef DEBUG
+        printf("calling FinishSending (status pak done)\r\n");
+#endif
         // finish sending whatever didn't make it out
         byteSent += fComm->FinishSending(timeout_clock);
 
@@ -1075,6 +1098,8 @@
 
 #ifdef DEBUG
     printf("byteSent=%u, toBeSent=%u\r\n", byteSent, toBeSent);
+    printf("timed out = %s\r\n", (fComm->IsTimedOut(timeout_clock) ? "true" : "false"));
+    printf("time(0)=%u, timeout_clock=%u\r\n", time(0), timeout_clock);
 #endif
 
     if (byteSent==toBeSent) {