Refactor TMTC Stack, improve test framework #655

Merged
mohr merged 150 commits from mueller/refactor-tmtc-stack into development 2022-09-12 14:31:23 +02:00
46 changed files with 615 additions and 355 deletions
Showing only changes of commit d80941514f - Show all commits

View File

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

View File

@ -5,33 +5,25 @@
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcpacket/pus/tm/TmPacketStored.h"
Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId)
: PusServiceBase(objectId, apid, serviceId), packetSubCounter(0) {}
Service17Test::Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId,
StorageManagerIF* tmStore, StorageManagerIF* ipcStore,
InternalErrorReporterIF* errReporter)
: PusServiceBase(objectId, apid, serviceId, ipcStore),
helper(tmStore, MessageQueueIF::NO_QUEUE, MessageQueueIF::NO_QUEUE, errReporter),
packetSubCounter(0) {}
Service17Test::~Service17Test() {}
Service17Test::~Service17Test() = default;
ReturnValue_t Service17Test::handleRequest(uint8_t subservice) {
switch (subservice) {
case Subservice::CONNECTION_TEST: {
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT,
packetSubCounter++);
#else
TmPacketStoredPusC connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT,
packetSubCounter++);
#endif
connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId());
helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter);
helper.sendPacket();
return HasReturnvaluesIF::RETURN_OK;
}
case Subservice::EVENT_TRIGGER_TEST: {
#if FSFW_USE_PUS_C_TELEMETRY == 0
TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT,
packetSubCounter++);
#else
TmPacketStoredPusC connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT,
packetSubCounter++);
#endif
connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId());
helper.preparePacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++);
helper.sendPacket();
triggerEvent(TEST, 1234, 5678);
return RETURN_OK;
}
@ -41,3 +33,12 @@ ReturnValue_t Service17Test::handleRequest(uint8_t subservice) {
}
ReturnValue_t Service17Test::performService() { return HasReturnvaluesIF::RETURN_OK; }
ReturnValue_t Service17Test::initialize() {
ReturnValue_t result = PusServiceBase::initialize();
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
helper.setMsgDestination(requestQueue->getDefaultDestination());
helper.setMsgSource(requestQueue->getId());
if (tm) }

View File

@ -3,6 +3,7 @@
#include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/tmtcservices/PusServiceBase.h"
#include "fsfw/tmtcservices/TmStoreHelper.h"
/**
* @brief Test Service
@ -32,12 +33,16 @@ class Service17Test : public PusServiceBase {
EVENT_TRIGGER_TEST = 128,
};
Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId);
virtual ~Service17Test();
virtual ReturnValue_t handleRequest(uint8_t subservice) override;
virtual ReturnValue_t performService() override;
Service17Test(object_id_t objectId, uint16_t apid, uint8_t serviceId,
InternalErrorReporterIF* errReporter, StorageManagerIF* tmStore = nullptr,
StorageManagerIF* ipcStore = nullptr);
~Service17Test() override;
ReturnValue_t handleRequest(uint8_t subservice) override;
ReturnValue_t performService() override;
ReturnValue_t initialize() override;
protected:
TmStoreHelper helper;
uint16_t packetSubCounter = 0;
};

View File

@ -2,7 +2,7 @@
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
#define CCSDS_DISTRIBUTOR_DEBUGGING 0

View File

@ -1,7 +1,7 @@
#include "CcsdsPacketCheckerBase.h"
#include "fsfw/tcdistribution/definitions.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
CcsdsPacketCheckerBase::CcsdsPacketCheckerBase(uint16_t apid, ccsds::PacketType packetType_,
uint8_t ccsdsVersion_)

View File

@ -2,7 +2,7 @@
#define FSFW_TESTS_CCSDSPACKETCHECKERBASE_H
#include "CcsdsPacketCheckIF.h"
#include "fsfw/tmtcpacket/SpacePacketIF.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h"
class CcsdsPacketCheckerBase : public CcsdsPacketCheckIF, public HasReturnvaluesIF {
public:

View File

@ -1,7 +1,6 @@
target_sources(
${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp SpacePacketCreator.cpp
PacketStorageHelper.cpp)
target_sources(${LIB_FSFW_NAME} PRIVATE PacketStorageHelper.cpp)
add_subdirectory(ccsds)
add_subdirectory(pus)
add_subdirectory(cfdp)
add_subdirectory(packetmatcher)
add_subdirectory(pus)

View File

@ -1,7 +1,7 @@
#ifndef FSFW_TMTCPACKET_SPACEPACKETREADERIF_H
#define FSFW_TMTCPACKET_SPACEPACKETREADERIF_H
#include "SpacePacketIF.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h"
class ReadablePacketIF {
public:

View File

@ -1,87 +0,0 @@
#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H
#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H
#include "SpacePacketIF.h"
#include "fsfw/serialize/SerializeIF.h"
struct PacketId {
public:
/**
* Simple wrapper for Space Packet IDs. Does not check the APID for validity
* @param packetType_
* @param secHeaderFlag_
* @param apid_
*/
PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_)
: packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {}
/**
* NOTE: If the APID has an invalid value, the invalid bits will be cut off
* @return
*/
[[nodiscard]] uint16_t raw() const {
return (static_cast<uint16_t>(packetType) << 12) |
(static_cast<uint16_t>(secHeaderFlag) << 11) | (apid & 0x7ff);
}
ccsds::PacketType packetType;
bool secHeaderFlag;
uint16_t apid;
};
struct PacketSeqCtrl {
public:
PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount)
: seqFlags(seqFlags), seqCount(seqCount) {}
/**
* NOTE: If the sequence control has an invalid value, the invalid bits will be cut off
* @return
*/
[[nodiscard]] uint16_t raw() const {
return (static_cast<uint16_t>(seqFlags) << 14) | (seqCount & 0x3FFF);
}
ccsds::SequenceFlags seqFlags;
uint16_t seqCount;
};
struct SpacePacketParams {
PacketId packetId;
PacketSeqCtrl packetSeqCtrl;
uint16_t dataLen;
uint8_t version = 0b000;
};
class SpacePacketCreator : public SpacePacketIF, public SerializeIF {
public:
/*
SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid,
ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen,
uint8_t version = 0);
*/
explicit SpacePacketCreator(SpacePacketParams &params);
[[nodiscard]] bool isValid() const;
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
void setApid(uint16_t apid);
void setSeqCount(uint16_t seqCount);
void setSeqFlags(ccsds::SequenceFlags flags);
void setDataLen(uint16_t dataLen);
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const;
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
[[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
private:
void checkFieldValidity();
bool valid{};
SpacePacketParams params;
};
#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H

View File

@ -0,0 +1,2 @@
target_sources(${LIB_FSFW_NAME} PRIVATE SpacePacketReader.cpp
SpacePacketCreator.cpp header.cpp)

View File

@ -0,0 +1,68 @@
#ifndef FSFW_TMTCPACKET_PACKETID_H
#define FSFW_TMTCPACKET_PACKETID_H
#include <cstddef>
#include "defs.h"
#include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/serialize/SerializeIF.h"
struct PacketId : public SerializeIF {
public:
PacketId() = default;
/**
* Simple wrapper for Space Packet IDs. Does not check the APID for validity
* @param packetType_
* @param secHeaderFlag_
* @param apid_
*/
PacketId(ccsds::PacketType packetType_, bool secHeaderFlag_, uint16_t apid_)
: packetType(packetType_), secHeaderFlag(secHeaderFlag_), apid(apid_) {}
/**
* NOTE: If the APID has an invalid value, the invalid bits will be cut off
* @return
*/
[[nodiscard]] uint16_t raw() const {
return (static_cast<uint16_t>(packetType) << 12) |
(static_cast<uint16_t>(secHeaderFlag) << 11) | (apid & 0x7ff);
}
static PacketId fromRaw(uint16_t raw) {
uint8_t highByte = (raw >> 8) & 0xff;
uint8_t lowByte = raw & 0xff;
return {static_cast<ccsds::PacketType>((highByte >> 4) & 0b1),
static_cast<bool>((highByte >> 3) & 0b1),
static_cast<uint16_t>((highByte & 0b111) << 8 | lowByte)};
}
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
uint16_t pscRaw = raw();
return SerializeAdapter::serialize(&pscRaw, buffer, size, maxSize, streamEndianness);
}
[[nodiscard]] size_t getSerializedSize() const override { return 2; }
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override {
if (*size < 2) {
return SerializeIF::STREAM_TOO_SHORT;
}
uint8_t highByte = **buffer;
*buffer += 1;
uint8_t lowByte = **buffer;
*buffer += 1;
*size -= 2;
packetType = static_cast<ccsds::PacketType>((highByte >> 4) & 0b1);
secHeaderFlag = (highByte >> 3) & 0b1;
apid = static_cast<uint16_t>((highByte & 0b111) << 8 | lowByte);
return HasReturnvaluesIF::RETURN_OK;
}
ccsds::PacketType packetType = ccsds::PacketType::TM;
bool secHeaderFlag = false;
uint16_t apid = 0;
};
#endif // FSFW_TMTCPACKET_PACKETID_H

View File

@ -0,0 +1,56 @@
#ifndef FSFW_TMTCPACKET_PACKETSEQCTRL_H
#define FSFW_TMTCPACKET_PACKETSEQCTRL_H
#include "defs.h"
#include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/serialize/SerializeIF.h"
struct PacketSeqCtrl : public SerializeIF {
public:
PacketSeqCtrl() = default;
PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount)
: seqFlags(seqFlags), seqCount(seqCount) {}
/**
* NOTE: If the sequence control has an invalid value, the invalid bits will be cut off
* @return
*/
[[nodiscard]] uint16_t raw() const {
return (static_cast<uint16_t>(seqFlags) << 14) | (seqCount & 0x3FFF);
}
static PacketSeqCtrl fromRaw(uint16_t raw) {
uint8_t highByte = (raw >> 8) & 0xff;
uint8_t lowByte = raw & 0xff;
return {static_cast<ccsds::SequenceFlags>((highByte >> 6) & 0b11),
static_cast<uint16_t>(((highByte << 8) | lowByte) & 0x3FFF)};
}
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
uint16_t packetIdRaw = raw();
return SerializeAdapter::serialize(&packetIdRaw, buffer, size, maxSize, streamEndianness);
}
[[nodiscard]] size_t getSerializedSize() const override { return 2; }
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override {
if (*size < 2) {
return SerializeIF::STREAM_TOO_SHORT;
}
uint8_t highByte = **buffer;
*buffer += 1;
uint8_t lowByte = **buffer;
*buffer += 1;
*size -= 2;
seqFlags = static_cast<ccsds::SequenceFlags>((highByte >> 6) & 0b11);
seqCount = ((highByte << 8) | lowByte) & 0x3FFF;
return HasReturnvaluesIF::RETURN_OK;
}
ccsds::SequenceFlags seqFlags = ccsds::SequenceFlags::CONTINUATION;
uint16_t seqCount = 0;
};
#endif // FSFW_TMTCPACKET_PACKETSEQCTRL_H

View File

@ -1,13 +1,23 @@
#include "SpacePacketCreator.h"
#include <utility>
#include "fsfw/serialize/SerializeAdapter.h"
SpacePacketCreator::SpacePacketCreator(SpacePacketParams &params_) : params(params_) {
SpacePacketCreator::SpacePacketCreator(SpacePacketParams params_) : params(std::move(params_)) {
checkFieldValidity();
}
uint16_t SpacePacketCreator::getPacketId() const { return params.packetId.raw(); }
uint16_t SpacePacketCreator::getPacketSeqCtrl() const { return params.packetSeqCtrl.raw(); }
SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag,
uint16_t apid, ccsds::SequenceFlags seqFlags,
uint16_t seqCount, uint16_t dataLen, uint8_t version)
: params(SpacePacketParams(PacketId(packetType, secHeaderFlag, apid),
PacketSeqCtrl(seqFlags, seqCount), dataLen)) {
params.version = version;
}
uint16_t SpacePacketCreator::getPacketIdRaw() const { return params.packetId.raw(); }
uint16_t SpacePacketCreator::getPacketSeqCtrlRaw() const { return params.packetSeqCtrl.raw(); }
uint16_t SpacePacketCreator::getPacketDataLen() const { return params.dataLen; }
ReturnValue_t SpacePacketCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,

View File

@ -0,0 +1,53 @@
#ifndef FSFW_TMTCPACKET_SPACEPACKETCREATOR_H
#define FSFW_TMTCPACKET_SPACEPACKETCREATOR_H
#include <utility>
#include "PacketId.h"
#include "PacketSeqCtrl.h"
#include "SpacePacketIF.h"
#include "fsfw/serialize/SerializeIF.h"
struct SpacePacketParams {
SpacePacketParams(PacketId packetId, PacketSeqCtrl psc, uint16_t dataLen)
: packetId(std::move(packetId)), packetSeqCtrl(std::move(psc)), dataLen(dataLen) {}
PacketId packetId{};
PacketSeqCtrl packetSeqCtrl{};
uint16_t dataLen = 0;
uint8_t version = 0b000;
};
class SpacePacketCreator : public SpacePacketIF, public SerializeIF {
public:
explicit SpacePacketCreator(SpacePacketParams params);
SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid,
ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen,
uint8_t version = 0);
[[nodiscard]] bool isValid() const;
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
void setApid(uint16_t apid);
void setSeqCount(uint16_t seqCount);
void setSeqFlags(ccsds::SequenceFlags flags);
void setDataLen(uint16_t dataLen);
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const;
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
[[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
private:
void checkFieldValidity();
SpacePacketCreator() = default;
bool valid{};
SpacePacketParams params;
};
#endif // FSFW_TMTCPACKET_SPACEPACKETCREATOR_H

View File

@ -4,37 +4,10 @@
#include <cstddef>
#include <cstdint>
#include "ccsds_header.h"
namespace ccsds {
enum PacketType : uint8_t { TM = 0, TC = 1 };
enum SequenceFlags : uint8_t {
CONTINUATION = 0b00,
FIRST_SEGMENT = 0b01,
LAST_SEGMENT = 0b10,
UNSEGMENTED = 0b11
};
static const uint16_t LIMIT_APID = 2048; // 2^11
static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14
static const uint16_t APID_IDLE_PACKET = 0x7FF;
constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid,
bool secondaryHeaderFlag = true) {
return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
}
constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag);
}
constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag);
}
} // namespace ccsds
#include "PacketId.h"
#include "PacketSeqCtrl.h"
#include "fsfw/tmtcpacket/ccsds/defs.h"
#include "header.h"
class SpacePacketIF {
public:
@ -45,7 +18,7 @@ class SpacePacketIF {
/**
* This is the minimum size of a SpacePacket.
*/
static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE;
static const uint16_t MINIMUM_SIZE = sizeof(ccsds::PrimaryHeader) + CRC_SIZE;
virtual ~SpacePacketIF() = default;
@ -54,21 +27,25 @@ class SpacePacketIF {
* the CCSDS packet ID
* @return The CCSDS packet ID
*/
[[nodiscard]] virtual uint16_t getPacketId() const = 0;
[[nodiscard]] virtual uint16_t getPacketIdRaw() const = 0;
/**
* Returns the third and the fourth byte of the CCSDS header which are the packet sequence
* control field
* @return
*/
[[nodiscard]] virtual uint16_t getPacketSeqCtrl() const = 0;
[[nodiscard]] virtual uint16_t getPacketSeqCtrlRaw() const = 0;
/**
* Returns the fifth and the sixth byte of the CCSDS header which is the packet length field
* @return
*/
[[nodiscard]] virtual uint16_t getPacketDataLen() const = 0;
virtual PacketId getPacketId() { return PacketId::fromRaw(getPacketIdRaw()); }
virtual PacketSeqCtrl getPacketSeqCtrl() { return PacketSeqCtrl::fromRaw(getPacketSeqCtrlRaw()); }
[[nodiscard]] virtual uint16_t getApid() const {
uint16_t packetId = getPacketId();
uint16_t packetId = getPacketIdRaw();
// Uppermost 11 bits of packet ID
return ((packetId >> 8) & 0b111) | (packetId & 0xFF);
}
@ -78,12 +55,12 @@ class SpacePacketIF {
* @return
*/
[[nodiscard]] virtual uint8_t getVersion() const {
uint16_t packetId = getPacketId();
uint16_t packetId = getPacketIdRaw();
return (packetId >> 13) & 0b111;
}
[[nodiscard]] virtual ccsds::PacketType getPacketType() const {
return static_cast<ccsds::PacketType>((getPacketId() >> 12) & 0b1);
return static_cast<ccsds::PacketType>((getPacketIdRaw() >> 12) & 0b1);
}
[[nodiscard]] virtual bool isTc() const { return getPacketType() == ccsds::PacketType::TC; }
@ -95,20 +72,20 @@ class SpacePacketIF {
* which is checked with this method.
* @return Returns true if the bit is set and false if not.
*/
[[nodiscard]] virtual bool hasSecHeader() const { return (getPacketId() >> 11) & 0b1; }
[[nodiscard]] virtual bool hasSecHeader() const { return (getPacketIdRaw() >> 11) & 0b1; }
[[nodiscard]] virtual ccsds::SequenceFlags getSequenceFlags() const {
return static_cast<ccsds::SequenceFlags>(getPacketSeqCtrl() >> 14 & 0b11);
return static_cast<ccsds::SequenceFlags>(getPacketSeqCtrlRaw() >> 14 & 0b11);
}
[[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrl() & 0x3FFF; }
[[nodiscard]] virtual uint16_t getSequenceCount() const { return getPacketSeqCtrlRaw() & 0x3FFF; }
/**
* Returns the full packet length based of the packet data length field
* @return
*/
[[nodiscard]] virtual size_t getFullPacketLen() const {
return sizeof(CCSDSPrimaryHeader) + getPacketDataLen() + 1;
return ccsds::HEADER_LEN + getPacketDataLen() + 1;
}
};

View File

@ -1,4 +1,4 @@
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "SpacePacketReader.h"
#include <cstring>
@ -18,27 +18,24 @@ ReturnValue_t SpacePacketReader::checkLength() const {
SpacePacketReader::~SpacePacketReader() = default;
inline uint16_t SpacePacketReader::getPacketId() const {
return ((spHeader->packetIdHAndVersion) << 8) + spHeader->packetIdL;
}
inline uint16_t SpacePacketReader::getPacketIdRaw() const { return ccsds::getPacketId(*spHeader); }
const uint8_t* SpacePacketReader::getPacketData() { return packetDataField; }
ReturnValue_t SpacePacketReader::setData(uint8_t* pData, size_t maxSize_, void* args) {
setInternalFields(pData, maxSize_);
return HasReturnvaluesIF::RETURN_OK;
}
uint16_t SpacePacketReader::getPacketSeqCtrl() const {
return (spHeader->packetSeqCtrlH << 8) + spHeader->packetSeqCtrlL;
uint16_t SpacePacketReader::getPacketSeqCtrlRaw() const {
return ccsds::getPacketSeqCtrl(*spHeader);
}
uint16_t SpacePacketReader::getPacketDataLen() const {
return (spHeader->packetLenH << 8) | spHeader->packetIdL;
}
uint16_t SpacePacketReader::getPacketDataLen() const { return ccsds::getPacketLen(*spHeader); }
void SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) {
maxSize = maxSize_;
spHeader = reinterpret_cast<const CCSDSPrimaryHeader*>(data);
packetDataField = data + sizeof(CCSDSPrimaryHeader);
spHeader = reinterpret_cast<const ccsds::PrimaryHeader*>(data);
packetDataField = data + ccsds::HEADER_LEN;
}
const uint8_t* SpacePacketReader::getFullData() {
return reinterpret_cast<const uint8_t*>(spHeader);

View File

@ -1,13 +1,12 @@
#ifndef FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#include <fsfw/tmtcpacket/RedirectableDataPointerIF.h>
#include <cstddef>
#include "ReadablePacketIF.h"
#include "ccsds_header.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tmtcpacket/ReadablePacketIF.h"
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/ccsds/defs.h"
/**
* @defgroup tmtcpackets Space Packets
@ -46,8 +45,8 @@ class SpacePacketReader : public SpacePacketIF,
*/
~SpacePacketReader() override;
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
const uint8_t* getFullData() override;
@ -70,7 +69,7 @@ class SpacePacketReader : public SpacePacketIF,
* the packet header.
* To be hardware-safe, all elements are of byte size.
*/
const CCSDSPrimaryHeader* spHeader{};
const ccsds::PrimaryHeader* spHeader{};
const uint8_t* packetDataField{};
size_t maxSize = 0;

View File

@ -0,0 +1,36 @@
#ifndef CCSDS_HEADER_H_
#define CCSDS_HEADER_H_
#include <cstdint>
namespace ccsds {
enum PacketType : uint8_t { TM = 0, TC = 1 };
enum SequenceFlags : uint8_t {
CONTINUATION = 0b00,
FIRST_SEGMENT = 0b01,
LAST_SEGMENT = 0b10,
UNSEGMENTED = 0b11
};
static const uint16_t LIMIT_APID = 2048; // 2^11
static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14
static const uint16_t APID_IDLE_PACKET = 0x7FF;
constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid,
bool secondaryHeaderFlag = true) {
return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
}
constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag);
}
constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag);
}
} // namespace ccsds
#endif /* CCSDS_HEADER_H_ */

View File

@ -0,0 +1,29 @@
#include "header.h"
uint16_t ccsds::getPacketId(const PrimaryHeader &header) {
return ((header.packetIdHAndVersion & 0x1F00) << 8) + header.packetIdL;
}
uint16_t ccsds::getPacketSeqCtrl(const PrimaryHeader &header) {
return (header.packetSeqCtrlH << 8) | header.packetSeqCtrlL;
}
uint8_t ccsds::getVersion(const PrimaryHeader &header) {
return (header.packetIdHAndVersion >> 5) & 0b111;
}
uint16_t ccsds::getPacketLen(const PrimaryHeader &header) {
return (header.packetLenH << 8) | header.packetLenL;
}
void ccsds::setPacketId(PrimaryHeader &header, uint16_t packetId) {
header.packetIdHAndVersion = (packetId >> 8) & 0x1F;
header.packetIdL = packetId & 0xff;
}
void ccsds::setApid(PrimaryHeader &header, uint16_t apid) {
uint16_t packetIdRaw = getPacketId(header);
packetIdRaw &= ~0x7FF;
packetIdRaw |= apid & 0x7FF;
setPacketId(header, packetIdRaw);
}

View File

@ -0,0 +1,30 @@
#ifndef FSFW_TMTCPACKET_HEADER_H
#define FSFW_TMTCPACKET_HEADER_H
#include <cstddef>
#include <cstdint>
namespace ccsds {
static constexpr size_t HEADER_LEN = 6;
struct PrimaryHeader {
uint8_t packetIdHAndVersion;
uint8_t packetIdL;
uint8_t packetSeqCtrlH;
uint8_t packetSeqCtrlL;
uint8_t packetLenH;
uint8_t packetLenL;
};
uint16_t getPacketId(const PrimaryHeader& header);
uint16_t getPacketSeqCtrl(const PrimaryHeader& header);
uint8_t getVersion(const PrimaryHeader& header);
uint16_t getPacketLen(const PrimaryHeader& header);
void setPacketId(PrimaryHeader& header, uint16_t packetId);
void setApid(PrimaryHeader& header, uint16_t apid);
} // namespace ccsds
#endif // FSFW_TMTCPACKET_HEADER_H

View File

@ -1,15 +0,0 @@
#ifndef CCSDS_HEADER_H_
#define CCSDS_HEADER_H_
#include <cstdint>
struct CCSDSPrimaryHeader {
uint8_t packetIdHAndVersion;
uint8_t packetIdL;
uint8_t packetSeqCtrlH;
uint8_t packetSeqCtrlL;
uint8_t packetLenH;
uint8_t packetLenL;
};
#endif /* CCSDS_HEADER_H_ */

View File

@ -1,7 +1,7 @@
#ifndef FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_
#define FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
class CfdpReader : public SpacePacketReader {
public:

View File

@ -32,8 +32,8 @@ PacketMatchTree::~PacketMatchTree() = default;
ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t subtype) {
// We assume adding APID is always requested.
PusTmMinimal::TmPacketMinimalPointer data{};
Review

What does mintm mean?

What does mintm mean?
Review

minimal tm. I can rename it to minTm:: if that helps..

minimal tm. I can rename it to minTm:: if that helps..
Review

I think that minTm is better.

I think that minTm is better.
data.secHeader.service_type = type;
data.secHeader.service_subtype = subtype;
data.secHeader.service = type;
data.secHeader.subservice = subtype;
PusTmMinimal testPacket((uint8_t*)&data);
testPacket.setApid(apid);
@ -122,13 +122,13 @@ ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test,
}
ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t subtype) {
PusTmMinimal::TmPacketMinimalPointer data;
data.secHeader.service_type = type;
data.secHeader.service_subtype = subtype;
PusTmMinimal::TmPacketMinimalPointer data{};
data.secHeader.service = type;
data.secHeader.subservice = subtype;
PusTmMinimal testPacket((uint8_t*)&data);
testPacket.setApid(apid);
iterator foundElement = findMatch(begin(), &testPacket);
if (foundElement == this->end()) {
if (foundElement == PacketMatchTree::end()) {
return NO_MATCH;
}
if (type == 0) {

View File

@ -3,7 +3,7 @@
#include <cstdint>
#include "fsfw/tmtcpacket/SpacePacketIF.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h"
class PusIF : public SpacePacketIF {
public:

View File

@ -51,9 +51,9 @@ ReturnValue_t PusTcCreator::deSerialize(const uint8_t **buffer, size_t *size,
return HasReturnvaluesIF::RETURN_FAILED;
}
uint16_t PusTcCreator::getPacketId() const { return spCreator.getPacketId(); }
uint16_t PusTcCreator::getPacketIdRaw() const { return spCreator.getPacketIdRaw(); }
uint16_t PusTcCreator::getPacketSeqCtrl() const { return spCreator.getPacketSeqCtrl(); }
uint16_t PusTcCreator::getPacketSeqCtrlRaw() const { return spCreator.getPacketSeqCtrlRaw(); }
uint16_t PusTcCreator::getPacketDataLen() const { return spCreator.getPacketDataLen(); }

View File

@ -2,8 +2,8 @@
#define FSFW_TMTCPACKET_TCPACKETDESERIALIZER_H
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/SpacePacketIF.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketIF.h"
#include "fsfw/tmtcpacket/pus/definitions.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcIF.h"
@ -29,8 +29,8 @@ class PusTcCreator : public PusTcIF, public SerializeIF {
[[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
[[nodiscard]] uint8_t getPusVersion() const override;
[[nodiscard]] uint8_t getAcknowledgeFlags() const override;

View File

@ -45,7 +45,7 @@ class PusTcIF : public PusIF {
public:
~PusTcIF() override = default;
static const size_t MIN_LEN =
(sizeof(CCSDSPrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2);
(sizeof(ccsds::PrimaryHeader) + ecss::PusTcDataFieldHeader::MIN_LEN + 2);
/**
* This is a getter for the packet's Ack field, which are the lowest four

View File

@ -21,10 +21,10 @@ ReturnValue_t PusTcReader::parseData() {
}
// Might become variable sized field in the future
size_t secHeaderLen = ecss::PusTcDataFieldHeader::MIN_LEN;
pointers.secHeaderStart = pointers.spHeaderStart + sizeof(CCSDSPrimaryHeader);
pointers.secHeaderStart = pointers.spHeaderStart + ccsds::HEADER_LEN;
// TODO: No support for spare bytes yet
pointers.userDataStart = pointers.secHeaderStart + secHeaderLen;
appDataSize = size - (sizeof(CCSDSPrimaryHeader) + secHeaderLen);
appDataSize = size - (ccsds::HEADER_LEN + secHeaderLen);
pointers.crcStart = pointers.userDataStart + appDataSize;
return HasReturnvaluesIF::RETURN_OK;
}
@ -50,8 +50,8 @@ uint16_t PusTcReader::getErrorControl() const {
return pointers.crcStart[0] << 8 | pointers.crcStart[1];
}
uint16_t PusTcReader::getPacketId() const { return spReader.getPacketId(); }
uint16_t PusTcReader::getPacketSeqCtrl() const { return spReader.getPacketSeqCtrl(); }
uint16_t PusTcReader::getPacketIdRaw() const { return spReader.getPacketIdRaw(); }
uint16_t PusTcReader::getPacketSeqCtrlRaw() const { return spReader.getPacketSeqCtrlRaw(); }
uint16_t PusTcReader::getPacketDataLen() const { return spReader.getPacketDataLen(); }
uint8_t PusTcReader::getPusVersion() const { return spReader.getVersion(); }
const uint8_t* PusTcReader::getFullData() { return pointers.spHeaderStart; }
@ -64,6 +64,7 @@ ReturnValue_t PusTcReader::setData(uint8_t* pData, size_t size_, void* args) {
}
ReturnValue_t PusTcReader::setData(const uint8_t* data, size_t size_) {
setData(const_cast<uint8_t*>(data), size_, nullptr);
return HasReturnvaluesIF::RETURN_OK;
}
/*

View File

@ -5,7 +5,7 @@
#include "PusTcIF.h"
#include "fsfw/tmtcpacket/RedirectableDataPointerIF.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
/**
* This class is the basic data handler for any ECSS PUS Telecommand packet.
@ -40,8 +40,8 @@ class PusTcReader : public PusTcIF, public ReadablePacketIF, public Redirectable
* to the screen.
*/
// void print();
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
[[nodiscard]] uint8_t getPusVersion() const override;
[[nodiscard]] uint8_t getAcknowledgeFlags() const override;

View File

@ -6,7 +6,7 @@
#include "../definitions.h"
#include "PusTcReader.h"
#include "fsfw/FSFW.h"
#include "fsfw/tmtcpacket/ccsds_header.h"
#include "fsfw/tmtcpacket/ccsds/defs.h"
/**
* This struct defines the data structure of a PUS Telecommand A packet when

View File

@ -1,10 +1,12 @@
#include "PusTmCreator.h"
PusTmCreator::PusTmCreator(PusTmParams params_) : params(params_){};
PusTmCreator::PusTmCreator(PusTmParams& params_) : params(params_){};
uint16_t PusTmCreator::getPacketId() const { return 0; }
uint16_t PusTmCreator::getPacketSeqCtrl() const { return 0; }
uint16_t PusTmCreator::getPacketIdRaw() const { return 0; }
uint16_t PusTmCreator::getPacketSeqCtrlRaw() const { return 0; }
uint16_t PusTmCreator::getPacketDataLen() const { return 0; }
uint8_t PusTmCreator::getPusVersion() const { return 0; }
uint8_t PusTmCreator::getService() const { return 0; }
uint8_t PusTmCreator::getSubService() const { return 0; }
const uint8_t* PusTmCreator::getUserData(size_t& appDataLen) const { return nullptr; }
uint16_t PusTmCreator::getUserDataSize() const { return 0; }

View File

@ -16,16 +16,18 @@ struct PusTmParams {
class PusTmCreator : public PusIF {
public:
~PusTmCreator() override = default;
explicit PusTmCreator(PusTmParams params);
explicit PusTmCreator(PusTmParams& params);
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
[[nodiscard]] uint8_t getPusVersion() const override;
[[nodiscard]] uint8_t getService() const override;
[[nodiscard]] uint8_t getSubService() const override;
const uint8_t* getUserData(size_t& appDataLen) const override;
[[nodiscard]] uint16_t getUserDataSize() const override;
private:
PusTmParams params;
PusTmParams& params;
};
#endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H

View File

@ -5,8 +5,9 @@
#include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h"
PusTmMinimal::PusTmMinimal(mintm::MinimalPusTm* data) { tmData = data; }
PusTmMinimal::PusTmMinimal(uint8_t* data) {
this->tmData = reinterpret_cast<TmPacketMinimalPointer*>(data);
this->tmData = reinterpret_cast<mintm::MinimalPusTm*>(data);
}
PusTmMinimal::~PusTmMinimal() = default;
@ -27,8 +28,8 @@ void PusTmMinimal::setInterpretTimestampObject(PacketTimestampInterpreterIF* int
PacketTimestampInterpreterIF* PusTmMinimal::timestampInterpreter = nullptr;
// TODO: Implement all of this
ReturnValue_t PusTmMinimal::setData(uint8_t* dataPtr, size_t size, void* args) { return 0; }
uint16_t PusTmMinimal::getPacketId() const { return 0; }
uint16_t PusTmMinimal::getPacketSeqCtrl() const { return 0; }
uint16_t PusTmMinimal::getPacketIdRaw() const { return 0; }
uint16_t PusTmMinimal::getPacketSeqCtrlRaw() const { return 0; }
uint16_t PusTmMinimal::getPacketDataLen() const { return 0; }
uint8_t PusTmMinimal::getPusVersion() const { return 0; }
uint8_t PusTmMinimal::getService() const { return tmData->secHeader.service; }
@ -36,7 +37,9 @@ uint8_t PusTmMinimal::getSubService() const { return tmData->secHeader.subservic
const uint8_t* PusTmMinimal::getUserData(size_t& appDataLen) const { return nullptr; }
uint16_t PusTmMinimal::getUserDataSize() const { return 0; }
uint8_t PusTmMinimal::getScTimeRefStatus() { return 0; }
uint16_t PusTmMinimal::getMessageTypeCounter() { return tmData->secHeader.messageTypeCounter; }
uint16_t PusTmMinimal::getMessageTypeCounter() {
return (tmData->secHeader.messageTypeH << 8) | tmData->secHeader.messageTypeL;
}
uint16_t PusTmMinimal::getDestId() { return 0; }
const uint8_t* PusTmMinimal::getTimestamp(size_t& timeStampLen) { return nullptr; }
size_t PusTmMinimal::getTimestampLen() { return 0; }

View File

@ -3,10 +3,39 @@
#include "PusTmIF.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
struct timeval;
class PacketTimestampInterpreterIF;
namespace mintm {
// NOTE: Only PUS C compatible!
struct PusTmMinimalSecHeader {
uint8_t versionAndScTimeRefStatus;
uint8_t service;
uint8_t subservice;
uint8_t messageTypeH;
uint8_t messageTypeL;
};
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct MinimalPusTm {
ccsds::PrimaryHeader primary;
PusTmMinimalSecHeader secHeader;
uint8_t rest;
};
// Must include a checksum and is therefore at least one larger than the above struct.
static const uint16_t MINIMUM_SIZE = sizeof(MinimalPusTm) + 1;
} // namespace mintm
/**
* This is a minimal version of a PUS TmPacket without any variable field, or,
* in other words with Service Type, Subtype and subcounter only.
@ -15,6 +44,7 @@ class PacketTimestampInterpreterIF;
*/
class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF {
public:
explicit PusTmMinimal(mintm::MinimalPusTm* data);
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
@ -33,8 +63,8 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF {
static void setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter);
ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override;
[[nodiscard]] uint16_t getPacketId() const override;
[[nodiscard]] uint16_t getPacketSeqCtrl() const override;
[[nodiscard]] uint16_t getPacketIdRaw() const override;
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
[[nodiscard]] uint16_t getPacketDataLen() const override;
[[nodiscard]] uint8_t getPusVersion() const override;
[[nodiscard]] uint8_t getService() const override;
@ -47,27 +77,6 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF {
const uint8_t* getTimestamp(size_t& timeStampLen) override;
size_t getTimestampLen() override;
// NOTE: Only PUS C compatible!
struct PusTmMinimalSecHeader {
uint8_t versionAndScTimeRefStatus;
uint8_t service;
uint8_t subservice;
uint16_t messageTypeCounter;
};
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TmPacketMinimalPointer {
CCSDSPrimaryHeader primary;
PusTmMinimalSecHeader secHeader;
uint8_t rest;
};
// Must include a checksum and is therefore at least one larger than the above struct.
static const uint16_t MINIMUM_SIZE = sizeof(TmPacketMinimalPointer) + 1;
protected:
/**
* A pointer to a structure which defines the data structure of
@ -75,7 +84,7 @@ class PusTmMinimal : public PusTmIF, public RedirectableDataPointerIF {
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketMinimalPointer* tmData;
mintm::MinimalPusTm* tmData;
static PacketTimestampInterpreterIF* timestampInterpreter;
};

View File

@ -4,7 +4,7 @@
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
namespace Factory {

View File

@ -5,7 +5,7 @@
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketReader.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
namespace Factory {
void setStaticFrameworkObjectIds();
@ -35,7 +35,7 @@ struct PUSTmDataFieldHeaderPusC {
* @ingroup tmtcpackets
*/
struct TmPacketPointerPusC {
CCSDSPrimaryHeader primary;
ccsds::PrimaryHeader primary;
PUSTmDataFieldHeaderPusC dataField;
uint8_t data;
};
@ -52,7 +52,7 @@ class TmPacketPusC : public TmPacketBase {
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE =
(sizeof(CCSDSPrimaryHeader) + sizeof(PUSTmDataFieldHeaderPusC) + 2);
ccsds::HEADER_LEN + sizeof(PUSTmDataFieldHeaderPusC) + 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;

View File

@ -1,72 +1,73 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_
#include "TmPacketPusC.h"
#include "TmPacketStoredBase.h"
/**
* This class generates a ECSS PUS C 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 TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusC(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
* @param destinationId Destination ID containing the application process ID as specified
* by PUS C
* @param timeRefField 4 bit time reference field as specified by PUS C
*/
TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter = 0,
const uint8_t* data = nullptr, uint32_t size = 0,
const uint8_t* headerData = nullptr, uint32_t headerSize = 0,
uint16_t destinationId = 0, uint8_t timeRefField = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter,
SerializeIF* content, SerializeIF* header = nullptr,
uint16_t destinationId = 0, uint8_t timeRefField = 0);
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) override;
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */
//#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_
//#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_
//
//#include "TmPacketPusC.h"
//#include "TmPacketStoredBase.h"
//
///**
// * This class generates a ECSS PUS C 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 TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC {
// public:
// /**
// * This is a default constructor which does not set the data pointer.
// * However, it does try to set the packet store.
// */
// TmPacketStoredPusC(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
// * @param destinationId Destination ID containing the application process ID as specified
// * by PUS C
// * @param timeRefField 4 bit time reference field as specified by PUS C
// */
// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter =
// 0,
// const uint8_t* data = nullptr, uint32_t size = 0,
// const uint8_t* headerData = nullptr, uint32_t headerSize = 0,
// uint16_t destinationId = 0, uint8_t timeRefField = 0);
// /**
// * Another ctor to directly pass structured content and header data to the
// * packet to avoid additional buffers.
// */
// TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter,
// SerializeIF* content, SerializeIF* header = nullptr,
// uint16_t destinationId = 0, uint8_t timeRefField = 0);
//
// 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) override;
//};
//
//#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */

View File

@ -6,4 +6,5 @@ target_sources(
TmTcBridge.cpp
TmTcMessage.cpp
VerificationReporter.cpp
SpacePacketParser.cpp)
SpacePacketParser.cpp
TmStoreHelper.cpp)

View File

@ -12,8 +12,8 @@ object_id_t PusServiceBase::packetSource = 0;
object_id_t PusServiceBase::packetDestination = 0;
PusServiceBase::PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId,
StorageManagerIF* store_)
: SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), store(store_) {
StorageManagerIF* ipcStore_)
: SystemObject(setObjectId), apid(setApid), serviceId(setServiceId), ipcStore(ipcStore_) {
requestQueue = QueueFactory::instance()->createMessageQueue(PUS_SERVICE_MAX_RECEPTION);
}
@ -52,7 +52,7 @@ void PusServiceBase::handleRequestQueue() {
if (status == RETURN_OK) {
const uint8_t* dataPtr;
size_t dataLen = 0;
result = store->getData(message.getStorageId(), &dataPtr, &dataLen);
result = ipcStore->getData(message.getStorageId(), &dataPtr, &dataLen);
if (result != HasReturnvaluesIF::RETURN_OK) {
// TODO: Warning?
}
@ -73,7 +73,7 @@ void PusServiceBase::handleRequestQueue() {
&this->currentPacket, result, 0, errorParameter1,
errorParameter2);
}
store->deleteData(message.getStorageId());
ipcStore->deleteData(message.getStorageId());
errorParameter1 = 0;
errorParameter2 = 0;
} else if (status == MessageQueueIF::EMPTY) {
@ -112,6 +112,12 @@ ReturnValue_t PusServiceBase::initialize() {
}
this->requestQueue->setDefaultDestination(destService->getReportReceptionQueue());
distributor->registerService(this);
if (ipcStore == nullptr) {
ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore == nullptr) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -52,7 +52,7 @@ class PusServiceBase : public ExecutableObjectIF,
* The Service Identifier as specified in ECSS PUS.
*/
PusServiceBase(object_id_t setObjectId, uint16_t setApid, uint8_t setServiceId,
StorageManagerIF* store);
StorageManagerIF* ipcStore);
/**
* The destructor is empty.
*/
@ -144,7 +144,7 @@ class PusServiceBase : public ExecutableObjectIF,
* It is deleted after handleRequest was executed.
*/
// TcPacketStoredPus currentPacket;
StorageManagerIF* store;
StorageManagerIF* ipcStore;
PusTcReader currentPacket;
static object_id_t packetSource;

View File

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

View File

@ -0,0 +1,43 @@
#include "TmStoreHelper.h"
#include "TmTcMessage.h"
#include "fsfw/ipc/MessageQueueSenderIF.h"
TmStoreHelper::TmStoreHelper(StorageManagerIF *tmStore, MessageQueueId_t tmtcMsgDest,
MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF *reporter)
: creator(params),
tmtcMsgDest(tmtcMsgDest),
tmtcMsgSrc(tmtcMsgSrc),
errReporter(reporter),
tmStore(tmStore) {}
void TmStoreHelper::preparePacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t counter) {
// TODO: Implement
// creator.setApid(apid);
params.service = service;
params.subservice = subservice;
params.messageTypeCounter = counter;
// TODO: Implement serialize and then serialize into the store
}
ReturnValue_t TmStoreHelper::sendPacket() {
TmTcMessage tmMessage(currentAddr);
ReturnValue_t result = MessageQueueSenderIF::sendMessage(tmtcMsgDest, &tmMessage, tmtcMsgSrc);
if (result != HasReturnvaluesIF::RETURN_OK) {
tmStore->deleteData(currentAddr);
if (errReporter != nullptr) {
errReporter->lostTm();
}
return result;
}
return HasReturnvaluesIF::RETURN_OK;
}
void TmStoreHelper::setMsgDestination(MessageQueueId_t msgDest) { tmtcMsgDest = msgDest; }
void TmStoreHelper::setMsgSource(MessageQueueId_t msgSrc) { tmtcMsgSrc = msgSrc; }
void TmStoreHelper::setInternalErrorReporter(InternalErrorReporterIF *reporter) {
errReporter = reporter;
}

View File

@ -0,0 +1,33 @@
#ifndef FSFW_TMTCSERVICES_STOREHELPER_H
#define FSFW_TMTCSERVICES_STOREHELPER_H
#include "fsfw/internalerror/InternalErrorReporterIF.h"
#include "fsfw/ipc/MessageQueueMessageIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tmtcpacket/pus/tm/PusTmCreator.h"
// TODO: Serializing a packet into a store and sending the message are two different tasks
// Move them into separate classes
class TmStoreHelper {
public:
TmStoreHelper(StorageManagerIF* tmStore, MessageQueueId_t tmtcMsgDest,
MessageQueueId_t tmtcMsgSrc, InternalErrorReporterIF* reporter);
void setInternalErrorReporter(InternalErrorReporterIF* reporter);
void setMsgDestination(MessageQueueId_t msgDest);
void setMsgSource(MessageQueueId_t msgSrc);
void preparePacket(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t counter);
ReturnValue_t sendPacket();
private:
PusTmParams params{};
PusTmCreator creator;
bool doErrorReporting = true;
MessageQueueId_t tmtcMsgDest;
MessageQueueId_t tmtcMsgSrc;
InternalErrorReporterIF* errReporter;
store_address_t currentAddr{};
StorageManagerIF* tmStore;
};
#endif // FSFW_TMTCSERVICES_STOREHELPER_H

View File

@ -22,8 +22,8 @@ void VerificationReporter::sendSuccessReport(uint8_t set_report_id, PusTcReader*
return;
}
PusVerificationMessage message(set_report_id, currentPacket->getAcknowledgeFlags(),
currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(), 0,
set_step);
currentPacket->getPacketIdRaw(),
currentPacket->getPacketSeqCtrlRaw(), 0, set_step);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message);
if (status != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
@ -59,9 +59,9 @@ void VerificationReporter::sendFailureReport(uint8_t report_id, PusTcReader* cur
if (currentPacket == nullptr) {
return;
}
PusVerificationMessage message(report_id, currentPacket->getAcknowledgeFlags(),
currentPacket->getPacketId(), currentPacket->getPacketSeqCtrl(),
error_code, step, parameter1, parameter2);
PusVerificationMessage message(
report_id, currentPacket->getAcknowledgeFlags(), currentPacket->getPacketIdRaw(),
currentPacket->getPacketSeqCtrlRaw(), error_code, step, parameter1, parameter2);
ReturnValue_t status = MessageQueueSenderIF::sendMessage(acknowledgeQueue, &message);
if (status != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1

View File

@ -2,11 +2,12 @@
#include <catch2/catch_test_macros.hpp>
#include <cmath>
#include "fsfw/tmtcpacket/SpacePacketCreator.h"
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
SpacePacketCreator base = SpacePacketCreator(ccsds::PacketType::TC, true, 0x02,
ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02),
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16);
SpacePacketCreator base = SpacePacketCreator(params);
std::array<uint8_t, 6> buf{};
uint8_t* bufPtr = buf.data();
size_t serLen = 0;
@ -27,7 +28,7 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
REQUIRE(base.getSequenceCount() == 0x34);
REQUIRE(base.getPacketDataLen() == 0x16);
REQUIRE(base.getPacketType() == ccsds::PacketType::TC);
REQUIRE(base.getPacketId() == 0x1802);
REQUIRE(base.getPacketIdRaw() == 0x1802);
REQUIRE(base.getSerializedSize() == 6);
}
@ -71,17 +72,15 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
}
SECTION("Invalid APID") {
SpacePacketCreator invalid =
SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0xFFFF),
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16);
SpacePacketCreator invalid = SpacePacketCreator(
ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
REQUIRE(not invalid.isValid());
REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
}
SECTION("Invalid Seq Count") {
SpacePacketCreator invalid =
SpacePacketCreator(PacketId(ccsds::PacketType::TC, true, 0x02),
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF), 0x16);
SpacePacketCreator invalid = SpacePacketCreator(
ccsds::PacketType::TC, true, 0x02, ccsds::SequenceFlags::FIRST_SEGMENT, 0xFFFF, 0x16);
REQUIRE(not invalid.isValid());
REQUIRE(invalid.serialize(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
}

View File

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