refactor ctors

This commit is contained in:
Robin Müller 2022-09-05 15:30:53 +02:00
parent d64ad71529
commit f0b7a103d4
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
5 changed files with 39 additions and 28 deletions

View File

@ -125,6 +125,13 @@ void SerialBufferAdapter<count_t>::setBuffer(uint8_t* buffer, count_t bufferLeng
this->bufferLength = bufferLength;
}
template <typename count_t>
void SerialBufferAdapter<count_t>::setConstBuffer(const uint8_t* buf, count_t bufLen) {
this->buffer = nullptr;
this->bufferLength = bufLen;
this->constBuffer = buf;
}
// forward Template declaration for linker
template class SerialBufferAdapter<uint8_t>;
template class SerialBufferAdapter<uint16_t>;

View File

@ -21,6 +21,7 @@
template <typename count_t>
class SerialBufferAdapter : public SerializeIF {
public:
SerialBufferAdapter() = default;
/**
* Constructor for constant uint8_t buffer. Length field can be serialized optionally.
* Type of length can be supplied as template type.
@ -40,12 +41,12 @@ class SerialBufferAdapter : public SerializeIF {
*/
SerialBufferAdapter(uint8_t* buffer, count_t bufferLength, bool serializeLength = false);
virtual ~SerialBufferAdapter();
~SerialBufferAdapter() override;
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override;
[[nodiscard]] size_t getSerializedSize() const override;
/**
* @brief This function deserializes a buffer into the member buffer.
@ -59,12 +60,13 @@ class SerialBufferAdapter : public SerializeIF {
* @param bigEndian
* @return
*/
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
uint8_t* getBuffer();
const uint8_t* getConstBuffer() const;
[[nodiscard]] const uint8_t* getConstBuffer() const;
void setBuffer(uint8_t* buffer, count_t bufferLength);
void setConstBuffer(const uint8_t* buf, count_t bufLen);
private:
bool serializeLength = false;

View File

@ -7,6 +7,6 @@ class CustomUserDataIF {
public:
virtual ~CustomUserDataIF() = default;
virtual ReturnValue_t setRawUserData(const uint8_t* data, size_t len) = 0;
virtual ReturnValue_t setSerializableUserData(SerializeIF& serializable) = 0;
virtual ReturnValue_t setSerializableUserData(const SerializeIF& serializable) = 0;
};
#endif // FSFW_TMTCPACKET_CREATORDATAIF_H

View File

@ -51,7 +51,7 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max
if (result != returnvalue::OK) {
return result;
}
size_t userDataLen = pusParams.dataWrapper.getLength();
size_t userDataLen = pusParams.data->getSerializedSize();
**buffer =
((pusParams.secHeader.pusVersion << 4) & 0xF0) | (pusParams.secHeader.scTimeRefStatus & 0x0F);
*buffer += 1;
@ -77,15 +77,8 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max
}
}
if (pusParams.dataWrapper.type == util::DataTypes::RAW and
pusParams.dataWrapper.dataUnion.raw.data != nullptr) {
std::memcpy(*buffer, pusParams.dataWrapper.dataUnion.raw.data, userDataLen);
*buffer += userDataLen;
*size += userDataLen;
} else if (pusParams.dataWrapper.type == util::DataTypes::SERIALIZABLE and
pusParams.dataWrapper.dataUnion.serializable != nullptr) {
result = pusParams.dataWrapper.dataUnion.serializable->serialize(buffer, size, maxSize,
streamEndianness);
if (pusParams.data != nullptr) {
result = pusParams.data->serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
@ -111,7 +104,7 @@ TimeWriterIF* PusTmCreator::getTimestamper() const { return pusParams.secHeader.
SpacePacketParams& PusTmCreator::getSpParams() { return spCreator.getParams(); }
void PusTmCreator::updateSpLengthField() {
size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + pusParams.dataWrapper.getLength() +
size_t headerLen = PusTmIF::MIN_SEC_HEADER_LEN + pusParams.data->getSerializedSize() +
sizeof(ecss::PusChecksumT) - 1;
if (pusParams.secHeader.timeStamper != nullptr) {
headerLen += pusParams.secHeader.timeStamper->getSerializedSize();
@ -134,12 +127,12 @@ void PusTmCreator::setMessageTypeCounter(uint16_t messageTypeCounter) {
void PusTmCreator::setDestId(uint16_t destId) { pusParams.secHeader.destId = destId; }
ReturnValue_t PusTmCreator::setRawUserData(const uint8_t* data, size_t len) {
pusParams.dataWrapper.setRawData({data, len});
pusParams.adapter.setConstBuffer(data, len);
updateSpLengthField();
return returnvalue::OK;
}
ReturnValue_t PusTmCreator::setSerializableUserData(SerializeIF& serializable) {
pusParams.dataWrapper.setSerializable(serializable);
ReturnValue_t PusTmCreator::setSerializableUserData(const SerializeIF& serializable) {
pusParams.data = &serializable;
updateSpLengthField();
return returnvalue::OK;
}

View File

@ -22,20 +22,29 @@ struct PusTmSecHeader {
struct PusTmParams {
PusTmParams() = default;
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader){};
PusTmParams(PusTmSecHeader secHeader, util::DataWrapper dataWrapper)
: secHeader(secHeader), dataWrapper(dataWrapper) {}
explicit PusTmParams(PusTmSecHeader secHeader) : secHeader(secHeader) {};
PusTmParams(PusTmSecHeader secHeader, const SerializeIF& data)
: secHeader(secHeader), data(&data) {}
PusTmParams(PusTmSecHeader secHeader, const uint8_t* data, size_t dataLen)
: secHeader(secHeader), adapter(data, dataLen), data(&adapter) {
}
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper)
: secHeader(service, subservice, timeStamper) {}
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper,
util::DataWrapper dataWrapper_)
const SerializeIF& data_)
: PusTmParams(service, subservice, timeStamper) {
dataWrapper = dataWrapper_;
data = &data_;
}
PusTmParams(uint8_t service, uint8_t subservice, TimeWriterIF* timeStamper,
const uint8_t* data, size_t dataLen)
: secHeader(service, subservice, timeStamper),
adapter(data, dataLen),
data(&adapter) {}
PusTmSecHeader secHeader;
util::DataWrapper dataWrapper{};
SerialBufferAdapter<uint8_t> adapter;
const SerializeIF* data = nullptr;
};
class TimeWriterIF;
@ -88,7 +97,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF
[[nodiscard]] size_t getSerializedSize() const override;
[[nodiscard]] TimeWriterIF* getTimestamper() const;
ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override;
ReturnValue_t setSerializableUserData(SerializeIF& serializable) override;
ReturnValue_t setSerializableUserData(const SerializeIF& serializable) override;
// Load all big endian (network endian) helpers into scope
using SerializeIF::serializeBe;