Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Sat Oct 05 04:45:22 2013 +0000
Revision:
40:1324da35afd4
Parent:
28:484943132bb0
Child:
56:0bba0ef15697
first commit of major overhaul to 2013-2014 mbed code. NOT YET FULLY TESTED. too many changes to list (fix local file receive, fix rates, external comm packes, big SD cards, get to comm win w/o SD, v8 config frame, v4 files, SBD buffering changes...)

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 40:1324da35afd4 11 #include "Watchdog.h"
uci1 1:e392595b4b76 12
uci1 25:57b2627fe756 13 //#define ST_DEBUG
uci1 25:57b2627fe756 14
uci1 1:e392595b4b76 15 struct SnStatusFrame {
uci1 1:e392595b4b76 16 //
uci1 1:e392595b4b76 17 // A simple struct (everything public) to function like namespace.
uci1 1:e392595b4b76 18 // The contents of the status frame are sent from here, in order to
uci1 1:e392595b4b76 19 // help make sure the status frame is the same for each comm method.
uci1 1:e392595b4b76 20 //
uci1 1:e392595b4b76 21 // No member variables are used in order to preserve memory on the mbed.
uci1 1:e392595b4b76 22 // (i.e. no actual status frame middle-man object exists)
uci1 1:e392595b4b76 23 //
uci1 1:e392595b4b76 24
uci1 1:e392595b4b76 25 static const uint8_t kIOVers; // MUST BE INCREASED if bytes written/read change!!
uci1 1:e392595b4b76 26
uci1 10:3c93db1cfb12 27 static const uint32_t kMaxSizeOfV1 =
uci1 1:e392595b4b76 28 1u + sizeof(uint64_t)
uci1 1:e392595b4b76 29 + (sizeof(uint32_t)*3u) + (sizeof(uint16_t))
uci1 1:e392595b4b76 30 + (sizeof(uint8_t)*3u) + SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 31 + SnEventFrame::kMaxSizeOf;
uci1 10:3c93db1cfb12 32 static const uint32_t kMaxSizeOfV2 =
uci1 10:3c93db1cfb12 33 sizeof(uint64_t) + (3u*sizeof(uint32_t)) + (2u*sizeof(uint16_t))
uci1 10:3c93db1cfb12 34 + (3u*sizeof(uint8_t)) + (2u*sizeof(float))
uci1 10:3c93db1cfb12 35 + SnConfigFrame::kConfLblLen;
uci1 21:ce51bb0ba4a5 36 static const uint32_t kMaxSizeOfV3 =
uci1 21:ce51bb0ba4a5 37 kMaxSizeOfV2 + sizeof(uint32_t) + sizeof(float);
uci1 40:1324da35afd4 38 static const uint32_t kMaxSizeOfV4 = kMaxSizeOfV3 - sizeof(uint32_t);
uci1 40:1324da35afd4 39 static const uint32_t kMaxSizeOfV5 = kMaxSizeOfV4 + sizeof(uint8_t);
uci1 10:3c93db1cfb12 40 static const uint32_t kMaxSizeOf = kMaxSizeOfV1;
uci1 10:3c93db1cfb12 41
uci1 40:1324da35afd4 42
uci1 25:57b2627fe756 43 public:
uci1 25:57b2627fe756 44 static bool fgRecalcFiles;
uci1 25:57b2627fe756 45 private:
uci1 40:1324da35afd4 46 /*
uci1 25:57b2627fe756 47 static uint32_t fgNfiles;
uci1 25:57b2627fe756 48 static float fgTotKbytes;
uci1 40:1324da35afd4 49 */
uci1 40:1324da35afd4 50 static float fgFreeMB;
uci1 40:1324da35afd4 51
uci1 25:57b2627fe756 52 public:
uci1 40:1324da35afd4 53 /*
uci1 10:3c93db1cfb12 54 static
uci1 28:484943132bb0 55 uint32_t GetNfiles() { return fgNfiles; }
uci1 28:484943132bb0 56 static
uci1 28:484943132bb0 57 float GetTotKbytes() { return fgTotKbytes; }
uci1 40:1324da35afd4 58 */
uci1 40:1324da35afd4 59 static
uci1 40:1324da35afd4 60 float GetFreeMB() { return fgFreeMB; }
uci1 28:484943132bb0 61
uci1 28:484943132bb0 62 static
uci1 10:3c93db1cfb12 63 uint32_t GetMaxSizeOf(const uint8_t rv) {
uci1 10:3c93db1cfb12 64 if (rv==1) {
uci1 10:3c93db1cfb12 65 return kMaxSizeOfV1;
uci1 21:ce51bb0ba4a5 66 } else if (rv==2) {
uci1 21:ce51bb0ba4a5 67 return kMaxSizeOfV2;
uci1 40:1324da35afd4 68 } else if (rv==3) {
uci1 40:1324da35afd4 69 return kMaxSizeOfV3;
uci1 40:1324da35afd4 70 } else if (rv==4) {
uci1 40:1324da35afd4 71 return kMaxSizeOfV4;
uci1 40:1324da35afd4 72 } else if (rv==5) {
uci1 40:1324da35afd4 73 return kMaxSizeOfV5;
uci1 10:3c93db1cfb12 74 } else {
uci1 40:1324da35afd4 75 return kMaxSizeOf;
uci1 10:3c93db1cfb12 76 }
uci1 10:3c93db1cfb12 77 }
uci1 1:e392595b4b76 78
uci1 1:e392595b4b76 79 template<class T>
uci1 1:e392595b4b76 80 static
uci1 3:24c5f0f50bf1 81 SnCommWin::ECommWinResult WriteTo(T& x,
uci1 1:e392595b4b76 82 const SnConfigFrame& conf,
uci1 1:e392595b4b76 83 const SnEventFrame& evt,
uci1 10:3c93db1cfb12 84 char* const evtBuf,
uci1 10:3c93db1cfb12 85 const uint16_t seq,
uci1 10:3c93db1cfb12 86 const float thmrate,
uci1 21:ce51bb0ba4a5 87 const float evtrate,
uci1 21:ce51bb0ba4a5 88 const uint8_t loseLSB,
uci1 21:ce51bb0ba4a5 89 const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 90 const uint16_t wvBase) {
uci1 1:e392595b4b76 91 // expect 'x' to be a MODSERIAL& or a char const*
uci1 1:e392595b4b76 92
uci1 1:e392595b4b76 93 const uint32_t llen = strlen(conf.GetLabel());
uci1 1:e392595b4b76 94
uci1 1:e392595b4b76 95 // if anything about these writes changes, update kIOVers and SizeOf
uci1 1:e392595b4b76 96 x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
uci1 1:e392595b4b76 97 x = SnBitUtils::WriteTo(x, conf.GetMacAddress());
uci1 1:e392595b4b76 98 x = SnBitUtils::WriteTo(x, llen);
uci1 1:e392595b4b76 99 x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
uci1 1:e392595b4b76 100 x = SnBitUtils::WriteTo(x, conf.GetRun());
uci1 10:3c93db1cfb12 101 x = SnBitUtils::WriteTo(x, seq);
uci1 1:e392595b4b76 102 x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0)));
uci1 1:e392595b4b76 103 x = SnBitUtils::WriteTo(x, loseLSB);
uci1 1:e392595b4b76 104 x = SnBitUtils::WriteTo(x, loseMSB);
uci1 1:e392595b4b76 105 x = SnBitUtils::WriteTo(x, wvBase);
uci1 10:3c93db1cfb12 106 x = SnBitUtils::WriteTo(x, thmrate);
uci1 10:3c93db1cfb12 107 x = SnBitUtils::WriteTo(x, evtrate);
uci1 21:ce51bb0ba4a5 108 // file info
uci1 25:57b2627fe756 109 if (fgRecalcFiles) {
uci1 40:1324da35afd4 110 /*
uci1 25:57b2627fe756 111 #ifdef ST_DEBUG
uci1 25:57b2627fe756 112 printf("Calling GetDirProps for %s\r\n",SnSDUtils::kSDdir);
uci1 25:57b2627fe756 113 #endif
uci1 25:57b2627fe756 114 SnSDUtils::GetDirProps(SnSDUtils::kSDdir, fgNfiles, fgTotKbytes);
uci1 25:57b2627fe756 115 fgTotKbytes /= 1e3; // KB
uci1 25:57b2627fe756 116 #ifdef ST_DEBUG
uci1 25:57b2627fe756 117 printf("nfiles=%u, tb=%g kb\r\n",fgNfiles,fgTotKbytes);
uci1 25:57b2627fe756 118 #endif
uci1 40:1324da35afd4 119 */
uci1 40:1324da35afd4 120 fgFreeMB = SnSDUtils::GetFreeBytes() / 1048576.0;
uci1 40:1324da35afd4 121 #ifdef ST_DEBUG
uci1 40:1324da35afd4 122 printf("fgFreeMB = %g\r\n",fgFreeMB);
uci1 40:1324da35afd4 123 #endif
uci1 25:57b2627fe756 124 fgRecalcFiles = false;
uci1 21:ce51bb0ba4a5 125 }
uci1 40:1324da35afd4 126 /*
uci1 25:57b2627fe756 127 x = SnBitUtils::WriteTo(x, fgNfiles);
uci1 25:57b2627fe756 128 x = SnBitUtils::WriteTo(x, fgTotKbytes);
uci1 40:1324da35afd4 129 */
uci1 40:1324da35afd4 130 x = SnBitUtils::WriteTo(x, fgFreeMB);
uci1 21:ce51bb0ba4a5 131
uci1 40:1324da35afd4 132 // watchdog reset bit cleared after status received successfully, not here
uci1 40:1324da35afd4 133 const uint8_t wdreset = Watchdog::didWatchdogReset();
uci1 40:1324da35afd4 134 x = SnBitUtils::WriteTo(x, wdreset);
uci1 40:1324da35afd4 135
uci1 1:e392595b4b76 136 return SnCommWin::kOkMsgSent;
uci1 1:e392595b4b76 137 }
uci1 10:3c93db1cfb12 138
uci1 1:e392595b4b76 139 static
uci1 8:95a325df1f6b 140 uint32_t SizeOf(const uint8_t rv, const uint32_t confLblLen,
uci1 1:e392595b4b76 141 const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 1:e392595b4b76 142 // number of bytes read/written during i/o
uci1 10:3c93db1cfb12 143 const uint32_t maxsize = GetMaxSizeOf(rv);
uci1 10:3c93db1cfb12 144 const uint32_t msz = maxsize - SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 145 + confLblLen;
uci1 10:3c93db1cfb12 146 if (rv==1) {
uci1 10:3c93db1cfb12 147 if ((loseLSB==0) && (loseMSB==0)) {
uci1 10:3c93db1cfb12 148 return msz;
uci1 10:3c93db1cfb12 149 } else {
uci1 10:3c93db1cfb12 150 return msz - maxsize
uci1 10:3c93db1cfb12 151 + SnEventFrame::SizeOf(SnEventFrame::kIOVers,
uci1 10:3c93db1cfb12 152 loseLSB, loseMSB);
uci1 10:3c93db1cfb12 153 }
uci1 10:3c93db1cfb12 154 } else {
uci1 1:e392595b4b76 155 return msz;
uci1 1:e392595b4b76 156 }
uci1 1:e392595b4b76 157 }
uci1 1:e392595b4b76 158
uci1 1:e392595b4b76 159 static
uci1 8:95a325df1f6b 160 uint32_t SizeOf(const uint8_t rv, const SnConfigFrame& conf) {
uci1 8:95a325df1f6b 161 return SizeOf(rv, conf.GetLabelStrLen(),
uci1 1:e392595b4b76 162 conf.GetWvLoseLSB(), conf.GetWvLoseMSB());
uci1 1:e392595b4b76 163 }
uci1 1:e392595b4b76 164
uci1 1:e392595b4b76 165 };
uci1 1:e392595b4b76 166
uci1 1:e392595b4b76 167 #endif // SN_SnStatusFrame