fsfw/datapoollocal/LocalDataPoolManager.cpp

219 lines
7.6 KiB
C++
Raw Normal View History

2020-06-07 02:22:18 +02:00
#include <framework/datapoollocal/LocalDataPoolManager.h>
2020-07-14 15:45:03 +02:00
#include <framework/datapoollocal/LocalPoolDataSetBase.h>
2020-06-30 21:22:26 +02:00
#include <framework/housekeeping/AcceptsHkPacketsIF.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-07-09 00:59:10 +02:00
LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner,
2020-06-30 21:22:26 +02:00
MessageQueueIF* queueToUse, bool appendValidityBuffer):
2020-06-19 03:03:17 +02:00
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-30 21:22:26 +02:00
hkQueue = queueToUse;
}
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse,
object_id_t hkDestination) {
if(queueToUse == nullptr) {
sif::error << "LocalDataPoolManager::initialize: Supplied queue "
"invalid!" << std::endl;
}
hkQueue = queueToUse;
if(hkDestination == objects::NO_OBJECT) {
return initializeHousekeepingPoolEntriesOnce();
}
AcceptsHkPacketsIF* hkReceiver =
objectManager->get<AcceptsHkPacketsIF>(hkDestination);
if(hkReceiver != nullptr) {
setHkPacketDestination(hkReceiver->getHkQueue());
}
else {
sif::warning << "LocalDataPoolManager::initialize: Could not retrieve"
2020-07-01 14:34:16 +02:00
" queue ID from HK destination object ID. " << std::flush;
sif::warning << "Make sure it exists and the object impements "
"AcceptsHkPacketsIF!" << std::endl;
2020-06-30 21:22:26 +02:00
}
return initializeHousekeepingPoolEntriesOnce();
}
void LocalDataPoolManager::setHkPacketDestination(
MessageQueueId_t hkDestination) {
this->hkDestination = hkDestination;
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-07-09 00:59:10 +02:00
ReturnValue_t result = owner->initializePoolEntries(localPoolMap);
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(
CommandMessage* message) {
Command_t command = message->getCommand();
2020-06-19 03:03:17 +02:00
switch(command) {
// I think those are the only commands which can be handled here..
case(HousekeepingMessage::ADD_HK_REPORT_STRUCT):
case(HousekeepingMessage::ADD_DIAGNOSTICS_REPORT_STRUCT):
// We should use OwnsLocalPoolDataIF to specify those functions..
return HasReturnvaluesIF::RETURN_OK;
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES):
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES):
//return generateSetStructurePacket(message->getSid());
2020-06-19 03:03:17 +02:00
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT):
//return generateHousekeepingPacket(message->getSid());
2020-06-19 03:03:17 +02:00
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) {
2020-07-09 00:59:10 +02:00
auto poolIter = localPoolMap.find(localPoolId);
if (poolIter == localPoolMap.end()) {
2020-06-05 20:35:08 +02:00
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-07-09 00:59:10 +02:00
const HasLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
2020-06-19 03:03:17 +02:00
return owner;
}
2020-06-30 21:22:26 +02:00
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
MessageQueueId_t sendTo) {
2020-07-14 15:45:03 +02:00
LocalDataSetBase* dataSetToSerialize = dynamic_cast<LocalDataSetBase*>(
2020-06-05 20:35:08 +02:00
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.
2020-06-29 15:46:16 +02:00
CommandMessage hkMessage;
HousekeepingMessage::setHkReportMessage(&hkMessage, sid, storeId);
if(hkQueue == nullptr) {
2020-06-30 21:22:26 +02:00
return QUEUE_OR_DESTINATION_NOT_SET;
2020-06-29 15:46:16 +02:00
}
2020-06-30 21:22:26 +02:00
if(sendTo != MessageQueueIF::NO_QUEUE) {
result = hkQueue->sendMessage(sendTo, &hkMessage);
2020-06-29 15:46:16 +02:00
}
else {
2020-06-30 21:22:26 +02:00
if(hkDestination == MessageQueueIF::NO_QUEUE) {
sif::warning << "LocalDataPoolManager::generateHousekeepingPacket:"
" Destination is not set properly!" << std::endl;
return QUEUE_OR_DESTINATION_NOT_SET;
}
else {
result = hkQueue->sendMessage(hkDestination, &hkMessage);
}
2020-06-29 15:46:16 +02:00
}
2020-06-19 03:03:17 +02:00
return result;
2020-06-07 18:53:55 +02:00
}
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid) {
2020-07-14 15:45:03 +02:00
LocalDataSetBase* dataSet = dynamic_cast<LocalDataSetBase*>(
owner->getDataSetHandle(sid));
if(dataSet == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
" Set ID not found" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
size_t expectedSize = dataSet->getFillCount() * sizeof(lp_id_t);
uint8_t* storePtr = nullptr;
store_address_t storeId;
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
expectedSize,&storePtr);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "HousekeepingManager::generateHousekeepingPacket: "
"Could not get free element from IPC store." << std::endl;
return result;
}
size_t size = 0;
result = dataSet->serializeLocalPoolIds(&storePtr, &size,
2020-07-01 14:17:55 +02:00
expectedSize, SerializeIF::Endianness::BIG);
if(expectedSize != size) {
sif::error << "HousekeepingManager::generateSetStructurePacket: "
"Expected size is not equal to serialized size" << std::endl;
}
return result;
}
2020-06-30 21:22:26 +02:00
void LocalDataPoolManager::setMinimalSamplingFrequency(float frequencySeconds) {
}
2020-06-19 03:03:17 +02:00
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
2020-07-14 15:45:03 +02:00
store_address_t *storeId, LocalDataSetBase* dataSet) {
2020-06-19 03:03:17 +02:00
size_t hkSize = dataSet->getSerializedSize();
uint8_t* storePtr = nullptr;
ReturnValue_t result = ipcStore->getFreeElement(storeId, hkSize,&storePtr);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "HousekeepingManager::generateHousekeepingPacket: "
2020-06-19 03:03:17 +02:00
"Could not get free element from IPC store." << std::endl;
return result;
}
size_t size = 0;
if(appendValidityBuffer) {
result = dataSet->serializeWithValidityBuffer(&storePtr,
2020-07-01 14:17:55 +02:00
&size, hkSize, SerializeIF::Endianness::MACHINE);
2020-06-19 03:03:17 +02:00
}
else {
2020-07-01 14:17:55 +02:00
result = dataSet->serialize(&storePtr, &size, hkSize,
SerializeIF::Endianness::MACHINE);
2020-06-19 03:03:17 +02:00
}
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
2020-07-09 00:59:10 +02:00
ReturnValue_t LocalDataPoolManager::performHkOperation() {
return HasReturnvaluesIF::RETURN_OK;
}