2020-03-30 01:44:20 +02:00
|
|
|
/*
|
|
|
|
* NimBLEUtils.h
|
|
|
|
*
|
|
|
|
* Created: on Jan 25 2020
|
|
|
|
* Author H2zero
|
2020-05-14 06:03:56 +02:00
|
|
|
*
|
2020-03-30 01:44:20 +02:00
|
|
|
*/
|
|
|
|
|
2024-11-10 21:31:37 +01:00
|
|
|
#ifndef NIMBLE_CPP_UTILS_H_
|
|
|
|
#define NIMBLE_CPP_UTILS_H_
|
2021-09-07 05:14:43 +02:00
|
|
|
|
|
|
|
#include "nimconfig.h"
|
2020-03-30 01:44:20 +02:00
|
|
|
#if defined(CONFIG_BT_ENABLED)
|
2024-11-10 21:31:37 +01:00
|
|
|
# include <string>
|
2020-06-11 16:06:16 +02:00
|
|
|
|
2024-11-03 00:56:23 +01:00
|
|
|
class NimBLEAddress;
|
|
|
|
|
2024-11-10 21:31:37 +01:00
|
|
|
/**
|
|
|
|
* @brief A structure to hold data for a task that is waiting for a response.
|
|
|
|
* @details This structure is used in conjunction with NimBLEUtils::taskWait() and NimBLEUtils::taskRelease().
|
|
|
|
* All items are optional, the m_pHandle will be set in taskWait().
|
|
|
|
*/
|
|
|
|
struct NimBLETaskData {
|
2024-11-14 02:09:38 +01:00
|
|
|
NimBLETaskData(void* pInstance = nullptr, int flags = 0, void* buf = nullptr);
|
|
|
|
~NimBLETaskData();
|
2024-11-10 21:31:37 +01:00
|
|
|
void* m_pInstance{nullptr};
|
|
|
|
mutable int m_flags{0};
|
|
|
|
void* m_pBuf{nullptr};
|
|
|
|
|
|
|
|
private:
|
|
|
|
mutable void* m_pHandle{nullptr}; // semaphore or task handle
|
|
|
|
friend class NimBLEUtils;
|
2024-11-03 02:00:07 +01:00
|
|
|
};
|
2020-06-11 16:06:16 +02:00
|
|
|
|
2020-07-09 03:27:26 +02:00
|
|
|
/**
|
|
|
|
* @brief A BLE Utility class with methods for debugging and general purpose use.
|
|
|
|
*/
|
2020-03-30 01:44:20 +02:00
|
|
|
class NimBLEUtils {
|
2024-11-10 21:31:37 +01:00
|
|
|
public:
|
|
|
|
static const char* gapEventToString(uint8_t eventType);
|
|
|
|
static std::string dataToHexString(const uint8_t* source, uint8_t length);
|
|
|
|
static const char* advTypeToString(uint8_t advType);
|
|
|
|
static const char* returnCodeToString(int rc);
|
|
|
|
static NimBLEAddress generateAddr(bool nrpa);
|
|
|
|
static bool taskWait(const NimBLETaskData& taskData, uint32_t timeout);
|
|
|
|
static void taskRelease(const NimBLETaskData& taskData, int rc = 0);
|
2020-03-30 01:44:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CONFIG_BT_ENABLED
|
2024-11-10 21:31:37 +01:00
|
|
|
#endif // NIMBLE_CPP_UTILS_H_
|