2020-05-11 12:22:06 +02:00
|
|
|
#include <framework/globalfunctions/printer.h>
|
|
|
|
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
|
|
|
|
2020-05-19 20:24:58 +02:00
|
|
|
void printer::print(const uint8_t *data, size_t size, OutputType type,
|
|
|
|
bool printInfo, size_t maxCharPerLine) {
|
2020-05-19 19:53:10 +02:00
|
|
|
if(printInfo) {
|
|
|
|
sif::info << "Printing data with size " << size << ": ";
|
|
|
|
}
|
|
|
|
sif::info << "[";
|
2020-05-15 18:47:46 +02:00
|
|
|
if(type == OutputType::HEX) {
|
2020-05-19 19:53:10 +02:00
|
|
|
printer::printHex(data, size, maxCharPerLine);
|
2020-05-15 18:47:46 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-05-19 19:53:10 +02:00
|
|
|
printer::printDec(data, size, maxCharPerLine);
|
2020-05-15 18:47:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 20:25:54 +02:00
|
|
|
void printer::printHex(const uint8_t *data, size_t size,
|
|
|
|
size_t maxCharPerLine) {
|
2020-05-15 18:47:46 +02:00
|
|
|
sif::info << std::hex;
|
2020-05-11 12:22:06 +02:00
|
|
|
for(size_t i = 0; i < size; i++) {
|
2020-05-15 18:47:46 +02:00
|
|
|
sif::info << "0x" << static_cast<int>(data[i]);
|
2020-05-11 12:22:06 +02:00
|
|
|
if(i < size - 1){
|
|
|
|
sif::info << " , ";
|
2020-05-19 19:53:10 +02:00
|
|
|
if(i > 0 and i % maxCharPerLine == 0) {
|
|
|
|
sif::info << std::endl;
|
|
|
|
}
|
2020-05-11 12:22:06 +02:00
|
|
|
}
|
2020-05-19 19:53:10 +02:00
|
|
|
|
2020-05-11 12:22:06 +02:00
|
|
|
}
|
2020-05-15 18:47:46 +02:00
|
|
|
sif::info << std::dec;
|
2020-05-15 18:53:54 +02:00
|
|
|
sif::info << "]" << std::endl;
|
2020-05-11 12:22:06 +02:00
|
|
|
}
|
2020-05-15 18:47:46 +02:00
|
|
|
|
2020-05-19 20:25:54 +02:00
|
|
|
void printer::printDec(const uint8_t *data, size_t size,
|
|
|
|
size_t maxCharPerLine) {
|
2020-05-15 18:53:54 +02:00
|
|
|
sif::info << std::dec;
|
2020-05-15 18:47:46 +02:00
|
|
|
for(size_t i = 0; i < size; i++) {
|
2020-05-19 20:24:58 +02:00
|
|
|
sif::info << static_cast<int>(data[i]);
|
2020-05-15 18:47:46 +02:00
|
|
|
if(i < size - 1){
|
|
|
|
sif::info << " , ";
|
2020-05-19 19:53:10 +02:00
|
|
|
if(i > 0 and i % maxCharPerLine == 0) {
|
|
|
|
sif::info << std::endl;
|
|
|
|
}
|
2020-05-15 18:47:46 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-15 18:53:54 +02:00
|
|
|
sif::info << "]" << std::endl;
|
2020-05-15 18:47:46 +02:00
|
|
|
}
|