improved internal error reporter

This commit is contained in:
Robin Müller 2021-03-17 23:28:01 +01:00
parent cad302730e
commit b41eb518e7
2 changed files with 137 additions and 137 deletions

View File

@ -3,19 +3,20 @@
#include "../ipc/QueueFactory.h" #include "../ipc/QueueFactory.h"
#include "../ipc/MutexFactory.h" #include "../ipc/MutexFactory.h"
#include "../serviceinterface/ServiceInterface.h" #include "../serviceinterface/ServiceInterface.h"
#include "../datapool/PoolReadGuard.h"
InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId, InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId,
uint32_t messageQueueDepth): SystemObject(setObjectId), uint32_t messageQueueDepth): SystemObject(setObjectId),
commandQueue(QueueFactory::instance()-> commandQueue(QueueFactory::instance()->
createMessageQueue(messageQueueDepth)), createMessageQueue(messageQueueDepth)),
poolManager(this, commandQueue), poolManager(this, commandQueue),
internalErrorSid(setObjectId, InternalErrorDataset::ERROR_SET_ID), internalErrorSid(setObjectId, InternalErrorDataset::ERROR_SET_ID),
internalErrorDataset(this) { internalErrorDataset(this) {
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
} }
InternalErrorReporter::~InternalErrorReporter() { InternalErrorReporter::~InternalErrorReporter() {
MutexFactory::instance()->deleteMutex(mutex); MutexFactory::instance()->deleteMutex(mutex);
} }
void InternalErrorReporter::setDiagnosticPrintout(bool enable) { void InternalErrorReporter::setDiagnosticPrintout(bool enable) {
@ -23,126 +24,127 @@ void InternalErrorReporter::setDiagnosticPrintout(bool enable) {
} }
ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) { ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) {
internalErrorDataset.read(timeoutType, timeoutMs); CommandMessage message;
ReturnValue_t result = commandQueue->receiveMessage(&message);
if(result != MessageQueueIF::EMPTY) {
poolManager.handleHousekeepingMessage(&message);
}
uint32_t newQueueHits = getAndResetQueueHits(); uint32_t newQueueHits = getAndResetQueueHits();
uint32_t newTmHits = getAndResetTmHits(); uint32_t newTmHits = getAndResetTmHits();
uint32_t newStoreHits = getAndResetStoreHits(); uint32_t newStoreHits = getAndResetStoreHits();
#if FSFW_VERBOSE_LEVEL == 1 #if FSFW_VERBOSE_LEVEL >= 1
if(diagnosticPrintout) { if(diagnosticPrintout) {
if((newQueueHits > 0) or (newTmHits > 0) or (newStoreHits > 0)) { if((newQueueHits > 0) or (newTmHits > 0) or (newStoreHits > 0)) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "InternalErrorReporter::performOperation: Errors " sif::debug << "InternalErrorReporter::performOperation: Errors "
<< "occured!" << std::endl; << "occured!" << std::endl;
sif::debug << "Queue errors: " << newQueueHits << std::endl; sif::debug << "Queue errors: " << newQueueHits << std::endl;
sif::debug << "TM errors: " << newTmHits << std::endl; sif::debug << "TM errors: " << newTmHits << std::endl;
sif::debug << "Store errors: " << newStoreHits << std::endl; sif::debug << "Store errors: " << newStoreHits << std::endl;
#else #else
sif::printDebug("InternalErrorReporter::performOperation: Errors occured!\n"); sif::printDebug("InternalErrorReporter::performOperation: Errors occured!\n");
sif::printDebug("Queue errors: %lu\n", static_cast<unsigned int>(newQueueHits)); sif::printDebug("Queue errors: %lu\n", static_cast<unsigned int>(newQueueHits));
sif::printDebug("TM errors: %lu\n", static_cast<unsigned int>(newTmHits)); sif::printDebug("TM errors: %lu\n", static_cast<unsigned int>(newTmHits));
sif::printDebug("Store errors: %lu\n", static_cast<unsigned int>(newStoreHits)); sif::printDebug("Store errors: %lu\n", static_cast<unsigned int>(newStoreHits));
#endif #endif
} }
} }
#endif #endif
internalErrorDataset.queueHits.value += newQueueHits; PoolReadGuard readGuard(&internalErrorDataset);
internalErrorDataset.storeHits.value += newStoreHits; internalErrorDataset.read(timeoutType, timeoutMs);
internalErrorDataset.tmHits.value += newTmHits; if(readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
internalErrorDataset.setValidity(true, true); internalErrorDataset.queueHits.value += newQueueHits;
internalErrorDataset.commit(timeoutType, timeoutMs); internalErrorDataset.storeHits.value += newStoreHits;
internalErrorDataset.tmHits.value += newTmHits;
internalErrorDataset.setValidity(true, true);
}
poolManager.performHkOperation(); poolManager.performHkOperation();
return HasReturnvaluesIF::RETURN_OK;
CommandMessage message;
ReturnValue_t result = commandQueue->receiveMessage(&message);
if(result != MessageQueueIF::EMPTY) {
poolManager.handleHousekeepingMessage(&message);
}
return HasReturnvaluesIF::RETURN_OK;
} }
void InternalErrorReporter::queueMessageNotSent() { void InternalErrorReporter::queueMessageNotSent() {
incrementQueueHits(); incrementQueueHits();
} }
void InternalErrorReporter::lostTm() { void InternalErrorReporter::lostTm() {
incrementTmHits(); incrementTmHits();
} }
uint32_t InternalErrorReporter::getAndResetQueueHits() { uint32_t InternalErrorReporter::getAndResetQueueHits() {
uint32_t value; uint32_t value;
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
value = queueHits; value = queueHits;
queueHits = 0; queueHits = 0;
mutex->unlockMutex(); mutex->unlockMutex();
return value; return value;
} }
uint32_t InternalErrorReporter::getQueueHits() { uint32_t InternalErrorReporter::getQueueHits() {
uint32_t value; uint32_t value;
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
value = queueHits; value = queueHits;
mutex->unlockMutex(); mutex->unlockMutex();
return value; return value;
} }
void InternalErrorReporter::incrementQueueHits() { void InternalErrorReporter::incrementQueueHits() {
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
queueHits++; queueHits++;
mutex->unlockMutex(); mutex->unlockMutex();
} }
uint32_t InternalErrorReporter::getAndResetTmHits() { uint32_t InternalErrorReporter::getAndResetTmHits() {
uint32_t value; uint32_t value;
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
value = tmHits; value = tmHits;
tmHits = 0; tmHits = 0;
mutex->unlockMutex(); mutex->unlockMutex();
return value; return value;
} }
uint32_t InternalErrorReporter::getTmHits() { uint32_t InternalErrorReporter::getTmHits() {
uint32_t value; uint32_t value;
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
value = tmHits; value = tmHits;
mutex->unlockMutex(); mutex->unlockMutex();
return value; return value;
} }
void InternalErrorReporter::incrementTmHits() { void InternalErrorReporter::incrementTmHits() {
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
tmHits++; tmHits++;
mutex->unlockMutex(); mutex->unlockMutex();
} }
void InternalErrorReporter::storeFull() { void InternalErrorReporter::storeFull() {
incrementStoreHits(); incrementStoreHits();
} }
uint32_t InternalErrorReporter::getAndResetStoreHits() { uint32_t InternalErrorReporter::getAndResetStoreHits() {
uint32_t value; uint32_t value;
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
value = storeHits; value = storeHits;
storeHits = 0; storeHits = 0;
mutex->unlockMutex(); mutex->unlockMutex();
return value; return value;
} }
uint32_t InternalErrorReporter::getStoreHits() { uint32_t InternalErrorReporter::getStoreHits() {
uint32_t value; uint32_t value;
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
value = storeHits; value = storeHits;
mutex->unlockMutex(); mutex->unlockMutex();
return value; return value;
} }
void InternalErrorReporter::incrementStoreHits() { void InternalErrorReporter::incrementStoreHits() {
mutex->lockMutex(timeoutType, timeoutMs); mutex->lockMutex(timeoutType, timeoutMs);
storeHits++; storeHits++;
mutex->unlockMutex(); mutex->unlockMutex();
} }
object_id_t InternalErrorReporter::getObjectId() const { object_id_t InternalErrorReporter::getObjectId() const {
@ -155,14 +157,11 @@ MessageQueueId_t InternalErrorReporter::getCommandQueue() const {
ReturnValue_t InternalErrorReporter::initializeLocalDataPool( ReturnValue_t InternalErrorReporter::initializeLocalDataPool(
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) { localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(errorPoolIds::TM_HITS, localDataPoolMap.emplace(errorPoolIds::TM_HITS, new PoolEntry<uint32_t>());
new PoolEntry<uint32_t>()); localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, new PoolEntry<uint32_t>());
localDataPoolMap.emplace(errorPoolIds::QUEUE_HITS, localDataPoolMap.emplace(errorPoolIds::STORE_HITS, new PoolEntry<uint32_t>());
new PoolEntry<uint32_t>()); poolManager.subscribeForPeriodicPacket(internalErrorSid, false, getPeriodicOperationFrequency(),
localDataPoolMap.emplace(errorPoolIds::STORE_HITS, true);
new PoolEntry<uint32_t>());
poolManager.subscribeForPeriodicPacket(internalErrorSid, false,
getPeriodicOperationFrequency(), true);
internalErrorDataset.setValidity(true, true); internalErrorDataset.setValidity(true, true);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -192,9 +191,9 @@ ReturnValue_t InternalErrorReporter::initializeAfterTaskCreation() {
} }
void InternalErrorReporter::setMutexTimeout(MutexIF::TimeoutType timeoutType, void InternalErrorReporter::setMutexTimeout(MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs) { uint32_t timeoutMs) {
this->timeoutType = timeoutType; this->timeoutType = timeoutType;
this->timeoutMs = timeoutMs; this->timeoutMs = timeoutMs;
} }
LocalDataPoolManager* InternalErrorReporter::getHkManagerHandle() { LocalDataPoolManager* InternalErrorReporter::getHkManagerHandle() {

View File

@ -17,77 +17,78 @@
* All functions were kept virtual so this class can be extended easily * All functions were kept virtual so this class can be extended easily
* to store custom internal errors (e.g. communication interface errors). * to store custom internal errors (e.g. communication interface errors).
*/ */
class InternalErrorReporter: public SystemObject, class InternalErrorReporter:
public ExecutableObjectIF, public SystemObject,
public InternalErrorReporterIF, public ExecutableObjectIF,
public HasLocalDataPoolIF { public InternalErrorReporterIF,
public HasLocalDataPoolIF {
public: public:
InternalErrorReporter(object_id_t setObjectId, InternalErrorReporter(object_id_t setObjectId,
uint32_t messageQueueDepth = 5); uint32_t messageQueueDepth = 5);
/** /**
* Enable diagnostic printout. Please note that this feature will * Enable diagnostic printout. Please note that this feature will
* only work if DEBUG has been supplied to the build defines. * only work if DEBUG has been supplied to the build defines.
* @param enable * @param enable
*/ */
void setDiagnosticPrintout(bool enable); void setDiagnosticPrintout(bool enable);
void setMutexTimeout(MutexIF::TimeoutType timeoutType, void setMutexTimeout(MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs); uint32_t timeoutMs);
virtual ~InternalErrorReporter(); virtual ~InternalErrorReporter();
virtual object_id_t getObjectId() const override; virtual object_id_t getObjectId() const override;
virtual MessageQueueId_t getCommandQueue() const override; virtual MessageQueueId_t getCommandQueue() const override;
virtual ReturnValue_t initializeLocalDataPool( virtual ReturnValue_t initializeLocalDataPool(
localpool::DataPool& localDataPoolMap, localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override; LocalDataPoolManager& poolManager) override;
virtual dur_millis_t getPeriodicOperationFrequency() const override; virtual dur_millis_t getPeriodicOperationFrequency() const override;
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override;
LocalDataPoolManager* getHkManagerHandle() override; LocalDataPoolManager* getHkManagerHandle() override;
virtual ReturnValue_t initialize() override; virtual ReturnValue_t initialize() override;
virtual ReturnValue_t initializeAfterTaskCreation() override; virtual ReturnValue_t initializeAfterTaskCreation() override;
virtual ReturnValue_t performOperation(uint8_t opCode) override; virtual ReturnValue_t performOperation(uint8_t opCode) override;
virtual void queueMessageNotSent(); virtual void queueMessageNotSent();
virtual void lostTm(); virtual void lostTm();
virtual void storeFull(); virtual void storeFull();
virtual void setTaskIF(PeriodicTaskIF* task) override; virtual void setTaskIF(PeriodicTaskIF* task) override;
protected: protected:
MessageQueueIF* commandQueue; MessageQueueIF* commandQueue;
LocalDataPoolManager poolManager; LocalDataPoolManager poolManager;
PeriodicTaskIF* executingTask = nullptr; PeriodicTaskIF* executingTask = nullptr;
MutexIF* mutex = nullptr; MutexIF* mutex = nullptr;
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
uint32_t timeoutMs = 20; uint32_t timeoutMs = 20;
sid_t internalErrorSid; sid_t internalErrorSid;
InternalErrorDataset internalErrorDataset; InternalErrorDataset internalErrorDataset;
bool diagnosticPrintout = true; bool diagnosticPrintout = true;
uint32_t queueHits = 0; uint32_t queueHits = 0;
uint32_t tmHits = 0; uint32_t tmHits = 0;
uint32_t storeHits = 0; uint32_t storeHits = 0;
uint32_t getAndResetQueueHits(); uint32_t getAndResetQueueHits();
uint32_t getQueueHits(); uint32_t getQueueHits();
void incrementQueueHits(); void incrementQueueHits();
uint32_t getAndResetTmHits(); uint32_t getAndResetTmHits();
uint32_t getTmHits(); uint32_t getTmHits();
void incrementTmHits(); void incrementTmHits();
uint32_t getAndResetStoreHits(); uint32_t getAndResetStoreHits();
uint32_t getStoreHits(); uint32_t getStoreHits();
void incrementStoreHits(); void incrementStoreHits();
}; };