Skip to content

Commit c13e590

Browse files
pan-paul-szczepanek-arm
authored andcommitted
BLE: Refactor UUID string helper to match mbed-os coding style.
1 parent e001098 commit c13e590

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

connectivity/FEATURE_BLE/source/common/ble_trace_helpers.h

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,39 @@ static inline const char* tr_as_array(T item)
4747

4848
static inline char* to_string(const UUID& uuid)
4949
{
50-
const uint8_t* Buffer = uuid.getBaseUUID();
51-
const uint8_t Length = uuid.getLen();
52-
const size_t Row_Count = 4;
50+
static constexpr const size_t ROW_COUNT = 4;
51+
static constexpr const char *HEX = "0123456789ABCDEF";
52+
static constexpr const size_t HYPHENS_DELIMITER_COUNT = 4;
5353

54-
const char *Hex = "0123456789ABCDEF";
55-
56-
static char string_buffer[Row_Count][UUID::LENGTH_OF_LONG_UUID + /* Number of hyphen delimiters =*/ 4];
54+
static char string_buffer[ROW_COUNT][UUID::LENGTH_OF_LONG_UUID + HYPHENS_DELIMITER_COUNT];
5755
static uint8_t idx = 0;
5856

5957
++idx;
6058

61-
if (idx == Row_Count) {
59+
if (idx == ROW_COUNT) {
6260
idx= 0;
6361
}
6462

65-
char* p1 = (char *)Buffer + Length - 1;
66-
char* p2 = string_buffer[idx];
63+
const uint8_t length = uuid.getLen();
64+
const char* reader = (const char *) uuid.getBaseUUID() + length - 1;
65+
char* writer = string_buffer[idx];
6766

68-
if (Length == UUID::LENGTH_OF_LONG_UUID) {
69-
const uint8_t format[] = {4, 2, 2, 2, 6};
70-
for ( uint8_t i: format) {
71-
size_t j = 0;
72-
for (; j < i; ++j) {
73-
*p2++ = Hex[(*p1 >> 4) & 0xF];
74-
*p2++ = Hex[(*p1--) & 0xF];
67+
if (length == UUID::LENGTH_OF_LONG_UUID) {
68+
constexpr uint8_t format[] = {4, 2, 2, 2, 6};
69+
for ( uint8_t char_count: format) {
70+
for (size_t i = 0; i < char_count; ++i) {
71+
*writer++ = HEX[(*reader >> 4) & 0xF];
72+
*writer++ = HEX[(*reader--) & 0xF];
7573
}
76-
*p2++ = '-';
74+
*writer++ = '-';
7775
}
78-
*--p2 = 0;
76+
*--writer = 0;
7977
} else {
80-
size_t i = 0;
81-
for (; i < Length; ++i) {
82-
*p2++ = Hex[(*p1 >> 4) & 0xF];
83-
*p2++ = Hex[(*p1--) & 0xF];
78+
for (size_t i = 0; i < length; ++i) {
79+
*writer++ = HEX[(*reader >> 4) & 0xF];
80+
*writer++ = HEX[(*reader--) & 0xF];
8481
}
85-
*p2 = 0;
82+
*writer = 0;
8683
}
8784

8885
return string_buffer[idx];

0 commit comments

Comments
 (0)