Skip to content

Commit 1088ad8

Browse files
thekurtovich2zero
authored andcommitted
NimBLEAddress::toString allow formatting to be configured
1 parent 0b543d9 commit 1088ad8

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ config NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT
157157
while scanning as text messages in the debug log.
158158
This will use approximately 250 bytes of flash memory.
159159

160+
config NIMBLE_CPP_ADDR_FMT_INCLUDE_DELIMITER
161+
bool "Show colon characters when printing address."
162+
default "y"
163+
help
164+
Enabling this option will format MAC addresses with
165+
colon characters included when printing.
166+
167+
config NIMBLE_CPP_ADDR_FMT_UPPERCASE
168+
bool "Use uppercase letters when printing address."
169+
default "n"
170+
help
171+
Enabling this option will format MAC addresses in
172+
uppercase letters when printing.
173+
160174
config NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
161175
bool "Enable timestamps to be stored with attribute values."
162176
default "n"

src/NimBLEAddress.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323

2424
# include <algorithm>
2525

26+
# ifdef CONFIG_NIMBLE_CPP_ADDR_FMT_INCLUDE_DELIMITER
27+
# define NIMBLE_CPP_ADDR_DELIMITER ":"
28+
# else
29+
# define NIMBLE_CPP_ADDR_DELIMITER ""
30+
# endif
31+
32+
# ifdef CONFIG_NIMBLE_CPP_ADDR_FMT_UPPERCASE
33+
# define NIMBLE_CPP_ADDR_FMT "%02X%s%02X%s%02X%s%02X%s%02X%s%02X"
34+
# else
35+
# define NIMBLE_CPP_ADDR_FMT "%02x%s%02x%s%02x%s%02x%s%02x%s%02x"
36+
# endif
37+
2638
static const char* LOG_TAG = "NimBLEAddress";
2739

2840
/*************************************************
@@ -211,12 +223,12 @@ NimBLEAddress::operator std::string() const {
211223
char buffer[18];
212224
snprintf(buffer,
213225
sizeof(buffer),
214-
"%02x:%02x:%02x:%02x:%02x:%02x",
215-
this->val[5],
216-
this->val[4],
217-
this->val[3],
218-
this->val[2],
219-
this->val[1],
226+
NIMBLE_CPP_ADDR_FMT,
227+
this->val[5], NIMBLE_CPP_ADDR_DELIMITER,
228+
this->val[4], NIMBLE_CPP_ADDR_DELIMITER,
229+
this->val[3], NIMBLE_CPP_ADDR_DELIMITER,
230+
this->val[2], NIMBLE_CPP_ADDR_DELIMITER,
231+
this->val[1], NIMBLE_CPP_ADDR_DELIMITER,
220232
this->val[0]);
221233
return std::string{buffer};
222234
} // operator std::string

0 commit comments

Comments
 (0)