updated printer

This commit is contained in:
Robin Müller 2020-05-15 18:47:46 +02:00
parent effac0e9b7
commit e92c324c7e
2 changed files with 32 additions and 5 deletions

View File

@ -1,13 +1,34 @@
#include <framework/globalfunctions/printer.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
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<int>(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<int>(data[i]);
if(i < size - 1){
sif::info << " , ";
}
}
}

View File

@ -4,9 +4,15 @@
#include <cstddef>
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_ */