fsfw/globalfunctions/printer.cpp

37 lines
871 B
C++
Raw Normal View History

2020-05-11 12:22:06 +02:00
#include <framework/globalfunctions/printer.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
2020-05-15 18:47:46 +02:00
void printer::print(uint8_t *data, size_t size, OutputType type) {
sif::info << "Printing data with size " << size << ": [";
2020-05-15 18:47:46 +02:00
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;
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-15 18:47:46 +02:00
sif::info << std::dec;
2020-05-15 18:54:14 +02:00
sif::info << "]" << std::endl;
2020-05-11 12:22:06 +02:00
}
2020-05-15 18:47:46 +02:00
void printer::printDec(uint8_t *data, size_t size) {
2020-05-15 18:54:14 +02:00
sif::info << std::dec;
2020-05-15 18:47:46 +02:00
for(size_t i = 0; i < size; i++) {
sif::info << "0x" << static_cast<int>(data[i]);
if(i < size - 1){
sif::info << " , ";
}
}
2020-05-15 18:54:14 +02:00
sif::info << "]" << std::endl;
2020-05-15 18:47:46 +02:00
}