added periodic helper
This commit is contained in:
@ -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_ */
|
||||
|
47
housekeeping/PeriodicHousekeepingHelper.cpp
Normal file
47
housekeeping/PeriodicHousekeepingHelper.cpp
Normal 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);
|
||||
}
|
35
housekeeping/PeriodicHousekeepingHelper.h
Normal file
35
housekeeping/PeriodicHousekeepingHelper.h
Normal 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_ */
|
Reference in New Issue
Block a user