Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnClockSetFrame.h@110:d1da040a0cf2, 2015-11-24 (annotated)
- Committer:
- uci1
- Date:
- Tue Nov 24 21:52:27 2015 +0000
- Revision:
- 110:d1da040a0cf2
- Parent:
- 97:9f3fe603e8b5
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 | 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 | 84:80b15993944e | 13 | + sizeof(int32_t); |
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 | 84:80b15993944e | 19 | //Timer fSinceSet; |
uci1 | 84:80b15993944e | 20 | uint32_t fCurTime; |
uci1 | 84:80b15993944e | 21 | int32_t fUsSinceSet; // Timer for some reason givse an int instead of an unsigned int |
uci1 | 40:1324da35afd4 | 22 | |
uci1 | 84:80b15993944e | 23 | //void ResetCCtimer() { fSinceSet.reset(); fSinceSet.start(); } |
uci1 | 40:1324da35afd4 | 24 | |
uci1 | 40:1324da35afd4 | 25 | public: |
uci1 | 40:1324da35afd4 | 26 | SnClockSetFrame() : |
uci1 | 84:80b15993944e | 27 | fPrevTime(0), fSetTime(0), |
uci1 | 84:80b15993944e | 28 | fCurTime(0), fUsSinceSet(0) {} |
uci1 | 40:1324da35afd4 | 29 | virtual ~SnClockSetFrame() {} |
uci1 | 40:1324da35afd4 | 30 | |
uci1 | 84:80b15993944e | 31 | uint32_t GetCurTime() const { return fCurTime; } |
uci1 | 84:80b15993944e | 32 | |
uci1 | 84:80b15993944e | 33 | void SetClocks(const uint32_t prev, const uint32_t stim, |
uci1 | 84:80b15993944e | 34 | const uint32_t ctime, const int32_t usss) { |
uci1 | 84:80b15993944e | 35 | //ResetCCtimer(); |
uci1 | 84:80b15993944e | 36 | fPrevTime = prev; |
uci1 | 84:80b15993944e | 37 | fSetTime = stim; |
uci1 | 84:80b15993944e | 38 | fCurTime = ctime; |
uci1 | 84:80b15993944e | 39 | fUsSinceSet = usss; |
uci1 | 40:1324da35afd4 | 40 | } |
uci1 | 97:9f3fe603e8b5 | 41 | |
uci1 | 97:9f3fe603e8b5 | 42 | void UpdateClock(Timer& usSince) { |
uci1 | 97:9f3fe603e8b5 | 43 | fCurTime = time(0); |
uci1 | 97:9f3fe603e8b5 | 44 | fUsSinceSet = usSince.read_us(); |
uci1 | 97:9f3fe603e8b5 | 45 | } |
uci1 | 97:9f3fe603e8b5 | 46 | |
uci1 | 84:80b15993944e | 47 | /* |
uci1 | 84:80b15993944e | 48 | int32_t GetUsSinceSet() { |
uci1 | 84:80b15993944e | 49 | return static_cast<int32_t>(fUsSinceSet.read_us()); |
uci1 | 84:80b15993944e | 50 | } |
uci1 | 84:80b15993944e | 51 | */ |
uci1 | 40:1324da35afd4 | 52 | static |
uci1 | 40:1324da35afd4 | 53 | uint32_t SizeOf(const uint8_t rv=SnClockSetFrame::kIOVers) |
uci1 | 40:1324da35afd4 | 54 | { return kMaxSizeOf; } |
uci1 | 40:1324da35afd4 | 55 | |
uci1 | 40:1324da35afd4 | 56 | template<class T> |
uci1 | 84:80b15993944e | 57 | SnCommWin::ECommWinResult WriteTo(T& x) const { |
uci1 | 40:1324da35afd4 | 58 | // expect 'x' to be a MODSERIAL or a char const* or a FILE* |
uci1 | 40:1324da35afd4 | 59 | x = SnBitUtils::WriteTo(x, kIOVers); |
uci1 | 40:1324da35afd4 | 60 | x = SnBitUtils::WriteTo(x, fPrevTime); |
uci1 | 40:1324da35afd4 | 61 | x = SnBitUtils::WriteTo(x, fSetTime); |
uci1 | 84:80b15993944e | 62 | x = SnBitUtils::WriteTo(x, fCurTime); |
uci1 | 84:80b15993944e | 63 | x = SnBitUtils::WriteTo(x, fUsSinceSet); |
uci1 | 40:1324da35afd4 | 64 | // read_us returns a signed int for some reason. so we keep that |
uci1 | 40:1324da35afd4 | 65 | // convention and merely make the number of bits explicit via the |
uci1 | 40:1324da35afd4 | 66 | // cast. changing to an unsigned int is left for later. |
uci1 | 40:1324da35afd4 | 67 | return SnCommWin::kOkMsgSent; |
uci1 | 40:1324da35afd4 | 68 | } |
uci1 | 40:1324da35afd4 | 69 | |
uci1 | 84:80b15993944e | 70 | |
uci1 | 40:1324da35afd4 | 71 | template<class T> |
uci1 | 40:1324da35afd4 | 72 | static |
uci1 | 40:1324da35afd4 | 73 | SnCommWin::ECommWinResult ReadFrom(T& b, |
uci1 | 40:1324da35afd4 | 74 | uint32_t& prev, |
uci1 | 40:1324da35afd4 | 75 | uint32_t& stim, |
uci1 | 40:1324da35afd4 | 76 | uint32_t& ctim, |
uci1 | 40:1324da35afd4 | 77 | int32_t& ss) { |
uci1 | 40:1324da35afd4 | 78 | uint8_t Rv=0; |
uci1 | 40:1324da35afd4 | 79 | b = SnBitUtils::ReadFrom(b, Rv); |
uci1 | 40:1324da35afd4 | 80 | b = SnBitUtils::ReadFrom(b, prev); |
uci1 | 40:1324da35afd4 | 81 | b = SnBitUtils::ReadFrom(b, stim); |
uci1 | 40:1324da35afd4 | 82 | b = SnBitUtils::ReadFrom(b, ctim); |
uci1 | 40:1324da35afd4 | 83 | b = SnBitUtils::ReadFrom(b, ss); |
uci1 | 40:1324da35afd4 | 84 | return SnCommWin::kOkWithMsg; |
uci1 | 40:1324da35afd4 | 85 | } |
uci1 | 84:80b15993944e | 86 | |
uci1 | 84:80b15993944e | 87 | template<class T> |
uci1 | 84:80b15993944e | 88 | SnCommWin::ECommWinResult ReadFrom(T& b) { |
uci1 | 84:80b15993944e | 89 | return ReadFrom(b, fPrevTime, fSetTime, fCurTime, fUsSinceSet); |
uci1 | 84:80b15993944e | 90 | } |
uci1 | 40:1324da35afd4 | 91 | |
uci1 | 40:1324da35afd4 | 92 | }; |
uci1 | 40:1324da35afd4 | 93 | |
uci1 | 40:1324da35afd4 | 94 | #endif // SNS_SnClockSetFrame |