ESP32  1.0.4
BLEDescriptor クラス

A model of a BLE descriptor. [詳解]

#include <BLEDescriptor.h>

BLEDescriptor の継承関係図
BLE2902 BLE2904

公開メンバ関数

 BLEDescriptor (const char *uuid, uint16_t max_len=100)
 BLEDescriptor constructor. [詳解]
 
 BLEDescriptor (BLEUUID uuid, uint16_t max_len=100)
 BLEDescriptor constructor. [詳解]
 
virtual ~BLEDescriptor ()
 BLEDescriptor destructor. [詳解]
 
uint16_t getHandle ()
 Get the BLE handle for this descriptor. [詳解]
 
size_t getLength ()
 Get the length of the value of this descriptor. [詳解]
 
BLEUUID getUUID ()
 Get the UUID of the descriptor. [詳解]
 
uint8_tgetValue ()
 Get the value of this descriptor. [詳解]
 
void handleGATTServerEvent (esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
 Handle GATT server events for the descripttor. [詳解]
 
void setAccessPermissions (esp_gatt_perm_t perm)
 
void setCallbacks (BLEDescriptorCallbacks *pCallbacks)
 Set the callback handlers for this descriptor. [詳解]
 
void setValue (uint8_t *data, size_t size)
 Set the value of the descriptor. [詳解]
 
void setValue (std::string value)
 Set the value of the descriptor. [詳解]
 
std::string toString ()
 Return a string representation of the descriptor. [詳解]
 

フレンド

class BLEDescriptorMap
 
class BLECharacteristic
 

詳解

A model of a BLE descriptor.

BLEDescriptor.h25 行目に定義があります。

構築子と解体子

◆ BLEDescriptor() [1/2]

BLEDescriptor::BLEDescriptor ( const char *  uuid,
uint16_t  max_len = 100 
)

BLEDescriptor constructor.

BLEDescriptor.cpp26 行目に定義があります。

26  : BLEDescriptor(BLEUUID(uuid), len) {
27 }
A model of a BLE UUID.
Definition: BLEUUID.h:18
BLEDescriptor(const char *uuid, uint16_t max_len=100)
BLEDescriptor constructor.

◆ BLEDescriptor() [2/2]

BLEDescriptor::BLEDescriptor ( BLEUUID  uuid,
uint16_t  max_len = 100 
)

BLEDescriptor constructor.

BLEDescriptor.cpp32 行目に定義があります。

32  {
33  m_bleUUID = uuid;
34  m_value.attr_len = 0; // Initial length is 0.
35  m_value.attr_max_len = max_len; // Maximum length of the data.
36  m_handle = NULL_HANDLE; // Handle is initially unknown.
37  m_pCharacteristic = nullptr; // No initial characteristic.
38  m_pCallback = nullptr; // No initial callback.
39 
40  m_value.attr_value = (uint8_t*) malloc(max_len); // Allocate storage for the value.
41 } // BLEDescriptor
uint8_t * attr_value
uint16_t attr_max_len
#define NULL_HANDLE
__uint8_t uint8_t
Definition: stdint.h:21

◆ ~BLEDescriptor()

BLEDescriptor::~BLEDescriptor ( )
virtual

BLEDescriptor destructor.

BLEDescriptor.cpp47 行目に定義があります。

47  {
48  free(m_value.attr_value); // Release the storage we created in the constructor.
49 } // ~BLEDescriptor
uint8_t * attr_value

関数詳解

◆ getHandle()

uint16_t BLEDescriptor::getHandle ( )

Get the BLE handle for this descriptor.

戻り値
The handle for this descriptor.

BLEDescriptor.cpp89 行目に定義があります。

89  {
90  return m_handle;
91 } // getHandle

◆ getLength()

size_t BLEDescriptor::getLength ( )

Get the length of the value of this descriptor.

戻り値
The length (in bytes) of the value of this descriptor.

BLEDescriptor.cpp98 行目に定義があります。

98  {
99  return m_value.attr_len;
100 } // getLength

◆ getUUID()

BLEUUID BLEDescriptor::getUUID ( )

Get the UUID of the descriptor.

BLEDescriptor.cpp106 行目に定義があります。

106  {
107  return m_bleUUID;
108 } // getUUID

◆ getValue()

uint8_t * BLEDescriptor::getValue ( )

Get the value of this descriptor.

戻り値
A pointer to the value of this descriptor.

BLEDescriptor.cpp116 行目に定義があります。

116  {
117  return m_value.attr_value;
118 } // getValue
uint8_t * attr_value

◆ handleGATTServerEvent()

void BLEDescriptor::handleGATTServerEvent ( esp_gatts_cb_event_t  event,
esp_gatt_if_t  gatts_if,
esp_ble_gatts_cb_param_t param 
)

Handle GATT server events for the descripttor.

引数
[in]event
[in]gatts_if
[in]param

BLEDescriptor.cpp127 行目に定義があります。

130  {
131  switch (event) {
132  // ESP_GATTS_ADD_CHAR_DESCR_EVT
133  //
134  // add_char_descr:
135  // - esp_gatt_status_t status
136  // - uint16_t attr_handle
137  // - uint16_t service_handle
138  // - esp_bt_uuid_t char_uuid
140  if (m_pCharacteristic != nullptr &&
141  m_bleUUID.equals(BLEUUID(param->add_char_descr.descr_uuid)) &&
142  m_pCharacteristic->getService()->getHandle() == param->add_char_descr.service_handle &&
143  m_pCharacteristic == m_pCharacteristic->getService()->getLastCreatedCharacteristic()) {
144  setHandle(param->add_char_descr.attr_handle);
145  m_semaphoreCreateEvt.give();
146  }
147  break;
148  } // ESP_GATTS_ADD_CHAR_DESCR_EVT
149 
150  // ESP_GATTS_WRITE_EVT - A request to write the value of a descriptor has arrived.
151  //
152  // write:
153  // - uint16_t conn_id
154  // - uint16_t trans_id
155  // - esp_bd_addr_t bda
156  // - uint16_t handle
157  // - uint16_t offset
158  // - bool need_rsp
159  // - bool is_prep
160  // - uint16_t len
161  // - uint8_t *value
162  case ESP_GATTS_WRITE_EVT: {
163  if (param->write.handle == m_handle) {
164  setValue(param->write.value, param->write.len); // Set the value of the descriptor.
165 
166  if (m_pCallback != nullptr) { // We have completed the write, if there is a user supplied callback handler, invoke it now.
167  m_pCallback->onWrite(this); // Invoke the onWrite callback handler.
168  }
169  } // End of ... this is our handle.
170 
171  break;
172  } // ESP_GATTS_WRITE_EVT
173 
174  // ESP_GATTS_READ_EVT - A request to read the value of a descriptor has arrived.
175  //
176  // read:
177  // - uint16_t conn_id
178  // - uint32_t trans_id
179  // - esp_bd_addr_t bda
180  // - uint16_t handle
181  // - uint16_t offset
182  // - bool is_long
183  // - bool need_rsp
184  //
185  case ESP_GATTS_READ_EVT: {
186  if (param->read.handle == m_handle) { // If this event is for this descriptor ... process it
187 
188  if (m_pCallback != nullptr) { // If we have a user supplied callback, invoke it now.
189  m_pCallback->onRead(this); // Invoke the onRead callback method in the callback handler.
190  }
191 
192  } // End of this is our handle
193  break;
194  } // ESP_GATTS_READ_EVT
195 
196  default:
197  break;
198  } // switch event
199 } // handleGATTServerEvent
A model of a BLE UUID.
Definition: BLEUUID.h:18
struct esp_ble_gatts_cb_param_t::gatts_read_evt_param read
virtual void onWrite(BLEDescriptor *pDescriptor)
Callback function to support a write request.
void give()
Give a semaphore. The Semaphore is given.
Definition: FreeRTOS.cpp:142
struct esp_ble_gatts_cb_param_t::gatts_add_char_descr_evt_param add_char_descr
uint16_t getHandle()
Get the handle associated with this service.
Definition: BLEService.cpp:208
bool equals(BLEUUID uuid)
Compare a UUID against this UUID.
Definition: BLEUUID.cpp:219
virtual void onRead(BLEDescriptor *pDescriptor)
Callback function to support a read request.
void setValue(uint8_t *data, size_t size)
Set the value of the descriptor.
struct esp_ble_gatts_cb_param_t::gatts_write_evt_param write
null_event event
Definition: event.hpp:36

◆ setAccessPermissions()

void BLEDescriptor::setAccessPermissions ( esp_gatt_perm_t  perm)

BLEDescriptor.cpp249 行目に定義があります。

249  {
250  m_permissions = perm;
251 }

◆ setCallbacks()

void BLEDescriptor::setCallbacks ( BLEDescriptorCallbacks pCallback)

Set the callback handlers for this descriptor.

引数
[in]pCallbacksAn instance of a callback structure used to define any callbacks for the descriptor.

BLEDescriptor.cpp206 行目に定義があります。

206  {
207  log_v(">> setCallbacks: 0x%x", (uint32_t) pCallback);
208  m_pCallback = pCallback;
209  log_v("<< setCallbacks");
210 } // setCallbacks
__uint32_t uint32_t
Definition: stdint.h:45
#define log_v(format,...)
Definition: esp32-hal-log.h:84

◆ setValue() [1/2]

void BLEDescriptor::setValue ( uint8_t data,
size_t  length 
)

Set the value of the descriptor.

引数
[in]dataThe data to set for the descriptor.
[in]lengthThe length of the data in bytes.

BLEDescriptor.cpp231 行目に定義があります。

231  {
233  log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);
234  return;
235  }
236  m_value.attr_len = length;
237  memcpy(m_value.attr_value, data, length);
238 } // setValue
uint8_t * attr_value
#define ESP_GATT_MAX_ATTR_LEN
GATT maximum attribute length
#define log_e(format,...)
char const int length
Definition: cJSON.h:161

◆ setValue() [2/2]

void BLEDescriptor::setValue ( std::string  value)

Set the value of the descriptor.

引数
[in]valueThe value of the descriptor in string form.

BLEDescriptor.cpp245 行目に定義があります。

245  {
246  setValue((uint8_t*) value.data(), value.length());
247 } // setValue
const char *const const char *const const cJSON *const value
Definition: cJSON_Utils.h:42
void setValue(uint8_t *data, size_t size)
Set the value of the descriptor.
__uint8_t uint8_t
Definition: stdint.h:21

◆ toString()

std::string BLEDescriptor::toString ( void  )

Return a string representation of the descriptor.

戻り値
A string representation of the descriptor.

BLEDescriptor.cpp257 行目に定義があります。

257  {
258  char hex[5];
259  snprintf(hex, sizeof(hex), "%04x", m_handle);
260  std::string res = "UUID: " + m_bleUUID.toString() + ", handle: 0x" + hex;
261  return res;
262 } // toString
const char *const string
Definition: cJSON.h:170
std::string toString()
Get a string representation of the UUID.
Definition: BLEUUID.cpp:350

フレンドと関連関数の詳解

◆ BLECharacteristic

friend class BLECharacteristic
friend

BLEDescriptor.h49 行目に定義があります。

◆ BLEDescriptorMap

friend class BLEDescriptorMap
friend

BLEDescriptor.h48 行目に定義があります。


このクラス詳解は次のファイルから抽出されました: