fsfw/serviceinterface/ServiceInterfacePrinter.h

61 lines
1.7 KiB
C
Raw Permalink Normal View History

2021-01-14 20:00:48 +01:00
#ifndef FSFW_SERVICEINTERFACE_SERVICEINTERFACEPRINTER
#define FSFW_SERVICEINTERFACE_SERVICEINTERFACEPRINTER
2021-01-12 15:06:25 +01:00
#if FSFW_DISABLE_PRINTOUT == 0
#include <cstdio>
#endif
2021-01-03 01:02:07 +01:00
2021-01-14 19:32:18 +01:00
//! https://stackoverflow.com/questions/111928/is-there-a-printf-converter-to-print-in-binary-format
//! Can be used to print out binary numbers in human-readable format.
2021-06-04 14:39:21 +02:00
//! Example usage:
//! sif::printInfo("Status register: " BYTE_TO_BINARY_PATTERN "\n",BYTE_TO_BINARY(0x1f));
2021-01-14 19:32:18 +01:00
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"
#define BYTE_TO_BINARY(byte) \
(byte & 0x80 ? '1' : '0'), \
(byte & 0x40 ? '1' : '0'), \
(byte & 0x20 ? '1' : '0'), \
(byte & 0x10 ? '1' : '0'), \
(byte & 0x08 ? '1' : '0'), \
(byte & 0x04 ? '1' : '0'), \
(byte & 0x02 ? '1' : '0'), \
(byte & 0x01 ? '1' : '0')
2021-01-12 15:06:25 +01:00
namespace sif {
2021-01-03 01:02:07 +01:00
2021-01-12 15:06:25 +01:00
enum PrintLevel {
2021-01-03 01:02:07 +01:00
NONE = 0,
//! Strange error when using just ERROR..
2021-01-12 15:06:25 +01:00
ERROR_LEVEL = 1,
WARNING_LEVEL = 2,
INFO_LEVEL = 3,
DEBUG_LEVEL = 4
2021-01-03 01:02:07 +01:00
};
2021-01-12 15:06:25 +01:00
/**
* Set the print level. All print types with a smaller level will be printed
* as well. For example, set to PrintLevel::WARNING to only enable error
* and warning output.
* @param printLevel
*/
2021-01-03 01:02:07 +01:00
void setPrintLevel(PrintLevel printLevel);
PrintLevel getPrintLevel();
2021-01-12 15:06:25 +01:00
void setToAddCrAtEnd(bool addCrAtEnd_);
2021-01-03 01:47:01 +01:00
/**
* These functions can be used like the C stdio printf and forward the
* supplied formatted string arguments to a printf function.
* They prepend the string with a color (if enabled), a log preamble and
* a timestamp.
* @param fmt Formatted string
*/
2021-01-03 01:02:07 +01:00
void printInfo(const char *fmt, ...);
void printWarning(const char* fmt, ...);
void printDebug(const char* fmt, ...);
void printError(const char* fmt, ...);
}
2021-01-14 20:00:48 +01:00
#endif /* FSFW_SERVICEINTERFACE_SERVICEINTERFACEPRINTER */