From 95e654f232bcf526a418c184fdb80bf4d30383ec Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 11 Nov 2022 13:54:59 +0100 Subject: [PATCH] sys/fmt: add print_bytes_hex() --- sys/fmt/fmt.c | 9 +++++++++ sys/include/fmt.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/sys/fmt/fmt.c b/sys/fmt/fmt.c index 2c997c6c29..11eddf3cfa 100644 --- a/sys/fmt/fmt.c +++ b/sys/fmt/fmt.c @@ -550,6 +550,15 @@ void print_byte_hex(uint8_t byte) print(buf, sizeof(buf)); } +void print_bytes_hex(const void *bytes, size_t num) +{ + const uint8_t *b = bytes; + + while (num--) { + print_byte_hex(*b++); + } +} + void print_u32_hex(uint32_t val) { char buf[8]; diff --git a/sys/include/fmt.h b/sys/include/fmt.h index c3a7b1cace..45d340fed7 100644 --- a/sys/include/fmt.h +++ b/sys/include/fmt.h @@ -450,6 +450,14 @@ void print_s32_dec(int32_t val); */ void print_byte_hex(uint8_t byte); +/** + * @brief Print bytes as hex to stdout + * + * @param[in] bytes Byte array to print + * @param[in] n Number of bytes to print + */ +void print_bytes_hex(const void *bytes, size_t n); + /** * @brief Print uint32 value as hex to stdout *