3 #include "ble_descriptor.h" 10 #include <esp_gap_ble_api.h> 11 #include <esp_gatt_defs.h> 12 #include <esp_gattc_api.h> 13 #include <esp_gatts_api.h> 14 #include <esp_bt_defs.h> 15 #include <freertos/FreeRTOS.h> 16 #include <freertos/semphr.h> 19 namespace esp32_ble_server {
21 using namespace esp32_ble;
30 void set_value(
const uint8_t *data,
size_t length);
31 void set_value(std::vector<uint8_t> value);
32 void set_value(
const std::string &value);
33 void set_value(uint8_t &data);
34 void set_value(uint16_t &data);
35 void set_value(uint32_t &data);
36 void set_value(
int &data);
37 void set_value(
float &data);
38 void set_value(
double &data);
39 void set_value(
bool &data);
41 void set_broadcast_property(
bool value);
42 void set_indicate_property(
bool value);
43 void set_notify_property(
bool value);
44 void set_read_property(
bool value);
45 void set_write_property(
bool value);
46 void set_write_no_response_property(
bool value);
48 void notify(
bool notification =
true);
51 void gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
53 void on_write(
const std::function<
void(
const std::vector<uint8_t> &)> &&func) { this->on_write_ = func; }
60 std::vector<uint8_t> &
get_value() {
return this->value_; }
62 static const uint32_t PROPERTY_READ = 1 << 0;
63 static const uint32_t PROPERTY_WRITE = 1 << 1;
64 static const uint32_t PROPERTY_NOTIFY = 1 << 2;
65 static const uint32_t PROPERTY_BROADCAST = 1 << 3;
66 static const uint32_t PROPERTY_INDICATE = 1 << 4;
67 static const uint32_t PROPERTY_WRITE_NR = 1 << 5;
73 bool write_event_{
false};
77 uint16_t handle_{0xFFFF};
79 uint16_t value_read_offset_{0};
85 std::function<void(const std::vector<uint8_t> &)> on_write_;
87 esp_gatt_perm_t permissions_ = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
BLEService * get_service()
std::vector< BLEDescriptor * > descriptors_
esp_gatt_char_prop_t properties_
std::vector< uint8_t > value_
SemaphoreHandle_t set_value_lock_
std::vector< uint8_t > & get_value()
void on_write(const std::function< void(const std::vector< uint8_t > &)> &&func)
Implementation of SPI Controller mode.