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

The model of a BLE service. More...

#include <BLEService.hpp>

Public Member Functions

void addCharacteristic (BLECharacteristic *pCharacteristic)
 Add a characteristic to the service. More...
 
BLECharacteristiccreateCharacteristic (const char *uuid, uint32_t properties)
 Create a new BLE Characteristic associated with this service. More...
 
BLECharacteristiccreateCharacteristic (BLEUUID uuid, uint32_t properties)
 Create a new BLE Characteristic associated with this service. More...
 
void dump ()
 Dump details of this BLE GATT service. More...
 
void executeCreate (BLEServer *pServer)
 
void executeDelete ()
 
BLECharacteristicgetCharacteristic (const char *uuid)
 
BLECharacteristicgetCharacteristic (BLEUUID uuid)
 
BLEUUID getUUID ()
 Get the UUID of the service. More...
 
BLEServergetServer ()
 Get the BLE server associated with this service. More...
 
void start ()
 
void stop ()
 
std::string toString ()
 Return a string representation of this service. A service is defined by: More...
 
uint16_t getHandle ()
 Get the handle associated with this service. More...
 

Public Attributes

uint8_t m_instId = 0
 

Detailed Description

The model of a BLE service.

Member Function Documentation

◆ addCharacteristic()

void BLEService::addCharacteristic ( BLECharacteristic pCharacteristic)

Add a characteristic to the service.

Parameters
[in]pCharacteristicA pointer to the characteristic to be added.
115  {
116  // We maintain a mapping of characteristics owned by this service. These are managed by the
117  // BLECharacteristicMap class instance found in m_characteristicMap. We add the characteristic
118  // to the map and then ask the service to add the characteristic at the BLE level (ESP-IDF).
119 
120  _debug_print(TAG, ">> addCharacteristic()");
121  void *logCtx __attribute__((unused)) = nullptr;
122  _debug_print_s(TAG, "Adding characteristic: uuid", pCharacteristic->getUUID().toString().c_str(), &logCtx);
123  _debug_print_s(TAG, " to service", toString().c_str());
124 
125  // Check that we don't add the same characteristic twice.
126  if (m_characteristicMap.getByUUID(pCharacteristic->getUUID()) != nullptr) {
127  _debug_print(TAG, "<< Adding a new characteristic with the same UUID as a previous one");
128  //return;
129  }
130 
131  // Remember this characteristic in our map of characteristics. At this point, we can lookup by UUID
132  // but not by handle. The handle is allocated to us on the ESP_GATTS_ADD_CHAR_EVT.
133  m_characteristicMap.setByUUID(pCharacteristic, pCharacteristic->getUUID());
134 
135  _debug_print(TAG, "<< addCharacteristic()");
136 } // addCharacteristic

◆ createCharacteristic() [1/2]

BLECharacteristic * BLEService::createCharacteristic ( BLEUUID  uuid,
uint32_t  properties 
)

Create a new BLE Characteristic associated with this service.

Parameters
[in]uuid- The UUID of the characteristic.
[in]properties- The properties of the characteristic.
Returns
The new BLE characteristic.
156  {
157  BLECharacteristic* pCharacteristic = new BLECharacteristic(uuid, properties);
158  addCharacteristic(pCharacteristic);
159  return pCharacteristic;
160 } // createCharacteristic

◆ createCharacteristic() [2/2]

BLECharacteristic * BLEService::createCharacteristic ( const char *  uuid,
uint32_t  properties 
)

Create a new BLE Characteristic associated with this service.

Parameters
[in]uuid- The UUID of the characteristic.
[in]properties- The properties of the characteristic.
Returns
The new BLE characteristic.
145  {
146  return createCharacteristic(BLEUUID(uuid), properties);
147 }

◆ dump()

void BLEService::dump ( )

Dump details of this BLE GATT service.

Returns
N/A.
67  {
68  void *logCtx __attribute__((unused)) = nullptr;
69  _debug_print_s(TAG, "Service: uuid", m_uuid.toString().c_str(), &logCtx);
70  _debug_print_d(TAG, ", handle:", m_handle, &logCtx);
71  _debug_print_s(TAG, ", Characteristics", m_characteristicMap.toString().c_str(), &logCtx);
72 } // dump

◆ getHandle()

uint16_t BLEService::getHandle ( )

Get the handle associated with this service.

Returns
The handle associated with this service.
106  {
107  return m_handle;
108 } // getHandle

◆ getServer()

BLEServer * BLEService::getServer ( )

Get the BLE server associated with this service.

Returns
The BLEServer associated with this service.
204  {
205  return m_pServer;
206 } // getServer

◆ getUUID()

BLEUUID BLEService::getUUID ( )

Get the UUID of the service.

Returns
the UUID of the service.
79  {
80  return m_uuid;
81 } // getUUID

◆ toString()

std::string BLEService::toString ( )

Return a string representation of this service. A service is defined by:

  • Its UUID
  • Its handle
    Returns
    A string representation of this service.
180  {
181  std::stringstream stringStream;
182  stringStream << "UUID: " << getUUID().toString() <<
183  ", handle: 0x" << std::hex << std::setfill('0') << std::setw(2) << getHandle();
184  return stringStream.str();
185 } // toString

The documentation for this class was generated from the following files:
BLEUUID::toString
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:317
BLECharacteristic
The model of a BLE Characteristic.
Definition: BLECharacteristic.hpp:76
BLEUUID
A model of a BLE UUID.
Definition: BLEUUID.hpp:41
BLEService::toString
std::string toString()
Return a string representation of this service. A service is defined by:
Definition: BLEService.cpp:180
BLEService::getHandle
uint16_t getHandle()
Get the handle associated with this service.
Definition: BLEService.cpp:106
BLEService::addCharacteristic
void addCharacteristic(BLECharacteristic *pCharacteristic)
Add a characteristic to the service.
Definition: BLEService.cpp:115
BLECharacteristic::getUUID
BLEUUID getUUID()
Get the UUID of the characteristic.
Definition: BLECharacteristic.cpp:136
BLEService::createCharacteristic
BLECharacteristic * createCharacteristic(const char *uuid, uint32_t properties)
Create a new BLE Characteristic associated with this service.
Definition: BLEService.cpp:145
BLECharacteristicMap::getByUUID
BLECharacteristic * getByUUID(const char *uuid)
Return the characteristic by UUID.
Definition: BLECharacteristicMap.cpp:46
BLEService::getUUID
BLEUUID getUUID()
Get the UUID of the service.
Definition: BLEService.cpp:79
BLECharacteristicMap::toString
std::string toString()
Return a string representation of the characteristic map.
Definition: BLECharacteristicMap.cpp:132