1
0
forked from fsfw/fsfw

hk continued

This commit is contained in:
2020-06-19 03:03:17 +02:00
parent 583efec3f8
commit 84b8d733c0
8 changed files with 186 additions and 56 deletions

View File

@ -1,16 +1,17 @@
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/LocalDataSet.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/objectmanager/frameworkObjects.h>
#include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h>
#include <framework/ipc/QueueFactory.h>
#include <array>
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner) {
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner,
uint32_t replyQueueDepth, bool appendValidityBuffer):
appendValidityBuffer(appendValidityBuffer) {
if(owner == nullptr) {
sif::error << "HkManager: Invalid supplied owner!" << std::endl;
std::exit(0);
return;
}
this->owner = owner;
mutex = MutexFactory::instance()->createMutex();
@ -23,6 +24,8 @@ LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
"Could not set IPC store." << std::endl;
}
hkQueue = QueueFactory::instance()->createMessageQueue(replyQueueDepth,
HousekeepingMessage::HK_MESSAGE_SIZE);
}
LocalDataPoolManager::~LocalDataPoolManager() {}
@ -36,13 +39,21 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
}
return result;
}
sif::warning << "HousekeepingManager: The map" << std::endl;
sif::warning << "HousekeepingManager: The map should only be initialized "
"once!" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
HousekeepingMessage& message) {
return HasReturnvaluesIF::RETURN_FAILED;
Command_t command = message.getCommand();
switch(command) {
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT):
return generateHousekeepingPacket(message.getSid());
default:
return CommandMessageIF::UNKNOWN_COMMAND;
}
}
ReturnValue_t LocalDataPoolManager::printPoolEntry(
@ -51,7 +62,7 @@ ReturnValue_t LocalDataPoolManager::printPoolEntry(
if (poolIter == localDpMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl;
return OwnsLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
return POOL_ENTRY_NOT_FOUND;
}
poolIter->second->print();
return HasReturnvaluesIF::RETURN_OK;
@ -61,6 +72,15 @@ MutexIF* LocalDataPoolManager::getMutexHandle() {
return mutex;
}
void LocalDataPoolManager::setHkPacketDestination(
MessageQueueId_t destinationQueueId) {
this->currentHkPacketDestination = destinationQueueId;
}
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner;
}
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>(
owner->getDataSetHandle(sid));
@ -70,28 +90,56 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
return HasReturnvaluesIF::RETURN_FAILED;
}
store_address_t storeId;
size_t hkSize = dataSetToSerialize->getSerializedSize();
uint8_t* storePtr = nullptr;
ReturnValue_t result = ipcStore->getFreeElement(&storeId, hkSize,&storePtr);
ReturnValue_t result = serializeHkPacketIntoStore(&storeId,
dataSetToSerialize);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket: "
"Could not get free element from IPC store." << std::endl;
return result;
}
size_t size = 0;
dataSetToSerialize->serialize(&storePtr, &size, hkSize, false);
// and now we have to set a HK message and send it the queue.
return HasReturnvaluesIF::RETURN_OK;
// and now we set a HK message and send it the HK packet destination.
MessageQueueMessage message;
HousekeepingMessage hkMessage(&message);
hkMessage.setHkReportMessage(sid, storeId);
if(hkQueue == nullptr) {
return QUEUE_NOT_SET;
}
if(currentHkPacketDestination != MessageQueueIF::NO_QUEUE) {
result = hkQueue->sendMessage(currentHkPacketDestination, &hkMessage);
}
else {
result = hkQueue->sendToDefault(&hkMessage);
}
return result;
}
void LocalDataPoolManager::setHkPacketQueue(MessageQueueIF *msgQueue) {
this->hkPacketQueue = msgQueue;
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
store_address_t *storeId, LocalDataSet* dataSet) {
size_t hkSize = dataSet->getSerializedSize();
uint8_t* storePtr = nullptr;
ReturnValue_t result = ipcStore->getFreeElement(storeId, hkSize,&storePtr);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket: "
"Could not get free element from IPC store." << std::endl;
return result;
}
size_t size = 0;
if(appendValidityBuffer) {
result = dataSet->serializeWithValidityBuffer(&storePtr,
&size, hkSize, false);
}
else {
result = dataSet->serialize(&storePtr, &size, hkSize, false);
}
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "HousekeepingManager::serializeHkPacketIntoStore: "
"Serialization proccess failed!" << std::endl;
}
return result;
}
void LocalDataPoolManager::setHkReplyQueue(MessageQueueIF *replyQueue) {
this->hkReplyQueue = replyQueue;
}
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner;
}