|
Ocean
|
This class encapsulates the logic for calculating the offset between a domain time and unix time. More...
#include <Timestamp.h>
Public Member Functions | |
| OffsetCalculator ()=default | |
| Default constructor creating an invalid calculator. | |
| OffsetCalculator (const size_t necessaryMeasurements, const bool useSlidingWindow) | |
| Creates a new offset calculator. | |
| int64_t | domainToUnixOffsetNs (const int64_t currentDomainTimestampNs, const int64_t currentUnixTimestampNs, bool &isFinal) |
| Calculates the domain-to-unix offset based on a new pair of timestamps. | |
| size_t | measurements () const |
| Returns the number of measurements accumulated so far. | |
| bool | isValid () const |
| Returns whether this calculator is valid. | |
Protected Types | |
| using | OffsetQueue = std::deque< int64_t > |
| Definition of a double-ended queue holding offsets between the domain time and the unix time. | |
Protected Attributes | |
| int64_t | initialDomainNs_ = invalidValue_ |
| The initial domain timestamp, in nanoseconds. | |
| int64_t | initialUnixNs_ = invalidValue_ |
| The initial unix timestamp, in nanoseconds. | |
| int64_t | sumDomainToUnixOffsetNs_ = 0 |
| The measured sum of the domain to unix offsets, in nanoseconds. | |
| size_t | measurements_ = 0 |
| The number of measurements. | |
| size_t | necessaryMeasurements_ = 0 |
| The number of necessary measurements before the converter keeps the determined offset fixed. | |
| bool | useSlidingWindow_ = false |
| True, if a sliding window is used to determine the average offset; False, to determine the average offset once based on several measurements. | |
| OffsetQueue | domainToUnixOffsetQueueNs_ |
| The queue holding the domain to unix offsets, in case a sliding window is used to determine the average offset, in nanoseconds. | |
This class encapsulates the logic for calculating the offset between a domain time and unix time.
The calculator gathers timestamp pairs (domain and unix) and computes an averaged offset to reduce measurement noise. Two modes are supported:
|
protected |
Definition of a double-ended queue holding offsets between the domain time and the unix time.
|
default |
Default constructor creating an invalid calculator.
| Ocean::TimestampConverter::OffsetCalculator::OffsetCalculator | ( | const size_t | necessaryMeasurements, |
| const bool | useSlidingWindow | ||
| ) |
Creates a new offset calculator.
| necessaryMeasurements | The number of measurements necessary to determine the offset, with range [1, infinity) |
| useSlidingWindow | True, to use a sliding window for continuous offset updates; False, to fix the offset after necessaryMeasurements |
| int64_t Ocean::TimestampConverter::OffsetCalculator::domainToUnixOffsetNs | ( | const int64_t | currentDomainTimestampNs, |
| const int64_t | currentUnixTimestampNs, | ||
| bool & | isFinal | ||
| ) |
Calculates the domain-to-unix offset based on a new pair of timestamps.
This function accumulates measurements and returns the current averaged offset. In fixed mode, once the necessary number of measurements is reached, isFinal is set to true. In sliding window mode, isFinal is never set to true (the offset is continuously updated).
| currentDomainTimestampNs | The current domain timestamp, in nanoseconds |
| currentUnixTimestampNs | The current unix timestamp, in nanoseconds |
| isFinal | Output parameter set to true when the offset is finalized (only in fixed mode) |
|
inline |
Returns whether this calculator is valid.
|
inline |
Returns the number of measurements accumulated so far.
In sliding window mode, this is capped at necessaryMeasurements.
|
protected |
The queue holding the domain to unix offsets, in case a sliding window is used to determine the average offset, in nanoseconds.
|
protected |
The initial domain timestamp, in nanoseconds.
|
protected |
The initial unix timestamp, in nanoseconds.
|
protected |
The number of measurements.
|
protected |
The number of necessary measurements before the converter keeps the determined offset fixed.
|
protected |
The measured sum of the domain to unix offsets, in nanoseconds.
|
protected |
True, if a sliding window is used to determine the average offset; False, to determine the average offset once based on several measurements.