mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-12-23 15:18:16 +01:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2feaedb755 | ||
|
|
60290cd75c | ||
|
|
2f6ab7589b | ||
|
|
ed51076d0c | ||
|
|
4972f3e08b | ||
|
|
95a35ec081 | ||
|
|
a127aba925 | ||
|
|
c655b21590 | ||
|
|
d10ffa19db | ||
|
|
dc53052411 | ||
|
|
da48844e2f | ||
|
|
ea1c055826 | ||
|
|
65f6ee18ca | ||
|
|
fd0187bfc9 | ||
|
|
275def333c | ||
|
|
ec4d4c43e1 | ||
|
|
3e0ce87a94 | ||
|
|
3743eb954e | ||
|
|
6357a0dbea | ||
|
|
a6ed1933bc | ||
|
|
675d6bbf0d | ||
|
|
8753782425 | ||
|
|
af1872623e | ||
|
|
62de1b23fa | ||
|
|
57e583c17a | ||
|
|
5afb5af81e | ||
|
|
2d1e33a75e |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
# See https://hub.docker.com/r/espressif/idf/tags and
|
||||
# https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/tools/idf-docker-image.html
|
||||
# for details.
|
||||
idf_ver: ["release-v4.4", "release-v5.1", "release-v5.3"]
|
||||
idf_ver: ["release-v4.4", "release-v5.1", "v5.3.2"]
|
||||
idf_target: ["esp32", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2", "esp32p4"]
|
||||
example:
|
||||
- NimBLE_Client
|
||||
|
||||
20
.github/workflows/release.yml
vendored
Normal file
20
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build_docs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Doxygen Action
|
||||
uses: mattnotmitt/doxygen-action@v1.9.8
|
||||
with:
|
||||
working-directory: 'docs/'
|
||||
- name: Deploy
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./docs/doxydocs/html
|
||||
17
.github/workflows/sponsors.yml
vendored
Normal file
17
.github/workflows/sponsors.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
name: Generate Sponsors README
|
||||
on:
|
||||
workflow_dispatch:
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout 🛎️
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Generate Sponsors 💖
|
||||
uses: JamesIves/github-sponsors-readme-action@v1.5.4
|
||||
with:
|
||||
token: ${{ secrets.PAT }}
|
||||
file: 'README.md'
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
docs/doxydocs
|
||||
docs/doxydocs
|
||||
|
||||
42
CHANGELOG.md
42
CHANGELOG.md
@@ -1,7 +1,44 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
## [Unreleased]
|
||||
|
||||
## [2.0.3] 2025-01-05
|
||||
|
||||
## Fixed
|
||||
- Unused variable warning when log level is below info.
|
||||
- Build error missing definition of CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT in platformio.
|
||||
- Race condition in `NimBLEScan` that can cause a crash due to heap corruption if `NimBLEScan::stop` is called from the `onResult` callback.
|
||||
- Advertisement data not set if scan response is enabled after the data is set.
|
||||
- `NimBLECharacteristic`/`NimBLEDescriptor` not able to update their values in the `onRead` callback.
|
||||
- Too short of a timeout being requested in NimBLE_Server example leading to frequent disconnects.
|
||||
|
||||
## Changed
|
||||
- `NimBLEHIDDevice` now allows for the same report ID in multiple input/output/feature reports.
|
||||
|
||||
## Added
|
||||
- Config for custom log colors pre level.
|
||||
- Error logs in the case that NIMBLE_CPP_DEBUG_ASSERT is not defined.
|
||||
- Error logs when setting advertisement data fails.
|
||||
- Missing documentation in the migration guide about enabling automatic advertising on disconnect, which was disabled by default in 2.x.
|
||||
|
||||
## [2.0.2] 2024-12-21
|
||||
|
||||
## Fixed
|
||||
- Compile error when only advertising role is enabled.
|
||||
- Possible crash if bonded client reconnects.
|
||||
|
||||
## Changed
|
||||
- `NimBLEHIDDevice` can now create more than one in/out/feature report map.
|
||||
|
||||
## [2.0.1] 2024-12-16
|
||||
|
||||
## Fixed
|
||||
- `NimBLEHIDDevice::getOutputReport` will now return the correct characteristic.
|
||||
- Compile error when central is disabled, class `NimBLEServer` has no member named `m_pClient`.
|
||||
|
||||
## Changed
|
||||
- Added missing includes for `NimBLEConnInfo` and `NimBLEUtils` to `NimBLEDevice.h`.
|
||||
|
||||
## [2.0.0] 2024-12-14
|
||||
|
||||
## **Breaking changes**
|
||||
- All connection oriented callbacks now receive a reference to `NimBLEConnInfo`, the `ble_gap_conn_desc` has also been replace with `NimBLEConnInfo` in the functions that received it.
|
||||
@@ -60,6 +97,7 @@ All notable changes to this project will be documented in this file.
|
||||
- `NimBLEService::getCharacteristics` now returns a `const std::vector<NimBLECharacteristic*>&` instead of std::vector<NimBLECharacteristic *>.
|
||||
- `NimBLEUUID::getNative` method replaced with `NimBLEUUID::getBase` which returns a read-only pointer to the underlying `ble_uuid_t` struct.
|
||||
- `NimBLEUUID`; `msbFirst` parameter has been removed from constructor, caller should reverse the data first or call the new `reverseByteOrder` method after.
|
||||
- `NimBLEAddress` constructor; default value for the `type` parameter removed, caller should know the address type and specify it.
|
||||
- `NimBLEAddress::getNative` replaced with `NimBLEAddress::getBase` and now returns a pointer to `const ble_addr_t` instead of a pointer to the address value.
|
||||
- `NimBLEAddress::equals` method and `NimBLEAddress::== operator` will now also test if the address types are the same.
|
||||
- `NimBLEUtils::dumpGapEvent` function removed.
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(SUPPORTED_TARGETS esp32)
|
||||
|
||||
set(COMPONENT_SRCS
|
||||
"src/NimBLE2904.cpp"
|
||||
"src/NimBLEAddress.cpp"
|
||||
"src/NimBLEAdvertisedDevice.cpp"
|
||||
"src/NimBLEAdvertising.cpp"
|
||||
"src/NimBLEBeacon.cpp"
|
||||
"src/NimBLECharacteristic.cpp"
|
||||
"src/NimBLEClient.cpp"
|
||||
"src/NimBLEDescriptor.cpp"
|
||||
"src/NimBLEDevice.cpp"
|
||||
"src/NimBLEEddystoneTLM.cpp"
|
||||
"src/NimBLEEddystoneURL.cpp"
|
||||
"src/NimBLEHIDDevice.cpp"
|
||||
"src/NimBLERemoteCharacteristic.cpp"
|
||||
"src/NimBLERemoteDescriptor.cpp"
|
||||
"src/NimBLERemoteService.cpp"
|
||||
"src/NimBLEScan.cpp"
|
||||
"src/NimBLESecurity.cpp"
|
||||
"src/NimBLEServer.cpp"
|
||||
"src/NimBLEService.cpp"
|
||||
"src/NimBLEUtils.cpp"
|
||||
"src/NimBLEUUID.cpp"
|
||||
)
|
||||
|
||||
set(COMPONENT_ADD_INCLUDEDIRS
|
||||
src
|
||||
)
|
||||
|
||||
set(COMPONENT_PRIV_REQUIRES
|
||||
nvs_flash
|
||||
bt
|
||||
)
|
||||
|
||||
if(COMPONENTS MATCHES "esp-nimble-component")
|
||||
list(APPEND COMPONENT_PRIV_REQUIRES
|
||||
esp-nimble-component
|
||||
)
|
||||
elseif(COMPONENTS MATCHES "nimble")
|
||||
list(APPEND COMPONENT_PRIV_REQUIRES
|
||||
nimble
|
||||
)
|
||||
endif()
|
||||
|
||||
if(COMPONENTS MATCHES "arduino")
|
||||
list(APPEND COMPONENT_PRIV_REQUIRES
|
||||
arduino
|
||||
)
|
||||
endif()
|
||||
|
||||
register_component()
|
||||
4
LICENSE
4
LICENSE
@@ -186,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {2020} {Ryan Powell}
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -199,5 +199,3 @@
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
This product partly derives from esp32-snippets; Copyright 2017 Neil Kolban.
|
||||
10
NOTICE
Normal file
10
NOTICE
Normal file
@@ -0,0 +1,10 @@
|
||||
esp-nimble-cpp
|
||||
NimBLE-Arduino
|
||||
Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
|
||||
The Initial Developer of some parts of this library, which are copied from,
|
||||
derived from, or inspired by is, esp32-snippets, Copyright 2017 Neil Kolban.
|
||||
|
||||
If this library is used for commercial purposes, it is requested that the user consider
|
||||
making a donation and/or sponsoring this project to support it's ongoing development.
|
||||
31
README.md
31
README.md
@@ -1,19 +1,20 @@
|
||||
[Latest release 
|
||||
[
|
||||
](https://github.com/h2zero/esp-nimble-cpp/releases/latest/)
|
||||
|
||||
Need help? Have questions or suggestions? Join the [](https://gitter.im/NimBLE-Arduino/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
<br/>
|
||||
> [!IMPORTANT]
|
||||
> Version 2 is now released!
|
||||
> Check out the [1.x to 2.x Migration Guide](docs/1.x_to2.x_migration_guide.md) and [Release Notes](https://github.com/h2zero/esp-nimble-cpp/releases/latest/)
|
||||
|
||||
# esp-nimble-cpp
|
||||
|
||||
NimBLE CPP library for use with ESP32 that attempts to maintain compatibility with the [nkolban cpp_uitls BLE API](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils).
|
||||
NimBLE CPP library for use with ESP32 that attempts to maintain compatibility with the [nkolban cpp_utils BLE API](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils).
|
||||
|
||||
**An Arduino version of this library, including NimBLE, can be [found here.](https://github.com/h2zero/NimBLE-Arduino)**
|
||||
|
||||
This library **significantly** reduces resource usage and improves performance for ESP32 BLE applications as compared
|
||||
with the bluedroid based library. The goal is to maintain, as much as reasonable, compatibility with the original
|
||||
library but refactored to use the NimBLE stack. In addition, this library will be more actively developed and maintained
|
||||
to provide improved capabilites and stability over the original.
|
||||
library but using the NimBLE stack. In addition, this library will be more actively developed and maintained
|
||||
to provide improved capabilities and stability over the original.
|
||||
|
||||
**Testing shows a nearly 50% reduction in flash use and approx. 100kB less ram consumed vs the original!**
|
||||
*Your results may vary*
|
||||
@@ -35,16 +36,6 @@ Configure settings in `NimBLE Options`.
|
||||
Call `NimBLEDevice::init("");` in `app_main`.
|
||||
<br/>
|
||||
|
||||
### ESP-IDF v3.2 & v3.3
|
||||
The NimBLE component does not come with these versions of IDF (now included in 3.3.2 and above).
|
||||
A backport that works in these versions has been created and is [available here](https://github.com/h2zero/esp-nimble-component).
|
||||
Download or clone that repo into your project/components folder and run menuconfig.
|
||||
Configure settings in `main menu -> NimBLE Options`.
|
||||
|
||||
`#include "NimBLEDevice.h"` in main.cpp.
|
||||
Call `NimBLEDevice::init("");` in `app_main`.
|
||||
<br/>
|
||||
|
||||
# Using
|
||||
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.
|
||||
|
||||
@@ -62,6 +53,14 @@ When using this library along with Arduino and compiling with *CMake* you must a
|
||||
in your project/CMakeLists.txt after the line `include($ENV{IDF_PATH}/tools/cmake/project.cmake)` to prevent Arduino from releasing BLE memory.
|
||||
<br>
|
||||
|
||||
# Sponsors
|
||||
Thank you to all the sponsors who support this project!
|
||||
|
||||
<!-- sponsors --><!-- sponsors -->
|
||||
|
||||
If you use this library for a commercial product please consider [sponsoring the development](https://github.com/sponsors/h2zero) to ensure the continued updates and maintenance.
|
||||
<br/>
|
||||
|
||||
# Acknowledgments
|
||||
* [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from.
|
||||
* [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples.
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := src
|
||||
COMPONENT_SRCDIRS := src
|
||||
@@ -65,7 +65,8 @@ This returns a pointer to `const ble_addr_t` instead of a pointer to the address
|
||||
## Server
|
||||
- `NimBLEServer::disconnect` now returns `bool`, true = success, instead of `int` to be consistent with the rest of the library.
|
||||
- `NimBLEServerCallbacks::onMTUChanged` renamed to `NimBLEServerCallbacks::onMTUChange` to be consistent with the client callback.
|
||||
- `NimBLEServer::getPeerIDInfo` renamed to `NimBLEServer::getPeerInfoByHandle` to better describe it's use.
|
||||
- `NimBLEServer::getPeerIDInfo` renamed to `NimBLEServer::getPeerInfoByHandle` to better describe it's use.
|
||||
- Advertising is no longer automatically restarted when a peer disconnects, to re-enable this feature either call `NimBLEServer::advertiseOnDisconnect(true);` after creating the server or manually restart advertising in the `onDisconnect` callback.
|
||||
<br/>
|
||||
|
||||
### Services
|
||||
|
||||
@@ -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.0
|
||||
PROJECT_NUMBER = 2.0.3
|
||||
|
||||
# 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
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Overview
|
||||
|
||||
This is a C++ BLE library for the ESP32 that uses the NimBLE host stack instead of bluedroid.
|
||||
The aim is to maintain, as much as reasonable, the original bluedroid C++ & Arduino BLE API by while adding new features
|
||||
and making improvements in performance, resource use, and stability.
|
||||
@@ -23,16 +22,6 @@ Configure settings in `NimBLE Options`.
|
||||
Call `NimBLEDevice::init` in `app_main`.
|
||||
<br/>
|
||||
|
||||
### v3.2 & v3.3
|
||||
The NimBLE component does not come with these versions of IDF (now included in 3.3.2 and above).
|
||||
A backport that works in these versions has been created and is [available here](https://github.com/h2zero/esp-nimble-component).
|
||||
Download or clone that repo into your project/components folder and run menuconfig.
|
||||
Configure settings in `main menu -> NimBLE Options`.
|
||||
|
||||
`#include "NimBLEDevice.h"` in main.cpp.
|
||||
Call `NimBLEDevice::init` in `app_main`.
|
||||
<br/>
|
||||
|
||||
# Using
|
||||
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.
|
||||
|
||||
@@ -43,12 +32,13 @@ If you are familiar with the original library, see: [The migration guide](Migrat
|
||||
For more advanced usage see [Usage tips](Usage_tips.md) for more performance and optimization.
|
||||
<br/>
|
||||
|
||||
# Need help? Have a question or suggestion?
|
||||
Come chat on [gitter](https://gitter.im/NimBLE-Arduino/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link) or open an issue at [NimBLE-Arduino](https://github.com/h2zero/NimBLE-Arduino/issues) or [esp-nimble-cpp](https://github.com/h2zero/esp-nimble-cpp/issues)
|
||||
# Sponsors
|
||||
Thank you to all the sponsors who support this project!
|
||||
|
||||
If you use this library for a commercial product please consider [sponsoring the development](https://github.com/sponsors/h2zero) to ensure the continued updates and maintenance.
|
||||
<br/>
|
||||
|
||||
# Acknowledgments
|
||||
|
||||
* [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from.
|
||||
* [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples.
|
||||
* [Jeroen88](https://github.com/Jeroen88) for the amazing help debugging and improving the client code.
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#define CHARACTERISTIC_UUID "1234"
|
||||
|
||||
static const NimBLEAdvertisedDevice* advDevice;
|
||||
static bool doConnect = false;
|
||||
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
|
||||
static bool doConnect = false;
|
||||
static uint32_t scanTimeMs = 10 * 1000; // In milliseconds, 0 = scan forever
|
||||
|
||||
/** Define the PHY's to use when connecting to peer devices, can be 1, 2, or all 3 (default).*/
|
||||
static uint8_t connectPhys = BLE_GAP_LE_PHY_CODED_MASK | BLE_GAP_LE_PHY_1M_MASK /*| BLE_GAP_LE_PHY_2M_MASK */;
|
||||
@@ -26,7 +26,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
|
||||
|
||||
void onDisconnect(NimBLEClient* pClient, int reason) override {
|
||||
printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason);
|
||||
NimBLEDevice::getScan()->start(scanTime);
|
||||
NimBLEDevice::getScan()->start(scanTimeMs);
|
||||
}
|
||||
} clientCallbacks;
|
||||
|
||||
@@ -123,7 +123,7 @@ extern "C" void app_main(void) {
|
||||
* Start scanning for advertisers for the scan time specified (in milliseconds) 0 = forever
|
||||
* Optional callback for when scanning stops.
|
||||
*/
|
||||
pScan->start(scanTime);
|
||||
pScan->start(scanTimeMs);
|
||||
|
||||
printf("Scanning for peripherals\n");
|
||||
|
||||
@@ -137,7 +137,7 @@ extern "C" void app_main(void) {
|
||||
}
|
||||
|
||||
doConnect = false;
|
||||
NimBLEDevice::getScan()->start(scanTime);
|
||||
NimBLEDevice::getScan()->start(scanTimeMs);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
|
||||
#include <NimBLEDevice.h>
|
||||
|
||||
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
|
||||
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;
|
||||
static uint32_t scanTimeMs = 10 * 1000; // In milliseconds, 0 = scan forever
|
||||
static NimBLEScan::Phy scanPhy = NimBLEScan::Phy::SCAN_ALL;
|
||||
|
||||
/** Define a class to handle the callbacks when advertisements are received */
|
||||
class ScanCallbacks : public NimBLEScanCallbacks {
|
||||
@@ -43,7 +43,7 @@ class ScanCallbacks : public NimBLEScanCallbacks {
|
||||
|
||||
NimBLEScan* pScan = NimBLEDevice::getScan();
|
||||
pScan->setPhy(scanPhy);
|
||||
pScan->start(scanTime);
|
||||
pScan->start(scanTimeMs);
|
||||
}
|
||||
} scanCallbacks;
|
||||
|
||||
@@ -63,7 +63,7 @@ extern "C" void app_main(void) {
|
||||
/** Set the initial PHY's to scan on, default is SCAN_ALL */
|
||||
pScan->setPhy(scanPhy);
|
||||
|
||||
/** Start scanning for scanTime */
|
||||
pScan->start(scanTime);
|
||||
/** Start scanning for scanTimeMs */
|
||||
pScan->start(scanTimeMs);
|
||||
printf("Scanning for peripherals\n");
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <NimBLEDevice.h>
|
||||
|
||||
static const NimBLEAdvertisedDevice* advDevice;
|
||||
static bool doConnect = false;
|
||||
static uint32_t scanTime = 5000; /** scan time in milliseconds, 0 = scan forever */
|
||||
static bool doConnect = false;
|
||||
static uint32_t scanTimeMs = 5000; /** scan time in milliseconds, 0 = scan forever */
|
||||
|
||||
/** None of these are required as they will be handled by the library with defaults. **
|
||||
** Remove as you see fit for your needs */
|
||||
@@ -20,7 +20,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
|
||||
|
||||
void onDisconnect(NimBLEClient* pClient, int reason) override {
|
||||
printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason);
|
||||
NimBLEDevice::getScan()->start(scanTime, false, true);
|
||||
NimBLEDevice::getScan()->start(scanTimeMs, false, true);
|
||||
}
|
||||
|
||||
/********************* Security handled here *********************/
|
||||
@@ -48,10 +48,10 @@ class ClientCallbacks : public NimBLEClientCallbacks {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} clientCB;
|
||||
} clientCallbacks;
|
||||
|
||||
/** Define a class to handle the callbacks when scan events are received */
|
||||
class scanCallbacks : public NimBLEScanCallbacks {
|
||||
class ScanCallbacks : public NimBLEScanCallbacks {
|
||||
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) override {
|
||||
printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str());
|
||||
if (advertisedDevice->isAdvertisingService(NimBLEUUID("DEAD"))) {
|
||||
@@ -68,9 +68,9 @@ class scanCallbacks : public NimBLEScanCallbacks {
|
||||
/** Callback to process the results of the completed scan or restart it */
|
||||
void onScanEnd(const NimBLEScanResults& results, int reason) override {
|
||||
printf("Scan Ended, reason: %d, device count: %d; Restarting scan\n", reason, results.getCount());
|
||||
NimBLEDevice::getScan()->start(scanTime, false, true);
|
||||
NimBLEDevice::getScan()->start(scanTimeMs, false, true);
|
||||
}
|
||||
} scanCB;
|
||||
} scanCallbacks;
|
||||
|
||||
/** Notification / Indication receiving handler callback */
|
||||
void notifyCB(NimBLERemoteCharacteristic* pRemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify) {
|
||||
@@ -121,7 +121,7 @@ bool connectToServer() {
|
||||
|
||||
printf("New client created\n");
|
||||
|
||||
pClient->setClientCallbacks(&clientCB, false);
|
||||
pClient->setClientCallbacks(&clientCallbacks, false);
|
||||
/**
|
||||
* Set initial connection parameters:
|
||||
* These settings are safe for 3 clients to connect reliably, can go faster if you have less
|
||||
@@ -241,8 +241,7 @@ bool connectToServer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void app_main(void) {
|
||||
extern "C" void app_main(void) {
|
||||
printf("Starting NimBLE Client\n");
|
||||
/** Initialize NimBLE and set the device name */
|
||||
NimBLEDevice::init("NimBLE-Client");
|
||||
@@ -266,11 +265,11 @@ void app_main(void) {
|
||||
NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
|
||||
|
||||
/** Optional: set the transmit power */
|
||||
NimBLEDevice::setPower(3); // 9dbm
|
||||
NimBLEDevice::setPower(3); /** 3dbm */
|
||||
NimBLEScan* pScan = NimBLEDevice::getScan();
|
||||
|
||||
/** Set the callbacks to call when scan events occur, no duplicates */
|
||||
pScan->setScanCallbacks(&scanCB, false);
|
||||
pScan->setScanCallbacks(&scanCallbacks, false);
|
||||
|
||||
/** Set scan interval (how often) and window (how long) in milliseconds */
|
||||
pScan->setInterval(100);
|
||||
@@ -283,7 +282,7 @@ void app_main(void) {
|
||||
pScan->setActiveScan(true);
|
||||
|
||||
/** Start scanning for advertisers */
|
||||
pScan->start(scanTime);
|
||||
pScan->start(scanTimeMs);
|
||||
printf("Scanning for peripherals\n");
|
||||
|
||||
/** Loop here until we find a device we want to connect to */
|
||||
@@ -299,7 +298,7 @@ void app_main(void) {
|
||||
printf("Failed to connect, starting scan\n");
|
||||
}
|
||||
|
||||
NimBLEDevice::getScan()->start(scanTime, false, true);
|
||||
NimBLEDevice::getScan()->start(scanTimeMs, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class ServerCallbacks : public NimBLEServerCallbacks {
|
||||
* Latency: number of intervals allowed to skip.
|
||||
* Timeout: 10 millisecond increments.
|
||||
*/
|
||||
pServer->updateConnParams(connInfo.getConnHandle(), 24, 48, 0, 18);
|
||||
pServer->updateConnParams(connInfo.getConnHandle(), 24, 48, 0, 180);
|
||||
}
|
||||
|
||||
void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) override {
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
## IDF Component Manager Manifest File
|
||||
version: "2.0.3"
|
||||
license: "Apache-2.0"
|
||||
description: "C++ wrapper for the NimBLE BLE stack"
|
||||
url: "https://github.com/h2zero/esp-nimble-cpp"
|
||||
repository: "https://github.com/h2zero/esp-nimble-cpp"
|
||||
maintainers:
|
||||
- Ryan Powell <ryan@nable-embedded.io>
|
||||
documentation: "https://h2zero.github.io/esp-nimble-cpp/"
|
||||
tags:
|
||||
- BLE
|
||||
- NimBLE
|
||||
dependencies:
|
||||
espressif/esp_hosted:
|
||||
version: "*"
|
||||
@@ -8,8 +19,6 @@ dependencies:
|
||||
version: "*"
|
||||
rules:
|
||||
- if: "target in [esp32p4]"
|
||||
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: ">=5.3.0"
|
||||
rules:
|
||||
|
||||
23
library.json
Normal file
23
library.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "esp-nimble-cpp",
|
||||
"version": "2.0.3",
|
||||
"description": "C++ wrapper for the NimBLE BLE stack",
|
||||
"keywords": [
|
||||
"BLE",
|
||||
"espidf",
|
||||
"espressif",
|
||||
"esp32",
|
||||
"nimble"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/h2zero/esp-nimble-cpp"
|
||||
},
|
||||
"authors": {
|
||||
"name": "Ryan Powell",
|
||||
"email": "ryan@nable-embedded.io",
|
||||
"url": "https://github.com/h2zero/esp-nimble-cpp",
|
||||
"maintainer": true
|
||||
}
|
||||
}
|
||||
17
package.json
17
package.json
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"name": "esp-nimble-cpp",
|
||||
"version": "1.5.0",
|
||||
"description": "NimBLE, BLE stack for the Espressif ESP32, ESP32-S and ESP32-C series of SoCs",
|
||||
"keywords": [
|
||||
"BLE",
|
||||
"espidf",
|
||||
"arduino",
|
||||
"espressif",
|
||||
"esp32"
|
||||
],
|
||||
"license": "LGPL-2.1-or-later",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/h2zero/esp-nimble-cpp"
|
||||
}
|
||||
}
|
||||
20
pkg.yml
20
pkg.yml
@@ -1,20 +0,0 @@
|
||||
pkg.name: esp-nimble-cpp
|
||||
pkg.type: lib
|
||||
pkg.description: NimBLE CPP wrapper
|
||||
pkg.author: "Ryan Powell"
|
||||
pkg.homepage: "http://mynewt.apache.org/"
|
||||
pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- "@apache-mynewt-nimble/nimble"
|
||||
- "@apache-mynewt-nimble/nimble/host"
|
||||
- "@apache-mynewt-nimble/nimble/host/services/gap"
|
||||
- "@apache-mynewt-nimble/nimble/host/services/gatt"
|
||||
- "@apache-mynewt-nimble/nimble/host/store/config"
|
||||
- "@apache-mynewt-nimble/nimble/host/util"
|
||||
|
||||
pkg.source_dirs:
|
||||
- src
|
||||
|
||||
pkg.include_dirs:
|
||||
- src
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLE2904.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 13, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLE2904.cpp
|
||||
*
|
||||
* Created on: Dec 23, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLE2904.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 13, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLE2904.h
|
||||
*
|
||||
* Created on: Dec 23, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_2904_H_
|
||||
@@ -23,8 +26,8 @@
|
||||
struct NimBLE2904Data {
|
||||
uint8_t m_format{0};
|
||||
int8_t m_exponent{0};
|
||||
uint16_t m_unit{0x2700}; // Unitless; See https://www.bluetooth.com/specifications/assigned-numbers/units
|
||||
uint8_t m_namespace{1}; // 1 = Bluetooth SIG Assigned Numbers
|
||||
uint16_t m_unit{0x2700}; // Unitless; See https://www.bluetooth.com/specifications/assigned-numbers/units
|
||||
uint8_t m_namespace{1}; // 1 = Bluetooth SIG Assigned Numbers
|
||||
uint16_t m_description{0}; // unknown description
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
/*
|
||||
* NimBLEAddress.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEAddress.cpp
|
||||
*
|
||||
* Created on: Jul 2, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
@@ -41,7 +45,9 @@ NimBLEAddress::NimBLEAddress(ble_addr_t address) : ble_addr_t{address} {}
|
||||
* ```
|
||||
* which is 17 characters in length.
|
||||
* @param [in] addr The hex string representation of the address.
|
||||
* @param [in] type The type of the address.
|
||||
* @param [in] type The type of the address, should be one of:
|
||||
* * BLE_ADDR_PUBLIC (0)
|
||||
* * BLE_ADDR_RANDOM (1)
|
||||
*/
|
||||
NimBLEAddress::NimBLEAddress(const std::string& addr, uint8_t type) {
|
||||
this->type = type;
|
||||
@@ -66,7 +72,9 @@ NimBLEAddress::NimBLEAddress(const std::string& addr, uint8_t type) {
|
||||
/**
|
||||
* @brief Constructor for compatibility with bluedroid esp library using native ESP representation.
|
||||
* @param [in] address A uint8_t[6] or esp_bd_addr_t containing the address.
|
||||
* @param [in] type The type of the address.
|
||||
* @param [in] type The type of the address should be one of:
|
||||
* * BLE_ADDR_PUBLIC (0)
|
||||
* * BLE_ADDR_RANDOM (1)
|
||||
*/
|
||||
NimBLEAddress::NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type) {
|
||||
std::reverse_copy(address, address + BLE_DEV_ADDR_LEN, this->val);
|
||||
@@ -77,7 +85,9 @@ NimBLEAddress::NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t ty
|
||||
* @brief Constructor for address using a hex value.\n
|
||||
* Use the same byte order, so use 0xa4c1385def16 for "a4:c1:38:5d:ef:16"
|
||||
* @param [in] address uint64_t containing the address.
|
||||
* @param [in] type The type of the address.
|
||||
* @param [in] type The type of the address should be one of:
|
||||
* * BLE_ADDR_PUBLIC (0)
|
||||
* * BLE_ADDR_RANDOM (1)
|
||||
*/
|
||||
NimBLEAddress::NimBLEAddress(const uint64_t& address, uint8_t type) {
|
||||
memcpy(this->val, &address, sizeof this->val);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEAddress.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEAddress.h
|
||||
*
|
||||
* Created on: Jul 2, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_ADDRESS_H_
|
||||
@@ -31,9 +34,9 @@
|
||||
# include <string>
|
||||
|
||||
/**
|
||||
* @brief A %BLE device address.
|
||||
* @brief A BLE device address.
|
||||
*
|
||||
* Every %BLE device has a unique address which can be used to identify it and form connections.
|
||||
* Every BLE device has a unique address which can be used to identify it and form connections.
|
||||
*/
|
||||
class NimBLEAddress : private ble_addr_t {
|
||||
public:
|
||||
@@ -42,9 +45,9 @@ class NimBLEAddress : private ble_addr_t {
|
||||
*/
|
||||
NimBLEAddress() = default;
|
||||
NimBLEAddress(const ble_addr_t address);
|
||||
NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type = BLE_ADDR_PUBLIC);
|
||||
NimBLEAddress(const std::string& stringAddress, uint8_t type = BLE_ADDR_PUBLIC);
|
||||
NimBLEAddress(const uint64_t& address, uint8_t type = BLE_ADDR_PUBLIC);
|
||||
NimBLEAddress(const uint8_t address[BLE_DEV_ADDR_LEN], uint8_t type);
|
||||
NimBLEAddress(const std::string& stringAddress, uint8_t type);
|
||||
NimBLEAddress(const uint64_t& address, uint8_t type);
|
||||
|
||||
bool isRpa() const;
|
||||
bool isNrpa() const;
|
||||
@@ -59,8 +62,8 @@ class NimBLEAddress : private ble_addr_t {
|
||||
const NimBLEAddress& reverseByteOrder();
|
||||
bool operator==(const NimBLEAddress& rhs) const;
|
||||
bool operator!=(const NimBLEAddress& rhs) const;
|
||||
operator std::string() const;
|
||||
operator uint64_t() const;
|
||||
operator std::string() const;
|
||||
operator uint64_t() const;
|
||||
};
|
||||
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEAdvertisedDevice.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEAdvertisedDevice.cpp
|
||||
*
|
||||
* Created on: Jul 3, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEAdvertisedDevice.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEAdvertisedDevice.h
|
||||
*
|
||||
* Created on: Jul 3, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_ADVERTISED_DEVICE_H_
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* NimBLEAdvertisementData.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on November 24, 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -30,7 +39,7 @@ static const char* LOG_TAG = "NimBLEAdvertisementData";
|
||||
* @param [in] length The size of data to be added to the payload.
|
||||
*/
|
||||
bool NimBLEAdvertisementData::addData(const uint8_t* data, size_t length) {
|
||||
if ((m_payload.size() + length) > BLE_HS_ADV_MAX_SZ) {
|
||||
if (m_payload.size() + length > BLE_HS_ADV_MAX_SZ) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Data length exceeded");
|
||||
return false;
|
||||
}
|
||||
@@ -150,6 +159,7 @@ bool NimBLEAdvertisementData::addServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
type = BLE_HS_ADV_TYPE_COMP_UUIDS128;
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot add UUID, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -160,10 +170,11 @@ bool NimBLEAdvertisementData::addServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
}
|
||||
|
||||
if (length + getPayload().size() > BLE_HS_ADV_MAX_SZ) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot add UUID, data length exceeded!");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t data[31];
|
||||
uint8_t data[BLE_HS_ADV_MAX_SZ];
|
||||
const uint8_t* uuid = serviceUUID.getValue();
|
||||
if (dataLoc == -1) {
|
||||
data[0] = 1 + bytes;
|
||||
@@ -205,6 +216,7 @@ bool NimBLEAdvertisementData::removeServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
type = BLE_HS_ADV_TYPE_COMP_UUIDS128;
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot remove UUID, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -257,12 +269,12 @@ bool NimBLEAdvertisementData::removeServices() {
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool NimBLEAdvertisementData::setManufacturerData(const uint8_t* data, size_t length) {
|
||||
if (length > 29) {
|
||||
if (length > BLE_HS_ADV_MAX_FIELD_SZ) {
|
||||
NIMBLE_LOGE(LOG_TAG, "MFG data too long");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t mdata[31];
|
||||
uint8_t mdata[BLE_HS_ADV_MAX_SZ];
|
||||
mdata[0] = length + 1;
|
||||
mdata[1] = BLE_HS_ADV_TYPE_MFG_DATA;
|
||||
memcpy(&mdata[2], data, length);
|
||||
@@ -293,12 +305,12 @@ bool NimBLEAdvertisementData::setManufacturerData(const std::vector<uint8_t>& da
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool NimBLEAdvertisementData::setURI(const std::string& uri) {
|
||||
if (uri.length() > 29) {
|
||||
if (uri.length() > BLE_HS_ADV_MAX_FIELD_SZ) {
|
||||
NIMBLE_LOGE(LOG_TAG, "URI too long");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t data[31];
|
||||
uint8_t data[BLE_HS_ADV_MAX_SZ];
|
||||
uint8_t length = 2 + uri.length();
|
||||
data[0] = length - 1;
|
||||
data[1] = BLE_HS_ADV_TYPE_URI;
|
||||
@@ -315,16 +327,16 @@ bool NimBLEAdvertisementData::setURI(const std::string& uri) {
|
||||
* @return True if successful.
|
||||
*/
|
||||
bool NimBLEAdvertisementData::setName(const std::string& name, bool isComplete) {
|
||||
if (name.length() > 29) {
|
||||
if (name.length() > BLE_HS_ADV_MAX_FIELD_SZ) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Name too long - truncating");
|
||||
isComplete = false;
|
||||
}
|
||||
|
||||
uint8_t data[31];
|
||||
uint8_t length = 2 + std::min<uint8_t>(name.length(), 29);
|
||||
uint8_t data[BLE_HS_ADV_MAX_SZ];
|
||||
uint8_t length = 2 + std::min<uint8_t>(name.length(), BLE_HS_ADV_MAX_FIELD_SZ);
|
||||
data[0] = length - 1;
|
||||
data[1] = isComplete ? BLE_HS_ADV_TYPE_COMP_NAME : BLE_HS_ADV_TYPE_INCOMP_NAME;
|
||||
memcpy(&data[2], name.c_str(), std::min<uint8_t>(name.length(), 29));
|
||||
memcpy(&data[2], name.c_str(), std::min<uint8_t>(name.length(), BLE_HS_ADV_MAX_FIELD_SZ));
|
||||
return addData(data, length);
|
||||
} // setName
|
||||
|
||||
@@ -402,14 +414,14 @@ bool NimBLEAdvertisementData::setPartialServices32(const std::vector<NimBLEUUID>
|
||||
bool NimBLEAdvertisementData::setServices(bool complete, uint8_t size, const std::vector<NimBLEUUID>& uuids) {
|
||||
uint8_t bytes = size / 8;
|
||||
uint8_t length = 2; // start with 2 for length + type bytes
|
||||
uint8_t data[31];
|
||||
uint8_t data[BLE_HS_ADV_MAX_SZ];
|
||||
|
||||
for (const auto& uuid : uuids) {
|
||||
if (uuid.bitSize() != size) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Service UUID(%d) invalid", size);
|
||||
continue;
|
||||
} else {
|
||||
if (length + bytes >= 31) {
|
||||
if (length + bytes >= BLE_HS_ADV_MAX_SZ) {
|
||||
NIMBLE_LOGW(LOG_TAG, "Too many services - truncating");
|
||||
complete = false;
|
||||
break;
|
||||
@@ -432,6 +444,7 @@ bool NimBLEAdvertisementData::setServices(bool complete, uint8_t size, const std
|
||||
data[1] = (complete ? BLE_HS_ADV_TYPE_COMP_UUIDS128 : BLE_HS_ADV_TYPE_INCOMP_UUIDS128);
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot set services, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -449,7 +462,7 @@ bool NimBLEAdvertisementData::setServices(bool complete, uint8_t size, const std
|
||||
bool NimBLEAdvertisementData::setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length) {
|
||||
uint8_t uuidBytes = uuid.bitSize() / 8;
|
||||
uint8_t sDataLen = 2 + uuidBytes + length;
|
||||
if (sDataLen > 31) {
|
||||
if (sDataLen > BLE_HS_ADV_MAX_SZ) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Service Data too long");
|
||||
return false;
|
||||
}
|
||||
@@ -466,6 +479,7 @@ bool NimBLEAdvertisementData::setServiceData(const NimBLEUUID& uuid, const uint8
|
||||
type = BLE_HS_ADV_TYPE_SVC_DATA_UUID128;
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot set service data, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -474,7 +488,7 @@ bool NimBLEAdvertisementData::setServiceData(const NimBLEUUID& uuid, const uint8
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t sData[31];
|
||||
uint8_t sData[BLE_HS_ADV_MAX_SZ];
|
||||
sData[0] = uuidBytes + length + 1;
|
||||
sData[1] = type;
|
||||
memcpy(&sData[2], uuid.getValue(), uuidBytes);
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* NimBLEAdvertisementData.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on November 24, 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_ADVERTISEMENT_DATA_H_
|
||||
@@ -13,9 +22,9 @@
|
||||
#if (defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_BROADCASTER) && !CONFIG_BT_NIMBLE_EXT_ADV) || \
|
||||
defined(_DOXYGEN_)
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
# include <cstdint>
|
||||
# include <string>
|
||||
# include <vector>
|
||||
|
||||
class NimBLEUUID;
|
||||
/**
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
/*
|
||||
* NimBLEAdvertising.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 3, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
*
|
||||
* BLEAdvertising.cpp
|
||||
*
|
||||
* This class encapsulates advertising a BLE Server.
|
||||
* Created on: Jun 21, 2017
|
||||
* Author: kolban
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -407,7 +408,7 @@ bool NimBLEAdvertising::refreshAdvertisingData() {
|
||||
* @return True if the service was added successfully.
|
||||
*/
|
||||
bool NimBLEAdvertising::addServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
if (!m_advData.addServiceUUID(serviceUUID) && m_scanResp) {
|
||||
if (!m_advData.addServiceUUID(serviceUUID)) {
|
||||
if (!m_scanData.addServiceUUID(serviceUUID)) {
|
||||
return false;
|
||||
}
|
||||
@@ -465,7 +466,7 @@ bool NimBLEAdvertising::removeServices() {
|
||||
* @return True if the appearance was set successfully.
|
||||
*/
|
||||
bool NimBLEAdvertising::setAppearance(uint16_t appearance) {
|
||||
if (!m_advData.setAppearance(appearance) && m_scanResp) {
|
||||
if (!m_advData.setAppearance(appearance)) {
|
||||
if (!m_scanData.setAppearance(appearance)) {
|
||||
return false;
|
||||
}
|
||||
@@ -483,7 +484,7 @@ bool NimBLEAdvertising::setAppearance(uint16_t appearance) {
|
||||
* @details Range = 0x0006(7.5ms) to 0x0C80(4000ms), values not within the range will be limited to this range.
|
||||
*/
|
||||
bool NimBLEAdvertising::setPreferredParams(uint16_t minInterval, uint16_t maxInterval) {
|
||||
if (!m_advData.setPreferredParams(minInterval, maxInterval) && m_scanResp) {
|
||||
if (!m_advData.setPreferredParams(minInterval, maxInterval)) {
|
||||
if (!m_scanData.setPreferredParams(minInterval, maxInterval)) {
|
||||
return false;
|
||||
}
|
||||
@@ -498,7 +499,7 @@ bool NimBLEAdvertising::setPreferredParams(uint16_t minInterval, uint16_t maxInt
|
||||
* @return True if the transmission power level was added successfully.
|
||||
*/
|
||||
bool NimBLEAdvertising::addTxPower() {
|
||||
if (!m_advData.addTxPower() && m_scanResp) {
|
||||
if (!m_advData.addTxPower()) {
|
||||
if (!m_scanData.addTxPower()) {
|
||||
return false;
|
||||
}
|
||||
@@ -536,7 +537,7 @@ bool NimBLEAdvertising::setName(const std::string& name) {
|
||||
* @return True if the manufacturer data was set successfully.
|
||||
*/
|
||||
bool NimBLEAdvertising::setManufacturerData(const uint8_t* data, size_t length) {
|
||||
if (!m_advData.setManufacturerData(data, length) && m_scanResp) {
|
||||
if (!m_advData.setManufacturerData(data, length)) {
|
||||
if (!m_scanData.setManufacturerData(data, length)) {
|
||||
return false;
|
||||
}
|
||||
@@ -570,7 +571,7 @@ bool NimBLEAdvertising::setManufacturerData(const std::vector<uint8_t>& data) {
|
||||
* @return True if the URI was set successfully.
|
||||
*/
|
||||
bool NimBLEAdvertising::setURI(const std::string& uri) {
|
||||
if (!m_advData.setURI(uri) && m_scanResp) {
|
||||
if (!m_advData.setURI(uri)) {
|
||||
if (!m_scanData.setURI(uri)) {
|
||||
return false;
|
||||
}
|
||||
@@ -589,7 +590,7 @@ bool NimBLEAdvertising::setURI(const std::string& uri) {
|
||||
* @note If data length is 0 the service data will not be advertised.
|
||||
*/
|
||||
bool NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const uint8_t* data, size_t length) {
|
||||
if (!m_advData.setServiceData(uuid, data, length) && m_scanResp) {
|
||||
if (!m_advData.setServiceData(uuid, data, length)) {
|
||||
if (!m_scanData.setServiceData(uuid, data, length)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEAdvertising.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 3, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEAdvertising.h
|
||||
*
|
||||
* Created on: Jun 21, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_ADVERTISING_H_
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* NimBLEAttValue.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on July 17, 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -16,6 +25,9 @@
|
||||
# endif
|
||||
|
||||
# include "NimBLEAttValue.h"
|
||||
# include "NimBLELog.h"
|
||||
|
||||
static const char* LOG_TAG = "NimBLEAttValue";
|
||||
|
||||
// Default constructor implementation.
|
||||
NimBLEAttValue::NimBLEAttValue(uint16_t init_len, uint16_t max_len)
|
||||
@@ -29,14 +41,17 @@ NimBLEAttValue::NimBLEAttValue(uint16_t init_len, uint16_t max_len)
|
||||
# endif
|
||||
{
|
||||
NIMBLE_CPP_DEBUG_ASSERT(m_attr_value);
|
||||
if (m_attr_value == nullptr) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Failed to calloc ctx");
|
||||
}
|
||||
}
|
||||
|
||||
// Value constructor implementation.
|
||||
NimBLEAttValue::NimBLEAttValue(const uint8_t *value, uint16_t len, uint16_t max_len)
|
||||
: NimBLEAttValue(len, max_len) {
|
||||
memcpy(m_attr_value, value, len);
|
||||
m_attr_value[len] = '\0';
|
||||
m_attr_len = len;
|
||||
NimBLEAttValue::NimBLEAttValue(const uint8_t* value, uint16_t len, uint16_t max_len) : NimBLEAttValue(len, max_len) {
|
||||
if (m_attr_value != nullptr) {
|
||||
memcpy(m_attr_value, value, len);
|
||||
m_attr_len = len;
|
||||
}
|
||||
}
|
||||
|
||||
// Destructor implementation.
|
||||
@@ -73,6 +88,10 @@ NimBLEAttValue& NimBLEAttValue::operator=(const NimBLEAttValue& source) {
|
||||
void NimBLEAttValue::deepCopy(const NimBLEAttValue& source) {
|
||||
uint8_t* res = static_cast<uint8_t*>(realloc(m_attr_value, source.m_capacity + 1));
|
||||
NIMBLE_CPP_DEBUG_ASSERT(res);
|
||||
if (res == nullptr) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Failed to realloc deepCopy");
|
||||
return;
|
||||
}
|
||||
|
||||
ble_npl_hw_enter_critical();
|
||||
m_attr_value = res;
|
||||
@@ -98,7 +117,7 @@ NimBLEAttValue& NimBLEAttValue::append(const uint8_t* value, uint16_t len) {
|
||||
}
|
||||
|
||||
if ((m_attr_len + len) > m_attr_max_len) {
|
||||
NIMBLE_LOGE("NimBLEAttValue", "val > max, len=%u, max=%u", len, m_attr_max_len);
|
||||
NIMBLE_LOGE(LOG_TAG, "val > max, len=%u, max=%u", len, m_attr_max_len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -109,6 +128,10 @@ NimBLEAttValue& NimBLEAttValue::append(const uint8_t* value, uint16_t len) {
|
||||
m_capacity = new_len;
|
||||
}
|
||||
NIMBLE_CPP_DEBUG_ASSERT(res);
|
||||
if (res == nullptr) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Failed to realloc append");
|
||||
return *this;
|
||||
}
|
||||
|
||||
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
|
||||
time_t t = time(nullptr);
|
||||
@@ -127,4 +150,13 @@ NimBLEAttValue& NimBLEAttValue::append(const uint8_t* value, uint16_t len) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
uint8_t NimBLEAttValue::operator[](int pos) const {
|
||||
NIMBLE_CPP_DEBUG_ASSERT(pos < m_attr_len);
|
||||
if (pos >= m_attr_len) {
|
||||
NIMBLE_LOGE(LOG_TAG, "pos >= len, pos=%u, len=%u", pos, m_attr_len);
|
||||
return 0;
|
||||
}
|
||||
return m_attr_value[pos];
|
||||
}
|
||||
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* NimBLEAttValue.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 18, 2021
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_ATTVALUE_H
|
||||
@@ -15,7 +24,6 @@
|
||||
# include <Arduino.h>
|
||||
# endif
|
||||
|
||||
# include "NimBLELog.h"
|
||||
# include <string>
|
||||
# include <vector>
|
||||
# include <ctime>
|
||||
@@ -314,10 +322,7 @@ class NimBLEAttValue {
|
||||
/*********************** Operators ************************/
|
||||
|
||||
/** @brief Subscript operator */
|
||||
uint8_t operator[](int pos) const {
|
||||
NIMBLE_CPP_DEBUG_ASSERT(pos < m_attr_len);
|
||||
return m_attr_value[pos];
|
||||
}
|
||||
uint8_t operator[](int pos) const;
|
||||
|
||||
/** @brief Operator; Get the value as a std::vector<uint8_t>. */
|
||||
operator std::vector<uint8_t>() const { return std::vector<uint8_t>(m_attr_value, m_attr_value + m_attr_len); }
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
/*
|
||||
* NimBLEAttribute.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on July 28 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_ATTRIBUTE_H_
|
||||
@@ -43,7 +53,7 @@ class NimBLEAttribute {
|
||||
~NimBLEAttribute() = default;
|
||||
|
||||
const NimBLEUUID m_uuid{};
|
||||
uint16_t m_handle{0};
|
||||
uint16_t m_handle{0};
|
||||
};
|
||||
|
||||
#endif // CONFIG_BT_ENABLED && (CONFIG_BT_NIMBLE_ROLE_PERIPHERAL || CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEBeacon.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 15 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEBeacon.cpp
|
||||
*
|
||||
* Created on: Jan 4, 2018
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEBeacon.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 15 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEBeacon.h
|
||||
*
|
||||
* Created on: Jan 4, 2018
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_BEACON_H_
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
/*
|
||||
* NimBLECharacteristic.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 3, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* BLECharacteristic.cpp
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Created on: Jun 22, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
/*
|
||||
* NimBLECharacteristic.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 3, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* BLECharacteristic.h
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Created on: Jun 22, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_CHARACTERISTIC_H_
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
/*
|
||||
* NimBLEClient.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 26 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* BLEClient.cpp
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Created on: Mar 22, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -21,7 +25,7 @@
|
||||
# include "NimBLELog.h"
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
//# include "nimble/nimble_port.h"
|
||||
# include "nimble/nimble_port.h"
|
||||
# else
|
||||
# include "nimble/porting/nimble/include/nimble/nimble_port.h"
|
||||
# endif
|
||||
@@ -304,7 +308,7 @@ bool NimBLEClient::secureConnection(bool async) const {
|
||||
|
||||
int rc = 0;
|
||||
if (async && !NimBLEDevice::startSecurity(m_connHandle, &rc)) {
|
||||
m_lastErr = rc;
|
||||
m_lastErr = rc;
|
||||
m_asyncSecureAttempt = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
/*
|
||||
* NimBLEClient.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 26 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* BLEClient.h
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Created on: Mar 22, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_CLIENT_H_
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLECONNINFO_H_
|
||||
#define NIMBLECONNINFO_H_
|
||||
|
||||
@@ -60,7 +77,7 @@ class NimBLEConnInfo {
|
||||
friend class NimBLEDescriptor;
|
||||
|
||||
ble_gap_conn_desc m_desc{};
|
||||
NimBLEConnInfo(){};
|
||||
NimBLEConnInfo() {};
|
||||
NimBLEConnInfo(ble_gap_conn_desc desc) { m_desc = desc; }
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEDescriptor.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 10, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEDescriptor.cpp
|
||||
*
|
||||
* Created on: Jun 22, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEDescriptor.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 10, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEDescriptor.h
|
||||
*
|
||||
* Created on: Jun 22, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_DESCRIPTOR_H_
|
||||
@@ -18,17 +21,12 @@
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
class NimBLEDescriptor;
|
||||
class NimBLEDescriptorCallbacks;
|
||||
|
||||
# include "NimBLELocalValueAttribute.h"
|
||||
# include "NimBLECharacteristic.h"
|
||||
# include "NimBLEUUID.h"
|
||||
# include "NimBLEAttValue.h"
|
||||
# include "NimBLEConnInfo.h"
|
||||
|
||||
# include <string>
|
||||
|
||||
class NimBLECharacteristic;
|
||||
class NimBLEDescriptorCallbacks;
|
||||
|
||||
/**
|
||||
* @brief A model of a BLE descriptor.
|
||||
*/
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEDevice.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEDevice.cpp
|
||||
*
|
||||
* Created on: Mar 16, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -39,12 +42,7 @@
|
||||
# include "nimble/esp_port/esp-hci/include/esp_nimble_hci.h"
|
||||
# endif
|
||||
# else
|
||||
//# include "nimble/nimble/controller/include/controller/ble_phy.h"
|
||||
# include "controller/ble_phy.h"
|
||||
# include "host/ble_hs.h"
|
||||
# include "host/util/util.h"
|
||||
# include "services/gap/ble_svc_gap.h"
|
||||
# include "services/gatt/ble_svc_gatt.h"
|
||||
# include "nimble/nimble/controller/include/controller/ble_phy.h"
|
||||
# endif
|
||||
|
||||
# ifndef CONFIG_NIMBLE_CPP_IDF
|
||||
@@ -517,7 +515,7 @@ int NimBLEDevice::getPower() {
|
||||
return 0;
|
||||
# endif
|
||||
# else
|
||||
return ble_phy_tx_power_get(); //ble_phy_txpwr_get();
|
||||
return ble_phy_txpwr_get();
|
||||
# endif
|
||||
} // getPower
|
||||
|
||||
@@ -616,18 +614,14 @@ bool NimBLEDevice::isBonded(const NimBLEAddress& address) {
|
||||
/**
|
||||
* @brief Get the address of a bonded peer device by index.
|
||||
* @param [in] index The index to retrieve the peer address of.
|
||||
* @returns NimBLEAddress of the found bonded peer or nullptr if not found.
|
||||
* @returns NimBLEAddress of the found bonded peer or null address if not found.
|
||||
*/
|
||||
NimBLEAddress NimBLEDevice::getBondedAddress(int index) {
|
||||
ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
|
||||
int num_peers, rc;
|
||||
rc = ble_store_util_bonded_peers(&peer_id_addrs[0], &num_peers, MYNEWT_VAL(BLE_STORE_MAX_BONDS));
|
||||
if (rc != 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (index > num_peers || index < 0) {
|
||||
return nullptr;
|
||||
if (rc != 0 || index > num_peers || index < 0) {
|
||||
return NimBLEAddress{};
|
||||
}
|
||||
|
||||
return NimBLEAddress(peer_id_addrs[index]);
|
||||
@@ -706,12 +700,12 @@ size_t NimBLEDevice::getWhiteListCount() {
|
||||
/**
|
||||
* @brief Gets the address at the vector index.
|
||||
* @param [in] index The vector index to retrieve the address from.
|
||||
* @returns The NimBLEAddress at the whitelist index or nullptr if not found.
|
||||
* @returns The NimBLEAddress at the whitelist index or null address if not found.
|
||||
*/
|
||||
NimBLEAddress NimBLEDevice::getWhiteListAddress(size_t index) {
|
||||
if (index > m_whiteList.size()) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Invalid index; %u", index);
|
||||
return nullptr;
|
||||
return NimBLEAddress{};
|
||||
}
|
||||
|
||||
return m_whiteList[index];
|
||||
@@ -814,19 +808,10 @@ void NimBLEDevice::onSync(void) {
|
||||
*/
|
||||
void NimBLEDevice::host_task(void* param) {
|
||||
NIMBLE_LOGI(LOG_TAG, "BLE Host Task Started");
|
||||
#ifndef MYNEWT
|
||||
nimble_port_run(); // This function will return only when nimble_port_stop() is executed
|
||||
nimble_port_freertos_deinit();
|
||||
#else
|
||||
while (1) {
|
||||
os_eventq_run(os_eventq_dflt_get());
|
||||
}
|
||||
#endif
|
||||
} // host_task
|
||||
|
||||
static struct os_task ble_nimble_task;
|
||||
static os_stack_t ble_nimble_stack[1024];
|
||||
|
||||
/**
|
||||
* @brief Initialize the BLE environment.
|
||||
* @param [in] deviceName The device name of the device.
|
||||
@@ -889,10 +874,8 @@ bool NimBLEDevice::init(const std::string& deviceName) {
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#ifndef MYNEWT
|
||||
nimble_port_init();
|
||||
#endif
|
||||
|
||||
// Setup callbacks for host events
|
||||
ble_hs_cfg.reset_cb = NimBLEDevice::onReset;
|
||||
ble_hs_cfg.sync_cb = NimBLEDevice::onSync;
|
||||
@@ -907,13 +890,8 @@ bool NimBLEDevice::init(const std::string& deviceName) {
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr; /*TODO: Implement handler for this*/
|
||||
|
||||
setDeviceName(deviceName);
|
||||
#ifndef MYNEWT
|
||||
ble_store_config_init();
|
||||
nimble_port_freertos_init(NimBLEDevice::host_task);
|
||||
#else
|
||||
os_task_init(&ble_nimble_task, "ble_nimble_task", NimBLEDevice::host_task, NULL, 8,
|
||||
OS_WAIT_FOREVER, ble_nimble_stack, 1024);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Wait for host and controller to sync before returning and accepting new tasks
|
||||
@@ -935,7 +913,6 @@ bool NimBLEDevice::init(const std::string& deviceName) {
|
||||
bool NimBLEDevice::deinit(bool clearAll) {
|
||||
int rc = 0;
|
||||
if (m_initialized) {
|
||||
#ifndef MYNEWT
|
||||
rc = nimble_port_stop();
|
||||
if (rc == 0) {
|
||||
nimble_port_deinit();
|
||||
@@ -947,10 +924,6 @@ bool NimBLEDevice::deinit(bool clearAll) {
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
rc = ble_hs_shutdown(0);
|
||||
if (rc == 0) {
|
||||
#endif
|
||||
m_initialized = false;
|
||||
m_synced = false;
|
||||
}
|
||||
@@ -1181,6 +1154,7 @@ bool NimBLEDevice::startSecurity(uint16_t connHandle, int* rcPtr) {
|
||||
return rc == 0 || rc == BLE_HS_EALREADY;
|
||||
} // startSecurity
|
||||
|
||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
/**
|
||||
* @brief Inject the provided passkey into the Security Manager.
|
||||
* @param [in] peerInfo Connection information for the peer.
|
||||
@@ -1205,6 +1179,7 @@ bool NimBLEDevice::injectConfirmPasskey(const NimBLEConnInfo& peerInfo, bool acc
|
||||
NIMBLE_LOGD(LOG_TAG, "BLE_SM_IOACT_NUMCMP; ble_sm_inject_io result: %d", rc);
|
||||
return rc == 0;
|
||||
}
|
||||
# endif // CONFIG_BT_NIMBLE_ROLE_CENTRAL || CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* UTILITIES */
|
||||
@@ -1256,7 +1231,8 @@ std::string NimBLEDevice::toString() {
|
||||
* @param [in] line The line number where the assert occurred.
|
||||
*/
|
||||
void nimble_cpp_assert(const char* file, unsigned line) {
|
||||
NIMBLE_LOGC("", "Assertion failed at %s:%u\n", file, line);
|
||||
console_printf("Assertion failed at %s:%u\n", file, line);
|
||||
ble_npl_time_delay(10);
|
||||
abort();
|
||||
}
|
||||
# endif // CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEDevice.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEDevice.h
|
||||
*
|
||||
* Created on: Mar 16, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_DEVICE_H_
|
||||
@@ -279,5 +282,11 @@ class NimBLEDevice {
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) || defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
# include "NimBLEConnInfo.h"
|
||||
# endif
|
||||
|
||||
# include "NimBLEUtils.h"
|
||||
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
#endif // NIMBLE_CPP_DEVICE_H_
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEEddystoneTLM.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 15 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEEddystoneTLM.cpp
|
||||
*
|
||||
* Created on: Mar 12, 2018
|
||||
* Author: pcbreflux
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEEddystoneTLM.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 15 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEEddystoneTLM.h
|
||||
*
|
||||
* Created on: Mar 12, 2018
|
||||
* Author: pcbreflux
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_EDDYSTONETLM_H_
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
/*
|
||||
* NimBLEExtAdvertising.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on February 6, 2022
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -691,6 +701,7 @@ bool NimBLEExtAdvertisement::addServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
type = BLE_HS_ADV_TYPE_COMP_UUIDS128;
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot add UUID, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -701,10 +712,11 @@ bool NimBLEExtAdvertisement::addServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
}
|
||||
|
||||
if (length + getDataSize() > CONFIG_BT_NIMBLE_MAX_EXT_ADV_DATA_LEN) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot add UUID, data length exceeded!");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t data[31];
|
||||
uint8_t data[BLE_HS_ADV_MAX_SZ];
|
||||
const uint8_t* uuid = serviceUUID.getValue();
|
||||
if (dataLoc == -1) {
|
||||
data[0] = 1 + bytes;
|
||||
@@ -746,6 +758,7 @@ bool NimBLEExtAdvertisement::removeServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
type = BLE_HS_ADV_TYPE_COMP_UUIDS128;
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot remove UUID, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -755,7 +768,7 @@ bool NimBLEExtAdvertisement::removeServiceUUID(const NimBLEUUID& serviceUUID) {
|
||||
}
|
||||
|
||||
int uuidLoc = -1;
|
||||
for (int i = dataLoc + 2; i < m_payload.size(); i += bytes) {
|
||||
for (size_t i = dataLoc + 2; i < m_payload.size(); i += bytes) {
|
||||
if (memcmp(&m_payload[i], serviceUUID.getValue(), bytes) == 0) {
|
||||
uuidLoc = i;
|
||||
break;
|
||||
@@ -868,6 +881,7 @@ bool NimBLEExtAdvertisement::setServices(bool complete, uint8_t size, const std:
|
||||
header[1] = complete ? BLE_HS_ADV_TYPE_COMP_UUIDS128 : BLE_HS_ADV_TYPE_INCOMP_UUIDS128;
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot set services, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -922,6 +936,7 @@ bool NimBLEExtAdvertisement::setServiceData(const NimBLEUUID& uuid, const uint8_
|
||||
type = BLE_HS_ADV_TYPE_SVC_DATA_UUID128;
|
||||
break;
|
||||
default:
|
||||
NIMBLE_LOGE(LOG_TAG, "Cannot set service data, invalid size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1009,7 +1024,7 @@ void NimBLEExtAdvertisement::addTxPower() {
|
||||
* @return -1 if the data is not found, otherwise the index of the data in the payload.
|
||||
*/
|
||||
int NimBLEExtAdvertisement::getDataLocation(uint8_t type) const {
|
||||
int index = 0;
|
||||
size_t index = 0;
|
||||
while (index < m_payload.size()) {
|
||||
if (m_payload[index + 1] == type) {
|
||||
return index;
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
/*
|
||||
* NimBLEExtAdvertising.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on February 6, 2022
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_EXTADVERTISING_H_
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEHIDDevice.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Oct 06 2020
|
||||
* Author wakwak-koba
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEHIDDevice.cpp
|
||||
*
|
||||
* Created on: Jan 03, 2018
|
||||
* Author: chegewara
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -146,14 +149,35 @@ void NimBLEHIDDevice::setBatteryLevel(uint8_t level, bool notify) {
|
||||
}
|
||||
} // setBatteryLevel
|
||||
|
||||
/**
|
||||
* @brief Locate the characteristic for a report ID and a report type.
|
||||
*
|
||||
* @param [in] reportId Report identifier to locate.
|
||||
* @param [in] reportType Type of report (input/output/feature).
|
||||
* @return NimBLECharacteristic* The characteristic.
|
||||
* @return nullptr If the characteristic does not exist.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::locateReportCharacteristicByIdAndType(uint8_t reportId, uint8_t reportType) {
|
||||
NimBLECharacteristic* candidate = m_hidSvc->getCharacteristic(inputReportChrUuid, 0);
|
||||
for (uint16_t i = 1; (candidate != nullptr) && (i != 0); i++) {
|
||||
NimBLEDescriptor* dsc = candidate->getDescriptorByUUID(featureReportDscUuid);
|
||||
NimBLEAttValue desc1_val_att = dsc->getValue();
|
||||
const uint8_t* desc1_val = desc1_val_att.data();
|
||||
if ((desc1_val[0] == reportId) && (desc1_val[1] == reportType)) return candidate;
|
||||
candidate = m_hidSvc->getCharacteristic(inputReportChrUuid, i);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the input report characteristic.
|
||||
* @param [in] reportId input report ID, the same as in report map for input object related to the characteristic.
|
||||
* @return A pointer to the input report characteristic.
|
||||
* @param [in] reportId Input report ID, the same as in report map for input object related to the characteristic.
|
||||
* @return NimBLECharacteristic* A pointer to the input report characteristic.
|
||||
* Store this value to avoid computational overhead.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getInputReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* inputReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
NimBLECharacteristic* inputReportChr = locateReportCharacteristicByIdAndType(reportId, 0x01);
|
||||
if (inputReportChr == nullptr) {
|
||||
inputReportChr =
|
||||
m_hidSvc->createCharacteristic(inputReportChrUuid,
|
||||
@@ -171,11 +195,12 @@ NimBLECharacteristic* NimBLEHIDDevice::getInputReport(uint8_t reportId) {
|
||||
/**
|
||||
* @brief Get the output report characteristic.
|
||||
* @param [in] reportId Output report ID, the same as in report map for output object related to the characteristic.
|
||||
* @return A pointer to the output report characteristic.
|
||||
* @return NimBLECharacteristic* A pointer to the output report characteristic.
|
||||
* Store this value to avoid computational overhead.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* outputReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
NimBLECharacteristic* outputReportChr = locateReportCharacteristicByIdAndType(reportId, 0x02);
|
||||
if (outputReportChr == nullptr) {
|
||||
outputReportChr =
|
||||
m_hidSvc->createCharacteristic(inputReportChrUuid,
|
||||
@@ -184,7 +209,6 @@ NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
|
||||
NimBLEDescriptor* outputReportDsc = outputReportChr->createDescriptor(
|
||||
featureReportDscUuid,
|
||||
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC);
|
||||
|
||||
uint8_t desc1_val[] = {reportId, 0x02};
|
||||
outputReportDsc->setValue(desc1_val, 2);
|
||||
}
|
||||
@@ -195,11 +219,12 @@ NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
|
||||
/**
|
||||
* @brief Get the feature report characteristic.
|
||||
* @param [in] reportId Feature report ID, the same as in report map for feature object related to the characteristic.
|
||||
* @return A pointer to feature report characteristic.
|
||||
* @return NimBLECharacteristic* A pointer to feature report characteristic.
|
||||
* Store this value to avoid computational overhead.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getFeatureReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* featureReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
NimBLECharacteristic* featureReportChr = locateReportCharacteristicByIdAndType(reportId, 0x03);
|
||||
if (featureReportChr == nullptr) {
|
||||
featureReportChr = m_hidSvc->createCharacteristic(
|
||||
inputReportChrUuid,
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEHIDDevice.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Oct 06 2020
|
||||
* Author wakwak-koba
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEHIDDevice.h
|
||||
*
|
||||
* Created on: Jan 03, 2018
|
||||
* Author: chegewara
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_HIDDEVICE_H_
|
||||
@@ -78,6 +81,8 @@ class NimBLEHIDDevice {
|
||||
NimBLECharacteristic* m_hidControlChr{nullptr}; // 0x2a4c
|
||||
NimBLECharacteristic* m_protocolModeChr{nullptr}; // 0x2a4e
|
||||
NimBLECharacteristic* m_batteryLevelChr{nullptr}; // 0x2a19
|
||||
|
||||
NimBLECharacteristic* locateReportCharacteristicByIdAndType(uint8_t reportId, uint8_t reportType);
|
||||
};
|
||||
|
||||
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
/*
|
||||
* NimBLELocalAttribute.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on July 28 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_LOCAL_ATTRIBUTE_H_
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
/*
|
||||
* NimBLELocalValueAttribute.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on July 28 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_LOCAL_VALUE_ATTRIBUTE_H_
|
||||
|
||||
@@ -1,81 +1,78 @@
|
||||
/*
|
||||
* NimBLELog.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Feb 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MAIN_NIMBLELOG_H_
|
||||
#define MAIN_NIMBLELOG_H_
|
||||
|
||||
#ifndef NIMBLE_CPP_LOG_H_
|
||||
#define NIMBLE_CPP_LOG_H_
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if (0) // using esp-idf
|
||||
# if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
# include "esp_log.h"
|
||||
# include "console/console.h"
|
||||
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# 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__); \
|
||||
} while(0)
|
||||
# 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)
|
||||
|
||||
# define NIMBLE_LOGD(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
|
||||
# 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__)
|
||||
# define NIMBLE_LOGE(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, 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__)
|
||||
|
||||
# define NIMBLE_LOGE(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
|
||||
|
||||
#else // using Arduino
|
||||
//# include "nimble/porting/nimble/include/syscfg/syscfg.h"
|
||||
//# include "nimble/console/console.h"
|
||||
# include "syscfg/syscfg.h"
|
||||
# include "console/console.h"
|
||||
# else
|
||||
# include "nimble/porting/nimble/include/syscfg/syscfg.h"
|
||||
# include "nimble/console/console.h"
|
||||
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
|
||||
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
|
||||
# else
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
|
||||
# else
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
|
||||
# define NIMBLE_LOGD( tag, format, ... ) console_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGD(tag, format, ...) console_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGD( tag, format, ... ) (void)tag
|
||||
# define NIMBLE_LOGD(tag, format, ...) (void)tag
|
||||
# endif
|
||||
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
|
||||
# define NIMBLE_LOGI( tag, format, ... ) console_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGI(tag, format, ...) console_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGI( tag, format, ... ) (void)tag
|
||||
# define NIMBLE_LOGI(tag, format, ...) (void)tag
|
||||
# endif
|
||||
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 2
|
||||
# define NIMBLE_LOGW( tag, format, ... ) console_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGW(tag, format, ...) console_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGW( tag, format, ... ) (void)tag
|
||||
# define NIMBLE_LOGW(tag, format, ...) (void)tag
|
||||
# endif
|
||||
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 1
|
||||
# define NIMBLE_LOGE( tag, format, ... ) console_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGE(tag, format, ...) console_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGE( tag, format, ... ) (void)tag
|
||||
# define NIMBLE_LOGE(tag, format, ...) (void)tag
|
||||
# endif
|
||||
|
||||
#endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
|
||||
#define NIMBLE_LOGC( tag, format, ... ) console_printf("CRIT %s: " format "\n", tag, ##__VA_ARGS__)
|
||||
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* MAIN_NIMBLELOG_H_ */
|
||||
# endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* NIMBLE_CPP_LOG_H_ */
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteCharacteristic.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 27 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLERemoteCharacteristic.cpp
|
||||
*
|
||||
* Created on: Mar 16, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteCharacteristic.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 27 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLERemoteCharacteristic.h
|
||||
*
|
||||
* Created on: Jul 8, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_REMOTE_CHARACTERISTIC_H_
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteDescriptor.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 27 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLERemoteDescriptor.cpp
|
||||
*
|
||||
* Created on: Jul 8, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -25,7 +28,8 @@
|
||||
*/
|
||||
NimBLERemoteDescriptor::NimBLERemoteDescriptor(const NimBLERemoteCharacteristic* pRemoteCharacteristic,
|
||||
const ble_gatt_dsc* dsc)
|
||||
: NimBLERemoteValueAttribute{dsc->uuid, dsc->handle}, m_pRemoteCharacteristic{pRemoteCharacteristic} {} // NimBLERemoteDescriptor
|
||||
: NimBLERemoteValueAttribute{dsc->uuid, dsc->handle},
|
||||
m_pRemoteCharacteristic{pRemoteCharacteristic} {} // NimBLERemoteDescriptor
|
||||
|
||||
/**
|
||||
* @brief Get the characteristic that owns this descriptor.
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteDescriptor.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 27 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLERemoteDescriptor.h
|
||||
*
|
||||
* Created on: Jul 8, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_REMOTE_DESCRIPTOR_H_
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteService.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 27 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLERemoteService.cpp
|
||||
*
|
||||
* Created on: Jul 8, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -148,7 +151,6 @@ int NimBLERemoteService::characteristicDiscCB(uint16_t conn_handle,
|
||||
auto pTaskData = (NimBLETaskData*)arg;
|
||||
const auto pSvc = (NimBLERemoteService*)pTaskData->m_pInstance;
|
||||
|
||||
|
||||
if (error->status == BLE_HS_ENOTCONN) {
|
||||
NIMBLE_LOGE(LOG_TAG, "<< Characteristic Discovery; Not connected");
|
||||
NimBLEUtils::taskRelease(*pTaskData, error->status);
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteService.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 27 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLERemoteService.h
|
||||
*
|
||||
* Created on: Jul 8, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_REMOTE_SERVICE_H_
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteValueAttribute.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on July 28 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -11,6 +21,7 @@
|
||||
# include "NimBLERemoteValueAttribute.h"
|
||||
# include "NimBLEClient.h"
|
||||
# include "NimBLEUtils.h"
|
||||
# include "NimBLELog.h"
|
||||
|
||||
# include <climits>
|
||||
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
/*
|
||||
* NimBLERemoteValueAttribute.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on July 28 2024
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_REMOTE_VALUE_ATTRIBUTE_H_
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEScan.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEScan.cpp
|
||||
*
|
||||
* Created on: Jul 1, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -116,19 +119,19 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
|
||||
}
|
||||
|
||||
if (!advertisedDevice->m_callbackSent) {
|
||||
pScan->m_pScanCallbacks->onDiscovered(advertisedDevice);
|
||||
advertisedDevice->m_callbackSent++;
|
||||
pScan->m_pScanCallbacks->onDiscovered(advertisedDevice);
|
||||
}
|
||||
|
||||
// If not active scanning or scan response is not available
|
||||
// or extended advertisement scanning, report the result to the callback now.
|
||||
if (pScan->m_scanParams.passive || !isLegacyAdv || !advertisedDevice->isScannable()) {
|
||||
pScan->m_pScanCallbacks->onResult(advertisedDevice);
|
||||
advertisedDevice->m_callbackSent++;
|
||||
pScan->m_pScanCallbacks->onResult(advertisedDevice);
|
||||
} else if (isLegacyAdv && event_type == BLE_HCI_ADV_RPT_EVTYPE_SCAN_RSP) {
|
||||
advertisedDevice->m_callbackSent++;
|
||||
// got the scan response report the full data.
|
||||
pScan->m_pScanCallbacks->onResult(advertisedDevice);
|
||||
advertisedDevice->m_callbackSent++;
|
||||
}
|
||||
|
||||
// If not storing results and we have invoked the callback, delete the device.
|
||||
@@ -476,7 +479,6 @@ void NimBLEScan::clearResults() {
|
||||
*/
|
||||
void NimBLEScanResults::dump() const {
|
||||
for (const auto& dev : m_deviceVec) {
|
||||
(void)dev; // suppress unused variable warning when log level is less than info
|
||||
NIMBLE_LOGI(LOG_TAG, "- %s", dev->toString().c_str());
|
||||
}
|
||||
} // dump
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
/*
|
||||
* NimBLEScan.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEScan.h
|
||||
*
|
||||
* Created on: Jul 1, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_SCAN_H_
|
||||
#define NIMBLE_CPP_SCAN_H_
|
||||
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEServer.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 2, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEServer.cpp
|
||||
*
|
||||
* Created on: Apr 16, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -67,9 +70,11 @@ NimBLEServer::~NimBLEServer() {
|
||||
delete m_pServerCallbacks;
|
||||
}
|
||||
|
||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
if (m_pClient != nullptr) {
|
||||
delete m_pClient;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,10 +401,12 @@ int NimBLEServer::handleGapEvent(ble_gap_event* event, void* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
if (pServer->m_pClient && pServer->m_pClient->m_connHandle == event->disconnect.conn.conn_handle) {
|
||||
// If this was also the client make sure it's flagged as disconnected.
|
||||
pServer->m_pClient->m_connHandle = BLE_HS_CONN_HANDLE_NONE;
|
||||
}
|
||||
# endif
|
||||
|
||||
if (pServer->m_svcChanged) {
|
||||
pServer->resetGATT();
|
||||
@@ -604,8 +611,9 @@ int NimBLEServer::handleGattEvent(uint16_t connHandle, uint16_t attrHandle, ble_
|
||||
NIMBLE_LOGD(LOG_TAG,
|
||||
"Gatt %s event",
|
||||
(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR || ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) ? "Read" : "Write");
|
||||
auto pAtt = static_cast<NimBLELocalValueAttribute*>(arg);
|
||||
auto val = pAtt->getAttVal();
|
||||
auto pAtt = static_cast<NimBLELocalValueAttribute*>(arg);
|
||||
const NimBLEAttValue& val = pAtt->getAttVal();
|
||||
|
||||
NimBLEConnInfo peerInfo{};
|
||||
ble_gap_conn_find(connHandle, &peerInfo.m_desc);
|
||||
|
||||
@@ -616,7 +624,7 @@ int NimBLEServer::handleGattEvent(uint16_t connHandle, uint16_t attrHandle, ble_
|
||||
if (connHandle != BLE_HS_CONN_HANDLE_NONE) {
|
||||
// If the packet header is only 8 bytes then this is a follow up of a long read
|
||||
// so we don't want to call the onRead() callback again.
|
||||
if (ctxt->om->om_pkthdr_len > 8 || pAtt->getAttVal().size() <= (ble_att_mtu(connHandle) - 3)) {
|
||||
if (ctxt->om->om_pkthdr_len > 8 || val.size() <= (ble_att_mtu(connHandle) - 3)) {
|
||||
pAtt->readEvent(peerInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEServer.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 2, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEServer.h
|
||||
*
|
||||
* Created on: Apr 16, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_SERVER_H_
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
/*
|
||||
* NimBLEService.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 2, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEService.cpp
|
||||
*
|
||||
* Created on: Mar 25, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// A service is identified by a UUID. A service is also the container for one or more characteristics.
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
@@ -90,6 +91,13 @@ void NimBLEService::dump() const {
|
||||
*/
|
||||
bool NimBLEService::start() {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> start(): Starting service: %s", toString().c_str());
|
||||
|
||||
// If started previously and no characteristics have been added or removed,
|
||||
// then we can skip the service registration process.
|
||||
if (m_pSvcDef->characteristics && !getServer()->m_svcChanged) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If started previously, clear everything and start over
|
||||
if (m_pSvcDef->characteristics) {
|
||||
if (m_pSvcDef->characteristics->descriptors) {
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEService.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on March 2, 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEService.h
|
||||
*
|
||||
* Created on: Mar 25, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_SERVICE_H_
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEUUID.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEUUID.cpp
|
||||
*
|
||||
* Created on: Jun 21, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -334,4 +337,4 @@ NimBLEUUID::operator std::string() const {
|
||||
return ble_uuid_to_str(&m_uuid.u, buf);
|
||||
} // operator std::string
|
||||
|
||||
# endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
/*
|
||||
* NimBLEUUID.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 24 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* Originally:
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* BLEUUID.h
|
||||
*
|
||||
* Created on: Jun 21, 2017
|
||||
* Author: kolban
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_UUID_H_
|
||||
@@ -61,7 +64,7 @@ class NimBLEUUID {
|
||||
|
||||
bool operator==(const NimBLEUUID& rhs) const;
|
||||
bool operator!=(const NimBLEUUID& rhs) const;
|
||||
operator std::string() const;
|
||||
operator std::string() const;
|
||||
|
||||
private:
|
||||
ble_uuid_any_t m_uuid{};
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* NimBLEUtils.cpp
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 25 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "nimconfig.h"
|
||||
@@ -28,6 +37,9 @@
|
||||
# include <climits>
|
||||
|
||||
# if defined INC_FREERTOS_H
|
||||
# ifndef CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT
|
||||
# define CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT 31
|
||||
# endif
|
||||
constexpr uint32_t TASK_BLOCK_BIT = (1 << CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT);
|
||||
# endif
|
||||
|
||||
@@ -66,6 +78,7 @@ NimBLETaskData::NimBLETaskData(void* pInstance, int flags, void* buf)
|
||||
NimBLETaskData::~NimBLETaskData() {
|
||||
# if !defined INC_FREERTOS_H
|
||||
if (m_pHandle != nullptr) {
|
||||
ble_npl_sem_deinit(static_cast<ble_npl_sem*>(m_pHandle));
|
||||
delete static_cast<ble_npl_sem*>(m_pHandle);
|
||||
}
|
||||
# endif
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
/*
|
||||
* NimBLEUtils.h
|
||||
* Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
|
||||
* esp-nimble-cpp, NimBLE-Arduino contributors.
|
||||
*
|
||||
* Created: on Jan 25 2020
|
||||
* Author H2zero
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NIMBLE_CPP_UTILS_H_
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#include "nimconfig_rename.h"
|
||||
|
||||
@@ -150,25 +150,3 @@ void nimble_cpp_assert(const char *file, unsigned line) __attribute((weak, noret
|
||||
#define CONFIG_BT_NIMBLE_TASK_STACK_SIZE 4096
|
||||
|
||||
#endif // _DOXYGEN_
|
||||
#else
|
||||
#include "syscfg/syscfg.h"
|
||||
#define CONFIG_BT_ENABLED
|
||||
#define CONFIG_BT_NIMBLE_ROLE_OBSERVER
|
||||
#define CONFIG_BT_NIMBLE_ROLE_BROADCASTER
|
||||
#define CONFIG_BT_NIMBLE_ROLE_CENTRAL
|
||||
#define CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
|
||||
#define CONFIG_NIMBLE_CPP_IDF
|
||||
#define CONFIG_BT_NIMBLE_MAX_CONNECTIONS 3
|
||||
#define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
#if CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED && !defined NDEBUG
|
||||
void nimble_cpp_assert(const char *file, unsigned line) __attribute((weak, noreturn));
|
||||
# define NIMBLE_ATT_VAL_FILE (__builtin_strrchr(__FILE__, '/') ? \
|
||||
__builtin_strrchr (__FILE__, '/') + 1 : __FILE__)
|
||||
# define NIMBLE_CPP_DEBUG_ASSERT(cond) \
|
||||
if (!(cond)) { \
|
||||
nimble_cpp_assert(NIMBLE_ATT_VAL_FILE, __LINE__); \
|
||||
}
|
||||
#else
|
||||
# define NIMBLE_CPP_DEBUG_ASSERT(cond) (void(0))
|
||||
#endif
|
||||
#endif // ESP_PLATFORM
|
||||
Reference in New Issue
Block a user