additional ctor for space packet creator

This commit is contained in:
Robin Müller 2022-07-18 10:53:55 +02:00
parent d7a2eada94
commit 0c5f623780
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 37 additions and 9 deletions

View File

@ -74,7 +74,7 @@ class SerializeAdapter {
return HasReturnvaluesIF::RETURN_FAILED;
}
InternalSerializeAdapter<T, std::is_base_of<SerializeIF, T>::value> adapter;
uint8_t **tempPtr = const_cast<uint8_t **>(&buffer);
auto **tempPtr = const_cast<uint8_t **>(&buffer);
size_t tmpSize = 0;
ReturnValue_t result = adapter.serialize(object, tempPtr, &tmpSize, maxSize, streamEndianness);
if (serSize != nullptr) {
@ -232,7 +232,7 @@ class SerializeAdapter {
}
}
uint32_t getSerializedSize(const T *object) { return sizeof(T); }
uint32_t getSerializedSize(const T *) { return sizeof(T); }
};
/**

View File

@ -3,11 +3,30 @@
#include "fsfw/serialize/SerializeAdapter.h"
SpacePacketCreator::SpacePacketCreator(uint16_t packetId_, uint16_t packetSeqCtrl_,
uint16_t packetLen_, uint8_t version_) {
uint16_t dataLen_, uint8_t version_) {
packetId = packetId_;
packetSeqCtrl = packetSeqCtrl_;
packetLen = packetLen_;
dataLen = dataLen_;
version = version_;
valid = true;
}
SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag,
uint16_t apid, ccsds::SequenceFlags seqFlags,
uint16_t seqCount, uint16_t dataLen_, uint8_t version_) {
if (apid > ccsds::LIMIT_APID) {
valid = false;
return;
}
if (seqCount > ccsds::LIMIT_SEQUENCE_COUNT) {
valid = false;
return;
}
version = version_;
packetId =
(version_ << 13) | (static_cast<uint8_t>(packetType) << 12) | (secHeaderFlag << 11) | apid;
packetSeqCtrl = static_cast<uint8_t>(seqFlags) << 14 | seqCount;
dataLen = dataLen_;
}
uint16_t SpacePacketCreator::getPacketId() const { return 0; }
@ -26,7 +45,7 @@ ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return SerializeAdapter::serialize(&packetLen, buffer, size, maxSize, streamEndianness);
return SerializeAdapter::serialize(&dataLen, buffer, size, maxSize, streamEndianness);
}
size_t SpacePacketCreator::getSerializedSize() const { return 0; }

View File

@ -6,21 +6,25 @@
class SpacePacketCreator : public SerializeIF, public SpacePacketIF {
public:
SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t packetLen,
SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid,
ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen,
uint8_t version = 0);
SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t dataLen,
uint8_t version = 0);
bool valid;
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
size_t getSerializedSize() const override;
[[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
private:
uint16_t packetId;
uint16_t packetSeqCtrl;
uint16_t packetLen;
uint16_t dataLen;
uint8_t version;
};
#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H

View File

@ -1,5 +1,6 @@
#include <catch2/catch_test_macros.hpp>
#include "fsfw/tmtcpacket/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
TEST_CASE("CCSDS Test", "[ccsds]") {
@ -11,5 +12,9 @@ TEST_CASE("CCSDS Test", "[ccsds]") {
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff);
}
SECTION("Header Tests") { SpacePacketReader base = SpacePacketReader(); }
SECTION("Header Creator Tests") {
SpacePacketCreator base = SpacePacketCreator(
ccsds::PacketType::TM, true, 0x22,
ccsds::SequenceFlags::CONTINUATION, 12, 0x42);
}
}