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