8000 Changes from BLE to BLEDevice() ... #33 · copercini/esp32-snippets@fcd3276 · GitHub
[go: up one dir, main page]

Skip to content

Commit fcd3276

Browse files
committed
Changes from BLE to BLEDevice() ... nkolban#33
1 parent b4c514a commit fcd3276

17 files changed

+54
-76
lines changed

cpp_utils/BLECharacteristic.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ static const char* LOG_TAG = "BLECharacteristic";
2929
* @param [in] uuid - UUID (const char*) for the characteristic.
3030
* @param [in] properties - Properties for the characteristic.
3131
*/
32-
BLECharacteristic::BLECharacteristic(const char* uuid, uint32_t properties) {
33-
BLECharacteristic(BLEUUID(uuid), properties);
32+
BLECharacteristic::BLECharacteristic(const char* uuid, uint32_t properties) : BLECharacteristic(BLEUUID(uuid), properties) {
3433
}
3534

3635
/ 8000 **

cpp_utils/BLEClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BLEClient {
3838
std::string toString();
3939

4040
private:
41-
friend class BLE;
41+
friend class BLEDevice;
4242
friend class BLERemoteCharacteristic;
4343
friend class BLERemoteService;
4444

cpp_utils/BLEDescriptor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ static const char* LOG_TAG = "BLEDescriptor";
2626
/**
2727
* @brief BLEDescriptor constructor.
2828
*/
29-
BLEDescriptor::BLEDescriptor(const char* uuid) {
30-
BLEDescriptor(BLEUUID(uuid));
29+
BLEDescriptor::BLEDescriptor(const char* uuid) : BLEDescriptor(BLEUUID(uuid)) {
3130
}
31+
3232
/**
3333
* @brief BLEDescriptor constructor.
3434
*/

cpp_utils/BLE.cpp renamed to cpp_utils/BLEDevice.cpp

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
#include <sstream>
2222
#include <iomanip>
2323

24-
#include "BLE.h"
24+
#include "BLEDevice.h"
2525
#include "BLEClient.h"
2626
#include "BLEUtils.h"
2727
#include "GeneralUtils.h"
2828

2929
static const char* LOG_TAG = "BLE";
3030

31-
BLEServer *BLE::m_bleServer = nullptr;
32-
BLEScan *BLE::m_pScan = nullptr;
33-
BLEClient *BLE::m_pClient = nullptr;
31+
BLEServer *BLEDevice::m_bleServer = nullptr;
32+
BLEScan *BLEDevice::m_pScan = nullptr;
33+
BLEClient *BLEDevice::m_pClient = nullptr;
3434

3535
#include <esp_gattc_api.h>
3636

3737

38-
BLEClient* BLE::createClient() {
38+
BLEClient* BLEDevice::createClient() {
3939
m_pClient = new BLEClient();
4040
return m_pClient;
4141
} // createClient
@@ -48,7 +48,7 @@ BLEClient* BLE::createClient() {
4848
* @param [in] gatts_if
4949
* @param [in] param
5050
*/
51-
void BLE::gattServerEventHandler(
51+
void BLEDevice::gattServerEventHandler(
5252
esp_gatts_cb_event_t event,
5353
esp_gatt_if_t gatts_if,
5454
esp_ble_gatts_cb_param_t *param
@@ -57,8 +57,8 @@ void BLE::gattServerEventHandler(
5757
gatts_if,
5858
BLEUtils::gattServerEventTypeToString(event).c_str());
5959
BLEUtils::dumpGattServerEvent(event, gatts_if, param);
60-
if (BLE::m_bleServer != nullptr) {
61-
BLE::m_bleServer->handleGATTServerEvent(event, gatts_if, param);
60+
if (BLEDevice::m_bleServer != nullptr) {
61+
BLEDevice::m_bleServer->handleGATTServerEvent(event, gatts_if, param);
6262
}
6363
} // gattServerEventHandler
6464

@@ -76,7 +76,7 @@ void BLE::gattServerEventHandler(
7676
* @param [in] gattc_if
7777
* @param [in] param
7878
*/
79-
void BLE::gattClientEventHandler(
79+
void BLEDevice::gattClientEventHandler(
8080
esp_gattc_cb_event_t event,
8181
esp_gatt_if_t gattc_if,
8282
esp_ble_gattc_cb_param_t *param) {
@@ -92,8 +92,8 @@ void BLE::gattClientEventHandler(
9292
} // switch
9393

9494
// If we have a client registered, call it.
95-
if (BLE::m_pClient != nullptr) {
96-
BLE::m_pClient->gattClientEventHandler(event, gattc_if, param);
95+
if (BLEDevice::m_pClient != nullptr) {
96+
BLEDevice::m_pClient->gattClientEventHandler(event, gattc_if, param);
9797
}
9898

9999
} // gattClientEventHandler
@@ -102,7 +102,7 @@ void BLE::gattClientEventHandler(
102102
/**
103103
* @brief Handle GAP events.
104104
*/
105-
void BLE::gapEventHandler(
105+
void BLEDevice::gapEventHandler(
106106
esp_gap_ble_cb_event_t event,
107107
esp_ble_gap_cb_param_t *param) {
108108

@@ -122,17 +122,21 @@ void BLE::gapEventHandler(
122122
}
123123
} // switch
124124

125-
if (BLE::m_bleServer != nullptr) {
126-
BLE::m_bleServer->handleGAPEvent(event, param);
125+
if (BLEDevice::m_bleServer != nullptr) {
126+
BLEDevice::m_bleServer->handleGAPEvent(event, param);
127127
}
128128

129-
if (BLE::m_pScan != nullptr) {
130-
BLE::getScan()->gapEventHandler(event, param);
129+
if (BLEDevice::m_pScan != nullptr) {
130+
BLEDevice::getScan()->gapEventHandler(event, param);
131131
}
132132
} // gapEventHandler
133133

134134

135-
static void commonInit() {
135+
/**
136+
* @brief Initialize the %BLE environment.
137+
* @param deviceName The device name of the device.
138+
*/
139+
void BLEDevice::init(std::string deviceName) {
136140
esp_err_t errRc = ::nvs_flash_init();
137141
if (errRc != ESP_OK) {
138142
ESP_LOGE(LOG_TAG, "nvs_flash_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
@@ -163,22 +167,20 @@ static void commonInit() {
163167
ESP_LOGE(LOG_TAG, "esp_bluedroid_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
164168
return;
165169
}
166-
} // commonInit
167170

168-
/**
169-
* @brief Initialize the server %BLE environment.
170-
*
171-
*/
172-
void BLE::initServer(std::string deviceName) {
173-
commonInit();
174-
175-
esp_err_t errRc = esp_ble_gap_register_callback(BLE::gapEventHandler);
171+
errRc = esp_ble_gap_register_callback(BLEDevice::gapEventHandler);
176172
if (errRc != ESP_OK) {
177173
ESP_LOGE(LOG_TAG, "esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
178174
return;
179175
}
180176

181-
errRc = esp_ble_gatts_register_callback(BLE::gattServerEventHandler);
177+
errRc = esp_ble_gattc_register_callback(BLEDevice::gattClientEventHandler);
178+
if (errRc != ESP_OK) {
179+
ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
180+
return;
181+
}
182+
183+
errRc = esp_ble_gatts_register_callback(BLEDevice::gattServerEventHandler);
182184
if (errRc != ESP_OK) {
183185
ESP_LOGE(LOG_TAG, "esp_ble_gatts_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
184186
return;
@@ -197,36 +199,15 @@ void BLE::initServer(std::string deviceName) {
197199
return;
198200
};
199201

200-
return;
201-
} // initServer
202-
203-
204-
/**
205-
* @brief Initialize the client %BLE environment.
206-
*/
207-
void BLE::initClient() {
208-
commonInit();
209-
210-
esp_err_t errRc = esp_ble_gap_register_callback(BLE::gapEventHandler);
211-
if (errRc != ESP_OK) {
212-
ESP_LOGE(LOG_TAG, "esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
213-
return;
214-
}
215-
216-
errRc = esp_ble_gattc_register_callback(BLE::gattClientEventHandler);
217-
if (errRc != ESP_OK) {
218-
ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
219-
return;
220-
}
202+
} // init
221203

222-
} // initClient
223204

224205

225206
/**
226207
* @brief Retrieve the Scan object that we use for scanning.
227208
* @return The scanning object reference.
228209
*/
229-
BLEScan* BLE::getScan() {
210+
BLEScan* BLEDevice::getScan() {
230211
if (m_pScan == nullptr) {
231212
m_pScan = new BLEScan 1241 ();
232213
}

cpp_utils/BLE.h renamed to cpp_utils/BLEDevice.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* BLE.h
2+
* BLEDevice.h
33
*
44
* Created on: Mar 16, 2017
55
* Author: kolban
66
*/
77

8-
#ifndef MAIN_BLE_H_
9-
#define MAIN_BLE_H_
8+
#ifndef MAIN_BLEDevice_H_
9+
#define MAIN_BLEDevice_H_
1010
#include "sdkconfig.h"
1111
#if defined(CONFIG_BT_ENABLED)
1212
#include <esp_gap_ble_api.h> // ESP32 BLE
@@ -22,13 +22,12 @@
2222
/**
2323
* @brief %BLE functions.
2424
*/
25-
class BLE {
25+
class BLEDevice {
2626
public:
2727
static void dumpDevices();
2828
static BLEClient *createClient();
2929

30-
static void initClient();
31-
static void initServer(std::string deviceName);
30+
static void init(std::string deviceName);
3231
//static void scan(int duration, esp_ble_scan_type_t scan_type = BLE_SCAN_TYPE_PASSIVE);
3332
static BLEScan *getScan();
3433
static BLEServer *m_bleServer;
@@ -52,4 +51,4 @@ class BLE {
5251
}; // class BLE
5352

5453
#endif // CONFIG_BT_ENABLED
55-
#endif /* MAIN_BLE_H_ */
54+
#endif /* MAIN_BLEDevice_H_ */

cpp_utils/BLEScan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BLEScan {
4848
void stop();
4949

5050
private:
51-
friend class BLE;
51+
friend class BLEDevice;
5252
void gapEventHandler(
5353
esp_gap_ble_cb_event_t event,
5454
esp_ble_gap_cb_param_t* param);

cpp_utils/BLEServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <esp_bt_main.h>
1313
#include <esp_gap_ble_api.h>
1414
#include <esp_gatts_api.h>
15-
#include "BLE.h"
15+
#include "BLEDevice.h"
1616
#include "BLEServer.h"
1717
#include "BLEService.h"
1818
#include "BLEUtils.h"
@@ -35,7 +35,7 @@ BLEServer::BLEServer() {
3535
m_gatts_if = -1;
3636
m_connectedCount = 0;
3737
m_connId = -1;
38-
BLE::m_bleServer = this;
38+
BLEDevice::m_bleServer = this;
3939
m_pServerCallbacks = nullptr;
4040

4141
createApp(0);

cpp_utils/BLEServer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BLEServer {
6565
private:
6666
friend class BLEService;
6767
friend class BLECharacteristic;
68-
friend class BLE;
68+
friend class BLEDevice;
6969
esp_ble_adv_data_t m_adv_data;
7070
uint16_t m_appId;
7171
BLEAdvertising m_bleAdvertising;

cpp_utils/BLEService.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ static const char* LOG_TAG = "BLEService"; // Tag for logging.
3030
* @brief Construct an instance of the BLEService
3131
* @param [in] uuid The UUID of the service.
3232
*/
33-
BLEService::BLEService(const char* uuid) {
34-
BLEService(BLEUUID(uuid));
33+
BLEService::BLEService(const char* uuid) : BLEService(BLEUUID(uuid)) {
3534
}
3635

3736

cpp_utils/tests/BLE Tests/Sample-MLE-15.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "BLE.h"
21
#include "BLEUtils.h"
32
#include "BLEScan.h"
43
#include <esp_log.h>
54
#include <string>
65

6+
#include "../../BLEDevice.h"
77
#include "BLEAdvertisedDevice.h"
88
#include "BLEClient.h"
99
#include "sdkconfig.h"

cpp_utils/tests/BLE Tests/Sample1.cpp

Lines changed: 1 addition & 1 deletion

cpp_utils/tests/BLE Tests/SampleClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "BLE.h"
21
#include "BLEUtils.h"
32
#include "BLEServer.h"
43
#include <esp_log.h>
54
#include <string>
65

6+
#include "../../BLEDevice.h"
77
#include "sdkconfig.h"
88

99
// See the following for generating UUIDs:
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#include <string>
33
#include <sstream>
44
#include <sys/time.h>
5+
#include "../../BLEDevice.h"
56

6-
#include "BLE.h"
77
#include "BLEAdvertisedDevice.h"
88
#include "BLEClient.h"
99
#include "BLEScan.h"

cpp_utils/tests/BLE Tests/SampleNotify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <string>
2424
#include <sstream>
2525
#include <sys/time.h>
26+
#include "../../BLEDevice.h"
2627

27-
#include "BLE.h"
2828
#include "BLEServer.h"
2929
#include "BLEUtils.h"
3030
#include "BLE2902.h"

cpp_utils/tests/BLE Tests/SampleRead.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "BLE.h"
21
#include "BLEUtils.h"
32
#include "BLEServer.h"
43
#include <esp_log.h>
54
#include <string>
65
#include <sys/time.h>
76
#include <sstream>
7+
#include "../../BLEDevice.h"
88

99
#include "sdkconfig.h"
1010

cpp_utils/tests/BLE Tests/SampleScan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "BLE.h"
21
#include "BLEUtils.h"
32
#include "BLEScan.h"
43
#include <esp_log.h>
54
#include <string>
65

6+
#include "../../BLEDevice.h"
77
#include "BLEAdvertisedDevice.h"
88
#include "sdkconfig.h"
99

cpp_utils/tests/BLE Tests/SampleServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "BLE.h"
21
#include "BLEUtils.h"
32
#include "BLEServer.h"
43
#include "BLE2902.h"
54
#include <esp_log.h>
65
#include <string>
76
#include <Task.h>
7+
#include "../../BLEDevice.h"
88

99
#include "sdkconfig.h"
1010

cpp_utils/tests/BLE Tests/SampleWrite.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#include "BLE.h"
21
#include "BLEUtils.h"
32
#include "BLEServer.h"
43
#include <esp_log.h>
54
#include <string>
65
#include <sys/time.h>
76
#include <sstream>
7+
#include "../../BLEDevice.h"
88

99
#include "sdkconfig.h"
1010

0 commit comments

Comments
 (0)
0