EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timeManager.h
Go to the documentation of this file.
1 
9 #ifndef _TIMEMANAGER_h
10 #define _TIMEMANAGER_h
11 
12 #include <Arduino.h>
13 #include "sys/time.h"
14 
16 protected:
17  bool timeIsAdjusted = false;
18  int64_t offset = 0;
19  int64_t roundTripDelay;
20 
21 public:
26  int64_t clock ();
27 
32  int64_t clock_us ();
33 
34 
40  time_t unixtime () {
41  uint64_t time_sec = clock () / 1000000L;
42  return time_sec;
43  }
44 
53  int64_t adjustTime (int64_t t1r, int64_t t2r, int64_t t3r, int64_t t4r);
54 
59  int64_t getOffset () {
60  return offset;
61  }
62 
67  bool isTimeAdjusted () {
68  return timeIsAdjusted;
69  }
70 
75  int64_t getDelay () {
76  return roundTripDelay;
77  }
78 
82  void reset () {
83  offset = 0;
84  timeIsAdjusted = false;
85  }
86 };
87 
89 
90 #endif
91 
TimeManagerClass::clock_us
int64_t clock_us()
Gets local clock.
Definition: timeManager.cpp:23
TimeManagerClass::isTimeAdjusted
bool isTimeAdjusted()
Gets synchronization status.
Definition: timeManager.h:67
TimeManagerClass::unixtime
time_t unixtime()
Gets local clock in seconds. It returns millis() / 1000 if not synchronized, local clock otherwise....
Definition: timeManager.h:40
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:34
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:75
TimeManager
TimeManagerClass TimeManager
Definition: timeManager.cpp:65
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:59
TimeManagerClass::clock
int64_t clock()
Gets local clock.
Definition: timeManager.cpp:12
TimeManagerClass
Definition: timeManager.h:15
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:82