Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Revision:
1:e392595b4b76
Parent:
0:664899e0b988
Child:
3:24c5f0f50bf1
--- a/SnStatusFrame.h	Sat Jun 30 02:03:51 2012 +0000
+++ b/SnStatusFrame.h	Fri Jul 20 19:04:02 2012 +0000
@@ -1,82 +1,99 @@
-#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
+#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);
+        
+        const uint32_t llen = strlen(conf.GetLabel());
+        
+        // if anything about these writes changes, update kIOVers and SizeOf
+        x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
+        x = SnBitUtils::WriteTo(x, conf.GetMacAddress());
+        x = SnBitUtils::WriteTo(x, llen);
+        x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
+        x = SnBitUtils::WriteTo(x, conf.GetRun());
+        x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0)));
+        x = SnBitUtils::WriteTo(x, loseLSB);
+        x = SnBitUtils::WriteTo(x, loseMSB);
+        x = SnBitUtils::WriteTo(x, wvBase);
+        x = WriteEventTo(x, evtBuf, evt, 
+                         loseLSB, loseMSB, wvBase);
+        
+        return SnCommWin::kOkMsgSent;
+    }
+    
+    static
+    MODSERIAL& WriteEventTo(MODSERIAL& x, char* const evtBuf, const SnEventFrame& evt,
+                            const uint8_t loseLSB, const uint8_t loseMSB,
+                            const uint16_t wvBase) {
+        evt.WriteTo(evtBuf, loseLSB, loseMSB, wvBase);
+        x = SnBitUtils::WriteTo(x, evtBuf, evt.SizeOf(loseLSB, loseMSB));
+        return x;
+    }
+    
+    static
+    char* WriteEventTo(char* const x, char* const evtBuf, const SnEventFrame& evt,
+                       const uint8_t loseLSB, const uint8_t loseMSB,
+                       const uint16_t wvBase) {
+        evt.WriteTo(x, loseLSB, loseMSB, wvBase);
+        return x;
+    }
+    
+    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