added periodic helper

This commit is contained in:
Robin Müller 2020-09-19 02:46:29 +02:00
parent ba56f48e8e
commit 9ecbc8199e
7 changed files with 195 additions and 49 deletions

View File

@ -1,3 +1,4 @@
#include <fsfw/housekeeping/HousekeepingSetPacket.h>
#include "LocalDataPoolManager.h"
#include "LocalPoolDataSetBase.h"
#include "../housekeeping/AcceptsHkPacketsIF.h"
@ -155,8 +156,8 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES):
case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES):
return generateSetStructurePacket(sid);
//return generateSetStructurePacket(sid, );
return HasReturnvaluesIF::RETURN_OK;
case(HousekeepingMessage::MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL):
case(HousekeepingMessage::MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL): {
float newCollIntvl = 0;
@ -274,40 +275,11 @@ ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
SerializeIF::Endianness::MACHINE);
}
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid) {
LocalPoolDataSetBase* dataSet = dynamic_cast<LocalPoolDataSetBase*>(
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,
expectedSize, SerializeIF::Endianness::BIG);
if(expectedSize != size) {
sif::error << "HousekeepingManager::generateSetStructurePacket: "
"Expected size is not equal to serialized size" << std::endl;
}
return result;
}
void LocalDataPoolManager::setNonDiagnosticIntervalFactor(
uint8_t nonDiagInvlFactor) {
this->nonDiagnosticIntervalFactor = nonDiagInvlFactor;
}
void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver* receiver) {
if(receiver->intervalCounter >=
receiver->hkParameter.collectionIntervalTicks) {
@ -386,14 +358,56 @@ ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid,
return WRONG_HK_PACKET_TYPE;
}
for(auto& receiver: hkReceiversMap) {
if(receiver.second.reportingType != ReportingType::PERIODIC) {
continue;
}
uint32_t newInterval = intervalSecondsToInterval(isDiagnostics,
newCollectionInterval);
receiver.second.hkParameter.collectionIntervalTicks = newInterval;
if(dataSet->periodicHelper == nullptr) {
// config error
return HasReturnvaluesIF::RETURN_FAILED;
}
dataSet->periodicHelper->changeCollectionInterval(newCollectionInterval);
// for(auto& receiver: hkReceiversMap) {
// if(receiver.second.reportingType != ReportingType::PERIODIC) {
// continue;
// }
//
// uint32_t newInterval = intervalSecondsToInterval(isDiagnostics,
// newCollectionInterval);
// receiver.second.hkParameter.collectionIntervalTicks = newInterval;
// }
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid,
float collectionInterval, bool isDiagnostics) {
LocalPoolDataSetBase* dataSet = dynamic_cast<LocalPoolDataSetBase*>(
owner->getDataSetHandle(sid));
if(dataSet == nullptr) {
sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
" Set ID not found" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
bool valid = dataSet->isValid();
bool targetIsDiagnostics = dataSet->getIsDiagnostics();
bool reportingEnabled = dataSet->getReportingEnabled();
size_t expectedSize = dataSet->getFillCount() * sizeof(lp_id_t);
uint8_t* storePtr = nullptr;
store_address_t storeId;
HousekeepingSetPacket setPacket = HousekeepingSetPacket(sid, reportingEnabled,
valid, collectionInterval, dataSet);
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,
expectedSize, SerializeIF::Endianness::BIG);
if(expectedSize != size) {
sif::error << "HousekeepingManager::generateSetStructurePacket: "
"Expected size is not equal to serialized size" << std::endl;
}
return result;
}

View File

@ -114,7 +114,6 @@ public:
ReturnValue_t generateHousekeepingPacket(sid_t sid,
LocalPoolDataSetBase* dataSet, bool forDownlink,
MessageQueueId_t destination = MessageQueueIF::NO_QUEUE);
ReturnValue_t generateSetStructurePacket(sid_t sid);
ReturnValue_t handleHousekeepingMessage(CommandMessage* message);
@ -263,6 +262,8 @@ private:
bool isDiagnostics);
ReturnValue_t changeCollectionInterval(sid_t sid,
float newCollectionInterval, bool isDiagnostics);
ReturnValue_t generateSetStructurePacket(sid_t sid,
float collectionInterval, bool isDiagnostics);
};

View File

@ -17,6 +17,9 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
hkManager = hkOwner->getHkManagerHandle();
this->sid.objectId = hkOwner->getObjectId();
this->sid.ownerSetId = setId;
// Data creators get a periodic helper for periodic HK data generation.
periodicHelper = new PeriodicHousekeepingHelper(this);
}
LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid,

View File

@ -1,6 +1,7 @@
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
#define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETBASE_H_
#include <fsfw/housekeeping/PeriodicHousekeepingHelper.h>
#include "HasLocalDataPoolIF.h"
#include "../datapool/DataSetIF.h"
#include "../datapool/PoolDataSetBase.h"
@ -33,6 +34,7 @@ class LocalDataPoolManager;
*/
class LocalPoolDataSetBase: public PoolDataSetBase {
friend class LocalDataPoolManager;
friend class PeriodicHousekeepingHelper;
public:
/**
* @brief Constructor for the creator of local pool data.
@ -100,20 +102,19 @@ public:
void setValidity(bool valid, bool setEntriesRecursively);
bool isValid() const override;
void setIsDiagnostic(bool diagnostics);
bool getIsDiagnostics() const;
protected:
sid_t sid;
bool isDiagnostics = false;
void setIsDiagnostic(bool diagnostics);
bool getIsDiagnostics() const;
void setReportingEnabled(bool enabled);
bool getReportingEnabled() const;
/**
* Used for periodic generation.
*/
bool reportingEnabled = false;
bool reportingEnabled = false;
void setReportingEnabled(bool enabled);
bool getReportingEnabled() const;
/**
* If the valid state of a dataset is always relevant to the whole
@ -147,7 +148,7 @@ protected:
void bitSetter(uint8_t* byte, uint8_t position) const;
bool bitGetter(const uint8_t* byte, uint8_t position) const;
private:
PeriodicHousekeepingHelper* periodicHelper = nullptr;
};

View File

@ -1,13 +1,58 @@
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_
#include "../housekeeping/HousekeepingMessage.h"
#include "../serialize/SerialLinkedListAdapter.h"
#include "../datapoollocal/LocalPoolDataSetBase.h"
class HousekeepingSetPacket: public SerialLinkedListAdapter<SerializeIF> {
public:
HousekeepingSetPacket(sid_t sid, bool reportingEnabled, bool valid,
float collectionInterval, LocalPoolDataSetBase* dataSetPtr):
objectId(sid.objectId), setId(sid.ownerSetId),
reportingEnabled(reportingEnabled), valid(valid),
collectionIntervalSeconds(collectionInterval), dataSet(dataSetPtr) {
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const override {
ReturnValue_t result = SerialLinkedListAdapter::serialize(buffer, size,
maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return dataSet->serializeLocalPoolIds(buffer, size ,maxSize,
streamEndianness);
}
size_t getSerializedSize() const override {
size_t linkedSize = SerialLinkedListAdapter::getSerializedSize();
linkedSize += dataSet->getFillCount() * sizeof(lp_id_t);
return linkedSize;
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override {
return HasReturnvaluesIF::RETURN_OK;
}
private:
void setLinks() {
setStart(&objectId);
objectId.setNext(&setId);
setId.setNext(&reportingEnabled);
reportingEnabled.setNext(&valid);
valid.setNext(&collectionIntervalSeconds);
collectionIntervalSeconds.setEnd();
}
SerializeElement<object_id_t> objectId;
SerializeElement<uint32_t> setId;
SerializeElement<bool> reportingEnabled;
SerializeElement<bool> valid;
SerializeElement<float> collectionIntervalSeconds;
LocalPoolDataSetBase* dataSet;
};
#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_ */

View File

@ -0,0 +1,47 @@
#include "../datapoollocal/LocalPoolDataSetBase.h"
#include "PeriodicHousekeepingHelper.h"
#include <cmath>
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(
LocalPoolDataSetBase* owner): owner(owner) {}
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
dur_millis_t minimumPeriodicInterval, bool isDiagnostics,
uint8_t nonDiagIntervalFactor) {
this->minimumPeriodicInterval = minimumPeriodicInterval;
if(not owner->getIsDiagnostics()) {
this->minimumPeriodicInterval = this->minimumPeriodicInterval *
nonDiagIntervalFactor;
}
}
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() {
return intervalToIntervalSeconds(collectionIntervalTicks);
}
bool PeriodicHousekeepingHelper::checkOpNecessary() {
if(internalTickCounter >= collectionIntervalTicks) {
internalTickCounter = 1;
return true;
}
internalTickCounter++;
return false;
}
uint32_t PeriodicHousekeepingHelper::intervalSecondsToInterval(
float collectionIntervalSeconds) {
return std::ceil(collectionIntervalSeconds * 1000
/ minimumPeriodicInterval);
}
float PeriodicHousekeepingHelper::intervalToIntervalSeconds(
uint32_t collectionInterval) {
return static_cast<float>(collectionInterval *
minimumPeriodicInterval);
}
void PeriodicHousekeepingHelper::changeCollectionInterval(
float newIntervalSeconds) {
collectionIntervalTicks = intervalSecondsToInterval(newIntervalSeconds);
}

View File

@ -0,0 +1,35 @@
#ifndef FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
#define FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
#include "../timemanager/Clock.h"
#include <cstdint>
class LocalPoolDataSetBase;
class PeriodicHousekeepingHelper {
public:
PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner);
void initialize(float collectionInterval,
dur_millis_t minimumPeriodicInterval, bool isDiagnostics,
uint8_t nonDiagIntervalFactor);
void changeCollectionInterval(float newInterval);
float getCollectionIntervalInSeconds();
bool checkOpNecessary();
private:
LocalPoolDataSetBase* owner = nullptr;
uint32_t intervalSecondsToInterval(float collectionIntervalSeconds);
float intervalToIntervalSeconds(uint32_t collectionInterval);
dur_millis_t minimumPeriodicInterval = 0;
uint32_t internalTickCounter = 1;
uint32_t collectionIntervalTicks = 0;
};
#endif /* FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_ */