some refactoring
This commit is contained in:
@ -3,4 +3,10 @@ target_sources(${TARGET_NAME} PRIVATE
|
||||
FsfwExampleTask.cpp
|
||||
MutexExample.cpp
|
||||
FsfwTestTask.cpp
|
||||
)
|
||||
)
|
||||
|
||||
if(FSFW_ADD_FMT_TESTS)
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
testFmt.cpp
|
||||
)
|
||||
endif()
|
||||
|
@ -1,9 +1,16 @@
|
||||
#include "FsfwTestTask.h"
|
||||
#include "../test/testFmt.h"
|
||||
|
||||
#include <commonConfig.h>
|
||||
|
||||
#if FSFW_ADD_FMT_TESTS == 1
|
||||
#include "testFmt.h"
|
||||
#endif
|
||||
|
||||
FsfwTestTask::FsfwTestTask(object_id_t objectId, bool periodicEvent)
|
||||
: TestTask(objectId), periodicEvent(periodicEvent) {
|
||||
#if FSFW_ADD_FMT_TESTS == 1
|
||||
fmtTests();
|
||||
#endif
|
||||
}
|
||||
|
||||
ReturnValue_t FsfwTestTask::performPeriodicAction() {
|
||||
|
12
example/test/testFmt.cpp
Normal file
12
example/test/testFmt.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "testFmt.h"
|
||||
|
||||
void fmtTests() {
|
||||
sif::fdebug_t("Hallo\n");
|
||||
sif::fdebug("Hallo\n");
|
||||
sif::finfo_t("Hallo\n");
|
||||
sif::finfo("Hallo\n");
|
||||
sif::fwarning("Hello\n");
|
||||
sif::fwarning_t("Hello\n");
|
||||
sif::ferror("Hello\n");
|
||||
sif::ferror_t("Hello\n");
|
||||
}
|
82
example/test/testFmt.h
Normal file
82
example/test/testFmt.h
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef FSFW_EXAMPLE_HOSTED_TESTFMT_H
|
||||
#define FSFW_EXAMPLE_HOSTED_TESTFMT_H
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/core.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include "fsfw/ipc/MutexFactory.h"
|
||||
#include "fsfw/ipc/MutexGuard.h"
|
||||
#include "fsfw/ipc/MutexIF.h"
|
||||
#include "fsfw/timemanager/Clock.h"
|
||||
|
||||
void fmtTests();
|
||||
|
||||
namespace sif {
|
||||
|
||||
static std::array<char, 256> PRINT_BUF = {};
|
||||
static MutexIF* PRINT_MUTEX = MutexFactory::instance()->createMutex();
|
||||
|
||||
template <typename... T>
|
||||
void flog(const char* prefix, fmt::color color, fmt::format_string<T...> fmt, T&&... args) {
|
||||
MutexGuard mg(PRINT_MUTEX);
|
||||
const auto result = fmt::format_to_n(PRINT_BUF.begin(), PRINT_BUF.size() - 1, "{} | {}",
|
||||
format(fg(color), prefix), fmt::format(fmt, args...));
|
||||
*result.out = '\0';
|
||||
fmt::print("{}", PRINT_BUF.data());
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void flog_t(const char* prefix, fmt::color color, fmt::format_string<T...> fmt, T&&... args) {
|
||||
Clock::TimeOfDay_t logTime;
|
||||
Clock::getDateAndTime(&logTime);
|
||||
flog(prefix, color, "{:02}:{:02}:{:02}.{:03} | {}", logTime.hour, logTime.minute,
|
||||
logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...));
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fdebug_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("DEBUG", fmt::color::deep_sky_blue, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fdebug(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("DEBUG", fmt::color::deep_sky_blue, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void finfo_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("INFO", fmt::color::forest_green, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void finfo(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("INFO", fmt::color::forest_green, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fwarning(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("WARNING", fmt::color::orange_red, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void fwarning_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("WARNING", fmt::color::orange_red, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void ferror(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog("ERROR", fmt::color::red, fmt, args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
void ferror_t(fmt::format_string<T...> fmt, T&&... args) {
|
||||
flog_t("ERROR", fmt::color::red, fmt, args...);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // FSFW_EXAMPLE_HOSTED_TESTFMT_H
|
Reference in New Issue
Block a user