Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Wed Oct 10 05:54:12 2012 +0000
Revision:
21:ce51bb0ba4a5
Parent:
10:3c93db1cfb12
Child:
25:57b2627fe756
Uses USB comm. Fix rates calc. Power up/down ETH with Afar. Fix sending evt with status. Add num files and bytes of data to status. Can save a local file (i.e. reprogram MBED) via comms. Set config after each comm win (need if cards pow cycle).

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 21:ce51bb0ba4a5 10 #include "SnSDUtils.h"
uci1 1:e392595b4b76 11
uci1 1:e392595b4b76 12 struct SnStatusFrame {
uci1 1:e392595b4b76 13 //
uci1 1:e392595b4b76 14 // A simple struct (everything public) to function like namespace.
uci1 1:e392595b4b76 15 // The contents of the status frame are sent from here, in order to
uci1 1:e392595b4b76 16 // help make sure the status frame is the same for each comm method.
uci1 1:e392595b4b76 17 //
uci1 1:e392595b4b76 18 // No member variables are used in order to preserve memory on the mbed.
uci1 1:e392595b4b76 19 // (i.e. no actual status frame middle-man object exists)
uci1 1:e392595b4b76 20 //
uci1 1:e392595b4b76 21
uci1 1:e392595b4b76 22 static const uint8_t kIOVers; // MUST BE INCREASED if bytes written/read change!!
uci1 1:e392595b4b76 23
uci1 10:3c93db1cfb12 24 static const uint32_t kMaxSizeOfV1 =
uci1 1:e392595b4b76 25 1u + sizeof(uint64_t)
uci1 1:e392595b4b76 26 + (sizeof(uint32_t)*3u) + (sizeof(uint16_t))
uci1 1:e392595b4b76 27 + (sizeof(uint8_t)*3u) + SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 28 + SnEventFrame::kMaxSizeOf;
uci1 10:3c93db1cfb12 29 static const uint32_t kMaxSizeOfV2 =
uci1 10:3c93db1cfb12 30 sizeof(uint64_t) + (3u*sizeof(uint32_t)) + (2u*sizeof(uint16_t))
uci1 10:3c93db1cfb12 31 + (3u*sizeof(uint8_t)) + (2u*sizeof(float))
uci1 10:3c93db1cfb12 32 + SnConfigFrame::kConfLblLen;
uci1 21:ce51bb0ba4a5 33 static const uint32_t kMaxSizeOfV3 =
uci1 21:ce51bb0ba4a5 34 kMaxSizeOfV2 + sizeof(uint32_t) + sizeof(float);
uci1 10:3c93db1cfb12 35 static const uint32_t kMaxSizeOf = kMaxSizeOfV1;
uci1 10:3c93db1cfb12 36
uci1 10:3c93db1cfb12 37 static
uci1 10:3c93db1cfb12 38 uint32_t GetMaxSizeOf(const uint8_t rv) {
uci1 10:3c93db1cfb12 39 if (rv==1) {
uci1 10:3c93db1cfb12 40 return kMaxSizeOfV1;
uci1 21:ce51bb0ba4a5 41 } else if (rv==2) {
uci1 21:ce51bb0ba4a5 42 return kMaxSizeOfV2;
uci1 10:3c93db1cfb12 43 } else {
uci1 21:ce51bb0ba4a5 44 return kMaxSizeOfV3;
uci1 10:3c93db1cfb12 45 }
uci1 10:3c93db1cfb12 46 }
uci1 1:e392595b4b76 47
uci1 1:e392595b4b76 48 template<class T>
uci1 1:e392595b4b76 49 static
uci1 3:24c5f0f50bf1 50 SnCommWin::ECommWinResult WriteTo(T& x,
uci1 1:e392595b4b76 51 const SnConfigFrame& conf,
uci1 1:e392595b4b76 52 const SnEventFrame& evt,
uci1 10:3c93db1cfb12 53 char* const evtBuf,
uci1 10:3c93db1cfb12 54 const uint16_t seq,
uci1 10:3c93db1cfb12 55 const float thmrate,
uci1 21:ce51bb0ba4a5 56 const float evtrate,
uci1 21:ce51bb0ba4a5 57 const uint8_t loseLSB,
uci1 21:ce51bb0ba4a5 58 const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 59 const uint16_t wvBase) {
uci1 1:e392595b4b76 60 // expect 'x' to be a MODSERIAL& or a char const*
uci1 1:e392595b4b76 61
uci1 1:e392595b4b76 62 const uint32_t llen = strlen(conf.GetLabel());
uci1 1:e392595b4b76 63
uci1 1:e392595b4b76 64 // if anything about these writes changes, update kIOVers and SizeOf
uci1 1:e392595b4b76 65 x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
uci1 1:e392595b4b76 66 x = SnBitUtils::WriteTo(x, conf.GetMacAddress());
uci1 1:e392595b4b76 67 x = SnBitUtils::WriteTo(x, llen);
uci1 1:e392595b4b76 68 x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
uci1 1:e392595b4b76 69 x = SnBitUtils::WriteTo(x, conf.GetRun());
uci1 10:3c93db1cfb12 70 x = SnBitUtils::WriteTo(x, seq);
uci1 1:e392595b4b76 71 x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0)));
uci1 1:e392595b4b76 72 x = SnBitUtils::WriteTo(x, loseLSB);
uci1 1:e392595b4b76 73 x = SnBitUtils::WriteTo(x, loseMSB);
uci1 1:e392595b4b76 74 x = SnBitUtils::WriteTo(x, wvBase);
uci1 10:3c93db1cfb12 75 x = SnBitUtils::WriteTo(x, thmrate);
uci1 10:3c93db1cfb12 76 x = SnBitUtils::WriteTo(x, evtrate);
uci1 21:ce51bb0ba4a5 77 // file info
uci1 21:ce51bb0ba4a5 78 uint32_t nfiles(0);
uci1 21:ce51bb0ba4a5 79 float totbytes(0);
uci1 21:ce51bb0ba4a5 80 SnSDUtils::GetDirProps(SnSDUtils::kSDdir, nfiles, totbytes);
uci1 21:ce51bb0ba4a5 81 if (strcmp(SnSDUtils::kSDdir, SnSDUtils::kSDsubDir)!=0) {
uci1 21:ce51bb0ba4a5 82 uint32_t sf(0);
uci1 21:ce51bb0ba4a5 83 float sb(0);
uci1 21:ce51bb0ba4a5 84 SnSDUtils::GetDirProps(SnSDUtils::kSDsubDir, sf, sb);
uci1 21:ce51bb0ba4a5 85 nfiles += sf;
uci1 21:ce51bb0ba4a5 86 totbytes += sb;
uci1 21:ce51bb0ba4a5 87 }
uci1 21:ce51bb0ba4a5 88 totbytes /= 1000; // KB
uci1 21:ce51bb0ba4a5 89 x = SnBitUtils::WriteTo(x, nfiles);
uci1 21:ce51bb0ba4a5 90 x = SnBitUtils::WriteTo(x, totbytes);
uci1 21:ce51bb0ba4a5 91
uci1 1:e392595b4b76 92 return SnCommWin::kOkMsgSent;
uci1 1:e392595b4b76 93 }
uci1 10:3c93db1cfb12 94
uci1 1:e392595b4b76 95 static
uci1 8:95a325df1f6b 96 uint32_t SizeOf(const uint8_t rv, const uint32_t confLblLen,
uci1 1:e392595b4b76 97 const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 1:e392595b4b76 98 // number of bytes read/written during i/o
uci1 10:3c93db1cfb12 99 const uint32_t maxsize = GetMaxSizeOf(rv);
uci1 10:3c93db1cfb12 100 const uint32_t msz = maxsize - SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 101 + confLblLen;
uci1 10:3c93db1cfb12 102 if (rv==1) {
uci1 10:3c93db1cfb12 103 if ((loseLSB==0) && (loseMSB==0)) {
uci1 10:3c93db1cfb12 104 return msz;
uci1 10:3c93db1cfb12 105 } else {
uci1 10:3c93db1cfb12 106 return msz - maxsize
uci1 10:3c93db1cfb12 107 + SnEventFrame::SizeOf(SnEventFrame::kIOVers,
uci1 10:3c93db1cfb12 108 loseLSB, loseMSB);
uci1 10:3c93db1cfb12 109 }
uci1 10:3c93db1cfb12 110 } else {
uci1 1:e392595b4b76 111 return msz;
uci1 1:e392595b4b76 112 }
uci1 1:e392595b4b76 113 }
uci1 1:e392595b4b76 114
uci1 1:e392595b4b76 115 static
uci1 8:95a325df1f6b 116 uint32_t SizeOf(const uint8_t rv, const SnConfigFrame& conf) {
uci1 8:95a325df1f6b 117 return SizeOf(rv, conf.GetLabelStrLen(),
uci1 1:e392595b4b76 118 conf.GetWvLoseLSB(), conf.GetWvLoseMSB());
uci1 1:e392595b4b76 119 }
uci1 1:e392595b4b76 120
uci1 1:e392595b4b76 121 };
uci1 1:e392595b4b76 122
uci1 1:e392595b4b76 123 #endif // SN_SnStatusFrame