Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnClockSetFrame.h@40:1324da35afd4, 2013-10-05 (annotated)
- Committer:
- uci1
- Date:
- Sat Oct 05 04:45:22 2013 +0000
- Revision:
- 40:1324da35afd4
- Child:
- 84:80b15993944e
first commit of major overhaul to 2013-2014 mbed code. NOT YET FULLY TESTED. too many changes to list (fix local file receive, fix rates, external comm packes, big SD cards, get to comm win w/o SD, v8 config frame, v4 files, SBD buffering changes...)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uci1 | 40:1324da35afd4 | 1 | #ifndef SNS_SnClockSetFrame |
uci1 | 40:1324da35afd4 | 2 | #define SNS_SnClockSetFrame |
uci1 | 40:1324da35afd4 | 3 | |
uci1 | 40:1324da35afd4 | 4 | #include "mbed.h" |
uci1 | 40:1324da35afd4 | 5 | #include <stdint.h> |
uci1 | 40:1324da35afd4 | 6 | |
uci1 | 40:1324da35afd4 | 7 | #include "SnCommWin.h" |
uci1 | 40:1324da35afd4 | 8 | |
uci1 | 40:1324da35afd4 | 9 | class SnClockSetFrame { |
uci1 | 40:1324da35afd4 | 10 | public: |
uci1 | 40:1324da35afd4 | 11 | static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes |
uci1 | 40:1324da35afd4 | 12 | static const uint32_t kMaxSizeOf = sizeof(uint8_t) + (3u*sizeof(uint32_t)) |
uci1 | 40:1324da35afd4 | 13 | + sizeof(int); |
uci1 | 40:1324da35afd4 | 14 | |
uci1 | 40:1324da35afd4 | 15 | |
uci1 | 40:1324da35afd4 | 16 | private: |
uci1 | 40:1324da35afd4 | 17 | uint32_t fPrevTime; |
uci1 | 40:1324da35afd4 | 18 | uint32_t fSetTime; |
uci1 | 40:1324da35afd4 | 19 | Timer fSinceSet; |
uci1 | 40:1324da35afd4 | 20 | |
uci1 | 40:1324da35afd4 | 21 | void ResetCCtimer() { fSinceSet.reset(); fSinceSet.start(); } |
uci1 | 40:1324da35afd4 | 22 | |
uci1 | 40:1324da35afd4 | 23 | public: |
uci1 | 40:1324da35afd4 | 24 | SnClockSetFrame() : |
uci1 | 40:1324da35afd4 | 25 | fPrevTime(0), fSetTime(0) {} |
uci1 | 40:1324da35afd4 | 26 | virtual ~SnClockSetFrame() {} |
uci1 | 40:1324da35afd4 | 27 | |
uci1 | 40:1324da35afd4 | 28 | void SetClocks(const uint32_t prev, const uint32_t stim) { |
uci1 | 40:1324da35afd4 | 29 | ResetCCtimer(); |
uci1 | 40:1324da35afd4 | 30 | fPrevTime = prev; |
uci1 | 40:1324da35afd4 | 31 | fSetTime = stim; |
uci1 | 40:1324da35afd4 | 32 | } |
uci1 | 40:1324da35afd4 | 33 | |
uci1 | 40:1324da35afd4 | 34 | static |
uci1 | 40:1324da35afd4 | 35 | uint32_t SizeOf(const uint8_t rv=SnClockSetFrame::kIOVers) |
uci1 | 40:1324da35afd4 | 36 | { return kMaxSizeOf; } |
uci1 | 40:1324da35afd4 | 37 | |
uci1 | 40:1324da35afd4 | 38 | template<class T> |
uci1 | 40:1324da35afd4 | 39 | SnCommWin::ECommWinResult WriteTo(T& x) { |
uci1 | 40:1324da35afd4 | 40 | // expect 'x' to be a MODSERIAL or a char const* or a FILE* |
uci1 | 40:1324da35afd4 | 41 | x = SnBitUtils::WriteTo(x, kIOVers); |
uci1 | 40:1324da35afd4 | 42 | x = SnBitUtils::WriteTo(x, fPrevTime); |
uci1 | 40:1324da35afd4 | 43 | x = SnBitUtils::WriteTo(x, fSetTime); |
uci1 | 40:1324da35afd4 | 44 | x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0))); |
uci1 | 40:1324da35afd4 | 45 | x = SnBitUtils::WriteTo(x, static_cast<int32_t>(fSinceSet.read_us())); |
uci1 | 40:1324da35afd4 | 46 | // read_us returns a signed int for some reason. so we keep that |
uci1 | 40:1324da35afd4 | 47 | // convention and merely make the number of bits explicit via the |
uci1 | 40:1324da35afd4 | 48 | // cast. changing to an unsigned int is left for later. |
uci1 | 40:1324da35afd4 | 49 | return SnCommWin::kOkMsgSent; |
uci1 | 40:1324da35afd4 | 50 | } |
uci1 | 40:1324da35afd4 | 51 | |
uci1 | 40:1324da35afd4 | 52 | template<class T> |
uci1 | 40:1324da35afd4 | 53 | static |
uci1 | 40:1324da35afd4 | 54 | SnCommWin::ECommWinResult ReadFrom(T& b, |
uci1 | 40:1324da35afd4 | 55 | uint32_t& prev, |
uci1 | 40:1324da35afd4 | 56 | uint32_t& stim, |
uci1 | 40:1324da35afd4 | 57 | uint32_t& ctim, |
uci1 | 40:1324da35afd4 | 58 | int32_t& ss) { |
uci1 | 40:1324da35afd4 | 59 | uint8_t Rv=0; |
uci1 | 40:1324da35afd4 | 60 | b = SnBitUtils::ReadFrom(b, Rv); |
uci1 | 40:1324da35afd4 | 61 | b = SnBitUtils::ReadFrom(b, prev); |
uci1 | 40:1324da35afd4 | 62 | b = SnBitUtils::ReadFrom(b, stim); |
uci1 | 40:1324da35afd4 | 63 | b = SnBitUtils::ReadFrom(b, ctim); |
uci1 | 40:1324da35afd4 | 64 | b = SnBitUtils::ReadFrom(b, ss); |
uci1 | 40:1324da35afd4 | 65 | return SnCommWin::kOkWithMsg; |
uci1 | 40:1324da35afd4 | 66 | } |
uci1 | 40:1324da35afd4 | 67 | |
uci1 | 40:1324da35afd4 | 68 | |
uci1 | 40:1324da35afd4 | 69 | }; |
uci1 | 40:1324da35afd4 | 70 | |
uci1 | 40:1324da35afd4 | 71 | #endif // SNS_SnClockSetFrame |