33 if (_timeMs == 0)
return 0;
34 uint32_t now = TINY_CTS_MILLIS();
35 _timeMs +=
static_cast<uint32_t
>(now - _lastMillis);
45 time_t t =
static_cast<time_t
>(
getTime());
53 time_t t =
static_cast<time_t
>(
getTime()) + _info.utcOffsetMinutes() * 60;
91 bool storeCurrentTime(
const uint8_t* data,
size_t len, uint32_t startMs, uint32_t endMs) {
95 if (_timeIsLocal) ms -=
static_cast<int64_t
>(_info.utcOffsetMinutes()) * 60000;
97 _timeMs = ms +
static_cast<uint32_t
>(endMs - startMs) / 2;
102 void storeLocalInfo(
const uint8_t* data,
size_t len) {
103 TinyCTSLocalTimeInfo::decode(data, len, _info);
106 void storeReferenceInfo(
const uint8_t* data,
size_t len) {
107 TinyCTSReferenceTimeInfo::decode(data, len, _ref);
112 if (_timeIsLocal) unixMs +=
static_cast<int64_t
>(_info.utcOffsetMinutes()) * 60000;
117 bool isWanted(
const std::string& address,
const std::string& name)
const {
118 return equalsIgnoreCase(address, _device) || name == _device;
121 static bool equalsIgnoreCase(
const std::string& a,
const std::string& b) {
122 if (a.size() != b.size())
return false;
123 for (
size_t i = 0; i < a.size(); i++) {
124 if (tolower(a[i]) != tolower(b[i]))
return false;
129 std::string _device, _name, _address;
130 uint64_t _timeMs = 0;
131 uint32_t _lastMillis = 0;
132 bool _timeIsLocal =
false;
133 TinyCTSCurrentTime _current;
134 TinyCTSLocalTimeInfo _info;
135 TinyCTSReferenceTimeInfo _ref;
Time sources of the TinyCTSServer: the interface, a software clock, the system clock and an adapter f...
The data of the Bluetooth Current Time Service (CTS, 0x1805): UUIDs and the encoding of the character...
void ctsGmtime(time_t t, std::tm &tm)
gmtime_r() where it exists, gmtime_s() on Windows
Definition TinyCTSTypes.h:49
The data of a TinyCTSClient. Use TinyCTSClient, which adds the Bluetooth part.
Definition TinyCTSClientBase.h:25
std::tm getTm()
The UTC time as std::tm.
Definition TinyCTSClientBase.h:44
std::tm getLocalTm()
The local time as std::tm, with the offsets of the device.
Definition TinyCTSClientBase.h:52
const std::string & getDeviceAddress() const
The address of the device that was used.
Definition TinyCTSClientBase.h:72
uint64_t getTimeMs() override
The UTC time in ms since 1970-01-01, extrapolated since the last update.
Definition TinyCTSClientBase.h:32
size_t timeToWrite(uint64_t unixMs, uint8_t *out) const
Definition TinyCTSClientBase.h:111
const TinyCTSCurrentTime & getCurrentTime() const
The Current Time as it was sent by the device.
Definition TinyCTSClientBase.h:66
bool isWanted(const std::string &address, const std::string &name) const
Definition TinyCTSClientBase.h:117
void setTimeIsLocal(bool local)
The Current Time of the device is the local time, not UTC.
Definition TinyCTSClientBase.h:82
uint32_t getTime()
The UTC time in seconds since 1970-01-01 (0 if not known).
Definition TinyCTSClientBase.h:41
const TinyCTSReferenceTimeInfo & getReferenceTimeInfo() const
Where the time of the device comes from.
Definition TinyCTSClientBase.h:63
const std::string & getDeviceName() const
The name of the device that was used (empty before begin()).
Definition TinyCTSClientBase.h:69
const TinyCTSLocalTimeInfo & getLocalTimeInfo() const
The time zone of the device (valid after update() if it has it).
Definition TinyCTSClientBase.h:60
bool storeCurrentTime(const uint8_t *data, size_t len, uint32_t startMs, uint32_t endMs)
Definition TinyCTSClientBase.h:91
void setLocalTimeInfo(const TinyCTSLocalTimeInfo &info)
Tell the client the time zone of the device, if it does not have the Local Time Information....
Definition TinyCTSClientBase.h:79
Abstract base class of the time sources: an object that knows the current UTC time.
Definition TinyCTSTimeSource.h:51
The Current Time characteristic (0x2A2B): 10 bytes with the date and time (Exact Time 256),...
Definition TinyCTSTypes.h:68
static TinyCTSCurrentTime fromUnixMs(uint64_t unixMs, uint8_t reason=0)
The characteristic for a time in ms since 1970-01-01.
Definition TinyCTSTypes.h:90
bool toUnixMs(uint64_t &unixMs) const
The time in ms since 1970-01-01.
Definition TinyCTSTypes.h:115
static bool decode(const uint8_t *data, size_t len, TinyCTSCurrentTime &t)
Read the characteristic. Some devices send the 9 bytes of the Exact Time 256 without the adjust reaso...
Definition TinyCTSTypes.h:153
size_t encode(uint8_t *out) const
Write the 10 bytes.
Definition TinyCTSTypes.h:134
The Local Time Information characteristic (0x2A0F): the time zone and the daylight saving time (DST) ...
Definition TinyCTSTypes.h:173
The Reference Time Information characteristic (0x2A14): where the time of the server comes from,...
Definition TinyCTSTypes.h:227