Ocean
Loading...
Searching...
No Matches
Ocean::TimestampConverter::OffsetCalculator Class Reference

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.
 

Detailed Description

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:

  • Fixed mode: Accumulates measurements until the necessary count is reached, then the offset becomes final.
  • Sliding window mode: Continuously updates the offset using the most recent N measurements.

Member Typedef Documentation

◆ OffsetQueue

using Ocean::TimestampConverter::OffsetCalculator::OffsetQueue = std::deque<int64_t>
protected

Definition of a double-ended queue holding offsets between the domain time and the unix time.

Constructor & Destructor Documentation

◆ OffsetCalculator() [1/2]

Ocean::TimestampConverter::OffsetCalculator::OffsetCalculator ( )
default

Default constructor creating an invalid calculator.

◆ OffsetCalculator() [2/2]

Ocean::TimestampConverter::OffsetCalculator::OffsetCalculator ( const size_t  necessaryMeasurements,
const bool  useSlidingWindow 
)

Creates a new offset calculator.

Parameters
necessaryMeasurementsThe number of measurements necessary to determine the offset, with range [1, infinity)
useSlidingWindowTrue, to use a sliding window for continuous offset updates; False, to fix the offset after necessaryMeasurements

Member Function Documentation

◆ domainToUnixOffsetNs()

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).

Parameters
currentDomainTimestampNsThe current domain timestamp, in nanoseconds
currentUnixTimestampNsThe current unix timestamp, in nanoseconds
isFinalOutput parameter set to true when the offset is finalized (only in fixed mode)
Returns
The averaged domain-to-unix offset, in nanoseconds

◆ isValid()

bool Ocean::TimestampConverter::OffsetCalculator::isValid ( ) const
inline

Returns whether this calculator is valid.

Returns
True, if the calculator was initialized with valid parameters

◆ measurements()

size_t Ocean::TimestampConverter::OffsetCalculator::measurements ( ) const
inline

Returns the number of measurements accumulated so far.

In sliding window mode, this is capped at necessaryMeasurements.

Returns
The number of measurements

Field Documentation

◆ domainToUnixOffsetQueueNs_

OffsetQueue Ocean::TimestampConverter::OffsetCalculator::domainToUnixOffsetQueueNs_
protected

The queue holding the domain to unix offsets, in case a sliding window is used to determine the average offset, in nanoseconds.

◆ initialDomainNs_

int64_t Ocean::TimestampConverter::OffsetCalculator::initialDomainNs_ = invalidValue_
protected

The initial domain timestamp, in nanoseconds.

◆ initialUnixNs_

int64_t Ocean::TimestampConverter::OffsetCalculator::initialUnixNs_ = invalidValue_
protected

The initial unix timestamp, in nanoseconds.

◆ measurements_

size_t Ocean::TimestampConverter::OffsetCalculator::measurements_ = 0
protected

The number of measurements.

◆ necessaryMeasurements_

size_t Ocean::TimestampConverter::OffsetCalculator::necessaryMeasurements_ = 0
protected

The number of necessary measurements before the converter keeps the determined offset fixed.

◆ sumDomainToUnixOffsetNs_

int64_t Ocean::TimestampConverter::OffsetCalculator::sumDomainToUnixOffsetNs_ = 0
protected

The measured sum of the domain to unix offsets, in nanoseconds.

◆ useSlidingWindow_

bool Ocean::TimestampConverter::OffsetCalculator::useSlidingWindow_ = false
protected

True, if a sliding window is used to determine the average offset; False, to determine the average offset once based on several measurements.


The documentation for this class was generated from the following file: