/*
* Author: Sven Gothel
* Implementation utilizes a lock free ringbuffer receiving data within its separate thread.
*
* Controlling Environment variables:
*
* - 'direct_bt.debug.gatt.data': Debug messages about detailed GATT data, see debug_data
*
*
* Returns the server-mtu if successful, otherwise 0. *
*/ uint16_t exchangeMTU(const uint16_t clientMaxMTU); public: GATTHandler(const std::shared_ptr* Returns nullptr if not found. *
*/ GATTCharacteristicRef findCharacterisicsByValueHandle(const uint16_t charValueHandle); /** * Find and return the GATTCharacterisicsDecl within given list of primary services * via given characteristic value handle. ** Returns nullptr if not found. *
*/ GATTCharacteristicRef findCharacterisicsByValueHandle(const uint16_t charValueHandle, std::vector* Returns nullptr if not found. *
*/ GATTCharacteristicRef findCharacterisicsByValueHandle(const uint16_t charValueHandle, GATTServiceRef service); /** * Discover all primary services _and_ all its characteristics declarations * including their client config. ** BT Core Spec v5.2: Vol 3, Part G GATT: 4.4.1 Discover All Primary Services *
* Method returns reference to GATTHandler internal data. */ std::vector* The internal list will be populated via {@link #discoverCompletePrimaryServices()}. *
*/ std::vector* BT Core Spec v5.2: Vol 3, Part G GATT: 4.4.1 Discover All Primary Services *
*/ bool discoverPrimaryServices(std::vector* BT Core Spec v5.2: Vol 3, Part G GATT: 4.6.1 Discover All Characteristics of a Service *
** BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.1 Characterisic Declaration Attribute Value *
*/ bool discoverCharacteristics(GATTServiceRef & service); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 4.7.1 Discover All Characteristic Descriptors */ bool discoverDescriptors(GATTServiceRef & service); /** * Generic read GATT value and long value ** If expectedLength = 0, then only one ATT_READ_REQ/RSP will be used. *
** If expectedLength < 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used until * the response returns zero. This is the default parameter. *
** If expectedLength > 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used * if required until the response returns zero. *
*/ bool readValue(const uint16_t handle, POctets & res, int expectedLength=-1); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.1 Read Characteristic Value ** BT Core Spec v5.2: Vol 3, Part G GATT: 4.8.3 Read Long Characteristic Value *
** If expectedLength = 0, then only one ATT_READ_REQ/RSP will be used. *
** If expectedLength < 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used until * the response returns zero. This is the default parameter. *
** If expectedLength > 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used * if required until the response returns zero. *
*/ bool readCharacteristicValue(const GATTCharacteristic & c, POctets & res, int expectedLength=-1); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.1 Read Characteristic Descriptor ** BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.2 Read Long Characteristic Descriptor *
** If expectedLength = 0, then only one ATT_READ_REQ/RSP will be used. *
** If expectedLength < 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used until * the response returns zero. This is the default parameter. *
** If expectedLength > 0, then long values using multiple ATT_READ_BLOB_REQ/RSP will be used * if required until the response returns zero. *
*/ bool readDescriptorValue(GATTDescriptor & cd, int expectedLength=-1); /** * Generic write GATT value and long value */ bool writeValue(const uint16_t handle, const TROOctets & value, const bool withResponse); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 4.12.3 Write Characteristic Descriptors ** BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3 Characteristic Descriptor *
** BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration *
*/ bool writeDescriptorValue(const GATTDescriptor & cd); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.3 Write Characteristic Value */ bool writeCharacteristicValue(const GATTCharacteristic & c, const TROOctets & value); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 4.9.1 Write Characteristic Value Without Response */ bool writeCharacteristicValueNoResp(const GATTCharacteristic & c, const TROOctets & value); /** * BT Core Spec v5.2: Vol 3, Part G GATT: 3.3.3.3 Client Characteristic Configuration ** Method enables notification and/or indication for the corresponding characteristic at BLE level. *
** It is recommended to utilize notification over indication, as its link-layer handshake * and higher potential bandwidth may deliver material higher performance. *
** Throws an IllegalArgumentException if the given GATTDescriptor is not a ClientCharacteristicConfiguration. *
*/ bool configNotificationIndication(GATTDescriptor & cd, const bool enableNotification, const bool enableIndication); /** * Add the given listener to the list if not already present. ** Returns true if the given listener is not element of the list and has been newly added, * otherwise false. *
*/ bool addCharacteristicListener(std::shared_ptr* Returns true if the given listener is an element of the list and has been removed, * otherwise false. *
*/ bool removeCharacteristicListener(std::shared_ptr* Returns true if the given listener is an element of the list and has been removed, * otherwise false. *
*/ bool removeCharacteristicListener(const GATTCharacteristicListener * l); /** * Remove all {@link GATTCharacteristicListener} from the list, which are associated to the given {@link GATTCharacteristic}. ** Implementation tests all listener's GATTCharacteristicListener::match(const GATTCharacteristic & characteristic) * to match with the given associated characteristic. *
* @param associatedCharacteristic the match criteria to remove any GATTCharacteristicListener from the list * @return number of removed listener. */ int removeAllAssociatedCharacteristicListener(std::shared_ptr* Returns the number of removed event listener. *
*/ int removeAllCharacteristicListener(); /** * Enable or disable sending an immediate confirmation for received indication events from the device. ** Default value is true. *
** This setting is per GATTHandler and hence per DBTDevice. *
*/ void setSendIndicationConfirmation(const bool v); /** * Returns whether sending an immediate confirmation for received indication events from the device is enabled. ** Default value is true. *
** This setting is per GATTHandler and hence per DBTDevice. *
*/ bool getSendIndicationConfirmation(); /*****************************************************/ /** Higher level semantic functionality **/ /*****************************************************/ std::shared_ptr* This method could be periodically utilized to shorten the underlying OS disconnect period * after turning the device off, which lies within 7-13s. *
** In case the device is no more reachable, disconnect will be initiated due to the occurring IO error. *
* @return {@code true} if successful, otherwise false in case no GATT services exists etc. */ bool ping(); }; } // namespace direct_bt #endif /* GATT_HANDLER_HPP_ */