Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnStatusFrame.h@28:484943132bb0, 2012-11-24 (annotated)
- Committer:
- uci1
- Date:
- Sat Nov 24 06:38:43 2012 +0000
- Revision:
- 28:484943132bb0
- Parent:
- 25:57b2627fe756
- Child:
- 40:1324da35afd4
Afar, SBD, twitter enabled. Debug disabled. Safety nets on config parameters. Patched up netif code to connect to multiple sockets. Add default mbed IP according to mac address.
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 | 21:ce51bb0ba4a5 | 10 | #include "SnSDUtils.h" |
uci1 | 1:e392595b4b76 | 11 | |
uci1 | 25:57b2627fe756 | 12 | //#define ST_DEBUG |
uci1 | 25:57b2627fe756 | 13 | |
uci1 | 1:e392595b4b76 | 14 | struct SnStatusFrame { |
uci1 | 1:e392595b4b76 | 15 | // |
uci1 | 1:e392595b4b76 | 16 | // A simple struct (everything public) to function like namespace. |
uci1 | 1:e392595b4b76 | 17 | // The contents of the status frame are sent from here, in order to |
uci1 | 1:e392595b4b76 | 18 | // help make sure the status frame is the same for each comm method. |
uci1 | 1:e392595b4b76 | 19 | // |
uci1 | 1:e392595b4b76 | 20 | // No member variables are used in order to preserve memory on the mbed. |
uci1 | 1:e392595b4b76 | 21 | // (i.e. no actual status frame middle-man object exists) |
uci1 | 1:e392595b4b76 | 22 | // |
uci1 | 1:e392595b4b76 | 23 | |
uci1 | 1:e392595b4b76 | 24 | static const uint8_t kIOVers; // MUST BE INCREASED if bytes written/read change!! |
uci1 | 1:e392595b4b76 | 25 | |
uci1 | 10:3c93db1cfb12 | 26 | static const uint32_t kMaxSizeOfV1 = |
uci1 | 1:e392595b4b76 | 27 | 1u + sizeof(uint64_t) |
uci1 | 1:e392595b4b76 | 28 | + (sizeof(uint32_t)*3u) + (sizeof(uint16_t)) |
uci1 | 1:e392595b4b76 | 29 | + (sizeof(uint8_t)*3u) + SnConfigFrame::kConfLblLen |
uci1 | 1:e392595b4b76 | 30 | + SnEventFrame::kMaxSizeOf; |
uci1 | 10:3c93db1cfb12 | 31 | static const uint32_t kMaxSizeOfV2 = |
uci1 | 10:3c93db1cfb12 | 32 | sizeof(uint64_t) + (3u*sizeof(uint32_t)) + (2u*sizeof(uint16_t)) |
uci1 | 10:3c93db1cfb12 | 33 | + (3u*sizeof(uint8_t)) + (2u*sizeof(float)) |
uci1 | 10:3c93db1cfb12 | 34 | + SnConfigFrame::kConfLblLen; |
uci1 | 21:ce51bb0ba4a5 | 35 | static const uint32_t kMaxSizeOfV3 = |
uci1 | 21:ce51bb0ba4a5 | 36 | kMaxSizeOfV2 + sizeof(uint32_t) + sizeof(float); |
uci1 | 10:3c93db1cfb12 | 37 | static const uint32_t kMaxSizeOf = kMaxSizeOfV1; |
uci1 | 10:3c93db1cfb12 | 38 | |
uci1 | 25:57b2627fe756 | 39 | public: |
uci1 | 25:57b2627fe756 | 40 | static bool fgRecalcFiles; |
uci1 | 25:57b2627fe756 | 41 | private: |
uci1 | 25:57b2627fe756 | 42 | static uint32_t fgNfiles; |
uci1 | 25:57b2627fe756 | 43 | static float fgTotKbytes; |
uci1 | 25:57b2627fe756 | 44 | public: |
uci1 | 10:3c93db1cfb12 | 45 | static |
uci1 | 28:484943132bb0 | 46 | uint32_t GetNfiles() { return fgNfiles; } |
uci1 | 28:484943132bb0 | 47 | static |
uci1 | 28:484943132bb0 | 48 | float GetTotKbytes() { return fgTotKbytes; } |
uci1 | 28:484943132bb0 | 49 | |
uci1 | 28:484943132bb0 | 50 | static |
uci1 | 10:3c93db1cfb12 | 51 | uint32_t GetMaxSizeOf(const uint8_t rv) { |
uci1 | 10:3c93db1cfb12 | 52 | if (rv==1) { |
uci1 | 10:3c93db1cfb12 | 53 | return kMaxSizeOfV1; |
uci1 | 21:ce51bb0ba4a5 | 54 | } else if (rv==2) { |
uci1 | 21:ce51bb0ba4a5 | 55 | return kMaxSizeOfV2; |
uci1 | 10:3c93db1cfb12 | 56 | } else { |
uci1 | 21:ce51bb0ba4a5 | 57 | return kMaxSizeOfV3; |
uci1 | 10:3c93db1cfb12 | 58 | } |
uci1 | 10:3c93db1cfb12 | 59 | } |
uci1 | 1:e392595b4b76 | 60 | |
uci1 | 1:e392595b4b76 | 61 | template<class T> |
uci1 | 1:e392595b4b76 | 62 | static |
uci1 | 3:24c5f0f50bf1 | 63 | SnCommWin::ECommWinResult WriteTo(T& x, |
uci1 | 1:e392595b4b76 | 64 | const SnConfigFrame& conf, |
uci1 | 1:e392595b4b76 | 65 | const SnEventFrame& evt, |
uci1 | 10:3c93db1cfb12 | 66 | char* const evtBuf, |
uci1 | 10:3c93db1cfb12 | 67 | const uint16_t seq, |
uci1 | 10:3c93db1cfb12 | 68 | const float thmrate, |
uci1 | 21:ce51bb0ba4a5 | 69 | const float evtrate, |
uci1 | 21:ce51bb0ba4a5 | 70 | const uint8_t loseLSB, |
uci1 | 21:ce51bb0ba4a5 | 71 | const uint8_t loseMSB, |
uci1 | 21:ce51bb0ba4a5 | 72 | const uint16_t wvBase) { |
uci1 | 1:e392595b4b76 | 73 | // expect 'x' to be a MODSERIAL& or a char const* |
uci1 | 1:e392595b4b76 | 74 | |
uci1 | 1:e392595b4b76 | 75 | const uint32_t llen = strlen(conf.GetLabel()); |
uci1 | 1:e392595b4b76 | 76 | |
uci1 | 1:e392595b4b76 | 77 | // if anything about these writes changes, update kIOVers and SizeOf |
uci1 | 1:e392595b4b76 | 78 | x = SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers); |
uci1 | 1:e392595b4b76 | 79 | x = SnBitUtils::WriteTo(x, conf.GetMacAddress()); |
uci1 | 1:e392595b4b76 | 80 | x = SnBitUtils::WriteTo(x, llen); |
uci1 | 1:e392595b4b76 | 81 | x = SnBitUtils::WriteTo(x, conf.GetLabel(), llen); |
uci1 | 1:e392595b4b76 | 82 | x = SnBitUtils::WriteTo(x, conf.GetRun()); |
uci1 | 10:3c93db1cfb12 | 83 | x = SnBitUtils::WriteTo(x, seq); |
uci1 | 1:e392595b4b76 | 84 | x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0))); |
uci1 | 1:e392595b4b76 | 85 | x = SnBitUtils::WriteTo(x, loseLSB); |
uci1 | 1:e392595b4b76 | 86 | x = SnBitUtils::WriteTo(x, loseMSB); |
uci1 | 1:e392595b4b76 | 87 | x = SnBitUtils::WriteTo(x, wvBase); |
uci1 | 10:3c93db1cfb12 | 88 | x = SnBitUtils::WriteTo(x, thmrate); |
uci1 | 10:3c93db1cfb12 | 89 | x = SnBitUtils::WriteTo(x, evtrate); |
uci1 | 21:ce51bb0ba4a5 | 90 | // file info |
uci1 | 25:57b2627fe756 | 91 | if (fgRecalcFiles) { |
uci1 | 25:57b2627fe756 | 92 | #ifdef ST_DEBUG |
uci1 | 25:57b2627fe756 | 93 | printf("Calling GetDirProps for %s\r\n",SnSDUtils::kSDdir); |
uci1 | 25:57b2627fe756 | 94 | #endif |
uci1 | 25:57b2627fe756 | 95 | SnSDUtils::GetDirProps(SnSDUtils::kSDdir, fgNfiles, fgTotKbytes); |
uci1 | 25:57b2627fe756 | 96 | fgTotKbytes /= 1e3; // KB |
uci1 | 25:57b2627fe756 | 97 | #ifdef ST_DEBUG |
uci1 | 25:57b2627fe756 | 98 | printf("nfiles=%u, tb=%g kb\r\n",fgNfiles,fgTotKbytes); |
uci1 | 25:57b2627fe756 | 99 | #endif |
uci1 | 25:57b2627fe756 | 100 | fgRecalcFiles = false; |
uci1 | 21:ce51bb0ba4a5 | 101 | } |
uci1 | 25:57b2627fe756 | 102 | x = SnBitUtils::WriteTo(x, fgNfiles); |
uci1 | 25:57b2627fe756 | 103 | x = SnBitUtils::WriteTo(x, fgTotKbytes); |
uci1 | 21:ce51bb0ba4a5 | 104 | |
uci1 | 1:e392595b4b76 | 105 | return SnCommWin::kOkMsgSent; |
uci1 | 1:e392595b4b76 | 106 | } |
uci1 | 10:3c93db1cfb12 | 107 | |
uci1 | 1:e392595b4b76 | 108 | static |
uci1 | 8:95a325df1f6b | 109 | uint32_t SizeOf(const uint8_t rv, const uint32_t confLblLen, |
uci1 | 1:e392595b4b76 | 110 | const uint8_t loseLSB, const uint8_t loseMSB) { |
uci1 | 1:e392595b4b76 | 111 | // number of bytes read/written during i/o |
uci1 | 10:3c93db1cfb12 | 112 | const uint32_t maxsize = GetMaxSizeOf(rv); |
uci1 | 10:3c93db1cfb12 | 113 | const uint32_t msz = maxsize - SnConfigFrame::kConfLblLen |
uci1 | 1:e392595b4b76 | 114 | + confLblLen; |
uci1 | 10:3c93db1cfb12 | 115 | if (rv==1) { |
uci1 | 10:3c93db1cfb12 | 116 | if ((loseLSB==0) && (loseMSB==0)) { |
uci1 | 10:3c93db1cfb12 | 117 | return msz; |
uci1 | 10:3c93db1cfb12 | 118 | } else { |
uci1 | 10:3c93db1cfb12 | 119 | return msz - maxsize |
uci1 | 10:3c93db1cfb12 | 120 | + SnEventFrame::SizeOf(SnEventFrame::kIOVers, |
uci1 | 10:3c93db1cfb12 | 121 | loseLSB, loseMSB); |
uci1 | 10:3c93db1cfb12 | 122 | } |
uci1 | 10:3c93db1cfb12 | 123 | } else { |
uci1 | 1:e392595b4b76 | 124 | return msz; |
uci1 | 1:e392595b4b76 | 125 | } |
uci1 | 1:e392595b4b76 | 126 | } |
uci1 | 1:e392595b4b76 | 127 | |
uci1 | 1:e392595b4b76 | 128 | static |
uci1 | 8:95a325df1f6b | 129 | uint32_t SizeOf(const uint8_t rv, const SnConfigFrame& conf) { |
uci1 | 8:95a325df1f6b | 130 | return SizeOf(rv, conf.GetLabelStrLen(), |
uci1 | 1:e392595b4b76 | 131 | conf.GetWvLoseLSB(), conf.GetWvLoseMSB()); |
uci1 | 1:e392595b4b76 | 132 | } |
uci1 | 1:e392595b4b76 | 133 | |
uci1 | 1:e392595b4b76 | 134 | }; |
uci1 | 1:e392595b4b76 | 135 | |
uci1 | 1:e392595b4b76 | 136 | #endif // SN_SnStatusFrame |