revamed and imroved error handling

This commit is contained in:
Robin Müller 2021-01-08 15:10:33 +01:00
parent 5a8647d367
commit f2ecd6d740
2 changed files with 131 additions and 67 deletions

View File

@ -3,6 +3,7 @@
#include "LocalPoolDataSetBase.h" #include "LocalPoolDataSetBase.h"
#include "../housekeeping/HousekeepingPacketUpdate.h" #include "../housekeeping/HousekeepingPacketUpdate.h"
#include "../serviceinterface/ServiceInterface.h"
#include "../housekeeping/HousekeepingSetPacket.h" #include "../housekeeping/HousekeepingSetPacket.h"
#include "../housekeeping/AcceptsHkPacketsIF.h" #include "../housekeeping/AcceptsHkPacketsIF.h"
@ -21,19 +22,17 @@ LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner,
MessageQueueIF* queueToUse, bool appendValidityBuffer): MessageQueueIF* queueToUse, bool appendValidityBuffer):
appendValidityBuffer(appendValidityBuffer) { appendValidityBuffer(appendValidityBuffer) {
if(owner == nullptr) { if(owner == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::WARNING_TYPE,
sif::error << "LocalDataPoolManager::LocalDataPoolManager: " "LocalDataPoolManager", HasReturnvaluesIF::RETURN_FAILED,
<< "Invalid supplied owner!" << std::endl; "Invalid supplied owner");
#endif
return; return;
} }
this->owner = owner; this->owner = owner;
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
if(mutex == nullptr) { if(mutex == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::ERROR_TYPE,
sif::error << "LocalDataPoolManager::LocalDataPoolManager: " "LocalDataPoolManager", HasReturnvaluesIF::RETURN_FAILED,
<< "Could not create mutex." << std::endl; "Could not create mutex");
#endif
} }
hkQueue = queueToUse; hkQueue = queueToUse;
@ -43,21 +42,18 @@ LocalDataPoolManager::~LocalDataPoolManager() {}
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) { ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) {
if(queueToUse == nullptr) { if(queueToUse == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 // error, all destinations invalid
sif::error << "LocalDataPoolManager::initialize: " printWarningOrError(ErrorTypes::ERROR_TYPE,
<< std::hex << "0x" << owner->getObjectId() << ". Supplied " "initialize", QUEUE_OR_DESTINATION_INVALID);
<< "queue invalid!" << std::dec << std::endl;
#endif
} }
hkQueue = queueToUse; hkQueue = queueToUse;
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE); ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
if(ipcStore == nullptr) { if(ipcStore == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 // error, all destinations invalid
sif::error << "LocalDataPoolManager::initialize: " printWarningOrError(ErrorTypes::ERROR_TYPE,
<< std::hex << "0x" << owner->getObjectId() << ": Could not " "initialize", HasReturnvaluesIF::RETURN_FAILED,
<< "set IPC store." <<std::dec << std::endl; "Could not set IPC store.");
#endif
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
@ -69,11 +65,9 @@ ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) {
hkDestinationId = hkPacketReceiver->getHkQueue(); hkDestinationId = hkPacketReceiver->getHkQueue();
} }
else { else {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::ERROR_TYPE,
sif::error << "LocalDataPoolManager::LocalDataPoolManager: " "initialize", QUEUE_OR_DESTINATION_INVALID);
<< "Default HK destination object is invalid!" << std::endl; return QUEUE_OR_DESTINATION_INVALID;
#endif
return HasReturnvaluesIF::RETURN_FAILED;
} }
} }
@ -95,10 +89,10 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
} }
return result; return result;
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "HousekeepingManager: The map should only be initialized " printWarningOrError(ErrorTypes::WARNING_TYPE,
<< "once!" << std::endl; "initialize", HasReturnvaluesIF::RETURN_FAILED,
#endif "The map should only be initialized once");
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -163,7 +157,9 @@ ReturnValue_t LocalDataPoolManager::handleNotificationUpdate(
LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(
receiver.dataId.localPoolId); receiver.dataId.localPoolId);
if(poolObj == nullptr) { if(poolObj == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; printWarningOrError(ErrorTypes::WARNING_TYPE,
"handleNotificationUpdate", POOLOBJECT_NOT_FOUND);
return POOLOBJECT_NOT_FOUND;
} }
if(poolObj->hasChanged()) { if(poolObj->hasChanged()) {
// prepare and send update notification. // prepare and send update notification.
@ -183,7 +179,9 @@ ReturnValue_t LocalDataPoolManager::handleNotificationUpdate(
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
receiver.dataId.sid); receiver.dataId.sid);
if(dataSet == nullptr) { if(dataSet == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; printWarningOrError(ErrorTypes::WARNING_TYPE,
"handleNotificationUpdate", DATASET_NOT_FOUND);
return DATASET_NOT_FOUND;
} }
if(dataSet->hasChanged()) { if(dataSet->hasChanged()) {
// prepare and send update notification // prepare and send update notification
@ -213,6 +211,8 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(
LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(
receiver.dataId.localPoolId); receiver.dataId.localPoolId);
if(poolObj == nullptr) { if(poolObj == nullptr) {
printWarningOrError(ErrorTypes::WARNING_TYPE,
"handleNotificationSnapshot", POOLOBJECT_NOT_FOUND);
return POOLOBJECT_NOT_FOUND; return POOLOBJECT_NOT_FOUND;
} }
@ -249,6 +249,8 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
receiver.dataId.sid); receiver.dataId.sid);
if(dataSet == nullptr) { if(dataSet == nullptr) {
printWarningOrError(ErrorTypes::WARNING_TYPE,
"handleNotificationSnapshot", DATASET_NOT_FOUND);
return DATASET_NOT_FOUND; return DATASET_NOT_FOUND;
} }
@ -351,11 +353,9 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid,
AcceptsHkPacketsIF* hkReceiverObject = AcceptsHkPacketsIF* hkReceiverObject =
objectManager->get<AcceptsHkPacketsIF>(packetDestination); objectManager->get<AcceptsHkPacketsIF>(packetDestination);
if(hkReceiverObject == nullptr) { if(hkReceiverObject == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::WARNING_TYPE,
sif::error << "LocalDataPoolManager::subscribeForPeriodicPacket:" "subscribeForPeriodicPacket", QUEUE_OR_DESTINATION_INVALID);
<< " Invalid receiver!"<< std::endl; return QUEUE_OR_DESTINATION_INVALID;
#endif
return HasReturnvaluesIF::RETURN_OK;
} }
struct HkReceiver hkReceiver; struct HkReceiver hkReceiver;
@ -383,11 +383,9 @@ ReturnValue_t LocalDataPoolManager::subscribeForUpdatePackets(sid_t sid,
AcceptsHkPacketsIF* hkReceiverObject = AcceptsHkPacketsIF* hkReceiverObject =
objectManager->get<AcceptsHkPacketsIF>(packetDestination); objectManager->get<AcceptsHkPacketsIF>(packetDestination);
if(hkReceiverObject == nullptr) { if(hkReceiverObject == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::WARNING_TYPE,
sif::error << "LocalDataPoolManager::subscribeForPeriodicPacket:" "subscribeForPeriodicPacket", QUEUE_OR_DESTINATION_INVALID);
<< " Invalid receiver!"<< std::endl; return QUEUE_OR_DESTINATION_INVALID;
#endif
return HasReturnvaluesIF::RETURN_OK;
} }
struct HkReceiver hkReceiver; struct HkReceiver hkReceiver;
@ -591,10 +589,8 @@ ReturnValue_t LocalDataPoolManager::printPoolEntry(
lp_id_t localPoolId) { lp_id_t localPoolId) {
auto poolIter = localPoolMap.find(localPoolId); auto poolIter = localPoolMap.find(localPoolId);
if (poolIter == localPoolMap.end()) { if (poolIter == localPoolMap.end()) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::WARNING_TYPE, "printPoolEntry",
sif::debug << "HousekeepingManager::fechPoolEntry:" HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND);
<< " Pool entry not found." << std::endl;
#endif
return HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND; return HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
} }
poolIter->second->print(); poolIter->second->print();
@ -614,10 +610,9 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
MessageQueueId_t destination) { MessageQueueId_t destination) {
if(dataSet == nullptr) { if(dataSet == nullptr) {
// Configuration error. // Configuration error.
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::WARNING_TYPE,
sif::warning << "HousekeepingManager::generateHousekeepingPacket:" "generateHousekeepingPacket",
<< " Set ID not found or dataset not assigned!" << std::endl; DATASET_NOT_FOUND);
#endif
return DATASET_NOT_FOUND; return DATASET_NOT_FOUND;
} }
@ -640,12 +635,18 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
} }
if(hkQueue == nullptr) { if(hkQueue == nullptr) {
return QUEUE_OR_DESTINATION_NOT_SET; // error, all destinations invalid
printWarningOrError(ErrorTypes::WARNING_TYPE,
"generateHousekeepingPacket",
QUEUE_OR_DESTINATION_INVALID);
return QUEUE_OR_DESTINATION_INVALID;
} }
if(destination == MessageQueueIF::NO_QUEUE) { if(destination == MessageQueueIF::NO_QUEUE) {
if(hkDestinationId == MessageQueueIF::NO_QUEUE) { if(hkDestinationId == MessageQueueIF::NO_QUEUE) {
// error, all destinations invalid // error, all destinations invalid
return HasReturnvaluesIF::RETURN_FAILED; printWarningOrError(ErrorTypes::WARNING_TYPE,
"generateHousekeepingPacket",
QUEUE_OR_DESTINATION_INVALID);
} }
destination = hkDestinationId; destination = hkDestinationId;
} }
@ -681,6 +682,13 @@ void LocalDataPoolManager::setNonDiagnosticIntervalFactor(
void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) { void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) {
sid_t sid = receiver.dataId.sid; sid_t sid = receiver.dataId.sid;
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
if(dataSet == nullptr) {
printWarningOrError(ErrorTypes::WARNING_TYPE,
"performPeriodicHkGeneration",
DATASET_NOT_FOUND);
return;
}
if(not dataSet->getReportingEnabled()) { if(not dataSet->getReportingEnabled()) {
return; return;
} }
@ -699,10 +707,11 @@ void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) {
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
// configuration error // configuration error
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "LocalDataPoolManager::performHkOperation:" sif::warning << "LocalDataPoolManager::performHkOperation: "
<< "0x" << std::hex << std::setfill('0') << std::setw(8) << "HK generation failed." << std::endl;
<< owner->getObjectId() << " Error generating " #else
<< "HK packet" << std::setfill(' ') << std::dec << std::endl; fsfw::printWarning("LocalDataPoolManager::performHkOperation: "
"HK generation failed.\n");
#endif #endif
} }
} }
@ -748,11 +757,10 @@ ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
// Get and check dataset first. // Get and check dataset first.
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
if(dataSet == nullptr) { if(dataSet == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::WARNING_TYPE,
sif::warning << "HousekeepingManager::generateHousekeepingPacket:" "performPeriodicHkGeneration",
<< " Set ID not found" << std::endl; DATASET_NOT_FOUND);
#endif return DATASET_NOT_FOUND;
return HasReturnvaluesIF::RETURN_FAILED;
} }
@ -776,10 +784,9 @@ ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
ReturnValue_t result = ipcStore->getFreeElement(&storeId, ReturnValue_t result = ipcStore->getFreeElement(&storeId,
expectedSize,&storePtr); expectedSize,&storePtr);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::ERROR_TYPE,
sif::error << "HousekeepingManager::generateHousekeepingPacket: " "generateSetStructurePacket", HasReturnvaluesIF::RETURN_FAILED,
<< "Could not get free element from IPC store." << std::endl; "Could not get free element from IPC store.");
#endif
return result; return result;
} }
@ -788,10 +795,9 @@ ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
result = setPacket.serialize(&storePtr, &size, expectedSize, result = setPacket.serialize(&storePtr, &size, expectedSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
if(expectedSize != size) { if(expectedSize != size) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 printWarningOrError(ErrorTypes::WARNING_TYPE,
sif::error << "HousekeepingManager::generateSetStructurePacket: " "generateSetStructurePacket", HasReturnvaluesIF::RETURN_FAILED,
<< "Expected size is not equal to serialized size" << std::endl; "Expected size is not equal to serialized size");
#endif
} }
// Send structure reporting reply. // Send structure reporting reply.
@ -808,3 +814,52 @@ ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
hkQueue->reply(&reply); hkQueue->reply(&reply);
return result; return result;
} }
void LocalDataPoolManager::printWarningOrError(ErrorTypes errorType,
const char* functionName, ReturnValue_t error, const char* errorPrint) {
if(errorPrint == nullptr) {
if(error == DATASET_NOT_FOUND) {
errorPrint = "Dataset not found";
}
else if(error == POOLOBJECT_NOT_FOUND) {
errorPrint = "Pool Object not found";
}
else if(error == HasReturnvaluesIF::RETURN_FAILED) {
if(errorType == ErrorTypes::WARNING_TYPE) {
errorPrint = "Generic Warning";
}
else {
errorPrint = "Generic error";
}
}
else if(error == QUEUE_OR_DESTINATION_INVALID) {
errorPrint = "Queue or destination not set";
}
else {
errorPrint = "Unknown error";
}
}
if(errorType == ErrorTypes::WARNING_TYPE) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalDataPoolManager::" << functionName
<< ": Object ID " << std::setw(8) << std::setfill('0')
<< std::hex << owner->getObjectId() << " | " << errorPrint
<< std::dec << std::setfill(' ') << std::endl;
#else
fsfw::printWarning("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
owner->getObjectId(), errorPrint);
#endif
}
else if(errorType == ErrorTypes::ERROR_TYPE) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalDataPoolManager::" << functionName
<< ": Object ID " << std::setw(8) << std::setfill('0')
<< std::hex << owner->getObjectId() << " | " << errorPrint
<< std::dec << std::setfill(' ') << std::endl;
#else
fsfw::printError("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n",
owner->getObjectId(), errorPrint);
#endif
}
}

View File

@ -56,7 +56,7 @@ class LocalDataPoolManager {
public: public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER; static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER;
static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0); static constexpr ReturnValue_t QUEUE_OR_DESTINATION_INVALID = MAKE_RETURN_CODE(0);
static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(1); static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(1);
static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(2); static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(2);
@ -370,6 +370,15 @@ private:
ReturnValue_t& status); ReturnValue_t& status);
ReturnValue_t addUpdateToStore(HousekeepingPacketUpdate& updatePacket, ReturnValue_t addUpdateToStore(HousekeepingPacketUpdate& updatePacket,
store_address_t& storeId); store_address_t& storeId);
enum class ErrorTypes {
WARNING_TYPE,
ERROR_TYPE
};
void printWarningOrError(ErrorTypes errorType, const char* functionName,
ReturnValue_t errorCode = HasReturnvaluesIF::RETURN_FAILED,
const char* errorPrint = nullptr);
}; };