printer fixes and improvements

This commit is contained in:
Robin Müller 2020-05-19 20:26:12 +02:00
parent 5482b71b3c
commit e2e6ec28c0
2 changed files with 10 additions and 8 deletions

View File

@ -1,8 +1,8 @@
#include <framework/globalfunctions/printer.h> #include <framework/globalfunctions/printer.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
void printer::print(uint8_t *data, size_t size, OutputType type, bool printInfo, void printer::print(const uint8_t *data, size_t size, OutputType type,
size_t maxCharPerLine) { bool printInfo, size_t maxCharPerLine) {
if(printInfo) { if(printInfo) {
sif::info << "Printing data with size " << size << ": "; sif::info << "Printing data with size " << size << ": ";
} }
@ -15,7 +15,8 @@ void printer::print(uint8_t *data, size_t size, OutputType type, bool printInfo,
} }
} }
void printer::printHex(uint8_t *data, size_t size, size_t maxCharPerLine) { void printer::printHex(const uint8_t *data, size_t size,
size_t maxCharPerLine) {
sif::info << std::hex; sif::info << std::hex;
for(size_t i = 0; i < size; i++) { for(size_t i = 0; i < size; i++) {
sif::info << "0x" << static_cast<int>(data[i]); sif::info << "0x" << static_cast<int>(data[i]);
@ -31,10 +32,11 @@ void printer::printHex(uint8_t *data, size_t size, size_t maxCharPerLine) {
sif::info << "]" << std::endl; sif::info << "]" << std::endl;
} }
void printer::printDec(uint8_t *data, size_t size, size_t maxCharPerLine) { void printer::printDec(const uint8_t *data, size_t size,
size_t maxCharPerLine) {
sif::info << std::dec; sif::info << std::dec;
for(size_t i = 0; i < size; i++) { for(size_t i = 0; i < size; i++) {
sif::info << "0x" << static_cast<int>(data[i]); sif::info << static_cast<int>(data[i]);
if(i < size - 1){ if(i < size - 1){
sif::info << " , "; sif::info << " , ";
if(i > 0 and i % maxCharPerLine == 0) { if(i > 0 and i % maxCharPerLine == 0) {

View File

@ -10,10 +10,10 @@ enum class OutputType {
HEX HEX
}; };
void print(uint8_t* data, size_t size, OutputType type = OutputType::HEX, void print(const uint8_t* data, size_t size, OutputType type = OutputType::HEX,
bool printInfo = true, size_t maxCharPerLine = 12); bool printInfo = true, size_t maxCharPerLine = 12);
void printHex(uint8_t* data, size_t size, size_t maxCharPerLine = 12); void printHex(const uint8_t* data, size_t size, size_t maxCharPerLine = 12);
void printDec(uint8_t* data, size_t size, size_t maxCharPerLine = 12); void printDec(const uint8_t* data, size_t size, size_t maxCharPerLine = 12);
} }
#endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */ #endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */