Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Thu Oct 30 06:42:17 2014 +0000
Revision:
56:0bba0ef15697
Parent:
40:1324da35afd4
Child:
61:42cbfc02e0e0
update ext libs, add tempr, allow SST/ATWD, improve handshaking, run/seq list, req seq range, allow SBD only in low pwr, all pins start off, can collect data to ram w/o SD card, add parameters to status update

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 1:e392595b4b76 32 + SnEventFrame::kMaxSizeOf;
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 10:3c93db1cfb12 44 static const uint32_t kMaxSizeOf = kMaxSizeOfV1;
uci1 10:3c93db1cfb12 45
uci1 40:1324da35afd4 46
uci1 25:57b2627fe756 47 public:
uci1 25:57b2627fe756 48 static bool fgRecalcFiles;
uci1 25:57b2627fe756 49 private:
uci1 40:1324da35afd4 50 /*
uci1 25:57b2627fe756 51 static uint32_t fgNfiles;
uci1 25:57b2627fe756 52 static float fgTotKbytes;
uci1 40:1324da35afd4 53 */
uci1 40:1324da35afd4 54 static float fgFreeMB;
uci1 40:1324da35afd4 55
uci1 25:57b2627fe756 56 public:
uci1 40:1324da35afd4 57 /*
uci1 10:3c93db1cfb12 58 static
uci1 28:484943132bb0 59 uint32_t GetNfiles() { return fgNfiles; }
uci1 28:484943132bb0 60 static
uci1 28:484943132bb0 61 float GetTotKbytes() { return fgTotKbytes; }
uci1 40:1324da35afd4 62 */
uci1 40:1324da35afd4 63 static
uci1 40:1324da35afd4 64 float GetFreeMB() { return fgFreeMB; }
uci1 28:484943132bb0 65
uci1 28:484943132bb0 66 static
uci1 10:3c93db1cfb12 67 uint32_t GetMaxSizeOf(const uint8_t rv) {
uci1 10:3c93db1cfb12 68 if (rv==1) {
uci1 10:3c93db1cfb12 69 return kMaxSizeOfV1;
uci1 21:ce51bb0ba4a5 70 } else if (rv==2) {
uci1 21:ce51bb0ba4a5 71 return kMaxSizeOfV2;
uci1 40:1324da35afd4 72 } else if (rv==3) {
uci1 40:1324da35afd4 73 return kMaxSizeOfV3;
uci1 40:1324da35afd4 74 } else if (rv==4) {
uci1 40:1324da35afd4 75 return kMaxSizeOfV4;
uci1 40:1324da35afd4 76 } else if (rv==5) {
uci1 40:1324da35afd4 77 return kMaxSizeOfV5;
uci1 56:0bba0ef15697 78 } else if (rv==6) {
uci1 56:0bba0ef15697 79 return kMaxSizeOfV6;
uci1 56:0bba0ef15697 80 } else if (rv==7) {
uci1 56:0bba0ef15697 81 return kMaxSizeOfV7;
uci1 56:0bba0ef15697 82 } else if (rv==8) {
uci1 56:0bba0ef15697 83 return kMaxSizeOfV8;
uci1 10:3c93db1cfb12 84 } else {
uci1 40:1324da35afd4 85 return kMaxSizeOf;
uci1 10:3c93db1cfb12 86 }
uci1 10:3c93db1cfb12 87 }
uci1 1:e392595b4b76 88
uci1 1:e392595b4b76 89 template<class T>
uci1 1:e392595b4b76 90 static
uci1 3:24c5f0f50bf1 91 SnCommWin::ECommWinResult WriteTo(T& x,
uci1 1:e392595b4b76 92 const SnConfigFrame& conf,
uci1 1:e392595b4b76 93 const SnEventFrame& evt,
uci1 10:3c93db1cfb12 94 char* const evtBuf,
uci1 10:3c93db1cfb12 95 const uint16_t seq,
uci1 10:3c93db1cfb12 96 const float thmrate,
uci1 21:ce51bb0ba4a5 97 const float evtrate,
uci1 56:0bba0ef15697 98 const uint32_t powerOnTime,
uci1 56:0bba0ef15697 99 const SnTempFrame& temper,
uci1 21:ce51bb0ba4a5 100 const uint8_t loseLSB,
uci1 21:ce51bb0ba4a5 101 const uint8_t loseMSB,
uci1 21:ce51bb0ba4a5 102 const uint16_t wvBase) {
uci1 1:e392595b4b76 103 // expect 'x' to be a MODSERIAL& or a char const*
uci1 1:e392595b4b76 104
uci1 1:e392595b4b76 105 const uint32_t llen = strlen(conf.GetLabel());
uci1 1:e392595b4b76 106
uci1 1:e392595b4b76 107 // if anything about these writes changes, update kIOVers and SizeOf
uci1 1:e392595b4b76 108 x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers);
uci1 1:e392595b4b76 109 x = SnBitUtils::WriteTo(x, conf.GetMacAddress());
uci1 1:e392595b4b76 110 x = SnBitUtils::WriteTo(x, llen);
uci1 1:e392595b4b76 111 x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen);
uci1 1:e392595b4b76 112 x = SnBitUtils::WriteTo(x, conf.GetRun());
uci1 10:3c93db1cfb12 113 x = SnBitUtils::WriteTo(x, seq);
uci1 1:e392595b4b76 114 x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0)));
uci1 1:e392595b4b76 115 x = SnBitUtils::WriteTo(x, loseLSB);
uci1 1:e392595b4b76 116 x = SnBitUtils::WriteTo(x, loseMSB);
uci1 1:e392595b4b76 117 x = SnBitUtils::WriteTo(x, wvBase);
uci1 10:3c93db1cfb12 118 x = SnBitUtils::WriteTo(x, thmrate);
uci1 10:3c93db1cfb12 119 x = SnBitUtils::WriteTo(x, evtrate);
uci1 21:ce51bb0ba4a5 120 // file info
uci1 25:57b2627fe756 121 if (fgRecalcFiles) {
uci1 40:1324da35afd4 122 /*
uci1 25:57b2627fe756 123 #ifdef ST_DEBUG
uci1 25:57b2627fe756 124 printf("Calling GetDirProps for %s\r\n",SnSDUtils::kSDdir);
uci1 25:57b2627fe756 125 #endif
uci1 25:57b2627fe756 126 SnSDUtils::GetDirProps(SnSDUtils::kSDdir, fgNfiles, fgTotKbytes);
uci1 25:57b2627fe756 127 fgTotKbytes /= 1e3; // KB
uci1 25:57b2627fe756 128 #ifdef ST_DEBUG
uci1 25:57b2627fe756 129 printf("nfiles=%u, tb=%g kb\r\n",fgNfiles,fgTotKbytes);
uci1 25:57b2627fe756 130 #endif
uci1 40:1324da35afd4 131 */
uci1 40:1324da35afd4 132 fgFreeMB = SnSDUtils::GetFreeBytes() / 1048576.0;
uci1 40:1324da35afd4 133 #ifdef ST_DEBUG
uci1 40:1324da35afd4 134 printf("fgFreeMB = %g\r\n",fgFreeMB);
uci1 40:1324da35afd4 135 #endif
uci1 25:57b2627fe756 136 fgRecalcFiles = false;
uci1 21:ce51bb0ba4a5 137 }
uci1 40:1324da35afd4 138 /*
uci1 25:57b2627fe756 139 x = SnBitUtils::WriteTo(x, fgNfiles);
uci1 25:57b2627fe756 140 x = SnBitUtils::WriteTo(x, fgTotKbytes);
uci1 40:1324da35afd4 141 */
uci1 40:1324da35afd4 142 x = SnBitUtils::WriteTo(x, fgFreeMB);
uci1 21:ce51bb0ba4a5 143
uci1 40:1324da35afd4 144 // watchdog reset bit cleared after status received successfully, not here
uci1 40:1324da35afd4 145 const uint8_t wdreset = Watchdog::didWatchdogReset();
uci1 40:1324da35afd4 146 x = SnBitUtils::WriteTo(x, wdreset);
uci1 56:0bba0ef15697 147
uci1 56:0bba0ef15697 148 // the config i/o version we expect (might be needed to send a new config to the station)
uci1 56:0bba0ef15697 149 x = SnBitUtils::WriteTo(x, conf.kIOVers);
uci1 40:1324da35afd4 150
uci1 56:0bba0ef15697 151 x = SnBitUtils::WriteTo(x, powerOnTime);
uci1 56:0bba0ef15697 152 x = SnBitUtils::WriteTo(x, temper.GetTemperature());
uci1 56:0bba0ef15697 153 x = SnBitUtils::WriteTo(x, static_cast<uint8_t>(SnSDUtils::IsInitOk()));
uci1 56:0bba0ef15697 154
uci1 1:e392595b4b76 155 return SnCommWin::kOkMsgSent;
uci1 1:e392595b4b76 156 }
uci1 10:3c93db1cfb12 157
uci1 1:e392595b4b76 158 static
uci1 8:95a325df1f6b 159 uint32_t SizeOf(const uint8_t rv, const uint32_t confLblLen,
uci1 1:e392595b4b76 160 const uint8_t loseLSB, const uint8_t loseMSB) {
uci1 1:e392595b4b76 161 // number of bytes read/written during i/o
uci1 10:3c93db1cfb12 162 const uint32_t maxsize = GetMaxSizeOf(rv);
uci1 10:3c93db1cfb12 163 const uint32_t msz = maxsize - SnConfigFrame::kConfLblLen
uci1 1:e392595b4b76 164 + confLblLen;
uci1 10:3c93db1cfb12 165 if (rv==1) {
uci1 10:3c93db1cfb12 166 if ((loseLSB==0) && (loseMSB==0)) {
uci1 10:3c93db1cfb12 167 return msz;
uci1 10:3c93db1cfb12 168 } else {
uci1 10:3c93db1cfb12 169 return msz - maxsize
uci1 10:3c93db1cfb12 170 + SnEventFrame::SizeOf(SnEventFrame::kIOVers,
uci1 10:3c93db1cfb12 171 loseLSB, loseMSB);
uci1 10:3c93db1cfb12 172 }
uci1 10:3c93db1cfb12 173 } else {
uci1 1:e392595b4b76 174 return msz;
uci1 1:e392595b4b76 175 }
uci1 1:e392595b4b76 176 }
uci1 1:e392595b4b76 177
uci1 1:e392595b4b76 178 static
uci1 8:95a325df1f6b 179 uint32_t SizeOf(const uint8_t rv, const SnConfigFrame& conf) {
uci1 8:95a325df1f6b 180 return SizeOf(rv, conf.GetLabelStrLen(),
uci1 1:e392595b4b76 181 conf.GetWvLoseLSB(), conf.GetWvLoseMSB());
uci1 1:e392595b4b76 182 }
uci1 1:e392595b4b76 183
uci1 1:e392595b4b76 184 };
uci1 1:e392595b4b76 185
uci1 1:e392595b4b76 186 #endif // SN_SnStatusFrame