From e92c324c7ef26eef4877041df94fa2d8fa16f8db Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 15 May 2020 18:47:46 +0200 Subject: [PATCH] updated printer --- globalfunctions/printer.cpp | 25 +++++++++++++++++++++++-- globalfunctions/printer.h | 12 +++++++++--- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/globalfunctions/printer.cpp b/globalfunctions/printer.cpp index d6ede0a5..d7af30a5 100644 --- a/globalfunctions/printer.cpp +++ b/globalfunctions/printer.cpp @@ -1,13 +1,34 @@ #include #include -void printer::print(uint8_t *data, size_t size) { +void printer::print(uint8_t *data, size_t size, OutputType type) { sif::info << "StorageAccessor: Printing data: ["; + if(type == OutputType::HEX) { + printer::printHex(data, size); + } + else { + printer::printDec(data, size); + } +} + +void printer::printHex(uint8_t *data, size_t size) { + sif::info << std::hex; for(size_t i = 0; i < size; i++) { - sif::info << std::hex << (int)data[i]; + sif::info << "0x" << static_cast(data[i]); if(i < size - 1){ sif::info << " , "; } } + sif::info << std::dec; sif::info << " ] " << std::endl; } + +void printer::printDec(uint8_t *data, size_t size) { + for(size_t i = 0; i < size; i++) { + sif::info << "0x" << static_cast(data[i]); + if(i < size - 1){ + sif::info << " , "; + } + } +} + diff --git a/globalfunctions/printer.h b/globalfunctions/printer.h index d4a573e9..3c9d6aa0 100644 --- a/globalfunctions/printer.h +++ b/globalfunctions/printer.h @@ -4,9 +4,15 @@ #include namespace printer { -void print(uint8_t *data, size_t size); + +enum class OutputType { + DEC, + HEX +}; + +void print(uint8_t* data, size_t size, OutputType type = OutputType::HEX); +void printHex(uint8_t* data, size_t size); +void printDec(uint8_t* data, size_t size); } - - #endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */