esp-nimble-cpp 2.3.3
Loading...
Searching...
No Matches
NimBLEUtils.h
1/*
2 * Copyright 2020-2025 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_UTILS_H_
19#define NIMBLE_CPP_UTILS_H_
20
21#include "syscfg/syscfg.h"
22#if CONFIG_BT_NIMBLE_ENABLED
23
24# ifndef MYNEWT_VAL_NIMBLE_CPP_DEBUG_ASSERT_ENABLED
25# if defined(CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED)
26# define MYNEWT_VAL_NIMBLE_CPP_DEBUG_ASSERT_ENABLED CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED
27# else
28# define MYNEWT_VAL_NIMBLE_CPP_DEBUG_ASSERT_ENABLED (0)
29# endif
30# endif
31
32#if MYNEWT_VAL(NIMBLE_CPP_DEBUG_ASSERT_ENABLED) && !defined NDEBUG
33void nimble_cpp_assert(const char *file, unsigned line) __attribute((weak, noreturn));
34# define NIMBLE_ATT_VAL_FILE (__builtin_strrchr(__FILE__, '/') ? \
35 __builtin_strrchr (__FILE__, '/') + 1 : __FILE__)
36# define NIMBLE_CPP_DEBUG_ASSERT(cond) \
37 if (!(cond)) { \
38 nimble_cpp_assert(NIMBLE_ATT_VAL_FILE, __LINE__); \
39 }
40#else
41# define NIMBLE_CPP_DEBUG_ASSERT(cond) (void(0))
42#endif
43
44# include <string>
45
46class NimBLEAddress;
47
54 NimBLETaskData(void* pInstance = nullptr, int flags = 0, void* buf = nullptr);
56 void* m_pInstance{nullptr};
57 mutable int m_flags{0};
58 void* m_pBuf{nullptr};
59
60 private:
61 mutable void* m_pHandle{nullptr}; // semaphore or task handle
62 friend class NimBLEUtils;
63};
64
69 public:
70 static const char* gapEventToString(uint8_t eventType);
71 static std::string dataToHexString(const uint8_t* source, uint8_t length);
72 static const char* advTypeToString(uint8_t advType);
73 static const char* returnCodeToString(int rc);
74 static NimBLEAddress generateAddr(bool nrpa);
75 static bool taskWait(const NimBLETaskData& taskData, uint32_t timeout);
76 static void taskRelease(const NimBLETaskData& taskData, int rc = 0);
77};
78
79#endif // CONFIG_BT_NIMBLE_ENABLED
80#endif // NIMBLE_CPP_UTILS_H_
A BLE device address.
Definition NimBLEAddress.h:42
A BLE Utility class with methods for debugging and general purpose use.
Definition NimBLEUtils.h:68
static std::string dataToHexString(const uint8_t *source, uint8_t length)
Create a hexadecimal string representation of the input data.
Definition NimBLEUtils.cpp:578
static bool taskWait(const NimBLETaskData &taskData, uint32_t timeout)
Blocks the calling task until released or timeout.
Definition NimBLEUtils.cpp:120
static NimBLEAddress generateAddr(bool nrpa)
Generate a random BLE address.
Definition NimBLEUtils.cpp:597
static const char * advTypeToString(uint8_t advType)
Convert the advertising type flag to a string.
Definition NimBLEUtils.cpp:458
static void taskRelease(const NimBLETaskData &taskData, int rc=0)
Release a task.
Definition NimBLEUtils.cpp:147
static const char * returnCodeToString(int rc)
Converts a return code from the NimBLE stack to a text string.
Definition NimBLEUtils.cpp:163
static const char * gapEventToString(uint8_t eventType)
Convert a GAP event type to a string representation.
Definition NimBLEUtils.cpp:485
A structure to hold data for a task that is waiting for a response.
Definition NimBLEUtils.h:53
~NimBLETaskData()
Destructor.
Definition NimBLEUtils.cpp:105