service interface update
This commit is contained in:
parent
295852a45c
commit
165710b43c
@ -2,6 +2,7 @@
|
||||
#define FSFW_SERVICEINTERFACE_SERVICEINTERFACE_H_
|
||||
|
||||
#include <FSFWConfig.h>
|
||||
#include "serviceInterfaceDefintions.h"
|
||||
|
||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
@ -29,19 +29,19 @@ ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string setMessage,
|
||||
|
||||
#if FSFW_COLORED_OUTPUT == 1
|
||||
if(setMessage.find("DEBUG") != std::string::npos) {
|
||||
colorPrefix = fsfw::ANSI_COLOR_MAGENTA;
|
||||
colorPrefix = sif::ANSI_COLOR_MAGENTA;
|
||||
}
|
||||
else if(setMessage.find("INFO") != std::string::npos) {
|
||||
colorPrefix = fsfw::ANSI_COLOR_GREEN;
|
||||
colorPrefix = sif::ANSI_COLOR_GREEN;
|
||||
}
|
||||
else if(setMessage.find("WARNING") != std::string::npos) {
|
||||
colorPrefix = fsfw::ANSI_COLOR_YELLOW;
|
||||
colorPrefix = sif::ANSI_COLOR_YELLOW;
|
||||
}
|
||||
else if(setMessage.find("ERROR") != std::string::npos) {
|
||||
colorPrefix = fsfw::ANSI_COLOR_RED;
|
||||
colorPrefix = sif::ANSI_COLOR_RED;
|
||||
}
|
||||
else {
|
||||
colorPrefix = fsfw::ANSI_COLOR_RESET;
|
||||
colorPrefix = sif::ANSI_COLOR_RESET;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -6,14 +6,18 @@
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
fsfw::PrintLevel printLevel = fsfw::PrintLevel::DEBUG;
|
||||
uint8_t printBuffer[fsfwconfig::FSFW_PRINT_BUFFER_SIZE];
|
||||
static sif::PrintLevel printLevel = sif::PrintLevel::DEBUG_LEVEL;
|
||||
#if defined(WIN32) && FSFW_COLORED_OUTPUT == 1
|
||||
bool consoleInitialized = false;
|
||||
#endif
|
||||
static bool consoleInitialized = false;
|
||||
#endif /* defined(WIN32) && FSFW_COLORED_OUTPUT == 1 */
|
||||
|
||||
void fsfwPrint(fsfw::PrintLevel printType, const char* fmt, va_list arg) {
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
|
||||
static bool addCrAtEnd = false;
|
||||
|
||||
uint8_t printBuffer[fsfwconfig::FSFW_PRINT_BUFFER_SIZE];
|
||||
|
||||
void fsfwPrint(sif::PrintLevel printType, const char* fmt, va_list arg) {
|
||||
|
||||
#if defined(WIN32) && FSFW_COLORED_OUTPUT == 1
|
||||
if(not consoleInitialized) {
|
||||
@ -30,38 +34,38 @@ void fsfwPrint(fsfw::PrintLevel printType, const char* fmt, va_list arg) {
|
||||
char* bufferPosition = reinterpret_cast<char*>(printBuffer);
|
||||
|
||||
/* Check logger level */
|
||||
if(printType == fsfw::PrintLevel::NONE or printType > printLevel) {
|
||||
if(printType == sif::PrintLevel::NONE or printType > printLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Log message to terminal */
|
||||
|
||||
#if FSFW_COLORED_OUTPUT == 1
|
||||
if(printType == fsfw::PrintLevel::INFO) {
|
||||
len += sprintf(bufferPosition, fsfw::ANSI_COLOR_GREEN);
|
||||
if(printType == sif::PrintLevel::INFO_LEVEL) {
|
||||
len += sprintf(bufferPosition, sif::ANSI_COLOR_GREEN);
|
||||
}
|
||||
else if(printType == fsfw::PrintLevel::DEBUG) {
|
||||
len += sprintf(bufferPosition, fsfw::ANSI_COLOR_MAGENTA);
|
||||
else if(printType == sif::PrintLevel::DEBUG_LEVEL) {
|
||||
len += sprintf(bufferPosition, sif::ANSI_COLOR_MAGENTA);
|
||||
}
|
||||
else if(printType == fsfw::PrintLevel::WARNING) {
|
||||
len += sprintf(bufferPosition, fsfw::ANSI_COLOR_YELLOW);
|
||||
else if(printType == sif::PrintLevel::WARNING_LEVEL) {
|
||||
len += sprintf(bufferPosition, sif::ANSI_COLOR_YELLOW);
|
||||
}
|
||||
else if(printType == fsfw::PrintLevel::ERROR_TYPE) {
|
||||
len += sprintf(bufferPosition, fsfw::ANSI_COLOR_RED);
|
||||
else if(printType == sif::PrintLevel::ERROR_LEVEL) {
|
||||
len += sprintf(bufferPosition, sif::ANSI_COLOR_RED);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (printType == fsfw::PrintLevel::INFO) {
|
||||
if (printType == sif::PrintLevel::INFO_LEVEL) {
|
||||
len += sprintf(bufferPosition + len, "INFO: ");
|
||||
}
|
||||
if(printType == fsfw::PrintLevel::DEBUG) {
|
||||
if(printType == sif::PrintLevel::DEBUG_LEVEL) {
|
||||
len += sprintf(bufferPosition + len, "DEBUG: ");
|
||||
}
|
||||
if(printType == fsfw::PrintLevel::WARNING) {
|
||||
if(printType == sif::PrintLevel::WARNING_LEVEL) {
|
||||
len += sprintf(bufferPosition + len, "WARNING: ");
|
||||
}
|
||||
|
||||
if(printType == fsfw::PrintLevel::ERROR_TYPE) {
|
||||
if(printType == sif::PrintLevel::ERROR_LEVEL) {
|
||||
len += sprintf(bufferPosition + len, "ERROR: ");
|
||||
}
|
||||
|
||||
@ -78,41 +82,59 @@ void fsfwPrint(fsfw::PrintLevel printType, const char* fmt, va_list arg) {
|
||||
|
||||
len += vsnprintf(bufferPosition + len, sizeof(printBuffer) - len, fmt, arg);
|
||||
|
||||
if(addCrAtEnd) {
|
||||
len += sprintf(bufferPosition + len, "\r");
|
||||
}
|
||||
|
||||
printf("%s", printBuffer);
|
||||
}
|
||||
|
||||
void fsfw::setPrintLevel(PrintLevel printLevel_) {
|
||||
|
||||
void sif::printInfo(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(sif::PrintLevel::INFO_LEVEL, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void sif::printWarning(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(sif::PrintLevel::WARNING_LEVEL, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void sif::printDebug(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(sif::PrintLevel::DEBUG_LEVEL, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void sif::setToAddCrAtEnd(bool addCrAtEnd_) {
|
||||
addCrAtEnd = addCrAtEnd_;
|
||||
}
|
||||
|
||||
void sif::printError(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(sif::PrintLevel::ERROR_LEVEL, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void sif::printInfo(const char *fmt, ...) {}
|
||||
void sif::printWarning(const char *fmt, ...) {}
|
||||
void sif::printDebug(const char *fmt, ...) {}
|
||||
void sif::printError(const char *fmt, ...) {}
|
||||
|
||||
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
||||
|
||||
void sif::setPrintLevel(PrintLevel printLevel_) {
|
||||
printLevel = printLevel_;
|
||||
}
|
||||
|
||||
fsfw::PrintLevel fsfw::getPrintLevel() {
|
||||
sif::PrintLevel sif::getPrintLevel() {
|
||||
return printLevel;
|
||||
}
|
||||
|
||||
void fsfw::printInfo(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(fsfw::PrintLevel::INFO, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void fsfw::printWarning(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(fsfw::PrintLevel::WARNING, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void fsfw::printDebug(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(fsfw::PrintLevel::DEBUG, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void fsfw::printError(const char *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
fsfwPrint(fsfw::PrintLevel::ERROR_TYPE, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
@ -1,19 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#if FSFW_DISABLE_PRINTOUT == 0
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
||||
namespace fsfw {
|
||||
namespace sif {
|
||||
|
||||
enum class PrintLevel {
|
||||
enum PrintLevel {
|
||||
NONE = 0,
|
||||
//! Strange error when using just ERROR..
|
||||
ERROR_TYPE = 1,
|
||||
WARNING = 2,
|
||||
INFO = 3,
|
||||
DEBUG = 4
|
||||
ERROR_LEVEL = 1,
|
||||
WARNING_LEVEL = 2,
|
||||
INFO_LEVEL = 3,
|
||||
DEBUG_LEVEL = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
void setPrintLevel(PrintLevel printLevel);
|
||||
PrintLevel getPrintLevel();
|
||||
|
||||
void setToAddCrAtEnd(bool addCrAtEnd_);
|
||||
|
||||
/**
|
||||
* These functions can be used like the C stdio printf and forward the
|
||||
* supplied formatted string arguments to a printf function.
|
||||
|
@ -1,7 +1,14 @@
|
||||
#ifndef FSFW_SERVICEINTERFACE_SERVICEINTERFACEDEFINTIONS_H_
|
||||
#define FSFW_SERVICEINTERFACE_SERVICEINTERFACEDEFINTIONS_H_
|
||||
|
||||
namespace fsfw {
|
||||
namespace sif {
|
||||
|
||||
enum class OutputTypes {
|
||||
OUT_INFO,
|
||||
OUT_DEBUG,
|
||||
OUT_WARNING,
|
||||
OUT_ERROR
|
||||
};
|
||||
|
||||
static const char* const ANSI_COLOR_RED = "\x1b[31m";
|
||||
static const char* const ANSI_COLOR_GREEN = "\x1b[32m";
|
||||
|
Loading…
Reference in New Issue
Block a user