binary printer added

This commit is contained in:
Robin Müller 2020-05-19 23:07:28 +02:00
parent 9b53e2b64f
commit 338651af2f
2 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#include <framework/globalfunctions/printer.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <bitset>
void printer::print(const uint8_t *data, size_t size, OutputType type,
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) {
printer::printHex(data, size, maxCharPerLine);
}
else {
else if (type == OutputType::DEC) {
printer::printDec(data, size, maxCharPerLine);
}
else if(type == OutputType::BIN) {
printer::printBin(data, 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;
}
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 {
DEC,
HEX
HEX,
BIN
};
void print(const uint8_t* data, size_t size, OutputType type = OutputType::HEX,
bool printInfo = true, 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 printBin(const uint8_t* data, size_t size);
}
#endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */