EnigmaIOT  0.9.3
Secure sensor and gateway platform based on ESP8266 and ESP32
timeManager.h
Go to the documentation of this file.
1 
9 #ifndef _TIMEMANAGER_h
10 #define _TIMEMANAGER_h
11 
12 #include <Arduino.h>
13 
15 protected:
16  //clock_t t1, t2, t3, t4;
17  bool timeIsAdjusted = false;
18  int64_t offset = 0;
19  int64_t roundTripDelay;
20 
21 public:
26  int64_t setOrigin ();
27 
32  int64_t clock ();
33 
39  time_t unixtime () {
40  uint64_t time_sec = clock () / 1000;
41  return time_sec;
42  }
43 
52  int64_t adjustTime (int64_t t1r, int64_t t2r, int64_t t3r, int64_t t4r);
53 
58  int64_t getOffset () {
59  return offset;
60  }
61 
66  bool isTimeAdjusted () {
67  return timeIsAdjusted;
68  }
69 
74  int64_t getDelay () {
75  return roundTripDelay;
76  }
77 
81  void reset () {
82  offset = 0;
83  timeIsAdjusted = false;
84  }
85 };
86 
88 
89 #endif
90 
TimeManagerClass::isTimeAdjusted
bool isTimeAdjusted()
Gets synchronization status.
Definition: timeManager.h:66
TimeManagerClass::unixtime
time_t unixtime()
Gets local clock in seconds. It returns millis() / 1000 if not synchronized, local clock otherwise....
Definition: timeManager.h:39
TimeManagerClass::adjustTime
int64_t adjustTime(int64_t t1r, int64_t t2r, int64_t t3r, int64_t t4r)
Gets delay between Gateway time and local clock and adjust local clock accordingly....
Definition: timeManager.cpp:30
TimeManagerClass::roundTripDelay
int64_t roundTripDelay
Propagation delay between Node and Gateway.
Definition: timeManager.h:19
TimeManagerClass::getDelay
int64_t getDelay()
Gets propagation + processing delay between Node and Gateway in milliseconds.
Definition: timeManager.h:74
TimeManager
TimeManagerClass TimeManager
Definition: timeManager.cpp:51
TimeManagerClass::timeIsAdjusted
bool timeIsAdjusted
Indicates if time has been synchronized.
Definition: timeManager.h:17
TimeManagerClass::getOffset
int64_t getOffset()
Gets current offset to calculate clock, in milliseconds.
Definition: timeManager.h:58
TimeManagerClass::setOrigin
int64_t setOrigin()
Inits time synchronization getting local clock to be assigned to T1.
Definition: timeManager.cpp:12
TimeManagerClass::clock
int64_t clock()
Gets local clock. It returns millis() if not synchronized, local clock otherwise.
Definition: timeManager.cpp:20
TimeManagerClass
Definition: timeManager.h:14
TimeManagerClass::offset
int64_t offset
Offet between node millis() and gateway time.
Definition: timeManager.h:18
TimeManagerClass::reset
void reset()
Resets clock synchronization and sets values to initial status.
Definition: timeManager.h:81