SDK  23.9.2
For IoT System Software Development
Public Member Functions | List of all members
BLERemoteCharacteristic Class Reference

A model of a remote BLE characteristic. More...

#include <BLERemoteCharacteristic.hpp>

Public Member Functions

 ~BLERemoteCharacteristic ()
 Destructor.
 
bool canBroadcast ()
 Does the characteristic support broadcasting? More...
 
bool canIndicate ()
 Does the characteristic support indications? More...
 
bool canNotify ()
 Does the characteristic support notifications? More...
 
bool canRead ()
 Does the characteristic support reading? More...
 
bool canWrite ()
 Does the characteristic support writing? More...
 
bool canWriteNoResponse ()
 Does the characteristic support writing with no response? More...
 
BLERemoteDescriptorgetDescriptor (BLEUUID uuid)
 Get the descriptor instance with the given UUID that belongs to this characteristic. More...
 
std::map< std::string, BLERemoteDescriptor * > * getDescriptors ()
 Retrieve the map of descriptors keyed by UUID.
 
uint16_t getHandle ()
 Get the handle for this characteristic. More...
 
BLEUUID getUUID ()
 Get the UUID for this characteristic. More...
 
std::string readValue ()
 
uint8_t readUInt8 ()
 Read a byte value. More...
 
uint16_t readUInt16 ()
 Read an unsigned 16 bit value. More...
 
uint32_t readUInt32 ()
 Read an unsigned 32 bit value. More...
 
void registerForNotify (notify_callback _callback, bool notifications=true)
 
bool writeValue (uint8_t *data, size_t length, bool response=false)
 
bool writeValue (std::string newValue, bool response=false)
 Write the new value for the characteristic. More...
 
bool writeValue (uint8_t newValue, bool response=false)
 Write the new value for the characteristic. More...
 
std::string toString ()
 Convert a BLERemoteCharacteristic to a string representation;. More...
 
uint8_t * readRawData ()
 Read raw data from remote characteristic as hex bytes. More...
 
BLERemoteServicegetRemoteService ()
 Get the remote service associated with this characteristic. More...
 

Detailed Description

A model of a remote BLE characteristic.

Member Function Documentation

◆ canBroadcast()

bool BLERemoteCharacteristic::canBroadcast ( )

Does the characteristic support broadcasting?

Returns
True if the characteristic supports broadcasting.
73  {
74  return (m_charProp & BLE_GATT_CHAR_PROP_BIT_BROADCAST) != 0;
75 } // canBroadcast

◆ canIndicate()

bool BLERemoteCharacteristic::canIndicate ( )

Does the characteristic support indications?

Returns
True if the characteristic supports indications.
82  {
83  return (m_charProp & BLE_GATT_CHAR_PROP_BIT_INDICATE) != 0;
84 } // canIndicate

◆ canNotify()

bool BLERemoteCharacteristic::canNotify ( )

Does the characteristic support notifications?

Returns
True if the characteristic supports notifications.
91  {
92  return (m_charProp & BLE_GATT_CHAR_PROP_BIT_NOTIFY) != 0;
93 } // canNotify

◆ canRead()

bool BLERemoteCharacteristic::canRead ( )

Does the characteristic support reading?

Returns
True if the characteristic supports reading.
100  {
101  return (m_charProp & BLE_GATT_CHAR_PROP_BIT_READ) != 0;
102 } // canRead

◆ canWrite()

bool BLERemoteCharacteristic::canWrite ( )

Does the characteristic support writing?

Returns
True if the characteristic supports writing.
109  {
110  return (m_charProp & BLE_GATT_CHAR_PROP_BIT_WRITE) != 0;
111 } // canWrite

◆ canWriteNoResponse()

bool BLERemoteCharacteristic::canWriteNoResponse ( )

Does the characteristic support writing with no response?

Returns
True if the characteristic supports writing with no response.
118  {
119  return (m_charProp & BLE_GATT_CHAR_PROP_BIT_WRITE_NR) != 0;
120 } // canWriteNoResponse

◆ getDescriptor()

BLERemoteDescriptor * BLERemoteCharacteristic::getDescriptor ( BLEUUID  uuid)

Get the descriptor instance with the given UUID that belongs to this characteristic.

Parameters
[in]uuidThe UUID of the descriptor to find.
Returns
The Remote descriptor (if present) or null if not present.
172  {
173  _debug_print_s(TAG, ">> getDescriptor: uuid", uuid.toString().c_str());
174 
175  std::string v = uuid.toString();
176  for (auto &myPair : m_descriptorMap) {
177  if (myPair.first == v) {
178  _debug_print(TAG, "<< getDescriptor: found");
179  return myPair.second;
180  }
181  }
182 
183  _debug_print(TAG, "<< getDescriptor: Not found");
184  return nullptr;
185 } // getDescriptor

◆ getHandle()

uint16_t BLERemoteCharacteristic::getHandle ( )

Get the handle for this characteristic.

Returns
The handle for this characteristic.
160  {
161  //ESP_LOGD(LOG_TAG, ">> getHandle: Characteristic: %s", getUUID().toString().c_str());
162  //ESP_LOGD(LOG_TAG, "<< getHandle: %d 0x%.2x", m_handle, m_handle);
163  return m_handle;
164 } // getHandle

◆ getRemoteService()

BLERemoteService * BLERemoteCharacteristic::getRemoteService ( )

Get the remote service associated with this characteristic.

Returns
The remote service associated with this characteristic.
192  {
193  return m_pRemoteService;
194 } // getRemoteService

◆ getUUID()

BLEUUID BLERemoteCharacteristic::getUUID ( )

Get the UUID for this characteristic.

Returns
The UUID for this characteristic.
201  {
202  return m_uuid;
203 } // getUUID

◆ readRawData()

uint8_t * BLERemoteCharacteristic::readRawData ( )

Read raw data from remote characteristic as hex bytes.

Returns
return pointer data read
302  {
303  return m_rawData;
304 }

◆ readUInt16()

uint16_t BLERemoteCharacteristic::readUInt16 ( )

Read an unsigned 16 bit value.

Returns
The unsigned 16 bit value.
210  {
211  std::string value = readValue();
212  if (value.length() >= 2) {
213  return *(uint16_t*)(value.data());
214  }
215  return 0;
216 } // readUInt16

◆ readUInt32()

uint32_t BLERemoteCharacteristic::readUInt32 ( )

Read an unsigned 32 bit value.

Returns
the unsigned 32 bit value.
223  {
224  std::string value = readValue();
225  if (value.length() >= 4) {
226  return *(uint32_t*)(value.data());
227  }
228  return 0;
229 } // readUInt32

◆ readUInt8()

uint8_t BLERemoteCharacteristic::readUInt8 ( )

Read a byte value.

Returns
The value as a byte
236  {
237  std::string value = readValue();
238  if (value.length() >= 1) {
239  return (uint8_t)value[0];
240  }
241  return 0;
242 } // readUInt8

◆ toString()

std::string BLERemoteCharacteristic::toString ( )

Convert a BLERemoteCharacteristic to a string representation;.

Returns
a String representation.
266  {
267  std::ostringstream ss;
268  ss << "Characteristic: uuid: " << m_uuid.toString() <<
269  ", handle: " << getHandle() << " 0x" << std::hex << getHandle() <<
270  ", props: " << " 0x" << std::hex << m_charProp;
271  return ss.str();
272 } // toString

◆ writeValue() [1/2]

bool BLERemoteCharacteristic::writeValue ( std::string  newValue,
bool  response = false 
)

Write the new value for the characteristic.

Parameters
[in]newValueThe new value to write.
[in]responseDo we expect a response?
Returns
false if not connected or cant perform write for some reason.
281  {
282  return writeValue((uint8_t*)newValue.c_str(), strlen(newValue.c_str()), response);
283 } // writeValue

◆ writeValue() [2/2]

bool BLERemoteCharacteristic::writeValue ( uint8_t  newValue,
bool  response = false 
)

Write the new value for the characteristic.

This is a convenience function. Many BLE characteristics are a single byte of data.

Parameters
[in]newValueThe new byte value to write.
[in]responseWhether we require a response from the write.
Returns
false if not connected or cant perform write for some reason.
294  {
295  return writeValue(&newValue, 1, response);
296 } // writeValue

The documentation for this class was generated from the following files:
BLERemoteCharacteristic::getHandle
uint16_t getHandle()
Get the handle for this characteristic.
Definition: BLERemoteCharacteristic.cpp:160
BLEUUID::toString
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:317