replaced loggers

This commit is contained in:
Robin Müller 2022-05-09 00:09:39 +02:00
parent e1aa39f5e4
commit 6f2e03f003
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
9 changed files with 238 additions and 312 deletions

View File

@ -27,11 +27,7 @@ ReturnValue_t pst::pollingSequenceExamples(FixedTimeslotTaskIF* thisSequence) {
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
#if FSFW_CPP_OSTREAM_ENABLED == 1 std::cerr << "pst::pollingSequenceInitFunction: Initialization errors!" << std::endl;
sif::error << "pst::pollingSequenceInitFunction: Initialization errors!" << std::endl;
#else
sif::printError("pst::pollingSequenceInitFunction: Initialization errors!\n");
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
@ -58,7 +54,7 @@ ReturnValue_t pst::pollingSequenceDevices(FixedTimeslotTaskIF* thisSequence) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} else { } else {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "pst::pollingSequenceTestFunction: Initialization errors!" << std::endl; std::cerr << "pst::pollingSequenceTestFunction: Initialization errors!" << std::endl;
#else #else
sif::printError("pst::pollingSequenceTestFunction: Initialization errors!\n"); sif::printError("pst::pollingSequenceTestFunction: Initialization errors!\n");
#endif #endif

View File

@ -33,24 +33,15 @@ void FsfwTestController::performControlOperation() {
} }
case (TRACE_DEV_0_UINT8): { case (TRACE_DEV_0_UINT8): {
if (traceCounter == 0) { if (traceCounter == 0) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGI("Tracing finished\n");
sif::info << "Tracing finished" << std::endl;
#else
sif::printInfo("Tracing finished\n");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
traceVariable = false; traceVariable = false;
traceCounter = traceCycles; traceCounter = traceCycles;
currentTraceType = TraceTypes::NONE; currentTraceType = TraceTypes::NONE;
break; break;
} }
PoolReadGuard readHelper(&deviceDataset0.testUint8Var); PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGI("Tracing device 0 variable 0 (UINT8), current value: {}",
sif::info << "Tracing device 0 variable 0 (UINT8), current value: " static_cast<int>(deviceDataset0.testUint8Var.value));
<< static_cast<int>(deviceDataset0.testUint8Var.value) << std::endl;
#else
sif::printInfo("Tracing device 0 variable 0 (UINT8), current value: %d\n",
deviceDataset0.testUint8Var.value);
#endif
traceCounter--; traceCounter--;
break; break;
} }
@ -67,18 +58,10 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
HasLocalDataPoolIF* device0 = auto* device0 =
ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId()); ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId());
if (device0 == nullptr) { if (device0 == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("initializeAfterTaskCreation: Test device handler 0 handle invalid\n");
sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 0 "
"handle invalid!"
<< std::endl;
#else
sif::printWarning(
"TestController::initializeAfterTaskCreation: Test device handler 0 "
"handle invalid!");
#endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface(); ProvidesDataPoolSubscriptionIF* subscriptionIF = device0->getSubscriptionInterface();
@ -90,18 +73,10 @@ ReturnValue_t FsfwTestController::initializeAfterTaskCreation() {
getCommandQueue(), false); getCommandQueue(), false);
} }
HasLocalDataPoolIF* device1 = auto* device1 =
ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId()); ObjectManager::instance()->get<HasLocalDataPoolIF>(deviceDataset0.getCreatorObjectId());
if (device1 == nullptr) { if (device1 == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_LOGW("initializeAfterTaskCreation: Test device handler 1 handle invalid\n");
sif::warning << "TestController::initializeAfterTaskCreation: Test device handler 1 "
"handle invalid!"
<< std::endl;
#else
sif::printWarning(
"TestController::initializeAfterTaskCreation: Test device handler 1 "
"handle invalid!");
#endif
} }
subscriptionIF = device1->getSubscriptionInterface(); subscriptionIF = device1->getSubscriptionInterface();
@ -133,18 +108,8 @@ void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId
} else { } else {
printout = "Snapshot"; printout = "Snapshot";
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGI("handleChangedDataset: {} update from object ID {:#08x} and set ID {}\n", printout,
sif::info << "FsfwTestController::handleChangedDataset: " << printout sid.objectId, sid.ownerSetId);
<< " update"
"from object ID "
<< setw(8) << setfill('0') << hex << sid.objectId << " and set ID " << sid.ownerSetId
<< dec << setfill(' ') << endl;
#else
sif::printInfo(
"FsfwTestController::handleChangedPoolVariable: %s update from"
"object ID 0x%08x and set ID %lu\n",
printout, sid.objectId, sid.ownerSetId);
#endif
if (storeId == storeId::INVALID_STORE_ADDRESS) { if (storeId == storeId::INVALID_STORE_ADDRESS) {
if (sid.objectId == device0Id) { if (sid.objectId == device0Id) {
@ -154,7 +119,7 @@ void FsfwTestController::handleChangedDataset(sid_t sid, store_address_t storeId
floatVec[1] = deviceDataset0.testFloat3Vec.value[1]; floatVec[1] = deviceDataset0.testFloat3Vec.value[1];
floatVec[2] = deviceDataset0.testFloat3Vec.value[2]; floatVec[2] = deviceDataset0.testFloat3Vec.value[2];
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Current float vector (3) values: [" << floatVec[0] << ", " << floatVec[1] std::cout << "Current float vector (3) values: [" << floatVec[0] << ", " << floatVec[1]
<< ", " << floatVec[2] << "]" << std::endl; << ", " << floatVec[2] << "]" << std::endl;
#else #else
sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", floatVec[0], floatVec[1], sif::printInfo("Current float vector (3) values: [%f, %f, %f]\n", floatVec[0], floatVec[1],
@ -185,7 +150,7 @@ void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_add
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TestController::handleChangedPoolVariable: " << printout std::cout << "TestController::handleChangedPoolVariable: " << printout
<< " update from object " << " update from object "
"ID 0x" "ID 0x"
<< setw(8) << setfill('0') << hex << globPoolId.objectId << " and local pool ID " << setw(8) << setfill('0') << hex << globPoolId.objectId << " and local pool ID "
@ -201,7 +166,7 @@ void FsfwTestController::handleChangedPoolVariable(gp_id_t globPoolId, store_add
if (globPoolId.objectId == device0Id) { if (globPoolId.objectId == device0Id) {
PoolReadGuard readHelper(&deviceDataset0.testUint8Var); PoolReadGuard readHelper(&deviceDataset0.testUint8Var);
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "Current test variable 0 (UINT8) value: " std::cout << "Current test variable 0 (UINT8) value: "
<< static_cast<int>(deviceDataset0.testUint8Var.value) << std::endl; << static_cast<int>(deviceDataset0.testUint8Var.value) << std::endl;
#else #else
sif::printInfo("Current test variable 0 (UINT8) value %d\n", sif::printInfo("Current test variable 0 (UINT8) value %d\n",

View File

@ -80,24 +80,16 @@ object_id_t FsfwExampleTask::getSender() {
ReturnValue_t FsfwExampleTask::initialize() { ReturnValue_t FsfwExampleTask::initialize() {
// Get the dataset of the sender. Will be cached for later checks. // Get the dataset of the sender. Will be cached for later checks.
object_id_t sender = getSender(); object_id_t sender = getSender();
HasLocalDataPoolIF* senderIF = ObjectManager::instance()->get<HasLocalDataPoolIF>(sender); auto* senderIF = ObjectManager::instance()->get<HasLocalDataPoolIF>(sender);
if (senderIF == nullptr) { if (senderIF == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 std::cerr << "FsfwDemoTask::initialize: Sender object invalid!" << std::endl;
sif::error << "FsfwDemoTask::initialize: Sender object invalid!" << std::endl;
#else
sif::printError("FsfwDemoTask::initialize: Sender object invalid!\n");
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
// we need a private copy of the previous dataset.. or we use the shared dataset. // we need a private copy of the previous dataset.. or we use the shared dataset.
senderSet = new FsfwDemoSet(senderIF); senderSet = new FsfwDemoSet(senderIF);
if (senderSet == nullptr) { if (senderSet == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 std::cerr << "FsfwDemoTask::initialize: Sender dataset invalid!" << std::endl;
sif::error << "FsfwDemoTask::initialize: Sender dataset invalid!" << std::endl;
#else
sif::printError("FsfwDemoTask::initialize: Sender dataset invalid!\n");
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
return poolManager.initialize(commandQueue); return poolManager.initialize(commandQueue);
@ -128,11 +120,7 @@ ReturnValue_t FsfwExampleTask::performMonitoringDemo() {
ReturnValue_t result = demoSet.variableLimit.read(MutexIF::TimeoutType::WAITING, 20); ReturnValue_t result = demoSet.variableLimit.read(MutexIF::TimeoutType::WAITING, 20);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
/* Configuration error */ /* Configuration error */
#if FSFW_CPP_OSTREAM_ENABLED == 1 std::cerr << "DummyObject::performOperation: Could not read variableLimit!" << std::endl;
sif::error << "DummyObject::performOperation: Could not read variableLimit!" << std::endl;
#else
sif::printError("DummyObject::performOperation: Could not read variableLimit!\n");
#endif
return result; return result;
} }
if (this->getObjectId() == objects::TEST_DUMMY_5) { if (this->getObjectId() == objects::TEST_DUMMY_5) {
@ -151,11 +139,7 @@ ReturnValue_t FsfwExampleTask::performSendOperation() {
FsfwExampleTask* target = ObjectManager::instance()->get<FsfwExampleTask>(nextRecipient); FsfwExampleTask* target = ObjectManager::instance()->get<FsfwExampleTask>(nextRecipient);
if (target == nullptr) { if (target == nullptr) {
/* Configuration error */ /* Configuration error */
#if FSFW_CPP_OSTREAM_ENABLED == 1 std::cerr << "DummyObject::performOperation: Next recipient does not exist!" << std::endl;
sif::error << "DummyObject::performOperation: Next recipient does not exist!" << std::endl;
#else
sif::printError("DummyObject::performOperation: Next recipient does not exist!\n");
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@ -167,22 +151,14 @@ ReturnValue_t FsfwExampleTask::performSendOperation() {
/* Send message using own message queue */ /* Send message using own message queue */
ReturnValue_t result = commandQueue->sendMessage(target->getMessageQueueId(), &message); ReturnValue_t result = commandQueue->sendMessage(target->getMessageQueueId(), &message);
if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 std::cerr << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl;
sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl;
#else
sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result);
#endif
} }
/* Send message without via MessageQueueSenderIF */ /* Send message without via MessageQueueSenderIF */
result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(), &message, result = MessageQueueSenderIF::sendMessage(target->getMessageQueueId(), &message,
commandQueue->getId()); commandQueue->getId());
if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) { if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::FULL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 std::cerr << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl;
sif::error << "FsfwDemoTask::performSendOperation: Send failed with " << result << std::endl;
#else
sif::printError("FsfwDemoTask::performSendOperation: Send failed with %hu\n", result);
#endif
} }
demoSet.variableWrite.value = randomNumber; demoSet.variableWrite.value = randomNumber;
@ -197,9 +173,7 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
CommandMessage receivedMessage; CommandMessage receivedMessage;
result = commandQueue->receiveMessage(&receivedMessage); result = commandQueue->receiveMessage(&receivedMessage);
if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::EMPTY) { if (result != HasReturnvaluesIF::RETURN_OK && result != MessageQueueIF::EMPTY) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGD("performReceiveOperation: Receive failed with {}\n", result);
sif::debug << "Receive failed with " << result << std::endl;
#endif
break; break;
} }
if (result != MessageQueueIF::EMPTY) { if (result != MessageQueueIF::EMPTY) {
@ -221,10 +195,10 @@ ReturnValue_t FsfwExampleTask::performReceiveOperation() {
} }
if (senderSet->variableRead.value != receivedMessage.getParameter()) { if (senderSet->variableRead.value != receivedMessage.getParameter()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "FsfwDemoTask::performReceiveOperation: Variable " << std::hex << "0x" std::cerr << "FsfwDemoTask::performReceiveOperation: Variable " << std::hex << "0x"
<< senderSet->variableRead.getDataPoolId() << std::dec << " has wrong value." << senderSet->variableRead.getDataPoolId() << std::dec << " has wrong value."
<< std::endl; << std::endl;
sif::error << "Value: " << demoSet.variableRead.value std::cerr << "Value: " << demoSet.variableRead.value
<< ", expected: " << receivedMessage.getParameter() << std::endl; << ", expected: " << receivedMessage.getParameter() << std::endl;
#endif #endif
} }

View File

@ -35,10 +35,10 @@ ReturnValue_t FsfwReaderTask::performOperation(uint8_t operationCode) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
if (opDivider.checkAndIncrement() and printoutEnabled) { if (opDivider.checkAndIncrement() and printoutEnabled) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "FsfwPeriodicTask::performOperation: Reading variables." << std::endl; std::cout << "FsfwPeriodicTask::performOperation: Reading variables." << std::endl;
sif::info << "Variable read from demo object 1: " << variable1 << std::endl; std::cout << "Variable read from demo object 1: " << variable1 << std::endl;
sif::info << "Variable read from demo object 2: " << variable2 << std::endl; std::cout << "Variable read from demo object 2: " << variable2 << std::endl;
sif::info << "Variable read from demo object 3: " << variable3 << std::endl; std::cout << "Variable read from demo object 3: " << variable3 << std::endl;
#else #else
sif::printInfo("FsfwPeriodicTask::performOperation: Reading variables.\n\r"); sif::printInfo("FsfwPeriodicTask::performOperation: Reading variables.\n\r");
sif::printInfo("Variable read from demo object 1: %d\n\r", variable1); sif::printInfo("Variable read from demo object 1: %d\n\r", variable1);

View File

@ -1,7 +1,7 @@
#include "MutexExample.h" #include "MutexExample.h"
#include <fsfw/ipc/MutexFactory.h> #include <fsfw/ipc/MutexFactory.h>
#include <fsfw/serviceinterface/ServiceInterface.h> #include <fsfw/serviceinterface.h>
void MutexExample::example() { void MutexExample::example() {
MutexIF* mutex = MutexFactory::instance()->createMutex(); MutexIF* mutex = MutexFactory::instance()->createMutex();
@ -9,37 +9,21 @@ void MutexExample::example() {
ReturnValue_t result = mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000); ReturnValue_t result = mutex->lockMutex(MutexIF::TimeoutType::WAITING, 2 * 60 * 1000);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGET("MutexExample::example: Lock Failed with {}\n", result);
sif::error << "MutexExample::example: Lock Failed with " << result << std::endl;
#else
sif::printError("MutexExample::example: Lock Failed with %hu\n", result);
#endif
} }
result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING); result = mutex2->lockMutex(MutexIF::TimeoutType::BLOCKING);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGET("MutexExample::example: Lock Failed with {}\n", result);
sif::error << "MutexExample::example: Lock Failed with " << result << std::endl;
#else
sif::printError("MutexExample::example: Lock Failed with %hu\n", result);
#endif
} }
result = mutex->unlockMutex(); result = mutex->unlockMutex();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGET("MutexExample::example: Unlock Failed with {}\n", result);
sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl;
#else
sif::printError("MutexExample::example: Unlock Failed with %hu\n", result);
#endif
} }
result = mutex2->unlockMutex(); result = mutex2->unlockMutex();
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGET("MutexExample::example: Unlock Failed with {}\n", result);
sif::error << "MutexExample::example: Unlock Failed with " << result << std::endl;
#else
sif::printError("MutexExample::example: Unlock Failed with %hu\n", result);
#endif
} }
} }

View File

@ -1,14 +1,14 @@
#include "testFmt.h" #include "fsfw/serviceinterface/fmtWrapper.h"
void fmtTests() { void fmtTests() {
sif::fdebug(__FILENAME__, __LINE__, "Hello {} {}", "World\n"); sif::initialize();
sif::fdebug_t(__FILENAME__, __LINE__, "Hallo\n"); sif::debug(__FILENAME__, __LINE__, "Hello {}", "World\n");
FSFW_LOGD("{}", "Hallo\n"); sif::debug_t(__FILENAME__, __LINE__, "Hallo\n");
// MY_LOG("{}", "test\n"); FSFW_FLOGD("{}", "Hallo\n");
// sif::finfo_t("Hallo\n"); sif::info_t("Hallo\n");
// sif::finfo("Hallo\n"); sif::info("Hallo\n");
// sif::fwarning("Hello\n"); sif::warning(__FILENAME__, __LINE__, "Hello\n");
// sif::fwarning_t("Hello\n"); sif::warning_t(__FILENAME__, __LINE__, "Hello\n");
// sif::ferror("Hello\n"); sif::error(__FILENAME__, __LINE__, "Hello\n");
// sif::ferror_t("Hello\n"); sif::error_t(__FILENAME__, __LINE__, "Hello\n");
} }

View File

@ -1,159 +1,180 @@
#ifndef FSFW_EXAMPLE_HOSTED_TESTFMT_H //#ifndef FSFW_EXAMPLE_HOSTED_TESTFMT_H
#define FSFW_EXAMPLE_HOSTED_TESTFMT_H //#define FSFW_EXAMPLE_HOSTED_TESTFMT_H
//
#include <fmt/chrono.h> //#include <fmt/chrono.h>
#include <fmt/color.h> //#include <fmt/color.h>
#include <fmt/compile.h> //#include <fmt/compile.h>
#include <fmt/core.h> //#include <fmt/core.h>
//
#include <array> //#include <array>
#include <cstdint> //#include <cstdint>
//
#include "fsfw/ipc/MutexFactory.h" //#include "fsfw/ipc/MutexFactory.h"
#include "fsfw/ipc/MutexGuard.h" //#include "fsfw/ipc/MutexGuard.h"
#include "fsfw/ipc/MutexIF.h" //#include "fsfw/ipc/MutexIF.h"
#include "fsfw/timemanager/Clock.h" //#include "fsfw/timemanager/Clock.h"
//
#define __FILENAME_REL__ (((const char*)__FILE__ + SOURCE_PATH_SIZE)) //#define __FILENAME_REL__ (((const char*)__FILE__ + SOURCE_PATH_SIZE))
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) //#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
//
void fmtTests(); void fmtTests();
//
namespace sif { // namespace sif {
//
static std::array<char, 524> PRINT_BUF = {}; // static std::array<char, 524> _PRINT_BUF = {};
//
static const char INFO_PREFIX[] = "INFO"; // static const char INFO_PREFIX[] = "INFO";
static const char DEBUG_PREFIX[] = "DEBUG"; // static const char DEBUG_PREFIX[] = "DEBUG";
static const char WARNING_PREFIX[] = "WARNING"; // static const char WARNING_PREFIX[] = "WARNING";
static const char ERROR_PREFIX[] = "ERROR"; // static const char ERROR_PREFIX[] = "ERROR";
//
enum class LogLevel : unsigned int { DEBUG = 0, INFO = 1, WARNING = 2, ERROR = 3 }; // enum class LogLevel : unsigned int { DEBUG = 0, INFO = 1, WARNING = 2, ERROR = 3 };
//
static const char* PREFIX_ARR[4] = {DEBUG_PREFIX, INFO_PREFIX, WARNING_PREFIX, ERROR_PREFIX}; // static const char* PREFIX_ARR[4] = {DEBUG_PREFIX, INFO_PREFIX, WARNING_PREFIX, ERROR_PREFIX};
//
static const std::array<fmt::color, 4> LOG_COLOR_ARR = { // static const std::array<fmt::color, 4> LOG_COLOR_ARR = {
fmt::color::deep_sky_blue, fmt::color::forest_green, fmt::color::orange_red, fmt::color::red}; // fmt::color::deep_sky_blue, fmt::color::forest_green, fmt::color::orange_red, fmt::color::red};
//
static MutexIF* PRINT_MUTEX = MutexFactory::instance()->createMutex(); // static MutexIF* PRINT_MUTEX = nullptr;
//
static size_t writeTypePrefix(LogLevel level) { ////static ReturnValue_t initialize() {
auto idx = static_cast<unsigned int>(level); //// PRINT_MUTEX = MutexFactory::instance()->createMutex();
const auto result = //// if(PRINT_MUTEX == nullptr) {
fmt::format_to_n(PRINT_BUF.begin(), PRINT_BUF.size() - 1, //// return HasReturnvaluesIF::RETURN_FAILED;
fmt::runtime(fmt::format(fg(LOG_COLOR_ARR[idx]), PREFIX_ARR[idx]))); //// }
return result.size; //// return HasReturnvaluesIF::RETURN_OK;
} ////}
//
template <typename... T> // static size_t writeTypePrefix(LogLevel level) {
size_t logTraced(LogLevel level, const char* file, unsigned int line, bool timed, // auto idx = static_cast<unsigned int>(level);
fmt::format_string<T...> fmt, T&&... args) noexcept { // const auto result =
try { // fmt::format_to_n(_PRINT_BUF.begin(), _PRINT_BUF.size() - 1,
MutexGuard mg(PRINT_MUTEX); // fmt::runtime(fmt::format(fg(LOG_COLOR_ARR[idx]), PREFIX_ARR[idx])));
size_t bufPos = writeTypePrefix(level); // return result.size;
auto currentIter = PRINT_BUF.begin() + bufPos; //}
if (timed) { //
Clock::TimeOfDay_t logTime; // template <typename... T>
Clock::getDateAndTime(&logTime); // size_t logTraced(LogLevel level, const char* file, unsigned int line, bool timed,
const auto result = fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos, // fmt::format_string<T...> fmt, T&&... args) noexcept {
" | {}[l.{}] | {:02}:{:02}:{:02}.{:03} | {}", file, line, // if(PRINT_MUTEX == nullptr) {
logTime.hour, logTime.minute, logTime.second, // fmt::print("Please call sif::initialize at program startup\n");
logTime.usecond / 1000, fmt::format(fmt, args...)); // return 0;
*result.out = '\0'; // }
bufPos += result.size; // try {
} else { // MutexGuard mg(PRINT_MUTEX);
const auto result = fmt::format_to_n(currentIter, PRINT_BUF.size() - 1 - bufPos, // size_t bufPos = writeTypePrefix(level);
" | {}[l.{}] | {}", file, line, fmt::format(fmt, args...)); // auto currentIter = _PRINT_BUF.begin() + bufPos;
*result.out = '\0'; // if (timed) {
bufPos += result.size; // Clock::TimeOfDay_t logTime;
} // Clock::getDateAndTime(&logTime);
// const auto result = fmt::format_to_n(currentIter, _PRINT_BUF.size() - 1 - bufPos,
fmt::print(fmt::runtime(PRINT_BUF.data())); // " | {}[l.{}] | {:02}:{:02}:{:02}.{:03} | {}", file,
return bufPos; // line, logTime.hour, logTime.minute, logTime.second,
} catch (const fmt::v8::format_error& e) { // logTime.usecond / 1000, fmt::format(fmt, args...));
fmt::print("Printing failed with error: {}\n", e.what()); // *result.out = '\0';
return 0; // bufPos += result.size;
} // } else {
} // const auto result = fmt::format_to_n(currentIter, _PRINT_BUF.size() - 1 - bufPos,
// " | {}[l.{}] | {}", file, line, fmt::format(fmt,
template <typename... T> // args...));
size_t log(LogLevel level, bool timed, fmt::format_string<T...> fmt, T&&... args) noexcept { // *result.out = '\0';
try { // bufPos += result.size;
MutexGuard mg(PRINT_MUTEX); // }
size_t bufPos = writeTypePrefix(level); //
auto currentIter = PRINT_BUF.begin() + bufPos; // fmt::print(fmt::runtime(_PRINT_BUF.data()));
if (timed) { // return bufPos;
Clock::TimeOfDay_t logTime; // } catch (const fmt::v8::format_error& e) {
Clock::getDateAndTime(&logTime); // fmt::print("Printing failed with error: {}\n", e.what());
const auto result = fmt::format_to_n( // return 0;
currentIter, PRINT_BUF.size() - bufPos, " | {:02}:{:02}:{:02}.{:03} | {}", logTime.hour, // }
logTime.minute, logTime.second, logTime.usecond / 1000, fmt::format(fmt, args...)); //}
bufPos += result.size; //
} // template <typename... T>
fmt::print(fmt::runtime(PRINT_BUF.data())); // size_t log(LogLevel level, bool timed, fmt::format_string<T...> fmt, T&&... args) noexcept {
return bufPos; // if(PRINT_MUTEX == nullptr) {
} catch (const fmt::v8::format_error& e) { // fmt::print("Please call sif::initialize at program startup\n");
fmt::print("Printing failed with error: {}\n", e.what()); // return 0;
return 0; // }
} // try {
} // MutexGuard mg(PRINT_MUTEX);
// size_t bufPos = writeTypePrefix(level);
template <typename... T> // auto currentIter = _PRINT_BUF.begin() + bufPos;
void fdebug(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) noexcept { // if (timed) {
logTraced(LogLevel::DEBUG, file, line, false, fmt, args...); // Clock::TimeOfDay_t logTime;
} // Clock::getDateAndTime(&logTime);
// const auto result = fmt::format_to_n(
template <typename... T> // currentIter, _PRINT_BUF.size() - bufPos, " | {:02}:{:02}:{:02}.{:03} | {}",
void fdebug_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) noexcept { // logTime.hour, logTime.minute, logTime.second, logTime.usecond / 1000, fmt::format(fmt,
logTraced(LogLevel::DEBUG, file, line, true, fmt, args...); // args...));
} // bufPos += result.size;
// }
template <typename... T> // fmt::print(fmt::runtime(_PRINT_BUF.data()));
void finfo_t(fmt::format_string<T...> fmt, T&&... args) { // return bufPos;
log(LogLevel::INFO, true, fmt, args...); // } catch (const fmt::v8::format_error& e) {
} // fmt::print("Printing failed with error: {}\n", e.what());
// return 0;
template <typename... T> // }
void finfo(fmt::format_string<T...> fmt, T&&... args) { //}
log(LogLevel::INFO, false, fmt, args...); //
} // template <typename... T>
// void fdebug(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args)
template <typename... T> // noexcept {
void fwarning(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { // logTraced(LogLevel::DEBUG, file, line, false, fmt, args...);
logTraced(LogLevel::WARNING, file, line, false, fmt, args...); //}
} //
// template <typename... T>
template <typename... T> // void fdebug_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args)
void fwarning_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { // noexcept {
logTraced(LogLevel::WARNING, file, line, true, fmt, args...); // logTraced(LogLevel::DEBUG, file, line, true, fmt, args...);
} //}
//
template <typename... T> // template <typename... T>
void ferror(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { // void finfo_t(fmt::format_string<T...> fmt, T&&... args) {
logTraced(LogLevel::ERROR, file, line, false, fmt, args...); // log(LogLevel::INFO, true, fmt, args...);
} //}
//
template <typename... T> // template <typename... T>
void ferror_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) { // void finfo(fmt::format_string<T...> fmt, T&&... args) {
logTraced(LogLevel::ERROR, file, line, true, fmt, args...); // log(LogLevel::INFO, false, fmt, args...);
} //}
//
} // namespace sif // template <typename... T>
// void fwarning(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) {
#define FSFW_LOGI(format, ...) finfo(FMT_STRING(format), __VA_ARGS__) // logTraced(LogLevel::WARNING, file, line, false, fmt, args...);
//}
#define FSFW_LOGIT(format, ...) finfo_t(FMT_STRING(format), __VA_ARGS__) //
// template <typename... T>
#define FSFW_LOGD(format, ...) sif::fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) // void fwarning_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) {
// logTraced(LogLevel::WARNING, file, line, true, fmt, args...);
#define FSFW_LOGDT(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) //}
//
#define FSFW_LOGW(format, ...) fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) // template <typename... T>
// void ferror(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) {
#define FSFW_LOGWT(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) // logTraced(LogLevel::ERROR, file, line, false, fmt, args...);
//}
#define FSFW_LOGE(format, ...) fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) //
// template <typename... T>
#define FSFW_LOGET(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__) // void ferror_t(const char* file, unsigned int line, fmt::format_string<T...> fmt, T&&... args) {
// logTraced(LogLevel::ERROR, file, line, true, fmt, args...);
#endif // FSFW_EXAMPLE_HOSTED_TESTFMT_H //}
//
//} // namespace sif
//
//#define FSFW_FLOGI(format, ...) finfo(FMT_STRING(format), __VA_ARGS__)
//
//#define FSFW_FLOGIT(format, ...) finfo_t(FMT_STRING(format), __VA_ARGS__)
//
//#define FSFW_FLOGD(format, ...) sif::fdebug(__FILENAME__, __LINE__, FMT_STRING(format),
//__VA_ARGS__)
//
//#define FSFW_FLOGDT(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__)
//
//#define FSFW_FLOGW(format, ...) fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__)
//
//#define FSFW_FLOGWT(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__)
//
//#define FSFW_FLOGE(format, ...) fdebug(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__)
//
//#define FSFW_FLOGET(format, ...) fdebug_t(__FILENAME__, __LINE__, FMT_STRING(format), __VA_ARGS__)
//
//#endif // FSFW_EXAMPLE_HOSTED_TESTFMT_H

View File

@ -2,18 +2,12 @@
#define MISSION_UTILITY_TASKCREATION_H_ #define MISSION_UTILITY_TASKCREATION_H_
#include <fsfw/objectmanager/SystemObjectIF.h> #include <fsfw/objectmanager/SystemObjectIF.h>
#include <fsfw/serviceinterface/ServiceInterface.h> #include <fsfw/serviceinterface.h>
namespace task { namespace task {
void printInitError(const char* objName, object_id_t objectId) { void printInitError(const char* objName, object_id_t objectId) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGW("InitMission: Adding object {} ({:#08x}) failed\n", objName, objectId);
sif::error << "InitMission: Adding object " << objName << "(" << std::setw(8) << std::setfill('0')
<< std::hex << objectId << std::dec << ") failed." << std::endl;
#else
sif::printError("InitMission: Adding object %s (0x%08x) failed.\n", objName,
static_cast<unsigned int>(objectId));
#endif
} }
} // namespace task } // namespace task

View File

@ -2,7 +2,7 @@
#include <fsfw/ipc/QueueFactory.h> #include <fsfw/ipc/QueueFactory.h>
#include <fsfw/objectmanager/ObjectManager.h> #include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/serviceinterface/ServiceInterface.h> #include <fsfw/serviceinterface.h>
#include <fsfw/tmtcpacket/pus/tm.h> #include <fsfw/tmtcpacket/pus/tm.h>
object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT; object_id_t TmFunnel::downlinkDestination = objects::NO_OBJECT;
@ -56,9 +56,7 @@ ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) {
result = tmQueue->sendToDefault(message); result = tmQueue->sendToDefault(message);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
tmPool->deleteData(message->getStorageId()); tmPool->deleteData(message->getStorageId());
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGET("{}", "handlePacket: Error sending to downlink handler\n");
sif::error << "TmFunnel::handlePacket: Error sending to downlink handler" << std::endl;
#endif
return result; return result;
} }
@ -66,9 +64,7 @@ ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) {
result = storageQueue->sendToDefault(message); result = storageQueue->sendToDefault(message);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
tmPool->deleteData(message->getStorageId()); tmPool->deleteData(message->getStorageId());
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGET("{}", "handlePacket: Error sending to storage handler\n");
sif::error << "TmFunnel::handlePacket: Error sending to storage handler" << std::endl;
#endif
return result; return result;
} }
} }
@ -78,22 +74,18 @@ ReturnValue_t TmFunnel::handlePacket(TmTcMessage* message) {
ReturnValue_t TmFunnel::initialize() { ReturnValue_t TmFunnel::initialize() {
tmPool = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE); tmPool = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (tmPool == nullptr) { if (tmPool == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 FSFW_FLOGE("{}",
sif::error << "TmFunnel::initialize: TM store not set." << std::endl; "initialize: TM store not set\n"
sif::error << "Make sure the tm store is set up properly and implements StorageManagerIF" "Make sure the tm store is set up properly and implements StorageManagerIF");
<< std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
AcceptsTelemetryIF* tmTarget = auto* tmTarget = ObjectManager::instance()->get<AcceptsTelemetryIF>(downlinkDestination);
ObjectManager::instance()->get<AcceptsTelemetryIF>(downlinkDestination);
if (tmTarget == nullptr) { if (tmTarget == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmFunnel::initialize: Downlink Destination not set." << std::endl; FSFW_FLOGE("{}",
sif::error << "Make sure the downlink destination object is set up properly and implements " "initialize: Downlink Destination not set. Make sure the downlink destination "
"AcceptsTelemetryIF" "object is set up properly and implements AcceptsTelemetryIF\n");
<< std::endl;
#endif #endif
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }