improved printer
This commit is contained in:
parent
f612b095c1
commit
e2418d61a6
@ -1,36 +1,46 @@
|
|||||||
#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) {
|
void printer::print(uint8_t *data, size_t size, OutputType type, bool printInfo,
|
||||||
sif::info << "Printing data with size " << size << ": [";
|
size_t maxCharPerLine) {
|
||||||
|
if(printInfo) {
|
||||||
|
sif::info << "Printing data with size " << size << ": ";
|
||||||
|
}
|
||||||
|
sif::info << "[";
|
||||||
if(type == OutputType::HEX) {
|
if(type == OutputType::HEX) {
|
||||||
printer::printHex(data, size);
|
printer::printHex(data, size, maxCharPerLine);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printer::printDec(data, size);
|
printer::printDec(data, size, maxCharPerLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printer::printHex(uint8_t *data, size_t size) {
|
void printer::printHex(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]);
|
||||||
if(i < size - 1){
|
if(i < size - 1){
|
||||||
sif::info << " , ";
|
sif::info << " , ";
|
||||||
|
if(i > 0 and i % maxCharPerLine == 0) {
|
||||||
|
sif::info << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
sif::info << std::dec;
|
sif::info << std::dec;
|
||||||
sif::info << "]" << std::endl;
|
sif::info << "]" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printer::printDec(uint8_t *data, size_t size) {
|
void printer::printDec(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 << "0x" << static_cast<int>(data[i]);
|
||||||
if(i < size - 1){
|
if(i < size - 1){
|
||||||
sif::info << " , ";
|
sif::info << " , ";
|
||||||
|
if(i > 0 and i % maxCharPerLine == 0) {
|
||||||
|
sif::info << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sif::info << "]" << std::endl;
|
sif::info << "]" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,9 +10,10 @@ enum class OutputType {
|
|||||||
HEX
|
HEX
|
||||||
};
|
};
|
||||||
|
|
||||||
void print(uint8_t* data, size_t size, OutputType type = OutputType::HEX);
|
void print(uint8_t* data, size_t size, OutputType type = OutputType::HEX,
|
||||||
void printHex(uint8_t* data, size_t size);
|
bool printInfo = true, size_t maxCharPerLine = 12);
|
||||||
void printDec(uint8_t* data, size_t size);
|
void printHex(uint8_t* data, size_t size, size_t maxCharPerLine = 12);
|
||||||
|
void printDec(uint8_t* data, size_t size, size_t maxCharPerLine = 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */
|
#endif /* FRAMEWORK_GLOBALFUNCTIONS_PRINTER_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user