start PUS TC refactoring

This commit is contained in:
Robin Müller 2022-07-18 18:36:41 +02:00
parent 95b476d4bd
commit 5fffbd4a90
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
26 changed files with 213 additions and 678 deletions

View File

@ -136,8 +136,8 @@ 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/PusTcCreator.h
src/fsfw/tmtcpacket/pus/tc/PusTcCreator.cpp
src/fsfw/tmtcpacket/pus/tc/PusTcIF.h
src/fsfw/tmtcpacket/SpacePacketCreator.h
src/fsfw/tmtcpacket/SpacePacketCreator.cpp)

View File

@ -1,10 +1,10 @@
#ifndef FSFW_INC_FSFW_SERIALIZE_H_
#define FSFW_INC_FSFW_SERIALIZE_H_
#ifndef FSFW_SERIALIZE_H_
#define FSFW_SERIALIZE_H_
#include "src/core/serialize/EndianConverter.h"
#include "src/core/serialize/SerialArrayListAdapter.h"
#include "src/core/serialize/SerialBufferAdapter.h"
#include "src/core/serialize/SerialLinkedListAdapter.h"
#include "src/core/serialize/SerializeElement.h"
#include "serialize/EndianConverter.h"
#include "serialize/SerialArrayListAdapter.h"
#include "serialize/SerialBufferAdapter.h"
#include "serialize/SerialLinkedListAdapter.h"
#include "serialize/SerializeElement.h"
#endif /* FSFW_INC_FSFW_SERIALIZE_H_ */
#endif /* FSFW_SERIALIZE_H_ */

View File

@ -3,7 +3,7 @@
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h"
#include "fsfw/tmtcservices/VerificationCodes.h"

View File

@ -3,6 +3,8 @@
#include <cstdint>
#include "ccsds_header.h"
namespace ccsds {
enum PacketType : uint8_t { TM = 0, TC = 1 };
@ -35,6 +37,15 @@ constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeade
class SpacePacketIF {
public:
/**
* This definition defines the CRC size in byte.
*/
static const uint8_t CRC_SIZE = 2;
/**
* This is the minimum size of a SpacePacket.
*/
static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE;
virtual ~SpacePacketIF() = default;
/**

View File

@ -10,58 +10,10 @@ SpacePacketReader::SpacePacketReader(const uint8_t* setAddress) {
SpacePacketReader::~SpacePacketReader() = default;
ReturnValue_t SpacePacketReader::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
uint16_t apid, uint16_t sequenceCount) {
if (data == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpacePacketBase::initSpacePacketHeader: Data pointer is invalid" << std::endl;
#else
sif::printWarning("SpacePacketBase::initSpacePacketHeader: Data pointer is invalid!\n");
#endif
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
// reset header to zero:
memset(data, 0, sizeof(this->data->header));
// Set TC/TM bit.
data->header.packetIdHAndVersion = ((isTelecommand ? 1 : 0)) << 4;
// Set secondaryHeader bit
data->header.packetIdHAndVersion |= ((hasSecondaryHeader ? 1 : 0)) << 3;
this->setApid(apid);
// Always initialize as standalone packets.
data->header.packetSeqCtrlH = 0b11000000;
setPacketSequenceCount(sequenceCount);
return HasReturnvaluesIF::RETURN_OK;
}
inline uint16_t SpacePacketReader::getPacketId() const {
return ((this->data->header.packetIdHAndVersion) << 8) + this->data->header.packetIdL;
}
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 SpacePacketReader::setSequenceFlags(uint8_t sequenceflags) {
this->data->header.packetSeqCtrlH &= 0x3F;
this->data->header.packetSeqCtrlH |= sequenceflags << 6;
}
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 SpacePacketReader::setPacketDataLength(uint16_t new_length) {
this->data->header.packetLenH = ((new_length & 0xFF00) >> 8);
this->data->header.packetLenL = (new_length & 0x00FF);
}
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;

View File

@ -19,16 +19,6 @@
* standards.
*/
/**
* This struct defines the data structure of a Space Packet when accessed
* via a pointer.
* @ingroup tmtcpackets
*/
struct SpacePacketPointer {
CCSDSPrimaryHeader header;
uint8_t packet_data;
};
/**
* This class is the basic data handler for any CCSDS Space Packet
* compatible Telecommand and Telemetry packet.
@ -50,16 +40,6 @@ class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF
SpacePacketPointer* data;
public:
/**
* This definition defines the CRC size in byte.
*/
static const uint8_t CRC_SIZE = 2;
/**
* 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.
@ -71,45 +51,10 @@ class SpacePacketReader : public SpacePacketIF, public RedirectableDataPointerIF
*/
~SpacePacketReader() override;
ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid,
uint16_t sequenceCount = 0);
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
/**
* Sets the APID of a packet, which are the lowest 11 bit of the packet
* id.
* @param The APID to set. The highest five bits of the parameter are
* ignored.
*/
void setApid(uint16_t setAPID);
/**
* Sets the sequence flags of a packet, which are bit 17 and 18 in the space packet header.
* @param The sequence flags to set
*/
void setSequenceFlags(uint8_t sequenceflags);
/**
* Sets the packet sequence count, which are the lowest 14 bit of the
* packet sequence control field.
* setCount is modulo-divided by \c LIMIT_SEQUENCE_COUNT to avoid overflows.
* @param setCount The value to set the count to.
*/
void setPacketSequenceCount(uint16_t setCount);
/**
* Sets the packet data length, which is the fifth and sixth byte of the
* CCSDS Primary Header.
* @param setLength The value of the length to set. It must fit the true
* CCSDS packet data length . The packet data length is
* the size of every kind of data \b after the CCSDS
* Primary Header \b -1.
*/
void setPacketDataLength(uint16_t setLength);
// Helper methods:
/**
* This method returns a raw uint8_t pointer to the packet.

View File

@ -1,3 +1,4 @@
target_sources(
${LIB_FSFW_NAME} PRIVATE TcPacketPusBase.cpp TcPacketPus.cpp
${LIB_FSFW_NAME}
PRIVATE PusTcReader.cpp TcPacketPus.cpp PusTcReader.cpp PusTcCreator.cpp
TcPacketStoredBase.cpp TcPacketStoredPus.cpp)

View File

@ -1,3 +1,3 @@
#include "TcPacketDeserializer.h"
#include "PusTcCreator.h"
TcPacketDeserializer::TcPacketDeserializer(const uint8_t *data, size_t maxSize) {}

View File

@ -4,9 +4,9 @@
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/SpacePacketIF.h"
class TcPacketDeserializer : public SpacePacketIF, public RedirectableDataPointerIF {
class PusTcCreator : public SpacePacketIF {
public:
TcPacketDeserializer(const uint8_t* data, size_t maxSize);
PusTcCreator(const uint8_t* data, size_t maxSize);
private:
};

View File

@ -3,17 +3,50 @@
#include <cstdint>
class PusTcIF {
public:
virtual ~PusTcIF() = default;
#include "TcPacketPus.h"
namespace ecss {
enum AckField {
//! No acknowledgements are expected.
ACK_NONE = 0b0000,
//! Acknowledgements on acceptance are expected.
ACK_ACCEPTANCE = 0b0001,
//! Acknowledgements on start are expected.
ACK_START = 0b0010,
//! Acknowledgements on step are expected.
ACK_STEP = 0b0100,
//! Acknowledgement on completion are expected.
ACK_COMPLETION = 0b1000
};
static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP | ACK_COMPLETION;
/**
* This command returns the CCSDS Secondary Header Flag.
* It shall always be zero for PUS Packets. This is the
* highest bit of the first byte of the Data Field Header.
* @return the CCSDS Secondary Header Flag
* This struct defines a byte-wise structured PUS C ata Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, the Source Id field is present with one byte.
* No spare byte support for now.
* @ingroup tmtcpackets
*/
[[nodiscard]] virtual uint8_t getSecondaryHeaderFlag() const = 0;
struct PusTcDataFieldHeader {
// Version and ACK byte, Service Byte, Subservice Byte, 2 byte Source ID
static constexpr size_t MIN_LEN = 5;
uint8_t pusVersion;
uint8_t ackFlags;
uint8_t serviceType;
uint8_t serviceSubtype;
uint16_t sourceId;
};
} // namespace ecss
class PusTcIF : public SpacePacketIF {
public:
~PusTcIF() override = default;
static const uint16_t MIN_LEN =
(sizeof(CCSDSPrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2);
/**
* This command returns the TC Packet PUS Version Number.
* The version number of ECSS PUS 2003 is 1.

View File

@ -0,0 +1,47 @@
#include "PusTcReader.h"
#include <cstring>
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serialize.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
PusTcReader::PusTcReader(const uint8_t* setData, size_t size) : spReader(setData), maxSize(size) {
pointers.spHeaderStart = setData;
}
PusTcReader::~PusTcReader() = default;
ReturnValue_t PusTcReader::parseData() {
if (maxSize < sizeof(CCSDSPrimaryHeader)) {
return SerializeIF::BUFFER_TOO_SHORT;
}
pointers.secHeaderStart = pointers.spHeaderStart + sizeof(CCSDSPrimaryHeader);
// TODO: No support for spare bytes yet
pointers.userDataStart = pointers.secHeaderStart + ecss::PusTcDataFieldHeader::MIN_LEN;
}
uint8_t PusTcReader::getAcknowledgeFlags() const { return 0; }
uint8_t PusTcReader::getService() const { return 0; }
uint8_t PusTcReader::getSubService() const { return 0; }
uint16_t PusTcReader::getSourceId() const { return 0; }
const uint8_t* PusTcReader::getApplicationData() const { return nullptr; }
uint16_t PusTcReader::getApplicationDataSize() const { return 0; }
uint16_t PusTcReader::getErrorControl() const { return 0; }
uint16_t PusTcReader::getPacketId() const { return spReader.getPacketId(); }
uint16_t PusTcReader::getPacketSeqCtrl() const { return spReader.getPacketSeqCtrl(); }
uint16_t PusTcReader::getPacketDataLen() const { return spReader.getPacketDataLen(); }
uint8_t PusTcReader::getPusVersion() const { return spReader.getVersion(); }
/*
void PusTcReader::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TcPacketBase::print:" << std::endl;
#else
sif::printInfo("TcPacketBase::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
}
*/

View File

@ -0,0 +1,82 @@
#ifndef TMTCPACKET_PUS_TCPACKETBASE_H_
#define TMTCPACKET_PUS_TCPACKETBASE_H_
#include <cstddef>
#include "PusTcIF.h"
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
/**
* This class is the basic data handler for any ECSS PUS Telecommand packet.
*
* In addition to #SpacePacketBase, the class provides methods to handle
* the standardized entries of the PUS TC Packet Data Field Header.
* It does not contain the packet data itself but a pointer to the
* data must be set on instantiation. An invalid pointer may cause
* damage, as no getter method checks data validity. Anyway, a NULL
* check can be performed by making use of the getWholeData method.
* @ingroup tmtcpackets
*/
class PusTcReader : public PusTcIF, public RedirectableDataPointerIF {
friend class TcPacketStoredBase;
public:
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param setData The position where the packet data lies.
*/
explicit PusTcReader(const uint8_t* setData, size_t size);
ReturnValue_t parseData();
/**
* This is the empty default destructor.
*/
~PusTcReader() override;
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
[[nodiscard]] uint8_t getPusVersion() const override;
[[nodiscard]] uint8_t getAcknowledgeFlags() const override;
[[nodiscard]] uint8_t getService() const override;
[[nodiscard]] uint8_t getSubService() const override;
[[nodiscard]] uint16_t getSourceId() const override;
[[nodiscard]] const uint8_t* getApplicationData() const override;
[[nodiscard]] uint16_t getApplicationDataSize() const override;
[[nodiscard]] uint16_t getErrorControl() const override;
protected:
/**
* With this method, the packet data pointer can be redirected to another
* location.
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telecommand Packet.
*/
ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args) override = 0;
SpacePacketReader spReader;
/**
* This struct defines the data structure of a Space Packet when accessed
* via a pointer.
* @ingroup tmtcpackets
*/
struct PusTcPointers {
const uint8_t* spHeaderStart;
const uint8_t* secHeaderStart;
const uint8_t* userDataStart;
};
PusTcPointers pointers{};
size_t maxSize = 0;
};
#endif /* TMTCPACKET_PUS_TCPACKETBASE_H_ */

View File

@ -4,44 +4,25 @@
#include <cstdint>
#include "../definitions.h"
#include "TcPacketPusBase.h"
#include "PusTcReader.h"
#include "fsfw/FSFW.h"
#include "fsfw/tmtcpacket/ccsds_header.h"
/**
* This struct defines a byte-wise structured PUS TC A Data Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, the Source Id field is present with one byte.
* @ingroup tmtcpackets
*/
struct PUSTcDataFieldHeader {
uint8_t versionTypeAck;
uint8_t serviceType;
uint8_t serviceSubtype;
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
uint8_t sourceIdH;
uint8_t sourceIdL;
#else
uint8_t sourceId;
#endif
};
/**
* This struct defines the data structure of a PUS Telecommand A packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
/*
struct TcPacketPointer {
CCSDSPrimaryHeader primary;
PUSTcDataFieldHeader dataField;
PusTcDataFieldHeader dataField;
uint8_t appData;
};
*/
class TcPacketPus : public TcPacketPusBase {
public:
static const uint16_t TC_PACKET_MIN_SIZE =
(sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + 2);
/**
* Initialize a PUS A telecommand packet which already exists. You can also
* create an empty (invalid) object by passing nullptr as the data pointer

View File

@ -1,20 +0,0 @@
#include "TcPacketPusBase.h"
#include <cstring>
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
TcPacketPusBase::TcPacketPusBase(const uint8_t* setData) : SpacePacketReader(setData) {}
TcPacketPusBase::~TcPacketPusBase() {}
void TcPacketPusBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TcPacketBase::print:" << std::endl;
#else
sif::printInfo("TcPacketBase::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
}

View File

@ -1,151 +0,0 @@
#ifndef TMTCPACKET_PUS_TCPACKETBASE_H_
#define TMTCPACKET_PUS_TCPACKETBASE_H_
#include <fsfw/tmtcpacket/RedirectableDataPointerIF.h>
#include <cstddef>
#include "fsfw/tmtcpacket/SpacePacketReader.h"
/**
* This class is the basic data handler for any ECSS PUS Telecommand packet.
*
* In addition to #SpacePacketBase, the class provides methods to handle
* the standardized entries of the PUS TC Packet Data Field Header.
* It does not contain the packet data itself but a pointer to the
* data must be set on instantiation. An invalid pointer may cause
* damage, as no getter method checks data validity. Anyway, a NULL
* check can be performed by making use of the getWholeData method.
* @ingroup tmtcpackets
*/
class TcPacketPusBase : public SpacePacketReader {
friend class TcPacketStoredBase;
public:
enum AckField {
//! No acknowledgements are expected.
ACK_NONE = 0b0000,
//! Acknowledgements on acceptance are expected.
ACK_ACCEPTANCE = 0b0001,
//! Acknowledgements on start are expected.
ACK_START = 0b0010,
//! Acknowledgements on step are expected.
ACK_STEP = 0b0100,
//! Acknowledfgement on completion are expected.
ACK_COMPLETION = 0b1000
};
static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP | ACK_COMPLETION;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param setData The position where the packet data lies.
*/
TcPacketPusBase(const uint8_t* setData);
/**
* This is the empty default destructor.
*/
virtual ~TcPacketPusBase();
/**
* This command returns the CCSDS Secondary Header Flag.
* It shall always be zero for PUS Packets. This is the
* highest bit of the first byte of the Data Field Header.
* @return the CCSDS Secondary Header Flag
*/
virtual uint8_t getSecondaryHeaderFlag() const = 0;
/**
* This command returns the TC Packet PUS Version Number.
* The version number of ECSS PUS 2003 is 1.
* It consists of the second to fourth highest bits of the
* first byte.
* @return
*/
virtual uint8_t getPusVersionNumber() const = 0;
/**
* This is a getter for the packet's Ack field, which are the lowest four
* bits of the first byte of the Data Field Header.
*
* It is packed in a uint8_t variable.
* @return The packet's PUS Ack field.
*/
virtual uint8_t getAcknowledgeFlags() const = 0;
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
virtual uint8_t getService() const = 0;
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
virtual uint8_t getSubService() const = 0;
/**
* The source ID can be used to have an additional identifier, e.g. for different ground
* station.
* @return
*/
virtual uint16_t getSourceId() const = 0;
/**
* This is a getter for a pointer to the packet's Application data.
*
* These are the bytes that follow after the Data Field Header. They form
* the packet's application data.
* @return A pointer to the PUS Application Data.
*/
virtual const uint8_t* getApplicationData() const = 0;
/**
* This method calculates the size of the PUS Application data field.
*
* It takes the information stored in the CCSDS Packet Data Length field
* and subtracts the Data Field Header size and the CRC size.
* @return The size of the PUS Application Data (without Error Control
* field)
*/
virtual uint16_t getApplicationDataSize() const = 0;
/**
* This getter returns the Error Control Field of the packet.
*
* The field is placed after any possible Application Data. If no
* Application Data is present there's still an Error Control field. It is
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
virtual uint16_t getErrorControl() const = 0;
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet.
*/
virtual void setErrorControl() = 0;
/**
* Calculate full packet length from application data length.
* @param appDataLen
* @return
*/
virtual size_t calculateFullPacketLength(size_t appDataLen) const = 0;
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
protected:
/**
* With this method, the packet data pointer can be redirected to another
* location.
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telecommand Packet.
*/
virtual ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override = 0;
};
#endif /* TMTCPACKET_PUS_TCPACKETBASE_H_ */

View File

@ -1,6 +1,7 @@
#ifndef TMTCPACKET_PUS_TCPACKETSTORED_H_
#define TMTCPACKET_PUS_TCPACKETSTORED_H_
#include "PusTcReader.h"
#include "TcPacketStoredIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"

View File

@ -3,7 +3,7 @@
#include <fsfw/tmtcpacket/RedirectableDataPointerIF.h>
#include "TcPacketPusBase.h"
#include "PusTcReader.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/storagemanager/storeAddress.h"

View File

@ -1,9 +1,4 @@
target_sources(
${LIB_FSFW_NAME}
PRIVATE TmPacketStoredPusA.cpp
TmPacketStoredPusC.cpp
TmPacketPusA.cpp
TmPacketPusC.cpp
TmPacketStoredBase.cpp
TmPacketBase.cpp
TmPacketMinimal.cpp)
PRIVATE TmPacketStoredPusC.cpp TmPacketPusC.cpp TmPacketStoredBase.cpp
TmPacketBase.cpp TmPacketMinimal.cpp)

View File

@ -1,68 +0,0 @@
#include "TmPacketPusA.h"
#include <cstring>
#include "../definitions.h"
#include "TmPacketBase.h"
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/objectmanager/ObjectManagerIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h"
TmPacketPusA::TmPacketPusA(uint8_t* setData) : TmPacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointerPusA*>(setData);
}
TmPacketPusA::~TmPacketPusA() {
// Nothing to do.
}
uint8_t TmPacketPusA::getService() { return tmData->data_field.service_type; }
uint8_t TmPacketPusA::getSubService() { return tmData->data_field.service_subtype; }
uint8_t* TmPacketPusA::getSourceData() { return &tmData->data; }
uint16_t TmPacketPusA::getSourceDataSize() {
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 = SpacePacketReader::setData(p_Data, maxSize, args);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
tmData = reinterpret_cast<TmPacketPointerPusA*>(const_cast<uint8_t*>(p_Data));
return HasReturnvaluesIF::RETURN_OK;
}
size_t TmPacketPusA::getPacketMinimumSize() const { return TM_PACKET_MIN_SIZE; }
uint16_t TmPacketPusA::getDataFieldSize() { return sizeof(PUSTmDataFieldHeaderPusA); }
uint8_t* TmPacketPusA::getPacketTimeRaw() const { return tmData->data_field.time; }
void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter) {
// Set primary header:
initSpacePacketHeader(false, true, apid);
// Set data Field Header:
// First, set to zero.
memset(&tmData->data_field, 0, sizeof(tmData->data_field));
tmData->data_field.version_type_ack = pus::PusVersion::PUS_A_VERSION << 4;
tmData->data_field.service_type = service;
tmData->data_field.service_subtype = subservice;
tmData->data_field.subcounter = packetSubcounter;
// Timestamp packet
if (TmPacketBase::checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->data_field.time, sizeof(tmData->data_field.time));
}
}
void TmPacketPusA::setSourceDataSize(uint16_t size) {
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
size_t TmPacketPusA::getTimestampSize() const { return sizeof(tmData->data_field.time); }

View File

@ -1,129 +0,0 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_
#include "TmPacketBase.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
namespace Factory {
void setStaticFrameworkObjectIds();
}
/**
* This struct defines a byte-wise structured PUS TM Data Field Header.
* Any optional fields in the header must be added or removed here.
* Currently, no Destination field is present, but an eigth-byte representation
* for a time tag.
* @ingroup tmtcpackets
*/
struct PUSTmDataFieldHeaderPusA {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t subcounter;
// uint8_t destination;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
};
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TmPacketPointerPusA {
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeaderPusA data_field;
uint8_t data;
};
/**
* PUS A packet implementation
* @ingroup tmtcpackets
*/
class TmPacketPusA : public TmPacketBase {
friend void(Factory::setStaticFrameworkObjectIds)();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE =
(sizeof(CCSDSPrimaryHeader) + sizeof(PUSTmDataFieldHeaderPusA) + 2);
//! Maximum size of a TM Packet in this mission.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketPusA(uint8_t* setData);
/**
* This is the empty default destructor.
*/
virtual ~TmPacketPusA();
/* TmPacketBase implementations */
uint8_t getService() override;
uint8_t getSubService() override;
uint8_t* getSourceData() override;
uint16_t getSourceDataSize() override;
uint16_t getDataFieldSize() override;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const override;
size_t getTimestampSize() const override;
size_t getPacketMinimumSize() const override;
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointerPusA* tmData;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
*/
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter);
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telemetry Packet.
*/
ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override;
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
/**
* Checks if a time stamper is available and tries to set it if not.
* @return Returns false if setting failed.
*/
bool checkAndSetStamper();
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_ */

View File

@ -2,7 +2,6 @@
#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_
#include "TmPacketBase.h"
#include "TmPacketPusA.h"
#include "TmPacketStoredBase.h"
#include "fsfw/FSFW.h"
#include "fsfw/internalerror/InternalErrorReporterIF.h"

View File

@ -1,73 +0,0 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h"
#include <cstring>
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress)
: TmPacketStoredBase(setAddress), TmPacketPusA(nullptr) {}
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter, const uint8_t *data, uint32_t size,
const uint8_t *headerData, uint32_t headerSize)
: TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header)
: TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != nullptr) {
sourceDataSize += content->getSerializedSize();
}
if (header != nullptr) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG);
}
if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG);
}
setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
uint8_t *TmPacketStoredPusA::getAllTmData() { return getWholeData(); }
ReturnValue_t TmPacketStoredPusA::setData(uint8_t *newPointer, size_t maxSize, void *args) {
return TmPacketPusA::setData(newPointer, maxSize);
}

View File

@ -1,69 +0,0 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_
#include <FSFWConfig.h>
#include "TmPacketPusA.h"
#include "TmPacketStoredBase.h"
/**
* This class generates a ECSS PUS A Telemetry packet within a given
* intermediate storage.
* As most packets are passed between tasks with the help of a storage
* anyway, it seems logical to create a Packet-In-Storage access class
* which saves the user almost all storage handling operation.
* Packets can both be newly created with the class and be "linked" to
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStoredPusA : public TmPacketStoredBase, public TmPacketPusA {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusA(store_address_t setAddress);
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* The Application data is passed in two parts, first a header, then a
* data field. This allows building a Telemetry Packet from two separate
* data sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
*/
TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter = 0,
const uint8_t* data = nullptr, uint32_t size = 0,
const uint8_t* headerData = nullptr, uint32_t headerSize = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter,
SerializeIF* content, SerializeIF* header = nullptr);
uint8_t* getAllTmData() override;
private:
/**
* Implementation required by base class
* @param newPointer
* @param maxSize
* @param args
* @return
*/
ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args = nullptr) override;
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ */

View File

@ -4,7 +4,7 @@
#include "VerificationCodes.h"
#include "fsfw/ipc/MessageQueueMessage.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tmtcpacket/pus/tc/TcPacketPusBase.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h"
class PusVerificationMessage : public MessageQueueMessage {
private:

View File

@ -4,7 +4,6 @@
#include "fsfw/tmtcpacket/SpacePacketCreator.h"
TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02,
ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);

View File

@ -1,6 +1,5 @@
#include <catch2/catch_test_macros.hpp>
#include "fsfw/tmtcpacket/SpacePacketReader.h"
TEST_CASE("CCSDS Reader", "[ccsds-reader]") {
}
TEST_CASE("CCSDS Reader", "[ccsds-reader]") {}