Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue Jul 31 04:59:16 2012 +0000
Revision:
3:24c5f0f50bf1
Parent:
1:e392595b4b76
Child:
8:95a325df1f6b
Test bench version. Communications not completed. Debugging output present. But will read the local config file and save events that can be used for testing.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 1:e392595b4b76 1 #ifndef SN_SnStatusFrame
uci1 1:e392595b4b76 2 #define SN_SnStatusFrame
uci1 1:e392595b4b76 3
uci1 1:e392595b4b76 4 #include <stdint.h>
uci1 1:e392595b4b76 5
uci1 1:e392595b4b76 6 #include "SnBitUtils.h"
uci1 1:e392595b4b76 7 #include "SnCommWin.h"
uci1 1:e392595b4b76 8 #include "SnConfigFrame.h"
uci1 1:e392595b4b76 9 #include "SnEventFrame.h"
uci1 1:e392595b4b76 10
uci1 1:e392595b4b76 11 struct SnStatusFrame {
uci1 1:e392595b4b76 12 //
uci1 1:e392595b4b76 13 // A simple struct (everything public) to function like namespace.
uci1 1:e392595b4b76 14 // The contents of the status frame are sent from here, in order to
uci1 1:e392595b4b76 15 // help make sure the status frame is the same for each comm method.
uci1 1:e392595b4b76 16 //
uci1 1:e392595b4b76 17 // No member variables are used in order to preserve memory on the mbed.
uci1 1:e392595b4b76 18 // (i.e. no actual status frame middle-man object exists)
uci1 1:e392595b4b76 19 //
uci1 1:e392595b4b76 20
uci1 1:e392595b4b76 21 static const uint8_t kIOVers; // MUST BE INCREASED if bytes written/read change!!
uci1 1:e392595b4b76 22
uci1 1:e392595b4b76 23 static const uint32_t kMaxSizeOf =
uci1 1:e392595b4b76 24 1u + sizeof(uint64_t)
uci1 1:e392595b4b76 25 + (sizeof(uint32_t)*3u) + (sizeof(uint16_t))
uci1 1:e392595b4b76 26 + (sizeof(uint8_t)*3u) + SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 27 + SnEventFrame::kMaxSizeOf;
uci1 1:e392595b4b76 28
uci1 1:e392595b4b76 29 template<class T>
uci1 1:e392595b4b76 30 static
uci1 3:24c5f0f50bf1 31 SnCommWin::ECommWinResult WriteTo(T& x,
uci1 1:e392595b4b76 32 const SnConfigFrame::EDatPackBit type,
uci1 1:e392595b4b76 33 const SnConfigFrame& conf,
uci1 1:e392595b4b76 34 const SnEventFrame& evt,
uci1 1:e392595b4b76 35 char* const evtBuf) {
uci1 1:e392595b4b76 36 // expect 'x' to be a MODSERIAL& or a char const*
uci1 1:e392595b4b76 37
uci1 1:e392595b4b76 38 uint8_t loseLSB=0, loseMSB=0;
uci1 1:e392595b4b76 39 uint16_t wvBase=0;
uci1 1:e392595b4b76 40 conf.GetPackParsFor(type, loseLSB, loseMSB, wvBase);
uci1 1:e392595b4b76 41
uci1 1:e392595b4b76 42 const uint32_t llen = strlen(conf.GetLabel());
uci1 1:e392595b4b76 43
uci1 1:e392595b4b76 44 // if anything about these writes changes, update kIOVers and SizeOf
uci1 1:e392595b4b76 45 x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
uci1 1:e392595b4b76 46 x = SnBitUtils::WriteTo(x, conf.GetMacAddress());
uci1 1:e392595b4b76 47 x = SnBitUtils::WriteTo(x, llen);
uci1 1:e392595b4b76 48 x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
uci1 1:e392595b4b76 49 x = SnBitUtils::WriteTo(x, conf.GetRun());
uci1 1:e392595b4b76 50 x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0)));
uci1 1:e392595b4b76 51 x = SnBitUtils::WriteTo(x, loseLSB);
uci1 1:e392595b4b76 52 x = SnBitUtils::WriteTo(x, loseMSB);
uci1 1:e392595b4b76 53 x = SnBitUtils::WriteTo(x, wvBase);
uci1 1:e392595b4b76 54 x = WriteEventTo(x, evtBuf, evt,
uci1 1:e392595b4b76 55 loseLSB, loseMSB, wvBase);
uci1 1:e392595b4b76 56
uci1 1:e392595b4b76 57 return SnCommWin::kOkMsgSent;
uci1 1:e392595b4b76 58 }
uci1 1:e392595b4b76 59
uci1 1:e392595b4b76 60 static
uci1 1:e392595b4b76 61 MODSERIAL& WriteEventTo(MODSERIAL& x, char* const evtBuf, const SnEventFrame& evt,
uci1 1:e392595b4b76 62 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 1:e392595b4b76 63 const uint16_t wvBase) {
uci1 1:e392595b4b76 64 evt.WriteTo(evtBuf, loseLSB, loseMSB, wvBase);
uci1 1:e392595b4b76 65 x = SnBitUtils::WriteTo(x, evtBuf, evt.SizeOf(loseLSB, loseMSB));
uci1 1:e392595b4b76 66 return x;
uci1 1:e392595b4b76 67 }
uci1 1:e392595b4b76 68
uci1 1:e392595b4b76 69 static
uci1 1:e392595b4b76 70 char* WriteEventTo(char* const x, char* const evtBuf, const SnEventFrame& evt,
uci1 1:e392595b4b76 71 const uint8_t loseLSB, const uint8_t loseMSB,
uci1 1:e392595b4b76 72 const uint16_t wvBase) {
uci1 3:24c5f0f50bf1 73 return evt.WriteTo(x, loseLSB, loseMSB, wvBase);
uci1 1:e392595b4b76 74 }
uci1 1:e392595b4b76 75
uci1 1:e392595b4b76 76 static
uci1 1:e392595b4b76 77 uint32_t SizeOf(const uint32_t confLblLen,
uci1 1:e392595b4b76 78 const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 1:e392595b4b76 79 // number of bytes read/written during i/o
uci1 1:e392595b4b76 80 const uint32_t msz = kMaxSizeOf - SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 81 + confLblLen;
uci1 1:e392595b4b76 82 if ((loseLSB==0) && (loseMSB==0)) {
uci1 1:e392595b4b76 83 return msz;
uci1 1:e392595b4b76 84 } else {
uci1 1:e392595b4b76 85 return msz - SnEventFrame::kMaxSizeOf
uci1 1:e392595b4b76 86 + SnEventFrame::SizeOf(loseLSB, loseMSB);
uci1 1:e392595b4b76 87 }
uci1 1:e392595b4b76 88 }
uci1 1:e392595b4b76 89
uci1 1:e392595b4b76 90 static
uci1 1:e392595b4b76 91 uint32_t SizeOf(const SnConfigFrame& conf) {
uci1 1:e392595b4b76 92 return SizeOf(conf.GetLabelStrLen(),
uci1 1:e392595b4b76 93 conf.GetWvLoseLSB(), conf.GetWvLoseMSB());
uci1 1:e392595b4b76 94 }
uci1 1:e392595b4b76 95
uci1 1:e392595b4b76 96 };
uci1 1:e392595b4b76 97
uci1 1:e392595b4b76 98 #endif // SN_SnStatusFrame