fsfw/src/fsfw/housekeeping/HousekeepingSnapshot.h

112 lines
3.8 KiB
C
Raw Permalink Normal View History

2021-01-25 00:55:27 +01:00
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_
2020-10-01 12:05:24 +02:00
#include "../datapoollocal/LocalPoolDataSetBase.h"
2021-01-25 00:55:27 +01:00
#include "../datapoollocal/LocalPoolObjectBase.h"
2022-02-02 10:29:30 +01:00
#include "../serialize/SerialBufferAdapter.h"
#include "../serialize/SerialLinkedListAdapter.h"
2021-01-25 00:55:27 +01:00
#include "../timemanager/CCSDSTime.h"
2020-10-01 12:05:24 +02:00
/**
2021-01-25 00:55:27 +01:00
* @brief This helper class will be used to serialize and deserialize update housekeeping packets
* into the store.
2020-10-01 12:05:24 +02:00
*/
2022-02-02 10:29:30 +01:00
class HousekeepingSnapshot : public SerializeIF {
public:
/**
* Update packet constructor for datasets.
* @param cdsShort If a CSD short timestamp is used, a reference should be
* supplied here
* @param dataSetPtr Pointer to the dataset instance to serialize or deserialize the
* data into
*/
HousekeepingSnapshot(CCSDSTime::CDS_short* cdsShort, LocalPoolDataSetBase* dataSetPtr)
: timeStamp(reinterpret_cast<uint8_t*>(cdsShort)),
timeStampSize(sizeof(CCSDSTime::CDS_short)),
updateData(dataSetPtr){};
/**
* Update packet constructor for datasets.
* @param timeStamp Pointer to the buffer where the timestamp will be stored.
* @param timeStampSize Size of the timestamp
* @param dataSetPtr Pointer to the dataset instance to deserialize the data into
*/
HousekeepingSnapshot(uint8_t* timeStamp, size_t timeStampSize, LocalPoolDataSetBase* dataSetPtr)
: timeStamp(timeStamp), timeStampSize(timeStampSize), updateData(dataSetPtr){};
/**
* Update packet constructor for pool variables.
* @param timeStamp
* @param timeStampSize
* @param dataSetPtr
*/
HousekeepingSnapshot(CCSDSTime::CDS_short* cdsShort, LocalPoolObjectBase* dataSetPtr)
: timeStamp(reinterpret_cast<uint8_t*>(cdsShort)),
timeStampSize(sizeof(CCSDSTime::CDS_short)),
updateData(dataSetPtr){};
/**
* Update packet constructor for pool variables.
* @param timeStamp
* @param timeStampSize
* @param dataSetPtr
*/
HousekeepingSnapshot(uint8_t* timeStamp, size_t timeStampSize, LocalPoolObjectBase* dataSetPtr)
: timeStamp(timeStamp), timeStampSize(timeStampSize), updateData(dataSetPtr){};
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const {
if (timeStamp != nullptr) {
/* Endianness will always be MACHINE, so we can simply use memcpy
here. */
std::memcpy(*buffer, timeStamp, timeStampSize);
*size += timeStampSize;
*buffer += timeStampSize;
}
if (updateData == nullptr) {
2022-08-16 01:08:26 +02:00
return returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
2020-10-01 12:05:24 +02:00
2022-02-02 10:29:30 +01:00
return updateData->serialize(buffer, size, maxSize, streamEndianness);
}
2020-10-01 12:05:24 +02:00
2022-02-02 10:29:30 +01:00
virtual size_t getSerializedSize() const {
if (updateData == nullptr) {
return 0;
2020-10-01 12:05:24 +02:00
}
2022-02-02 10:29:30 +01:00
return timeStampSize + updateData->getSerializedSize();
}
2020-10-01 12:05:24 +02:00
2022-02-02 10:29:30 +01:00
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
SerializeIF::Endianness streamEndianness) override {
if (*size < timeStampSize) {
return SerializeIF::STREAM_TOO_SHORT;
2020-10-01 12:05:24 +02:00
}
2022-02-02 10:29:30 +01:00
if (timeStamp != nullptr) {
/* Endianness will always be MACHINE, so we can simply use memcpy
here. */
std::memcpy(timeStamp, *buffer, timeStampSize);
*size -= timeStampSize;
*buffer += timeStampSize;
}
2020-12-03 13:00:04 +01:00
2022-02-02 10:29:30 +01:00
if (updateData == nullptr) {
2022-08-16 01:08:26 +02:00
return returnvalue::FAILED;
2022-02-02 10:29:30 +01:00
}
if (*size < updateData->getSerializedSize()) {
return SerializeIF::STREAM_TOO_SHORT;
2020-10-01 12:05:24 +02:00
}
2022-02-02 10:29:30 +01:00
return updateData->deSerialize(buffer, size, streamEndianness);
}
2020-10-01 12:05:24 +02:00
2022-02-02 10:29:30 +01:00
private:
uint8_t* timeStamp = nullptr;
size_t timeStampSize = 0;
2020-10-01 12:05:24 +02:00
2022-02-02 10:29:30 +01:00
SerializeIF* updateData = nullptr;
};
2020-10-01 12:05:24 +02:00
2021-01-25 00:55:27 +01:00
#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_ */