TinyCTS
Bluetooth Current Time Service client and server for Arduino
Loading...
Searching...
No Matches
tiny_cts::TinyCTSCurrentTime Class Reference

The Current Time characteristic (0x2A2B): 10 bytes with the date and time (Exact Time 256), the day of week, fractions of a second and the reason for the last adjustment. More...

#include <TinyCTSTypes.h>

Public Types

enum  AdjustReason : uint8_t { ManualUpdate = 1 , ExternalReference = 2 , TimeZoneChange = 4 , DstChange = 8 }
 Bits of adjustReason.

Public Member Functions

size_t encode (uint8_t *out) const
 Write the 10 bytes.
bool toUnixMs (uint64_t &unixMs) const
 The time in ms since 1970-01-01.

Static Public Member Functions

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 reason: this is accepted.
static TinyCTSCurrentTime fromUnixMs (uint64_t unixMs, uint8_t reason=0)
 The characteristic for a time in ms since 1970-01-01.

Public Attributes

uint8_t adjustReason = 0
 bits of AdjustReason
uint8_t day = 0
 1-31, 0 = unknown
uint8_t dayOfWeek = 0
 1 = Monday ... 7 = Sunday, 0 = unknown
uint8_t fractions256 = 0
 1/256 seconds
uint8_t hours = 0
 0-23
uint8_t minutes = 0
 0-59
uint8_t month = 0
 1-12, 0 = unknown
uint8_t seconds = 0
 0-59
uint16_t year = 0
 1582-9999, 0 = unknown

Static Public Attributes

static constexpr size_t Size = 10
 Size of the encoded characteristic.

Detailed Description

The Current Time characteristic (0x2A2B): 10 bytes with the date and time (Exact Time 256), the day of week, fractions of a second and the reason for the last adjustment.

Use fromUnixMs() and toUnixMs() to convert from and to the time in milliseconds since 1970-01-01. The conversion does not use the time zone: it is up to the user of the library if the date and time are UTC (default) or the local time (see TinyCTSServer::setTimeIsLocal()).

Member Function Documentation

◆ decode()

bool tiny_cts::TinyCTSCurrentTime::decode ( const uint8_t * data,
size_t len,
TinyCTSCurrentTime & t )
inlinestatic

Read the characteristic. Some devices send the 9 bytes of the Exact Time 256 without the adjust reason: this is accepted.

Returns
false if the data is too short.

◆ encode()

size_t tiny_cts::TinyCTSCurrentTime::encode ( uint8_t * out) const
inline

Write the 10 bytes.

Returns
10

◆ toUnixMs()

bool tiny_cts::TinyCTSCurrentTime::toUnixMs ( uint64_t & unixMs) const
inline

The time in ms since 1970-01-01.

Parameters
unixMsResult
Returns
false if the date is unknown or invalid (before 1970 included).

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