Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Fri Aug 10 18:35:43 2012 +0000
Revision:
10:3c93db1cfb12
Parent:
8:95a325df1f6b
Child:
21:ce51bb0ba4a5
Ensure that lockRegisters (p20) is 0 before accessing the SD card, for example when closing the file. This fixes an issue seen when running in power count mode. Communications still under dev. Many debug outputs.

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 10:3c93db1cfb12 23 static const uint32_t kMaxSizeOfV1 =
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 10:3c93db1cfb12 28 static const uint32_t kMaxSizeOfV2 =
uci1 10:3c93db1cfb12 29 sizeof(uint64_t) + (3u*sizeof(uint32_t)) + (2u*sizeof(uint16_t))
uci1 10:3c93db1cfb12 30 + (3u*sizeof(uint8_t)) + (2u*sizeof(float))
uci1 10:3c93db1cfb12 31 + SnConfigFrame::kConfLblLen;
uci1 10:3c93db1cfb12 32 static const uint32_t kMaxSizeOf = kMaxSizeOfV1;
uci1 10:3c93db1cfb12 33
uci1 10:3c93db1cfb12 34 static
uci1 10:3c93db1cfb12 35 uint32_t GetMaxSizeOf(const uint8_t rv) {
uci1 10:3c93db1cfb12 36 if (rv==1) {
uci1 10:3c93db1cfb12 37 return kMaxSizeOfV1;
uci1 10:3c93db1cfb12 38 } else {
uci1 10:3c93db1cfb12 39 return kMaxSizeOfV2;
uci1 10:3c93db1cfb12 40 }
uci1 10:3c93db1cfb12 41 }
uci1 1:e392595b4b76 42
uci1 1:e392595b4b76 43 template<class T>
uci1 1:e392595b4b76 44 static
uci1 3:24c5f0f50bf1 45 SnCommWin::ECommWinResult WriteTo(T& x,
uci1 1:e392595b4b76 46 const SnConfigFrame::EDatPackBit type,
uci1 1:e392595b4b76 47 const SnConfigFrame& conf,
uci1 1:e392595b4b76 48 const SnEventFrame& evt,
uci1 10:3c93db1cfb12 49 char* const evtBuf,
uci1 10:3c93db1cfb12 50 const uint16_t seq,
uci1 10:3c93db1cfb12 51 const float thmrate,
uci1 10:3c93db1cfb12 52 const float evtrate) {
uci1 1:e392595b4b76 53 // expect 'x' to be a MODSERIAL& or a char const*
uci1 1:e392595b4b76 54
uci1 1:e392595b4b76 55 uint8_t loseLSB=0, loseMSB=0;
uci1 1:e392595b4b76 56 uint16_t wvBase=0;
uci1 1:e392595b4b76 57 conf.GetPackParsFor(type, loseLSB, loseMSB, wvBase);
uci1 1:e392595b4b76 58
uci1 1:e392595b4b76 59 const uint32_t llen = strlen(conf.GetLabel());
uci1 1:e392595b4b76 60
uci1 1:e392595b4b76 61 // if anything about these writes changes, update kIOVers and SizeOf
uci1 1:e392595b4b76 62 x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
uci1 1:e392595b4b76 63 x = SnBitUtils::WriteTo(x, conf.GetMacAddress());
uci1 1:e392595b4b76 64 x = SnBitUtils::WriteTo(x, llen);
uci1 1:e392595b4b76 65 x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
uci1 1:e392595b4b76 66 x = SnBitUtils::WriteTo(x, conf.GetRun());
uci1 10:3c93db1cfb12 67 x = SnBitUtils::WriteTo(x, seq);
uci1 1:e392595b4b76 68 x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0)));
uci1 1:e392595b4b76 69 x = SnBitUtils::WriteTo(x, loseLSB);
uci1 1:e392595b4b76 70 x = SnBitUtils::WriteTo(x, loseMSB);
uci1 1:e392595b4b76 71 x = SnBitUtils::WriteTo(x, wvBase);
uci1 10:3c93db1cfb12 72 x = SnBitUtils::WriteTo(x, thmrate);
uci1 10:3c93db1cfb12 73 x = SnBitUtils::WriteTo(x, evtrate);
uci1 10:3c93db1cfb12 74 /*
uci1 1:e392595b4b76 75 x = WriteEventTo(x, evtBuf, evt,
uci1 1:e392595b4b76 76 loseLSB, loseMSB, wvBase);
uci1 10:3c93db1cfb12 77 */
uci1 1:e392595b4b76 78 return SnCommWin::kOkMsgSent;
uci1 1:e392595b4b76 79 }
uci1 10:3c93db1cfb12 80
uci1 1:e392595b4b76 81 static
uci1 8:95a325df1f6b 82 uint32_t SizeOf(const uint8_t rv, const uint32_t confLblLen,
uci1 1:e392595b4b76 83 const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 1:e392595b4b76 84 // number of bytes read/written during i/o
uci1 10:3c93db1cfb12 85 const uint32_t maxsize = GetMaxSizeOf(rv);
uci1 10:3c93db1cfb12 86 const uint32_t msz = maxsize - SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 87 + confLblLen;
uci1 10:3c93db1cfb12 88 if (rv==1) {
uci1 10:3c93db1cfb12 89 if ((loseLSB==0) && (loseMSB==0)) {
uci1 10:3c93db1cfb12 90 return msz;
uci1 10:3c93db1cfb12 91 } else {
uci1 10:3c93db1cfb12 92 return msz - maxsize
uci1 10:3c93db1cfb12 93 + SnEventFrame::SizeOf(SnEventFrame::kIOVers,
uci1 10:3c93db1cfb12 94 loseLSB, loseMSB);
uci1 10:3c93db1cfb12 95 }
uci1 10:3c93db1cfb12 96 } else {
uci1 1:e392595b4b76 97 return msz;
uci1 1:e392595b4b76 98 }
uci1 1:e392595b4b76 99 }
uci1 1:e392595b4b76 100
uci1 1:e392595b4b76 101 static
uci1 8:95a325df1f6b 102 uint32_t SizeOf(const uint8_t rv, const SnConfigFrame& conf) {
uci1 8:95a325df1f6b 103 return SizeOf(rv, conf.GetLabelStrLen(),
uci1 1:e392595b4b76 104 conf.GetWvLoseLSB(), conf.GetWvLoseMSB());
uci1 1:e392595b4b76 105 }
uci1 1:e392595b4b76 106
uci1 1:e392595b4b76 107 };
uci1 1:e392595b4b76 108
uci1 1:e392595b4b76 109 #endif // SN_SnStatusFrame