added stdio pinters

This commit is contained in:
Robin Müller 2021-01-03 01:02:07 +01:00
parent 7759b19961
commit b30405fee7
4 changed files with 149 additions and 3 deletions

View File

@ -4,14 +4,20 @@
#include <cstddef>
#include <cstdint>
//! Used to determine whether C++ ostreams are used
//! Those can lead to code bloat.
//! Used to determine whether C++ ostreams are used which can increase
//! the binary size significantly. If this is disabled,
//! the C stdio functions can be used alternatively
#define FSFW_CPP_OSTREAM_ENABLED 1
//! Reduced printout to further decrease code size
//! Be careful, this also turns off most diagnostic prinouts!
#define FSFW_ENHANCED_PRINTOUT 0
//! Can be used to completely disable printouts, even the C stdio ones.
#if FSFW_CPP_OSTREAM_ENABLED == 1
#define FSFW_DISABLE_PRINTOUT 0
#endif
//! Can be used to enable additional debugging printouts for developing the FSFW
#define FSFW_PRINT_VERBOSITY_LEVEL 0
@ -20,6 +26,8 @@
//! and translateEvents (and their compiled source files)
#define FSFW_OBJ_EVENT_TRANSLATION 0
#define FSFW_COLORED_OUTPUT 1
#if FSFW_OBJ_EVENT_TRANSLATION == 1
//! Specify whether info events are printed too.
#define FSFW_DEBUG_INFO 1
@ -50,6 +58,8 @@ static constexpr size_t FSFW_EVENTMGMR_RANGEMATCHERS = 120;
//! simulataneously. This will increase the required RAM for
//! each CSB service !
static constexpr uint8_t FSFW_CSB_FIFO_DEPTH = 6;
static constexpr size_t FSFW_PRINT_BUFFER_SIZE = 124;
}
#endif /* CONFIG_FSFWCONFIG_H_ */

View File

@ -2,6 +2,7 @@
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_
#include "../returnvalues/HasReturnvaluesIF.h"
#include <FSFWConfig.h>
#include <iostream>
#include <sstream>
#include <iomanip>
@ -54,7 +55,7 @@ private:
bool errStream;
//! Needed for buffered mode.
static size_t const BUF_SIZE = 128;
static size_t const BUF_SIZE = fsfwconfig::FSFW_PRINT_BUFFER_SIZE;
char buf[BUF_SIZE];
//! In this function, the characters are parsed.

View File

@ -1,2 +1,104 @@
#include "ServiceInterfacePrinter.h"
#include "../timemanager/Clock.h"
#include <FSFWConfig.h>
#include <cstdarg>
#include <cstdint>
fsfw::PrintLevel printLevel = fsfw::PrintLevel::DEBUG;
uint8_t printBuffer[fsfwconfig::FSFW_PRINT_BUFFER_SIZE];
void fsfwPrint(fsfw::PrintLevel printType, const char* fmt, va_list arg) {
uint32_t len = 0;
/* Check logger level */
if(printType == fsfw::PrintLevel::NONE or printType > printLevel) {
return;
}
/* Log message to terminal */
#if FSFW_COLORED_OUTPUT == 1
if(printType == fsfw::PrintLevel::INFO) {
len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_GREEN);
}
else if(printType == fsfw::PrintLevel::DEBUG) {
len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_BLUE);
}
else if(printType == fsfw::PrintLevel::WARNING) {
len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_YELLOW);
}
else if(printType == fsfw::PrintLevel::ERROR_TYPE) {
len += sprintf((char *)printBuffer, fsfw::ANSI_COLOR_RED);
}
#endif
if (printType == fsfw::PrintLevel::INFO) {
len += sprintf((char *)printBuffer + len, "INFO: ");
}
if(printType == fsfw::PrintLevel::DEBUG) {
len += sprintf((char *)printBuffer + len, "DEBUG: ");
}
if(printType == fsfw::PrintLevel::WARNING) {
len += sprintf((char *)printBuffer + len, "WARNING: ");
}
if(printType == fsfw::PrintLevel::ERROR_TYPE) {
len += sprintf((char *)printBuffer + len, "ERROR: ");
}
Clock::TimeOfDay_t now;
Clock::getDateAndTime(&now);
/*
* Log current time to terminal if desired.
*/
len += sprintf((char*)printBuffer + len, "| %lu:%02lu:%02lu.%03lu | ",
(unsigned long) now.hour,
(unsigned long) now.minute,
(unsigned long) now.second,
(unsigned long) now.usecond /1000);
//changed Jan 2017. Need to update length with buffer size
len += vsnprintf((char *)(printBuffer + len),
sizeof(printBuffer)-len, fmt, arg);
printf("%s", printBuffer);
}
void fsfw::setPrintLevel(PrintLevel printLevel_) {
printLevel = printLevel_;
}
fsfw::PrintLevel fsfw::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);
}

View File

@ -0,0 +1,33 @@
#include <stdio.h>
namespace fsfw {
enum class PrintLevel {
NONE = 0,
//! Strange error when using just ERROR..
ERROR_TYPE = 1,
WARNING = 2,
INFO = 3,
DEBUG = 4
};
static const char* const ANSI_COLOR_RED = "\x1b[31m";
static const char* const ANSI_COLOR_GREEN = "\x1b[32m";
static const char* const ANSI_COLOR_YELLOW = "\x1b[33m";
static const char* const ANSI_COLOR_BLUE = "\x1b[34m";
static const char* const ANSI_COLOR_MAGENTA = "\x1b[35m";
static const char* const ANSI_COLOR_CYAN = "\x1b[36m";
static const char* const ANSI_COLOR_RESET = "\x1b[0m";
void setPrintLevel(PrintLevel printLevel);
PrintLevel getPrintLevel();
void printInfo(const char *fmt, ...);
void printWarning(const char* fmt, ...);
void printDebug(const char* fmt, ...);
void printError(const char* fmt, ...);
}