9static const char *
const TAG =
"esp32_ble_server.service";
12 : uuid_(uuid), num_handles_(num_handles), inst_id_(inst_id), advertise_(advertise) {}
21 if (chr->get_uuid() == uuid)
40 return characteristic;
46 esp_gatt_srvc_id_t srvc_id;
47 srvc_id.is_primary =
true;
51 esp_err_t err = esp_ble_gatts_create_service(server->
get_gatts_if(), &srvc_id, this->num_handles_);
53 ESP_LOGE(TAG,
"esp_ble_gatts_create_service failed: %d", err);
70 esp_err_t err = esp_ble_gatts_delete_service(this->
handle_);
72 ESP_LOGE(TAG,
"esp_ble_gatts_delete_service failed: %d", err);
79 (this->last_created_characteristic_ ==
nullptr || this->last_created_characteristic_->is_created()))
97 esp_err_t err = esp_ble_gatts_start_service(this->
handle_);
99 ESP_LOGE(TAG,
"esp_ble_gatts_start_service failed: %d", err);
115 esp_err_t err = esp_ble_gatts_stop_service(this->
handle_);
117 ESP_LOGE(TAG,
"esp_ble_gatts_stop_service failed: %d", err);
125 if (this->state_ ==
FAILED)
129 failed |= characteristic->is_failed();
133 return this->state_ ==
FAILED;
137 esp_ble_gatts_cb_param_t *param) {
139 case ESP_GATTS_CREATE_EVT: {
141 this->inst_id_ == param->create.service_id.id.inst_id) {
142 this->
handle_ = param->create.service_handle;
149 case ESP_GATTS_DELETE_EVT:
150 if (param->del.service_handle == this->handle_) {
154 case ESP_GATTS_START_EVT: {
155 if (param->start.service_handle == this->handle_) {
160 case ESP_GATTS_STOP_EVT: {
161 if (param->stop.service_handle == this->handle_) {
171 characteristic->gatts_event_handler(event, gatts_if, param);
void advertising_add_service_uuid(ESPBTUUID uuid)
void advertising_remove_service_uuid(ESPBTUUID uuid)
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
static ESPBTUUID from_uint16(uint16_t uuid)
static ESPBTUUID from_raw(const uint8_t *data)
esp_bt_uuid_t get_uuid() const
void do_create(BLEService *service)
esp_gatt_if_t get_gatts_if()
BLECharacteristic * create_characteristic(const std::string &uuid, esp_gatt_char_prop_t properties)
BLEService(ESPBTUUID uuid, uint16_t num_handles, uint8_t inst_id, bool advertise)
uint32_t created_characteristic_count_
void do_create(BLEServer *server)
void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
BLECharacteristic * last_created_characteristic_
bool do_create_characteristics_()
std::vector< BLECharacteristic * > characteristics_
BLECharacteristic * get_characteristic(ESPBTUUID uuid)