11namespace esp32_ble_server {
13static const char *
const TAG =
"esp32_ble_server.descriptor";
15static RAMAllocator<uint8_t> descriptor_allocator{};
20 this->
value_.attr_max_len = max_len;
34 esp_attr_control_t control;
35 control.auto_rsp = ESP_GATT_AUTO_RSP;
37 ESP_LOGV(TAG,
"Creating descriptor - %s", this->
uuid_.
to_string().c_str());
40 this->permissions_, &this->value_, &control);
42 ESP_LOGE(TAG,
"esp_ble_gatts_add_char_descr failed: %d", err);
55 ESP_LOGE(TAG,
"Size %d too large, must be no bigger than %d",
length, this->
value_.attr_max_len);
63 esp_ble_gatts_cb_param_t *param) {
65 case ESP_GATTS_ADD_CHAR_DESCR_EVT: {
67 this->characteristic_->get_service()->get_handle() == param->add_char_descr.service_handle &&
68 this->characteristic_ == this->characteristic_->get_service()->get_last_created_characteristic()) {
69 this->
handle_ = param->add_char_descr.attr_handle;
74 case ESP_GATTS_WRITE_EVT: {
75 if (this->
handle_ != param->write.handle)
77 this->
value_.attr_len = param->write.len;
78 memcpy(this->
value_.attr_value, param->write.value, param->write.len);
80 (*this->
on_write_callback_)(std::span<const uint8_t>(param->write.value, param->write.len),
81 param->write.conn_id);
std::string to_string() const
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
esp_bt_uuid_t get_uuid() const
BLEService * get_service()
esp_gatt_perm_t permissions_
std::unique_ptr< std::function< void(std::span< const uint8_t >, uint16_t)> > on_write_callback_
void set_value(std::vector< uint8_t > &&buffer)
void set_value_impl_(const uint8_t *data, size_t length)
void do_create(BLECharacteristic *characteristic)
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
BLEDescriptor(ESPBTUUID uuid, uint16_t max_len=100, bool read=true, bool write=true)
BLECharacteristic * characteristic_
Providing packet encoding functions for exchanging data with a remote host.