Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: SnClockSetFrame.h
- Revision:
- 84:80b15993944e
- Parent:
- 40:1324da35afd4
- Child:
- 97:9f3fe603e8b5
--- a/SnClockSetFrame.h Mon Feb 23 03:04:39 2015 +0000 +++ b/SnClockSetFrame.h Fri Oct 30 04:49:40 2015 +0000 @@ -10,45 +10,58 @@ public: static const uint8_t kIOVers; // MUST BE INCREASED if any member var changes static const uint32_t kMaxSizeOf = sizeof(uint8_t) + (3u*sizeof(uint32_t)) - + sizeof(int); + + sizeof(int32_t); private: uint32_t fPrevTime; uint32_t fSetTime; - Timer fSinceSet; + //Timer fSinceSet; + uint32_t fCurTime; + int32_t fUsSinceSet; // Timer for some reason givse an int instead of an unsigned int - void ResetCCtimer() { fSinceSet.reset(); fSinceSet.start(); } + //void ResetCCtimer() { fSinceSet.reset(); fSinceSet.start(); } public: SnClockSetFrame() : - fPrevTime(0), fSetTime(0) {} + fPrevTime(0), fSetTime(0), + fCurTime(0), fUsSinceSet(0) {} virtual ~SnClockSetFrame() {} - void SetClocks(const uint32_t prev, const uint32_t stim) { - ResetCCtimer(); - fPrevTime = prev; - fSetTime = stim; + uint32_t GetCurTime() const { return fCurTime; } + + void SetClocks(const uint32_t prev, const uint32_t stim, + const uint32_t ctime, const int32_t usss) { + //ResetCCtimer(); + fPrevTime = prev; + fSetTime = stim; + fCurTime = ctime; + fUsSinceSet = usss; } - + /* + int32_t GetUsSinceSet() { + return static_cast<int32_t>(fUsSinceSet.read_us()); + } + */ static uint32_t SizeOf(const uint8_t rv=SnClockSetFrame::kIOVers) { return kMaxSizeOf; } template<class T> - SnCommWin::ECommWinResult WriteTo(T& x) { + SnCommWin::ECommWinResult WriteTo(T& x) const { // expect 'x' to be a MODSERIAL or a char const* or a FILE* x = SnBitUtils::WriteTo(x, kIOVers); x = SnBitUtils::WriteTo(x, fPrevTime); x = SnBitUtils::WriteTo(x, fSetTime); - x = SnBitUtils::WriteTo(x, static_cast<uint32_t>(time(0))); - x = SnBitUtils::WriteTo(x, static_cast<int32_t>(fSinceSet.read_us())); + x = SnBitUtils::WriteTo(x, fCurTime); + x = SnBitUtils::WriteTo(x, fUsSinceSet); // read_us returns a signed int for some reason. so we keep that // convention and merely make the number of bits explicit via the // cast. changing to an unsigned int is left for later. return SnCommWin::kOkMsgSent; } + template<class T> static SnCommWin::ECommWinResult ReadFrom(T& b, @@ -64,7 +77,11 @@ b = SnBitUtils::ReadFrom(b, ss); return SnCommWin::kOkWithMsg; } - + + template<class T> + SnCommWin::ECommWinResult ReadFrom(T& b) { + return ReadFrom(b, fPrevTime, fSetTime, fCurTime, fUsSinceSet); + } };