Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
0:664899e0b988
Child:
1:e392595b4b76
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SnStatusFrame.h	Sat Jun 30 02:03:51 2012 +0000
@@ -0,0 +1,82 @@
+#ifndef SN_SnStatusFrame
+#define SN_SnStatusFrame
+
+#include <stdint.h>
+
+#include "SnBitUtils.h"
+#include "SnCommWin.h"
+#include "SnConfigFrame.h"
+#include "SnEventFrame.h"
+
+struct SnStatusFrame {
+    //
+    // A simple struct (everything public) to function like namespace.
+    // The contents of the status frame are sent from here, in order to
+    // help make sure the status frame is the same for each comm method.
+    //
+    // No member variables are used in order to preserve memory on the mbed.
+    // (i.e. no actual status frame middle-man object exists)
+    //
+    
+    static const uint8_t    kIOVers;    // MUST BE INCREASED if bytes written/read change!!
+    
+    static const uint32_t   kMaxSizeOf =
+               1u + sizeof(uint64_t)
+            + (sizeof(uint32_t)*3u) + (sizeof(uint16_t))
+            + (sizeof(uint8_t)*3u) + SnConfigFrame::kConfLblLen
+            + SnEventFrame::kMaxSizeOf;
+    
+    template<class T>
+    static
+    SnCommWin::ECommWinResult WriteTo(T x,
+                                      const SnConfigFrame::EDatPackBit type,
+                                      const SnConfigFrame& conf,
+                                      const SnEventFrame& evt,
+                                      char* const evtBuf) {
+        // expect 'x' to be a MODSERIAL& or a char const*
+        
+        uint8_t loseLSB=0, loseMSB=0;
+        uint16_t wvBase=0;
+        conf.GetPackParsFor(type, loseLSB, loseMSB, wvBase);
+        
+        evt.WriteTo(evtBuf, loseLSB, loseMSB, wvBase);
+        const uint32_t llen = strlen(conf.GetLabel());
+        
+        // if anything about these writes changes, update kIOVers and SizeOf
+        SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
+        SnBitUtils::WriteTo(x, conf.GetMacAddress());
+        SnBitUtils::WriteTo(x, llen);
+        SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
+        SnBitUtils::WriteTo(x, conf.GetRun());
+        SnBitUtils::WriteTo(x, time(0));
+        SnBitUtils::WriteTo(x, loseLSB);
+        SnBitUtils::WriteTo(x, loseMSB);
+        SnBitUtils::WriteTo(x, wvBase);
+        SnBitUtils::WriteTo(x, evtBuf, evt.SizeOf(loseLSB, loseMSB));
+        
+        return SnCommWin::kOkMsgSent;
+    }
+        
+    static
+    uint32_t SizeOf(const uint32_t confLblLen,
+                    const uint8_t loseLSB, const uint8_t loseMSB) {
+        // number of bytes read/written during i/o
+        const uint32_t msz = kMaxSizeOf - SnConfigFrame::kConfLblLen 
+                           + confLblLen;
+        if ((loseLSB==0) && (loseMSB==0)) {
+            return msz;
+        } else {
+            return msz - SnEventFrame::kMaxSizeOf 
+                       + SnEventFrame::SizeOf(loseLSB, loseMSB);
+        }
+    }
+    
+    static
+    uint32_t SizeOf(const SnConfigFrame& conf) {
+        return SizeOf(conf.GetLabelStrLen(),
+                      conf.GetWvLoseLSB(), conf.GetWvLoseMSB());
+    }
+    
+};
+
+#endif // SN_SnStatusFrame