Initial commit based on common repo commit ffeb9c9b
This commit is contained in:
78
libs/gempa/caps/mseed/spclock.h
Normal file
78
libs/gempa/caps/mseed/spclock.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*****************************************************************************
|
||||
* 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:
|
||||
typedef Gempa::CAPS::Time INT_TIME;
|
||||
|
||||
private:
|
||||
INT_TIME itime;
|
||||
int ticks;
|
||||
int corr;
|
||||
|
||||
public:
|
||||
const int freqn;
|
||||
const int freqd;
|
||||
|
||||
SPClock(int freqn_init, int freqd_init): ticks(0), corr(0),
|
||||
freqn(freqn_init), freqd(freqd_init)
|
||||
{}
|
||||
|
||||
void sync_time(const INT_TIME &time)
|
||||
{
|
||||
itime = time;
|
||||
ticks = 0;
|
||||
corr = 0;
|
||||
}
|
||||
|
||||
void tick()
|
||||
{
|
||||
++ticks;
|
||||
}
|
||||
|
||||
INT_TIME get_time(int tick_diff) const
|
||||
{
|
||||
int64_t correctness = (double)freqd / (double)freqn * 1000000 * (ticks - tick_diff - corr);
|
||||
return itime + Gempa::CAPS::TimeSpan(long(correctness/1000000),long(correctness%1000000));
|
||||
}
|
||||
|
||||
int correction() const
|
||||
{
|
||||
return corr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // SPCLOCK_H
|
||||
Reference in New Issue
Block a user