Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Tue May 03 02:01:35 2016 +0000
Revision:
116:8099b754fbb4
Parent:
84:80b15993944e
One program for all stns via UID/MAC lookup table or generation. Status sends number trg/evt and livetime, not rates. Add 512 sample evt and RFFT-LUTs. Add L1Scaledown trg bit. Allow skip SST reset at start. Fix dt at end of seq. End of comm signal.

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