-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeClock.h
44 lines (41 loc) · 1.01 KB
/
TimeClock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "utils.h"
#include "Arduino.h"
#include "Configuration.h"
#include "DataTypes.h"
class ServerOffsetCumulativeMean{
private:
Configuration* conf;
Sample<double> lastCumulativeMean;
Sample<double> cumulativeMean;
unsigned long packets;
int successCount;
bool wasCalibratedAtLeastOnce;
public:
ServerOffsetCumulativeMean();
double updateMean(const Sample<long> serverOffsetSample);
bool isCalibrated();
long getMean();
void reset();
void expireCalculation();
};
class TimeClock: public ConfigurationObserver {
SINGLETON_H(TimeClock)
private:
Configuration* configuration;
ServerOffsetCumulativeMean serverOffsetCumulativeMean;
long correction;
bool synced;
unsigned long minimumOffset;
unsigned long expirationPeriodIndex;
int offsetExpirationExponent;
unsigned int firstInvalidPacketsQty;
void configurationChanged();
public:
TimeClock();
void setup();
bool isSynced();
bool updateServerOffset(Frame* frame);
unsigned long time();
unsigned long rawTime();
};