mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-25 09:02:30 +00:00
btstack_util: manually convert to hex in printf_hexdump
This commit is contained in:
parent
b8d0d01487
commit
c1c586473a
@ -160,11 +160,14 @@ uint32_t btstack_max(uint32_t a, uint32_t b){
|
|||||||
return a > b ? a : b;
|
return a > b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char * char_to_nibble = "0123456789ABCDEF";
|
||||||
|
|
||||||
char char_for_nibble(int nibble){
|
char char_for_nibble(int nibble){
|
||||||
if (nibble < 10) return (char)('0' + nibble);
|
if (nibble < 16){
|
||||||
nibble -= 10;
|
return char_to_nibble[nibble];
|
||||||
if (nibble < 6) return (char)('A' + nibble);
|
} else {
|
||||||
return '?';
|
return '?';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char char_for_high_nibble(int value){
|
static inline char char_for_high_nibble(int value){
|
||||||
@ -175,6 +178,7 @@ static inline char char_for_low_nibble(int value){
|
|||||||
return char_for_nibble(value & 0x0f);
|
return char_for_nibble(value & 0x0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int nibble_for_char(char c){
|
int nibble_for_char(char c){
|
||||||
if (c >= '0' && c <= '9') return c - '0';
|
if (c >= '0' && c <= '9') return c - '0';
|
||||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||||
@ -183,10 +187,15 @@ int nibble_for_char(char c){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printf_hexdump(const void *data, int size){
|
void printf_hexdump(const void *data, int size){
|
||||||
if (size <= 0) return;
|
char buffer[4];
|
||||||
int i;
|
buffer[2] = ' ';
|
||||||
for (i=0; i<size;i++){
|
buffer[3] = 0;
|
||||||
printf("%02X ", ((uint8_t *)data)[i]);
|
while (size > 0){
|
||||||
|
uint8_t byte = *((uint8_t *)data++);
|
||||||
|
buffer[0] = char_for_high_nibble(byte);
|
||||||
|
buffer[1] = char_for_low_nibble(byte);
|
||||||
|
printf("%s", buffer);
|
||||||
|
size--;
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user