8000 Sync · programmer131/esp32-snippets@7b5db7d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b5db7d

Browse files
committed
Sync
1 parent 18fa8fe commit 7b5db7d

17 files changed

+505
-214
lines changed

cpp_utils/BLE.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,61 +361,59 @@ std::map<ble_address, BLEDevice> getDevices() {
361361
* @brief Initialize the server %BLE environment.
362362
*
363363
*/
364-
BLEServer *BLE::initServer(std::string deviceName) {
364+
void BLE::initServer(std::string deviceName) {
365365
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
366366
esp_err_t errRc = esp_bt_controller_init(&bt_cfg);
367367
if (errRc != ESP_OK) {
368368
ESP_LOGE(LOG_TAG, "esp_bt_controller_init: rc=%d %s", errRc, espToString(errRc));
369-
return nullptr;
369+
return;
370370
}
371371

372372

373373
errRc = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
374374
if (errRc != ESP_OK) {
375375
ESP_LOGE(LOG_TAG, "esp_bt_controller_enable: rc=%d %s", errRc, espToString(errRc));
376-
return nullptr;
376+
return;
377377
}
378378

379379
errRc = esp_bluedroid_init();
380380
if (errRc != ESP_OK) {
381381
ESP_LOGE(LOG_TAG, "esp_bluedroid_init: rc=%d %s", errRc, espToString(errRc));
382-
return nullptr;
382+
return;
383383
}
384384

385385
errRc = esp_bluedroid_enable();
386386
if (errRc != ESP_OK) {
387387
ESP_LOGE(LOG_TAG, "esp_bluedroid_enable: rc=%d %s", errRc, espToString(errRc));
388-
return nullptr;
388+
return;
389389
}
390390

391391
errRc = esp_ble_gap_register_callback(gap_event_handler);
392392
if (errRc != ESP_OK) {
393393
ESP_LOGE(LOG_TAG, "esp_ble_gap_register_callback: rc=%d %s", errRc, espToString(errRc));
394-
return nullptr;
394+
return;
395395
}
396396

397397
errRc = esp_ble_gatts_register_callback(gatt_server_event_handler);
398398
if (errRc != ESP_OK) {
399399
ESP_LOGE(LOG_TAG, "esp_ble_gatts_register_callback: rc=%d %s", errRc, espToString(errRc));
400-
return nullptr;
400+
return;
401401
}
402402

403403
errRc = ::esp_ble_gap_set_device_name(deviceName.c_str());
404404
if (errRc != ESP_OK) {
405405
ESP_LOGE(LOG_TAG, "esp_ble_gap_set_device_name: rc=%d %s", errRc, espToString(errRc));
406-
return nullptr;
406+
return;
407407
};
408408

409409
esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE;
410410
errRc = ::esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
411411
if (errRc != ESP_OK) {
412412
ESP_LOGE(LOG_TAG, "esp_ble_gap_set_security_param: rc=%d %s", errRc, espToString(errRc));
413-
return nullptr;
413+
return;
414414
};
415415

416-
m_bleServer = new BLEServer(0);
417-
m_bleServer->registerApp();
418-
return m_bleServer;
416+
return;
419417
}
420418

421419

cpp_utils/BLE.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BLE {
2828
static std::map<ble_address, BLEDevice> getDevices();
2929

3030
static void initClient();
31-
static BLEServer *initServer(std::string deviceName);
31+
static void initServer(std::string deviceName);
3232
static void scan(int duration, esp_ble_scan_type_t scan_type = BLE_SCAN_TYPE_PASSIVE);
3333
static esp_gatt_if_t getGattcIF();
3434
static BLEServer *m_bleServer;

cpp_utils/BLE2902.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,29 @@ BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t) 0x2902)) {
1919
BLE2902::~BLE2902() {
2020
}
2121

22+
/**
23+
* @brief Set the notifications flag.
24+
* @param [in] flag The notifications flag.
25+
*/
2226
void BLE2902::setNotifications(bool flag) {
2327
uint8_t *pValue = getValue();
2428
if (flag) {
2529
pValue[0] |= 1<<0;
2630
} else {
2731
pValue[0] &= ~(1<<0);
2832
}
29-
}
33+
} // setNotifications
34+
3035

36+
/**
37+
* @brief Set the indications flag.
38+
* @param [in] flag The indications flag.
39+
*/
3140
void BLE2902::setIndications(bool flag) {
3241
uint8_t *pValue = getValue();
3342
if (flag) {
3443
pValue[0] |= 1<<1;
3544
} else {
3645
pValue[0] &= ~(1<<1);
3746
}
38-
}
47+
} // setIndications

cpp_utils/BLE2902.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@
1010

1111
#include "BLEDescriptor.h"
1212

13+
/*
14+
* @brief Descriptor for Client Characteristic Configuration.
15+
*
16+
* This is a convenience descriptor for the Client Characteristic Configuration which has a UUID of 0x2902.
17+
*
18+
* See also:
19+
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
20+
*/
21+
1322
class BLE2902: public BLEDescriptor {
1423
public:
1524
BLE2902();
1625
virtual ~BLE2902();
1726
void setNotifications(bool flag);
1827
void setIndications(bool flag);
19-
};
28+
}; // BLE2902
2029

2130
#endif /* COMPONENTS_CPP_UTILS_BLE2902_H_ */

cpp_utils/BLEAdvertising.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ BLEAdvertising::~BLEAdvertising() {
5252
*/
5353
void BLEAdvertising::start() {
5454
ESP_LOGD(LOG_TAG, ">> start()");
55-
uint8_t tempData[16*2+1];
55+
uint8_t hexData[16*2+1];
5656
if (m_advData.service_uuid_len > 0) {
57-
BLEUtils::dumpHexData(tempData, m_advData.p_service_uuid, m_advData.service_uuid_len);
57+
BLEUtils::buildHexData(hexData, m_advData.p_service_uuid, m_advData.service_uuid_len);
5858
}
< 6813 /code>
5959

6060
ESP_LOGD(LOG_TAG, " - Service: service_uuid_len=%d, p_service_uuid=0x%x (data=%s)",
6161
m_advData.service_uuid_len,
6262
(uint32_t)m_advData.p_service_uuid,
63-
(m_advData.service_uuid_len > 0?(char *)tempData:"N/A")
63+
(m_advData.service_uuid_len > 0?(char *)hexData:"N/A")
6464
);
6565
// Set the configuration for advertising.
6666
esp_err_t errRc = ::esp_ble_gap_config_adv_data(&m_advData);

0 commit comments

Comments
 (0)
0