2020-11-03 15:45:04 +01:00
|
|
|
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_
|
|
|
|
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_
|
2020-08-08 21:32:15 +02:00
|
|
|
|
2020-09-19 01:17:43 +02:00
|
|
|
#include "../serialize/SerialBufferAdapter.h"
|
|
|
|
#include "../serialize/SerialLinkedListAdapter.h"
|
|
|
|
#include "../datapoollocal/LocalPoolDataSetBase.h"
|
2020-08-08 21:32:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This helper class will be used to serialize and deserialize
|
2020-08-09 20:06:29 +02:00
|
|
|
* update housekeeping packets into the store.
|
2020-08-08 21:32:15 +02:00
|
|
|
*/
|
2020-08-09 19:46:37 +02:00
|
|
|
class HousekeepingPacketUpdate: public SerializeIF {
|
2020-08-08 21:32:15 +02:00
|
|
|
public:
|
|
|
|
/**
|
2020-11-03 23:23:05 +01:00
|
|
|
* Update packet constructor for datasets
|
2020-08-08 21:32:15 +02:00
|
|
|
* @param timeStamp
|
|
|
|
* @param timeStampSize
|
|
|
|
* @param hkData
|
|
|
|
* @param hkDataSize
|
|
|
|
*/
|
2020-08-09 19:46:37 +02:00
|
|
|
HousekeepingPacketUpdate(uint8_t* timeStamp, size_t timeStampSize,
|
2020-08-08 21:32:15 +02:00
|
|
|
LocalPoolDataSetBase* dataSetPtr):
|
2020-11-03 23:23:05 +01:00
|
|
|
timeStamp(timeStamp), timeStampSize(timeStampSize),
|
|
|
|
updateData(dataSetPtr) {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update packet constructor for pool variables.
|
|
|
|
* @param timeStamp
|
|
|
|
* @param timeStampSize
|
|
|
|
* @param dataSetPtr
|
|
|
|
*/
|
|
|
|
HousekeepingPacketUpdate(uint8_t* timeStamp, size_t timeStampSize,
|
|
|
|
LocalPoolObjectBase* dataSetPtr):
|
|
|
|
timeStamp(timeStamp), timeStampSize(timeStampSize),
|
|
|
|
updateData(dataSetPtr) {};
|
2020-08-08 21:32:15 +02:00
|
|
|
|
|
|
|
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
|
|
|
|
size_t maxSize, Endianness streamEndianness) const {
|
|
|
|
if(timeStamp != nullptr) {
|
2020-08-09 20:06:29 +02:00
|
|
|
/* Endianness will always be MACHINE, so we can simply use memcpy
|
|
|
|
here. */
|
2020-08-08 21:32:15 +02:00
|
|
|
std::memcpy(*buffer, timeStamp, timeStampSize);
|
|
|
|
*size += timeStampSize;
|
|
|
|
*buffer += timeStampSize;
|
|
|
|
}
|
2020-11-03 23:23:05 +01:00
|
|
|
if(updateData == nullptr) {
|
2020-08-08 21:32:15 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
2020-11-03 23:23:05 +01:00
|
|
|
return updateData->serialize(buffer, size, maxSize, streamEndianness);
|
2020-08-08 21:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual size_t getSerializedSize() const {
|
2020-11-03 23:23:05 +01:00
|
|
|
if(updateData == nullptr) {
|
2020-08-08 21:32:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-11-03 23:23:05 +01:00
|
|
|
return timeStampSize + updateData->getSerializedSize();
|
2020-08-08 21:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
|
|
SerializeIF::Endianness streamEndianness) override {
|
2020-11-03 23:29:03 +01:00
|
|
|
if(*size < timeStampSize) {
|
|
|
|
return SerializeIF::STREAM_TOO_SHORT;
|
|
|
|
}
|
|
|
|
|
2020-08-08 21:32:15 +02:00
|
|
|
if(timeStamp != nullptr) {
|
2020-08-09 20:06:29 +02:00
|
|
|
/* Endianness will always be MACHINE, so we can simply use memcpy
|
|
|
|
here. */
|
2020-08-08 21:32:15 +02:00
|
|
|
std::memcpy(timeStamp, *buffer, timeStampSize);
|
2020-11-03 23:26:28 +01:00
|
|
|
*size -= timeStampSize;
|
2020-08-08 21:32:15 +02:00
|
|
|
*buffer += timeStampSize;
|
|
|
|
}
|
|
|
|
|
2020-11-03 23:23:05 +01:00
|
|
|
if(updateData == nullptr) {
|
2020-08-08 21:32:15 +02:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
2020-11-03 23:29:03 +01:00
|
|
|
if(*size < updateData->getSerializedSize()) {
|
|
|
|
return SerializeIF::STREAM_TOO_SHORT;
|
|
|
|
}
|
|
|
|
|
2020-11-03 23:23:05 +01:00
|
|
|
return updateData->deSerialize(buffer, size, streamEndianness);
|
2020-08-08 21:32:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-11-03 23:23:05 +01:00
|
|
|
uint8_t* timeStamp = nullptr;
|
|
|
|
size_t timeStampSize = 0;
|
2020-08-08 21:32:15 +02:00
|
|
|
|
2020-11-03 23:23:05 +01:00
|
|
|
SerializeIF* updateData = nullptr;
|
2020-08-08 21:32:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-03 15:45:04 +01:00
|
|
|
#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_ */
|