add space packet creator class

This commit is contained in:
Robin Müller 2022-07-18 10:42:56 +02:00
parent 546e173cef
commit d7a2eada94
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
30 changed files with 164 additions and 89 deletions

View File

@ -133,7 +133,14 @@ option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF)
set(FSFW_TEST_TGT fsfw-tests)
set(FSFW_DUMMY_TGT fsfw-dummy)
add_library(${LIB_FSFW_NAME} src/fsfw/tmtcpacket/SpacePacketIF.h src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp src/fsfw/tmtcpacket/pus/tc/PusTcIF.h)
add_library(
${LIB_FSFW_NAME}
src/fsfw/tmtcpacket/SpacePacketIF.h
src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.h
src/fsfw/tmtcpacket/pus/tc/TcPacketDeserializer.cpp
src/fsfw/tmtcpacket/pus/tc/PusTcIF.h
src/fsfw/tmtcpacket/SpacePacketCreator.h
src/fsfw/tmtcpacket/SpacePacketCreator.cpp)
if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION

View File

@ -6,7 +6,7 @@
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
#include "fsfw/tmtcservices/TmTcMessage.h"

View File

@ -2,7 +2,7 @@
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#define CCSDS_DISTRIBUTOR_DEBUGGING 0
@ -40,7 +40,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() {
#endif
return queueMap.end();
}
SpacePacketBase currentPacket(packet);
SpacePacketReader currentPacket(packet);
#if FSFW_CPP_OSTREAM_ENABLED == 1 && CCSDS_DISTRIBUTOR_DEBUGGING == 1
sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex

View File

@ -4,6 +4,6 @@
TcPacketCheckCFDP::TcPacketCheckCFDP(uint16_t setApid) : apid(setApid) {}
ReturnValue_t TcPacketCheckCFDP::checkPacket(SpacePacketBase* currentPacket) { return RETURN_OK; }
ReturnValue_t TcPacketCheckCFDP::checkPacket(SpacePacketReader* currentPacket) { return RETURN_OK; }
uint16_t TcPacketCheckCFDP::getApid() const { return apid; }

View File

@ -25,7 +25,7 @@ class TcPacketCheckCFDP : public TcPacketCheckIF, public HasReturnvaluesIF {
*/
TcPacketCheckCFDP(uint16_t setApid);
ReturnValue_t checkPacket(SpacePacketBase* currentPacket) override;
ReturnValue_t checkPacket(SpacePacketReader* currentPacket) override;
uint16_t getApid() const;
};

View File

@ -3,7 +3,7 @@
#include "../returnvalues/HasReturnvaluesIF.h"
class SpacePacketBase;
class SpacePacketReader;
/**
* This interface is used by PacketCheckers for PUS packets and CFDP packets .
@ -24,7 +24,7 @@ class TcPacketCheckIF {
* - @c INCORRECT_CHECKSUM if checksum is invalid.
* - @c ILLEGAL_APID if APID does not match.
*/
virtual ReturnValue_t checkPacket(SpacePacketBase* currentPacket) = 0;
virtual ReturnValue_t checkPacket(SpacePacketReader* currentPacket) = 0;
};
#endif /* FSFW_TCDISTRIBUTION_TCPACKETCHECKIF_H_ */

View File

@ -10,7 +10,7 @@
TcPacketCheckPUS::TcPacketCheckPUS(uint16_t setApid) : apid(setApid) {}
ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketBase* currentPacket) {
ReturnValue_t TcPacketCheckPUS::checkPacket(SpacePacketReader* currentPacket) {
auto* storedPacket = dynamic_cast<TcPacketStoredBase*>(currentPacket);
auto* tcPacketBase = dynamic_cast<TcPacketPusBase*>(currentPacket);
if (tcPacketBase == nullptr or storedPacket == nullptr) {

View File

@ -53,7 +53,7 @@ class TcPacketCheckPUS : public TcPacketCheckIF, public HasReturnvaluesIF {
*/
TcPacketCheckPUS(uint16_t setApid);
ReturnValue_t checkPacket(SpacePacketBase* currentPacket) override;
ReturnValue_t checkPacket(SpacePacketReader* currentPacket) override;
uint16_t getApid() const;
};

View File

@ -1,4 +1,4 @@
target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketBase.cpp)
target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp)
add_subdirectory(cfdp)
add_subdirectory(packetmatcher)

View File

@ -0,0 +1,36 @@
#include "SpacePacketCreator.h"
#include "fsfw/serialize/SerializeAdapter.h"
SpacePacketCreator::SpacePacketCreator(uint16_t packetId_, uint16_t packetSeqCtrl_,
uint16_t packetLen_, uint8_t version_) {
packetId = packetId_;
packetSeqCtrl = packetSeqCtrl_;
packetLen = packetLen_;
version = version_;
}
uint16_t SpacePacketCreator::getPacketId() const { return 0; }
uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return 0; }
uint16_t SpacePacketCreator::getPacketDataLen() const { return 0; }
ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
uint16_t packetIdAndVersion = version << 13 | packetId;
ReturnValue_t result =
SerializeAdapter::serialize(&packetIdAndVersion, buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
result = SerializeAdapter::serialize(&packetSeqCtrl, buffer, size, maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return SerializeAdapter::serialize(&packetLen, buffer, size, maxSize, streamEndianness);
}
size_t SpacePacketCreator::getSerializedSize() const { return 0; }
ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) {
return HasReturnvaluesIF::RETURN_FAILED;
}

View File

@ -0,0 +1,26 @@
#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H
#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H
#include "SpacePacketIF.h"
#include "fsfw/serialize/SerializeIF.h"
class SpacePacketCreator : public SerializeIF, public SpacePacketIF {
public:
SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t packetLen,
uint8_t version = 0);
[[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;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
private:
uint16_t packetId;
uint16_t packetSeqCtrl;
uint16_t packetLen;
uint8_t version;
};
#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H

View File

@ -1,16 +1,16 @@
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include <cstring>
#include "fsfw/serviceinterface/ServiceInterface.h"
SpacePacketBase::SpacePacketBase(const uint8_t* setAddress) {
SpacePacketReader::SpacePacketReader(const uint8_t* setAddress) {
this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(setAddress));
}
SpacePacketBase::~SpacePacketBase() = default;
SpacePacketReader::~SpacePacketReader() = default;
ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
ReturnValue_t SpacePacketReader::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
uint16_t apid, uint16_t sequenceCount) {
if (data == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
@ -35,54 +35,54 @@ ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool ha
return HasReturnvaluesIF::RETURN_OK;
}
inline uint16_t SpacePacketBase::getPacketId() const {
inline uint16_t SpacePacketReader::getPacketId() const {
return ((this->data->header.packetIdHAndVersion) << 8) + this->data->header.packetIdL;
}
void SpacePacketBase::setApid(uint16_t setAPID) {
void SpacePacketReader::setApid(uint16_t setAPID) {
// Use first three bits of new APID, but keep rest of packet id as it was (see specification).
this->data->header.packetIdHAndVersion =
(this->data->header.packetIdHAndVersion & 0b11111000) | ((setAPID & 0x0700) >> 8);
this->data->header.packetIdL = (setAPID & 0x00FF);
}
void SpacePacketBase::setSequenceFlags(uint8_t sequenceflags) {
void SpacePacketReader::setSequenceFlags(uint8_t sequenceflags) {
this->data->header.packetSeqCtrlH &= 0x3F;
this->data->header.packetSeqCtrlH |= sequenceflags << 6;
}
void SpacePacketBase::setPacketSequenceCount(uint16_t new_count) {
void SpacePacketReader::setPacketSequenceCount(uint16_t new_count) {
this->data->header.packetSeqCtrlH = (this->data->header.packetSeqCtrlH & 0b11000000) |
(((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x3F00) >> 8);
this->data->header.packetSeqCtrlL = ((new_count % ccsds::LIMIT_SEQUENCE_COUNT) & 0x00FF);
}
void SpacePacketBase::setPacketDataLength(uint16_t new_length) {
void SpacePacketReader::setPacketDataLength(uint16_t new_length) {
this->data->header.packetLenH = ((new_length & 0xFF00) >> 8);
this->data->header.packetLenL = (new_length & 0x00FF);
}
size_t SpacePacketBase::getFullSize() {
size_t SpacePacketReader::getFullSize() {
// +1 is done because size in packet data length field is: size of data field -1
return this->getPacketDataLen() + sizeof(this->data->header) + 1;
}
uint8_t* SpacePacketBase::getWholeData() { return reinterpret_cast<uint8_t*>(this->data); }
uint8_t* SpacePacketReader::getWholeData() { return reinterpret_cast<uint8_t*>(this->data); }
uint8_t* SpacePacketBase::getPacketData() { return &(data->packet_data); }
uint8_t* SpacePacketReader::getPacketData() { return &(data->packet_data); }
ReturnValue_t SpacePacketBase::setData(uint8_t* pData, size_t maxSize, void* args) {
ReturnValue_t SpacePacketReader::setData(uint8_t* pData, size_t maxSize, void* args) {
if (maxSize < 6) {
return HasReturnvaluesIF::RETURN_FAILED;
}
this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(pData));
return HasReturnvaluesIF::RETURN_OK;
}
uint16_t SpacePacketBase::getPacketSeqCtrl() const {
uint16_t SpacePacketReader::getPacketSeqCtrl() const {
return ((this->data->header.packetSeqCtrlH & 0b00111111) << 8) +
this->data->header.packetSeqCtrlL;
}
uint16_t SpacePacketBase::getPacketDataLen() const {
uint16_t SpacePacketReader::getPacketDataLen() const {
return ((this->data->header.packetLenH) << 8) + this->data->header.packetLenL;
}

View File

@ -40,7 +40,7 @@ struct SpacePacketPointer {
* the most significant bit (from left).
* @ingroup tmtcpackets
*/
class SpacePacketBase : public SpacePacketIF, public RedirectableDataPointerIF {
class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF {
protected:
/**
* A pointer to a structure which defines the data structure of
@ -58,16 +58,18 @@ class SpacePacketBase : public SpacePacketIF, public RedirectableDataPointerIF {
* This is the minimum size of a SpacePacket.
*/
static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE;
SpacePacketReader(uint16_t apid, ccsds::PacketType packetType, bool secHeader, uint16_t seqCount,
uint16_t dataLen);
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed.
* @param set_address The position where the packet data lies.
*/
explicit SpacePacketBase(const uint8_t* set_address);
explicit SpacePacketReader(const uint8_t* set_address);
/**
* No data is allocated, so the destructor is empty.
*/
~SpacePacketBase() override;
~SpacePacketReader() override;
ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid,
uint16_t sequenceCount = 0);

View File

@ -6,7 +6,7 @@
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
CFDPPacket::CFDPPacket(const uint8_t* setData) : SpacePacketBase(setData) {}
CFDPPacket::CFDPPacket(const uint8_t* setData) : SpacePacketReader(setData) {}
CFDPPacket::~CFDPPacket() {}

View File

@ -1,9 +1,9 @@
#ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_
#define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
class CFDPPacket : public SpacePacketBase {
class CFDPPacket : public SpacePacketReader {
public:
/**
* This is the default constructor.

View File

@ -7,8 +7,8 @@
class TcPacketDeserializer : public SpacePacketIF, public RedirectableDataPointerIF {
public:
TcPacketDeserializer(const uint8_t* data, size_t maxSize);
private:
private:
};
#endif // FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H

View File

@ -37,7 +37,7 @@ uint8_t TcPacketPus::getAcknowledgeFlags() const {
const uint8_t *TcPacketPus::getApplicationData() const { return &tcData->appData; }
uint16_t TcPacketPus::getApplicationDataSize() const {
return SpacePacketBase::getPacketDataLen() - sizeof(tcData->dataField) - CRC_SIZE + 1;
return SpacePacketReader::getPacketDataLen() - sizeof(tcData->dataField) - CRC_SIZE + 1;
}
uint16_t TcPacketPus::getErrorControl() const {
@ -85,7 +85,7 @@ size_t TcPacketPus::calculateFullPacketLength(size_t appDataLen) const {
}
ReturnValue_t TcPacketPus::setData(uint8_t *dataPtr, size_t maxSize, void *args) {
ReturnValue_t result = SpacePacketBase::setData(dataPtr, maxSize, args);
ReturnValue_t result = SpacePacketReader::setData(dataPtr, maxSize, args);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}

View File

@ -6,7 +6,7 @@
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
TcPacketPusBase::TcPacketPusBase(const uint8_t* setData) : SpacePacketBase(setData) {}
TcPacketPusBase::TcPacketPusBase(const uint8_t* setData) : SpacePacketReader(setData) {}
TcPacketPusBase::~TcPacketPusBase() {}

View File

@ -5,7 +5,7 @@
#include <cstddef>
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
/**
* This class is the basic data handler for any ECSS PUS Telecommand packet.
@ -18,7 +18,7 @@
* check can be performed by making use of the getWholeData method.
* @ingroup tmtcpackets
*/
class TcPacketPusBase : public SpacePacketBase {
class TcPacketPusBase : public SpacePacketReader {
friend class TcPacketStoredBase;
public:

View File

@ -11,12 +11,12 @@
TimeStamperIF* TmPacketBase::timeStamper = nullptr;
object_id_t TmPacketBase::timeStamperId = objects::NO_OBJECT;
TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketBase(setData) {}
TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketReader(setData) {}
TmPacketBase::~TmPacketBase() = default;
uint16_t TmPacketBase::getSourceDataSize() {
return SpacePacketBase::getPacketDataLen() - getDataFieldSize() - CRC_SIZE + 1;
return SpacePacketReader::getPacketDataLen() - getDataFieldSize() - CRC_SIZE + 1;
}
uint16_t TmPacketBase::getErrorControl() {

View File

@ -4,7 +4,7 @@
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
namespace Factory {
@ -23,7 +23,7 @@ void setStaticFrameworkObjectIds();
* check can be performed by making use of the getWholeData method.
* @ingroup tmtcpackets
*/
class TmPacketBase : public SpacePacketBase {
class TmPacketBase : public SpacePacketReader {
friend void(Factory::setStaticFrameworkObjectIds)();
public:

View File

@ -5,7 +5,7 @@
#include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h"
TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketBase(set_data) {
TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketReader(set_data) {
this->tm_data = (TmPacketMinimalPointer*)set_data;
}

View File

@ -2,7 +2,7 @@
#define FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
#include "../../../returnvalues/HasReturnvaluesIF.h"
#include "../../SpacePacketBase.h"
#include "../../SpacePacketReader.h"
struct timeval;
class PacketTimestampInterpreterIF;
@ -12,7 +12,7 @@ class PacketTimestampInterpreterIF;
* This is required for handling TM packets with different APIDs with different
* secondary headers.
*/
class TmPacketMinimal : public SpacePacketBase {
class TmPacketMinimal : public SpacePacketReader {
public:
/**
* This is the default constructor.

View File

@ -25,11 +25,11 @@ uint8_t TmPacketPusA::getSubService() { return tmData->data_field.service_subtyp
uint8_t* TmPacketPusA::getSourceData() { return &tmData->data; }
uint16_t TmPacketPusA::getSourceDataSize() {
return SpacePacketBase::getPacketDataLen() - sizeof(tmData->data_field) - CRC_SIZE + 1;
return SpacePacketReader::getPacketDataLen() - sizeof(tmData->data_field) - CRC_SIZE + 1;
}
ReturnValue_t TmPacketPusA::setData(uint8_t* p_Data, size_t maxSize, void* args) {
ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize, args);
ReturnValue_t result = SpacePacketReader::setData(p_Data, maxSize, args);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}

View File

@ -5,7 +5,7 @@
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
namespace Factory {
void setStaticFrameworkObjectIds();

View File

@ -23,11 +23,11 @@ uint8_t TmPacketPusC::getSubService() { return tmData->dataField.serviceSubtype;
uint8_t* TmPacketPusC::getSourceData() { return &tmData->data; }
uint16_t TmPacketPusC::getSourceDataSize() {
return SpacePacketBase::getPacketDataLen() - sizeof(tmData->dataField) - CRC_SIZE + 1;
return SpacePacketReader::getPacketDataLen() - sizeof(tmData->dataField) - CRC_SIZE + 1;
}
ReturnValue_t TmPacketPusC::setData(uint8_t* p_Data, size_t maxSize, void* args) {
ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize, args);
ReturnValue_t result = SpacePacketReader::setData(p_Data, maxSize, args);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}

View File

@ -5,7 +5,7 @@
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
namespace Factory {
void setStaticFrameworkObjectIds();

View File

@ -1,7 +1,7 @@
#ifndef FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_
#define FSFW_TMTCSERVICES_SOURCESEQUENCECOUNTER_H_
#include "../tmtcpacket/SpacePacketBase.h"
#include "../tmtcpacket/SpacePacketReader.h"
class SourceSequenceCounter {
private:

View File

@ -1,11 +1,15 @@
#include <catch2/catch_test_macros.hpp>
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
TEST_CASE("CCSDS Test", "[ccsds]") {
SECTION("Constexpr Helpers") {
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822);
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822);
REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff);
REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff);
}
SECTION("Header Tests") { SpacePacketReader base = SpacePacketReader(); }
}