You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.6 KiB
C++

/*****************************************************************************
* 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