2020-03-30 01:44:20 +02:00
|
|
|
/*
|
|
|
|
* NimBLERemoteCharacteristic.h
|
|
|
|
*
|
|
|
|
* Created: on Jan 27 2020
|
|
|
|
* Author H2zero
|
2020-05-14 06:03:56 +02:00
|
|
|
*
|
2020-03-30 01:44:20 +02:00
|
|
|
* Originally:
|
|
|
|
*
|
|
|
|
* BLERemoteCharacteristic.h
|
|
|
|
*
|
|
|
|
* Created on: Jul 8, 2017
|
|
|
|
* Author: kolban
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
|
|
|
|
#define COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
#if defined(CONFIG_BT_ENABLED)
|
|
|
|
|
2020-05-14 06:03:56 +02:00
|
|
|
#include "nimconfig.h"
|
|
|
|
#if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
//#include "NimBLEUUID.h"
|
|
|
|
//#include "FreeRTOS.h"
|
|
|
|
#include "NimBLERemoteService.h"
|
|
|
|
#include "NimBLERemoteDescriptor.h"
|
|
|
|
|
|
|
|
//#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class NimBLERemoteService;
|
|
|
|
class NimBLERemoteDescriptor;
|
|
|
|
|
|
|
|
|
|
|
|
typedef void (*notify_callback)(NimBLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief A model of a remote %BLE characteristic.
|
|
|
|
*/
|
|
|
|
class NimBLERemoteCharacteristic {
|
|
|
|
public:
|
|
|
|
~NimBLERemoteCharacteristic();
|
|
|
|
|
|
|
|
// Public member functions
|
|
|
|
bool canBroadcast();
|
|
|
|
bool canIndicate();
|
|
|
|
bool canNotify();
|
|
|
|
bool canRead();
|
|
|
|
bool canWrite();
|
|
|
|
bool canWriteNoResponse();
|
2020-05-10 15:21:46 +02:00
|
|
|
NimBLERemoteDescriptor* getDescriptor(const NimBLEUUID &uuid);
|
2020-03-30 01:44:20 +02:00
|
|
|
std::map<std::string, NimBLERemoteDescriptor*>* getDescriptors();
|
|
|
|
uint16_t getHandle();
|
|
|
|
uint16_t getDefHandle();
|
|
|
|
NimBLEUUID getUUID();
|
|
|
|
std::string readValue();
|
|
|
|
uint8_t readUInt8();
|
|
|
|
uint16_t readUInt16();
|
|
|
|
uint32_t readUInt32();
|
|
|
|
bool registerForNotify(notify_callback _callback, bool notifications = true, bool response = true);
|
2020-05-10 15:21:46 +02:00
|
|
|
bool writeValue(const uint8_t* data, size_t length, bool response = false);
|
|
|
|
bool writeValue(const std::string &newValue, bool response = false);
|
2020-03-30 01:44:20 +02:00
|
|
|
bool writeValue(uint8_t newValue, bool response = false);
|
|
|
|
std::string toString();
|
|
|
|
uint8_t* readRawData();
|
2020-05-08 03:47:41 +02:00
|
|
|
size_t getDataLength();
|
2020-03-30 01:44:20 +02:00
|
|
|
NimBLERemoteService* getRemoteService();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
NimBLERemoteCharacteristic(NimBLERemoteService *pRemoteservice, const struct ble_gatt_chr *chr);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
friend class NimBLEClient;
|
|
|
|
friend class NimBLERemoteService;
|
|
|
|
friend class NimBLERemoteDescriptor;
|
|
|
|
|
|
|
|
// Private member functions
|
|
|
|
void removeDescriptors();
|
|
|
|
bool retrieveDescriptors(uint16_t endHdl);
|
|
|
|
static int onReadCB(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg);
|
|
|
|
static int onWriteCB(uint16_t conn_handle, const struct ble_gatt_error *error, struct ble_gatt_attr *attr, void *arg);
|
|
|
|
void releaseSemaphores();
|
|
|
|
static int descriptorDiscCB(uint16_t conn_handle, const struct ble_gatt_error *error,
|
|
|
|
uint16_t chr_val_handle, const struct ble_gatt_dsc *dsc,
|
|
|
|
void *arg);
|
2020-05-14 06:03:56 +02:00
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
// Private properties
|
|
|
|
NimBLEUUID m_uuid;
|
|
|
|
uint8_t m_charProp;
|
|
|
|
uint16_t m_handle;
|
|
|
|
uint16_t m_defHandle;
|
|
|
|
NimBLERemoteService* m_pRemoteService;
|
|
|
|
FreeRTOS::Semaphore m_semaphoreGetDescEvt = FreeRTOS::Semaphore("GetDescEvt");
|
|
|
|
FreeRTOS::Semaphore m_semaphoreReadCharEvt = FreeRTOS::Semaphore("ReadCharEvt");
|
|
|
|
FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt");
|
|
|
|
std::string m_value;
|
2020-05-08 03:47:41 +02:00
|
|
|
uint8_t* m_rawData;
|
|
|
|
size_t m_dataLen;
|
2020-03-30 01:44:20 +02:00
|
|
|
notify_callback m_notifyCallback;
|
|
|
|
|
|
|
|
// We maintain a map of descriptors owned by this characteristic keyed by a string representation of the UUID.
|
|
|
|
std::map<std::string, NimBLERemoteDescriptor*> m_descriptorMap;
|
|
|
|
}; // BLERemoteCharacteristic
|
2020-05-14 06:03:56 +02:00
|
|
|
|
|
|
|
#endif // #if defined( CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
2020-03-30 01:44:20 +02:00
|
|
|
#endif /* CONFIG_BT_ENABLED */
|
|
|
|
#endif /* COMPONENTS_NIMBLEREMOTECHARACTERISTIC_H_ */
|