bin printer added

This commit is contained in:
Robin Müller 2020-05-19 23:08:17 +02:00
parent e2e6ec28c0
commit 6961b5e866
2 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#include <framework/globalfunctions/printer.h> #include <framework/globalfunctions/printer.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h> #include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <bitset>
void printer::print(const uint8_t *data, size_t size, OutputType type, void printer::print(const uint8_t *data, size_t size, OutputType type,
bool printInfo, size_t maxCharPerLine) { bool printInfo, size_t maxCharPerLine) {
@ -10,9 +11,12 @@ void printer::print(const uint8_t *data, size_t size, OutputType type,
if(type == OutputType::HEX) { if(type == OutputType::HEX) {
printer::printHex(data, size, maxCharPerLine); printer::printHex(data, size, maxCharPerLine);
} }
else { else if (type == OutputType::DEC) {
printer::printDec(data, size, maxCharPerLine); printer::printDec(data, size, maxCharPerLine);
} }
else if(type == OutputType::BIN) {
printer::printBin(data, size);
}
} }
void printer::printHex(const uint8_t *data, size_t size, void printer::printHex(const uint8_t *data, size_t size,
@ -46,3 +50,12 @@ void printer::printDec(const uint8_t *data, size_t size,
} }
sif::info << "]" << std::endl; sif::info << "]" << std::endl;
} }
void printer::printBin(const uint8_t *data, size_t size) {
sif::info << "\n" << std::flush;
for(size_t i = 0; i < size; i++) {
sif::info << "Byte " << i + 1 << ": 0b"<<
std::bitset<8>(data[i]) << ",\n" << std::flush;
}
sif::info << "]" << std::endl;
}

View File

@ -7,13 +7,15 @@ namespace printer {
enum class OutputType { enum class OutputType {
DEC, DEC,
HEX HEX,
BIN
}; };
void print(const 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(const 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(const uint8_t* data, size_t size, size_t maxCharPerLine = 12); void printDec(const uint8_t* data, size_t size, size_t maxCharPerLine = 12);
void printBin(const uint8_t* data, size_t size);
} }
#endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */ #endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */