mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2025-12-23 15:18:16 +01:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da48844e2f | ||
|
|
ea1c055826 | ||
|
|
65f6ee18ca | ||
|
|
fd0187bfc9 | ||
|
|
275def333c | ||
|
|
ec4d4c43e1 | ||
|
|
3e0ce87a94 | ||
|
|
3743eb954e | ||
|
|
6357a0dbea |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
docs/doxydocs
|
||||
docs/doxydocs
|
||||
|
||||
18
CHANGELOG.md
18
CHANGELOG.md
@@ -1,6 +1,24 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [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**
|
||||
|
||||
@@ -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.2
|
||||
|
||||
# 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,5 @@
|
||||
## IDF Component Manager Manifest File
|
||||
version: "2.0.0"
|
||||
version: "2.0.2"
|
||||
license: "Apache-2.0"
|
||||
description: "C++ wrapper for the NimBLE BLE stack"
|
||||
url: "https://github.com/h2zero/esp-nimble-cpp"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "esp-nimble-cpp",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.1",
|
||||
"description": "C++ wrapper for the NimBLE BLE stack",
|
||||
"keywords": [
|
||||
"BLE",
|
||||
|
||||
@@ -21,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.
|
||||
*/
|
||||
|
||||
@@ -1154,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.
|
||||
@@ -1178,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 */
|
||||
|
||||
@@ -282,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_
|
||||
|
||||
@@ -149,14 +149,41 @@ void NimBLEHIDDevice::setBatteryLevel(uint8_t level, bool notify) {
|
||||
}
|
||||
} // setBatteryLevel
|
||||
|
||||
/**
|
||||
* @brief Locate the characteristic for a report ID.
|
||||
*
|
||||
* @param [in] reportId Report identifier to locate.
|
||||
* @param [out] reportType Type of report (input/output/feature). Not meaningful if the return value is nullptr.
|
||||
* @return NimBLECharacteristic* The characteristic.
|
||||
* @return nullptr If the characteristic does not exist.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::locateReportCharacteristicById(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();
|
||||
reportType = desc1_val[1];
|
||||
if (desc1_val[0] == reportId) 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.
|
||||
* @return nullptr If the report is already created as an output or feature report.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getInputReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* inputReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
uint8_t reportType;
|
||||
NimBLECharacteristic* inputReportChr = locateReportCharacteristicById(reportId, reportType);
|
||||
if ((inputReportChr != nullptr) && (reportType != 0x01))
|
||||
// ERROR: this reportId exists, but it is not an input report
|
||||
return nullptr;
|
||||
if (inputReportChr == nullptr) {
|
||||
inputReportChr =
|
||||
m_hidSvc->createCharacteristic(inputReportChrUuid,
|
||||
@@ -174,11 +201,17 @@ 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.
|
||||
* @return nullptr If the report is already created as an input or feature report.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getOutputReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* outputReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
uint8_t reportType;
|
||||
NimBLECharacteristic* outputReportChr = locateReportCharacteristicById(reportId, reportType);
|
||||
if ((outputReportChr != nullptr) && (reportType != 0x02))
|
||||
// ERROR: this reportId exists, but it is not an output report
|
||||
return nullptr;
|
||||
if (outputReportChr == nullptr) {
|
||||
outputReportChr =
|
||||
m_hidSvc->createCharacteristic(inputReportChrUuid,
|
||||
@@ -187,7 +220,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);
|
||||
}
|
||||
@@ -198,11 +230,17 @@ 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.
|
||||
* @return nullptr If the report is already created as an input or output report.
|
||||
* @details This will create the characteristic if not already created.
|
||||
*/
|
||||
NimBLECharacteristic* NimBLEHIDDevice::getFeatureReport(uint8_t reportId) {
|
||||
NimBLECharacteristic* featureReportChr = m_hidSvc->getCharacteristic(inputReportChrUuid);
|
||||
uint8_t reportType;
|
||||
NimBLECharacteristic* featureReportChr = locateReportCharacteristicById(reportId, reportType);
|
||||
if ((featureReportChr != nullptr) && (reportType != 0x03))
|
||||
// ERROR: this reportId exists, but it is not a feature report
|
||||
return nullptr;
|
||||
if (featureReportChr == nullptr) {
|
||||
featureReportChr = m_hidSvc->createCharacteristic(
|
||||
inputReportChrUuid,
|
||||
|
||||
@@ -81,6 +81,8 @@ class NimBLEHIDDevice {
|
||||
NimBLECharacteristic* m_hidControlChr{nullptr}; // 0x2a4c
|
||||
NimBLECharacteristic* m_protocolModeChr{nullptr}; // 0x2a4e
|
||||
NimBLECharacteristic* m_batteryLevelChr{nullptr}; // 0x2a19
|
||||
|
||||
NimBLECharacteristic* locateReportCharacteristicById(uint8_t reportId, uint8_t& reportType);
|
||||
};
|
||||
|
||||
#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && defined(CONFIG_BT_NIMBLE_ROLE_PERIPHERAL)
|
||||
|
||||
@@ -70,9 +70,11 @@ NimBLEServer::~NimBLEServer() {
|
||||
delete m_pServerCallbacks;
|
||||
}
|
||||
|
||||
# if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
if (m_pClient != nullptr) {
|
||||
delete m_pClient;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,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();
|
||||
|
||||
@@ -91,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) {
|
||||
|
||||
Reference in New Issue
Block a user