Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnStatusFrame.h@0:664899e0b988, 2012-06-30 (annotated)
- Committer:
- uci1
- Date:
- Sat Jun 30 02:03:51 2012 +0000
- Revision:
- 0:664899e0b988
- Child:
- 1:e392595b4b76
first version. SD card writing and data readout works. communications not tested.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uci1 | 0:664899e0b988 | 1 | #ifndef SN_SnStatusFrame |
uci1 | 0:664899e0b988 | 2 | #define SN_SnStatusFrame |
uci1 | 0:664899e0b988 | 3 | |
uci1 | 0:664899e0b988 | 4 | #include <stdint.h> |
uci1 | 0:664899e0b988 | 5 | |
uci1 | 0:664899e0b988 | 6 | #include "SnBitUtils.h" |
uci1 | 0:664899e0b988 | 7 | #include "SnCommWin.h" |
uci1 | 0:664899e0b988 | 8 | #include "SnConfigFrame.h" |
uci1 | 0:664899e0b988 | 9 | #include "SnEventFrame.h" |
uci1 | 0:664899e0b988 | 10 | |
uci1 | 0:664899e0b988 | 11 | struct SnStatusFrame { |
uci1 | 0:664899e0b988 | 12 | // |
uci1 | 0:664899e0b988 | 13 | // A simple struct (everything public) to function like namespace. |
uci1 | 0:664899e0b988 | 14 | // The contents of the status frame are sent from here, in order to |
uci1 | 0:664899e0b988 | 15 | // help make sure the status frame is the same for each comm method. |
uci1 | 0:664899e0b988 | 16 | // |
uci1 | 0:664899e0b988 | 17 | // No member variables are used in order to preserve memory on the mbed. |
uci1 | 0:664899e0b988 | 18 | // (i.e. no actual status frame middle-man object exists) |
uci1 | 0:664899e0b988 | 19 | // |
uci1 | 0:664899e0b988 | 20 | |
uci1 | 0:664899e0b988 | 21 | static const uint8_t kIOVers; // MUST BE INCREASED if bytes written/read change!! |
uci1 | 0:664899e0b988 | 22 | |
uci1 | 0:664899e0b988 | 23 | static const uint32_t kMaxSizeOf = |
uci1 | 0:664899e0b988 | 24 | 1u + sizeof(uint64_t) |
uci1 | 0:664899e0b988 | 25 | + (sizeof(uint32_t)*3u) + (sizeof(uint16_t)) |
uci1 | 0:664899e0b988 | 26 | + (sizeof(uint8_t)*3u) + SnConfigFrame::kConfLblLen |
uci1 | 0:664899e0b988 | 27 | + SnEventFrame::kMaxSizeOf; |
uci1 | 0:664899e0b988 | 28 | |
uci1 | 0:664899e0b988 | 29 | template<class T> |
uci1 | 0:664899e0b988 | 30 | static |
uci1 | 0:664899e0b988 | 31 | SnCommWin::ECommWinResult WriteTo(T x, |
uci1 | 0:664899e0b988 | 32 | const SnConfigFrame::EDatPackBit type, |
uci1 | 0:664899e0b988 | 33 | const SnConfigFrame& conf, |
uci1 | 0:664899e0b988 | 34 | const SnEventFrame& evt, |
uci1 | 0:664899e0b988 | 35 | char* const evtBuf) { |
uci1 | 0:664899e0b988 | 36 | // expect 'x' to be a MODSERIAL& or a char const* |
uci1 | 0:664899e0b988 | 37 | |
uci1 | 0:664899e0b988 | 38 | uint8_t loseLSB=0, loseMSB=0; |
uci1 | 0:664899e0b988 | 39 | uint16_t wvBase=0; |
uci1 | 0:664899e0b988 | 40 | conf.GetPackParsFor(type, loseLSB, loseMSB, wvBase); |
uci1 | 0:664899e0b988 | 41 | |
uci1 | 0:664899e0b988 | 42 | evt.WriteTo(evtBuf, loseLSB, loseMSB, wvBase); |
uci1 | 0:664899e0b988 | 43 | const uint32_t llen = strlen(conf.GetLabel()); |
uci1 | 0:664899e0b988 | 44 | |
uci1 | 0:664899e0b988 | 45 | // if anything about these writes changes, update kIOVers and SizeOf |
uci1 | 0:664899e0b988 | 46 | SnBitUtils::WriteTo(x, SnStatusFrame::kIOVers); |
uci1 | 0:664899e0b988 | 47 | SnBitUtils::WriteTo(x, conf.GetMacAddress()); |
uci1 | 0:664899e0b988 | 48 | SnBitUtils::WriteTo(x, llen); |
uci1 | 0:664899e0b988 | 49 | SnBitUtils::WriteTo(x, conf.GetLabel(), llen); |
uci1 | 0:664899e0b988 | 50 | SnBitUtils::WriteTo(x, conf.GetRun()); |
uci1 | 0:664899e0b988 | 51 | SnBitUtils::WriteTo(x, time(0)); |
uci1 | 0:664899e0b988 | 52 | SnBitUtils::WriteTo(x, loseLSB); |
uci1 | 0:664899e0b988 | 53 | SnBitUtils::WriteTo(x, loseMSB); |
uci1 | 0:664899e0b988 | 54 | SnBitUtils::WriteTo(x, wvBase); |
uci1 | 0:664899e0b988 | 55 | SnBitUtils::WriteTo(x, evtBuf, evt.SizeOf(loseLSB, loseMSB)); |
uci1 | 0:664899e0b988 | 56 | |
uci1 | 0:664899e0b988 | 57 | return SnCommWin::kOkMsgSent; |
uci1 | 0:664899e0b988 | 58 | } |
uci1 | 0:664899e0b988 | 59 | |
uci1 | 0:664899e0b988 | 60 | static |
uci1 | 0:664899e0b988 | 61 | uint32_t SizeOf(const uint32_t confLblLen, |
uci1 | 0:664899e0b988 | 62 | const uint8_t loseLSB, const uint8_t loseMSB) { |
uci1 | 0:664899e0b988 | 63 | // number of bytes read/written during i/o |
uci1 | 0:664899e0b988 | 64 | const uint32_t msz = kMaxSizeOf - SnConfigFrame::kConfLblLen |
uci1 | 0:664899e0b988 | 65 | + confLblLen; |
uci1 | 0:664899e0b988 | 66 | if ((loseLSB==0) && (loseMSB==0)) { |
uci1 | 0:664899e0b988 | 67 | return msz; |
uci1 | 0:664899e0b988 | 68 | } else { |
uci1 | 0:664899e0b988 | 69 | return msz - SnEventFrame::kMaxSizeOf |
uci1 | 0:664899e0b988 | 70 | + SnEventFrame::SizeOf(loseLSB, loseMSB); |
uci1 | 0:664899e0b988 | 71 | } |
uci1 | 0:664899e0b988 | 72 | } |
uci1 | 0:664899e0b988 | 73 | |
uci1 | 0:664899e0b988 | 74 | static |
uci1 | 0:664899e0b988 | 75 | uint32_t SizeOf(const SnConfigFrame& conf) { |
uci1 | 0:664899e0b988 | 76 | return SizeOf(conf.GetLabelStrLen(), |
uci1 | 0:664899e0b988 | 77 | conf.GetWvLoseLSB(), conf.GetWvLoseMSB()); |
uci1 | 0:664899e0b988 | 78 | } |
uci1 | 0:664899e0b988 | 79 | |
uci1 | 0:664899e0b988 | 80 | }; |
uci1 | 0:664899e0b988 | 81 | |
uci1 | 0:664899e0b988 | 82 | #endif // SN_SnStatusFrame |