1
0
forked from fsfw/fsfw

fnished PUS TC creator unittests

This commit is contained in:
2022-07-21 17:48:11 +02:00
parent 08e0b0f1a0
commit 5af3138e81
22 changed files with 239 additions and 30 deletions

View File

@ -19,6 +19,10 @@ struct PacketId : public SerializeIF {
PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_)
: packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {}
bool operator==(const PacketId &other) const {
return packetType == other.packetType and secHeaderFlag == other.secHeaderFlag and
apid == other.apid;
}
/**
* NOTE: If the APID has an invalid value, the invalid bits will be cut off
* @return

View File

@ -79,3 +79,7 @@ void SpacePacketCreator::checkFieldValidity() {
void SpacePacketCreator::setParams(SpacePacketParams params_) { params = std::move(params_); }
SpacePacketParams &SpacePacketCreator::getParams() { return params; }
void SpacePacketCreator::setPacketType(ccsds::PacketType type) {
params.packetId.packetType = type;
}

View File

@ -35,6 +35,7 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF {
SpacePacketParams &getParams();
void setParams(SpacePacketParams params);
void setPacketType(ccsds::PacketType type);
void setApid(uint16_t apid);
void setSeqCount(uint16_t seqCount);
void setSeqFlags(ccsds::SequenceFlags flags);

View File

@ -9,8 +9,10 @@
class PusIF : public SpacePacketIF {
public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::PUS_IF;
static constexpr ReturnValue_t INVALID_CRC_16 =
static constexpr ReturnValue_t INVALID_PUS_VERSION =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0);
static constexpr ReturnValue_t INVALID_CRC_16 =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 1);
~PusIF() override = default;
/**

View File

@ -2,6 +2,7 @@
#define FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_
#include <cstdint>
#include <utility>
#include "fsfw/serialize/SerializeIF.h"
@ -27,6 +28,7 @@ union DataUnion {
struct DataWrapper {
DataTypes type;
DataUnion dataUnion;
using BufPairT = std::pair<uint8_t*, size_t>;
[[nodiscard]] size_t getLength() const {
if (type == DataTypes::RAW) {
@ -36,6 +38,17 @@ struct DataWrapper {
}
return 0;
}
void setRawData(BufPairT bufPair) {
type = DataTypes::RAW;
dataUnion.raw.data = bufPair.first;
dataUnion.raw.len = bufPair.second;
}
void setSerializable(SerializeIF* serializable) {
type = DataTypes::SERIALIZABLE;
dataUnion.serializable = serializable;
}
};
/**

View File

@ -8,29 +8,31 @@
PusTcCreator::PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams)
: spCreator(std::move(spParams)), pusParams(pusParams) {
spCreator.setPacketType(ccsds::PacketType::TC);
updateSpLengthField();
}
ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
const uint8_t *start = *buffer;
size_t userDataLen = pusParams.dataWrapper.getLength();
if (*size + PusTcIF::MIN_SIZE + userDataLen > maxSize) {
if (*size + getFullPacketLen() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
if (pusParams.pusVersion != ecss::PusVersion::PUS_C) {
return PusIF::INVALID_PUS_VERSION;
}
ReturnValue_t result = spCreator.serialize(buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (pusParams.pusVersion != ecss::PusVersion::PUS_C) {
// TODO: Dedicated returnvalue
return HasReturnvaluesIF::RETURN_FAILED;
}
**buffer = pusParams.pusVersion << 4 | pusParams.ackFlags;
*buffer += 1;
**buffer = pusParams.service;
*buffer += 1;
**buffer = pusParams.subservice;
*buffer += 1;
*size += 3;
result =
SerializeAdapter::serialize(&pusParams.sourceId, buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
@ -52,7 +54,7 @@ ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t max
}
}
uint16_t crc16 = CRC::crc16ccitt(*buffer, getFullPacketLen() - 2);
uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - 2);
return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness);
}
@ -89,3 +91,7 @@ ecss::DataWrapper &PusTcCreator::getDataWrapper() { return pusParams.dataWrapper
PusTcParams &PusTcCreator::getPusParams() { return pusParams; }
SpacePacketParams &PusTcCreator::getSpParams() { return spCreator.getParams(); }
ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}

View File

@ -21,13 +21,19 @@ struct PusTcParams {
class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF {
public:
PusTcCreator(SpacePacketParams spParams, PusTcParams pusParams);
PusTcCreator(SpacePacketParams initSpParams, PusTcParams initPusParams);
/**
* If the parameter structure is changed in a way which changes the resulting serialized packet
* size, this function should be called to set the data length field in the space packet
* header. This fields is the primary source of information for length information.
*
* The only case for a telecommand where this size changes would be if user data is set.
*/
void updateSpLengthField();
PusTcParams &getPusParams();
SpacePacketParams &getSpParams();
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize);
[[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
@ -42,6 +48,8 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CreatorDataIF {
ecss::DataWrapper &getDataWrapper() override;
private:
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
SpacePacketCreator spCreator;
PusTcParams pusParams;
};