Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
26 #ifndef BT_GATT_HANDLER_HPP_
27 #define BT_GATT_HANDLER_HPP_
155 std::weak_ptr<BTDevice> wbr_device;
158 const std::string deviceString;
159 std::recursive_mutex mtx_command;
168 std::mutex mtx_l2capReaderLifecycle;
169 std::condition_variable cv_l2capReaderInit;
170 pthread_t l2capReaderThreadId;
176 characteristicListenerList_t characteristicListenerList;
179 std::atomic<uint16_t> usedMTU;
181 std::shared_ptr<GattGenericAccessSvc> genericAccess =
nullptr;
183 bool validateConnected() noexcept;
185 void l2capReaderThreadImpl();
224 std::unique_ptr<const
AttPDUMsg> sendWithReply(const
AttPDUMsg & msg, const
int timeout);
232 uint16_t exchangeMTUImpl(const uint16_t clientMaxMTU, const int32_t timeout);
263 bool disconnect(
const bool disconnectDevice,
const bool ioErrorCause) noexcept;
266 inline uint16_t
getUsedMTU() const noexcept {
return usedMTU; }
322 inline std::shared_ptr<GattGenericAccessSvc>
getGenericAccess() noexcept {
return genericAccess; }
365 bool readValue(
const uint16_t handle,
POctets & res,
int expectedLength=-1);
static BTGattEnv & get() noexcept
bool writeDescriptorValue(const BTGattDesc &cd)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.3 Write Characteristic Descriptors.
int removeAllCharListener() noexcept
Remove all event listener from the list.
GATT Singleton runtime environment properties.
std::shared_ptr< BTDevice > getDeviceUnchecked() const noexcept
std::shared_ptr< GattDeviceInformationSvc > getDeviceInformation(jau::darray< BTGattServiceRef > &primServices)
jau::darray< BTGattServiceRef > & getServices() noexcept
Returns a reference of the internal kept BTGattService list.
void setSendIndicationConfirmation(const bool v)
Enable or disable sending an immediate confirmation for received indication events from the device.
bool hasIOError() const noexcept
bool readDescriptorValue(BTGattDesc &cd, int expectedLength=-1)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.1 Read Characteristic Descriptor.
Base jau environment class, merely to tag all environment settings by inheritance and hence documenta...
BTGattCharRef findCharacterisicsByValueHandle(const uint16_t charValueHandle) noexcept
Find and return the BTGattChar within internal primary services via given characteristic value handle...
const bool DEBUG_DATA
Debug all GATT Data communication.
std::shared_ptr< BTGattService > BTGattServiceRef
Read/Write L2CAP communication channel.
bool writeValue(const uint16_t handle, const TROOctets &value, const bool withResponse)
Generic write GATT value and long value.
bool discoverDescriptors(BTGattServiceRef &service)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.7.1 Discover All Characteristic Descriptors.
bool readCharacteristicValue(const BTGattChar &c, POctets &res, int expectedLength=-1)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.1 Read Characteristic Value.
std::string getStateString() const
bool readValue(const uint16_t handle, POctets &res, int expectedLength=-1)
Generic read GATT value and long value.
std::shared_ptr< BTDevice > getDeviceChecked() const
std::shared_ptr< BTGattChar > BTGattCharRef
Handles the Attribute Protocol (ATT) using Protocol Data Unit (PDU) encoded messages over L2CAP chann...
const int32_t GATT_WRITE_COMMAND_REPLY_TIMEOUT
Timeout for GATT write command replies, defaults to 500ms.
BTGattChar event listener for notification and indication events.
uint16_t getServerMTU() const noexcept
Generic Access Service is a mandatory GATT service all peripherals are required to implement.
bool ping()
Issues a ping to the device, validating whether it is still reachable.
const int32_t ATTPDU_RING_CAPACITY
Medium ringbuffer capacity, defaults to 128 messages.
Ring buffer implementation, a.k.a circular buffer, exposing lock-free get*(..) and put*(....
Implementation of a Copy-On-Write (CoW) using jau::darray as the underlying storage,...
bool writeCharacteristicValueNoResp(const BTGattChar &c, const TROOctets &value)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response.
bool addCharListener(std::shared_ptr< BTGattCharListener > l)
Add the given listener to the list if not already present.
A thread safe GATT handler associated to one device via one L2CAP connection.
uint16_t getUsedMTU() const noexcept
Transient read only octet data, i.e.
std::string getStateString() const noexcept
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
bool getSendIndicationConfirmation() noexcept
Returns whether sending an immediate confirmation for received indication events from the device is e...
std::shared_ptr< GattGenericAccessSvc > getGenericAccess() noexcept
Returns the internal kept shared GattGenericAccessSvc instance.
bool isConnected() const noexcept
bool writeCharacteristicValue(const BTGattChar &c, const TROOctets &value)
BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value.
int removeAllAssociatedCharListener(std::shared_ptr< BTGattChar > associatedChar) noexcept
Remove all BTGattCharListener from the list, which are associated to the given BTGattChar.
bool discoverPrimaryServices(std::shared_ptr< BTGattHandler > shared_this, jau::darray< BTGattServiceRef > &result)
Discover all primary services only.
bool disconnect(const bool disconnectDevice, const bool ioErrorCause) noexcept
Disconnect this BTGattHandler and optionally the associated device.
Persistent octet data, i.e.
const int32_t GATT_READ_COMMAND_REPLY_TIMEOUT
Timeout for GATT read command replies, defaults to 500ms.
bool configNotificationIndication(BTGattDesc &cd, const bool enableNotification, const bool enableIndication)
BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration.
const int32_t GATT_INITIAL_COMMAND_REPLY_TIMEOUT
Timeout for l2cap initial command reply, defaults to 2500ms.
static constexpr int number(const Defaults d)
BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3 Characteristic Descriptor.
jau::darray< BTGattServiceRef > & discoverCompletePrimaryServices(std::shared_ptr< BTGattHandler > shared_this)
Discover all primary services and all its characteristics declarations including their client config.
bool removeCharListener(std::shared_ptr< BTGattCharListener > l) noexcept
Remove the given listener from the list.
bool discoverCharacteristics(BTGattServiceRef &service)
Discover all characteristics of a service and declaration attributes only.