forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLEService.h
99 lines (85 loc) · 3.04 KB
/
BLEService.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* BLEService.h
*
* Created on: Mar 25, 2017
* Author: kolban
*/
#ifndef COMPONENTS_CPP_UTILS_BLESERVICE_H_
#define COMPONENTS_CPP_UTILS_BLESERVICE_H_
#include "soc/soc_caps.h"
#if SOC_BLE_SUPPORTED
#include "sdkconfig.h"
#if defined(CONFIG_BLUEDROID_ENABLED)
#include <esp_gatts_api.h>
#include "BLECharacteristic.h"
#include "BLEServer.h"
#include "BLEUUID.h"
#include "RTOS.h"
class BLEServer;
/**
* @brief A data mapping used to manage the set of %BLE characteristics known to the server.
*/
class BLECharacteristicMap {
public:
void setByUUID(BLECharacteristic *pCharacteristic, const char *uuid);
void setByUUID(BLECharacteristic *pCharacteristic, BLEUUID uuid);
void setByHandle(uint16_t handle, BLECharacteristic *pCharacteristic);
BLECharacteristic *getByUUID(const char *uuid);
BLECharacteristic *getByUUID(BLEUUID uuid);
BLECharacteristic *getByHandle(uint16_t handle);
BLECharacteristic *getFirst();
BLECharacteristic *getNext();
String toString();
void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
private:
std::map<BLECharacteristic *, String> m_uuidMap;
std::map<uint16_t, BLECharacteristic *> m_handleMap;
std::map<BLECharacteristic *, String>::iterator m_iterator;
};
/**
* @brief The model of a %BLE service.
*
*/
class BLEService {
public:
void addCharacteristic(BLECharacteristic *pCharacteristic);
BLECharacteristic *createCharacteristic(const char *uuid, uint32_t properties);
BLECharacteristic *createCharacteristic(BLEUUID uuid, uint32_t properties);
void dump();
void executeCreate(BLEServer *pServer);
void executeDelete();
BLECharacteristic *getCharacteristic(const char *uuid);
BLECharacteristic *getCharacteristic(BLEUUID uuid);
BLEUUID getUUID();
BLEServer *getServer();
void start();
void stop();
String toString();
uint16_t getHandle();
uint8_t m_instId = 0;
private:
BLEService(const char *uuid, uint16_t numHandles);
BLEService(BLEUUID uuid, uint16_t numHandles);
friend class BLEServer;
friend class BLEServiceMap;
friend class BLEDescriptor;
friend class BLECharacteristic;
friend class BLEDevice;
BLECharacteristicMap m_characteristicMap;
uint16_t m_handle;
BLECharacteristic *m_lastCreatedCharacteristic = nullptr;
BLEServer *m_pServer = nullptr;
BLEUUID m_uuid;
FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
FreeRTOS::Semaphore m_semaphoreDeleteEvt = FreeRTOS::Semaphore("DeleteEvt");
FreeRTOS::Semaphore m_semaphoreStartEvt = FreeRTOS::Semaphore("StartEvt");
FreeRTOS::Semaphore m_semaphoreStopEvt = FreeRTOS::Semaphore("StopEvt");
uint16_t m_numHandles;
BLECharacteristic *getLastCreatedCharacteristic();
void handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
void setHandle(uint16_t handle);
//void setService(esp_gatt_srvc_id_t srvc_id);
}; // BLEService
#endif /* CONFIG_BLUEDROID_ENABLED */
#endif /* SOC_BLE_SUPPORTED */
#endif /* COMPONENTS_CPP_UTILS_BLESERVICE_H_ */