|
|
|
/*****************************************************************************
|
|
|
|
* spclock.h
|
|
|
|
*
|
|
|
|
* Stream Processor Clock
|
|
|
|
*
|
|
|
|
* (c) 2000 Andres Heinloo, GFZ Potsdam
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any later
|
|
|
|
* version. For more information, see http://www.gnu.org/
|
|
|
|
*
|
|
|
|
* ================
|
|
|
|
* Change log
|
|
|
|
* ===============
|
|
|
|
*
|
|
|
|
* 01.01.2013 Adapted code to CAPS client library requirements (gempa GmbH)
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef CAPS_MSEED_SPCLOCK_H
|
|
|
|
#define CAPS_MSEED_SPCLOCK_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <gempa/caps/datetime.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Gempa {
|
|
|
|
namespace CAPS {
|
|
|
|
|
|
|
|
|
|
|
|
class SPClock {
|
|
|
|
public:
|
|
|
|
SPClock(int freqn, int freqd)
|
|
|
|
: freqn(freqn), freqd(freqd) {}
|
|
|
|
|
|
|
|
void syncTime(const Time &time) {
|
|
|
|
_itime = time;
|
|
|
|
_ticks = 0;
|
|
|
|
_corr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tick() {
|
|
|
|
++_ticks;
|
|
|
|
}
|
|
|
|
|
|
|
|
Time getTime(int tickDiff) const {
|
|
|
|
int64_t correctness = (double)freqd / (double)freqn * 1000000 * (_ticks - tickDiff - _corr);
|
|
|
|
return _itime + TimeSpan(long(correctness / 1000000), long(correctness % 1000000));
|
|
|
|
}
|
|
|
|
|
|
|
|
int correction() const {
|
|
|
|
return _corr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
const int freqn;
|
|
|
|
const int freqd;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Time _itime;
|
|
|
|
int _ticks{0};
|
|
|
|
int _corr{0};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|