mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-03 10:30:55 +01:00
[BREAKING]- Refactor client
* General code cleanup and rename variables to use a consistent style. * Removes the disconnect timer and will use the BLE_GAP_EVENT_TERM_FAILURE event to handle failed disconnects. * `NimBLEClient::getConnId` has been renamed to `getConnHandle` to be consistent with bluetooth terminology. * `NimBLEClient::disconnect` now returns a `bool = true on success` instead of an int to be consistent with the rest of the library. * `NimBLEClient::setPeerAddress` now returns a bool, true on success. * `NimBLEClientCallbacks::onConfirmPIN` renamed to `NimBLEClientCallbacks::onConfirmPasskey` to be consistent with bluetooth terminology. * `NimBLEClient::setDataLen` now returns bool, true if successful. * `NimBLEClient::updateConnParams` now returns bool, true if successful. * `NimBLEClient::getServices` now returns a const reference to std::vector<NimBLERemoteService*> instead of a pointer to the internal vector.
This commit is contained in:
parent
68b82f5b85
commit
020c61700d
19 changed files with 532 additions and 667 deletions
|
@ -383,7 +383,7 @@ The security callback methods are now incorporated in the `NimBLEServerCallbacks
|
|||
|
||||
The callback methods are:
|
||||
|
||||
> `bool onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pin)`
|
||||
> `bool onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pin)`
|
||||
|
||||
Receives the pin when using numeric comparison authentication.
|
||||
Call `NimBLEDevice::injectConfirmPIN(connInfo, true);` to accept or `NimBLEDevice::injectConfirmPIN(connInfo, false);` to reject.
|
||||
|
|
|
@ -47,7 +47,7 @@ class ClientCallbacks : public NimBLEClientCallbacks {
|
|||
NimBLEDevice::injectPassKey(connInfo, 123456);
|
||||
};
|
||||
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||
|
|
|
@ -52,7 +52,7 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
|||
return 123456;
|
||||
};
|
||||
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmasskeyN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||
|
|
|
@ -59,7 +59,7 @@ class MyClientCallback : public BLEClientCallbacks {
|
|||
NimBLEDevice::injectPassKey(connInfo, 123456);
|
||||
};
|
||||
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||
|
|
|
@ -65,7 +65,7 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
|||
return 123456;
|
||||
};
|
||||
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||
|
|
|
@ -67,7 +67,7 @@ class MyServerCallbacks: public BLEServerCallbacks {
|
|||
return 123456;
|
||||
};
|
||||
|
||||
void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
void onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pass_key){
|
||||
printf("The passkey YES/NO number: %" PRIu32 "\n", pass_key);
|
||||
/** Inject false if passkeys don't match. */
|
||||
NimBLEDevice::injectConfirmPasskey(connInfo, true);
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -11,116 +11,121 @@
|
|||
* Author: kolban
|
||||
*/
|
||||
|
||||
#ifndef MAIN_NIMBLECLIENT_H_
|
||||
#define MAIN_NIMBLECLIENT_H_
|
||||
#ifndef NIMBLE_CPP_CLIENT_H_
|
||||
#define NIMBLE_CPP_CLIENT_H_
|
||||
|
||||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED) && defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)
|
||||
|
||||
#include "NimBLEAddress.h"
|
||||
#include "NimBLEUUID.h"
|
||||
#include "NimBLEUtils.h"
|
||||
#include "NimBLEConnInfo.h"
|
||||
#include "NimBLEAttValue.h"
|
||||
#include "NimBLEAdvertisedDevice.h"
|
||||
# if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
# include "host/ble_gap.h"
|
||||
# else
|
||||
# include "nimble/nimble/host/include/host/ble_gap.h"
|
||||
# endif
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
# include "NimBLEAddress.h"
|
||||
|
||||
# include <stdint.h>
|
||||
# include <vector>
|
||||
# include <string>
|
||||
|
||||
class NimBLEAddress;
|
||||
class NimBLEUUID;
|
||||
class NimBLERemoteService;
|
||||
class NimBLERemoteCharacteristic;
|
||||
class NimBLEAdvertisedDevice;
|
||||
class NimBLEAttValue;
|
||||
class NimBLEClientCallbacks;
|
||||
class NimBLEConnInfo;
|
||||
struct BleTaskData;
|
||||
|
||||
/**
|
||||
* @brief A model of a %BLE client.
|
||||
* @brief A model of a BLE client.
|
||||
*/
|
||||
class NimBLEClient {
|
||||
public:
|
||||
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttributes = true);
|
||||
bool connect(const NimBLEAddress &address, bool deleteAttributes = true);
|
||||
bool connect(bool deleteAttributes = true);
|
||||
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
|
||||
NimBLEAddress getPeerAddress() const;
|
||||
void setPeerAddress(const NimBLEAddress &address);
|
||||
int getRssi();
|
||||
std::vector<NimBLERemoteService*>* getServices(bool refresh = false);
|
||||
public:
|
||||
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttributes = true);
|
||||
bool connect(const NimBLEAddress& address, bool deleteAttributes = true);
|
||||
bool connect(bool deleteAttributes = true);
|
||||
bool disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
|
||||
NimBLEAddress getPeerAddress() const;
|
||||
bool setPeerAddress(const NimBLEAddress& address);
|
||||
int getRssi() const;
|
||||
bool isConnected() const;
|
||||
void setClientCallbacks(NimBLEClientCallbacks* pClientCallbacks, bool deleteCallbacks = true);
|
||||
std::string toString() const;
|
||||
uint16_t getConnHandle() const;
|
||||
void clearConnection();
|
||||
bool setConnection(const NimBLEConnInfo& connInfo);
|
||||
bool setConnection(uint16_t connHandle);
|
||||
uint16_t getMTU() const;
|
||||
bool secureConnection() const;
|
||||
void setConnectTimeout(uint32_t timeout);
|
||||
bool setDataLen(uint16_t txOctets);
|
||||
bool discoverAttributes();
|
||||
NimBLEConnInfo getConnInfo() const;
|
||||
int getLastError() const;
|
||||
bool updateConnParams(uint16_t minInterval, uint16_t maxInterval, uint16_t latency, uint16_t timeout);
|
||||
void setConnectionParams(uint16_t minInterval,
|
||||
uint16_t maxInterval,
|
||||
uint16_t latency,
|
||||
uint16_t timeout,
|
||||
uint16_t scanInterval = 16,
|
||||
uint16_t scanWindow = 16);
|
||||
const std::vector<NimBLERemoteService*>& getServices(bool refresh = false);
|
||||
std::vector<NimBLERemoteService*>::iterator begin();
|
||||
std::vector<NimBLERemoteService*>::iterator end();
|
||||
NimBLERemoteCharacteristic* getCharacteristic(uint16_t handle);
|
||||
NimBLERemoteService* getService(const char* uuid);
|
||||
NimBLERemoteService* getService(const NimBLEUUID &uuid);
|
||||
NimBLERemoteService* getService(const NimBLEUUID& uuid);
|
||||
void deleteServices();
|
||||
size_t deleteService(const NimBLEUUID &uuid);
|
||||
NimBLEAttValue getValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID);
|
||||
bool setValue(const NimBLEUUID &serviceUUID, const NimBLEUUID &characteristicUUID,
|
||||
const NimBLEAttValue &value, bool response = false);
|
||||
NimBLERemoteCharacteristic* getCharacteristic(const uint16_t handle);
|
||||
bool isConnected();
|
||||
void setClientCallbacks(NimBLEClientCallbacks *pClientCallbacks,
|
||||
bool deleteCallbacks = true);
|
||||
std::string toString();
|
||||
uint16_t getConnId() const;
|
||||
void clearConnection();
|
||||
bool setConnection(NimBLEConnInfo &conn_info);
|
||||
bool setConnection(uint16_t conn_id);
|
||||
uint16_t getMTU() const;
|
||||
bool secureConnection() const;
|
||||
void setConnectTimeout(uint32_t timeout);
|
||||
void setConnectionParams(uint16_t minInterval, uint16_t maxInterval,
|
||||
uint16_t latency, uint16_t timeout,
|
||||
uint16_t scanInterval=16, uint16_t scanWindow=16);
|
||||
void updateConnParams(uint16_t minInterval, uint16_t maxInterval,
|
||||
uint16_t latency, uint16_t timeout);
|
||||
void setDataLen(uint16_t tx_octets);
|
||||
bool discoverAttributes();
|
||||
NimBLEConnInfo getConnInfo();
|
||||
int getLastError();
|
||||
#if CONFIG_BT_NIMBLE_EXT_ADV
|
||||
void setConnectPhy(uint8_t mask);
|
||||
#endif
|
||||
size_t deleteService(const NimBLEUUID& uuid);
|
||||
NimBLEAttValue getValue(const NimBLEUUID& serviceUUID, const NimBLEUUID& characteristicUUID);
|
||||
bool setValue(const NimBLEUUID& serviceUUID,
|
||||
const NimBLEUUID& characteristicUUID,
|
||||
const NimBLEAttValue& value,
|
||||
bool response = false);
|
||||
|
||||
private:
|
||||
NimBLEClient(const NimBLEAddress &peerAddress);
|
||||
# if CONFIG_BT_NIMBLE_EXT_ADV
|
||||
void setConnectPhy(uint8_t mask);
|
||||
# endif
|
||||
|
||||
private:
|
||||
NimBLEClient(const NimBLEAddress& peerAddress);
|
||||
~NimBLEClient();
|
||||
NimBLEClient(const NimBLEClient&) = delete;
|
||||
NimBLEClient& operator=(const NimBLEClient&) = delete;
|
||||
|
||||
friend class NimBLEDevice;
|
||||
friend class NimBLERemoteService;
|
||||
bool retrieveServices(const NimBLEUUID* uuidFilter = nullptr);
|
||||
static int handleGapEvent(struct ble_gap_event* event, void* arg);
|
||||
static int serviceDiscoveredCB(uint16_t connHandle,
|
||||
const struct ble_gatt_error* error,
|
||||
const struct ble_gatt_svc* service,
|
||||
void* arg);
|
||||
|
||||
static int handleGapEvent(struct ble_gap_event *event, void *arg);
|
||||
static int serviceDiscoveredCB(uint16_t conn_handle,
|
||||
const struct ble_gatt_error *error,
|
||||
const struct ble_gatt_svc *service,
|
||||
void *arg);
|
||||
static void dcTimerCb(ble_npl_event *event);
|
||||
bool retrieveServices(const NimBLEUUID *uuidFilter = nullptr);
|
||||
|
||||
NimBLEAddress m_peerAddress;
|
||||
mutable int m_lastErr;
|
||||
uint16_t m_conn_id;
|
||||
bool m_connEstablished;
|
||||
bool m_deleteCallbacks;
|
||||
int32_t m_connectTimeout;
|
||||
NimBLEClientCallbacks* m_pClientCallbacks;
|
||||
mutable ble_task_data_t* m_pTaskData;
|
||||
ble_npl_callout m_dcTimer;
|
||||
#if CONFIG_BT_NIMBLE_EXT_ADV
|
||||
uint8_t m_phyMask;
|
||||
#endif
|
||||
|
||||
std::vector<NimBLERemoteService*> m_servicesVector;
|
||||
|
||||
private:
|
||||
friend class NimBLEClientCallbacks;
|
||||
ble_gap_conn_params m_pConnParams;
|
||||
NimBLEAddress m_peerAddress;
|
||||
mutable int m_lastErr;
|
||||
int32_t m_connectTimeout;
|
||||
mutable BleTaskData* m_pTaskData;
|
||||
std::vector<NimBLERemoteService*> m_svcVec;
|
||||
NimBLEClientCallbacks* m_pClientCallbacks;
|
||||
uint16_t m_connHandle;
|
||||
uint8_t m_terminateFailCount;
|
||||
bool m_deleteCallbacks;
|
||||
bool m_connEstablished;
|
||||
# if CONFIG_BT_NIMBLE_EXT_ADV
|
||||
uint8_t m_phyMask;
|
||||
# endif
|
||||
ble_gap_conn_params m_connParams;
|
||||
|
||||
friend class NimBLEDevice;
|
||||
}; // class NimBLEClient
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callbacks associated with a %BLE client.
|
||||
*/
|
||||
class NimBLEClientCallbacks {
|
||||
public:
|
||||
public:
|
||||
virtual ~NimBLEClientCallbacks() {};
|
||||
|
||||
/**
|
||||
|
@ -162,7 +167,7 @@ public:
|
|||
* @param [in] connInfo A reference to a NimBLEConnInfo instance containing the peer info.
|
||||
* @param [in] pin The pin to compare with the server.
|
||||
*/
|
||||
virtual void onConfirmPIN(NimBLEConnInfo& connInfo, uint32_t pin);
|
||||
virtual void onConfirmPasskey(NimBLEConnInfo& connInfo, uint32_t pin);
|
||||
|
||||
/**
|
||||
* @brief Called when the peer identity address is resolved.
|
||||
|
@ -172,4 +177,4 @@ public:
|
|||
};
|
||||
|
||||
#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_CENTRAL */
|
||||
#endif /* MAIN_NIMBLECLIENT_H_ */
|
||||
#endif /* NIMBLE_CPP_CLIENT_H_ */
|
||||
|
|
|
@ -324,8 +324,7 @@ bool NimBLEDevice::deleteClient(NimBLEClient* pClient) {
|
|||
int rc = 0;
|
||||
|
||||
if (pClient->isConnected()) {
|
||||
rc = pClient->disconnect();
|
||||
if (rc != 0 && rc != BLE_HS_EALREADY && rc != BLE_HS_ENOTCONN) {
|
||||
if (!pClient->disconnect()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -378,7 +377,7 @@ size_t NimBLEDevice::getCreatedClientCount() {
|
|||
*/
|
||||
NimBLEClient* NimBLEDevice::getClientByHandle(uint16_t connHandle) {
|
||||
for (const auto clt : m_pClients) {
|
||||
if (clt != nullptr && clt->getConnId() == connHandle) {
|
||||
if (clt != nullptr && clt->getConnHandle() == connHandle) {
|
||||
return clt;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ int NimBLERemoteCharacteristic::descriptorDiscCB(
|
|||
NIMBLE_LOGD(LOG_TAG, "Descriptor Discovery >> status: %d handle: %d", rc, (rc == 0) ? dsc->handle : -1);
|
||||
|
||||
auto filter = (desc_filter_t*)arg;
|
||||
auto pTaskData = (ble_task_data_t*)filter->task_data;
|
||||
auto pTaskData = (BleTaskData*)filter->task_data;
|
||||
const auto pChr = (NimBLERemoteCharacteristic*)pTaskData->pATT;
|
||||
const NimBLEUUID* uuidFilter = filter->uuid;
|
||||
|
||||
|
@ -102,10 +102,10 @@ bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID* uuidFilte
|
|||
NIMBLE_LOGD(LOG_TAG, ">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str());
|
||||
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {const_cast<NimBLERemoteCharacteristic*>(this), cur_task, 0, nullptr};
|
||||
BleTaskData taskData = {const_cast<NimBLERemoteCharacteristic*>(this), cur_task, 0, nullptr};
|
||||
desc_filter_t filter = {uuidFilter, &taskData};
|
||||
|
||||
int rc = ble_gattc_disc_all_dscs(getClient()->getConnId(),
|
||||
int rc = ble_gattc_disc_all_dscs(getClient()->getConnHandle(),
|
||||
getHandle(),
|
||||
getRemoteService()->getEndHandle(),
|
||||
NimBLERemoteCharacteristic::descriptorDiscCB,
|
||||
|
|
|
@ -145,11 +145,11 @@ int NimBLERemoteService::characteristicDiscCB(uint16_t conn_handle,
|
|||
const ble_gatt_chr* chr,
|
||||
void* arg) {
|
||||
NIMBLE_LOGD(LOG_TAG, "Characteristic Discovery >>");
|
||||
auto pTaskData = (ble_task_data_t*)arg;
|
||||
auto pTaskData = (BleTaskData*)arg;
|
||||
const auto pSvc = (NimBLERemoteService*)pTaskData->pATT;
|
||||
|
||||
// Make sure the discovery is for this device
|
||||
if (pSvc->getClient()->getConnId() != conn_handle) {
|
||||
if (pSvc->getClient()->getConnHandle() != conn_handle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -173,16 +173,16 @@ bool NimBLERemoteService::retrieveCharacteristics(const NimBLEUUID* uuidFilter)
|
|||
NIMBLE_LOGD(LOG_TAG, ">> retrieveCharacteristics()");
|
||||
int rc = 0;
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {const_cast<NimBLERemoteService*>(this), cur_task, 0, nullptr};
|
||||
BleTaskData taskData = {const_cast<NimBLERemoteService*>(this), cur_task, 0, nullptr};
|
||||
|
||||
if (uuidFilter == nullptr) {
|
||||
rc = ble_gattc_disc_all_chrs(m_pClient->getConnId(),
|
||||
rc = ble_gattc_disc_all_chrs(m_pClient->getConnHandle(),
|
||||
getHandle(),
|
||||
getEndHandle(),
|
||||
NimBLERemoteService::characteristicDiscCB,
|
||||
&taskData);
|
||||
} else {
|
||||
rc = ble_gattc_disc_chrs_by_uuid(m_pClient->getConnId(),
|
||||
rc = ble_gattc_disc_chrs_by_uuid(m_pClient->getConnHandle(),
|
||||
getHandle(),
|
||||
getEndHandle(),
|
||||
uuidFilter->getBase(),
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
# include "NimBLERemoteValueAttribute.h"
|
||||
# include "NimBLEClient.h"
|
||||
# include "NimBLEUtils.h"
|
||||
|
||||
# include <climits>
|
||||
|
||||
|
@ -20,7 +21,7 @@ bool NimBLERemoteValueAttribute::writeValue(const uint8_t* data, size_t length,
|
|||
|
||||
const NimBLEClient* pClient = getClient();
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {const_cast<NimBLERemoteValueAttribute*>(this), cur_task, 0, nullptr};
|
||||
BleTaskData taskData = {const_cast<NimBLERemoteValueAttribute*>(this), cur_task, 0, nullptr};
|
||||
int retryCount = 1;
|
||||
int rc = 0;
|
||||
uint16_t mtu = pClient->getMTU() - 3;
|
||||
|
@ -28,7 +29,7 @@ bool NimBLERemoteValueAttribute::writeValue(const uint8_t* data, size_t length,
|
|||
// Check if the data length is longer than we can write in one connection event.
|
||||
// If so we must do a long write which requires a response.
|
||||
if (length <= mtu && !response) {
|
||||
rc = ble_gattc_write_no_rsp_flat(pClient->getConnId(), getHandle(), data, length);
|
||||
rc = ble_gattc_write_no_rsp_flat(pClient->getConnHandle(), getHandle(), data, length);
|
||||
goto Done;
|
||||
}
|
||||
|
||||
|
@ -36,9 +37,9 @@ bool NimBLERemoteValueAttribute::writeValue(const uint8_t* data, size_t length,
|
|||
if (length > mtu) {
|
||||
NIMBLE_LOGI(LOG_TAG, "writeValue: long write");
|
||||
os_mbuf* om = ble_hs_mbuf_from_flat(data, length);
|
||||
rc = ble_gattc_write_long(pClient->getConnId(), getHandle(), 0, om, NimBLERemoteValueAttribute::onWriteCB, &taskData);
|
||||
rc = ble_gattc_write_long(pClient->getConnHandle(), getHandle(), 0, om, NimBLERemoteValueAttribute::onWriteCB, &taskData);
|
||||
} else {
|
||||
rc = ble_gattc_write_flat(pClient->getConnId(),
|
||||
rc = ble_gattc_write_flat(pClient->getConnHandle(),
|
||||
getHandle(),
|
||||
data,
|
||||
length,
|
||||
|
@ -93,10 +94,10 @@ Done:
|
|||
* @return success == 0 or error code.
|
||||
*/
|
||||
int NimBLERemoteValueAttribute::onWriteCB(uint16_t conn_handle, const ble_gatt_error* error, ble_gatt_attr* attr, void* arg) {
|
||||
auto pTaskData = static_cast<ble_task_data_t*>(arg);
|
||||
auto pTaskData = static_cast<BleTaskData*>(arg);
|
||||
const auto pAtt = static_cast<NimBLERemoteValueAttribute*>(pTaskData->pATT);
|
||||
|
||||
if (pAtt->getClient()->getConnId() != conn_handle) {
|
||||
if (pAtt->getClient()->getConnHandle() != conn_handle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -119,10 +120,10 @@ NimBLEAttValue NimBLERemoteValueAttribute::readValue(time_t* timestamp) const {
|
|||
int rc = 0;
|
||||
int retryCount = 1;
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {const_cast<NimBLERemoteValueAttribute*>(this), cur_task, 0, &value};
|
||||
BleTaskData taskData = {const_cast<NimBLERemoteValueAttribute*>(this), cur_task, 0, &value};
|
||||
|
||||
do {
|
||||
rc = ble_gattc_read_long(pClient->getConnId(), getHandle(), 0, NimBLERemoteValueAttribute::onReadCB, &taskData);
|
||||
rc = ble_gattc_read_long(pClient->getConnHandle(), getHandle(), 0, NimBLERemoteValueAttribute::onReadCB, &taskData);
|
||||
if (rc != 0) {
|
||||
goto Done;
|
||||
}
|
||||
|
@ -142,7 +143,7 @@ NimBLEAttValue NimBLERemoteValueAttribute::readValue(time_t* timestamp) const {
|
|||
// Characteristic is not long-readable, return with what we have.
|
||||
case BLE_HS_ATT_ERR(BLE_ATT_ERR_ATTR_NOT_LONG):
|
||||
NIMBLE_LOGI(LOG_TAG, "Attribute not long");
|
||||
rc = ble_gattc_read(pClient->getConnId(), getHandle(), NimBLERemoteValueAttribute::onReadCB, &taskData);
|
||||
rc = ble_gattc_read(pClient->getConnHandle(), getHandle(), NimBLERemoteValueAttribute::onReadCB, &taskData);
|
||||
if (rc != 0) {
|
||||
goto Done;
|
||||
}
|
||||
|
@ -179,10 +180,10 @@ Done:
|
|||
* @return success == 0 or error code.
|
||||
*/
|
||||
int NimBLERemoteValueAttribute::onReadCB(uint16_t conn_handle, const ble_gatt_error* error, ble_gatt_attr* attr, void* arg) {
|
||||
auto pTaskData = static_cast<ble_task_data_t*>(arg);
|
||||
auto pTaskData = static_cast<BleTaskData*>(arg);
|
||||
const auto pAtt = static_cast<NimBLERemoteValueAttribute*>(pTaskData->pATT);
|
||||
|
||||
if (pAtt->getClient()->getConnId() != conn_handle) {
|
||||
if (pAtt->getClient()->getConnHandle() != conn_handle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -457,7 +457,7 @@ NimBLEScanResults NimBLEScan::getResults(uint32_t duration, bool is_continue) {
|
|||
}
|
||||
|
||||
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
|
||||
ble_task_data_t taskData = {nullptr, cur_task, 0, nullptr};
|
||||
BleTaskData taskData = {nullptr, cur_task, 0, nullptr};
|
||||
m_pTaskData = &taskData;
|
||||
|
||||
if(start(duration, is_continue)) {
|
||||
|
|
|
@ -94,7 +94,7 @@ private:
|
|||
bool m_ignoreResults;
|
||||
NimBLEScanResults m_scanResults;
|
||||
uint32_t m_duration;
|
||||
ble_task_data_t *m_pTaskData;
|
||||
BleTaskData *m_pTaskData;
|
||||
uint8_t m_maxResults;
|
||||
};
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ int NimBLEServer::peerNameCB(uint16_t conn_handle,
|
|||
const struct ble_gatt_error *error,
|
||||
struct ble_gatt_attr *attr,
|
||||
void *arg) {
|
||||
ble_task_data_t *pTaskData = (ble_task_data_t*)arg;
|
||||
BleTaskData *pTaskData = (BleTaskData*)arg;
|
||||
std::string *name = (std::string*)pTaskData->buf;
|
||||
int rc = error->status;
|
||||
|
||||
|
@ -414,7 +414,7 @@ int NimBLEServer::peerNameCB(uint16_t conn_handle,
|
|||
*/
|
||||
std::string NimBLEServer::getPeerNameInternal(uint16_t conn_handle, TaskHandle_t task, int cb_type) {
|
||||
std::string *buf = new std::string{};
|
||||
ble_task_data_t *taskData = new ble_task_data_t{this, task, cb_type, buf};
|
||||
BleTaskData *taskData = new BleTaskData{this, task, cb_type, buf};
|
||||
ble_uuid16_t uuid {{BLE_UUID_TYPE_16}, BLE_SVC_GAP_CHR_UUID16_DEVICE_NAME};
|
||||
int rc = ble_gattc_read_by_uuid(conn_handle,
|
||||
1,
|
||||
|
@ -628,7 +628,7 @@ int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
|||
if (rc != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
pServer->m_pServerCallbacks->onConnParamsUpdate(peerInfo);
|
||||
return 0;
|
||||
} // BLE_GAP_EVENT_CONN_UPDATE
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
# include "NimBLEUUID.h"
|
||||
# include "NimBLELog.h"
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
# undef min
|
||||
# undef max
|
||||
/**************************/
|
||||
|
||||
# include <algorithm>
|
||||
|
||||
static const char* LOG_TAG = "NimBLEUUID";
|
||||
|
|
|
@ -24,11 +24,6 @@
|
|||
# include "nimble/nimble/host/include/host/ble_uuid.h"
|
||||
# endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
# undef min
|
||||
# undef max
|
||||
/**************************/
|
||||
|
||||
# include <string>
|
||||
# include <cstring>
|
||||
|
||||
|
|
|
@ -13,6 +13,17 @@
|
|||
#include "NimBLEAddress.h"
|
||||
#include "NimBLELog.h"
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
# include "host/ble_hs.h"
|
||||
# else
|
||||
# include "nimble/nimble/host/include/host/ble_hs.h"
|
||||
# endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
#undef max
|
||||
/**************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char* LOG_TAG = "NimBLEUtils";
|
||||
|
|
|
@ -12,28 +12,21 @@
|
|||
#include "nimconfig.h"
|
||||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
||||
#include "host/ble_gap.h"
|
||||
#else
|
||||
#include "nimble/nimble/host/include/host/ble_gap.h"
|
||||
#endif
|
||||
|
||||
/**** FIX COMPILATION ****/
|
||||
#undef min
|
||||
#undef max
|
||||
/**************************/
|
||||
# include <freertos/FreeRTOS.h>
|
||||
# include <freertos/task.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
class NimBLEAddress;
|
||||
|
||||
typedef struct {
|
||||
void *pATT;
|
||||
struct BleTaskData {
|
||||
void* pATT;
|
||||
TaskHandle_t task;
|
||||
int rc;
|
||||
void *buf;
|
||||
} ble_task_data_t;
|
||||
int rc;
|
||||
void* buf;
|
||||
};
|
||||
|
||||
struct ble_gap_event;
|
||||
|
||||
/**
|
||||
* @brief A BLE Utility class with methods for debugging and general purpose use.
|
||||
|
@ -48,6 +41,5 @@ public:
|
|||
static NimBLEAddress generateAddr(bool nrpa);
|
||||
};
|
||||
|
||||
|
||||
#endif // CONFIG_BT_ENABLED
|
||||
#endif // COMPONENTS_NIMBLEUTILS_H_
|
||||
|
|
Loading…
Reference in a new issue