Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
SnHeartbeatFrame.h@125:ce4045184366, 2019-06-05 (annotated)
- Committer:
- uci1
- Date:
- Wed Jun 05 17:29:31 2019 +0000
- Revision:
- 125:ce4045184366
- Parent:
- 84:80b15993944e
Added SnRateListner proto-class, publishing this version of the code in order to enable exporting of most recent features.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
uci1 | 22:f957c4f840ad | 1 | #ifndef SN_SnHeartbeatFrame |
uci1 | 22:f957c4f840ad | 2 | #define SN_SnHeartbeatFrame |
uci1 | 22:f957c4f840ad | 3 | |
uci1 | 22:f957c4f840ad | 4 | #include <stdint.h> |
uci1 | 22:f957c4f840ad | 5 | #include "SnCommWin.h" |
uci1 | 22:f957c4f840ad | 6 | |
uci1 | 22:f957c4f840ad | 7 | class SnHeartbeatFrame { |
uci1 | 22:f957c4f840ad | 8 | public: |
uci1 | 22:f957c4f840ad | 9 | // i/o version |
uci1 | 22:f957c4f840ad | 10 | static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes |
uci1 | 40:1324da35afd4 | 11 | static const uint32_t kMaxSizeOf = 2u*sizeof(uint32_t) + sizeof(uint8_t); |
uci1 | 22:f957c4f840ad | 12 | |
uci1 | 84:80b15993944e | 13 | private: |
uci1 | 84:80b15993944e | 14 | uint32_t fTime; |
uci1 | 84:80b15993944e | 15 | uint32_t fNum; |
uci1 | 84:80b15993944e | 16 | |
uci1 | 22:f957c4f840ad | 17 | public: |
uci1 | 22:f957c4f840ad | 18 | SnHeartbeatFrame() {} |
uci1 | 22:f957c4f840ad | 19 | virtual ~SnHeartbeatFrame() {} |
uci1 | 22:f957c4f840ad | 20 | |
uci1 | 84:80b15993944e | 21 | uint32_t GetTime() const { return fTime; } |
uci1 | 84:80b15993944e | 22 | uint32_t GetNum() const { return fNum; } |
uci1 | 84:80b15993944e | 23 | |
uci1 | 84:80b15993944e | 24 | void SetTime(const uint32_t t) { fTime = t; } |
uci1 | 84:80b15993944e | 25 | void SetNum(const uint32_t n) { fNum = n; } |
uci1 | 84:80b15993944e | 26 | |
uci1 | 22:f957c4f840ad | 27 | static |
uci1 | 84:80b15993944e | 28 | uint32_t SizeOf(const uint8_t rv=SnHeartbeatFrame::kIOVers) { |
uci1 | 40:1324da35afd4 | 29 | if (rv>1) { |
uci1 | 40:1324da35afd4 | 30 | return kMaxSizeOf; |
uci1 | 40:1324da35afd4 | 31 | } else { |
uci1 | 40:1324da35afd4 | 32 | return kMaxSizeOf - sizeof(uint8_t); |
uci1 | 40:1324da35afd4 | 33 | } |
uci1 | 40:1324da35afd4 | 34 | } |
uci1 | 84:80b15993944e | 35 | |
uci1 | 84:80b15993944e | 36 | template<class T> |
uci1 | 84:80b15993944e | 37 | SnCommWin::ECommWinResult WriteTo(T& x) const { |
uci1 | 84:80b15993944e | 38 | return WriteTo(x, fTime, fNum); |
uci1 | 84:80b15993944e | 39 | } |
uci1 | 22:f957c4f840ad | 40 | |
uci1 | 22:f957c4f840ad | 41 | template<class T> |
uci1 | 22:f957c4f840ad | 42 | static |
uci1 | 22:f957c4f840ad | 43 | SnCommWin::ECommWinResult WriteTo(T& x, |
uci1 | 22:f957c4f840ad | 44 | const uint32_t time, |
uci1 | 22:f957c4f840ad | 45 | const uint32_t num) { |
uci1 | 22:f957c4f840ad | 46 | // expect 'x' to be a MODSERIAL or a char const* |
uci1 | 40:1324da35afd4 | 47 | x = SnBitUtils::WriteTo(x, kIOVers); |
uci1 | 22:f957c4f840ad | 48 | x = SnBitUtils::WriteTo(x, time); |
uci1 | 22:f957c4f840ad | 49 | x = SnBitUtils::WriteTo(x, num); |
uci1 | 22:f957c4f840ad | 50 | return SnCommWin::kOkMsgSent; |
uci1 | 22:f957c4f840ad | 51 | } |
uci1 | 22:f957c4f840ad | 52 | |
uci1 | 22:f957c4f840ad | 53 | template<class T> |
uci1 | 22:f957c4f840ad | 54 | static |
uci1 | 22:f957c4f840ad | 55 | SnCommWin::ECommWinResult ReadFrom(T& b, |
uci1 | 22:f957c4f840ad | 56 | uint32_t& time, |
uci1 | 22:f957c4f840ad | 57 | uint32_t& num) { |
uci1 | 40:1324da35afd4 | 58 | // this can't read V1 of the heartbeat |
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, time); |
uci1 | 40:1324da35afd4 | 62 | b = SnBitUtils::ReadFrom(b, num); |
uci1 | 40:1324da35afd4 | 63 | return SnCommWin::kOkWithMsg; |
uci1 | 40:1324da35afd4 | 64 | } |
uci1 | 40:1324da35afd4 | 65 | |
uci1 | 40:1324da35afd4 | 66 | template<class T> |
uci1 | 40:1324da35afd4 | 67 | static |
uci1 | 40:1324da35afd4 | 68 | SnCommWin::ECommWinResult ReadFromV1(T& b, |
uci1 | 40:1324da35afd4 | 69 | uint32_t& time, |
uci1 | 40:1324da35afd4 | 70 | uint32_t& num) { |
uci1 | 40:1324da35afd4 | 71 | // need a special fcn to read V1 of this frame, |
uci1 | 40:1324da35afd4 | 72 | // since the i/o version was not written out in V1 |
uci1 | 22:f957c4f840ad | 73 | b = SnBitUtils::ReadFrom(b, time); |
uci1 | 22:f957c4f840ad | 74 | b = SnBitUtils::ReadFrom(b, num); |
uci1 | 22:f957c4f840ad | 75 | return SnCommWin::kOkWithMsg; |
uci1 | 22:f957c4f840ad | 76 | } |
uci1 | 22:f957c4f840ad | 77 | |
uci1 | 22:f957c4f840ad | 78 | |
uci1 | 22:f957c4f840ad | 79 | }; |
uci1 | 22:f957c4f840ad | 80 | |
uci1 | 22:f957c4f840ad | 81 | #endif // SN_SnHeartbeatFrame |