fsfw/datapoollocal/LocalDataPoolManager.cpp

146 lines
4.6 KiB
C++
Raw Normal View History

2020-06-07 02:22:18 +02:00
#include <framework/datapoollocal/LocalDataPoolManager.h>
2020-06-05 20:35:08 +02:00
#include <framework/datapoollocal/LocalDataSet.h>
2020-05-17 01:17:11 +02:00
#include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h>
2020-06-19 03:03:17 +02:00
#include <framework/ipc/QueueFactory.h>
2020-05-17 01:17:11 +02:00
2020-06-05 20:35:08 +02:00
#include <array>
2020-06-19 03:03:17 +02:00
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner,
uint32_t replyQueueDepth, bool appendValidityBuffer):
appendValidityBuffer(appendValidityBuffer) {
2020-05-17 01:17:11 +02:00
if(owner == nullptr) {
sif::error << "HkManager: Invalid supplied owner!" << std::endl;
2020-06-19 03:03:17 +02:00
return;
2020-05-17 01:17:11 +02:00
}
this->owner = owner;
mutex = MutexFactory::instance()->createMutex();
2020-06-07 18:53:55 +02:00
if(mutex == nullptr) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
"Could not create mutex." << std::endl;
}
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
if(ipcStore == nullptr) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
"Could not set IPC store." << std::endl;
}
2020-06-19 03:03:17 +02:00
hkQueue = QueueFactory::instance()->createMessageQueue(replyQueueDepth,
HousekeepingMessage::HK_MESSAGE_SIZE);
2020-05-17 01:17:11 +02:00
}
2020-06-07 02:22:18 +02:00
LocalDataPoolManager::~LocalDataPoolManager() {}
2020-05-17 01:17:11 +02:00
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
2020-05-17 01:17:11 +02:00
if(not mapInitialized) {
2020-06-07 02:22:18 +02:00
ReturnValue_t result =
owner->initializeHousekeepingPoolEntries(localDpMap);
2020-05-17 01:17:11 +02:00
if(result == HasReturnvaluesIF::RETURN_OK) {
mapInitialized = true;
}
return result;
}
2020-06-19 03:03:17 +02:00
sif::warning << "HousekeepingManager: The map should only be initialized "
"once!" << std::endl;
2020-05-17 01:17:11 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
HousekeepingMessage& message) {
2020-06-19 03:03:17 +02:00
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;
}
2020-05-17 01:17:11 +02:00
}
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::printPoolEntry(
2020-06-05 20:35:08 +02:00
lp_id_t localPoolId) {
auto poolIter = localDpMap.find(localPoolId);
if (poolIter == localDpMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl;
2020-06-19 03:03:17 +02:00
return POOL_ENTRY_NOT_FOUND;
2020-06-05 20:35:08 +02:00
}
poolIter->second->print();
return HasReturnvaluesIF::RETURN_OK;
}
2020-06-07 02:22:18 +02:00
MutexIF* LocalDataPoolManager::getMutexHandle() {
2020-05-17 01:17:11 +02:00
return mutex;
}
2020-06-19 03:03:17 +02:00
void LocalDataPoolManager::setHkPacketDestination(
MessageQueueId_t destinationQueueId) {
this->currentHkPacketDestination = destinationQueueId;
}
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner;
}
2020-06-07 18:53:55 +02:00
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
2020-06-05 20:35:08 +02:00
LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>(
owner->getDataSetHandle(sid));
if(dataSetToSerialize == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
" Set ID not found" << std::endl;
2020-06-07 18:53:55 +02:00
return HasReturnvaluesIF::RETURN_FAILED;
}
store_address_t storeId;
2020-06-19 03:03:17 +02:00
ReturnValue_t result = serializeHkPacketIntoStore(&storeId,
dataSetToSerialize);
2020-06-07 18:53:55 +02:00
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
2020-06-05 20:35:08 +02:00
}
2020-05-17 01:17:11 +02:00
2020-06-19 03:03:17 +02:00
// 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;
}
2020-06-05 20:35:08 +02:00
2020-06-19 03:03:17 +02:00
if(currentHkPacketDestination != MessageQueueIF::NO_QUEUE) {
result = hkQueue->sendMessage(currentHkPacketDestination, &hkMessage);
}
else {
result = hkQueue->sendToDefault(&hkMessage);
}
return result;
2020-06-07 18:53:55 +02:00
}
2020-06-19 03:03:17 +02:00
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;
2020-06-05 20:35:08 +02:00
}
2020-06-19 03:03:17 +02:00