|
25 | 25 | #endif |
26 | 26 |
|
27 | 27 | #include "NimBLEAddress.h" |
| 28 | +#include <cstdio> |
28 | 29 |
|
29 | 30 | /** |
30 | 31 | * @brief Connection information. |
@@ -70,6 +71,41 @@ class NimBLEConnInfo { |
70 | 71 | /** @brief Gets the key size used to encrypt the connection */ |
71 | 72 | uint8_t getSecKeySize() const { return m_desc.sec_state.key_size; } |
72 | 73 |
|
| 74 | + /** @brief Get a string representation of the connection info, useful for debugging */ |
| 75 | + std::string toString() const { |
| 76 | + std::string str; |
| 77 | + // 294 chars max expected from all labels + worst-case values, round up to 300. |
| 78 | + str.resize(300); |
| 79 | + |
| 80 | + snprintf(&str[0], |
| 81 | + str.size(), |
| 82 | + " Address: %s\n" |
| 83 | + " ID Address: %s\n" |
| 84 | + " Connection Handle: %u\n" |
| 85 | + " Connection Interval: %.1f ms\n" |
| 86 | + " Connection Timeout: %u ms\n" |
| 87 | + " Connection Latency: %u\n" |
| 88 | + " MTU: %u bytes\n" |
| 89 | + " Role: %s\n" |
| 90 | + " Bonded: %s\n" |
| 91 | + " Encrypted: %s\n" |
| 92 | + " Authenticated: %s\n" |
| 93 | + " Security Key Size: %u\n", |
| 94 | + getAddress().toString().c_str(), |
| 95 | + getIdAddress().toString().c_str(), |
| 96 | + getConnHandle(), |
| 97 | + getConnInterval() * 1.25f, |
| 98 | + getConnTimeout() * 10, |
| 99 | + getConnLatency(), |
| 100 | + getMTU(), |
| 101 | + isMaster() ? "Master" : "Slave", |
| 102 | + isBonded() ? "Yes" : "No", |
| 103 | + isEncrypted() ? "Yes" : "No", |
| 104 | + isAuthenticated() ? "Yes" : "No", |
| 105 | + getSecKeySize()); |
| 106 | + return str; |
| 107 | + } |
| 108 | + |
73 | 109 | private: |
74 | 110 | friend class NimBLEServer; |
75 | 111 | friend class NimBLEClient; |
|
0 commit comments