1 #include "ble_service.h" 8 namespace esp32_ble_server {
10 static const char *
const TAG =
"esp32_ble_server.service";
13 : uuid_(uuid), num_handles_(num_handles), inst_id_(inst_id), advertise_(advertise) {}
22 if (chr->get_uuid() == uuid)
41 return characteristic;
47 esp_gatt_srvc_id_t srvc_id;
48 srvc_id.is_primary =
true;
54 ESP_LOGE(TAG,
"esp_ble_gatts_create_service failed: %d", err);
71 esp_err_t err = esp_ble_gatts_delete_service(this->
handle_);
73 ESP_LOGE(TAG,
"esp_ble_gatts_delete_service failed: %d", err);
98 esp_err_t err = esp_ble_gatts_start_service(this->
handle_);
100 ESP_LOGE(TAG,
"esp_ble_gatts_start_service failed: %d", err);
116 esp_err_t err = esp_ble_gatts_stop_service(this->
handle_);
118 ESP_LOGE(TAG,
"esp_ble_gatts_stop_service failed: %d", err);
126 if (this->state_ ==
FAILED)
130 failed |= characteristic->is_failed();
134 return this->state_ ==
FAILED;
138 esp_ble_gatts_cb_param_t *param) {
140 case ESP_GATTS_CREATE_EVT: {
142 this->inst_id_ == param->create.service_id.id.inst_id) {
143 this->
handle_ = param->create.service_handle;
150 case ESP_GATTS_DELETE_EVT:
151 if (param->del.service_handle == this->handle_) {
155 case ESP_GATTS_START_EVT: {
156 if (param->start.service_handle == this->handle_) {
161 case ESP_GATTS_STOP_EVT: {
162 if (param->start.service_handle == this->handle_) {
172 characteristic->gatts_event_handler(event, gatts_if, param);
void do_create(BLEService *service)
bool do_create_characteristics_()
BLECharacteristic * last_created_characteristic_
void advertising_remove_service_uuid(ESPBTUUID uuid)
uint32_t created_characteristic_count_
esp_gatt_if_t get_gatts_if()
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
BLEService(ESPBTUUID uuid, uint16_t num_handles, uint8_t inst_id, bool advertise)
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
static ESPBTUUID from_uint16(uint16_t uuid)
void do_create(BLEServer *server)
std::vector< BLECharacteristic * > characteristics_
Implementation of SPI Controller mode.
static ESPBTUUID from_raw(const uint8_t *data)
BLECharacteristic * get_characteristic(ESPBTUUID uuid)
BLECharacteristic * create_characteristic(const std::string &uuid, esp_gatt_char_prop_t properties)
void advertising_add_service_uuid(ESPBTUUID uuid)
esp_bt_uuid_t get_uuid() const