fsfw/datapoollocal/LocalDataPoolManager.cpp

670 lines
22 KiB
C++
Raw Normal View History

2020-09-06 14:57:05 +02:00
#include "LocalDataPoolManager.h"
2020-10-14 01:38:27 +02:00
#include "LocalPoolObjectBase.h"
2020-09-06 14:57:05 +02:00
#include "LocalPoolDataSetBase.h"
2020-09-26 15:28:28 +02:00
#include "../housekeeping/HousekeepingSetPacket.h"
#include "../housekeeping/AcceptsHkPacketsIF.h"
#include "../ipc/MutexFactory.h"
#include "../ipc/MutexHelper.h"
#include "../ipc/QueueFactory.h"
2020-09-29 13:54:08 +02:00
#include "../objectmanager/frameworkObjects.h"
2020-05-17 01:17:11 +02:00
2020-06-05 20:35:08 +02:00
#include <array>
2020-08-08 19:43:28 +02:00
#include <cmath>
2020-06-05 20:35:08 +02:00
2020-09-29 13:54:08 +02:00
object_id_t LocalDataPoolManager::defaultHkDestination =
objects::PUS_SERVICE_3_HOUSEKEEPING;
2020-08-23 21:00:25 +02:00
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-09-28 16:56:42 +02:00
if(owner == nullptr) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
<< "Invalid supplied owner!" << std::endl;
return;
}
this->owner = owner;
mutex = MutexFactory::instance()->createMutex();
if(mutex == nullptr) {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
<< "Could not create mutex." << std::endl;
}
2020-08-24 22:08:27 +02:00
2020-09-28 16:56:42 +02:00
hkQueue = queueToUse;
2020-06-30 21:22:26 +02:00
}
2020-08-23 23:24:48 +02:00
LocalDataPoolManager::~LocalDataPoolManager() {}
2020-08-24 22:08:27 +02:00
ReturnValue_t LocalDataPoolManager::initialize(MessageQueueIF* queueToUse) {
2020-06-30 21:22:26 +02:00
if(queueToUse == nullptr) {
2020-09-28 16:56:42 +02:00
sif::error << "LocalDataPoolManager::initialize: "
<< std::hex << "0x" << owner->getObjectId() << ". Supplied "
<< "queue invalid!" << std::dec << std::endl;
2020-06-30 21:22:26 +02:00
}
hkQueue = queueToUse;
2020-09-28 16:56:42 +02:00
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
if(ipcStore == nullptr) {
sif::error << "LocalDataPoolManager::initialize: "
<< std::hex << "0x" << owner->getObjectId() << ": Could not "
<< "set IPC store." <<std::dec << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
if(defaultHkDestination != objects::NO_OBJECT) {
AcceptsHkPacketsIF* hkPacketReceiver =
objectManager->get<AcceptsHkPacketsIF>(defaultHkDestination);
if(hkPacketReceiver != nullptr) {
hkDestinationId = hkPacketReceiver->getHkQueue();
}
else {
sif::error << "LocalDataPoolManager::LocalDataPoolManager: "
<< "Default HK destination object is invalid!" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
}
2020-08-24 22:08:27 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t LocalDataPoolManager::initializeAfterTaskCreation(
uint8_t nonDiagInvlFactor) {
2020-08-08 19:43:28 +02:00
setNonDiagnosticIntervalFactor(nonDiagInvlFactor);
2020-06-30 21:22:26 +02:00
return initializeHousekeepingPoolEntriesOnce();
}
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
2020-05-17 01:17:11 +02:00
if(not mapInitialized) {
2020-08-24 22:08:27 +02:00
ReturnValue_t result = owner->initializeLocalDataPool(localPoolMap,
*this);
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 "
2020-09-28 22:17:18 +02:00
<< "once!" << std::endl;
2020-05-17 01:17:11 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
2020-08-23 23:24:48 +02:00
ReturnValue_t LocalDataPoolManager::performHkOperation() {
2020-10-14 01:25:15 +02:00
ReturnValue_t status = HasReturnvaluesIF::RETURN_OK;
2020-09-19 15:58:34 +02:00
for(auto& receiver: hkReceiversMap) {
switch(receiver.reportingType) {
2020-08-23 23:24:48 +02:00
case(ReportingType::PERIODIC): {
2020-09-19 15:58:34 +02:00
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
2020-08-23 23:24:48 +02:00
// Periodic packets shall only be generated from datasets.
continue;
}
performPeriodicHkGeneration(receiver);
break;
}
2020-10-14 01:25:15 +02:00
case(ReportingType::UPDATE_HK): {
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
2020-10-14 01:38:27 +02:00
// Update packets shall only be generated from datasets.
2020-10-14 01:25:15 +02:00
continue;
}
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
receiver.dataId.sid);
if(dataSet->hasChanged()) {
// prepare and send update notification
ReturnValue_t result = generateHousekeepingPacket(
receiver.dataId.sid, dataSet, true);
if(result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
}
2020-10-14 12:42:30 +02:00
handleChangeResetLogic(receiver.dataType, receiver.dataId,
dataSet);
2020-10-14 01:25:15 +02:00
break;
}
case(ReportingType::UPDATE_NOTIFICATION): {
2020-10-14 12:42:30 +02:00
MarkChangedIF* toReset = nullptr;
2020-10-14 01:25:15 +02:00
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
2020-10-14 01:38:27 +02:00
LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(
receiver.dataId.localPoolId);
if(poolObj == nullptr) {
continue;
}
if(poolObj->hasChanged()) {
// prepare and send update notification.
2020-10-14 19:52:06 +02:00
toReset = poolObj;
2020-10-14 01:38:27 +02:00
}
2020-10-14 19:52:06 +02:00
2020-10-14 01:25:15 +02:00
}
else {
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
receiver.dataId.sid);
2020-10-14 01:38:27 +02:00
if(dataSet == nullptr) {
continue;
}
2020-10-14 01:25:15 +02:00
if(dataSet->hasChanged()) {
// prepare and send update notification
2020-10-14 19:52:06 +02:00
CommandMessage notification;
HousekeepingMessage::setUpdateNotificationSetCommand(
&notification, receiver.dataId.sid);
ReturnValue_t result = hkQueue->sendMessage(
receiver.destinationQueue, &notification);
if(result != HasReturnvaluesIF::RETURN_OK) {
status = result;
}
toReset = dataSet;
2020-10-14 01:25:15 +02:00
}
}
2020-10-14 19:52:06 +02:00
if(toReset != nullptr) {
handleChangeResetLogic(receiver.dataType,
receiver.dataId, toReset);
}
2020-10-14 01:25:15 +02:00
break;
}
2020-08-23 23:24:48 +02:00
case(ReportingType::UPDATE_SNAPSHOT): {
2020-10-14 12:42:30 +02:00
MarkChangedIF* toReset = nullptr;
2020-08-23 23:24:48 +02:00
// check whether data has changed and send messages in case it has.
2020-10-14 01:25:15 +02:00
if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) {
2020-10-14 01:38:27 +02:00
LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(
receiver.dataId.localPoolId);
if(poolObj == nullptr) {
continue;
}
if(poolObj->hasChanged()) {
// prepare and send update snapshot.
2020-10-14 19:52:06 +02:00
toReset = poolObj;
2020-10-14 01:38:27 +02:00
}
2020-10-14 01:25:15 +02:00
}
else {
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
receiver.dataId.sid);
2020-10-14 01:38:27 +02:00
if(dataSet == nullptr) {
continue;
}
2020-10-14 01:25:15 +02:00
if(dataSet->hasChanged()) {
// prepare and send update snapshot.
2020-10-14 19:52:06 +02:00
toReset = dataSet;
2020-10-14 01:25:15 +02:00
}
}
2020-10-14 19:52:06 +02:00
if(toReset != nullptr) {
handleChangeResetLogic(receiver.dataType,
receiver.dataId, toReset);
}
2020-08-23 23:24:48 +02:00
break;
}
default:
// This should never happen.
return HasReturnvaluesIF::RETURN_FAILED;
}
}
2020-10-14 12:42:30 +02:00
resetHkUpdateResetHelper();
2020-10-14 01:25:15 +02:00
return status;
2020-08-23 23:24:48 +02:00
}
2020-10-14 12:42:30 +02:00
void LocalDataPoolManager::handleChangeResetLogic(
DataType type, DataId dataId, MarkChangedIF* toReset) {
if(hkUpdateResetList == nullptr) {
// config error!
return;
}
for(auto& changeInfo: *hkUpdateResetList) {
if(changeInfo.dataType != type) {
continue;
}
if((changeInfo.dataType == DataType::DATA_SET) and
(changeInfo.dataId.sid != dataId.sid)) {
continue;
}
if((changeInfo.dataType == DataType::LOCAL_POOL_VARIABLE) and
(changeInfo.dataId.localPoolId != dataId.localPoolId)) {
continue;
}
if(changeInfo.updateCounter <= 1) {
toReset->setChanged(false);
}
if(changeInfo.currentUpdateCounter == 0) {
toReset->setChanged(false);
}
else {
changeInfo.currentUpdateCounter--;
}
return;
}
}
void LocalDataPoolManager::resetHkUpdateResetHelper() {
if(hkUpdateResetList == nullptr) {
return;
}
for(auto& changeInfo: *hkUpdateResetList) {
changeInfo.currentUpdateCounter = changeInfo.updateCounter;
}
}
2020-08-23 23:24:48 +02:00
ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid,
bool enableReporting, float collectionInterval, bool isDiagnostics,
object_id_t packetDestination) {
AcceptsHkPacketsIF* hkReceiverObject =
objectManager->get<AcceptsHkPacketsIF>(packetDestination);
if(hkReceiverObject == nullptr) {
sif::error << "LocalDataPoolManager::subscribeForPeriodicPacket:"
2020-09-28 22:17:18 +02:00
<< " Invalid receiver!"<< std::endl;
2020-08-23 23:24:48 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
struct HkReceiver hkReceiver;
2020-09-19 15:58:34 +02:00
hkReceiver.dataId.sid = sid;
2020-08-23 23:24:48 +02:00
hkReceiver.reportingType = ReportingType::PERIODIC;
2020-10-14 12:42:30 +02:00
hkReceiver.dataType = DataType::DATA_SET;
2020-08-23 23:24:48 +02:00
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
2020-09-19 01:17:43 +02:00
2020-09-19 15:58:34 +02:00
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
2020-09-19 01:17:43 +02:00
if(dataSet != nullptr) {
dataSet->setReportingEnabled(enableReporting);
2020-09-19 15:58:34 +02:00
dataSet->setDiagnostic(isDiagnostics);
dataSet->initializePeriodicHelper(collectionInterval,
owner->getPeriodicOperationFrequency(), isDiagnostics);
2020-09-19 01:17:43 +02:00
}
2020-09-19 15:58:34 +02:00
hkReceiversMap.push_back(hkReceiver);
2020-08-23 23:24:48 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
2020-10-14 12:42:30 +02:00
ReturnValue_t LocalDataPoolManager::subscribeForUpdatePackets(sid_t sid,
bool isDiagnostics, bool reportingEnabled,
object_id_t packetDestination) {
AcceptsHkPacketsIF* hkReceiverObject =
objectManager->get<AcceptsHkPacketsIF>(packetDestination);
if(hkReceiverObject == nullptr) {
sif::error << "LocalDataPoolManager::subscribeForPeriodicPacket:"
<< " Invalid receiver!"<< std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
struct HkReceiver hkReceiver;
hkReceiver.dataId.sid = sid;
hkReceiver.reportingType = ReportingType::UPDATE_HK;
hkReceiver.dataType = DataType::DATA_SET;
hkReceiver.destinationQueue = hkReceiverObject->getHkQueue();
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
if(dataSet != nullptr) {
dataSet->setReportingEnabled(true);
dataSet->setDiagnostic(isDiagnostics);
}
hkReceiversMap.push_back(hkReceiver);
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
return HasReturnvaluesIF::RETURN_OK;
}
2020-10-14 16:46:00 +02:00
ReturnValue_t LocalDataPoolManager::subscribeForSetUpdateMessages(
const uint32_t setId, object_id_t destinationObject,
MessageQueueId_t targetQueueId, bool generateSnapshot) {
2020-10-14 12:42:30 +02:00
struct HkReceiver hkReceiver;
hkReceiver.dataType = DataType::DATA_SET;
2020-10-14 16:46:00 +02:00
hkReceiver.dataId.sid = sid_t(this->getOwner()->getObjectId(), setId);
2020-10-14 12:42:30 +02:00
hkReceiver.destinationQueue = targetQueueId;
hkReceiver.objectId = destinationObject;
2020-10-14 16:46:00 +02:00
if(generateSnapshot) {
hkReceiver.reportingType = ReportingType::UPDATE_SNAPSHOT;
}
else {
hkReceiver.reportingType = ReportingType::UPDATE_NOTIFICATION;
}
2020-10-14 12:42:30 +02:00
hkReceiversMap.push_back(hkReceiver);
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
return HasReturnvaluesIF::RETURN_OK;
}
2020-10-14 16:46:00 +02:00
ReturnValue_t LocalDataPoolManager::subscribeForVariableUpdateMessages(
const lp_id_t localPoolId, object_id_t destinationObject,
MessageQueueId_t targetQueueId, bool generateSnapshot) {
2020-10-14 12:42:30 +02:00
struct HkReceiver hkReceiver;
hkReceiver.dataType = DataType::LOCAL_POOL_VARIABLE;
hkReceiver.dataId.localPoolId = localPoolId;
hkReceiver.destinationQueue = targetQueueId;
hkReceiver.objectId = destinationObject;
2020-10-14 16:46:00 +02:00
if(generateSnapshot) {
hkReceiver.reportingType = ReportingType::UPDATE_SNAPSHOT;
}
else {
hkReceiver.reportingType = ReportingType::UPDATE_NOTIFICATION;
}
2020-10-14 12:42:30 +02:00
hkReceiversMap.push_back(hkReceiver);
handleHkUpdateResetListInsertion(hkReceiver.dataType, hkReceiver.dataId);
return HasReturnvaluesIF::RETURN_OK;
}
void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType,
DataId dataId) {
if(hkUpdateResetList == nullptr) {
hkUpdateResetList = new std::vector<struct HkUpdateResetHelper>();
}
for(auto& updateResetStruct: *hkUpdateResetList) {
if(dataType == DataType::DATA_SET) {
if(updateResetStruct.dataId.sid == dataId.sid) {
updateResetStruct.updateCounter++;
updateResetStruct.currentUpdateCounter++;
return;
}
}
else {
if(updateResetStruct.dataId.localPoolId == dataId.localPoolId) {
updateResetStruct.updateCounter++;
updateResetStruct.currentUpdateCounter++;
return;
}
}
}
HkUpdateResetHelper hkUpdateResetHelper;
hkUpdateResetHelper.currentUpdateCounter = 1;
hkUpdateResetHelper.updateCounter = 1;
hkUpdateResetHelper.dataType = dataType;
if(dataType == DataType::DATA_SET) {
hkUpdateResetHelper.dataId.sid = dataId.sid;
}
else {
hkUpdateResetHelper.dataId.localPoolId = dataId.localPoolId;
}
hkUpdateResetList->push_back(hkUpdateResetHelper);
}
2020-06-07 02:22:18 +02:00
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
CommandMessage* message) {
Command_t command = message->getCommand();
2020-09-19 01:17:43 +02:00
sid_t sid = HousekeepingMessage::getSid(message);
2020-09-19 17:08:08 +02:00
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
2020-06-19 03:03:17 +02:00
switch(command) {
2020-09-19 17:08:08 +02:00
case(HousekeepingMessage::ENABLE_PERIODIC_DIAGNOSTICS_GENERATION): {
result = togglePeriodicGeneration(sid, true, true);
break;
}
case(HousekeepingMessage::DISABLE_PERIODIC_DIAGNOSTICS_GENERATION): {
result = togglePeriodicGeneration(sid, false, true);
break;
}
case(HousekeepingMessage::ENABLE_PERIODIC_HK_REPORT_GENERATION): {
result = togglePeriodicGeneration(sid, true, false);
break;
}
case(HousekeepingMessage::DISABLE_PERIODIC_HK_REPORT_GENERATION): {
result = togglePeriodicGeneration(sid, false, false);
break;
}
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES):
2020-09-26 15:32:16 +02:00
return generateSetStructurePacket(sid, true);
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES):
2020-09-26 15:32:16 +02:00
return generateSetStructurePacket(sid, false);
2020-09-19 01:17:43 +02:00
case(HousekeepingMessage::MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL):
case(HousekeepingMessage::MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL): {
float newCollIntvl = 0;
HousekeepingMessage::getCollectionIntervalModificationCommand(message,
&newCollIntvl);
if(command == HousekeepingMessage::
MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL) {
2020-09-19 17:14:09 +02:00
result = changeCollectionInterval(sid, newCollIntvl, true);
2020-09-19 01:17:43 +02:00
}
else {
2020-09-19 17:14:09 +02:00
result = changeCollectionInterval(sid, newCollIntvl, false);
2020-09-19 01:17:43 +02:00
}
2020-09-19 17:14:09 +02:00
break;
2020-09-19 01:17:43 +02:00
}
2020-06-19 03:03:17 +02:00
case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT):
2020-09-19 01:17:43 +02:00
case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT): {
2020-09-19 15:58:34 +02:00
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
2020-09-19 01:17:43 +02:00
if(command == HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT
2020-09-19 15:58:34 +02:00
and dataSet->isDiagnostics()) {
2020-09-19 01:17:43 +02:00
return WRONG_HK_PACKET_TYPE;
}
else if(command == HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT
2020-09-19 15:58:34 +02:00
and not dataSet->isDiagnostics()) {
2020-09-19 01:17:43 +02:00
return WRONG_HK_PACKET_TYPE;
}
return generateHousekeepingPacket(HousekeepingMessage::getSid(message),
dataSet, true);
}
2020-10-14 19:52:06 +02:00
case(HousekeepingMessage::UPDATE_NOTIFICATION_SET): {
owner->handleChangedDatasetOrVariable(sid);
return HasReturnvaluesIF::RETURN_OK;
}
2020-06-19 03:03:17 +02:00
default:
return CommandMessageIF::UNKNOWN_COMMAND;
}
2020-09-19 17:08:08 +02:00
CommandMessage reply;
if(result != HasReturnvaluesIF::RETURN_OK) {
HousekeepingMessage::setHkRequestFailureReply(&reply, sid, result);
}
else {
HousekeepingMessage::setHkRequestSuccessReply(&reply, sid);
}
hkQueue->sendMessage(hkDestinationId, &reply);
return result;
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:"
2020-09-28 22:17:18 +02:00
<< " 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-09-28 21:09:56 +02:00
HasLocalDataPoolIF* LocalDataPoolManager::getOwner() {
2020-06-19 03:03:17 +02:00
return owner;
}
2020-08-24 22:08:27 +02:00
ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
2020-09-19 01:17:43 +02:00
LocalPoolDataSetBase* dataSet, bool forDownlink,
MessageQueueId_t destination) {
if(dataSet == nullptr) {
// Configuration error.
2020-06-05 20:35:08 +02:00
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
2020-09-28 22:17:18 +02:00
<< " Set ID not found or dataset not assigned!" << std::endl;
2020-06-07 18:53:55 +02:00
return HasReturnvaluesIF::RETURN_FAILED;
}
2020-09-06 14:57:05 +02:00
2020-08-24 22:08:27 +02:00
store_address_t storeId;
2020-09-19 01:17:43 +02:00
HousekeepingPacketDownlink hkPacket(sid, dataSet);
size_t serializedSize = 0;
ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, storeId,
forDownlink, &serializedSize);
if(result != HasReturnvaluesIF::RETURN_OK or serializedSize == 0) {
2020-08-24 22:08:27 +02:00
return result;
}
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-08-24 22:08:27 +02:00
CommandMessage hkMessage;
2020-09-19 15:58:34 +02:00
if(dataSet->isDiagnostics()) {
2020-09-14 18:01:48 +02:00
HousekeepingMessage::setHkDiagnosticsReply(&hkMessage, sid, storeId);
2020-09-10 20:24:49 +02:00
}
else {
2020-09-14 18:01:48 +02:00
HousekeepingMessage::setHkReportReply(&hkMessage, sid, storeId);
2020-09-10 20:24:49 +02:00
}
2020-08-24 22:08:27 +02:00
if(hkQueue == nullptr) {
return QUEUE_OR_DESTINATION_NOT_SET;
}
if(destination == MessageQueueIF::NO_QUEUE) {
2020-09-19 01:17:43 +02:00
if(hkDestinationId == MessageQueueIF::NO_QUEUE) {
2020-08-24 22:08:27 +02:00
// error, all destinations invalid
return HasReturnvaluesIF::RETURN_FAILED;
}
2020-09-19 01:17:43 +02:00
destination = hkDestinationId;
2020-08-24 22:08:27 +02:00
}
2020-06-19 03:03:17 +02:00
2020-08-24 22:08:27 +02:00
return hkQueue->sendMessage(destination, &hkMessage);
2020-06-07 18:53:55 +02:00
}
ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
HousekeepingPacketDownlink& hkPacket,
store_address_t& storeId, bool forDownlink,
size_t* serializedSize) {
uint8_t* dataPtr = nullptr;
2020-08-24 22:08:27 +02:00
const size_t maxSize = hkPacket.getSerializedSize();
ReturnValue_t result = ipcStore->getFreeElement(&storeId,
maxSize, &dataPtr);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(forDownlink) {
return hkPacket.serialize(&dataPtr, serializedSize, maxSize,
SerializeIF::Endianness::BIG);
}
return hkPacket.serialize(&dataPtr, serializedSize, maxSize,
SerializeIF::Endianness::MACHINE);
}
2020-08-08 19:43:28 +02:00
void LocalDataPoolManager::setNonDiagnosticIntervalFactor(
uint8_t nonDiagInvlFactor) {
this->nonDiagnosticIntervalFactor = nonDiagInvlFactor;
2020-06-30 21:22:26 +02:00
}
2020-09-19 15:58:34 +02:00
void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) {
sid_t sid = receiver.dataId.sid;
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
if(not dataSet->getReportingEnabled()) {
return;
}
2020-09-19 01:17:43 +02:00
2020-09-19 15:58:34 +02:00
if(dataSet->periodicHelper == nullptr) {
// Configuration error.
return;
}
2020-08-08 19:43:28 +02:00
2020-09-19 15:58:34 +02:00
if(not dataSet->periodicHelper->checkOpNecessary()) {
return;
}
2020-08-08 19:43:28 +02:00
2020-09-19 15:58:34 +02:00
ReturnValue_t result = generateHousekeepingPacket(
sid, dataSet, true);
if(result != HasReturnvaluesIF::RETURN_OK) {
// configuration error
sif::debug << "LocalDataPoolManager::performHkOperation:"
2020-09-28 22:17:18 +02:00
<< "0x" << std::hex << std::setfill('0') << std::setw(8)
<< owner->getObjectId() << " Error generating "
<< "HK packet" << std::setfill(' ') << std::dec << std::endl;
2020-09-19 15:58:34 +02:00
}
2020-08-08 19:43:28 +02:00
}
2020-09-19 01:17:43 +02:00
2020-09-19 15:58:34 +02:00
2020-09-19 01:17:43 +02:00
ReturnValue_t LocalDataPoolManager::togglePeriodicGeneration(sid_t sid,
bool enable, bool isDiagnostics) {
2020-09-19 17:08:08 +02:00
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
2020-09-19 15:58:34 +02:00
if((dataSet->isDiagnostics() and not isDiagnostics) or
(not dataSet->isDiagnostics() and isDiagnostics)) {
2020-09-19 01:17:43 +02:00
return WRONG_HK_PACKET_TYPE;
}
if((dataSet->getReportingEnabled() and enable) or
(not dataSet->getReportingEnabled() and not enable)) {
return REPORTING_STATUS_UNCHANGED;
}
dataSet->setReportingEnabled(enable);
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid,
float newCollectionInterval, bool isDiagnostics) {
2020-09-19 17:08:08 +02:00
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
2020-09-19 15:58:34 +02:00
bool targetIsDiagnostics = dataSet->isDiagnostics();
2020-09-19 01:17:43 +02:00
if((targetIsDiagnostics and not isDiagnostics) or
(not targetIsDiagnostics and isDiagnostics)) {
return WRONG_HK_PACKET_TYPE;
}
2020-09-19 02:46:29 +02:00
if(dataSet->periodicHelper == nullptr) {
// config error
2020-09-19 17:14:09 +02:00
return PERIODIC_HELPER_INVALID;
2020-09-19 01:17:43 +02:00
}
2020-09-19 02:46:29 +02:00
dataSet->periodicHelper->changeCollectionInterval(newCollectionInterval);
2020-09-19 01:17:43 +02:00
return HasReturnvaluesIF::RETURN_OK;
}
2020-09-19 02:46:29 +02:00
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
2020-09-19 15:58:34 +02:00
bool isDiagnostics) {
2020-09-26 15:32:16 +02:00
// Get and check dataset first.
2020-10-14 01:25:15 +02:00
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid);
2020-09-19 15:58:34 +02:00
if(dataSet == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
2020-09-28 22:17:18 +02:00
<< " Set ID not found" << std::endl;
2020-09-19 15:58:34 +02:00
return HasReturnvaluesIF::RETURN_FAILED;
}
2020-09-28 21:09:56 +02:00
2020-09-19 15:58:34 +02:00
bool targetIsDiagnostics = dataSet->isDiagnostics();
if((targetIsDiagnostics and not isDiagnostics) or
(not targetIsDiagnostics and isDiagnostics)) {
return WRONG_HK_PACKET_TYPE;
}
2020-09-19 02:46:29 +02:00
2020-09-19 15:58:34 +02:00
bool valid = dataSet->isValid();
bool reportingEnabled = dataSet->getReportingEnabled();
float collectionInterval =
dataSet->periodicHelper->getCollectionIntervalInSeconds();
2020-09-19 02:46:29 +02:00
2020-09-26 15:32:16 +02:00
// Generate set packet which can be serialized.
2020-10-09 02:49:18 +02:00
HousekeepingSetPacket setPacket(sid,
2020-09-19 15:58:34 +02:00
reportingEnabled, valid, collectionInterval, dataSet);
size_t expectedSize = setPacket.getSerializedSize();
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: "
2020-09-28 22:17:18 +02:00
<< "Could not get free element from IPC store." << std::endl;
2020-09-19 15:58:34 +02:00
return result;
}
2020-09-26 15:32:16 +02:00
// Serialize set packet into store.
2020-09-19 15:58:34 +02:00
size_t size = 0;
result = setPacket.serialize(&storePtr, &size, expectedSize,
SerializeIF::Endianness::BIG);
if(expectedSize != size) {
sif::error << "HousekeepingManager::generateSetStructurePacket: "
2020-09-28 22:17:18 +02:00
<< "Expected size is not equal to serialized size" << std::endl;
2020-09-19 15:58:34 +02:00
}
2020-09-26 15:27:06 +02:00
2020-09-26 15:32:16 +02:00
// Send structure reporting reply.
2020-09-26 15:27:06 +02:00
CommandMessage reply;
if(isDiagnostics) {
HousekeepingMessage::setDiagnosticsStuctureReportReply(&reply,
sid, storeId);
}
else {
HousekeepingMessage::setHkStuctureReportReply(&reply,
sid, storeId);
}
hkQueue->reply(&reply);
2020-09-19 15:58:34 +02:00
return result;
2020-09-19 02:46:29 +02:00
}