mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-12-25 08:08:15 +01:00
Compare commits
31 Commits
release/2.
...
2.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e80e1ee38 | ||
|
|
e6249623d5 | ||
|
|
a9578637cb | ||
|
|
765193f223 | ||
|
|
3b019a0c9c | ||
|
|
5ac7272f5d | ||
|
|
4d8ab46e56 | ||
|
|
8468bb50dc | ||
|
|
1088ad8fe1 | ||
|
|
0b543d9f62 | ||
|
|
fa468d360a | ||
|
|
2759b1b69d | ||
|
|
1a0b7a8e31 | ||
|
|
1d01af0f8c | ||
|
|
f7d3c5e0c2 | ||
|
|
bc2bc35a8a | ||
|
|
15cb6bc7c6 | ||
|
|
aae70dfd21 | ||
|
|
ad12a48e9e | ||
|
|
09297fb72a | ||
|
|
b50a1b50b1 | ||
|
|
954ba0b5a7 | ||
|
|
015217c764 | ||
|
|
9a1ae677b8 | ||
|
|
6ee5174ba0 | ||
|
|
e843c6811c | ||
|
|
0d13044703 | ||
|
|
cfca3e7500 | ||
|
|
3c80c950ae | ||
|
|
182e3bb8a3 | ||
|
|
a627007a31 |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,6 +1,22 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [2.1.0] 2025-01-12
|
||||
|
||||
## Fixed
|
||||
- Crash when retrieving descriptors if more than one exists.
|
||||
- Incorrect TX power value being advertised.
|
||||
- New user guide code for 2.x
|
||||
- Potential race condition if `NimBLEScan::clearResults1 is called from multiple tasks.
|
||||
|
||||
## Changed
|
||||
- If privacy is not enabled identity keys will not be shared.
|
||||
- `NimBLEDevice::setPower` and `NimBLEDevice::getPower` now take an additional parameter `NimBLETxPowerType` to set/get the power level for different operations.
|
||||
|
||||
## Added
|
||||
- Config option `CONFIG_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER`, if defined will remove the ":" delimiter from the BLE address string.
|
||||
- Config option `CONFIG_NIMBLE_CPP_ADDR_FMT_UPPERCASE` if defined will make the BLE address strings uppercase.
|
||||
|
||||
## [2.0.3] 2025-01-05
|
||||
|
||||
## Fixed
|
||||
|
||||
127
Kconfig
127
Kconfig
@@ -26,6 +26,113 @@ config NIMBLE_CPP_LOG_LEVEL
|
||||
default 3 if NIMBLE_CPP_LOG_LEVEL_INFO
|
||||
default 4 if NIMBLE_CPP_LOG_LEVEL_DEBUG
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR
|
||||
bool "Enable log color override."
|
||||
default "n"
|
||||
help
|
||||
Enabling this option will allow NimBLE log levels to have
|
||||
specific colors assigned.
|
||||
|
||||
menu "NIMBLE Log Override Colors"
|
||||
depends on NIMBLE_CPP_LOG_OVERRIDE_COLOR
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR
|
||||
prompt "NimBLE CPP log override color Error"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_NONE
|
||||
help
|
||||
Select NimBLE CPP log override error color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN
|
||||
prompt "NimBLE CPP log override color Warning"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_NONE
|
||||
help
|
||||
Select NimBLE CPP log override warning color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO
|
||||
prompt "NimBLE CPP log override color Info"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_NONE
|
||||
help
|
||||
Select NimBLE CPP log override info color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG
|
||||
prompt "NimBLE CPP log override color Debug"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_NONE
|
||||
help
|
||||
Select NimBLE CPP log override debug color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG
|
||||
endmenu
|
||||
|
||||
config NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT
|
||||
bool "Show NimBLE return codes as text in debug log."
|
||||
default "n"
|
||||
@@ -50,6 +157,20 @@ config NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT
|
||||
while scanning as text messages in the debug log.
|
||||
This will use approximately 250 bytes of flash memory.
|
||||
|
||||
config NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER
|
||||
bool "Exclude colon characters when printing address."
|
||||
default "n"
|
||||
help
|
||||
Enabling this option will format MAC addresses without
|
||||
colon characters when printing.
|
||||
|
||||
config NIMBLE_CPP_ADDR_FMT_UPPERCASE
|
||||
bool "Use uppercase letters when printing address."
|
||||
default "n"
|
||||
help
|
||||
Enabling this option will format MAC addresses in
|
||||
uppercase letters when printing.
|
||||
|
||||
config NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
|
||||
bool "Enable timestamps to be stored with attribute values."
|
||||
default "n"
|
||||
@@ -77,12 +198,12 @@ config NIMBLE_CPP_DEBUG_ASSERT_ENABLED
|
||||
This will use approximately 1kB of flash memory.
|
||||
|
||||
config NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT
|
||||
int "FreeRTOS task block bit"
|
||||
int "FreeRTOS task block bit."
|
||||
default 31
|
||||
help
|
||||
Configure the bit to set in the task notification value when a task is blocked waiting for an event.
|
||||
This should be set to a bit that is not used by other notifications in the system.
|
||||
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
@@ -130,4 +251,4 @@ if IDF_TARGET_ESP32P4
|
||||
endchoice
|
||||
endif
|
||||
|
||||
endmenu
|
||||
endmenu
|
||||
@@ -48,7 +48,7 @@ PROJECT_NAME = esp-nimble-cpp
|
||||
# could be handy for archiving the generated documentation or if some version
|
||||
# control system is used.
|
||||
|
||||
PROJECT_NUMBER = 2.0.3
|
||||
PROJECT_NUMBER = 2.1.0
|
||||
|
||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||
# for a project that appears at the top of each page and should give viewer a
|
||||
|
||||
@@ -37,9 +37,7 @@ For this example we will keep it simple and use a 16 bit value: ABCD.
|
||||
```
|
||||
#include "NimBLEDevice.h"
|
||||
|
||||
// void setup() in Arduino
|
||||
void app_main(void)
|
||||
{
|
||||
extern "C" void app_main(void) {
|
||||
NimBLEDevice::init("NimBLE");
|
||||
|
||||
NimBLEServer *pServer = NimBLEDevice::createServer();
|
||||
@@ -79,9 +77,7 @@ The function call will simply be `pService->createCharacteristic("1234");`
|
||||
```
|
||||
#include "NimBLEDevice.h"
|
||||
|
||||
// void setup() in Arduino
|
||||
void app_main(void)
|
||||
{
|
||||
extern "C" void app_main(void) {
|
||||
NimBLEDevice::init("NimBLE");
|
||||
|
||||
NimBLEServer *pServer = NimBLEDevice::createServer();
|
||||
@@ -99,12 +95,13 @@ There are many different types you can send as parameters for the value but for
|
||||
`pCharacteristic->setValue("Hello BLE");`
|
||||
|
||||
Next we need to advertise for connections.
|
||||
To do this we create an instance of `NimBLEAdvertising` add our service to it (optional) and start advertisng.
|
||||
To do this we create an instance of `NimBLEAdvertising` add our service to it (optional) and start advertising.
|
||||
|
||||
**The code for this will be:**
|
||||
```
|
||||
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); // create advertising instance
|
||||
pAdvertising->addServiceUUID("ABCD"); // tell advertising the UUID of our service
|
||||
pAdvertising->addServiceUUID("ABCD"); // advertise the UUID of our service
|
||||
pAdvertising->setName("NimBLE"); // advertise the device name
|
||||
pAdvertising->start(); // start advertising
|
||||
```
|
||||
That's it, this will be enough to create a BLE server with a service and a characteristic and advertise for client connections.
|
||||
@@ -113,9 +110,7 @@ That's it, this will be enough to create a BLE server with a service and a chara
|
||||
```
|
||||
#include "NimBLEDevice.h"
|
||||
|
||||
// void setup() in Arduino
|
||||
void app_main(void)
|
||||
{
|
||||
extern "C" void app_main(void) {
|
||||
NimBLEDevice::init("NimBLE");
|
||||
|
||||
NimBLEServer *pServer = NimBLEDevice::createServer();
|
||||
@@ -126,7 +121,8 @@ void app_main(void)
|
||||
pCharacteristic->setValue("Hello BLE");
|
||||
|
||||
NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising();
|
||||
pAdvertising->addServiceUUID("ABCD");
|
||||
pAdvertising->addServiceUUID("ABCD"); // advertise the UUID of our service
|
||||
pAdvertising->setName("NimBLE"); // advertise the device name
|
||||
pAdvertising->start();
|
||||
}
|
||||
```
|
||||
@@ -144,7 +140,7 @@ After initializing the NimBLE stack we create a scan instance by calling `NimBLE
|
||||
|
||||
Once we have created the scan we can start looking for advertising servers.
|
||||
|
||||
To do this we call `NimBLEScan::start(duration)`, the duration parameter is a uint32_t that specifies the number of milliseconds to scan for,
|
||||
To do this we call `NimBLEScan::getResults(duration)`, the duration parameter is a uint32_t that specifies the number of milliseconds to scan for,
|
||||
passing 0 will scan forever.
|
||||
|
||||
In this example we will scan for 10 seconds. This is a blocking function (a non blocking overload is also available).
|
||||
@@ -154,9 +150,7 @@ This call returns an instance of `NimBLEScanResults` when the scan completes whi
|
||||
```
|
||||
#include "NimBLEDevice.h"
|
||||
|
||||
// void setup() in Arduino
|
||||
void app_main(void)
|
||||
{
|
||||
extern "C" void app_main(void) {
|
||||
NimBLEDevice::init("");
|
||||
|
||||
NimBLEScan *pScan = NimBLEDevice::getScan();
|
||||
@@ -168,7 +162,7 @@ void app_main(void)
|
||||
Now that we have scanned we need to check the results for any advertisers we are interested in connecting to.
|
||||
|
||||
To do this we iterate through the results and check if any of the devices found are advertising the service we want `ABCD`.
|
||||
Each result in `NimBLEScanResults` is a `NimBLEAdvertisedDevice` instance that we can access data from.
|
||||
Each result in `NimBLEScanResults` is a `const NimBLEAdvertisedDevice*` that we can access data from.
|
||||
|
||||
We will check each device found for the `ABCD` service by calling `NimBLEAdvertisedDevice::isAdvertisingService`.
|
||||
This takes an instance of `NimBLEUUID` as a parameter so we will need to create one.
|
||||
@@ -177,11 +171,11 @@ This takes an instance of `NimBLEUUID` as a parameter so we will need to create
|
||||
```
|
||||
NimBLEUUID serviceUuid("ABCD");
|
||||
|
||||
for(int i = 0; i < results.getCount(); i++) {
|
||||
NimBLEAdvertisedDevice device = results.getDevice(i);
|
||||
for (int i = 0; i < results.getCount(); i++) {
|
||||
const NimBLEAdvertisedDevice *device = results.getDevice(i);
|
||||
|
||||
if (device.isAdvertisingService(serviceUuid)) {
|
||||
// create a client and connect
|
||||
if (device->isAdvertisingService(serviceUuid)) {
|
||||
// create a client and connect
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -198,16 +192,16 @@ This takes a pointer to the `NimBLEAdvertisedDevice` and returns `true` if succe
|
||||
```
|
||||
NimBLEUUID serviceUuid("ABCD");
|
||||
|
||||
for(int i = 0; i < results.getCount(); i++) {
|
||||
NimBLEAdvertisedDevice device = results.getDevice(i);
|
||||
for (int i = 0; i < results.getCount(); i++) {
|
||||
const NimBLEAdvertisedDevice *device = results.getDevice(i);
|
||||
|
||||
if (device.isAdvertisingService(serviceUuid)) {
|
||||
if (device->isAdvertisingService(serviceUuid)) {
|
||||
NimBLEClient *pClient = NimBLEDevice::createClient();
|
||||
|
||||
if(pClient->connect(&device)) {
|
||||
//success
|
||||
if (pClient->connect(&device)) {
|
||||
//success
|
||||
} else {
|
||||
// failed to connect
|
||||
// failed to connect
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,11 +223,15 @@ Finally we will read the characteristic value with `NimBLERemoteCharacteristic::
|
||||
```
|
||||
NimBLEUUID serviceUuid("ABCD");
|
||||
|
||||
for(int i = 0; i < results.getCount(); i++) {
|
||||
NimBLEAdvertisedDevice device = results.getDevice(i);
|
||||
for (int i = 0; i < results.getCount(); i++) {
|
||||
const NimBLEAdvertisedDevice *device = results.getDevice(i);
|
||||
|
||||
if (device.isAdvertisingService(serviceUuid)) {
|
||||
if (device->isAdvertisingService(serviceUuid)) {
|
||||
NimBLEClient *pClient = NimBLEDevice::createClient();
|
||||
|
||||
if (!pClient) { // Make sure the client was created
|
||||
break;
|
||||
}
|
||||
|
||||
if (pClient->connect(&device)) {
|
||||
NimBLERemoteService *pService = pClient->getService(serviceUuid);
|
||||
@@ -247,7 +245,7 @@ for(int i = 0; i < results.getCount(); i++) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// failed to connect
|
||||
// failed to connect
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -262,12 +260,16 @@ This is done by calling `NimBLEDevice::deleteClient`.
|
||||
```
|
||||
NimBLEUUID serviceUuid("ABCD");
|
||||
|
||||
for(int i = 0; i < results.getCount(); i++) {
|
||||
NimBLEAdvertisedDevice device = results.getDevice(i);
|
||||
for (int i = 0; i < results.getCount(); i++) {
|
||||
const NimBLEAdvertisedDevice *device = results.getDevice(i);
|
||||
|
||||
if (device.isAdvertisingService(serviceUuid)) {
|
||||
if (device->isAdvertisingService(serviceUuid)) {
|
||||
NimBLEClient *pClient = NimBLEDevice::createClient();
|
||||
|
||||
|
||||
if (!pClient) { // Make sure the client was created
|
||||
break;
|
||||
}
|
||||
|
||||
if (pClient->connect(&device)) {
|
||||
NimBLERemoteService *pService = pClient->getService(serviceUuid);
|
||||
|
||||
@@ -280,7 +282,7 @@ for(int i = 0; i < results.getCount(); i++) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// failed to connect
|
||||
// failed to connect
|
||||
}
|
||||
|
||||
NimBLEDevice::deleteClient(pClient);
|
||||
@@ -294,37 +296,39 @@ Note that there is no need to disconnect as that will be done when deleting the
|
||||
```
|
||||
#include "NimBLEDevice.h"
|
||||
|
||||
// void setup() in Arduino
|
||||
void app_main(void)
|
||||
{
|
||||
extern "C" void app_main(void) {
|
||||
NimBLEDevice::init("");
|
||||
|
||||
|
||||
NimBLEScan *pScan = NimBLEDevice::getScan();
|
||||
NimBLEScanResults results = pScan->start(10 * 1000);
|
||||
|
||||
NimBLEScanResults results = pScan->getResults(10 * 1000);
|
||||
|
||||
NimBLEUUID serviceUuid("ABCD");
|
||||
|
||||
for(int i = 0; i < results.getCount(); i++) {
|
||||
NimBLEAdvertisedDevice device = results.getDevice(i);
|
||||
|
||||
if (device.isAdvertisingService(serviceUuid)) {
|
||||
|
||||
for (int i = 0; i < results.getCount(); i++) {
|
||||
const NimBLEAdvertisedDevice *device = results.getDevice(i);
|
||||
|
||||
if (device->isAdvertisingService(serviceUuid)) {
|
||||
NimBLEClient *pClient = NimBLEDevice::createClient();
|
||||
|
||||
|
||||
if (!pClient) { // Make sure the client was created
|
||||
break;
|
||||
}
|
||||
|
||||
if (pClient->connect(&device)) {
|
||||
NimBLERemoteService *pService = pClient->getService(serviceUuid);
|
||||
|
||||
|
||||
if (pService != nullptr) {
|
||||
NimBLERemoteCharacteristic *pCharacteristic = pService->getCharacteristic("1234");
|
||||
|
||||
|
||||
if (pCharacteristic != nullptr) {
|
||||
std::string value = pCharacteristic->readValue();
|
||||
// print or do whatever you need with the value
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// failed to connect
|
||||
// failed to connect
|
||||
}
|
||||
|
||||
|
||||
NimBLEDevice::deleteClient(pClient);
|
||||
}
|
||||
}
|
||||
@@ -334,4 +338,3 @@ void app_main(void)
|
||||
|
||||
For more advanced features and options please see the client examples in the examples folder.
|
||||
<br/>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
version: "2.0.3"
|
||||
version: "2.1.0"
|
||||
license: "Apache-2.0"
|
||||
description: "C++ wrapper for the NimBLE BLE stack"
|
||||
url: "https://github.com/h2zero/esp-nimble-cpp"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "esp-nimble-cpp",
|
||||
"version": "2.0.3",
|
||||
"version": "2.1.0",
|
||||
"description": "C++ wrapper for the NimBLE BLE stack",
|
||||
"keywords": [
|
||||
"BLE",
|
||||
|
||||
@@ -23,6 +23,18 @@
|
||||
|
||||
# include <algorithm>
|
||||
|
||||
# ifdef CONFIG_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER
|
||||
# define NIMBLE_CPP_ADDR_DELIMITER ""
|
||||
# else
|
||||
# define NIMBLE_CPP_ADDR_DELIMITER ":"
|
||||
# endif
|
||||
|
||||
# ifdef CONFIG_NIMBLE_CPP_ADDR_FMT_UPPERCASE
|
||||
# define NIMBLE_CPP_ADDR_FMT "%02X%s%02X%s%02X%s%02X%s%02X%s%02X"
|
||||
# else
|
||||
# define NIMBLE_CPP_ADDR_FMT "%02x%s%02x%s%02x%s%02x%s%02x%s%02x"
|
||||
# endif
|
||||
|
||||
static const char* LOG_TAG = "NimBLEAddress";
|
||||
|
||||
/*************************************************
|
||||
@@ -61,7 +73,7 @@ NimBLEAddress::NimBLEAddress(const std::string& addr, uint8_t type) {
|
||||
std::string mac{addr};
|
||||
mac.erase(std::remove(mac.begin(), mac.end(), ':'), mac.end());
|
||||
uint64_t address = std::stoull(mac, nullptr, 16);
|
||||
memcpy(this->val, &address, sizeof this->val);
|
||||
memcpy(this->val, &address, sizeof(this->val));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,7 +102,7 @@ NimBLEAddress::NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t ty
|
||||
* * BLE_ADDR_RANDOM (1)
|
||||
*/
|
||||
NimBLEAddress::NimBLEAddress(const uint64_t& address, uint8_t type) {
|
||||
memcpy(this->val, &address, sizeof this->val);
|
||||
memcpy(this->val, &address, sizeof(this->val));
|
||||
this->type = type;
|
||||
} // NimBLEAddress
|
||||
|
||||
@@ -193,7 +205,7 @@ bool NimBLEAddress::operator==(const NimBLEAddress& rhs) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
return memcmp(rhs.val, this->val, sizeof this->val) == 0;
|
||||
return memcmp(rhs.val, this->val, sizeof(this->val)) == 0;
|
||||
} // operator ==
|
||||
|
||||
/**
|
||||
@@ -211,12 +223,12 @@ NimBLEAddress::operator std::string() const {
|
||||
char buffer[18];
|
||||
snprintf(buffer,
|
||||
sizeof(buffer),
|
||||
"%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
this->val[5],
|
||||
this->val[4],
|
||||
this->val[3],
|
||||
this->val[2],
|
||||
this->val[1],
|
||||
NIMBLE_CPP_ADDR_FMT,
|
||||
this->val[5], NIMBLE_CPP_ADDR_DELIMITER,
|
||||
this->val[4], NIMBLE_CPP_ADDR_DELIMITER,
|
||||
this->val[3], NIMBLE_CPP_ADDR_DELIMITER,
|
||||
this->val[2], NIMBLE_CPP_ADDR_DELIMITER,
|
||||
this->val[1], NIMBLE_CPP_ADDR_DELIMITER,
|
||||
this->val[0]);
|
||||
return std::string{buffer};
|
||||
} // operator std::string
|
||||
@@ -226,7 +238,7 @@ NimBLEAddress::operator std::string() const {
|
||||
*/
|
||||
NimBLEAddress::operator uint64_t() const {
|
||||
uint64_t address = 0;
|
||||
memcpy(&address, this->val, sizeof this->val);
|
||||
memcpy(&address, this->val, sizeof(this->val));
|
||||
return address;
|
||||
} // operator uint64_t
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ bool NimBLEAdvertisementData::addTxPower() {
|
||||
data[0] = BLE_HS_ADV_TX_PWR_LVL_LEN + 1;
|
||||
data[1] = BLE_HS_ADV_TYPE_TX_PWR_LVL;
|
||||
# ifndef CONFIG_IDF_TARGET_ESP32P4
|
||||
data[2] = NimBLEDevice::getPower();
|
||||
data[2] = NimBLEDevice::getPower(NimBLETxPowerType::Advertise);
|
||||
# else
|
||||
data[2] = 0;
|
||||
# endif
|
||||
|
||||
@@ -464,7 +464,7 @@ bool NimBLEDevice::setPowerLevel(esp_power_level_t powerLevel, esp_ble_power_typ
|
||||
* @param [in] dbm The power level to set in dBm.
|
||||
* @return True if the power level was set successfully.
|
||||
*/
|
||||
bool NimBLEDevice::setPower(int8_t dbm) {
|
||||
bool NimBLEDevice::setPower(int8_t dbm, NimBLETxPowerType type) {
|
||||
# ifdef ESP_PLATFORM
|
||||
# ifdef CONFIG_IDF_TARGET_ESP32P4
|
||||
return false; // CONFIG_IDF_TARGET_ESP32P4 does not support esp_ble_tx_power_set
|
||||
@@ -472,9 +472,25 @@ bool NimBLEDevice::setPower(int8_t dbm) {
|
||||
if (dbm % 3 == 2) {
|
||||
dbm++; // round up to the next multiple of 3 to be able to target 20dbm
|
||||
}
|
||||
return setPowerLevel(static_cast<esp_power_level_t>(dbm / 3 + ESP_PWR_LVL_N0));
|
||||
|
||||
bool success = false;
|
||||
esp_power_level_t espPwr = static_cast<esp_power_level_t>(dbm / 3 + ESP_PWR_LVL_N0);
|
||||
if (type == NimBLETxPowerType::All) {
|
||||
success = setPowerLevel(espPwr, ESP_BLE_PWR_TYPE_ADV);
|
||||
success &= setPowerLevel(espPwr, ESP_BLE_PWR_TYPE_SCAN);
|
||||
success &= setPowerLevel(espPwr, ESP_BLE_PWR_TYPE_DEFAULT);
|
||||
} else if (type == NimBLETxPowerType::Advertise) {
|
||||
success = setPowerLevel(espPwr, ESP_BLE_PWR_TYPE_ADV);
|
||||
} else if (type == NimBLETxPowerType::Scan) {
|
||||
success = setPowerLevel(espPwr, ESP_BLE_PWR_TYPE_SCAN);
|
||||
} else if (type == NimBLETxPowerType::Connection) {
|
||||
success = setPowerLevel(espPwr, ESP_BLE_PWR_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
return success;
|
||||
# endif
|
||||
# else
|
||||
(void)type; // unused
|
||||
NIMBLE_LOGD(LOG_TAG, ">> setPower: %d", dbm);
|
||||
ble_hci_vs_set_tx_pwr_cp cmd{dbm};
|
||||
ble_hci_vs_set_tx_pwr_rp rsp{0};
|
||||
@@ -493,12 +509,16 @@ bool NimBLEDevice::setPower(int8_t dbm) {
|
||||
* @brief Get the transmission power.
|
||||
* @return The power level currently used in dbm or 0xFF on error.
|
||||
*/
|
||||
int NimBLEDevice::getPower() {
|
||||
int NimBLEDevice::getPower(NimBLETxPowerType type) {
|
||||
# ifdef ESP_PLATFORM
|
||||
# ifdef CONFIG_IDF_TARGET_ESP32P4
|
||||
return 0xFF; // CONFIG_IDF_TARGET_ESP32P4 does not support esp_ble_tx_power_get
|
||||
# else
|
||||
int pwr = getPowerLevel();
|
||||
esp_ble_power_type_t espPwr = type == NimBLETxPowerType::Advertise ? ESP_BLE_PWR_TYPE_ADV
|
||||
: type == NimBLETxPowerType::Scan ? ESP_BLE_PWR_TYPE_SCAN
|
||||
: ESP_BLE_PWR_TYPE_DEFAULT;
|
||||
|
||||
int pwr = getPowerLevel(espPwr);
|
||||
if (pwr < 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "esp_ble_tx_power_get failed rc=%d", pwr);
|
||||
return 0xFF;
|
||||
@@ -515,6 +535,7 @@ int NimBLEDevice::getPower() {
|
||||
return 0;
|
||||
# endif
|
||||
# else
|
||||
(void)type; // unused
|
||||
return ble_phy_txpwr_get();
|
||||
# endif
|
||||
} // getPower
|
||||
@@ -877,17 +898,21 @@ bool NimBLEDevice::init(const std::string& deviceName) {
|
||||
nimble_port_init();
|
||||
|
||||
// Setup callbacks for host events
|
||||
ble_hs_cfg.reset_cb = NimBLEDevice::onReset;
|
||||
ble_hs_cfg.sync_cb = NimBLEDevice::onSync;
|
||||
ble_hs_cfg.reset_cb = NimBLEDevice::onReset;
|
||||
ble_hs_cfg.sync_cb = NimBLEDevice::onSync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr; /*TODO: Implement handler for this*/
|
||||
|
||||
// Set initial security capabilities
|
||||
ble_hs_cfg.sm_io_cap = BLE_HS_IO_NO_INPUT_OUTPUT;
|
||||
ble_hs_cfg.sm_bonding = 0;
|
||||
ble_hs_cfg.sm_mitm = 0;
|
||||
ble_hs_cfg.sm_sc = 1;
|
||||
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
|
||||
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr; /*TODO: Implement handler for this*/
|
||||
ble_hs_cfg.sm_our_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
|
||||
ble_hs_cfg.sm_their_key_dist = BLE_SM_PAIR_KEY_DIST_ENC;
|
||||
# if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
|
||||
ble_hs_cfg.sm_our_key_dist |= BLE_SM_PAIR_KEY_DIST_ID;
|
||||
ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ID;
|
||||
# endif
|
||||
|
||||
setDeviceName(deviceName);
|
||||
ble_store_config_init();
|
||||
|
||||
@@ -101,6 +101,13 @@ class NimBLEAddress;
|
||||
# define NIMBLE_MAX_CONNECTIONS CONFIG_NIMBLE_MAX_CONNECTIONS
|
||||
# endif
|
||||
|
||||
enum class NimBLETxPowerType {
|
||||
All = 0,
|
||||
Advertise = 1,
|
||||
Scan = 2,
|
||||
Connection = 3
|
||||
};
|
||||
|
||||
typedef int (*gap_event_handler)(ble_gap_event* event, void* arg);
|
||||
|
||||
/**
|
||||
@@ -138,8 +145,8 @@ class NimBLEDevice {
|
||||
static void onReset(int reason);
|
||||
static void onSync(void);
|
||||
static void host_task(void* param);
|
||||
static int getPower();
|
||||
static bool setPower(int8_t dbm);
|
||||
static int getPower(NimBLETxPowerType type = NimBLETxPowerType::All);
|
||||
static bool setPower(int8_t dbm, NimBLETxPowerType type = NimBLETxPowerType::All);
|
||||
|
||||
# ifdef ESP_PLATFORM
|
||||
# ifndef CONFIG_IDF_TARGET_ESP32P4
|
||||
|
||||
@@ -359,7 +359,7 @@ NimBLEExtAdvertisement::NimBLEExtAdvertisement(uint8_t priPhy, uint8_t secPhy) {
|
||||
m_params.own_addr_type = NimBLEDevice::m_ownAddrType;
|
||||
m_params.primary_phy = priPhy;
|
||||
m_params.secondary_phy = secPhy;
|
||||
m_params.tx_power = 127;
|
||||
m_params.tx_power = NimBLEDevice::getPower(NimBLETxPowerType::Advertise);
|
||||
} // NimBLEExtAdvertisement
|
||||
|
||||
/**
|
||||
@@ -1014,8 +1014,22 @@ bool NimBLEExtAdvertisement::setPreferredParams(uint16_t minInterval, uint16_t m
|
||||
/**
|
||||
* @brief Adds Tx power level to the advertisement data.
|
||||
*/
|
||||
void NimBLEExtAdvertisement::addTxPower() {
|
||||
bool NimBLEExtAdvertisement::addTxPower() {
|
||||
if (m_params.legacy_pdu) {
|
||||
m_params.include_tx_power = 0;
|
||||
uint8_t data[3];
|
||||
data[0] = BLE_HS_ADV_TX_PWR_LVL_LEN + 1;
|
||||
data[1] = BLE_HS_ADV_TYPE_TX_PWR_LVL;
|
||||
# ifndef CONFIG_IDF_TARGET_ESP32P4
|
||||
data[2] = NimBLEDevice::getPower(NimBLETxPowerType::Advertise);
|
||||
# else
|
||||
data[2] = 0;
|
||||
# endif
|
||||
return addData(data, 3);
|
||||
}
|
||||
|
||||
m_params.include_tx_power = 1;
|
||||
return true;
|
||||
} // addTxPower
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,34 +46,33 @@ class NimBLEUUID;
|
||||
class NimBLEExtAdvertisement {
|
||||
public:
|
||||
NimBLEExtAdvertisement(uint8_t priPhy = BLE_HCI_LE_PHY_1M, uint8_t secPhy = BLE_HCI_LE_PHY_1M);
|
||||
bool setAppearance(uint16_t appearance);
|
||||
bool addServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool addServiceUUID(const char* serviceUUID);
|
||||
bool removeServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool removeServiceUUID(const char* serviceUUID);
|
||||
bool removeServices();
|
||||
bool setCompleteServices(const NimBLEUUID& uuid);
|
||||
bool setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setFlags(uint8_t flag);
|
||||
bool setManufacturerData(const uint8_t* data, size_t length);
|
||||
bool setManufacturerData(const std::string& data);
|
||||
bool setManufacturerData(const std::vector<uint8_t>& data);
|
||||
bool setURI(const std::string& uri);
|
||||
bool setName(const std::string& name, bool isComplete = true);
|
||||
bool setPartialServices(const NimBLEUUID& uuid);
|
||||
bool setPartialServices16(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setPartialServices32(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length);
|
||||
bool setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
||||
bool setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data);
|
||||
bool setShortName(const std::string& name);
|
||||
bool setData(const uint8_t* data, size_t length);
|
||||
bool addData(const uint8_t* data, size_t length);
|
||||
bool addData(const std::string& data);
|
||||
bool setPreferredParams(uint16_t min, uint16_t max);
|
||||
|
||||
void addTxPower();
|
||||
bool setAppearance(uint16_t appearance);
|
||||
bool addServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool addServiceUUID(const char* serviceUUID);
|
||||
bool removeServiceUUID(const NimBLEUUID& serviceUUID);
|
||||
bool removeServiceUUID(const char* serviceUUID);
|
||||
bool removeServices();
|
||||
bool setCompleteServices(const NimBLEUUID& uuid);
|
||||
bool setCompleteServices16(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setCompleteServices32(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setFlags(uint8_t flag);
|
||||
bool setManufacturerData(const uint8_t* data, size_t length);
|
||||
bool setManufacturerData(const std::string& data);
|
||||
bool setManufacturerData(const std::vector<uint8_t>& data);
|
||||
bool setURI(const std::string& uri);
|
||||
bool setName(const std::string& name, bool isComplete = true);
|
||||
bool setPartialServices(const NimBLEUUID& uuid);
|
||||
bool setPartialServices16(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setPartialServices32(const std::vector<NimBLEUUID>& uuids);
|
||||
bool setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length);
|
||||
bool setServiceData(const NimBLEUUID& uuid, const std::string& data);
|
||||
bool setServiceData(const NimBLEUUID& uuid, const std::vector<uint8_t>& data);
|
||||
bool setShortName(const std::string& name);
|
||||
bool setData(const uint8_t* data, size_t length);
|
||||
bool addData(const uint8_t* data, size_t length);
|
||||
bool addData(const std::string& data);
|
||||
bool setPreferredParams(uint16_t min, uint16_t max);
|
||||
bool addTxPower();
|
||||
void setLegacyAdvertising(bool enable);
|
||||
void setConnectable(bool enable);
|
||||
void setScannable(bool enable);
|
||||
|
||||
110
src/NimBLELog.h
110
src/NimBLELog.h
@@ -28,11 +28,109 @@
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
|
||||
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
|
||||
do { \
|
||||
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR)
|
||||
# if CONFIG_LOG_COLORS
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_D
|
||||
# endif
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_I
|
||||
# endif
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_W
|
||||
# endif
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_E
|
||||
# endif
|
||||
# else //CONFIG_LOG_COLORS
|
||||
# define NIMBLE_CPP_LOG_COLOR_D
|
||||
# define NIMBLE_CPP_LOG_COLOR_I
|
||||
# define NIMBLE_CPP_LOG_COLOR_W
|
||||
# define NIMBLE_CPP_LOG_COLOR_E
|
||||
# endif //CONFIG_LOG_COLORS
|
||||
|
||||
# define NIMBLE_CPP_LOG_FORMAT(letter, format) NIMBLE_CPP_LOG_COLOR_##letter #letter " (%lu) %s: " format LOG_RESET_COLOR "\n"
|
||||
|
||||
# define NIMBLE_CPP_LOG_LEVEL_LOCAL(level, tag, format, ...) \
|
||||
do { \
|
||||
if (level==ESP_LOG_ERROR) { esp_log_write(ESP_LOG_ERROR, tag, NIMBLE_CPP_LOG_FORMAT(E, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
else if (level==ESP_LOG_WARN) { esp_log_write(ESP_LOG_WARN, tag, NIMBLE_CPP_LOG_FORMAT(W, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
else if (level==ESP_LOG_INFO) { esp_log_write(ESP_LOG_INFO, tag, NIMBLE_CPP_LOG_FORMAT(I, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
else { esp_log_write(ESP_LOG_DEBUG, tag, NIMBLE_CPP_LOG_FORMAT(D, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
} while(0)
|
||||
|
||||
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
|
||||
do { \
|
||||
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) NIMBLE_CPP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
|
||||
do { \
|
||||
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
# endif /* CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR */
|
||||
|
||||
# define NIMBLE_LOGD(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGI(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGW(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
|
||||
@@ -73,6 +171,6 @@
|
||||
# define NIMBLE_LOGE(tag, format, ...) (void)tag
|
||||
# endif
|
||||
|
||||
# endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* NIMBLE_CPP_LOG_H_ */
|
||||
# endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* NIMBLE_CPP_LOG_H_ */
|
||||
@@ -468,19 +468,26 @@ NimBLEScanResults NimBLEScan::getResults() {
|
||||
* @brief Clear the stored results of the scan.
|
||||
*/
|
||||
void NimBLEScan::clearResults() {
|
||||
for (const auto& dev : m_scanResults.m_deviceVec) {
|
||||
delete dev;
|
||||
if (m_scanResults.m_deviceVec.size()) {
|
||||
std::vector<NimBLEAdvertisedDevice*> vSwap{};
|
||||
ble_npl_hw_enter_critical();
|
||||
vSwap.swap(m_scanResults.m_deviceVec);
|
||||
ble_npl_hw_exit_critical(0);
|
||||
for (const auto& dev : vSwap) {
|
||||
delete dev;
|
||||
}
|
||||
}
|
||||
std::vector<NimBLEAdvertisedDevice*>().swap(m_scanResults.m_deviceVec);
|
||||
} // clearResults
|
||||
|
||||
/**
|
||||
* @brief Dump the scan results to the log.
|
||||
*/
|
||||
void NimBLEScanResults::dump() const {
|
||||
#if CONFIG_NIMBLE_CPP_LOG_LEVEL >=3
|
||||
for (const auto& dev : m_deviceVec) {
|
||||
NIMBLE_LOGI(LOG_TAG, "- %s", dev->toString().c_str());
|
||||
}
|
||||
#endif
|
||||
} // dump
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user