42 TinyCTSServer() =
default;
43 ~TinyCTSServer()
override {
end(); }
46 void setAdapter(
const char* name) { _adapterName = name; }
56 std::lock_guard<std::recursive_mutex> lock(_mutex);
61 _error =
"no Bluetooth stack";
64 if (!_peripheral->start(deviceName, _settable, _encrypted,
this, _error)) {
73 std::lock_guard<std::recursive_mutex> lock(_mutex);
74 if (_peripheral) _peripheral->stop();
86 std::lock_guard<std::recursive_mutex> lock(_mutex);
87 if (!_peripheral)
return false;
88 _peripheral->process();
96 std::lock_guard<std::recursive_mutex> lock(_mutex);
97 if (!_peripheral)
return false;
113 bool onRead(uint16_t uuid, std::vector<uint8_t>& value)
override {
114 std::lock_guard<std::recursive_mutex> lock(_mutex);
119 value.resize(localTimeValue(value.data()));
121 value.resize(referenceTimeValue(value.data()));
129 bool onWrite(uint16_t uuid,
const uint8_t* data,
size_t len)
override {
130 std::lock_guard<std::recursive_mutex> lock(_mutex);
136 notifyTime(TinyCTSCurrentTime::TimeZoneChange);
142 std::string _adapterName =
"hci0", _error;
143 std::unique_ptr<TinyCTSPeripheral> _peripheral;
144 std::recursive_mutex _mutex;
145 uint32_t _requests = 0;
Includes the Bluetooth stack of the desktop: BlueZ (Linux) is header only. CoreBluetooth (macOS) and ...
std::unique_ptr< TinyCTSPeripheral > ctsCreatePeripheral(const std::string &adapter)
Definition TinyCTSBlueZBackend.h:442
The logic of the Current Time Service server, independent of the Bluetooth stack: the values of the c...
constexpr uint16_t CTS_CURRENT_TIME_UUID
16 bit UUID of the Current Time characteristic (read, notify, write)
Definition TinyCTSTypes.h:19
constexpr uint16_t CTS_REFERENCE_TIME_INFO_UUID
16 bit UUID of the Reference Time Information characteristic (read)
Definition TinyCTSTypes.h:23
constexpr uint16_t CTS_LOCAL_TIME_INFO_UUID
16 bit UUID of the Local Time Information characteristic (read, write)
Definition TinyCTSTypes.h:21
The callbacks of a TinyCTSPeripheral: it asks the handler for the value when a client reads a charact...
Definition TinyCTSDesktop.h:74
Settings and values of a TinyCTSServer. Use TinyCTSServer, which adds the Bluetooth part.
Definition TinyCTSServerBase.h:22
bool setTimeZoneFromWrite(const uint8_t *data, size_t len)
Definition TinyCTSServerBase.h:117
bool setTimeFromWrite(const uint8_t *data, size_t len)
Definition TinyCTSServerBase.h:102
bool notifyDue()
Definition TinyCTSServerBase.h:125
size_t currentTimeValue(uint8_t reason, uint8_t *out)
Definition TinyCTSServerBase.h:84
uint32_t getRequestCount() const
The number of values that the clients have read.
Definition TinyCTSServerDesktop.h:108
void end()
Unregister the service and stop the advertising.
Definition TinyCTSServerDesktop.h:72
bool begin(TinyCTSTimeSource &source, const char *deviceName="TinyCTS")
Register the service and start the advertising.
Definition TinyCTSServerDesktop.h:55
void onTimeZoneChanged() override
Definition TinyCTSServerDesktop.h:111
const std::string & getLastError() const
The reason why begin() failed.
Definition TinyCTSServerDesktop.h:105
bool process()
Handle the requests of the clients and send the notifications. Call this regularly in loop().
Definition TinyCTSServerDesktop.h:84
bool notifyTime(uint8_t adjustReason=0)
Notify the subscribed clients now.
Definition TinyCTSServerDesktop.h:95
bool onRead(uint16_t uuid, std::vector< uint8_t > &value) override
Definition TinyCTSServerDesktop.h:113
void setAdapter(const char *name)
The Bluetooth adapter to use (Linux only, default: hci0). Call it before begin().
Definition TinyCTSServerDesktop.h:46
bool onWrite(uint16_t uuid, const uint8_t *data, size_t len) override
Definition TinyCTSServerDesktop.h:129
Abstract base class of the time sources: an object that knows the current UTC time.
Definition TinyCTSTimeSource.h:51
static constexpr size_t Size
Size of the encoded characteristic.
Definition TinyCTSTypes.h:70