CFDP SOURCE handler #157

Merged
muellerr merged 107 commits from cfdp-source-handler into develop 2023-10-19 10:59:55 +02:00
105 changed files with 2351 additions and 670 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
# PyCharm and CLion # PyCharm and CLion
/.idea/* .idea/*
!/.idea/runConfigurations !/.idea/runConfigurations
!/.idea/cmake.xml !/.idea/cmake.xml
!/.idea/codeStyles !/.idea/codeStyles

View File

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="CMakeSharedSettings"> <component name="CMakeSharedSettings">
<configurations> <configurations>
<configuration PROFILE_NAME="Debug Test" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DFSFW_BUILD_TESTS=ON -DFSFW_OSAL=host" /> <configuration PROFILE_NAME="Debug Test" ENABLED="true" CONFIG_NAME="Debug" GENERATION_OPTIONS="-DFSFW_OSAL=host -DFSFW_BUILD_TESTS=ON" NO_GENERATOR="true" />
</configurations> </configurations>
</component> </component>
</project> </project>

View File

@ -32,6 +32,7 @@ add_subdirectory(timemanager)
add_subdirectory(tmtcpacket) add_subdirectory(tmtcpacket)
add_subdirectory(tmtcservices) add_subdirectory(tmtcservices)
add_subdirectory(filesystem) add_subdirectory(filesystem)
add_subdirectory(util)
# Optional # Optional

View File

@ -4,8 +4,9 @@ CfdpMessage::CfdpMessage() = default;
CfdpMessage::~CfdpMessage() = default; CfdpMessage::~CfdpMessage() = default;
void CfdpMessage::setCommand(CommandMessage *message, store_address_t cfdpPacket) { void CfdpMessage::setPutRequest(CommandMessage *message, store_address_t putRequest) {
message->setParameter(cfdpPacket.raw); message->setCommand(PUT_REQUEST);
message->setParameter(putRequest.raw);
} }
store_address_t CfdpMessage::getStoreId(const CommandMessage *message) { store_address_t CfdpMessage::getStoreId(const CommandMessage *message) {

View File

@ -11,9 +11,11 @@ class CfdpMessage {
public: public:
static const uint8_t MESSAGE_ID = messagetypes::CFDP; static const uint8_t MESSAGE_ID = messagetypes::CFDP;
static const Command_t PUT_REQUEST = MAKE_COMMAND_ID(1);
static const Command_t CANCEL_REQUEST = MAKE_COMMAND_ID(1);
virtual ~CfdpMessage(); virtual ~CfdpMessage();
static void setCommand(CommandMessage* message, store_address_t cfdpPacket); static void setPutRequest(CommandMessage* message, store_address_t putRequest);
static store_address_t getStoreId(const CommandMessage* message); static store_address_t getStoreId(const CommandMessage* message);

View File

@ -8,11 +8,14 @@
namespace cfdp { namespace cfdp {
struct FileSize : public SerializeIF { /**
* Helper type for the CFDP File Size Sensitive (FSS) fields.
*/
struct Fss : public SerializeIF {
public: public:
FileSize() = default; Fss() = default;
explicit FileSize(uint64_t fileSize, bool isLarge = false) { setFileSize(fileSize, isLarge); }; explicit Fss(uint64_t fileSize, bool isLarge = false) { setFileSize(fileSize, isLarge); };
[[nodiscard]] uint64_t value() const { return fileSize; } [[nodiscard]] uint64_t value() const { return fileSize; }

View File

@ -3,8 +3,8 @@
#include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/serviceinterface.h" #include "fsfw/serviceinterface.h"
cfdp::VarLenField::VarLenField(cfdp::WidthInBytes width, size_t value) : VarLenField() { cfdp::VarLenField::VarLenField(cfdp::WidthInBytes width, uint64_t value) : VarLenField() {
ReturnValue_t result = this->setValue(width, value); ReturnValue_t result = this->setValueAndWidth(width, value);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
#if FSFW_DISABLE_PRINTOUT == 0 #if FSFW_DISABLE_PRINTOUT == 0
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
@ -20,8 +20,8 @@ cfdp::VarLenField::VarLenField() : width(cfdp::WidthInBytes::ONE_BYTE) { value.o
cfdp::WidthInBytes cfdp::VarLenField::getWidth() const { return width; } cfdp::WidthInBytes cfdp::VarLenField::getWidth() const { return width; }
ReturnValue_t cfdp::VarLenField::setValue(cfdp::WidthInBytes widthInBytes, size_t value_) { ReturnValue_t cfdp::VarLenField::setValueAndWidth(cfdp::WidthInBytes width_, uint64_t value_) {
switch (widthInBytes) { switch (width_) {
case (cfdp::WidthInBytes::ONE_BYTE): { case (cfdp::WidthInBytes::ONE_BYTE): {
if (value_ > UINT8_MAX) { if (value_ > UINT8_MAX) {
return returnvalue::FAILED; return returnvalue::FAILED;
@ -43,15 +43,18 @@ ReturnValue_t cfdp::VarLenField::setValue(cfdp::WidthInBytes widthInBytes, size_
this->value.fourBytes = value_; this->value.fourBytes = value_;
break; break;
} }
case (cfdp::WidthInBytes::EIGHT_BYTES): {
this->value.eightBytes = value_;
}
default: { default: {
break; break;
} }
} }
this->width = widthInBytes; this->width = width_;
return returnvalue::OK; return returnvalue::OK;
} }
size_t cfdp::VarLenField::getValue() const { uint64_t cfdp::VarLenField::getValue() const {
switch (width) { switch (width) {
case (cfdp::WidthInBytes::ONE_BYTE): { case (cfdp::WidthInBytes::ONE_BYTE): {
return value.oneByte; return value.oneByte;
@ -62,6 +65,9 @@ size_t cfdp::VarLenField::getValue() const {
case (cfdp::WidthInBytes::FOUR_BYTES): { case (cfdp::WidthInBytes::FOUR_BYTES): {
return value.fourBytes; return value.fourBytes;
} }
case (cfdp::WidthInBytes::EIGHT_BYTES): {
return value.eightBytes;
}
} }
return 0; return 0;
} }
@ -84,6 +90,10 @@ ReturnValue_t cfdp::VarLenField::serialize(uint8_t **buffer, size_t *size, size_
case (cfdp::WidthInBytes::FOUR_BYTES): { case (cfdp::WidthInBytes::FOUR_BYTES): {
return SerializeAdapter::serialize(&value.fourBytes, buffer, size, maxSize, streamEndianness); return SerializeAdapter::serialize(&value.fourBytes, buffer, size, maxSize, streamEndianness);
} }
case (cfdp::WidthInBytes::EIGHT_BYTES): {
return SerializeAdapter::serialize(&value.eightBytes, buffer, size, maxSize,
streamEndianness);
}
default: { default: {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
@ -98,11 +108,16 @@ ReturnValue_t cfdp::VarLenField::deSerialize(cfdp::WidthInBytes width_, const ui
return deSerialize(buffer, size, streamEndianness); return deSerialize(buffer, size, streamEndianness);
} }
ReturnValue_t cfdp::VarLenField::setValue(uint64_t value_) {
return setValueAndWidth(getWidth(), value_);
}
ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *size, ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) { Endianness streamEndianness) {
switch (width) { switch (width) {
case (cfdp::WidthInBytes::ONE_BYTE): { case (cfdp::WidthInBytes::ONE_BYTE): {
value.oneByte = **buffer; value.oneByte = **buffer;
*buffer += 1;
*size += 1; *size += 1;
return returnvalue::OK; return returnvalue::OK;
} }
@ -112,6 +127,9 @@ ReturnValue_t cfdp::VarLenField::deSerialize(const uint8_t **buffer, size_t *siz
case (cfdp::WidthInBytes::FOUR_BYTES): { case (cfdp::WidthInBytes::FOUR_BYTES): {
return SerializeAdapter::deSerialize(&value.fourBytes, buffer, size, streamEndianness); return SerializeAdapter::deSerialize(&value.fourBytes, buffer, size, streamEndianness);
} }
case (cfdp::WidthInBytes::EIGHT_BYTES): {
return SerializeAdapter::deSerialize(&value.eightBytes, buffer, size, streamEndianness);
}
default: { default: {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
@ -135,3 +153,5 @@ bool cfdp::VarLenField::operator==(const cfdp::VarLenField &other) const {
bool cfdp::VarLenField::operator!=(const cfdp::VarLenField &other) const { bool cfdp::VarLenField::operator!=(const cfdp::VarLenField &other) const {
return not(*this == other); return not(*this == other);
} }
void cfdp::VarLenField::setWidth(cfdp::WidthInBytes width_) { this->width = width_; }

View File

@ -25,13 +25,15 @@ class VarLenField : public SerializeIF {
template <typename T> template <typename T>
explicit VarLenField(UnsignedByteField<T> byteField); explicit VarLenField(UnsignedByteField<T> byteField);
VarLenField(cfdp::WidthInBytes width, size_t value); VarLenField(cfdp::WidthInBytes width, uint64_t value);
bool operator==(const VarLenField &other) const; bool operator==(const VarLenField &other) const;
bool operator!=(const VarLenField &other) const; bool operator!=(const VarLenField &other) const;
bool operator<(const VarLenField &other) const; bool operator<(const VarLenField &other) const;
ReturnValue_t setValue(cfdp::WidthInBytes, size_t value); ReturnValue_t setValueAndWidth(cfdp::WidthInBytes width, uint64_t value);
void setWidth(cfdp::WidthInBytes width);
ReturnValue_t setValue(uint64_t value);
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override; Endianness streamEndianness) const override;
@ -42,7 +44,7 @@ class VarLenField : public SerializeIF {
Endianness streamEndianness); Endianness streamEndianness);
[[nodiscard]] cfdp::WidthInBytes getWidth() const; [[nodiscard]] cfdp::WidthInBytes getWidth() const;
[[nodiscard]] size_t getValue() const; [[nodiscard]] uint64_t getValue() const;
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
friend std::ostream &operator<<(std::ostream &os, const VarLenField &id) { friend std::ostream &operator<<(std::ostream &os, const VarLenField &id) {
@ -64,7 +66,7 @@ template <typename T>
cfdp::VarLenField::VarLenField(UnsignedByteField<T> byteField) cfdp::VarLenField::VarLenField(UnsignedByteField<T> byteField)
: width(static_cast<cfdp::WidthInBytes>(sizeof(T))) { : width(static_cast<cfdp::WidthInBytes>(sizeof(T))) {
static_assert((sizeof(T) % 2) == 0); static_assert((sizeof(T) % 2) == 0);
setValue(width, byteField.getValue()); setValueAndWidth(width, byteField.getValue());
} }
struct EntityId : public VarLenField { struct EntityId : public VarLenField {
@ -73,6 +75,32 @@ struct EntityId : public VarLenField {
template <typename T> template <typename T>
explicit EntityId(UnsignedByteField<T> byteField) : VarLenField(byteField) {} explicit EntityId(UnsignedByteField<T> byteField) : VarLenField(byteField) {}
EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {} EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {}
ReturnValue_t serializeAsLv(uint8_t **buffer, size_t *size, size_t maxSize) const {
if (buffer == nullptr or size == nullptr) {
return returnvalue::FAILED;
}
if (*size + 1 + getWidth() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
**buffer = getWidth();
*buffer += 1;
*size += 1;
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
ReturnValue_t deSerializeFromLv(const uint8_t **buffer, size_t *deserLen) {
if (buffer == nullptr or deserLen == nullptr) {
return returnvalue::FAILED;
}
if (*deserLen < 2) {
return SerializeIF::STREAM_TOO_SHORT;
}
auto width = static_cast<WidthInBytes>(**buffer);
*buffer += 1;
*deserLen -= 1;
return VarLenField::deSerialize(width, buffer, deserLen, SerializeIF::Endianness::NETWORK);
}
}; };
struct TransactionSeqNum : public VarLenField { struct TransactionSeqNum : public VarLenField {

View File

@ -17,7 +17,7 @@ static constexpr char CFDP_VERSION_2_NAME[] = "CCSDS 727.0-B-5";
static constexpr uint8_t CFDP_VERSION_2 = 0b001; static constexpr uint8_t CFDP_VERSION_2 = 0b001;
static constexpr uint8_t VERSION_BITS = CFDP_VERSION_2 << 5; static constexpr uint8_t VERSION_BITS = CFDP_VERSION_2 << 5;
static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP; static constexpr uint8_t CFDP_CLASS_ID = CLASS_ID::CFDP_BASE;
static constexpr ReturnValue_t INVALID_TLV_TYPE = returnvalue::makeCode(CFDP_CLASS_ID, 1); static constexpr ReturnValue_t INVALID_TLV_TYPE = returnvalue::makeCode(CFDP_CLASS_ID, 1);
static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELD = returnvalue::makeCode(CFDP_CLASS_ID, 2); static constexpr ReturnValue_t INVALID_DIRECTIVE_FIELD = returnvalue::makeCode(CFDP_CLASS_ID, 2);
@ -68,6 +68,7 @@ enum WidthInBytes : uint8_t {
ONE_BYTE = 1, ONE_BYTE = 1,
TWO_BYTES = 2, TWO_BYTES = 2,
FOUR_BYTES = 4, FOUR_BYTES = 4,
EIGHT_BYTES = 8
}; };
enum FileDirective : uint8_t { enum FileDirective : uint8_t {
@ -142,6 +143,20 @@ enum RecordContinuationState {
CONTAINS_START_AND_END = 0b11 CONTAINS_START_AND_END = 0b11
}; };
enum class ProxyOpMessageType : uint8_t {
PUT_REQUEST = 0x00,
MSG_TO_USR = 0x01,
FS_REQUEST = 0x02,
FAULT_HANDLER_OVERRIDE = 0x03,
TRANSMISSION_MODE = 0x04,
FLOW_LABEL = 0x05,
SEG_CTRL = 0x06,
PUT_RESPONSE = 0x07,
FS_RESPONSE = 0x08,
PUT_CANCEL = 0x09,
CLOSURE = 0x0b
};
} // namespace cfdp } // namespace cfdp
#endif /* FSFW_SRC_FSFW_CFDP_PDU_DEFINITIONS_H_ */ #endif /* FSFW_SRC_FSFW_CFDP_PDU_DEFINITIONS_H_ */

View File

@ -1,2 +1,4 @@
target_sources(${LIB_FSFW_NAME} PRIVATE SourceHandler.cpp DestHandler.cpp target_sources(
FaultHandlerBase.cpp UserBase.cpp) ${LIB_FSFW_NAME}
PRIVATE SourceHandler.cpp DestHandler.cpp PutRequest.cpp
ReservedMessageParser.cpp FaultHandlerBase.cpp UserBase.cpp)

View File

@ -16,25 +16,26 @@ using namespace returnvalue;
cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams) cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams)
: tlvVec(params.maxTlvsInOnePdu), : tlvVec(params.maxTlvsInOnePdu),
userTlvVec(params.maxTlvsInOnePdu), msgToUserVec(params.maxTlvsInOnePdu),
dp(std::move(params)), transactionParams(params.maxFilenameLen),
fp(fsfwParams), destParams(std::move(params)),
tp(params.maxFilenameLen) { fsfwParams(fsfwParams) {
tp.pduConf.direction = cfdp::Direction::TOWARDS_SENDER; transactionParams.pduConf.direction = cfdp::Direction::TOWARDS_SENDER;
} }
const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() { const cfdp::DestHandler::FsmResult& cfdp::DestHandler::stateMachine() {
ReturnValue_t result; ReturnValue_t result;
uint8_t errorIdx = 0; uint8_t errorIdx = 0;
fsmRes.resetOfIteration(); fsmRes.resetOfIteration();
if (fsmRes.step == TransactionStep::IDLE) { if (fsmRes.step == TransactionStep::IDLE) {
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { for (auto infoIter = destParams.packetListRef.begin();
infoIter != destParams.packetListRef.end();) {
if (infoIter->pduType == PduType::FILE_DIRECTIVE and if (infoIter->pduType == PduType::FILE_DIRECTIVE and
infoIter->directiveType == FileDirective::METADATA) { infoIter->directiveType == FileDirective::METADATA) {
result = handleMetadataPdu(*infoIter); result = handleMetadataPdu(*infoIter);
checkAndHandleError(result, errorIdx); checkAndHandleError(result, errorIdx);
// Store data was deleted in PDU handler because a store guard is used // Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++); destParams.packetListRef.erase(infoIter++);
} else { } else {
infoIter++; infoIter++;
} }
@ -42,11 +43,12 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() {
if (fsmRes.step == TransactionStep::IDLE) { if (fsmRes.step == TransactionStep::IDLE) {
// To decrease the already high complexity of the software, all packets arriving before // To decrease the already high complexity of the software, all packets arriving before
// a metadata PDU are deleted. // a metadata PDU are deleted.
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { for (auto infoIter = destParams.packetListRef.begin();
fp.tcStore->deleteData(infoIter->storeId); infoIter != destParams.packetListRef.end();) {
fsfwParams.tcStore->deleteData(infoIter->storeId);
infoIter++; infoIter++;
} }
dp.packetListRef.clear(); destParams.packetListRef.clear();
} }
if (fsmRes.step != TransactionStep::IDLE) { if (fsmRes.step != TransactionStep::IDLE) {
@ -54,21 +56,22 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() {
} }
return updateFsmRes(errorIdx); return updateFsmRes(errorIdx);
} }
if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { if (fsmRes.state == CfdpState::BUSY_CLASS_1_NACKED) {
if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) {
for (auto infoIter = dp.packetListRef.begin(); infoIter != dp.packetListRef.end();) { for (auto infoIter = destParams.packetListRef.begin();
infoIter != destParams.packetListRef.end();) {
if (infoIter->pduType == PduType::FILE_DATA) { if (infoIter->pduType == PduType::FILE_DATA) {
result = handleFileDataPdu(*infoIter); result = handleFileDataPdu(*infoIter);
checkAndHandleError(result, errorIdx); checkAndHandleError(result, errorIdx);
// Store data was deleted in PDU handler because a store guard is used // Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++); destParams.packetListRef.erase(infoIter++);
} else if (infoIter->pduType == PduType::FILE_DIRECTIVE and } else if (infoIter->pduType == PduType::FILE_DIRECTIVE and
infoIter->directiveType == FileDirective::EOF_DIRECTIVE) { infoIter->directiveType == FileDirective::EOF_DIRECTIVE) {
// TODO: Support for check timer missing // TODO: Support for check timer missing
result = handleEofPdu(*infoIter); result = handleEofPdu(*infoIter);
checkAndHandleError(result, errorIdx); checkAndHandleError(result, errorIdx);
// Store data was deleted in PDU handler because a store guard is used // Store data was deleted in PDU handler because a store guard is used
dp.packetListRef.erase(infoIter++); destParams.packetListRef.erase(infoIter++);
} else { } else {
infoIter++; infoIter++;
} }
@ -85,7 +88,7 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() {
} }
return updateFsmRes(errorIdx); return updateFsmRes(errorIdx);
} }
if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { if (fsmRes.state == CfdpState::BUSY_CLASS_2_ACKED) {
// TODO: Will be implemented at a later stage // TODO: Will be implemented at a later stage
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CFDP state machine for acknowledged mode not implemented yet" << std::endl; sif::warning << "CFDP state machine for acknowledged mode not implemented yet" << std::endl;
@ -95,29 +98,29 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::performStateMachine() {
} }
ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) { ReturnValue_t cfdp::DestHandler::passPacket(PacketInfo packet) {
if (dp.packetListRef.full()) { if (destParams.packetListRef.full()) {
return FAILED; return FAILED;
} }
dp.packetListRef.push_back(packet); destParams.packetListRef.push_back(packet);
return OK; return OK;
} }
ReturnValue_t cfdp::DestHandler::initialize() { ReturnValue_t cfdp::DestHandler::initialize() {
if (fp.tmStore == nullptr) { if (fsfwParams.tmStore == nullptr) {
fp.tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE); fsfwParams.tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (fp.tmStore == nullptr) { if (fsfwParams.tmStore == nullptr) {
return FAILED; return FAILED;
} }
} }
if (fp.tcStore == nullptr) { if (fsfwParams.tcStore == nullptr) {
fp.tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE); fsfwParams.tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (fp.tcStore == nullptr) { if (fsfwParams.tcStore == nullptr) {
return FAILED; return FAILED;
} }
} }
if (fp.msgQueue == nullptr) { if (fsfwParams.msgQueue == nullptr) {
return FAILED; return FAILED;
} }
return OK; return OK;
@ -125,18 +128,16 @@ ReturnValue_t cfdp::DestHandler::initialize() {
ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) { ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
// Process metadata PDU // Process metadata PDU
auto constAccessorPair = fp.tcStore->getData(info.storeId); auto constAccessorPair = fsfwParams.tcStore->getData(info.storeId);
if (constAccessorPair.first != OK) { if (constAccessorPair.first != OK) {
// TODO: This is not a CFDP error. Event and/or warning? // TODO: This is not a CFDP error. Event and/or warning?
return constAccessorPair.first; return constAccessorPair.first;
} }
cfdp::StringLv sourceFileName; cfdp::StringLv sourceFileName;
cfdp::StringLv destFileName; cfdp::StringLv destFileName;
MetadataInfo metadataInfo(tp.fileSize, sourceFileName, destFileName); MetadataGenericInfo metadataInfo(transactionParams.fileSize);
cfdp::Tlv* tlvArrayAsPtr = tlvVec.data();
metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size());
MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(),
metadataInfo); metadataInfo, tlvVec.data(), tlvVec.size());
ReturnValue_t result = reader.parseData(); ReturnValue_t result = reader.parseData();
// TODO: The standard does not really specify what happens if this kind of error happens // TODO: The standard does not really specify what happens if this kind of error happens
// I think it might be a good idea to cache some sort of error code, which // I think it might be a good idea to cache some sort of error code, which
@ -145,18 +146,17 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
return handleMetadataParseError(result, constAccessorPair.second.data(), return handleMetadataParseError(result, constAccessorPair.second.data(),
constAccessorPair.second.size()); constAccessorPair.second.size());
} }
return startTransaction(reader, metadataInfo); return startTransaction(reader);
} }
ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) { ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info) {
// Process file data PDU // Process file data PDU
auto constAccessorPair = fp.tcStore->getData(info.storeId); auto constAccessorPair = fsfwParams.tcStore->getData(info.storeId);
if (constAccessorPair.first != OK) { if (constAccessorPair.first != OK) {
// TODO: This is not a CFDP error. Event and/or warning? // TODO: This is not a CFDP error. Event and/or warning?
return constAccessorPair.first; return constAccessorPair.first;
} }
cfdp::FileSize offset; FileDataInfo fdInfo;
FileDataInfo fdInfo(offset);
FileDataReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), fdInfo); FileDataReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(), fdInfo);
ReturnValue_t result = reader.parseData(); ReturnValue_t result = reader.parseData();
if (result != OK) { if (result != OK) {
@ -164,46 +164,46 @@ ReturnValue_t cfdp::DestHandler::handleFileDataPdu(const cfdp::PacketInfo& info)
} }
size_t fileSegmentLen = 0; size_t fileSegmentLen = 0;
const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen); const uint8_t* fileData = fdInfo.getFileData(&fileSegmentLen);
FileOpParams fileOpParams(tp.destName.data(), fileSegmentLen); FileOpParams fileOpParams(transactionParams.destName.data(), fileSegmentLen);
fileOpParams.offset = offset.value(); fileOpParams.offset = fdInfo.getOffset().value();
if (dp.cfg.indicCfg.fileSegmentRecvIndicRequired) { if (destParams.cfg.indicCfg.fileSegmentRecvIndicRequired) {
FileSegmentRecvdParams segParams; FileSegmentRecvdParams segParams;
segParams.offset = offset.value(); segParams.offset = fdInfo.getOffset().value();
segParams.id = tp.transactionId; segParams.id = transactionParams.transactionId;
segParams.length = fileSegmentLen; segParams.length = fileSegmentLen;
segParams.recContState = fdInfo.getRecordContinuationState(); segParams.recContState = fdInfo.getRecordContinuationState();
size_t segmentMetadatLen = 0; size_t segmentMetadatLen = 0;
auto* segMetadata = fdInfo.getSegmentMetadata(&segmentMetadatLen); auto* segMetadata = fdInfo.getSegmentMetadata(&segmentMetadatLen);
segParams.segmentMetadata = {segMetadata, segmentMetadatLen}; segParams.segmentMetadata = {segMetadata, segmentMetadatLen};
dp.user.fileSegmentRecvdIndication(segParams); destParams.user.fileSegmentRecvdIndication(segParams);
} }
result = dp.user.vfs.writeToFile(fileOpParams, fileData); result = destParams.user.vfs.writeToFile(fileOpParams, fileData);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
// TODO: Proper Error handling // TODO: Proper Error handling
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "cfdp::DestHandler: VFS file write error with code 0x" << std::hex << std::setw(2) sif::error << "cfdp::DestHandler: VFS file write error with code 0x" << std::hex << std::setw(2)
<< result << std::endl; << result << std::endl;
#endif #endif
tp.vfsErrorCount++; transactionParams.vfsErrorCount++;
if (tp.vfsErrorCount < 3) { if (transactionParams.vfsErrorCount < 3) {
// TODO: Provide execution step as parameter // TODO: Provide execution step as parameter
fp.eventReporter->forwardEvent(events::FILESTORE_ERROR, static_cast<uint8_t>(fsmRes.step), fsfwParams.eventReporter->forwardEvent(events::FILESTORE_ERROR,
result); static_cast<uint8_t>(fsmRes.step), result);
} }
return result; return result;
} else { } else {
tp.deliveryStatus = FileDeliveryStatus::RETAINED_IN_FILESTORE; transactionParams.deliveryStatus = FileDeliveryStatus::RETAINED_IN_FILESTORE;
tp.vfsErrorCount = 0; transactionParams.vfsErrorCount = 0;
} }
if (offset.value() + fileSegmentLen > tp.progress) { if (fdInfo.getOffset().value() + fileSegmentLen > transactionParams.progress) {
tp.progress = offset.value() + fileSegmentLen; transactionParams.progress = fdInfo.getOffset().value() + fileSegmentLen;
} }
return result; return result;
} }
ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) { ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) {
// Process EOF PDU // Process EOF PDU
auto constAccessorPair = fp.tcStore->getData(info.storeId); auto constAccessorPair = fsfwParams.tcStore->getData(info.storeId);
if (constAccessorPair.first != OK) { if (constAccessorPair.first != OK) {
// TODO: This is not a CFDP error. Event and/or warning? // TODO: This is not a CFDP error. Event and/or warning?
return constAccessorPair.first; return constAccessorPair.first;
@ -216,21 +216,21 @@ ReturnValue_t cfdp::DestHandler::handleEofPdu(const cfdp::PacketInfo& info) {
} }
// TODO: Error handling // TODO: Error handling
if (eofInfo.getConditionCode() == ConditionCode::NO_ERROR) { if (eofInfo.getConditionCode() == ConditionCode::NO_ERROR) {
tp.crc = eofInfo.getChecksum(); transactionParams.crc = eofInfo.getChecksum();
uint64_t fileSizeFromEof = eofInfo.getFileSize().value(); uint64_t fileSizeFromEof = eofInfo.getFileSize().value();
// CFDP 4.6.1.2.9: Declare file size error if progress exceeds file size // CFDP 4.6.1.2.9: Declare file size error if progress exceeds file size
if (fileSizeFromEof > tp.progress) { if (fileSizeFromEof > transactionParams.progress) {
// TODO: File size error // TODO: File size error
} }
tp.fileSize.setFileSize(fileSizeFromEof, std::nullopt); transactionParams.fileSize.setFileSize(fileSizeFromEof, std::nullopt);
} }
if (dp.cfg.indicCfg.eofRecvIndicRequired) { if (destParams.cfg.indicCfg.eofRecvIndicRequired) {
dp.user.eofRecvIndication(getTransactionId()); destParams.user.eofRecvIndication(getTransactionId());
} }
if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) { if (fsmRes.step == TransactionStep::RECEIVING_FILE_DATA_PDUS) {
if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { if (fsmRes.state == CfdpState::BUSY_CLASS_1_NACKED) {
fsmRes.step = TransactionStep::TRANSFER_COMPLETION; fsmRes.step = TransactionStep::TRANSFER_COMPLETION;
} else if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { } else if (fsmRes.state == CfdpState::BUSY_CLASS_2_ACKED) {
fsmRes.step = TransactionStep::SENDING_ACK_PDU; fsmRes.step = TransactionStep::SENDING_ACK_PDU;
} }
} }
@ -260,7 +260,7 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result,
cfdp::EntityId destId; cfdp::EntityId destId;
headerReader.getDestId(destId); headerReader.getDestId(destId);
RemoteEntityCfg* remoteCfg; RemoteEntityCfg* remoteCfg;
if (not dp.remoteCfgTable.getRemoteCfg(destId, &remoteCfg)) { if (not destParams.remoteCfgTable.getRemoteCfg(destId, &remoteCfg)) {
// TODO: No remote config for dest ID. I consider this a configuration error, which is not // TODO: No remote config for dest ID. I consider this a configuration error, which is not
// covered by the standard. // covered by the standard.
// Warning or error, yield or cache appropriate returnvalue // Warning or error, yield or cache appropriate returnvalue
@ -274,51 +274,57 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(ReturnValue_t result,
return returnvalue::FAILED; return returnvalue::FAILED;
} }
ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) { ReturnValue_t cfdp::DestHandler::startTransaction(const MetadataPduReader& reader) {
if (fsmRes.state != CfdpStates::IDLE) { if (fsmRes.state != CfdpState::IDLE) {
// According to standard, discard metadata PDU if we are busy // According to standard, discard metadata PDU if we are busy
return OK; return OK;
} }
ReturnValue_t result = OK; ReturnValue_t result = OK;
size_t sourceNameSize = 0; size_t sourceNameSize = 0;
const uint8_t* sourceNamePtr = info.getSourceFileName().getValue(&sourceNameSize); if (not reader.getSourceFileName().isEmpty()) {
if (sourceNameSize + 1 > tp.sourceName.size()) { const uint8_t* sourceNamePtr = reader.getSourceFileName().getValue(&sourceNameSize);
fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0, "source filename too large"); if (sourceNameSize + 1 > transactionParams.sourceName.size()) {
return FAILED; fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0, "source filename too large");
return FAILED;
}
std::memcpy(transactionParams.sourceName.data(), sourceNamePtr, sourceNameSize);
transactionParams.sourceName[sourceNameSize] = '\0';
} }
std::memcpy(tp.sourceName.data(), sourceNamePtr, sourceNameSize);
tp.sourceName[sourceNameSize] = '\0';
size_t destNameSize = 0; size_t destNameSize = 0;
const uint8_t* destNamePtr = info.getDestFileName().getValue(&destNameSize); if (not reader.getDestFileName().isEmpty()) {
if (destNameSize + 1 > tp.destName.size()) { const uint8_t* destNamePtr = reader.getDestFileName().getValue(&destNameSize);
fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0, "dest filename too large"); if (destNameSize + 1 > transactionParams.destName.size()) {
return FAILED; fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0, "dest filename too large");
return FAILED;
}
std::memcpy(transactionParams.destName.data(), destNamePtr, destNameSize);
transactionParams.destName[destNameSize] = '\0';
} }
std::memcpy(tp.destName.data(), destNamePtr, destNameSize);
tp.destName[destNameSize] = '\0';
transactionParams.metadataOnly = true;
// If both dest name size and source name size are 0, we are dealing with a metadata only PDU, // If both dest name size and source name size are 0, we are dealing with a metadata only PDU,
// so there is no need to create a file or truncate an existing file // so there is no need to create a file or truncate an existing file
if (destNameSize > 0 and sourceNameSize > 0) { if (destNameSize > 0 and sourceNameSize > 0) {
FilesystemParams fparams(tp.destName.data()); transactionParams.metadataOnly = false;
FilesystemParams fparams(transactionParams.destName.data());
// handling to allow only specifying target directory. Example: // handling to allow only specifying target directory. Example:
// Source path /test/hello.txt, dest path /tmp -> dest path /tmp/hello.txt // Source path /test/hello.txt, dest path /tmp -> dest path /tmp/hello.txt
if (dp.user.vfs.isDirectory(tp.destName.data())) { if (destParams.user.vfs.isDirectory(transactionParams.destName.data())) {
result = tryBuildingAbsoluteDestName(destNameSize); result = tryBuildingAbsoluteDestName(destNameSize);
if (result != OK) { if (result != OK) {
return result; return result;
} }
} }
if (dp.user.vfs.fileExists(fparams)) { if (destParams.user.vfs.fileExists(fparams)) {
result = dp.user.vfs.truncateFile(fparams); result = destParams.user.vfs.truncateFile(fparams);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
fileErrorHandler(events::FILESTORE_ERROR, result, "file truncation error"); fileErrorHandler(events::FILESTORE_ERROR, result, "file truncation error");
return FAILED; return FAILED;
// TODO: Relevant for filestore rejection error? // TODO: Relevant for filestore rejection error?
} }
} else { } else {
result = dp.user.vfs.createFile(fparams); result = destParams.user.vfs.createFile(fparams);
if (result != OK) { if (result != OK) {
fileErrorHandler(events::FILESTORE_ERROR, result, "file creation error"); fileErrorHandler(events::FILESTORE_ERROR, result, "file creation error");
return FAILED; return FAILED;
@ -328,120 +334,135 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met
} }
EntityId sourceId; EntityId sourceId;
reader.getSourceId(sourceId); reader.getSourceId(sourceId);
if (not dp.remoteCfgTable.getRemoteCfg(sourceId, &tp.remoteCfg)) { if (not destParams.remoteCfgTable.getRemoteCfg(sourceId, &transactionParams.remoteCfg)) {
// TODO: Warning, event etc. // TODO: Warning, event etc.
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler" << __func__ sif::warning << "cfdp::DestHandler" << __func__
<< ": No remote configuration found for destination ID " << ": No remote configuration found for destination ID "
<< tp.pduConf.sourceId.getValue() << std::endl; << transactionParams.pduConf.sourceId.getValue() << std::endl;
#endif #endif
return FAILED; return FAILED;
} }
fsmRes.step = TransactionStep::TRANSACTION_START;
if (reader.getTransmissionMode() == TransmissionMode::UNACKNOWLEDGED) { if (reader.getTransmissionMode() == TransmissionMode::UNACKNOWLEDGED) {
fsmRes.state = CfdpStates::BUSY_CLASS_1_NACKED; fsmRes.state = CfdpState::BUSY_CLASS_1_NACKED;
} else if (reader.getTransmissionMode() == TransmissionMode::ACKNOWLEDGED) { } else if (reader.getTransmissionMode() == TransmissionMode::ACKNOWLEDGED) {
fsmRes.state = CfdpStates::BUSY_CLASS_2_ACKED; fsmRes.state = CfdpState::BUSY_CLASS_2_ACKED;
} }
tp.checksumType = info.getChecksumType(); if (transactionParams.metadataOnly) {
tp.closureRequested = info.isClosureRequested(); fsmRes.step = TransactionStep::TRANSFER_COMPLETION;
reader.fillConfig(tp.pduConf); } else {
tp.pduConf.direction = Direction::TOWARDS_SENDER; // Kind of ugly, make FSM working on packet per packet basis..
tp.transactionId.entityId = tp.pduConf.sourceId; fsmRes.step = TransactionStep::TRANSACTION_START;
tp.transactionId.seqNum = tp.pduConf.seqNum; fsmRes.step = TransactionStep::RECEIVING_FILE_DATA_PDUS;
fsmRes.step = TransactionStep::RECEIVING_FILE_DATA_PDUS; }
MetadataRecvdParams params(tp.transactionId, tp.pduConf.sourceId); auto& info = reader.getGenericInfo();
params.fileSize = tp.fileSize.getSize(); transactionParams.checksumType = info.getChecksumType();
params.destFileName = tp.destName.data(); transactionParams.closureRequested = info.isClosureRequested();
params.sourceFileName = tp.sourceName.data(); reader.fillConfig(transactionParams.pduConf);
params.msgsToUserArray = dynamic_cast<MessageToUserTlv*>(userTlvVec.data()); transactionParams.pduConf.direction = Direction::TOWARDS_SENDER;
params.msgsToUserLen = info.getOptionsLen(); transactionParams.transactionId.entityId = transactionParams.pduConf.sourceId;
dp.user.metadataRecvdIndication(params); transactionParams.transactionId.seqNum = transactionParams.pduConf.seqNum;
transactionParams.fileSize = info.getFileSize();
MetadataRecvdParams params(transactionParams.transactionId, transactionParams.pduConf.sourceId,
transactionParams.fileSize);
params.destFileName = transactionParams.destName.data();
params.sourceFileName = transactionParams.sourceName.data();
params.numberOfMsgsToUser = 0;
for (const auto& opt : tlvVec) {
if (opt.getType() == TlvType::MSG_TO_USER) {
msgToUserVec[params.numberOfMsgsToUser] =
MessageToUserTlv(opt.getValue(), opt.getLengthField());
params.numberOfMsgsToUser++;
}
}
params.msgsToUserArray = msgToUserVec.data();
destParams.user.metadataRecvdIndication(params);
return result; return result;
} }
cfdp::CfdpStates cfdp::DestHandler::getCfdpState() const { return fsmRes.state; } cfdp::CfdpState cfdp::DestHandler::getCfdpState() const { return fsmRes.state; }
ReturnValue_t cfdp::DestHandler::handleTransferCompletion() { ReturnValue_t cfdp::DestHandler::handleTransferCompletion() {
ReturnValue_t result; ReturnValue_t result;
if (tp.checksumType != ChecksumType::NULL_CHECKSUM) { if (transactionParams.checksumType != ChecksumType::NULL_CHECKSUM) {
result = checksumVerification(); result = checksumVerification();
if (result != OK) { if (result != OK) {
// TODO: Warning / error handling? // TODO: Warning / error handling?
} }
} else { } else {
tp.conditionCode = ConditionCode::NO_ERROR; transactionParams.conditionCode = ConditionCode::NO_ERROR;
} }
result = noticeOfCompletion(); result = noticeOfCompletion();
if (result != OK) { if (result != OK) {
} }
if (fsmRes.state == CfdpStates::BUSY_CLASS_1_NACKED) { if (fsmRes.state == CfdpState::BUSY_CLASS_1_NACKED) {
if (tp.closureRequested) { if (transactionParams.closureRequested) {
fsmRes.step = TransactionStep::SENDING_FINISHED_PDU; fsmRes.step = TransactionStep::SENDING_FINISHED_PDU;
} else { } else {
finish(); finish();
} }
} else if (fsmRes.state == CfdpStates::BUSY_CLASS_2_ACKED) { } else if (fsmRes.state == CfdpState::BUSY_CLASS_2_ACKED) {
fsmRes.step = TransactionStep::SENDING_FINISHED_PDU; fsmRes.step = TransactionStep::SENDING_FINISHED_PDU;
} }
return OK; return OK;
} }
ReturnValue_t cfdp::DestHandler::tryBuildingAbsoluteDestName(size_t destNameSize) { ReturnValue_t cfdp::DestHandler::tryBuildingAbsoluteDestName(size_t destNameSize) {
char baseNameBuf[tp.destName.size()]{}; // A path may only have a maximum of 256 characters in CFDP, so this buffer should be sufficient
FilesystemParams fparamsSrc(tp.sourceName.data()); // for all use-cases.
char baseNameBuf[512]{};
FilesystemParams fparamsSrc(transactionParams.sourceName.data());
size_t baseNameLen = 0; size_t baseNameLen = 0;
ReturnValue_t result = ReturnValue_t result = destParams.user.vfs.getBaseFilename(fparamsSrc, baseNameBuf,
dp.user.vfs.getBaseFilename(fparamsSrc, baseNameBuf, sizeof(baseNameBuf), baseNameLen); sizeof(baseNameBuf), baseNameLen);
if (result != returnvalue::OK or baseNameLen == 0) { if (result != returnvalue::OK or baseNameLen == 0) {
fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0, "error retrieving source base name"); fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0, "error retrieving source base name");
return FAILED; return FAILED;
} }
// Destination name + slash + base name + null termination // Destination name + slash + base name + null termination
if (destNameSize + 1 + baseNameLen + 1 > tp.destName.size()) { if (destNameSize + 1 + baseNameLen + 1 > transactionParams.destName.size()) {
fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0, fileErrorHandler(events::FILENAME_TOO_LARGE_ERROR, 0,
"dest filename too large after adding source base name"); "dest filename too large after adding source base name");
return FAILED; return FAILED;
} }
tp.destName[destNameSize++] = '/'; transactionParams.destName[destNameSize++] = '/';
std::memcpy(tp.destName.data() + destNameSize, baseNameBuf, baseNameLen); std::memcpy(transactionParams.destName.data() + destNameSize, baseNameBuf, baseNameLen);
destNameSize += baseNameLen; destNameSize += baseNameLen;
tp.destName[destNameSize++] = '\0'; transactionParams.destName[destNameSize++] = '\0';
return OK; return OK;
} }
void cfdp::DestHandler::fileErrorHandler(Event event, ReturnValue_t result, const char* info) { void cfdp::DestHandler::fileErrorHandler(Event event, ReturnValue_t result,
fp.eventReporter->forwardEvent(events::FILENAME_TOO_LARGE_ERROR, const char* info) const {
static_cast<uint8_t>(fsmRes.step), result); fsfwParams.eventReporter->forwardEvent(event, static_cast<uint8_t>(fsmRes.step), result);
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler: " << info << std::endl; sif::warning << "cfdp::DestHandler: " << info << std::endl;
#endif #endif
} }
void cfdp::DestHandler::finish() { void cfdp::DestHandler::finish() {
tp.reset(); transactionParams.reset();
dp.packetListRef.clear(); destParams.packetListRef.clear();
fsmRes.state = CfdpStates::IDLE; fsmRes.state = CfdpState::IDLE;
fsmRes.step = TransactionStep::IDLE; fsmRes.step = TransactionStep::IDLE;
} }
ReturnValue_t cfdp::DestHandler::checksumVerification() { ReturnValue_t cfdp::DestHandler::checksumVerification() {
std::array<uint8_t, 1024> buf{}; std::array<uint8_t, 1024> buf{};
// TODO: Checksum verification and notice of completion
etl::crc32 crcCalc; etl::crc32 crcCalc;
uint64_t currentOffset = 0; uint64_t currentOffset = 0;
FileOpParams params(tp.destName.data(), tp.fileSize.value()); FileOpParams params(transactionParams.destName.data(), transactionParams.fileSize.value());
while (currentOffset < tp.fileSize.value()) { while (currentOffset < transactionParams.fileSize.value()) {
uint64_t readLen; uint64_t readLen;
if (currentOffset + buf.size() > tp.fileSize.value()) { if (currentOffset + buf.size() > transactionParams.fileSize.value()) {
readLen = tp.fileSize.value() - currentOffset; readLen = transactionParams.fileSize.value() - currentOffset;
} else { } else {
readLen = buf.size(); readLen = buf.size();
} }
if (readLen > 0) { if (readLen > 0) {
params.offset = currentOffset; params.offset = currentOffset;
params.size = readLen; params.size = readLen;
auto result = dp.user.vfs.readFromFile(params, buf.data(), buf.size()); auto result = destParams.user.vfs.readFromFile(params, buf.data(), buf.size());
if (result != OK) { if (result != OK) {
// TODO: I think this is a case for a filestore rejection, but it might sense to print // TODO: I think this is a case for a filestore rejection, but it might sense to print
// a warning or trigger an event because this should generally not happen // a warning or trigger an event because this should generally not happen
@ -453,40 +474,43 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() {
} }
uint32_t value = crcCalc.value(); uint32_t value = crcCalc.value();
if (value == tp.crc) { if (value == transactionParams.crc) {
tp.conditionCode = ConditionCode::NO_ERROR; transactionParams.conditionCode = ConditionCode::NO_ERROR;
tp.deliveryCode = FileDeliveryCode::DATA_COMPLETE; transactionParams.deliveryCode = FileDeliveryCode::DATA_COMPLETE;
} else { } else {
// TODO: Proper error handling // TODO: Proper error handling
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "CRC check for file " << tp.destName.data() << " failed" << std::endl; sif::warning << "CRC check for file " << transactionParams.destName.data() << " failed"
<< std::endl;
#endif #endif
tp.conditionCode = ConditionCode::FILE_CHECKSUM_FAILURE; transactionParams.conditionCode = ConditionCode::FILE_CHECKSUM_FAILURE;
} }
return OK; return OK;
} }
ReturnValue_t cfdp::DestHandler::noticeOfCompletion() { ReturnValue_t cfdp::DestHandler::noticeOfCompletion() {
if (dp.cfg.indicCfg.transactionFinishedIndicRequired) { if (destParams.cfg.indicCfg.transactionFinishedIndicRequired) {
TransactionFinishedParams params(tp.transactionId, tp.conditionCode, tp.deliveryCode, TransactionFinishedParams params(
tp.deliveryStatus); transactionParams.transactionId, transactionParams.conditionCode,
dp.user.transactionFinishedIndication(params); transactionParams.deliveryCode, transactionParams.deliveryStatus);
destParams.user.transactionFinishedIndication(params);
} }
return OK; return OK;
} }
ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { ReturnValue_t cfdp::DestHandler::sendFinishedPdu() {
FinishedInfo info(tp.conditionCode, tp.deliveryCode, tp.deliveryStatus); FinishedInfo info(transactionParams.conditionCode, transactionParams.deliveryCode,
FinishPduCreator finishedPdu(tp.pduConf, info); transactionParams.deliveryStatus);
FinishPduCreator finishedPdu(transactionParams.pduConf, info);
store_address_t storeId; store_address_t storeId;
uint8_t* dataPtr = nullptr; uint8_t* dataPtr = nullptr;
ReturnValue_t result = ReturnValue_t result =
fp.tmStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr); fsfwParams.tmStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr);
if (result != OK) { if (result != OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler:sendFinishedPdu: Getting store slot failed" << std::endl; sif::warning << "cfdp::DestHandler:sendFinishedPdu: Getting store slot failed" << std::endl;
#endif #endif
fp.eventReporter->forwardEvent(events::STORE_ERROR, result, 0); fsfwParams.eventReporter->forwardEvent(events::STORE_ERROR, result, 0);
return result; return result;
} }
size_t serLen = 0; size_t serLen = 0;
@ -496,16 +520,16 @@ ReturnValue_t cfdp::DestHandler::sendFinishedPdu() {
sif::warning << "cfdp::DestHandler::sendFinishedPdu: Serializing Finished PDU failed" sif::warning << "cfdp::DestHandler::sendFinishedPdu: Serializing Finished PDU failed"
<< std::endl; << std::endl;
#endif #endif
fp.eventReporter->forwardEvent(events::SERIALIZATION_ERROR, result, 0); fsfwParams.eventReporter->forwardEvent(events::SERIALIZATION_ERROR, result, 0);
return result; return result;
} }
TmTcMessage msg(storeId); TmTcMessage msg(storeId);
result = fp.msgQueue->sendMessage(fp.packetDest.getReportReceptionQueue(), &msg); result = fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &msg);
if (result != OK) { if (result != OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "cfdp::DestHandler::sendFinishedPdu: Sending PDU failed" << std::endl; sif::warning << "cfdp::DestHandler::sendFinishedPdu: Sending PDU failed" << std::endl;
#endif #endif
fp.eventReporter->forwardEvent(events::MSG_QUEUE_ERROR, result, 0); fsfwParams.eventReporter->forwardEvent(events::MSG_QUEUE_ERROR, result, 0);
return result; return result;
} }
fsmRes.packetsSent++; fsmRes.packetsSent++;
@ -525,7 +549,9 @@ const cfdp::DestHandler::FsmResult& cfdp::DestHandler::updateFsmRes(uint8_t erro
return fsmRes; return fsmRes;
} }
const cfdp::TransactionId& cfdp::DestHandler::getTransactionId() const { return tp.transactionId; } const cfdp::TransactionId& cfdp::DestHandler::getTransactionId() const {
return transactionParams.transactionId;
}
void cfdp::DestHandler::checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx) { void cfdp::DestHandler::checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx) {
if (result != OK and errorIdx < 3) { if (result != OK and errorIdx < 3) {
@ -534,13 +560,15 @@ void cfdp::DestHandler::checkAndHandleError(ReturnValue_t result, uint8_t& error
} }
} }
void cfdp::DestHandler::setMsgQueue(MessageQueueIF& queue) { fp.msgQueue = &queue; } void cfdp::DestHandler::setMsgQueue(MessageQueueIF& queue) { fsfwParams.msgQueue = &queue; }
void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) { void cfdp::DestHandler::setEventReporter(EventReportingProxyIF& reporter) {
fp.eventReporter = &reporter; fsfwParams.eventReporter = &reporter;
} }
const cfdp::DestHandlerParams& cfdp::DestHandler::getDestHandlerParams() const { return dp; } const cfdp::DestHandlerParams& cfdp::DestHandler::getDestHandlerParams() const {
return destParams;
}
StorageManagerIF* cfdp::DestHandler::getTmStore() const { return fp.tmStore; } StorageManagerIF* cfdp::DestHandler::getTmStore() const { return fsfwParams.tmStore; }
StorageManagerIF* cfdp::DestHandler::getTcStore() const { return fp.tcStore; } StorageManagerIF* cfdp::DestHandler::getTcStore() const { return fsfwParams.tcStore; }

View File

@ -13,6 +13,7 @@
#include "fsfw/cfdp/handler/mib.h" #include "fsfw/cfdp/handler/mib.h"
#include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/cfdp/pdu/MetadataPduReader.h"
#include "fsfw/cfdp/pdu/PduConfig.h" #include "fsfw/cfdp/pdu/PduConfig.h"
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
#include "fsfw/container/DynamicFIFO.h" #include "fsfw/container/DynamicFIFO.h"
#include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/storagemanager/storeAddress.h" #include "fsfw/storagemanager/storeAddress.h"
@ -20,23 +21,9 @@
namespace cfdp { namespace cfdp {
struct PacketInfo {
PacketInfo(PduType type, store_address_t storeId,
std::optional<FileDirective> directive = std::nullopt)
: pduType(type), directiveType(directive), storeId(storeId) {}
PduType pduType = PduType::FILE_DATA;
std::optional<FileDirective> directiveType = FileDirective::INVALID_DIRECTIVE;
store_address_t storeId = store_address_t::invalid();
PacketInfo() = default;
};
template <size_t SIZE> template <size_t SIZE>
using LostSegmentsList = etl::set<etl::pair<uint64_t, uint64_t>, SIZE>; using LostSegmentsList = etl::set<etl::pair<uint64_t, uint64_t>, SIZE>;
template <size_t SIZE>
using PacketInfoList = etl::list<PacketInfo, SIZE>;
using LostSegmentsListBase = etl::iset<etl::pair<uint64_t, uint64_t>>; using LostSegmentsListBase = etl::iset<etl::pair<uint64_t, uint64_t>>;
using PacketInfoListBase = etl::ilist<PacketInfo>;
struct DestHandlerParams { struct DestHandlerParams {
DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable, DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable,
@ -44,6 +31,9 @@ struct DestHandlerParams {
// TODO: This container can potentially take tons of space. For a better // TODO: This container can potentially take tons of space. For a better
// memory efficient implementation, an additional abstraction could be // memory efficient implementation, an additional abstraction could be
// be used so users can use uint32_t as the pair type // be used so users can use uint32_t as the pair type
// TODO: Actually, we can provide a better abstraction via interface, which
// allows using something like a bounded map. This simplifies
// the implementation significantly.
LostSegmentsListBase& lostSegmentsContainer) LostSegmentsListBase& lostSegmentsContainer)
: cfg(std::move(cfg)), : cfg(std::move(cfg)),
user(user), user(user),
@ -57,31 +47,10 @@ struct DestHandlerParams {
PacketInfoListBase& packetListRef; PacketInfoListBase& packetListRef;
LostSegmentsListBase& lostSegmentsContainer; LostSegmentsListBase& lostSegmentsContainer;
uint8_t maxTlvsInOnePdu = 10; uint8_t maxTlvsInOnePdu = 20;
size_t maxFilenameLen = 255; size_t maxFilenameLen = 255;
}; };
struct FsfwParams {
FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue,
EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore,
StorageManagerIF& tmStore)
: FsfwParams(packetDest, msgQueue, eventReporter) {
this->tcStore = &tcStore;
this->tmStore = &tmStore;
}
FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue,
EventReportingProxyIF* eventReporter)
: packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {}
AcceptsTelemetryIF& packetDest;
MessageQueueIF* msgQueue;
EventReportingProxyIF* eventReporter = nullptr;
StorageManagerIF* tcStore = nullptr;
StorageManagerIF* tmStore = nullptr;
};
enum class CallStatus { DONE, CALL_AFTER_DELAY, CALL_AGAIN };
class DestHandler { class DestHandler {
public: public:
enum class TransactionStep : uint8_t { enum class TransactionStep : uint8_t {
@ -98,7 +67,7 @@ class DestHandler {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
CallStatus callStatus = CallStatus::CALL_AFTER_DELAY; CallStatus callStatus = CallStatus::CALL_AFTER_DELAY;
TransactionStep step = TransactionStep::IDLE; TransactionStep step = TransactionStep::IDLE;
CfdpStates state = CfdpStates::IDLE; CfdpState state = CfdpState::IDLE;
uint32_t packetsSent = 0; uint32_t packetsSent = 0;
uint8_t errors = 0; uint8_t errors = 0;
std::array<ReturnValue_t, 3> errorCodes = {}; std::array<ReturnValue_t, 3> errorCodes = {};
@ -123,7 +92,7 @@ class DestHandler {
* - @c returnvalue::OK State machine OK for this execution cycle * - @c returnvalue::OK State machine OK for this execution cycle
* - @c CALL_FSM_AGAIN State machine should be called again. * - @c CALL_FSM_AGAIN State machine should be called again.
*/ */
const FsmResult& performStateMachine(); const FsmResult& stateMachine();
void setMsgQueue(MessageQueueIF& queue); void setMsgQueue(MessageQueueIF& queue);
void setEventReporter(EventReportingProxyIF& reporter); void setEventReporter(EventReportingProxyIF& reporter);
@ -131,7 +100,7 @@ class DestHandler {
ReturnValue_t initialize(); ReturnValue_t initialize();
[[nodiscard]] CfdpStates getCfdpState() const; [[nodiscard]] CfdpState getCfdpState() const;
[[nodiscard]] TransactionStep getTransactionStep() const; [[nodiscard]] TransactionStep getTransactionStep() const;
[[nodiscard]] const TransactionId& getTransactionId() const; [[nodiscard]] const TransactionId& getTransactionId() const;
[[nodiscard]] const DestHandlerParams& getDestHandlerParams() const; [[nodiscard]] const DestHandlerParams& getDestHandlerParams() const;
@ -156,17 +125,19 @@ class DestHandler {
crc = 0; crc = 0;
progress = 0; progress = 0;
remoteCfg = nullptr; remoteCfg = nullptr;
metadataOnly = false;
closureRequested = false; closureRequested = false;
vfsErrorCount = 0; vfsErrorCount = 0;
checksumType = ChecksumType::NULL_CHECKSUM; checksumType = ChecksumType::NULL_CHECKSUM;
} }
bool metadataOnly = false;
ChecksumType checksumType = ChecksumType::NULL_CHECKSUM; ChecksumType checksumType = ChecksumType::NULL_CHECKSUM;
bool closureRequested = false; bool closureRequested = false;
uint16_t vfsErrorCount = 0; uint16_t vfsErrorCount = 0;
std::vector<char> sourceName; std::vector<char> sourceName;
std::vector<char> destName; std::vector<char> destName;
cfdp::FileSize fileSize; cfdp::Fss fileSize;
TransactionId transactionId; TransactionId transactionId;
PduConfig pduConf; PduConfig pduConf;
ConditionCode conditionCode = ConditionCode::NO_ERROR; ConditionCode conditionCode = ConditionCode::NO_ERROR;
@ -178,13 +149,13 @@ class DestHandler {
}; };
std::vector<cfdp::Tlv> tlvVec; std::vector<cfdp::Tlv> tlvVec;
std::vector<cfdp::Tlv> userTlvVec; std::vector<MessageToUserTlv> msgToUserVec;
DestHandlerParams dp; TransactionParams transactionParams;
FsfwParams fp; DestHandlerParams destParams;
TransactionParams tp; cfdp::FsfwParams fsfwParams;
FsmResult fsmRes; FsmResult fsmRes;
ReturnValue_t startTransaction(MetadataPduReader& reader, MetadataInfo& info); ReturnValue_t startTransaction(const MetadataPduReader& reader);
ReturnValue_t handleMetadataPdu(const PacketInfo& info); ReturnValue_t handleMetadataPdu(const PacketInfo& info);
ReturnValue_t handleFileDataPdu(const PacketInfo& info); ReturnValue_t handleFileDataPdu(const PacketInfo& info);
ReturnValue_t handleEofPdu(const PacketInfo& info); ReturnValue_t handleEofPdu(const PacketInfo& info);
@ -195,7 +166,7 @@ class DestHandler {
ReturnValue_t sendFinishedPdu(); ReturnValue_t sendFinishedPdu();
ReturnValue_t noticeOfCompletion(); ReturnValue_t noticeOfCompletion();
ReturnValue_t checksumVerification(); ReturnValue_t checksumVerification();
void fileErrorHandler(Event event, ReturnValue_t result, const char* info); void fileErrorHandler(Event event, ReturnValue_t result, const char* info) const;
const FsmResult& updateFsmRes(uint8_t errors); const FsmResult& updateFsmRes(uint8_t errors);
void checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx); void checkAndHandleError(ReturnValue_t result, uint8_t& errorIdx);
void finish(); void finish();

View File

@ -0,0 +1,201 @@
#include "PutRequest.h"
using namespace returnvalue;
cfdp::PutRequest::PutRequest(cfdp::EntityId destId, const uint8_t *msgsToUser,
size_t msgsToUserTotalSize, const uint8_t *fsRequests,
size_t fsRequestsSize)
: destId(std::move(destId)),
metadataOnly(true),
msgsToUsersTotalSize(msgsToUserTotalSize),
msgsToUserStartPtr(msgsToUser),
fsRequestsTotalSize(fsRequestsSize),
fsRequestStartPtr(fsRequests) {}
cfdp::PutRequest::PutRequest(cfdp::EntityId destId, cfdp::StringLv &sourceName,
cfdp::StringLv &destName)
: destId(std::move(destId)), sourceName(std::move(sourceName)), destName(std::move(destName)) {}
[[nodiscard]] bool cfdp::PutRequest::isMetadataOnly() const { return metadataOnly; }
ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
if (buffer == nullptr or size == nullptr) {
return FAILED;
}
if (*size + getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
ReturnValue_t result = destId.serializeAsLv(buffer, size, maxSize);
if (result != OK) {
return result;
}
result = SerializeAdapter::serialize(&metadataOnly, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
if (!metadataOnly) {
result = sourceName.serialize(buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
result = destName.serialize(buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
result =
SerializeAdapter::serialize(&hasTransmissionMode, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
result =
SerializeAdapter::serialize(&transmissionMode, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
result =
SerializeAdapter::serialize(&hasClosureRequested, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
result =
SerializeAdapter::serialize(&closureRequested, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
}
result =
SerializeAdapter::serialize(&msgsToUsersTotalSize, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
std::memcpy(*buffer, msgsToUserStartPtr, msgsToUsersTotalSize);
*buffer += msgsToUsersTotalSize;
*size += msgsToUsersTotalSize;
result =
SerializeAdapter::serialize(&fsRequestsTotalSize, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
std::memcpy(*buffer, fsRequestStartPtr, fsRequestsTotalSize);
*buffer += fsRequestsTotalSize;
*size += fsRequestsTotalSize;
return OK;
}
ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) {
if (buffer == nullptr or size == nullptr) {
return FAILED;
}
ReturnValue_t result = destId.deSerializeFromLv(buffer, size);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&metadataOnly, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
if (!metadataOnly) {
result = sourceName.deSerialize(buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = destName.deSerialize(buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hasTransmissionMode, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&transmissionMode, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&hasClosureRequested, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&closureRequested, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
}
result = SerializeAdapter::deSerialize(&msgsToUsersTotalSize, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
msgsToUserStartPtr = *buffer;
*buffer += msgsToUsersTotalSize;
*size += msgsToUsersTotalSize;
result = SerializeAdapter::deSerialize(&fsRequestsTotalSize, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
fsRequestStartPtr = *buffer;
*buffer += fsRequestsTotalSize;
*size += fsRequestsTotalSize;
return OK;
}
size_t cfdp::PutRequest::getSerializedSize() const {
// Entity ID LV (1 leading size byte) and the metadata only flag.
size_t baseSize = 1 + destId.getSerializedSize() + 1;
if (!metadataOnly) {
baseSize += sourceName.getSerializedSize() + destName.getSerializedSize() + 4;
}
baseSize += sizeof(msgsToUsersTotalSize) + msgsToUsersTotalSize + sizeof(fsRequestsTotalSize) +
fsRequestsTotalSize;
return baseSize;
}
void cfdp::PutRequest::setSourceAndDestName(cfdp::StringLv &sourceName_,
cfdp::StringLv &destName_) {
metadataOnly = false;
this->sourceName = std::move(sourceName_);
this->destName = std::move(destName_);
}
const cfdp::StringLv &cfdp::PutRequest::getSourceName() const { return sourceName; }
const cfdp::StringLv &cfdp::PutRequest::getDestName() const { return destName; }
const cfdp::EntityId &cfdp::PutRequest::getDestId() const { return destId; }
void cfdp::PutRequest::setDestId(cfdp::EntityId id) { destId = std::move(id); }
void cfdp::PutRequest::setTransmissionMode(cfdp::TransmissionMode transmissionMode_) {
this->transmissionMode = transmissionMode_;
hasTransmissionMode = true;
}
void cfdp::PutRequest::clearTransmissionMode() { hasTransmissionMode = false; }
void cfdp::PutRequest::clearClosureRequest() { hasClosureRequested = false; }
void cfdp::PutRequest::setClosureRequest(bool closureRequested_) {
this->closureRequested = closureRequested_;
hasClosureRequested = true;
}
const uint8_t *cfdp::PutRequest::getMessagesToUser(size_t &totalSize) {
totalSize = this->msgsToUsersTotalSize;
return msgsToUserStartPtr;
}
bool cfdp::PutRequest::getClosureRequested(bool &closureRequested_) const {
if (hasClosureRequested) {
closureRequested_ = this->closureRequested;
}
return hasClosureRequested;
}
bool cfdp::PutRequest::getTransmissionMode(cfdp::TransmissionMode &mode) const {
if (hasTransmissionMode) {
mode = static_cast<cfdp::TransmissionMode>(this->transmissionMode);
}
return hasTransmissionMode;
}

View File

@ -0,0 +1,82 @@
#pragma once
#include <optional>
#include <vector>
#include "fsfw/cfdp/VarLenFields.h"
#include "fsfw/cfdp/tlv/FilestoreRequestTlv.h"
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
namespace cfdp {
class PutRequest : public SerializeIF {
public:
/**
* Metadata only constructor.
* @param destId
* @param msgsToUser
* @param msgsToUserTotalSize
* @param fsRequests
* @param fsRequestsSize
*/
PutRequest(EntityId destId, const uint8_t* msgsToUser, size_t msgsToUserTotalSize,
const uint8_t* fsRequests, size_t fsRequestsSize);
/**
* Put request to initiate file transfers. By default, the transmission mode and closure requested
* parameter are not present, thereby being derived from the remote configuration for a
* particular destination ID.
* @param destId
* @param sourceName
* @param destName
*/
PutRequest(EntityId destId, cfdp::StringLv& sourceName, cfdp::StringLv& destName);
/**
* Default constructor for deserialization.
*/
PutRequest() = default;
[[nodiscard]] ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override;
[[nodiscard]] size_t getSerializedSize() const override;
void setSourceAndDestName(cfdp::StringLv& sourceName, cfdp::StringLv& destName);
[[nodiscard]] const cfdp::StringLv& getSourceName() const;
[[nodiscard]] const cfdp::StringLv& getDestName() const;
void setTransmissionMode(cfdp::TransmissionMode transmissionMode);
void clearTransmissionMode();
void setClosureRequest(bool closureRequested);
void clearClosureRequest();
const uint8_t* getMessagesToUser(size_t& msgSize);
[[nodiscard]] bool isMetadataOnly() const;
bool getTransmissionMode(TransmissionMode& mode) const;
bool getClosureRequested(bool& closureRequested) const;
[[nodiscard]] const EntityId& getDestId() const;
void setDestId(EntityId id);
private:
EntityId destId;
uint8_t metadataOnly = true;
// Transaction parameters. Omitted if the put request is metadata only.
cfdp::StringLv sourceName;
cfdp::StringLv destName;
bool hasTransmissionMode = false;
uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
bool hasClosureRequested = false;
uint8_t closureRequested = false;
// Metadata
size_t msgsToUsersTotalSize = 0;
const uint8_t* msgsToUserStartPtr = nullptr;
size_t fsRequestsTotalSize = 0;
const uint8_t* fsRequestStartPtr = nullptr;
};
} // namespace cfdp

View File

@ -16,7 +16,7 @@ class RemoteConfigTableIF {
*/ */
class OneRemoteConfigProvider : public RemoteConfigTableIF { class OneRemoteConfigProvider : public RemoteConfigTableIF {
public: public:
explicit OneRemoteConfigProvider(RemoteEntityCfg cfg) : cfg(std::move(cfg)) {} explicit OneRemoteConfigProvider(RemoteEntityCfg& cfg) : cfg(cfg) {}
bool getRemoteCfg(const EntityId& remoteId, cfdp::RemoteEntityCfg** cfg_) override { bool getRemoteCfg(const EntityId& remoteId, cfdp::RemoteEntityCfg** cfg_) override {
if (remoteId != cfg.remoteId) { if (remoteId != cfg.remoteId) {
@ -27,7 +27,7 @@ class OneRemoteConfigProvider : public RemoteConfigTableIF {
} }
private: private:
RemoteEntityCfg cfg; RemoteEntityCfg& cfg;
}; };
} // namespace cfdp } // namespace cfdp

View File

@ -0,0 +1,74 @@
#include "ReservedMessageParser.h"
#include "fsfw/cfdp/CfdpMessage.h"
#include "fsfw/cfdp/handler/PutRequest.h"
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
#include "fsfw/ipc/CommandMessage.h"
#include "fsfw/ipc/QueueFactory.h"
using namespace returnvalue;
cfdp::ReservedMessageParser::ReservedMessageParser(StorageManagerIF& ipcStore,
MessageQueueIF& msgQueue,
MessageQueueId_t userDestination)
: msgQueue(msgQueue), ipcStore(ipcStore), userDestination(userDestination) {}
ReturnValue_t cfdp::ReservedMessageParser::parse(const MessageToUserTlv* msgsToUserArray,
size_t numMsgToUser) {
ReturnValue_t result = returnvalue::OK;
cfdp::StringLv sourceFileName;
cfdp::StringLv destFileName;
PutRequest putRequest;
const uint8_t* currentPtr = nullptr;
size_t deserSize = 0;
bool needToSendPutRequest = false;
for (size_t idx = 0; idx < numMsgToUser; idx++) {
if (&msgsToUserArray[idx] == nullptr) {
continue;
}
uint8_t messageType = 0;
if (msgsToUserArray[idx].isReservedCfdpMessage(messageType, &currentPtr, deserSize)) {
if (messageType == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST)) {
EntityId entityIdLv;
result = entityIdLv.deSerializeFromLv(&currentPtr, &deserSize);
if (result != returnvalue::OK) {
return result;
}
putRequest.setDestId(entityIdLv);
result =
sourceFileName.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);
if (result != OK) {
return result;
}
result =
destFileName.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);
if (result != OK) {
return result;
}
putRequest.setSourceAndDestName(sourceFileName, destFileName);
needToSendPutRequest = true;
}
}
}
if (needToSendPutRequest) {
store_address_t storeId;
uint8_t* dataPtr;
result = ipcStore.getFreeElement(&storeId, putRequest.getSerializedSize(), &dataPtr);
if (result != OK) {
return result;
}
size_t serLen = 0;
result = putRequest.serialize(&dataPtr, &serLen, putRequest.getSerializedSize(),
SerializeIF::Endianness::MACHINE);
if (result != OK) {
return result;
}
CommandMessage msg;
CfdpMessage::setPutRequest(&msg, storeId);
result = msgQueue.sendMessage(userDestination, &msg);
if (result != OK) {
return result;
}
}
return OK;
}

View File

@ -0,0 +1,27 @@
#pragma once
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
namespace cfdp {
/**
* This class parses messages to user for special CFDP messages and converts them to appropriate
* CFDP requests sent via the IPC store where applicable. It also provides an API to retrieve
* custom messages which are not special CFDP messages from a provided bytestream.
*/
class ReservedMessageParser {
public:
ReservedMessageParser(StorageManagerIF& ipcStore, MessageQueueIF& msgQueue,
MessageQueueId_t userDestination);
ReturnValue_t parse(const MessageToUserTlv* msgsToUserArray, size_t numMsgsToUser);
private:
MessageQueueIF& msgQueue;
StorageManagerIF& ipcStore;
MessageQueueId_t userDestination;
};
} // namespace cfdp

View File

@ -1 +1,376 @@
#include "SourceHandler.h" #include "SourceHandler.h"
#include <etl/crc32.h>
#include <array>
#include "fsfw/cfdp/pdu/EofPduCreator.h"
#include "fsfw/cfdp/pdu/FileDataCreator.h"
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "fsfw/filesystem/HasFileSystemIF.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/objectmanager.h"
#include "fsfw/serviceinterface.h"
#include "fsfw/tasks/TaskFactory.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
using namespace returnvalue;
cfdp::SourceHandler::SourceHandler(SourceHandlerParams params, FsfwParams fsfwParams)
: sourceParams(std::move(params)), fsfwParams(fsfwParams) {
// The entity ID portion of the transaction ID will always remain fixed.
transactionParams.id.entityId = sourceParams.cfg.localId;
transactionParams.pduConf.sourceId = sourceParams.cfg.localId;
if (sourceParams.seqCountProvider.bitWidth() == 8) {
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::ONE_BYTE);
} else if (sourceParams.seqCountProvider.bitWidth() == 16) {
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::TWO_BYTES);
} else if (sourceParams.seqCountProvider.bitWidth() == 32) {
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::FOUR_BYTES);
} else if (sourceParams.seqCountProvider.bitWidth() == 64) {
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::EIGHT_BYTES);
} else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "cfdp::SourceHandler: Seq count provider bit width "
<< sourceParams.seqCountProvider.bitWidth() << " not allowed" << std::endl;
#else
sif::printError("cfdp::SourceHandler: Seq count provider bit width %d not allowed\n",
sourceParams.seqCountProvider.bitWidth());
#endif
// Yeah, what am I supposed to do here? Can't throw an exception in the FSFW..
transactionParams.pduConf.seqNum.setWidth(cfdp::WidthInBytes::ONE_BYTE);
}
transactionParams.pduConf.seqNum.setValue(0);
}
cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::fsmNacked() {
ReturnValue_t result;
if (step == TransactionStep::IDLE) {
step = TransactionStep::TRANSACTION_START;
}
if (step == TransactionStep::TRANSACTION_START) {
sourceParams.user.transactionIndication(transactionParams.id);
result = checksumGeneration();
if (result != OK) {
addError(result);
}
step = TransactionStep::SENDING_METADATA;
}

boop

boop
if (step == TransactionStep::SENDING_METADATA) {
result = prepareAndSendMetadataPdu();
if (result != OK) {
addError(result);
}
fsmResult.callStatus = CallStatus::CALL_AGAIN;
return fsmResult;

boop

boop
}
if (step == TransactionStep::SENDING_FILE_DATA) {
bool noFdPdu = false;
result = prepareAndSendNextFileDataPdu(noFdPdu);
if (result == OK and !noFdPdu) {
fsmResult.callStatus = CallStatus::CALL_AGAIN;
return fsmResult;
}
}
if (step == TransactionStep::SENDING_EOF) {
result = prepareAndSendEofPdu();
if (result != OK) {
addError(result);
}
if (sourceParams.cfg.indicCfg.eofSentIndicRequired) {
sourceParams.user.eofSentIndication(transactionParams.id);

boop

boop
}
if (transactionParams.closureRequested) {
step = TransactionStep::WAIT_FOR_FINISH;
fsmResult.callStatus = CallStatus::CALL_AFTER_DELAY;
} else {
step = TransactionStep::NOTICE_OF_COMPLETION;
fsmResult.callStatus = CallStatus::CALL_AGAIN;
}
return fsmResult;
}
if (step == TransactionStep::WAIT_FOR_FINISH) {
// TODO: In case this is a request with closure, wait for finish.
// Done, issue notice of completion
step = TransactionStep::NOTICE_OF_COMPLETION;
}
if (step == TransactionStep::NOTICE_OF_COMPLETION) {
noticeOfCompletion();
reset();
}
return fsmResult;
}
const cfdp::SourceHandler::FsmResult& cfdp::SourceHandler::stateMachine() {
fsmResult.packetsSent = 0;
fsmResult.errors = 0;
fsmResult.callStatus = CallStatus::DONE;
if (state == cfdp::CfdpState::IDLE) {
return fsmResult;
}
if (state == cfdp::CfdpState::BUSY_CLASS_1_NACKED) {
return fsmNacked();
}
return fsmResult;
}
ReturnValue_t cfdp::SourceHandler::checksumGeneration() {
if (transactionParams.fileSize.value() == 0) {
// NULL checksum for empty file.
transactionParams.crc = 0;
return OK;
}
std::array<uint8_t, 1024> buf{};
etl::crc32 crcCalc;
uint64_t currentOffset = 0;
FileOpParams params(transactionParams.sourceName.data(), transactionParams.fileSize.value());
while (currentOffset < transactionParams.fileSize.value()) {
uint64_t readLen;
if (currentOffset + buf.size() > transactionParams.fileSize.value()) {
readLen = transactionParams.fileSize.value() - currentOffset;
} else {
readLen = buf.size();
}
if (readLen > 0) {
params.offset = currentOffset;
params.size = readLen;
auto result = sourceParams.user.vfs.readFromFile(params, buf.data(), buf.size());
if (result != OK) {
addError(result);
return FAILED;
}
crcCalc.add(buf.begin(), buf.begin() + readLen);
Review

boop

boop
Review

Will be added when fault declaration works properly

Will be added when fault declaration works properly
}
currentOffset += readLen;
}
transactionParams.crc = crcCalc.value();
return OK;
}
ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, RemoteEntityCfg& cfg) {
if (state != CfdpState::IDLE) {
return SOURCE_TRANSACTION_PENDING;
}
if (cfg.remoteId != putRequest.getDestId()) {
return WRONG_REMOTE_CFG_ENTITY_ID;
}
if (putRequest.getSourceName().getValueLen() == 0) {
return SOURCE_NAME_EMPTY;
}
if (putRequest.getDestName().getValueLen() == 0) {
return DEST_NAME_EMPTY;
}
const char* srcNamePtr = putRequest.getSourceName().getCString(transactionParams.sourceNameSize);
const char* destNamePtr = putRequest.getDestName().getCString(transactionParams.destNameSize);
std::strncpy(transactionParams.sourceName.data(), srcNamePtr, transactionParams.sourceNameSize);
std::strncpy(transactionParams.destName.data(), destNamePtr, transactionParams.destNameSize);
// Add 0 termination. The source and dest name size can not be larger than UINT8_MAX, so this
// operation is safe.
transactionParams.sourceName[transactionParams.sourceNameSize] = '\0';
transactionParams.destName[transactionParams.destNameSize] = '\0';
FilesystemParams params(transactionParams.sourceName.data());
if (!sourceParams.user.vfs.fileExists(params)) {
return FILE_DOES_NOT_EXIST;
}
if (cfg.maxFileSegmentLen > fileBuf.size() or cfg.maxFileSegmentLen == 0) {
return FILE_SEGMENT_LEN_INVALID;
}
// If transmission mode is not set, use default transmission mode for the remote entity.
if (not putRequest.getTransmissionMode(transactionParams.pduConf.mode)) {
transactionParams.pduConf.mode = cfg.defaultTransmissionMode;
}
// If closure request field is not set, use default option for the remote entity.
if (not putRequest.getClosureRequested(transactionParams.closureRequested)) {
transactionParams.closureRequested = cfg.closureRequested;
}
const EntityId& destId = putRequest.getDestId();
// The width of the source and destination ID must be the same. Use the larger ID value to
// ensure the width is large enough for both IDs
if (destId.getWidth() > transactionParams.pduConf.sourceId.getWidth()) {
transactionParams.pduConf.destId = destId;
transactionParams.pduConf.sourceId.setWidth(destId.getWidth());
} else {
transactionParams.pduConf.destId.setValueAndWidth(transactionParams.pduConf.sourceId.getWidth(),
destId.getValue());
}
// Only used for PDU forwarding, file is sent to file receiver regularly here.
transactionParams.pduConf.direction = Direction::TOWARDS_RECEIVER;
transactionParams.pduConf.seqNum.setValue(sourceParams.seqCountProvider.getAndIncrement());
transactionParams.id.seqNum = transactionParams.pduConf.seqNum;
if (transactionParams.pduConf.mode == TransmissionMode::ACKNOWLEDGED) {
state = cfdp::CfdpState::BUSY_CLASS_2_ACKED;
} else if (transactionParams.pduConf.mode == TransmissionMode::UNACKNOWLEDGED) {
state = cfdp::CfdpState::BUSY_CLASS_1_NACKED;
}
step = TransactionStep::IDLE;
uint64_t fileSize = 0;
sourceParams.user.vfs.getFileSize(params, fileSize);
transactionParams.pduConf.largeFile = false;
if (fileSize > UINT32_MAX) {
transactionParams.pduConf.largeFile = true;
}
if (fileSize == 0) {
transactionParams.checksumType = ChecksumType::NULL_CHECKSUM;
} else {
transactionParams.checksumType = ChecksumType::CRC_32;
}
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
transactionParams.progress = 0;
transactionParams.remoteCfg = cfg;
return OK;
}
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
cfdp::StringLv destName(transactionParams.destName.data(), transactionParams.destNameSize);
auto metadataInfo =
MetadataGenericInfo(transactionParams.closureRequested, transactionParams.checksumType,
transactionParams.fileSize);
auto metadataPdu =
MetadataPduCreator(transactionParams.pduConf, metadataInfo, sourceName, destName, nullptr, 0);
ReturnValue_t result = sendGenericPdu(metadataPdu);
if (result != OK) {
return result;
}
// Advance FSM if everything works
step = TransactionStep::SENDING_FILE_DATA;
return OK;
}
ReturnValue_t cfdp::SourceHandler::prepareAndSendNextFileDataPdu(bool& noFileDataPdu) {
cfdp::Fss offset(transactionParams.progress);
uint64_t readLen;
uint64_t fileSize = transactionParams.fileSize.value();
noFileDataPdu = false;
if (fileSize == 0) {
// We are done, no need to send file data PDUs for an empty file.
step = TransactionStep::SENDING_EOF;
noFileDataPdu = true;
return OK;
}
if (fileSize < transactionParams.remoteCfg.maxFileSegmentLen) {
readLen = transactionParams.fileSize.value();
} else {
if (transactionParams.progress + transactionParams.remoteCfg.maxFileSegmentLen > fileSize) {
readLen = fileSize - transactionParams.progress;
} else {
readLen = transactionParams.remoteCfg.maxFileSegmentLen;
}
}
FileOpParams fileParams(transactionParams.sourceName.data(), readLen);
fileParams.offset = transactionParams.progress;
ReturnValue_t result =
sourceParams.user.vfs.readFromFile(fileParams, fileBuf.data(), fileBuf.size());
if (result != returnvalue::OK) {
addError(result);
return result;
}
auto fileDataInfo = FileDataInfo(offset, fileBuf.data(), readLen);
auto fileDataPdu = FileDataCreator(transactionParams.pduConf, fileDataInfo);
result = sendGenericPdu(fileDataPdu);
if (result != OK) {
return result;
}
transactionParams.progress += readLen;
if (transactionParams.progress >= fileSize) {
// Advance FSM after all file data PDUs were sent.
step = TransactionStep::SENDING_EOF;
}
return OK;
}
ReturnValue_t cfdp::SourceHandler::prepareAndSendEofPdu() {
auto eofInfo =
EofInfo(ConditionCode::NO_ERROR, transactionParams.crc, transactionParams.fileSize);
auto eofPdu = EofPduCreator(transactionParams.pduConf, eofInfo);
ReturnValue_t result = sendGenericPdu(eofPdu);
if (result != OK) {
return result;
}
return OK;
}
ReturnValue_t cfdp::SourceHandler::initialize() {
if (fsfwParams.tmStore == nullptr) {
fsfwParams.tmStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (fsfwParams.tmStore == nullptr) {
return FAILED;
}
}
if (fsfwParams.tcStore == nullptr) {
fsfwParams.tcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (fsfwParams.tcStore == nullptr) {
return FAILED;
}
}
if (fsfwParams.msgQueue == nullptr) {
return FAILED;
}
return OK;
}
ReturnValue_t cfdp::SourceHandler::sendGenericPdu(const SerializeIF& pdu) {
uint8_t* dataPtr;
store_address_t storeId;
ReturnValue_t result =
fsfwParams.tmStore->getFreeElement(&storeId, pdu.getSerializedSize(), &dataPtr);
if (result != OK) {
addError(result);
fsmResult.callStatus = CallStatus::CALL_AFTER_DELAY;
if (result == StorageManagerIF::DATA_STORAGE_FULL) {
return TM_STORE_FULL;
}
return result;
}
size_t serializedLen = 0;
result = pdu.serializeBe(dataPtr, serializedLen, pdu.getSerializedSize());
if (result != OK) {
addError(result);
return result;
}
TmTcMessage tmMsg(storeId);
result =
fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tmMsg);
if (result != OK) {
fsmResult.callStatus = CallStatus::CALL_AFTER_DELAY;
}
if (result == MessageQueueIF::FULL) {
return TARGET_MSG_QUEUE_FULL;
} else if (result == OK) {
fsmResult.packetsSent += 1;
}
return result;
}
ReturnValue_t cfdp::SourceHandler::noticeOfCompletion() {
if (sourceParams.cfg.indicCfg.transactionFinishedIndicRequired) {
cfdp::TransactionFinishedParams params(transactionParams.id, ConditionCode::NO_ERROR,
FileDeliveryCode::DATA_COMPLETE,
FileDeliveryStatus::RETAINED_IN_FILESTORE);
sourceParams.user.transactionFinishedIndication(params);
}
return OK;
}
ReturnValue_t cfdp::SourceHandler::reset() {
step = TransactionStep::IDLE;
state = cfdp::CfdpState::IDLE;
fsmResult.callStatus = CallStatus::DONE;
transactionParams.reset();
return OK;
}
cfdp::CfdpState cfdp::SourceHandler::getState() const { return state; }
cfdp::SourceHandler::TransactionStep cfdp::SourceHandler::getStep() const { return step; }
void cfdp::SourceHandler::addError(ReturnValue_t error) {
if (fsmResult.errors < fsmResult.errorCodes.size()) {
fsmResult.errorCodes[fsmResult.errors] = error;
fsmResult.errors++;
fsmResult.result = error;
}
}

View File

@ -1,6 +1,110 @@
#ifndef FSFW_CFDP_CFDPSOURCEHANDLER_H #ifndef FSFW_CFDP_CFDPSOURCEHANDLER_H
#define FSFW_CFDP_CFDPSOURCEHANDLER_H #define FSFW_CFDP_CFDPSOURCEHANDLER_H
class SourceHandler {}; #include <cstdint>
#include <vector>
#include "UserBase.h"
#include "defs.h"
#include "fsfw/cfdp/Fss.h"
#include "fsfw/cfdp/handler/PutRequest.h"
#include "fsfw/cfdp/handler/mib.h"
#include "fsfw/events/EventReportingProxyIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
#include "fsfw/util/ProvidesSeqCountIF.h"
namespace cfdp {
struct SourceHandlerParams {
SourceHandlerParams(LocalEntityCfg cfg, UserBase& user, ProvidesSeqCountIF& seqCountProvider)
: cfg(std::move(cfg)), user(user), seqCountProvider(seqCountProvider) {}
LocalEntityCfg cfg;
UserBase& user;
ProvidesSeqCountIF& seqCountProvider;
};
class SourceHandler {
public:
enum class TransactionStep : uint8_t {
IDLE = 0,
TRANSACTION_START = 1,
SENDING_METADATA = 3,
SENDING_FILE_DATA = 4,
SENDING_EOF = 5,
WAIT_FOR_ACK = 6,
WAIT_FOR_FINISH = 7,
NOTICE_OF_COMPLETION = 8
};
struct FsmResult {
public:
ReturnValue_t result = returnvalue::OK;
CallStatus callStatus = CallStatus::CALL_AFTER_DELAY;
CfdpState state = CfdpState::IDLE;
uint32_t packetsSent = 0;
uint8_t errors = 0;
std::array<ReturnValue_t, 3> errorCodes = {};
};
SourceHandler(SourceHandlerParams params, FsfwParams fsfwParams);
[[nodiscard]] CfdpState getState() const;
[[nodiscard]] TransactionStep getStep() const;
/**
* Pass a put request to the source handler, which might initiate a CFDP transaction and start
* the state machine
* @return
*/
ReturnValue_t transactionStart(PutRequest& putRequest, RemoteEntityCfg& cfg);
const FsmResult& stateMachine();
ReturnValue_t initialize();
private:
struct TransactionParams {
uint32_t crc{};
std::array<char, UINT8_MAX + 1> sourceName{};
size_t sourceNameSize = 0;
std::array<char, UINT8_MAX + 1> destName{};
size_t destNameSize = 0;
cfdp::Fss fileSize;
size_t progress = 0;
bool closureRequested = false;
ChecksumType checksumType = ChecksumType::NULL_CHECKSUM;
RemoteEntityCfg remoteCfg;
PduConfig pduConf;
cfdp::TransactionId id{};
void reset() {
sourceNameSize = 0;
destNameSize = 0;
fileSize.setFileSize(0, false);
progress = 0;
closureRequested = false;
}
} transactionParams;
cfdp::CfdpState state = cfdp::CfdpState::IDLE;
TransactionStep step = TransactionStep::IDLE;
std::array<uint8_t, 4096> fileBuf{};
SourceHandlerParams sourceParams;
cfdp::FsfwParams fsfwParams;
FsmResult fsmResult;
FsmResult& fsmNacked();
ReturnValue_t checksumGeneration();
ReturnValue_t prepareAndSendMetadataPdu();
ReturnValue_t prepareAndSendNextFileDataPdu(bool& noFileDataPdu);
ReturnValue_t prepareAndSendEofPdu();
ReturnValue_t noticeOfCompletion();
ReturnValue_t reset();
[[nodiscard]] ReturnValue_t sendGenericPdu(const SerializeIF& pdu);
void addError(ReturnValue_t error);
};
} // namespace cfdp
#endif // FSFW_CFDP_CFDPSOURCEHANDLER_H #endif // FSFW_CFDP_CFDPSOURCEHANDLER_H

View File

@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include "StatusReportIF.h" #include "StatusReportIF.h"
#include "fsfw/cfdp/Fss.h"
#include "fsfw/cfdp/VarLenFields.h" #include "fsfw/cfdp/VarLenFields.h"
#include "fsfw/cfdp/tlv/FilestoreResponseTlv.h" #include "fsfw/cfdp/tlv/FilestoreResponseTlv.h"
#include "fsfw/cfdp/tlv/MessageToUserTlv.h" #include "fsfw/cfdp/tlv/MessageToUserTlv.h"
@ -27,14 +28,14 @@ struct TransactionFinishedParams {
}; };
struct MetadataRecvdParams { struct MetadataRecvdParams {
MetadataRecvdParams(const TransactionId& id, const EntityId& sourceId) MetadataRecvdParams(const TransactionId& id, const EntityId& sourceId, Fss fileSize)
: id(id), sourceId(sourceId) {} : id(id), sourceId(sourceId), fileSize(std::move(fileSize)) {}
const TransactionId& id; const TransactionId& id;
const EntityId& sourceId; const EntityId& sourceId;
uint64_t fileSize = 0; Fss fileSize{};
const char* sourceFileName = ""; const char* sourceFileName = "";
const char* destFileName = ""; const char* destFileName = "";
size_t msgsToUserLen = 0; size_t numberOfMsgsToUser = 0;
const MessageToUserTlv* msgsToUserArray = nullptr; const MessageToUserTlv* msgsToUserArray = nullptr;
}; };
@ -65,6 +66,7 @@ struct FileSegmentRecvdParams {
*/ */
class UserBase { class UserBase {
friend class DestHandler; friend class DestHandler;
friend class SourceHandler;
public: public:
explicit UserBase(HasFileSystemIF& vfs); explicit UserBase(HasFileSystemIF& vfs);

View File

@ -1,11 +1,54 @@
#ifndef FSFW_CFDP_HANDLER_DEFS_H #ifndef FSFW_CFDP_HANDLER_DEFS_H
#define FSFW_CFDP_HANDLER_DEFS_H #define FSFW_CFDP_HANDLER_DEFS_H
#include <etl/list.h>
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "fsfw/storagemanager/storeAddress.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
namespace cfdp { namespace cfdp {
enum class CfdpStates { IDLE, BUSY_CLASS_1_NACKED, BUSY_CLASS_2_ACKED, SUSPENDED }; enum class CfdpState { IDLE, BUSY_CLASS_1_NACKED, BUSY_CLASS_2_ACKED, SUSPENDED };
static constexpr uint8_t SSID = SUBSYSTEM_ID::CFDP; static constexpr uint8_t SSID = SUBSYSTEM_ID::CFDP;
static constexpr uint8_t CID = CLASS_ID::CFDP_HANDLER;
struct PacketInfo {
PacketInfo(PduType type, store_address_t storeId,
std::optional<FileDirective> directive = std::nullopt)
: pduType(type), directiveType(directive), storeId(storeId) {}
PduType pduType = PduType::FILE_DATA;
std::optional<FileDirective> directiveType = FileDirective::INVALID_DIRECTIVE;
store_address_t storeId = store_address_t::invalid();
PacketInfo() = default;
};
struct FsfwParams {
FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue,
EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore,
StorageManagerIF& tmStore)
: FsfwParams(packetDest, msgQueue, eventReporter) {
this->tcStore = &tcStore;
this->tmStore = &tmStore;
}
FsfwParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue,
EventReportingProxyIF* eventReporter)
: packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {}
AcceptsTelemetryIF& packetDest;
MessageQueueIF* msgQueue;
EventReportingProxyIF* eventReporter = nullptr;
StorageManagerIF* tcStore = nullptr;
StorageManagerIF* tmStore = nullptr;
};
template <size_t SIZE>
using PacketInfoList = etl::list<PacketInfo, SIZE>;
using PacketInfoListBase = etl::ilist<PacketInfo>;
enum class CallStatus { DONE, CALL_AFTER_DELAY, CALL_AGAIN };
namespace events { namespace events {
@ -15,8 +58,19 @@ static constexpr Event SERIALIZATION_ERROR = event::makeEvent(SSID, 2, severity:
static constexpr Event FILESTORE_ERROR = event::makeEvent(SSID, 3, severity::LOW); static constexpr Event FILESTORE_ERROR = event::makeEvent(SSID, 3, severity::LOW);
//! [EXPORT] : [COMMENT] P1: Transaction step ID, P2: 0 for source file name, 1 for dest file name //! [EXPORT] : [COMMENT] P1: Transaction step ID, P2: 0 for source file name, 1 for dest file name
static constexpr Event FILENAME_TOO_LARGE_ERROR = event::makeEvent(SSID, 4, severity::LOW); static constexpr Event FILENAME_TOO_LARGE_ERROR = event::makeEvent(SSID, 4, severity::LOW);
//! [EXPORT] : [COMMENT] CFDP request handling failed. P2: Returncode.
static constexpr Event HANDLING_CFDP_REQUEST_FAILED = event::makeEvent(SSID, 5, severity::LOW);
} // namespace events } // namespace events
static constexpr ReturnValue_t SOURCE_TRANSACTION_PENDING = returnvalue::makeCode(CID, 0);
static constexpr ReturnValue_t FILE_DOES_NOT_EXIST = returnvalue::makeCode(CID, 1);
static constexpr ReturnValue_t FILE_SEGMENT_LEN_INVALID = returnvalue::makeCode(CID, 2);
static constexpr ReturnValue_t SOURCE_NAME_EMPTY = returnvalue::makeCode(CID, 3);
static constexpr ReturnValue_t DEST_NAME_EMPTY = returnvalue::makeCode(CID, 4);
static constexpr ReturnValue_t WRONG_REMOTE_CFG_ENTITY_ID = returnvalue::makeCode(CID, 5);
static constexpr ReturnValue_t TARGET_MSG_QUEUE_FULL = returnvalue::makeCode(CID, 6);
static constexpr ReturnValue_t TM_STORE_FULL = returnvalue::makeCode(CID, 7);
} // namespace cfdp } // namespace cfdp
#endif // FSFW_CFDP_HANDLER_DEFS_H #endif // FSFW_CFDP_HANDLER_DEFS_H

View File

@ -27,14 +27,15 @@ struct LocalEntityCfg {
}; };
struct RemoteEntityCfg { struct RemoteEntityCfg {
RemoteEntityCfg() = default;
explicit RemoteEntityCfg(EntityId id) : remoteId(std::move(id)) {} explicit RemoteEntityCfg(EntityId id) : remoteId(std::move(id)) {}
EntityId remoteId; EntityId remoteId;
size_t maxFileSegmentLen = 2048; size_t maxFileSegmentLen = 1024;
bool closureRequested = false; bool closureRequested = false;
bool crcOnTransmission = false; bool crcOnTransmission = false;
TransmissionMode defaultTransmissionMode = TransmissionMode::UNACKNOWLEDGED; TransmissionMode defaultTransmissionMode = TransmissionMode::UNACKNOWLEDGED;
ChecksumType defaultChecksum = ChecksumType::NULL_CHECKSUM; ChecksumType defaultChecksum = ChecksumType::NULL_CHECKSUM;
const uint8_t version = CFDP_VERSION_2; uint8_t version = CFDP_VERSION_2;
}; };
} // namespace cfdp } // namespace cfdp

View File

@ -17,7 +17,7 @@ target_sources(
FinishedInfo.cpp FinishedInfo.cpp
FinishedPduCreator.cpp FinishedPduCreator.cpp
FinishedPduReader.cpp FinishedPduReader.cpp
MetadataInfo.cpp MetadataGenericInfo.cpp
MetadataPduCreator.cpp MetadataPduCreator.cpp
MetadataPduReader.cpp MetadataPduReader.cpp
KeepAlivePduCreator.cpp KeepAlivePduCreator.cpp

View File

@ -1,8 +1,13 @@
#include "EofInfo.h" #include "EofInfo.h"
EofInfo::EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize, #include <utility>
EofInfo::EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::Fss fileSize,
EntityIdTlv* faultLoc) EntityIdTlv* faultLoc)
: conditionCode(conditionCode), checksum(checksum), fileSize(fileSize), faultLoc(faultLoc) {} : conditionCode(conditionCode),
checksum(checksum),
fileSize(std::move(fileSize)),
faultLoc(faultLoc) {}
EofInfo::EofInfo(EntityIdTlv* faultLoc) EofInfo::EofInfo(EntityIdTlv* faultLoc)
: conditionCode(cfdp::ConditionCode::NO_CONDITION_FIELD), : conditionCode(cfdp::ConditionCode::NO_CONDITION_FIELD),
@ -16,15 +21,15 @@ cfdp::ConditionCode EofInfo::getConditionCode() const { return conditionCode; }
EntityIdTlv* EofInfo::getFaultLoc() const { return faultLoc; } EntityIdTlv* EofInfo::getFaultLoc() const { return faultLoc; }
cfdp::FileSize& EofInfo::getFileSize() { return fileSize; } cfdp::Fss& EofInfo::getFileSize() { return fileSize; }
void EofInfo::setChecksum(uint32_t checksum) { this->checksum = checksum; } void EofInfo::setChecksum(uint32_t checksum_) { this->checksum = checksum_; }
void EofInfo::setConditionCode(cfdp::ConditionCode conditionCode) { void EofInfo::setConditionCode(cfdp::ConditionCode conditionCode_) {
this->conditionCode = conditionCode; this->conditionCode = conditionCode_;
} }
void EofInfo::setFaultLoc(EntityIdTlv* faultLoc) { this->faultLoc = faultLoc; } void EofInfo::setFaultLoc(EntityIdTlv* faultLoc_) { this->faultLoc = faultLoc_; }
size_t EofInfo::getSerializedSize(bool fssLarge) { size_t EofInfo::getSerializedSize(bool fssLarge) {
// Condition code + spare + 4 byte checksum // Condition code + spare + 4 byte checksum
@ -42,6 +47,6 @@ size_t EofInfo::getSerializedSize(bool fssLarge) {
return size; return size;
} }
ReturnValue_t EofInfo::setFileSize(size_t fileSize, bool isLarge) { ReturnValue_t EofInfo::setFileSize(size_t fileSize_, bool isLarge) {
return this->fileSize.setFileSize(fileSize, isLarge); return this->fileSize.setFileSize(fileSize_, isLarge);
} }

View File

@ -1,14 +1,14 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_EOFINFO_H_ #ifndef FSFW_SRC_FSFW_CFDP_PDU_EOFINFO_H_
#define FSFW_SRC_FSFW_CFDP_PDU_EOFINFO_H_ #define FSFW_SRC_FSFW_CFDP_PDU_EOFINFO_H_
#include "../FileSize.h" #include "../Fss.h"
#include "../definitions.h" #include "../definitions.h"
#include "fsfw/cfdp/tlv/EntityIdTlv.h" #include "fsfw/cfdp/tlv/EntityIdTlv.h"
struct EofInfo { struct EofInfo {
public: public:
explicit EofInfo(EntityIdTlv* faultLoc = nullptr); explicit EofInfo(EntityIdTlv* faultLoc = nullptr);
EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::FileSize fileSize, EofInfo(cfdp::ConditionCode conditionCode, uint32_t checksum, cfdp::Fss fileSize,
EntityIdTlv* faultLoc = nullptr); EntityIdTlv* faultLoc = nullptr);
size_t getSerializedSize(bool fssLarge = false); size_t getSerializedSize(bool fssLarge = false);
@ -17,7 +17,7 @@ struct EofInfo {
[[nodiscard]] cfdp::ConditionCode getConditionCode() const; [[nodiscard]] cfdp::ConditionCode getConditionCode() const;
[[nodiscard]] EntityIdTlv* getFaultLoc() const; [[nodiscard]] EntityIdTlv* getFaultLoc() const;
cfdp::FileSize& getFileSize(); cfdp::Fss& getFileSize();
void setChecksum(uint32_t checksum); void setChecksum(uint32_t checksum);
void setConditionCode(cfdp::ConditionCode conditionCode); void setConditionCode(cfdp::ConditionCode conditionCode);
void setFaultLoc(EntityIdTlv* faultLoc); void setFaultLoc(EntityIdTlv* faultLoc);
@ -26,7 +26,7 @@ struct EofInfo {
private: private:
cfdp::ConditionCode conditionCode; cfdp::ConditionCode conditionCode;
uint32_t checksum; uint32_t checksum;
cfdp::FileSize fileSize; cfdp::Fss fileSize;
EntityIdTlv* faultLoc = nullptr; EntityIdTlv* faultLoc = nullptr;
}; };

View File

@ -37,7 +37,7 @@ ReturnValue_t FileDataCreator::serialize(uint8_t** buffer, size_t* size, size_t
*buffer += segmentMetadataLen; *buffer += segmentMetadataLen;
*size += segmentMetadataLen; *size += segmentMetadataLen;
} }
cfdp::FileSize& offset = info.getOffset(); cfdp::Fss& offset = info.getOffset();
result = offset.serialize(this->getLargeFileFlag(), buffer, size, maxSize, streamEndianness); result = offset.serialize(this->getLargeFileFlag(), buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;

View File

@ -1,9 +1,9 @@
#include "FileDataInfo.h" #include "FileDataInfo.h"
FileDataInfo::FileDataInfo(cfdp::FileSize &offset, const uint8_t *fileData, size_t fileSize) #include <utility>
: offset(offset), fileData(fileData), fileSize(fileSize) {}
FileDataInfo::FileDataInfo(cfdp::FileSize &offset) : offset(offset) {} FileDataInfo::FileDataInfo(cfdp::Fss offset, const uint8_t *fileData, size_t fileSize)
: offset(std::move(offset)), fileData(fileData), fileSize(fileSize) {}
void FileDataInfo::setSegmentMetadataFlag(bool enable) { void FileDataInfo::setSegmentMetadataFlag(bool enable) {
if (enable) { if (enable) {
@ -71,7 +71,7 @@ const uint8_t *FileDataInfo::getSegmentMetadata(size_t *segmentMetadataLen_) {
return segmentMetadata; return segmentMetadata;
} }
cfdp::FileSize &FileDataInfo::getOffset() { return offset; } cfdp::Fss &FileDataInfo::getOffset() { return offset; }
void FileDataInfo::setRecordContinuationState(cfdp::RecordContinuationState recContState) { void FileDataInfo::setRecordContinuationState(cfdp::RecordContinuationState recContState) {
this->recContState = recContState; this->recContState = recContState;

View File

@ -1,17 +1,17 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FILEDATAINFO_H_ #ifndef FSFW_SRC_FSFW_CFDP_PDU_FILEDATAINFO_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FILEDATAINFO_H_ #define FSFW_SRC_FSFW_CFDP_PDU_FILEDATAINFO_H_
#include <fsfw/cfdp/FileSize.h> #include <fsfw/cfdp/Fss.h>
#include <fsfw/cfdp/definitions.h> #include <fsfw/cfdp/definitions.h>
class FileDataInfo { class FileDataInfo {
public: public:
explicit FileDataInfo(cfdp::FileSize& offset); FileDataInfo() = default;
FileDataInfo(cfdp::FileSize& offset, const uint8_t* fileData, size_t fileSize); FileDataInfo(cfdp::Fss offset, const uint8_t* fileData, size_t fileSize);
[[nodiscard]] size_t getSerializedSize(bool largeFile = false) const; [[nodiscard]] size_t getSerializedSize(bool largeFile = false) const;
cfdp::FileSize& getOffset(); cfdp::Fss& getOffset();
const uint8_t* getFileData(size_t* fileSize = nullptr) const; const uint8_t* getFileData(size_t* fileSize = nullptr) const;
void setFileData(const uint8_t* fileData, size_t fileSize); void setFileData(const uint8_t* fileData, size_t fileSize);
@ -33,7 +33,7 @@ class FileDataInfo {
private: private:
cfdp::SegmentMetadataFlag segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT; cfdp::SegmentMetadataFlag segmentMetadataFlag = cfdp::SegmentMetadataFlag::NOT_PRESENT;
cfdp::SegmentationControl segCtrl = cfdp::SegmentationControl::NO_RECORD_BOUNDARIES_PRESERVATION; cfdp::SegmentationControl segCtrl = cfdp::SegmentationControl::NO_RECORD_BOUNDARIES_PRESERVATION;
cfdp::FileSize& offset; cfdp::Fss offset;
const uint8_t* fileData = nullptr; const uint8_t* fileData = nullptr;
size_t fileSize = 0; size_t fileSize = 0;
cfdp::RecordContinuationState recContState = cfdp::RecordContinuationState::NO_START_NO_END; cfdp::RecordContinuationState recContState = cfdp::RecordContinuationState::NO_START_NO_END;

View File

@ -103,11 +103,11 @@ void PduHeaderReader::getTransactionSeqNum(cfdp::TransactionSeqNum &seqNum) cons
} }
void PduHeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInBytes width, void PduHeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInBytes width,
void *sourcePtr) const { void *sourcePtr) {
switch (width) { switch (width) {
case (cfdp::WidthInBytes::ONE_BYTE): { case (cfdp::WidthInBytes::ONE_BYTE): {
auto *fieldTyped = static_cast<uint8_t *>(sourcePtr); auto *fieldTyped = static_cast<uint8_t *>(sourcePtr);
field->setValue(width, *fieldTyped); field->setValueAndWidth(width, *fieldTyped);
break; break;
} }
case (cfdp::WidthInBytes::TWO_BYTES): { case (cfdp::WidthInBytes::TWO_BYTES): {
@ -115,7 +115,7 @@ void PduHeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInB
size_t deserSize = 0; size_t deserSize = 0;
SerializeAdapter::deSerialize(&fieldTyped, static_cast<uint8_t *>(sourcePtr), &deserSize, SerializeAdapter::deSerialize(&fieldTyped, static_cast<uint8_t *>(sourcePtr), &deserSize,
SerializeIF::Endianness::NETWORK); SerializeIF::Endianness::NETWORK);
field->setValue(width, fieldTyped); field->setValueAndWidth(width, fieldTyped);
break; break;
} }
case (cfdp::WidthInBytes::FOUR_BYTES): { case (cfdp::WidthInBytes::FOUR_BYTES): {
@ -123,7 +123,15 @@ void PduHeaderReader::assignVarLenField(cfdp::VarLenField *field, cfdp::WidthInB
size_t deserSize = 0; size_t deserSize = 0;
SerializeAdapter::deSerialize(&fieldTyped, static_cast<uint8_t *>(sourcePtr), &deserSize, SerializeAdapter::deSerialize(&fieldTyped, static_cast<uint8_t *>(sourcePtr), &deserSize,
SerializeIF::Endianness::NETWORK); SerializeIF::Endianness::NETWORK);
field->setValue(width, fieldTyped); field->setValueAndWidth(width, fieldTyped);
break;
}
case (cfdp::WidthInBytes::EIGHT_BYTES): {
uint64_t fieldTyped = 0;
size_t deserSize = 0;
SerializeAdapter::deSerialize(&fieldTyped, static_cast<uint8_t *>(sourcePtr), &deserSize,
SerializeIF::Endianness::NETWORK);
field->setValueAndWidth(width, fieldTyped);
break; break;
} }
} }

View File

@ -1,6 +1,6 @@
#include "KeepAlivePduCreator.h" #include "KeepAlivePduCreator.h"
KeepAlivePduCreator::KeepAlivePduCreator(PduConfig &conf, cfdp::FileSize &progress) KeepAlivePduCreator::KeepAlivePduCreator(PduConfig &conf, cfdp::Fss &progress)
: FileDirectiveCreator(conf, cfdp::FileDirective::KEEP_ALIVE, 4), progress(progress) { : FileDirectiveCreator(conf, cfdp::FileDirective::KEEP_ALIVE, 4), progress(progress) {
updateDirectiveFieldLen(); updateDirectiveFieldLen();
} }

View File

@ -1,12 +1,12 @@
#ifndef FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ #ifndef FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_
#define FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ #define FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_
#include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/Fss.h"
#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/pdu/FileDirectiveCreator.h"
class KeepAlivePduCreator : public FileDirectiveCreator { class KeepAlivePduCreator : public FileDirectiveCreator {
public: public:
KeepAlivePduCreator(PduConfig& conf, cfdp::FileSize& progress); KeepAlivePduCreator(PduConfig& conf, cfdp::Fss& progress);
void updateDirectiveFieldLen(); void updateDirectiveFieldLen();
@ -16,7 +16,7 @@ class KeepAlivePduCreator : public FileDirectiveCreator {
Endianness streamEndianness) const override; Endianness streamEndianness) const override;
private: private:
cfdp::FileSize& progress; cfdp::Fss& progress;
}; };
#endif /* FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ */ #endif /* FSFW_CFDP_PDU_KEEPALIVEPDUSERIALIZER_H_ */

View File

@ -1,7 +1,6 @@
#include "KeepAlivePduReader.h" #include "KeepAlivePduReader.h"
KeepAlivePduReader::KeepAlivePduReader(const uint8_t* pduBuf, size_t maxSize, KeepAlivePduReader::KeepAlivePduReader(const uint8_t* pduBuf, size_t maxSize, cfdp::Fss& progress)
cfdp::FileSize& progress)
: FileDirectiveReader(pduBuf, maxSize), progress(progress) {} : FileDirectiveReader(pduBuf, maxSize), progress(progress) {}
ReturnValue_t KeepAlivePduReader::parseData() { ReturnValue_t KeepAlivePduReader::parseData() {
@ -15,4 +14,4 @@ ReturnValue_t KeepAlivePduReader::parseData() {
return progress.deSerialize(&buffer, &remLen, getEndianness()); return progress.deSerialize(&buffer, &remLen, getEndianness());
} }
cfdp::FileSize& KeepAlivePduReader::getProgress() { return progress; } cfdp::Fss& KeepAlivePduReader::getProgress() { return progress; }

View File

@ -1,19 +1,19 @@
#ifndef FSFW_CFDP_PDU_KEEPALIVEREADER_H_ #ifndef FSFW_CFDP_PDU_KEEPALIVEREADER_H_
#define FSFW_CFDP_PDU_KEEPALIVEREADER_H_ #define FSFW_CFDP_PDU_KEEPALIVEREADER_H_
#include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/Fss.h"
#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h"
class KeepAlivePduReader : public FileDirectiveReader { class KeepAlivePduReader : public FileDirectiveReader {
public: public:
KeepAlivePduReader(const uint8_t* pduBuf, size_t maxSize, cfdp::FileSize& progress); KeepAlivePduReader(const uint8_t* pduBuf, size_t maxSize, cfdp::Fss& progress);
ReturnValue_t parseData() override; ReturnValue_t parseData() override;
cfdp::FileSize& getProgress(); cfdp::Fss& getProgress();
private: private:
cfdp::FileSize& progress; cfdp::Fss& progress;
}; };
#endif /* FSFW_CFDP_PDU_KEEPALIVEPDUREADER_H_ */ #endif /* FSFW_CFDP_PDU_KEEPALIVEPDUREADER_H_ */

View File

@ -0,0 +1,35 @@
#include "MetadataGenericInfo.h"
MetadataGenericInfo::MetadataGenericInfo(bool closureRequested, cfdp::ChecksumType checksumType,
cfdp::Fss fileSize)
: MetadataGenericInfo(std::move(fileSize)) {
this->closureRequested = closureRequested;
this->checksumType = checksumType;
}
MetadataGenericInfo::MetadataGenericInfo(cfdp::Fss fileSize) : fileSize(std::move(fileSize)) {}
cfdp::ChecksumType MetadataGenericInfo::getChecksumType() const { return checksumType; }
void MetadataGenericInfo::setChecksumType(cfdp::ChecksumType checksumType_) {
checksumType = checksumType_;
}
bool MetadataGenericInfo::isClosureRequested() const { return closureRequested; }
void MetadataGenericInfo::setClosureRequested(bool closureRequested_) {
closureRequested = closureRequested_;
}
const cfdp::Fss& MetadataGenericInfo::getFileSize() const { return fileSize; }
size_t MetadataGenericInfo::getSerializedSize(bool fssLarge) {
// 1 byte + minimal FSS 4 bytes
size_t size = 5;
if (fssLarge) {
size += 4;
}
return size;
}
cfdp::Fss& MetadataGenericInfo::getMutFileSize() { return fileSize; }

View File

@ -0,0 +1,35 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_
#define FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_
#include <optional>
#include "fsfw/cfdp/Fss.h"
#include "fsfw/cfdp/definitions.h"
#include "fsfw/cfdp/tlv/Lv.h"
#include "fsfw/cfdp/tlv/StringLv.h"
#include "fsfw/cfdp/tlv/Tlv.h"
class MetadataGenericInfo {
public:
MetadataGenericInfo() = default;
explicit MetadataGenericInfo(cfdp::Fss fileSize);
MetadataGenericInfo(bool closureRequested, cfdp::ChecksumType checksumType, cfdp::Fss fileSize);
static size_t getSerializedSize(bool fssLarge = false);
[[nodiscard]] cfdp::ChecksumType getChecksumType() const;
void setChecksumType(cfdp::ChecksumType checksumType);
[[nodiscard]] bool isClosureRequested() const;
void setClosureRequested(bool closureRequested = false);
[[nodiscard]] const cfdp::Fss& getFileSize() const;
cfdp::Fss& getMutFileSize();
private:
bool closureRequested = false;
cfdp::ChecksumType checksumType = cfdp::ChecksumType::NULL_CHECKSUM;
cfdp::Fss fileSize;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_ */

View File

@ -1,103 +0,0 @@
#include "MetadataInfo.h"
MetadataInfo::MetadataInfo(bool closureRequested, cfdp::ChecksumType checksumType,
cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName,
cfdp::StringLv& destFileName)
: MetadataInfo(fileSize, sourceFileName, destFileName) {
this->closureRequested = closureRequested;
this->checksumType = checksumType;
}
MetadataInfo::MetadataInfo(cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName,
cfdp::StringLv& destFileName)
: fileSize(fileSize), sourceFileName(sourceFileName), destFileName(destFileName) {}
void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, std::optional<size_t> optionsLen_,
std::optional<size_t> maxOptionsLen_) {
this->optionsArray = optionsArray_;
if (maxOptionsLen_) {
this->maxOptionsLen = maxOptionsLen_.value();
}
if (optionsLen_) {
this->optionsLen = optionsLen_.value();
}
}
cfdp::ChecksumType MetadataInfo::getChecksumType() const { return checksumType; }
void MetadataInfo::setChecksumType(cfdp::ChecksumType checksumType_) {
checksumType = checksumType_;
}
bool MetadataInfo::isClosureRequested() const { return closureRequested; }
void MetadataInfo::setClosureRequested(bool closureRequested_) {
closureRequested = closureRequested_;
}
cfdp::StringLv& MetadataInfo::getDestFileName() { return destFileName; }
cfdp::FileSize& MetadataInfo::getFileSize() { return fileSize; }
ReturnValue_t MetadataInfo::getOptions(cfdp::Tlv*** optionsArray_, size_t* optionsLen_,
size_t* maxOptsLen) {
if (optionsArray_ == nullptr or optionsArray == nullptr) {
return returnvalue::FAILED;
}
*optionsArray_ = optionsArray;
if (optionsLen_ != nullptr) {
*optionsLen_ = this->optionsLen;
}
if (maxOptsLen != nullptr) {
*maxOptsLen = this->maxOptionsLen;
}
return returnvalue::OK;
}
bool MetadataInfo::hasOptions() const {
if (optionsArray != nullptr and optionsLen > 0) {
return true;
}
return false;
}
bool MetadataInfo::canHoldOptions() const {
if (optionsArray != nullptr and maxOptionsLen > 0) {
return true;
}
return false;
}
size_t MetadataInfo::getSerializedSize(bool fssLarge) {
// 1 byte + minimal FSS 4 bytes
size_t size = 5;
if (fssLarge) {
size += 4;
}
size += sourceFileName.getSerializedSize();
size += destFileName.getSerializedSize();
if (hasOptions()) {
for (size_t idx = 0; idx < optionsLen; idx++) {
size += optionsArray[idx]->getSerializedSize();
}
}
return size;
}
void MetadataInfo::setDestFileName(cfdp::StringLv& destFileName_) {
this->destFileName = destFileName_;
}
void MetadataInfo::setSourceFileName(cfdp::StringLv& sourceFileName_) {
this->sourceFileName = sourceFileName_;
}
size_t MetadataInfo::getMaxOptionsLen() const { return maxOptionsLen; }
void MetadataInfo::setMaxOptionsLen(size_t maxOptionsLen_) { this->maxOptionsLen = maxOptionsLen_; }
size_t MetadataInfo::getOptionsLen() const { return optionsLen; }
void MetadataInfo::setOptionsLen(size_t optionsLen_) { this->optionsLen = optionsLen_; }
cfdp::StringLv& MetadataInfo::getSourceFileName() { return sourceFileName; }

View File

@ -1,55 +0,0 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_
#define FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_
#include <optional>
#include "fsfw/cfdp/FileSize.h"
#include "fsfw/cfdp/definitions.h"
#include "fsfw/cfdp/tlv/Lv.h"
#include "fsfw/cfdp/tlv/StringLv.h"
#include "fsfw/cfdp/tlv/Tlv.h"
class MetadataInfo {
public:
MetadataInfo(cfdp::FileSize& fileSize, cfdp::StringLv& sourceFileName,
cfdp::StringLv& destFileName);
MetadataInfo(bool closureRequested, cfdp::ChecksumType checksumType, cfdp::FileSize& fileSize,
cfdp::StringLv& sourceFileName, cfdp::StringLv& destFileName);
size_t getSerializedSize(bool fssLarge = false);
void setOptionsArray(cfdp::Tlv** optionsArray, std::optional<size_t> optionsLen,
std::optional<size_t> maxOptionsLen);
[[nodiscard]] cfdp::ChecksumType getChecksumType() const;
void setChecksumType(cfdp::ChecksumType checksumType);
[[nodiscard]] bool isClosureRequested() const;
void setClosureRequested(bool closureRequested = false);
void setDestFileName(cfdp::StringLv& destFileName);
void setSourceFileName(cfdp::StringLv& sourceFileName);
cfdp::StringLv& getDestFileName();
cfdp::StringLv& getSourceFileName();
cfdp::FileSize& getFileSize();
[[nodiscard]] bool hasOptions() const;
[[nodiscard]] bool canHoldOptions() const;
ReturnValue_t getOptions(cfdp::Tlv*** optionsArray, size_t* optionsLen, size_t* maxOptsLen);
void setOptionsLen(size_t optionsLen);
[[nodiscard]] size_t getOptionsLen() const;
void setMaxOptionsLen(size_t maxOptionsLen);
[[nodiscard]] size_t getMaxOptionsLen() const;
private:
bool closureRequested = false;
cfdp::ChecksumType checksumType = cfdp::ChecksumType::NULL_CHECKSUM;
cfdp::FileSize& fileSize;
cfdp::StringLv& sourceFileName;
cfdp::StringLv& destFileName;
cfdp::Tlv** optionsArray = nullptr;
size_t optionsLen = 0;
size_t maxOptionsLen = 0;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_ */

View File

@ -1,12 +1,26 @@
#include "MetadataPduCreator.h" #include "MetadataPduCreator.h"
MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataInfo &info) MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataGenericInfo &info,
: FileDirectiveCreator(conf, cfdp::FileDirective::METADATA, 5), info(info) { cfdp::StringLv &srcFileName, cfdp::StringLv &destFileName,
cfdp::Tlv **optionsArray, size_t optionsLen)
: FileDirectiveCreator(conf, cfdp::FileDirective::METADATA, 5),
info(info),
srcFileName(srcFileName),
destFileName(destFileName),
optionsArray(optionsArray),
optionsLen(optionsLen) {
updateDirectiveFieldLen(); updateDirectiveFieldLen();
} }
void MetadataPduCreator::updateDirectiveFieldLen() { void MetadataPduCreator::updateDirectiveFieldLen() {
setDirectiveDataFieldLen(info.getSerializedSize(getLargeFileFlag())); size_t dirFieldLen = MetadataGenericInfo::getSerializedSize(HeaderCreator::getLargeFileFlag()) +
srcFileName.getSerializedSize() + destFileName.getSerializedSize();
if (optionsLen > 0 and optionsArray != nullptr) {
for (size_t idx = 0; idx < optionsLen; idx++) {
dirFieldLen += optionsArray[idx]->getSerializedSize();
}
}
setDirectiveDataFieldLen(dirFieldLen);
} }
size_t MetadataPduCreator::getSerializedSize() const { size_t MetadataPduCreator::getSerializedSize() const {
@ -29,21 +43,18 @@ ReturnValue_t MetadataPduCreator::serialize(uint8_t **buffer, size_t *size, size
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
result = info.getSourceFileName().serialize(buffer, size, maxSize, streamEndianness); result = srcFileName.serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
result = info.getDestFileName().serialize(buffer, size, maxSize, streamEndianness); result = destFileName.serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
if (info.hasOptions()) { if (optionsLen > 0 and optionsArray != nullptr) {
cfdp::Tlv **optsArray = nullptr; for (size_t idx = 0; idx < optionsLen; idx++) {
size_t optsLen = 0; result = optionsArray[idx]->serialize(buffer, size, maxSize, streamEndianness);
info.getOptions(&optsArray, &optsLen, nullptr);
for (size_t idx = 0; idx < optsLen; idx++) {
result = optsArray[idx]->serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
@ -51,3 +62,5 @@ ReturnValue_t MetadataPduCreator::serialize(uint8_t **buffer, size_t *size, size
} }
return result; return result;
} }
const cfdp::StringLv &MetadataPduCreator::getSourceFileName() const { return srcFileName; }
const cfdp::StringLv &MetadataPduCreator::getDestFileName() const { return destFileName; }

View File

@ -2,22 +2,30 @@
#define FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ #define FSFW_CFDP_PDU_METADATAPDUCREATOR_H_
#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/pdu/FileDirectiveCreator.h"
#include "fsfw/cfdp/pdu/MetadataInfo.h" #include "fsfw/cfdp/pdu/MetadataGenericInfo.h"
class MetadataPduCreator : public FileDirectiveCreator { class MetadataPduCreator : public FileDirectiveCreator {
public: public:
MetadataPduCreator(PduConfig& conf, MetadataInfo& info); MetadataPduCreator(PduConfig& conf, MetadataGenericInfo& info, cfdp::StringLv& srcFileName,
cfdp::StringLv& destFileName, cfdp::Tlv** optionsArray, size_t optionsLen);
void updateDirectiveFieldLen(); void updateDirectiveFieldLen();
[[nodiscard]] size_t getSerializedSize() const override; [[nodiscard]] size_t getSerializedSize() const override;
const cfdp::StringLv& getSourceFileName() const;
const cfdp::StringLv& getDestFileName() const;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override; Endianness streamEndianness) const override;
using FileDirectiveCreator::serialize; using FileDirectiveCreator::serialize;
private: private:
MetadataInfo& info; MetadataGenericInfo& info;
cfdp::StringLv& srcFileName;
cfdp::StringLv& destFileName;
cfdp::Tlv** optionsArray;
size_t optionsLen;
}; };
#endif /* FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ */ #endif /* FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ */

View File

@ -1,9 +1,15 @@
#include "MetadataPduReader.h" #include "MetadataPduReader.h"
MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info) MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize,
: FileDirectiveReader(pduBuf, maxSize), info(info) {} MetadataGenericInfo& info, cfdp::Tlv* optionsArray,
size_t optArrayMaxSize)
: FileDirectiveReader(pduBuf, maxSize),
info(info),
optionArray(optionsArray),
optionArrayMaxSize(optArrayMaxSize) {}
ReturnValue_t MetadataPduReader::parseData() { ReturnValue_t MetadataPduReader::parseData() {
parsedOptions = 0;
ReturnValue_t result = FileDirectiveReader::parseData(); ReturnValue_t result = FileDirectiveReader::parseData();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -19,39 +25,43 @@ ReturnValue_t MetadataPduReader::parseData() {
remSize -= 1; remSize -= 1;
buf += 1; buf += 1;
auto endianness = getEndianness(); auto endianness = getEndianness();
result = info.getFileSize().deSerialize(&buf, &remSize, endianness); result = info.getMutFileSize().deSerialize(&buf, &remSize, endianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
result = info.getSourceFileName().deSerialize(&buf, &remSize, endianness); result = srcFileName.deSerialize(&buf, &remSize, endianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
result = info.getDestFileName().deSerialize(&buf, &remSize, endianness); result = destFileName.deSerialize(&buf, &remSize, endianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
info.setOptionsLen(0);
if (remSize > 0) { if (remSize > 0) {
if (not info.canHoldOptions()) { if (optionArrayMaxSize == 0 or optionArray == nullptr) {
return cfdp::METADATA_CANT_PARSE_OPTIONS; return cfdp::METADATA_CANT_PARSE_OPTIONS;
} }
cfdp::Tlv** optionsArray = nullptr;
size_t optsMaxLen = 0;
size_t optsIdx = 0; size_t optsIdx = 0;
info.getOptions(&optionsArray, nullptr, &optsMaxLen);
while (remSize > 0) { while (remSize > 0) {
if (optsIdx > optsMaxLen) { if (optsIdx > optionArrayMaxSize) {
return cfdp::METADATA_CANT_PARSE_OPTIONS; return cfdp::METADATA_CANT_PARSE_OPTIONS;
} }
result = optionsArray[optsIdx]->deSerialize(&buf, &remSize, endianness); result = optionArray[optsIdx].deSerialize(&buf, &remSize, endianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
optsIdx++; optsIdx++;
} }
info.setOptionsLen(optsIdx); parsedOptions = optsIdx;
} }
return result; return result;
} }
size_t MetadataPduReader::getNumberOfParsedOptions() const { return parsedOptions; }
const cfdp::StringLv& MetadataPduReader::getSourceFileName() const { return srcFileName; }
const cfdp::StringLv& MetadataPduReader::getDestFileName() const { return destFileName; }
const MetadataGenericInfo& MetadataPduReader::getGenericInfo() const { return info; }

View File

@ -2,16 +2,28 @@
#define FSFW_CFDP_PDU_METADATAPDUREADER_H_ #define FSFW_CFDP_PDU_METADATAPDUREADER_H_
#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h"
#include "fsfw/cfdp/pdu/MetadataInfo.h" #include "fsfw/cfdp/pdu/MetadataGenericInfo.h"
class MetadataPduReader : public FileDirectiveReader { class MetadataPduReader : public FileDirectiveReader {
public: public:
MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info); MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataGenericInfo& info,
cfdp::Tlv* optionsArray, size_t optArrayMaxSize);
ReturnValue_t parseData() override; ReturnValue_t parseData() override;
[[nodiscard]] const MetadataGenericInfo& getGenericInfo() const;
[[nodiscard]] const cfdp::StringLv& getSourceFileName() const;
[[nodiscard]] const cfdp::StringLv& getDestFileName() const;
[[nodiscard]] size_t getNumberOfParsedOptions() const;
private: private:
MetadataInfo& info; cfdp::StringLv srcFileName;
cfdp::StringLv destFileName;
MetadataGenericInfo& info;
cfdp::Tlv* optionArray;
size_t optionArrayMaxSize;
size_t parsedOptions = 0;
}; };
#endif /* FSFW_CFDP_PDU_METADATAPDUREADER_H_ */ #endif /* FSFW_CFDP_PDU_METADATAPDUREADER_H_ */

View File

@ -1,6 +1,6 @@
#include "NakInfo.h" #include "NakInfo.h"
NakInfo::NakInfo(cfdp::FileSize startOfScope, cfdp::FileSize endOfScope) NakInfo::NakInfo(cfdp::Fss startOfScope, cfdp::Fss endOfScope)
: startOfScope(startOfScope), endOfScope(endOfScope) {} : startOfScope(startOfScope), endOfScope(endOfScope) {}
size_t NakInfo::getSerializedSize(bool fssLarge) { size_t NakInfo::getSerializedSize(bool fssLarge) {
@ -57,9 +57,9 @@ void NakInfo::setSegmentRequests(SegmentRequest* segmentRequests, size_t* segmen
} }
} }
cfdp::FileSize& NakInfo::getStartOfScope() { return startOfScope; } cfdp::Fss& NakInfo::getStartOfScope() { return startOfScope; }
cfdp::FileSize& NakInfo::getEndOfScope() { return endOfScope; } cfdp::Fss& NakInfo::getEndOfScope() { return endOfScope; }
size_t NakInfo::getSegmentRequestsLen() const { return segmentRequestsLen; } size_t NakInfo::getSegmentRequestsLen() const { return segmentRequestsLen; }

View File

@ -3,21 +3,21 @@
#include <utility> #include <utility>
#include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/Fss.h"
class NakInfo { class NakInfo {
public: public:
using SegmentRequest = std::pair<cfdp::FileSize, cfdp::FileSize>; using SegmentRequest = std::pair<cfdp::Fss, cfdp::Fss>;
NakInfo(cfdp::FileSize startOfScope, cfdp::FileSize endOfScope); NakInfo(cfdp::Fss startOfScope, cfdp::Fss endOfScope);
void setSegmentRequests(SegmentRequest* segmentRequests, size_t* segmentRequestLen, void setSegmentRequests(SegmentRequest* segmentRequests, size_t* segmentRequestLen,
size_t* maxSegmentRequestLen); size_t* maxSegmentRequestLen);
size_t getSerializedSize(bool fssLarge = false); size_t getSerializedSize(bool fssLarge = false);
cfdp::FileSize& getStartOfScope(); cfdp::Fss& getStartOfScope();
cfdp::FileSize& getEndOfScope(); cfdp::Fss& getEndOfScope();
bool hasSegmentRequests() const; bool hasSegmentRequests() const;
bool canHoldSegmentRequests() const; bool canHoldSegmentRequests() const;
@ -31,8 +31,8 @@ class NakInfo {
void setSegmentRequestLen(size_t readLen); void setSegmentRequestLen(size_t readLen);
private: private:
cfdp::FileSize startOfScope; cfdp::Fss startOfScope;
cfdp::FileSize endOfScope; cfdp::Fss endOfScope;
SegmentRequest* segmentRequests = nullptr; SegmentRequest* segmentRequests = nullptr;
size_t segmentRequestsLen = 0; size_t segmentRequestsLen = 0;
size_t maxSegmentRequestsLen = 0; size_t maxSegmentRequestsLen = 0;

View File

@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include "NakInfo.h" #include "NakInfo.h"
#include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/Fss.h"
#include "fsfw/cfdp/definitions.h" #include "fsfw/cfdp/definitions.h"
#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/pdu/FileDirectiveCreator.h"

View File

@ -105,7 +105,8 @@ class PduHeaderReader : public RedirectableDataPointerIF, public PduHeaderIF {
* @return * @return
*/ */
ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args) override; ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args) override;
void assignVarLenField(cfdp::VarLenField* field, cfdp::WidthInBytes width, void* sourcePtr) const; static void assignVarLenField(cfdp::VarLenField* field, cfdp::WidthInBytes width,
void* sourcePtr);
void* sourceIdRaw = nullptr; void* sourceIdRaw = nullptr;
void* seqNumRaw = nullptr; void* seqNumRaw = nullptr;
void* destIdRaw = nullptr; void* destIdRaw = nullptr;

View File

@ -8,4 +8,5 @@ target_sources(
StringLv.cpp StringLv.cpp
FlowLabelTlv.cpp FlowLabelTlv.cpp
MessageToUserTlv.cpp MessageToUserTlv.cpp
FaultHandlerOverrideTlv.cpp) FaultHandlerOverrideTlv.cpp
ReservedMessageCreator.cpp)

View File

@ -14,23 +14,6 @@ cfdp::Lv::Lv(const std::vector<uint8_t>& data) : value(data.data(), data.size(),
cfdp::Lv::Lv() : value(static_cast<uint8_t*>(nullptr), 0, true) {} cfdp::Lv::Lv() : value(static_cast<uint8_t*>(nullptr), 0, true) {}
cfdp::Lv::Lv(const Lv& other)
: value(other.value.getConstBuffer(), other.value.getSerializedSize() - 1, true) {
if (other.value.getSerializedSize() - 1 > 0) {
zeroLen = false;
}
}
cfdp::Lv& cfdp::Lv::operator=(const Lv& other) {
size_t otherSize = 0;
auto* otherVal = const_cast<uint8_t*>(other.getValue(&otherSize));
if (otherVal == nullptr or otherSize == 0) {
this->zeroLen = true;
}
this->value.setConstBuffer(otherVal, otherSize);
return *this;
}
ReturnValue_t cfdp::Lv::serialize(uint8_t** buffer, size_t* size, size_t maxSize, ReturnValue_t cfdp::Lv::serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const { Endianness streamEndianness) const {
if (maxSize < 1) { if (maxSize < 1) {
@ -49,10 +32,8 @@ ReturnValue_t cfdp::Lv::serialize(uint8_t** buffer, size_t* size, size_t maxSize
} }
size_t cfdp::Lv::getSerializedSize() const { size_t cfdp::Lv::getSerializedSize() const {
if (zeroLen) { if (zeroLen or value.getConstBuffer() == nullptr) {
return 1; return 1;
} else if (value.getConstBuffer() == nullptr) {
return 0;
} }
return value.getSerializedSize(); return value.getSerializedSize();
} }
@ -85,7 +66,34 @@ ReturnValue_t cfdp::Lv::deSerialize(const uint8_t** buffer, size_t* size,
const uint8_t* cfdp::Lv::getValue(size_t* size) const { const uint8_t* cfdp::Lv::getValue(size_t* size) const {
if (size != nullptr) { if (size != nullptr) {
// Length without length field // Length without length field
*size = value.getSerializedSize() - 1; *size = getSerializedSize() - 1;
} }
return value.getConstBuffer(); return value.getConstBuffer();
} }
cfdp::Lv::Lv(cfdp::Lv&& other) noexcept
: value(other.value.getConstBuffer(), other.value.getSerializedSize() - 1, true) {
if (other.value.getSerializedSize() - 1 > 0) {
zeroLen = false;
}
// Leave other class in intact state.
other.zeroLen = false;
other.value = SerialBufferAdapter<uint8_t>();
}
cfdp::Lv& cfdp::Lv::operator=(cfdp::Lv&& other) noexcept {
size_t otherSize = 0;
this->zeroLen = false;
auto* otherVal = const_cast<uint8_t*>(other.getValue(&otherSize));
if (otherVal == nullptr or otherSize == 0) {
this->zeroLen = true;
}
this->value.setConstBuffer(otherVal, otherSize);
// Leave other class in intact state.
other.zeroLen = false;
other.value = SerialBufferAdapter<uint8_t>();
return *this;
}
size_t cfdp::Lv::getValueLen() const { return getSerializedSize() - 1; }
bool cfdp::Lv::isEmpty() const { return zeroLen; }

View File

@ -18,8 +18,12 @@ class Lv : public SerializeIF {
Lv(const uint8_t* value, size_t size); Lv(const uint8_t* value, size_t size);
Lv(); Lv();
Lv(const Lv&); // Semantically, this class is a zero-copy helper, so the copy ctor and copy assigment do not
Lv& operator=(const Lv&); // really make sense here.
Lv(const Lv&) = delete;
Lv& operator=(const Lv&) = delete;
Lv(Lv&&) noexcept;
Lv& operator=(Lv&&) noexcept;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override; Endianness streamEndianness) const override;
@ -36,6 +40,8 @@ class Lv : public SerializeIF {
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override; Endianness streamEndianness) override;
size_t getValueLen() const;
/** /**
* Get value field and its size. * Get value field and its size.
* @param size Optionally retrieve size. Size will be the size of the actual value field * @param size Optionally retrieve size. Size will be the size of the actual value field
@ -44,6 +50,8 @@ class Lv : public SerializeIF {
*/ */
const uint8_t* getValue(size_t* size) const; const uint8_t* getValue(size_t* size) const;
bool isEmpty() const;
private: private:
bool zeroLen = true; bool zeroLen = true;
SerialBufferAdapter<uint8_t> value; SerialBufferAdapter<uint8_t> value;

View File

@ -7,3 +7,22 @@ MessageToUserTlv::MessageToUserTlv() : Tlv() {}
MessageToUserTlv::MessageToUserTlv(const std::vector<uint8_t>& data) MessageToUserTlv::MessageToUserTlv(const std::vector<uint8_t>& data)
: Tlv(cfdp::TlvType::MSG_TO_USER, data.data(), data.size()) {} : Tlv(cfdp::TlvType::MSG_TO_USER, data.data(), data.size()) {}
MessageToUserTlv::MessageToUserTlv(const uint8_t* value, size_t size)
: Tlv(cfdp::TlvType::MSG_TO_USER, value, size) {}
bool MessageToUserTlv::isReservedCfdpMessage(uint8_t& messageType, const uint8_t** msgDataStart,
size_t& msgLen) const {
if (cfdp::Tlv::getLengthField() < 5) {
return false;
}
if (std::strncmp(reinterpret_cast<const char*>(getValue()), "cfdp", 4) == 0) {
messageType = getValue()[4];
if (msgDataStart != nullptr) {
*msgDataStart = getValue() + 5;
}
msgLen = cfdp::Tlv::getSerializedSize() - 5;
return true;
}
return false;
}

View File

@ -9,8 +9,12 @@ class MessageToUserTlv : public cfdp::Tlv {
public: public:
MessageToUserTlv(); MessageToUserTlv();
MessageToUserTlv(uint8_t* value, size_t size); MessageToUserTlv(uint8_t* value, size_t size);
MessageToUserTlv(const uint8_t* value, size_t size);
explicit MessageToUserTlv(const std::vector<uint8_t>& data); explicit MessageToUserTlv(const std::vector<uint8_t>& data);
bool isReservedCfdpMessage(uint8_t& messageType, const uint8_t** msgDataStart,
size_t& msgLen) const;
private: private:
}; };

View File

@ -0,0 +1,39 @@
#include "ReservedMessageCreator.h"
cfdp::ReservedMessageCreator::ReservedMessageCreator(uint8_t messageType, uint8_t *msgData,
size_t msgLen)
: messageType(messageType), msgData(msgData), msgSize(msgLen) {}
ReturnValue_t cfdp::ReservedMessageCreator::serialize(
uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
if (*size + getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
**buffer = TlvType::MSG_TO_USER;
*buffer += 1;
*size += 1;
**buffer = getSerializedSize() - 2;
*size += 1;
*buffer += 1;
std::memcpy(*buffer, MSG_HEADER, 4);
*buffer += 4;
*size += 4;
**buffer = messageType;
*buffer += 1;
*size += 1;
std::memcpy(*buffer, msgData, msgSize);
*buffer += msgSize;
*size += msgSize;
return returnvalue::OK;
}
size_t cfdp::ReservedMessageCreator::getSerializedSize() const {
// 2 bytes type and length, 4 bytes CFDP, 1 byte reserved message type, message data.
return 2 + 5 + msgSize;
}
ReturnValue_t cfdp::ReservedMessageCreator::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) {
return returnvalue::FAILED;
}

View File

@ -0,0 +1,24 @@
#pragma once
#include "Tlv.h"
namespace cfdp {
class ReservedMessageCreator : public SerializeIF {
public:
static constexpr char MSG_HEADER[] = "cfdp";
ReservedMessageCreator(uint8_t messageType, uint8_t *msgData, size_t msgLen);
[[nodiscard]] 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:
uint8_t messageType;
uint8_t *msgData;
size_t msgSize;
};
} // namespace cfdp

View File

@ -7,3 +7,12 @@ cfdp::StringLv::StringLv(const char* filename, size_t len)
: Lv(reinterpret_cast<const uint8_t*>(filename), len) {} : Lv(reinterpret_cast<const uint8_t*>(filename), len) {}
cfdp::StringLv::StringLv() : Lv() {} cfdp::StringLv::StringLv() : Lv() {}
const char* cfdp::StringLv::getCString(size_t& fileSize) const {
return reinterpret_cast<const char*>(getValue(&fileSize));
}
std::string cfdp::StringLv::getString() const {
size_t fileSize;
return {getCString(fileSize), fileSize};
}

View File

@ -13,6 +13,8 @@ class StringLv : public Lv {
explicit StringLv(const std::string& fileName); explicit StringLv(const std::string& fileName);
explicit StringLv(const char* filename, size_t len); explicit StringLv(const char* filename, size_t len);
const char* getCString(size_t& fileSize) const;
std::string getString() const;
// Delete the move constructor to avoid passing in a temporary // Delete the move constructor to avoid passing in a temporary
StringLv(const std::string&&) = delete; StringLv(const std::string&&) = delete;
}; };

View File

@ -54,6 +54,7 @@ ReturnValue_t cfdp::Tlv::deSerialize(const uint8_t **buffer, size_t *size,
return STREAM_TOO_SHORT; return STREAM_TOO_SHORT;
} }
rawData = *buffer;
uint8_t rawType = **buffer; uint8_t rawType = **buffer;
if (not checkType(rawType)) { if (not checkType(rawType)) {
return INVALID_TLV_TYPE; return INVALID_TLV_TYPE;
@ -102,3 +103,5 @@ void cfdp::Tlv::setValue(uint8_t *value, size_t len) {
uint8_t cfdp::Tlv::getLengthField() const { return this->value.getSerializedSize() - 1; } uint8_t cfdp::Tlv::getLengthField() const { return this->value.getSerializedSize() - 1; }
void cfdp::Tlv::setType(TlvType type) { this->type = type; } void cfdp::Tlv::setType(TlvType type) { this->type = type; }
const uint8_t *cfdp::Tlv::getRawData() const { return rawData; }

View File

@ -47,6 +47,7 @@ class Tlv : public TlvIF {
void setValue(uint8_t *value, size_t len); void setValue(uint8_t *value, size_t len);
[[nodiscard]] const uint8_t *getValue() const; [[nodiscard]] const uint8_t *getValue() const;
[[nodiscard]] const uint8_t *getRawData() const;
void setType(TlvType type); void setType(TlvType type);
[[nodiscard]] TlvType getType() const override; [[nodiscard]] TlvType getType() const override;
[[nodiscard]] uint8_t getLengthField() const override; [[nodiscard]] uint8_t getLengthField() const override;
@ -55,6 +56,7 @@ class Tlv : public TlvIF {
bool checkType(uint8_t rawType); bool checkType(uint8_t rawType);
bool zeroLen = true; bool zeroLen = true;
const uint8_t *rawData = nullptr;
TlvType type = TlvType::INVALID_TLV; TlvType type = TlvType::INVALID_TLV;
SerialBufferAdapter<uint8_t> value; SerialBufferAdapter<uint8_t> value;
}; };

View File

@ -17,7 +17,7 @@ struct FilesystemParams {
}; };
struct FileOpParams { struct FileOpParams {
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {} FileOpParams(const char* path, size_t opSize) : fsParams(path), size(opSize) {}
[[nodiscard]] const char* path() const { return fsParams.path; } [[nodiscard]] const char* path() const { return fsParams.path; }
@ -80,6 +80,8 @@ class HasFileSystemIF {
virtual bool isDirectory(const char* path) = 0; virtual bool isDirectory(const char* path) = 0;
virtual bool getFileSize(FilesystemParams params, uint64_t& fileSize) = 0;
virtual bool fileExists(FilesystemParams params) = 0; virtual bool fileExists(FilesystemParams params) = 0;
/** /**

View File

@ -116,8 +116,8 @@ void ObjectManager::initialize() {
<< std::dec << std::setfill(' ') << std::endl; << std::dec << std::setfill(' ') << std::endl;
#else #else
sif::printError( sif::printError(
"ObjectManager::initialize: Object 0x%08x failed to initialize with code 0x%04x\n", var, "ObjectManager::initialize: Object 0x%08x failed to initialize with code 0x%04x\n",
it.first); it.first, result);
#endif #endif
#endif #endif
errorCount++; errorCount++;

View File

@ -21,7 +21,7 @@ TcpTmTcBridge::TcpTmTcBridge(object_id_t objectId, object_id_t tcDestination,
: TmTcBridge("TCP TMTC Bridge", objectId, tcDestination, msgQueueDepth, tmStoreId, tcStoreId) { : TmTcBridge("TCP TMTC Bridge", objectId, tcDestination, msgQueueDepth, tmStoreId, tcStoreId) {
mutex = MutexFactory::instance()->createMutex(); mutex = MutexFactory::instance()->createMutex();
// Connection is always up, TM is requested by connecting to server and receiving packets // Connection is always up, TM is requested by connecting to server and receiving packets
registerCommConnect(); TmTcBridge::registerCommConnect();
} }
ReturnValue_t TcpTmTcBridge::initialize() { ReturnValue_t TcpTmTcBridge::initialize() {

View File

@ -123,6 +123,7 @@ class TcpTmTcServer : public SystemObject, public TcpIpBase, public ExecutableOb
StorageManagerIF* tmStore = nullptr; StorageManagerIF* tmStore = nullptr;
private: private:
//! [EXPORT] : [SKIP]
static constexpr ReturnValue_t CONN_BROKEN = returnvalue::makeCode(1, 0); static constexpr ReturnValue_t CONN_BROKEN = returnvalue::makeCode(1, 0);
//! TMTC bridge is cached. //! TMTC bridge is cached.
object_id_t tmtcBridgeId = objects::NO_OBJECT; object_id_t tmtcBridgeId = objects::NO_OBJECT;

View File

@ -61,7 +61,8 @@ enum : uint8_t {
HAS_ACTIONS_IF, // HF HAS_ACTIONS_IF, // HF
DEVICE_COMMUNICATION_IF, // DC DEVICE_COMMUNICATION_IF, // DC
BSP, // BSP BSP, // BSP
CFDP, // CFDP CFDP_BASE, // CFDP
CFDP_HANDLER, // CFDP
TIME_STAMPER_IF, // TSI TIME_STAMPER_IF, // TSI
SGP4PROPAGATOR_CLASS, // SGP4 SGP4PROPAGATOR_CLASS, // SGP4
MUTEX_IF, // MUX MUTEX_IF, // MUX

View File

@ -107,14 +107,6 @@ uint8_t* SerialBufferAdapter<count_t>::getBuffer() {
template <typename count_t> template <typename count_t>
const uint8_t* SerialBufferAdapter<count_t>::getConstBuffer() const { const uint8_t* SerialBufferAdapter<count_t>::getConstBuffer() const {
if (constBuffer == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "SerialBufferAdapter::getConstBuffer:"
" Buffers are unitialized!"
<< std::endl;
#endif
return nullptr;
}
return constBuffer; return constBuffer;
} }

View File

@ -63,7 +63,17 @@ class SerialBufferAdapter : public SerializeIF {
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override; Endianness streamEndianness) override;
/**
* Please note that this function can also return a nullpointer in case the length field contains
* 0.
* @return
*/
uint8_t* getBuffer(); uint8_t* getBuffer();
/**
* Please note that this function can also return a nullpointer in case the length field contains
* 0.
* @return
*/
[[nodiscard]] const uint8_t* getConstBuffer() const; [[nodiscard]] const uint8_t* getConstBuffer() const;
void setConstBuffer(const uint8_t* buf, count_t bufLen); void setConstBuffer(const uint8_t* buf, count_t bufLen);

View File

@ -89,7 +89,7 @@ ReturnValue_t LocalPool::deleteData(store_address_t storeId) {
ReturnValue_t status = returnvalue::OK; ReturnValue_t status = returnvalue::OK;
size_type pageSize = getSubpoolElementSize(storeId.poolIndex); size_type pageSize = getSubpoolElementSize(storeId.poolIndex);
if ((pageSize != 0) and (storeId.packetIndex < numberOfElements[storeId.poolIndex])) { if ((pageSize != 0) and (storeId.packetIndex < numberOfElements[storeId.poolIndex])) {
uint16_t packetPosition = getRawPosition(storeId); size_type packetPosition = getRawPosition(storeId);
uint8_t* ptr = &store[storeId.poolIndex][packetPosition]; uint8_t* ptr = &store[storeId.poolIndex][packetPosition];
std::memset(ptr, 0, pageSize); std::memset(ptr, 0, pageSize);
// Set free list // Set free list

View File

@ -23,18 +23,8 @@ TmTcBridge::TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDes
TmTcBridge::~TmTcBridge() { QueueFactory::instance()->deleteMessageQueue(tmTcReceptionQueue); } TmTcBridge::~TmTcBridge() { QueueFactory::instance()->deleteMessageQueue(tmTcReceptionQueue); }
ReturnValue_t TmTcBridge::setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle) { void TmTcBridge::setNumberOfSentPacketsPerCycle(uint32_t sentPacketsPerCycle_) {
if (sentPacketsPerCycle <= LIMIT_STORED_DATA_SENT_PER_CYCLE) { this->sentPacketsPerCycle = sentPacketsPerCycle_;
this->sentPacketsPerCycle = sentPacketsPerCycle;
return returnvalue::OK;
} else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TmTcBridge::setNumberOfSentPacketsPerCycle: Number of "
<< "packets sent per cycle exceeds limits. "
<< "Keeping default value." << std::endl;
#endif
return returnvalue::FAILED;
}
} }
ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(unsigned int maxNumberOfPacketsStored) { ReturnValue_t TmTcBridge::setMaxNumberOfPacketsStored(unsigned int maxNumberOfPacketsStored) {
@ -144,8 +134,8 @@ ReturnValue_t TmTcBridge::handleTmQueue() {
#endif #endif
#endif /* FSFW_VERBOSE_LEVEL >= 3 */ #endif /* FSFW_VERBOSE_LEVEL >= 3 */
if (communicationLinkUp == false or packetSentCounter >= sentPacketsPerCycle) { if (!communicationLinkUp or packetSentCounter >= sentPacketsPerCycle) {
ReturnValue_t result = storeDownlinkData(&message); result = storeDownlinkData(&message);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
tmStore->deleteData(message.getStorageId()); tmStore->deleteData(message.getStorageId());
} }

View File

@ -15,10 +15,9 @@ class TmTcBridge : public AcceptsTelemetryIF,
public ExecutableObjectIF, public ExecutableObjectIF,
public SystemObject { public SystemObject {
public: public:
static constexpr uint8_t LIMIT_STORED_DATA_SENT_PER_CYCLE = 15;
static constexpr unsigned int LIMIT_DOWNLINK_PACKETS_STORED = 500; static constexpr unsigned int LIMIT_DOWNLINK_PACKETS_STORED = 500;
static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 5; static constexpr uint8_t DEFAULT_STORED_DATA_SENT_PER_CYCLE = 20;
static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10; static constexpr uint8_t DEFAULT_DOWNLINK_PACKETS_STORED = 10;
TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDestination, TmTcBridge(const char* name, object_id_t objectId, object_id_t tcDestination,
@ -32,7 +31,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
* @return -@c returnvalue::OK if value was set successfully * @return -@c returnvalue::OK if value was set successfully
* -@c returnvalue::FAILED otherwise, stored value stays the same * -@c returnvalue::FAILED otherwise, stored value stays the same
*/ */
ReturnValue_t setNumberOfSentPacketsPerCycle(uint8_t sentPacketsPerCycle); void setNumberOfSentPacketsPerCycle(uint32_t sentPacketsPerCycle);
/** /**
* Set number of packets sent per performOperation().Please note that this * Set number of packets sent per performOperation().Please note that this
@ -151,7 +150,7 @@ class TmTcBridge : public AcceptsTelemetryIF,
* This FIFO can be used to store downlink data which can not be sent at the moment. * This FIFO can be used to store downlink data which can not be sent at the moment.
*/ */
DynamicFIFO<store_address_t>* tmFifo = nullptr; DynamicFIFO<store_address_t>* tmFifo = nullptr;
uint8_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE; uint32_t sentPacketsPerCycle = DEFAULT_STORED_DATA_SENT_PER_CYCLE;
unsigned int maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED; unsigned int maxNumberOfPacketsStored = DEFAULT_DOWNLINK_PACKETS_STORED;
}; };

View File

@ -0,0 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE)

View File

@ -0,0 +1,19 @@
#pragma once
#include <cstdint>
class ProvidesSeqCountIF {
public:
virtual ~ProvidesSeqCountIF() = default;
[[nodiscard]] virtual unsigned int bitWidth() const = 0;
virtual uint64_t get() = 0;
virtual void increment() = 0;
virtual uint64_t getAndIncrement() {
uint64_t val = get();
increment();
return val;
}
};

View File

@ -0,0 +1,25 @@
#pragma once
#include <type_traits>
#include "ProvidesSeqCountIF.h"
template <typename T>
class SeqCountProvider : public ProvidesSeqCountIF {
static_assert(std::is_same<T, uint8_t>::value || std::is_same<T, uint16_t>::value ||
std::is_same<T, uint32_t>::value,
"Only uint8_t, uint16_t, and uint32_t are allowed.");
public:
[[nodiscard]] unsigned int bitWidth() const override { return sizeof(T) * 8; }
uint64_t get() override { return counter; }
// I'm also abusing the primitive C variable overflow wrap around here.
void increment() override { counter++; }
private:
T counter{};
};
using SeqCountProviderU8 = SeqCountProvider<uint8_t>;
using SeqCountProviderU16 = SeqCountProvider<uint16_t>;
using SeqCountProviderU32 = SeqCountProvider<uint32_t>;

View File

@ -184,3 +184,11 @@ ReturnValue_t HostFilesystem::getBaseFilename(FilesystemParams params, char *nam
baseNameLen = baseName.size(); baseNameLen = baseName.size();
return returnvalue::OK; return returnvalue::OK;
} }
bool HostFilesystem::getFileSize(FilesystemParams params, uint64_t &fileSize) {
if (!fileExists(params)) {
return false;
}
fileSize = std::filesystem::file_size(params.path);
return true;
}

View File

@ -11,6 +11,7 @@ class HostFilesystem : public HasFileSystemIF {
ReturnValue_t getBaseFilename(FilesystemParams params, char *nameBuf, size_t maxLen, ReturnValue_t getBaseFilename(FilesystemParams params, char *nameBuf, size_t maxLen,
size_t &baseNameLen) override; size_t &baseNameLen) override;
virtual bool getFileSize(FilesystemParams params, uint64_t &fileSize) override;
bool isDirectory(const char *path) override; bool isDirectory(const char *path) override;
bool fileExists(FilesystemParams params) override; bool fileExists(FilesystemParams params) override;
ReturnValue_t truncateFile(FilesystemParams params) override; ReturnValue_t truncateFile(FilesystemParams params) override;

View File

@ -282,7 +282,7 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t *recvPtr, SPI_HandleT
#endif #endif
#endif #endif
spiCookie.setTransferState(spi::TransferStates::FAILURE); spiCookie.setTransferState(spi::TransferStates::FAILURE);
return spi::HAL_TIMEOUT_RETVAL; return spi::TIMEOUT;
} }
case (HAL_ERROR): case (HAL_ERROR):
default: { default: {
@ -296,7 +296,7 @@ ReturnValue_t SpiComIF::handlePollingSendOperation(uint8_t *recvPtr, SPI_HandleT
#endif #endif
#endif #endif
spiCookie.setTransferState(spi::TransferStates::FAILURE); spiCookie.setTransferState(spi::TransferStates::FAILURE);
return spi::HAL_ERROR_RETVAL; return spi::GENERIC_ERROR;
} }
} }
return returnvalue::OK; return returnvalue::OK;

View File

@ -9,11 +9,6 @@
namespace spi { namespace spi {
static constexpr uint8_t HAL_SPI_ID = CLASS_ID::HAL_SPI;
static constexpr ReturnValue_t HAL_TIMEOUT_RETVAL = returnvalue::makeCode(HAL_SPI_ID, 0);
static constexpr ReturnValue_t HAL_BUSY_RETVAL = returnvalue::makeCode(HAL_SPI_ID, 1);
static constexpr ReturnValue_t HAL_ERROR_RETVAL = returnvalue::makeCode(HAL_SPI_ID, 2);
enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE }; enum class TransferStates { IDLE, WAIT, SUCCESS, FAILURE };
enum SpiBus { SPI_1, SPI_2 }; enum SpiBus { SPI_1, SPI_2 };

View File

@ -32,7 +32,7 @@ void Factory::produceFrameworkObjects(void* args) {
setStaticFrameworkObjectIds(); setStaticFrameworkObjectIds();
new EventManager(objects::EVENT_MANAGER, 120); new EventManager(objects::EVENT_MANAGER, 120);
new HealthTable(objects::HEALTH_TABLE); new HealthTable(objects::HEALTH_TABLE);
new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER, 20, false, 1.0); new InternalErrorReporter(objects::INTERNAL_ERROR_REPORTER, 20, false, 5.0);
{ {
PoolManager::LocalPoolConfig poolCfg = {{100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024}}; PoolManager::LocalPoolConfig poolCfg = {{100, 16}, {50, 32}, {25, 64}, {15, 128}, {5, 1024}};

View File

@ -57,7 +57,7 @@ TEST_CASE("Action Helper", "[action]") {
step += 1; step += 1;
CHECK(testMqMock.wasMessageSent()); CHECK(testMqMock.wasMessageSent());
CommandMessage testMessage; CommandMessage testMessage;
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK); REQUIRE(testMqMock.getNextSentMessageToDefaultDest(testMessage) == returnvalue::OK);
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED)); REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
REQUIRE(testMessage.getParameter() == static_cast<uint32_t>(testActionId)); REQUIRE(testMessage.getParameter() == static_cast<uint32_t>(testActionId));
uint32_t parameter2 = ((uint32_t)step << 16) | (uint32_t)status; uint32_t parameter2 = ((uint32_t)step << 16) | (uint32_t)status;
@ -71,7 +71,7 @@ TEST_CASE("Action Helper", "[action]") {
actionHelper.finish(false, testMqMock.getId(), testActionId, status); actionHelper.finish(false, testMqMock.getId(), testActionId, status);
CHECK(testMqMock.wasMessageSent()); CHECK(testMqMock.wasMessageSent());
CommandMessage testMessage; CommandMessage testMessage;
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK); REQUIRE(testMqMock.getNextSentMessageToDefaultDest(testMessage) == returnvalue::OK);
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::COMPLETION_FAILED)); REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::COMPLETION_FAILED));
REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId); REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast<uint32_t>(status)); REQUIRE(ActionMessage::getReturnCode(&testMessage) == static_cast<uint32_t>(status));
@ -87,7 +87,7 @@ TEST_CASE("Action Helper", "[action]") {
REQUIRE(ipcStore->getData(toLongParamAddress).first == REQUIRE(ipcStore->getData(toLongParamAddress).first ==
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST)); static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
CommandMessage testMessage; CommandMessage testMessage;
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK); REQUIRE(testMqMock.getNextSentMessageToDefaultDest(testMessage) == returnvalue::OK);
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED)); REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE); REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE);
REQUIRE(ActionMessage::getStep(&testMessage) == 0); REQUIRE(ActionMessage::getStep(&testMessage) == 0);

View File

@ -1,5 +1,6 @@
target_sources(${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testOtherTlvs.cpp target_sources(
testTlv.cpp testLvs.cpp) ${FSFW_TEST_TGT} PRIVATE testCfdp.cpp testOtherTlvs.cpp
testReservedMsgCreator.cpp testTlv.cpp testLvs.cpp)
add_subdirectory(handler) add_subdirectory(handler)
add_subdirectory(pdu) add_subdirectory(pdu)

View File

@ -1,3 +1,4 @@
target_sources( target_sources(
${FSFW_TEST_TGT} PRIVATE testDistributor.cpp testDestHandler.cpp ${FSFW_TEST_TGT}
testSourceHandler.cpp testFaultHandler.cpp) PRIVATE testDistributor.cpp testDestHandler.cpp testReservedMsgParser.cpp
testPutRequest.cpp testSourceHandler.cpp testFaultHandler.cpp)

View File

@ -50,18 +50,18 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
auto destHandler = DestHandler(dp, fp); auto destHandler = DestHandler(dp, fp);
CHECK(destHandler.initialize() == OK); CHECK(destHandler.initialize() == OK);
auto metadataPreparation = [&](FileSize cfdpFileSize, ChecksumType checksumType) { auto metadataPreparation = [&](Fss cfdpFileSize, ChecksumType checksumType) {
std::string srcNameString = "hello.txt"; std::string srcNameString = "hello.txt";
std::string destNameString = "hello-cpy.txt"; std::string destNameString = "hello-cpy.txt";
StringLv srcName(srcNameString); StringLv srcName(srcNameString);
StringLv destName(destNameString); StringLv destName(destNameString);
MetadataInfo info(false, checksumType, cfdpFileSize, srcName, destName); MetadataGenericInfo info(false, checksumType, std::move(cfdpFileSize));
TransactionSeqNum seqNum(UnsignedByteField<uint16_t>(1)); TransactionSeqNum seqNum(UnsignedByteField<uint16_t>(1));
conf.sourceId = remoteId; conf.sourceId = remoteId;
conf.destId = localId; conf.destId = localId;
conf.mode = TransmissionMode::UNACKNOWLEDGED; conf.mode = TransmissionMode::UNACKNOWLEDGED;
conf.seqNum = seqNum; conf.seqNum = seqNum;
MetadataPduCreator metadataCreator(conf, info); MetadataPduCreator metadataCreator(conf, info, srcName, destName, nullptr, 0);
REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &buf) == OK); REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &buf) == OK);
REQUIRE(metadataCreator.serialize(buf, serLen, metadataCreator.getSerializedSize()) == OK); REQUIRE(metadataCreator.serialize(buf, serLen, metadataCreator.getSerializedSize()) == OK);
PacketInfo packetInfo(metadataCreator.getPduType(), storeId, PacketInfo packetInfo(metadataCreator.getPduType(), storeId,
@ -81,17 +81,17 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
auto& idMetadataPair = userMock.metadataRecvd.back(); auto& idMetadataPair = userMock.metadataRecvd.back();
REQUIRE(idMetadataPair.first == destHandler.getTransactionId()); REQUIRE(idMetadataPair.first == destHandler.getTransactionId());
REQUIRE(idMetadataPair.second.sourceId.getValue() == 3); REQUIRE(idMetadataPair.second.sourceId.getValue() == 3);
REQUIRE(idMetadataPair.second.fileSize == fileLen); REQUIRE(idMetadataPair.second.fileSize.getSize(nullptr) == fileLen);
REQUIRE(strcmp(idMetadataPair.second.destFileName, destName) == 0); REQUIRE(strcmp(idMetadataPair.second.destFileName, destName) == 0);
REQUIRE(strcmp(idMetadataPair.second.sourceFileName, sourceName) == 0); REQUIRE(strcmp(idMetadataPair.second.sourceFileName, sourceName) == 0);
userMock.metadataRecvd.pop(); userMock.metadataRecvd.pop();
REQUIRE(fsMock.fileMap.find(destName) != fsMock.fileMap.end()); REQUIRE(fsMock.fileMap.find(destName) != fsMock.fileMap.end());
REQUIRE(res.result == OK); REQUIRE(res.result == OK);
REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); REQUIRE(res.state == CfdpState::BUSY_CLASS_1_NACKED);
REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS);
}; };
auto eofPreparation = [&](FileSize cfdpFileSize, uint32_t crc) { auto eofPreparation = [&](Fss cfdpFileSize, uint32_t crc) {
EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, crc, std::move(cfdpFileSize)); EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, crc, std::move(cfdpFileSize));
EofPduCreator eofCreator(conf, eofInfo); EofPduCreator eofCreator(conf, eofInfo);
REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &buf) == OK); REQUIRE(tcStore.getFreeElement(&storeId, eofCreator.getSerializedSize(), &buf) == OK);
@ -102,14 +102,14 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
auto eofCheck = [&](const cfdp::DestHandler::FsmResult& res, const TransactionId& id) { auto eofCheck = [&](const cfdp::DestHandler::FsmResult& res, const TransactionId& id) {
REQUIRE(res.result == OK); REQUIRE(res.result == OK);
REQUIRE(res.state == CfdpStates::IDLE); REQUIRE(res.state == CfdpState::IDLE);
REQUIRE(res.errors == 0); REQUIRE(res.errors == 0);
REQUIRE(res.step == DestHandler::TransactionStep::IDLE); REQUIRE(res.step == DestHandler::TransactionStep::IDLE);
// Assert that the packet was deleted after handling // Assert that the packet was deleted after handling
REQUIRE(not tcStore.hasDataAtId(storeId)); REQUIRE(not tcStore.hasDataAtId(storeId));
REQUIRE(packetInfoList.empty()); REQUIRE(packetInfoList.empty());
REQUIRE(userMock.eofsRevd.size() == 1); REQUIRE(userMock.eofRecvdRecvd.size() == 1);
auto& eofId = userMock.eofsRevd.back(); auto& eofId = userMock.eofRecvdRecvd.back();
CHECK(eofId == id); CHECK(eofId == id);
REQUIRE(userMock.finishedRecvd.size() == 1); REQUIRE(userMock.finishedRecvd.size() == 1);
auto& idParamPair = userMock.finishedRecvd.back(); auto& idParamPair = userMock.finishedRecvd.back();
@ -120,7 +120,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res, auto fileDataPduCheck = [&](const cfdp::DestHandler::FsmResult& res,
const std::vector<store_address_t>& idsToCheck) { const std::vector<store_address_t>& idsToCheck) {
REQUIRE(res.result == OK); REQUIRE(res.result == OK);
REQUIRE(res.state == CfdpStates::BUSY_CLASS_1_NACKED); REQUIRE(res.state == CfdpState::BUSY_CLASS_1_NACKED);
REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS); REQUIRE(res.step == DestHandler::TransactionStep::RECEIVING_FILE_DATA_PDUS);
for (const auto id : idsToCheck) { for (const auto id : idsToCheck) {
REQUIRE(not tcStore.hasDataAtId(id)); REQUIRE(not tcStore.hasDataAtId(id));
@ -129,50 +129,50 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
}; };
SECTION("State") { SECTION("State") {
CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); CHECK(destHandler.getCfdpState() == CfdpState::IDLE);
CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE);
} }
SECTION("Idle State Machine Iteration") { SECTION("Idle State Machine Iteration") {
auto res = destHandler.performStateMachine(); auto res = destHandler.stateMachine();
CHECK(res.result == OK); CHECK(res.result == OK);
CHECK(res.callStatus == CallStatus::CALL_AFTER_DELAY); CHECK(res.callStatus == CallStatus::CALL_AFTER_DELAY);
CHECK(res.errors == 0); CHECK(res.errors == 0);
CHECK(destHandler.getCfdpState() == CfdpStates::IDLE); CHECK(destHandler.getCfdpState() == CfdpState::IDLE);
CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE); CHECK(destHandler.getTransactionStep() == DestHandler::TransactionStep::IDLE);
} }
SECTION("Empty File Transfer") { SECTION("Empty File Transfer") {
const DestHandler::FsmResult& res = destHandler.performStateMachine(); const DestHandler::FsmResult& res = destHandler.stateMachine();
CHECK(res.result == OK); CHECK(res.result == OK);
FileSize cfdpFileSize(0); Fss cfdpFileSize(0);
metadataPreparation(cfdpFileSize, ChecksumType::NULL_CHECKSUM); metadataPreparation(cfdpFileSize, ChecksumType::NULL_CHECKSUM);
destHandler.performStateMachine(); destHandler.stateMachine();
metadataCheck(res, "hello.txt", "hello-cpy.txt", 0); metadataCheck(res, "hello.txt", "hello-cpy.txt", 0);
destHandler.performStateMachine(); destHandler.stateMachine();
REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY);
auto transactionId = destHandler.getTransactionId(); auto transactionId = destHandler.getTransactionId();
eofPreparation(cfdpFileSize, 0); eofPreparation(cfdpFileSize, 0);
// After EOF, operation is done because no closure was requested // After EOF, operation is done because no closure was requested
destHandler.performStateMachine(); destHandler.stateMachine();
eofCheck(res, transactionId); eofCheck(res, transactionId);
} }
SECTION("Small File Transfer") { SECTION("Small File Transfer") {
const DestHandler::FsmResult& res = destHandler.performStateMachine(); const DestHandler::FsmResult& res = destHandler.stateMachine();
CHECK(res.result == OK); CHECK(res.result == OK);
std::string fileData = "hello test data"; std::string fileData = "hello test data";
etl::crc32 crcCalc; etl::crc32 crcCalc;
crcCalc.add(fileData.begin(), fileData.end()); crcCalc.add(fileData.begin(), fileData.end());
uint32_t crc32 = crcCalc.value(); uint32_t crc32 = crcCalc.value();
FileSize cfdpFileSize(fileData.size()); Fss cfdpFileSize(fileData.size());
metadataPreparation(cfdpFileSize, ChecksumType::CRC_32); metadataPreparation(cfdpFileSize, ChecksumType::CRC_32);
destHandler.performStateMachine(); destHandler.stateMachine();
metadataCheck(res, "hello.txt", "hello-cpy.txt", fileData.size()); metadataCheck(res, "hello.txt", "hello-cpy.txt", fileData.size());
destHandler.performStateMachine(); destHandler.stateMachine();
REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY);
auto transactionId = destHandler.getTransactionId(); auto transactionId = destHandler.getTransactionId();
FileSize offset(0); Fss offset(0);
FileDataInfo fdPduInfo(offset, reinterpret_cast<const uint8_t*>(fileData.data()), FileDataInfo fdPduInfo(offset, reinterpret_cast<const uint8_t*>(fileData.data()),
fileData.size()); fileData.size());
FileDataCreator fdPduCreator(conf, fdPduInfo); FileDataCreator fdPduCreator(conf, fdPduInfo);
@ -180,16 +180,16 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK); REQUIRE(fdPduCreator.serialize(buf, serLen, fdPduCreator.getSerializedSize()) == OK);
PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt); PacketInfo packetInfo(fdPduCreator.getPduType(), storeId, std::nullopt);
packetInfoList.push_back(packetInfo); packetInfoList.push_back(packetInfo);
destHandler.performStateMachine(); destHandler.stateMachine();
fileDataPduCheck(res, {storeId}); fileDataPduCheck(res, {storeId});
eofPreparation(cfdpFileSize, crc32); eofPreparation(cfdpFileSize, crc32);
// After EOF, operation is done because no closure was requested // After EOF, operation is done because no closure was requested
destHandler.performStateMachine(); destHandler.stateMachine();
eofCheck(res, transactionId); eofCheck(res, transactionId);
} }
SECTION("Segmented File Transfer") { SECTION("Segmented File Transfer") {
const DestHandler::FsmResult& res = destHandler.performStateMachine(); const DestHandler::FsmResult& res = destHandler.stateMachine();
CHECK(res.result == OK); CHECK(res.result == OK);
std::random_device dev; std::random_device dev;
std::mt19937 rng(dev()); std::mt19937 rng(dev());
@ -201,17 +201,17 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
etl::crc32 crcCalc; etl::crc32 crcCalc;
crcCalc.add(largerFileData.begin(), largerFileData.end()); crcCalc.add(largerFileData.begin(), largerFileData.end());
uint32_t crc32 = crcCalc.value(); uint32_t crc32 = crcCalc.value();
FileSize cfdpFileSize(largerFileData.size()); Fss cfdpFileSize(largerFileData.size());
metadataPreparation(cfdpFileSize, ChecksumType::CRC_32); metadataPreparation(cfdpFileSize, ChecksumType::CRC_32);
destHandler.performStateMachine(); destHandler.stateMachine();
metadataCheck(res, "hello.txt", "hello-cpy.txt", largerFileData.size()); metadataCheck(res, "hello.txt", "hello-cpy.txt", largerFileData.size());
destHandler.performStateMachine(); destHandler.stateMachine();
REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY); REQUIRE(res.callStatus == CallStatus::CALL_AFTER_DELAY);
auto transactionId = destHandler.getTransactionId(); auto transactionId = destHandler.getTransactionId();
std::vector<store_address_t> idsToCheck; std::vector<store_address_t> idsToCheck;
{ {
FileSize offset(0); Fss offset(0);
FileDataInfo fdPduInfo(offset, reinterpret_cast<const uint8_t*>(largerFileData.data()), FileDataInfo fdPduInfo(offset, reinterpret_cast<const uint8_t*>(largerFileData.data()),
largerFileData.size() / 2); largerFileData.size() / 2);
FileDataCreator fdPduCreator(conf, fdPduInfo); FileDataCreator fdPduCreator(conf, fdPduInfo);
@ -223,7 +223,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
} }
{ {
FileSize offset(512); Fss offset(512);
FileDataInfo fdPduInfo(offset, reinterpret_cast<const uint8_t*>(largerFileData.data() + 512), FileDataInfo fdPduInfo(offset, reinterpret_cast<const uint8_t*>(largerFileData.data() + 512),
largerFileData.size() / 2); largerFileData.size() / 2);
FileDataCreator fdPduCreator(conf, fdPduInfo); FileDataCreator fdPduCreator(conf, fdPduInfo);
@ -234,11 +234,11 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
packetInfoList.push_back(packetInfo); packetInfoList.push_back(packetInfo);
} }
destHandler.performStateMachine(); destHandler.stateMachine();
fileDataPduCheck(res, idsToCheck); fileDataPduCheck(res, idsToCheck);
eofPreparation(cfdpFileSize, crc32); eofPreparation(cfdpFileSize, crc32);
// After EOF, operation is done because no closure was requested // After EOF, operation is done because no closure was requested
destHandler.performStateMachine(); destHandler.stateMachine();
eofCheck(res, transactionId); eofCheck(res, transactionId);
} }
} }

View File

@ -21,7 +21,7 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") {
auto tcAcceptor = AcceptsTcMock("CFDP Receiver", 0, receiverQueueId); auto tcAcceptor = AcceptsTcMock("CFDP Receiver", 0, receiverQueueId);
// Set up Metadata PDU for generate test data. // Set up Metadata PDU for generate test data.
cfdp::FileSize fileSize(12); cfdp::Fss fileSize(12);
const cfdp::EntityId& sourceId(groundEntityId); const cfdp::EntityId& sourceId(groundEntityId);
const cfdp::EntityId& destId(obswEntityId); const cfdp::EntityId& destId(obswEntityId);
cfdp::TransactionSeqNum seqNum(UnsignedByteField<uint16_t>(12)); cfdp::TransactionSeqNum seqNum(UnsignedByteField<uint16_t>(12));
@ -30,9 +30,8 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") {
cfdp::StringLv sourceFileName(sourceFileString); cfdp::StringLv sourceFileName(sourceFileString);
std::string destFileString = "hello2.txt"; std::string destFileString = "hello2.txt";
cfdp::StringLv destFileName(destFileString); cfdp::StringLv destFileName(destFileString);
MetadataInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize, sourceFileName, MetadataGenericInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize);
destFileName); MetadataPduCreator creator(pduConf, metadataInfo, sourceFileName, destFileName, nullptr, 0);
MetadataPduCreator creator(pduConf, metadataInfo);
uint8_t* dataPtr = nullptr; uint8_t* dataPtr = nullptr;
SECTION("State") { SECTION("State") {

View File

@ -0,0 +1,59 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp/handler/PutRequest.h"
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
TEST_CASE("Put Request", "[cfdp]") {
using namespace cfdp;
using namespace returnvalue;
std::array<uint8_t, 32> reservedMsgCustomData{};
std::array<uint8_t, 128> reservedMsgBuf{};
std::array<uint8_t, 128> buffer{};
EntityId destId(WidthInBytes::ONE_BYTE, 5);
std::string srcFileName = "hello.txt";
std::string destFileName = "hello2.txt";
uint8_t* msgBufPtr = reservedMsgCustomData.data();
size_t msgSize = 0;
cfdp::StringLv srcName(srcFileName);
cfdp::StringLv destName(destFileName);
CHECK(destId.serializeAsLv(&msgBufPtr, &msgSize, reservedMsgCustomData.size()) == OK);
CHECK(srcName.serialize(&msgBufPtr, &msgSize, reservedMsgCustomData.size(),
SerializeIF::Endianness::NETWORK) == OK);
CHECK(destName.serialize(&msgBufPtr, &msgSize, reservedMsgCustomData.size(),
SerializeIF::Endianness::NETWORK) == OK);
ReservedMessageCreator creator(static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST),
reservedMsgCustomData.data(), msgSize);
msgSize = 0;
ReturnValue_t result = creator.serializeBe(reservedMsgBuf.data(), msgSize, buffer.size());
CHECK(result == returnvalue::OK);
SECTION("Put Request with reserved message") {
PutRequest putRequest(destId, reservedMsgBuf.data(), msgSize, nullptr, 0);
uint8_t* bufPtr = buffer.data();
size_t serLen = 0;
REQUIRE(putRequest.serialize(&bufPtr, &serLen, buffer.size(),
SerializeIF::Endianness::NETWORK) == OK);
CHECK(putRequest.getSerializedSize() == serLen);
PutRequest requestDeserialized;
size_t deserLen = putRequest.getSerializedSize();
const uint8_t* deserPtr = buffer.data();
REQUIRE(requestDeserialized.deSerialize(&deserPtr, &deserLen,
SerializeIF::Endianness::NETWORK) == OK);
CHECK(requestDeserialized.getDestId().getWidth() == destId.getWidth());
CHECK(requestDeserialized.getDestId().getValue() == destId.getValue());
size_t totalMsgsSize = 0;
const uint8_t* msgsToUserStart = requestDeserialized.getMessagesToUser(totalMsgsSize);
CHECK(totalMsgsSize == msgSize);
cfdp::Tlv genericTlv;
genericTlv.deSerialize(&msgsToUserStart, &totalMsgsSize, SerializeIF::Endianness::NETWORK);
CHECK(genericTlv.getType() == TlvType::MSG_TO_USER);
CHECK(genericTlv.getLengthField() == genericTlv.getSerializedSize() - 2);
CHECK(genericTlv.getValue()[0] == 'c');
CHECK(genericTlv.getValue()[1] == 'f');
CHECK(genericTlv.getValue()[2] == 'd');
CHECK(genericTlv.getValue()[3] == 'p');
}
}

View File

@ -0,0 +1,67 @@
#include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp/CfdpMessage.h"
#include "fsfw/cfdp/VarLenFields.h"
#include "fsfw/cfdp/handler/PutRequest.h"
#include "fsfw/cfdp/handler/ReservedMessageParser.h"
#include "fsfw/cfdp/tlv/Lv.h"
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
#include "fsfw/cfdp/tlv/StringLv.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serialize.h"
#include "mocks/MessageQueueMock.h"
#include "mocks/StorageManagerMock.h"
TEST_CASE("Reserved Message Parser", "[cfdp]") {
using namespace cfdp;
using namespace returnvalue;
std::string srcFileName = "hello.txt";
std::string destFileName = "hello2.txt";
MessageQueueId_t destQueueId = 2;
MessageQueueMock msgQueue(1);
LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}};
StorageManagerMock ipcStore(0, storeCfg);
std::array<uint8_t, 128> buffer{};
uint8_t msgBuf[32]{};
EntityId entityId(cfdp::WidthInBytes::ONE_BYTE, 5);
uint8_t* msgBufPtr = msgBuf;
size_t serLen = 0;
cfdp::StringLv srcName(srcFileName);
cfdp::StringLv destName(destFileName);
CHECK(entityId.serializeAsLv(&msgBufPtr, &serLen, sizeof(msgBuf)) == OK);
CHECK(srcName.serialize(&msgBufPtr, &serLen, sizeof(msgBuf), SerializeIF::Endianness::NETWORK) ==
OK);
CHECK(destName.serialize(&msgBufPtr, &serLen, sizeof(msgBuf), SerializeIF::Endianness::NETWORK) ==
OK);
ReservedMessageCreator creator(static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST), msgBuf,
serLen);
serLen = 0;
ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size());
CHECK(result == returnvalue::OK);
MessageToUserTlv msgToUser;
CHECK(msgToUser.deSerializeBe(buffer.data(), serLen, buffer.size()) == OK);
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
REQUIRE(parser.parse(&msgToUser, 1) == OK);
CommandMessage msg;
CHECK(msgQueue.wasMessageSent());
CHECK(msgQueue.numberOfSentMessages() == 1);
CHECK(msgQueue.getNextSentMessage(destQueueId, msg) == OK);
store_address_t storeId = CfdpMessage::getStoreId(&msg);
const uint8_t* data;
size_t packetLen;
CHECK(ipcStore.getData(storeId, &data, &packetLen) == OK);
CHECK(packetLen > 0);
PutRequest putRequest;
size_t dummy = packetLen;
REQUIRE(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK);
CHECK(putRequest.getDestId().getValue() == entityId.getValue());
CHECK(putRequest.getDestId().getWidth() == entityId.getWidth());
auto& sourceNameLv = putRequest.getSourceName();
std::string srcNameRead = sourceNameLv.getString();
CHECK(srcNameRead == srcFileName);
auto& destNameLv = putRequest.getDestName();
std::string destNameRead = destNameLv.getString();
CHECK(destNameRead == destFileName);
}

View File

@ -1,3 +1,286 @@
#include <catch2/catch_test_macros.hpp> #include <etl/crc32.h>
TEST_CASE("CFDP Source Handler", "[cfdp]") {} #include <catch2/catch_test_macros.hpp>
#include <filesystem>
#include <random>
#include "fsfw/cfdp.h"
#include "fsfw/cfdp/handler/PutRequest.h"
#include "fsfw/cfdp/handler/SourceHandler.h"
#include "fsfw/cfdp/pdu/EofPduCreator.h"
#include "fsfw/cfdp/pdu/EofPduReader.h"
#include "fsfw/cfdp/pdu/FileDataReader.h"
#include "fsfw/cfdp/pdu/MetadataPduCreator.h"
#include "fsfw/cfdp/pdu/MetadataPduReader.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
#include "fsfw/util/SeqCountProvider.h"
#include "mocks/AcceptsTmMock.h"
#include "mocks/EventReportingProxyMock.h"
#include "mocks/FilesystemMock.h"
#include "mocks/MessageQueueMock.h"
#include "mocks/StorageManagerMock.h"
#include "mocks/cfdp/FaultHandlerMock.h"
#include "mocks/cfdp/RemoteConfigTableMock.h"
#include "mocks/cfdp/UserMock.h"
TEST_CASE("CFDP Source Handler", "[cfdp]") {
using namespace cfdp;
using namespace returnvalue;
using namespace std::filesystem;
const size_t MAX_FILE_SEGMENT_SIZE = 255;
MessageQueueId_t destQueueId = 2;
AcceptsTmMock tmReceiver(destQueueId);
MessageQueueMock mqMock(destQueueId);
EntityId localId = EntityId(UnsignedByteField<uint16_t>(2));
EntityId remoteId = EntityId(UnsignedByteField<uint16_t>(5));
FaultHandlerMock fhMock;
LocalEntityCfg localEntityCfg(localId, IndicationCfg(), fhMock);
FilesystemMock fsMock;
UserMock userMock(fsMock);
SeqCountProviderU16 seqCountProvider;
SourceHandlerParams dp(localEntityCfg, userMock, seqCountProvider);
EventReportingProxyMock eventReporterMock;
LocalPool::LocalPoolConfig storeCfg = {{10, 32}, {10, 64}, {10, 128}, {10, 1024}};
StorageManagerMock tcStore(2, storeCfg);
StorageManagerMock tmStore(3, storeCfg);
FsfwParams fp(tmReceiver, &mqMock, &eventReporterMock);
fp.tcStore = &tcStore;
fp.tmStore = &tmStore;
auto sourceHandler = SourceHandler(dp, fp);
RemoteEntityCfg cfg;
cfg.maxFileSegmentLen = MAX_FILE_SEGMENT_SIZE;
cfg.remoteId = remoteId;
std::string srcFileName = "/tmp/cfdp-test.txt";
std::string destFileName = "/tmp/cfdp-test2.txt";
FilesystemParams srcFileNameFs(srcFileName.c_str());
fsMock.createFile(srcFileNameFs);
cfdp::StringLv srcNameLv(srcFileNameFs.path, std::strlen(srcFileNameFs.path));
FilesystemParams destFileNameFs(destFileName.c_str());
cfdp::StringLv destNameLv(destFileNameFs.path, std::strlen(destFileNameFs.path));
PutRequest putRequest(remoteId, srcNameLv, destNameLv);
CHECK(sourceHandler.initialize() == OK);
auto onePduSentCheck = [&](const SourceHandler::FsmResult& fsmResult, TmTcMessage& tmtcMessage,
const uint8_t** pduPtr) {
CHECK(fsmResult.errors == 0);
CHECK(fsmResult.packetsSent == 1);
CHECK(mqMock.numberOfSentMessages() == 1);
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
auto accessor = tmStore.getData(tmtcMessage.getStorageId());
REQUIRE(accessor.first == OK);
*pduPtr = accessor.second.data();
return std::move(accessor);
};
auto genericMetadataCheck = [&](const SourceHandler::FsmResult& fsmResult,
size_t expectedFileSize, uint16_t expectedSeqNum) {
CHECK(fsmResult.errors == 0);
CHECK(fsmResult.callStatus == CallStatus::CALL_AGAIN);
TmTcMessage tmtcMessage;
const uint8_t* pduPtr;
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
CHECK(accessor.second.size() == 55);
MetadataGenericInfo metadataInfo;
MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0);
REQUIRE(metadataReader.parseData() == OK);
std::string srcNameRead = metadataReader.getSourceFileName().getString();
CHECK(srcNameRead == srcFileName);
TransactionSeqNum seqNum;
metadataReader.getTransactionSeqNum(seqNum);
CHECK(seqNum.getValue() == expectedSeqNum);
CHECK(userMock.transactionIndicRecvd.size() == 1);
CHECK(userMock.transactionIndicRecvd.back() == TransactionId(localId, seqNum));
EntityId srcId;
metadataReader.getSourceId(srcId);
EntityId destId;
metadataReader.getDestId(destId);
CHECK(srcId.getValue() == localId.getValue());
CHECK(destId.getValue() == remoteId.getValue());
std::string destNameRead = metadataReader.getDestFileName().getString();
CHECK(destNameRead == destFileName);
if (expectedFileSize == 0) {
CHECK(metadataInfo.getChecksumType() == ChecksumType::NULL_CHECKSUM);
} else {
CHECK(metadataInfo.getChecksumType() == ChecksumType::CRC_32);
}
CHECK(metadataInfo.getFileSize().value() == expectedFileSize);
CHECK(!metadataInfo.isClosureRequested());
mqMock.clearMessages();
};
auto genericEofCheck = [&](const SourceHandler::FsmResult& fsmResult, size_t expectedFileSize,
uint32_t expectedChecksum, uint16_t expectedSeqNum) {
CHECK(fsmResult.errors == 0);
CHECK(fsmResult.callStatus == CallStatus::CALL_AGAIN);
TmTcMessage tmtcMessage;
const uint8_t* pduPtr;
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
// 10 byte PDU header, 1 byte directive field, 1 byte condition code, 4 byte checksum,
// 4 byte FSS
CHECK(accessor.second.size() == 20);
EofInfo eofInfo;
EofPduReader eofReader(pduPtr, accessor.second.size(), eofInfo);
REQUIRE(eofReader.parseData() == OK);
TransactionSeqNum seqNum;
eofReader.getTransactionSeqNum(seqNum);
CHECK(seqNum.getValue() == expectedSeqNum);
auto transactionId = TransactionId(localId, seqNum);
CHECK(userMock.eofSentRecvd.size() == 1);
CHECK(userMock.eofSentRecvd.back() == transactionId);
CHECK(eofInfo.getChecksum() == expectedChecksum);
CHECK(eofInfo.getConditionCode() == ConditionCode::NO_ERROR);
CHECK(eofInfo.getFileSize().value() == expectedFileSize);
};
auto genericNoticeOfCompletionCheck = [&](const SourceHandler::FsmResult& fsmResult,
uint16_t expectedSeqNum) {
CHECK(fsmResult.callStatus == CallStatus::DONE);
CHECK(userMock.finishedRecvd.size() == 1);
CHECK(userMock.finishedRecvd.back().first ==
TransactionId(localId, TransactionSeqNum(cfdp::WidthInBytes::TWO_BYTES, expectedSeqNum)));
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
CHECK(sourceHandler.getState() == CfdpState::IDLE);
};
SECTION("Test Basic") {
CHECK(sourceHandler.getState() == CfdpState::IDLE);
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
}
SECTION("Transfer empty file") {
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
size_t expectedFileSize = 0;
const SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
// Verify metadata PDU was sent.
genericMetadataCheck(fsmResult, expectedFileSize, 0);
sourceHandler.stateMachine();
// Verify EOF PDU was sent. No file data PDU is sent for an empty file and the checksum is 0.
genericEofCheck(fsmResult, expectedFileSize, 0, 0);
// Verify notice of completion.
sourceHandler.stateMachine();
genericNoticeOfCompletionCheck(fsmResult, 0);
}
SECTION("Transfer small file") {
uint16_t expectedSeqNum = 0;
fsMock.createFile(srcFileNameFs);
std::string fileContent = "hello world\n";
size_t expectedFileSize = fileContent.size();
FileOpParams params(srcFileName.c_str(), expectedFileSize);
fsMock.writeToFile(params, reinterpret_cast<const uint8_t*>(fileContent.data()));
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
const SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
// Verify metadata PDU was sent.
genericMetadataCheck(fsmResult, expectedFileSize, expectedSeqNum);
// Verify that a small file data PDU was sent.
sourceHandler.stateMachine();
TmTcMessage tmtcMessage;
const uint8_t* pduPtr;
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
FileDataInfo fdInfo;
FileDataReader fdReader(pduPtr, accessor.second.size(), fdInfo);
// 10 byte PDU header, 4 byte offset, 12 bytes file data.
CHECK(accessor.second.size() == 26);
CHECK(fdReader.parseData() == OK);
CHECK(fdInfo.getOffset().value() == 0);
size_t fileSize = 0;
const uint8_t* fileData = fdInfo.getFileData(&fileSize);
REQUIRE(fileSize == fileContent.size());
CHECK(fileData != nullptr);
std::string dataReadBack(reinterpret_cast<const char*>(fileData), fileSize);
CHECK(dataReadBack == fileContent);
mqMock.clearMessages();
sourceHandler.stateMachine();
etl::crc32 crcCalc;
crcCalc.add(fileContent.data(), fileContent.data() + fileContent.size());
// Verify EOF PDU was sent.
genericEofCheck(fsmResult, expectedFileSize, crcCalc.value(), expectedSeqNum);
// Verify notice of completion.
sourceHandler.stateMachine();
genericNoticeOfCompletionCheck(fsmResult, expectedSeqNum);
}
SECTION("Transfer two segment file") {
uint16_t expectedSeqNum = 0;
// Create 400 bytes of random data. This should result in two file segments, with one
// having the maximum size.
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> distU8(0, 255);
std::array<uint8_t, 400> largerFileData{};
for (auto& val : largerFileData) {
val = distU8(rng);
}
size_t expectedFileSize = largerFileData.size();
fsMock.createFile(srcFileNameFs);
FileOpParams params(srcFileName.c_str(), expectedFileSize);
fsMock.writeToFile(params, reinterpret_cast<const uint8_t*>(largerFileData.data()));
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
const SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
// Verify metadata PDU was sent.
genericMetadataCheck(fsmResult, expectedFileSize, expectedSeqNum);
// Check first file data PDU. It should have the maximum file segment size.
sourceHandler.stateMachine();
TmTcMessage tmtcMessage;
const uint8_t* pduPtr;
FileDataInfo fdInfo;
{
CHECK(fsmResult.callStatus == CallStatus::CALL_AGAIN);
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
FileDataReader fdReader(pduPtr, accessor.second.size(), fdInfo);
// 10 byte PDU header, 4 byte offset, 255 byte file data
CHECK(accessor.second.size() == 269);
CHECK(fdReader.parseData() == OK);
CHECK(fdInfo.getOffset().value() == 0);
size_t fileSize = 0;
const uint8_t* fileData = fdInfo.getFileData(&fileSize);
// Maximum file segment size.
REQUIRE(fileSize == MAX_FILE_SEGMENT_SIZE);
for (unsigned i = 0; i < fileSize; i++) {
CHECK(fileData[i] == largerFileData[i]);
}
}
mqMock.clearMessages();
// Check second file data PDU.
sourceHandler.stateMachine();
{
CHECK(fsmResult.callStatus == CallStatus::CALL_AGAIN);
auto accessor = onePduSentCheck(fsmResult, tmtcMessage, &pduPtr);
FileDataReader fdReader(pduPtr, accessor.second.size(), fdInfo);
// 10 byte PDU header, 4 byte offset, remaining file data (400 - 255 == 145).
CHECK(accessor.second.size() == 10 + 4 + largerFileData.size() - MAX_FILE_SEGMENT_SIZE);
CHECK(fdReader.parseData() == OK);
CHECK(fdInfo.getOffset().value() == MAX_FILE_SEGMENT_SIZE);
size_t fileDataSize = 0;
const uint8_t* fileData = fdInfo.getFileData(&fileDataSize);
// Maximum file segment size.
REQUIRE(fileDataSize == largerFileData.size() - MAX_FILE_SEGMENT_SIZE);
for (unsigned i = 0; i < fileDataSize; i++) {
CHECK(fileData[i] == largerFileData[MAX_FILE_SEGMENT_SIZE + i]);
}
}
mqMock.clearMessages();
// Check EOF and verify checksum.
sourceHandler.stateMachine();
etl::crc32 crcCalc;
crcCalc.add(largerFileData.data(), largerFileData.data() + largerFileData.size());
// Verify EOF PDU was sent.
genericEofCheck(fsmResult, expectedFileSize, crcCalc.value(), expectedSeqNum);
// Verify notice of completion.
sourceHandler.stateMachine();
genericNoticeOfCompletionCheck(fsmResult, expectedSeqNum);
}
}

View File

@ -110,9 +110,9 @@ TEST_CASE("CFDP Header", "[cfdp]") {
} }
SECTION("Other variable sized fields") { SECTION("Other variable sized fields") {
pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); pduConf.seqNum.setValueAndWidth(cfdp::WidthInBytes::TWO_BYTES, 0x0fff);
pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00);
pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); pduConf.destId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff);
REQUIRE(pduConf.sourceId.getSerializedSize() == 4); REQUIRE(pduConf.sourceId.getSerializedSize() == 4);
REQUIRE(creator.getSerializedSize() == 14); REQUIRE(creator.getSerializedSize() == 14);
REQUIRE(creator.serialize(&serTarget, &serSize, serBuf.size(), REQUIRE(creator.serialize(&serTarget, &serSize, serBuf.size(),
@ -146,9 +146,9 @@ TEST_CASE("CFDP Header", "[cfdp]") {
} }
SECTION("Buffer Too Short") { SECTION("Buffer Too Short") {
pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); pduConf.seqNum.setValueAndWidth(cfdp::WidthInBytes::TWO_BYTES, 0x0fff);
pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00);
pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); pduConf.destId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff);
for (uint8_t idx = 0; idx < 14; idx++) { for (uint8_t idx = 0; idx < 14; idx++) {
REQUIRE(creator.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG) == REQUIRE(creator.serialize(&serTarget, &serSize, idx, SerializeIF::Endianness::BIG) ==
SerializeIF::BUFFER_TOO_SHORT); SerializeIF::BUFFER_TOO_SHORT);
@ -157,11 +157,11 @@ TEST_CASE("CFDP Header", "[cfdp]") {
} }
SECTION("Invalid Variable Sized Fields") { SECTION("Invalid Variable Sized Fields") {
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 0xfff); result = pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::ONE_BYTE, 0xfff);
REQUIRE(result == returnvalue::FAILED); REQUIRE(result == returnvalue::FAILED);
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::TWO_BYTES, 0xfffff); result = pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::TWO_BYTES, 0xfffff);
REQUIRE(result == returnvalue::FAILED); REQUIRE(result == returnvalue::FAILED);
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff); result = pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 0xfffffffff);
REQUIRE(result == returnvalue::FAILED); REQUIRE(result == returnvalue::FAILED);
} }
@ -207,7 +207,7 @@ TEST_CASE("CFDP Header", "[cfdp]") {
SerializeIF::Endianness::MACHINE); SerializeIF::Endianness::MACHINE);
REQUIRE(pduConf.sourceId.getValue() == 0xf0f0f0f0); REQUIRE(pduConf.sourceId.getValue() == 0xf0f0f0f0);
pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 1); pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::ONE_BYTE, 1);
serTarget = serBuf.data(); serTarget = serBuf.data();
serSize = 1; serSize = 1;
result = pduConf.sourceId.serialize(&serTarget, &serSize, 1, SerializeIF::Endianness::MACHINE); result = pduConf.sourceId.serialize(&serTarget, &serSize, 1, SerializeIF::Endianness::MACHINE);
@ -257,11 +257,11 @@ TEST_CASE("CFDP Header", "[cfdp]") {
creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION); creator.setSegmentationControl(cfdp::SegmentationControl::RECORD_BOUNDARIES_PRESERVATION);
creator.setPduType(cfdp::PduType::FILE_DATA); creator.setPduType(cfdp::PduType::FILE_DATA);
creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT); creator.setSegmentMetadataFlag(cfdp::SegmentMetadataFlag::PRESENT);
result = pduConf.seqNum.setValue(cfdp::WidthInBytes::TWO_BYTES, 0x0fff); result = pduConf.seqNum.setValueAndWidth(cfdp::WidthInBytes::TWO_BYTES, 0x0fff);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
result = pduConf.sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00); result = pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 0xff00ff00);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
result = pduConf.destId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff); result = pduConf.destId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 0x00ff00ff);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
serTarget = serBuf.data(); serTarget = serBuf.data();
serSize = 0; serSize = 0;
@ -302,8 +302,8 @@ TEST_CASE("CFDP Header", "[cfdp]") {
SECTION("Manipulate Source Dest ID") { SECTION("Manipulate Source Dest ID") {
serTarget = serBuf.data(); serTarget = serBuf.data();
serSize = 0; serSize = 0;
pduConf.sourceId.setValue(cfdp::WidthInBytes::ONE_BYTE, 22); pduConf.sourceId.setValueAndWidth(cfdp::WidthInBytes::ONE_BYTE, 22);
pduConf.destId.setValue(cfdp::WidthInBytes::ONE_BYTE, 48); pduConf.destId.setValueAndWidth(cfdp::WidthInBytes::ONE_BYTE, 48);
result = creator.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG); result = creator.serialize(&serTarget, &serSize, serBuf.size(), SerializeIF::Endianness::BIG);
reader.getSourceId(sourceDestId); reader.getSourceId(sourceDestId);
REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE); REQUIRE(sourceDestId.getWidth() == cfdp::WidthInBytes::ONE_BYTE);

View File

@ -14,7 +14,7 @@ TEST_CASE("EOF PDU", "[cfdp][pdu]") {
size_t sz = 0; size_t sz = 0;
EntityId destId(WidthInBytes::TWO_BYTES, 2); EntityId destId(WidthInBytes::TWO_BYTES, 2);
EntityIdTlv faultLoc(destId); EntityIdTlv faultLoc(destId);
FileSize fileSize(12); Fss fileSize(12);
// We can already set the fault location, it will be ignored // We can already set the fault location, it will be ignored
EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, 5, fileSize, &faultLoc); EofInfo eofInfo(cfdp::ConditionCode::NO_ERROR, 5, fileSize, &faultLoc);
TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15); TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15);

View File

@ -22,7 +22,7 @@ TEST_CASE("File Data PDU", "[cfdp][pdu]") {
for (uint8_t idx = 0; idx < 10; idx++) { for (uint8_t idx = 0; idx < 10; idx++) {
fileBuffer[idx] = idx; fileBuffer[idx] = idx;
} }
FileSize offset(50); Fss offset(50);
FileDataInfo info(offset, fileBuffer.data(), 10); FileDataInfo info(offset, fileBuffer.data(), 10);
SECTION("Serialization") { SECTION("Serialization") {
@ -107,8 +107,7 @@ TEST_CASE("File Data PDU", "[cfdp][pdu]") {
serializer.serialize(&buffer, &sz, fileDataBuffer.size(), SerializeIF::Endianness::NETWORK); serializer.serialize(&buffer, &sz, fileDataBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
FileSize emptyOffset; FileDataInfo emptyInfo;
FileDataInfo emptyInfo(emptyOffset);
FileDataReader deserializer(fileDataBuffer.data(), fileDataBuffer.size(), emptyInfo); FileDataReader deserializer(fileDataBuffer.data(), fileDataBuffer.size(), emptyInfo);
result = deserializer.parseData(); result = deserializer.parseData();
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);

View File

@ -16,7 +16,7 @@ TEST_CASE("Keep Alive PDU", "[cfdp][pdu]") {
EntityId sourceId(WidthInBytes::TWO_BYTES, 1); EntityId sourceId(WidthInBytes::TWO_BYTES, 1);
PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum);
FileSize progress(0x50); Fss progress(0x50);
SECTION("Serialize") { SECTION("Serialize") {
KeepAlivePduCreator serializer(pduConf, progress); KeepAlivePduCreator serializer(pduConf, progress);

View File

@ -6,11 +6,10 @@
#include "fsfw/cfdp/pdu/MetadataPduReader.h" #include "fsfw/cfdp/pdu/MetadataPduReader.h"
#include "fsfw/cfdp/tlv/FilestoreResponseTlv.h" #include "fsfw/cfdp/tlv/FilestoreResponseTlv.h"
#include "fsfw/cfdp/tlv/MessageToUserTlv.h" #include "fsfw/cfdp/tlv/MessageToUserTlv.h"
#include "fsfw/globalfunctions/arrayprinter.h"
TEST_CASE("Metadata PDU", "[cfdp][pdu]") { TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
using namespace cfdp; using namespace cfdp;
ReturnValue_t result = returnvalue::OK; ReturnValue_t result;
std::array<uint8_t, 256> mdBuffer = {}; std::array<uint8_t, 256> mdBuffer = {};
uint8_t* buffer = mdBuffer.data(); uint8_t* buffer = mdBuffer.data();
size_t sz = 0; size_t sz = 0;
@ -22,30 +21,22 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
std::string firstFileName = "hello.txt"; std::string firstFileName = "hello.txt";
cfdp::StringLv sourceFileName(firstFileName); cfdp::StringLv sourceFileName(firstFileName);
cfdp::StringLv destFileName; cfdp::StringLv destFileName;
FileSize fileSize(35); Fss fileSize(35);
MetadataInfo info(false, ChecksumType::MODULAR, fileSize, sourceFileName, destFileName); MetadataGenericInfo info(false, ChecksumType::MODULAR, fileSize);
FilestoreResponseTlv response(FilestoreActionCode::CREATE_DIRECTORY, FSR_CREATE_NOT_ALLOWED, FilestoreResponseTlv response(FilestoreActionCode::CREATE_DIRECTORY, FSR_CREATE_NOT_ALLOWED,
sourceFileName, nullptr); sourceFileName, nullptr);
std::array<uint8_t, 3> msg = {0x41, 0x42, 0x43}; std::array<uint8_t, 3> msg = {0x41, 0x42, 0x43};
cfdp::Tlv responseTlv; cfdp::Tlv responseTlv;
std::array<uint8_t, 64> responseBuf = {}; std::array<uint8_t, 64> responseBuf = {};
uint8_t* responseBufPtr = responseBuf.data();
response.convertToTlv(responseTlv, buffer, responseBuf.size(), SerializeIF::Endianness::MACHINE); response.convertToTlv(responseTlv, buffer, responseBuf.size(), SerializeIF::Endianness::MACHINE);
MessageToUserTlv msgToUser(msg.data(), msg.size()); MessageToUserTlv msgToUser(msg.data(), msg.size());
std::array<Tlv*, 2> options{&responseTlv, &msgToUser}; std::array<Tlv*, 2> options{&responseTlv, &msgToUser};
std::array<Tlv, 5> tlvDeser{};
REQUIRE(options[0]->getSerializedSize() == 2 + 1 + 10 + 1); REQUIRE(options[0]->getSerializedSize() == 2 + 1 + 10 + 1);
REQUIRE(options[1]->getSerializedSize() == 5); REQUIRE(options[1]->getSerializedSize() == 5);
SECTION("Serialize") { auto metadataCheckPartOne = [&]() {
MetadataPduCreator serializer(pduConf, info);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
REQUIRE(serializer.getWholePduSize() == 27);
REQUIRE(info.getSourceFileName().getSerializedSize() == 10);
REQUIRE(info.getDestFileName().getSerializedSize() == 1);
REQUIRE(info.getSerializedSize() == 16);
REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 17);
REQUIRE(mdBuffer[10] == FileDirective::METADATA); REQUIRE(mdBuffer[10] == FileDirective::METADATA);
// no closure requested and checksum type is modular => 0x00 // no closure requested and checksum type is modular => 0x00
REQUIRE(mdBuffer[11] == 0x00); REQUIRE(mdBuffer[11] == 0x00);
@ -64,20 +55,59 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
REQUIRE(mdBuffer[23] == 't'); REQUIRE(mdBuffer[23] == 't');
REQUIRE(mdBuffer[24] == 'x'); REQUIRE(mdBuffer[24] == 'x');
REQUIRE(mdBuffer[25] == 't'); REQUIRE(mdBuffer[25] == 't');
REQUIRE(mdBuffer[26] == 0); };
SECTION("Serialize with empty dest name") {
MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, nullptr, 0);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
CHECK(sz == serializer.getSerializedSize());
// 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source
// name field (10) + dest name field (1).
REQUIRE(serializer.getWholePduSize() == 27);
REQUIRE(serializer.getSourceFileName().getSerializedSize() == 10);
REQUIRE(serializer.getDestFileName().getSerializedSize() == 1);
REQUIRE(info.getSerializedSize() == 5);
REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 17);
REQUIRE(serializer.getSerializedSize() == serializer.getWholePduSize());
metadataCheckPartOne();
REQUIRE(mdBuffer[26] == 0);
}
SECTION("Serialize with dest name") {
std::string secondFileName = "hello2.txt";
cfdp::StringLv destFileName2(secondFileName);
MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName2, nullptr, 0);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
// 10 byte heater + 1 byte PDU directive field + 1 byte PDU content + FSS field (4) + source
// name field (10) + dest name field (11).
REQUIRE(serializer.getWholePduSize() == 37);
CHECK(sz == serializer.getSerializedSize());
REQUIRE((mdBuffer[1] << 8 | mdBuffer[2]) == 27);
REQUIRE(serializer.getSerializedSize() == serializer.getWholePduSize());
metadataCheckPartOne();
// Size of destination name field
REQUIRE(mdBuffer[26] == 10);
REQUIRE(mdBuffer[27] == 'h');
REQUIRE(mdBuffer[28] == 'e');
REQUIRE(mdBuffer[29] == 'l');
REQUIRE(mdBuffer[30] == 'l');
REQUIRE(mdBuffer[31] == 'o');
REQUIRE(mdBuffer[32] == '2');
REQUIRE(mdBuffer[33] == '.');
REQUIRE(mdBuffer[34] == 't');
REQUIRE(mdBuffer[35] == 'x');
REQUIRE(mdBuffer[36] == 't');
}
SECTION("Serialize with 2 options") {
std::string otherFileName = "hello2.txt"; std::string otherFileName = "hello2.txt";
cfdp::StringLv otherFileNameLv(otherFileName.data(), otherFileName.size()); cfdp::StringLv otherFileNameLv(otherFileName.data(), otherFileName.size());
info.setSourceFileName(otherFileNameLv); MetadataPduCreator serializer(pduConf, info, otherFileNameLv, destFileName, options.data(),
size_t sizeOfOptions = options.size(); options.size());
info.setOptionsArray(options.data(), sizeOfOptions, sizeOfOptions);
REQUIRE(info.getMaxOptionsLen() == 2);
info.setMaxOptionsLen(3);
REQUIRE(info.getMaxOptionsLen() == 3);
info.setChecksumType(cfdp::ChecksumType::CRC_32C); info.setChecksumType(cfdp::ChecksumType::CRC_32C);
info.setClosureRequested(true); info.setClosureRequested(true);
uint8_t* buffer = mdBuffer.data();
size_t sz = 0;
serializer.updateDirectiveFieldLen(); serializer.updateDirectiveFieldLen();
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
@ -98,49 +128,47 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
// TLV unittests // TLV unittests
REQUIRE(sz == 10 + 37); REQUIRE(sz == 10 + 37);
for (size_t maxSz = 0; maxSz < sz; maxSz++) { for (size_t maxSz = 0; maxSz < sz; maxSz++) {
uint8_t* buffer = mdBuffer.data(); buffer = mdBuffer.data();
size_t sz = 0; sz = 0;
result = serializer.serialize(&buffer, &sz, maxSz, SerializeIF::Endianness::NETWORK); result = serializer.serialize(&buffer, &sz, maxSz, SerializeIF::Endianness::NETWORK);
REQUIRE(result == SerializeIF::BUFFER_TOO_SHORT); REQUIRE(result == SerializeIF::BUFFER_TOO_SHORT);
} }
for (size_t initSz = 1; initSz < 47; initSz++) { for (size_t initSz = 1; initSz < 47; initSz++) {
uint8_t* buffer = mdBuffer.data(); buffer = mdBuffer.data();
size_t sz = initSz; sz = initSz;
result = serializer.serialize(&buffer, &sz, 46, SerializeIF::Endianness::NETWORK); result = serializer.serialize(&buffer, &sz, 46, SerializeIF::Endianness::NETWORK);
REQUIRE(result == SerializeIF::BUFFER_TOO_SHORT); REQUIRE(result == SerializeIF::BUFFER_TOO_SHORT);
} }
info.setDestFileName(destFileName);
} }
SECTION("Deserialize") { SECTION("Deserialize") {
MetadataPduCreator serializer(pduConf, info); MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, nullptr, 0);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
MetadataPduReader deserializer(mdBuffer.data(), mdBuffer.size(), info); MetadataPduReader deserializer(mdBuffer.data(), mdBuffer.size(), info, nullptr, 0);
result = deserializer.parseData(); result = deserializer.parseData();
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
size_t fullSize = deserializer.getWholePduSize(); size_t fullSize = deserializer.getWholePduSize();
for (size_t maxSz = 0; maxSz < fullSize; maxSz++) { for (size_t maxSz = 0; maxSz < fullSize; maxSz++) {
MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info); MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info, nullptr, 0);
result = invalidSzDeser.parseData(); result = invalidSzDeser.parseData();
REQUIRE(result != returnvalue::OK); REQUIRE(result != returnvalue::OK);
} }
size_t sizeOfOptions = options.size(); }
size_t maxSize = 4;
info.setOptionsArray(options.data(), sizeOfOptions, maxSize); SECTION("Deserialize with 2 options") {
REQUIRE(info.getOptionsLen() == 2); MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, options.data(),
options.size());
info.setChecksumType(cfdp::ChecksumType::CRC_32C); info.setChecksumType(cfdp::ChecksumType::CRC_32C);
info.setClosureRequested(true); info.setClosureRequested(true);
uint8_t* buffer = mdBuffer.data();
size_t sz = 0;
serializer.updateDirectiveFieldLen(); serializer.updateDirectiveFieldLen();
info.setSourceFileName(sourceFileName);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK); result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info); MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info, tlvDeser.data(),
tlvDeser.max_size());
result = deserializer2.parseData(); result = deserializer2.parseData();
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
REQUIRE(options[0]->getType() == cfdp::TlvType::FILESTORE_RESPONSE); REQUIRE(options[0]->getType() == cfdp::TlvType::FILESTORE_RESPONSE);
@ -151,12 +179,15 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
for (size_t invalidFieldLen = 0; invalidFieldLen < 36; invalidFieldLen++) { for (size_t invalidFieldLen = 0; invalidFieldLen < 36; invalidFieldLen++) {
mdBuffer[1] = (invalidFieldLen >> 8) & 0xff; mdBuffer[1] = (invalidFieldLen >> 8) & 0xff;
mdBuffer[2] = invalidFieldLen & 0xff; mdBuffer[2] = invalidFieldLen & 0xff;
if (invalidFieldLen == 17) {
volatile uint32_t dummy = 0;
}
result = deserializer2.parseData(); result = deserializer2.parseData();
if (invalidFieldLen == 17) { if (invalidFieldLen == 17) {
REQUIRE(info.getOptionsLen() == 0); REQUIRE(deserializer2.getNumberOfParsedOptions() == 0);
} }
if (invalidFieldLen == 31) { if (invalidFieldLen == 31) {
REQUIRE(info.getOptionsLen() == 1); REQUIRE(deserializer2.getNumberOfParsedOptions() == 1);
} }
// This is the precise length where there are no options or one option // This is the precise length where there are no options or one option
if (invalidFieldLen != 17 and invalidFieldLen != 31) { if (invalidFieldLen != 17 and invalidFieldLen != 31) {
@ -165,11 +196,25 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
} }
mdBuffer[1] = (36 >> 8) & 0xff; mdBuffer[1] = (36 >> 8) & 0xff;
mdBuffer[2] = 36 & 0xff; mdBuffer[2] = 36 & 0xff;
info.setOptionsArray(nullptr, std::nullopt, std::nullopt); }
SECTION("Can not parse options") {
MetadataPduCreator serializer(pduConf, info, sourceFileName, destFileName, options.data(),
options.size());
info.setChecksumType(cfdp::ChecksumType::CRC_32C);
info.setClosureRequested(true);
buffer = mdBuffer.data();
sz = 0;
serializer.updateDirectiveFieldLen();
// info.setSourceFileName(sourceFileName);
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info, nullptr, 0);
REQUIRE(deserializer2.parseData() == cfdp::METADATA_CANT_PARSE_OPTIONS); REQUIRE(deserializer2.parseData() == cfdp::METADATA_CANT_PARSE_OPTIONS);
info.setOptionsArray(options.data(), sizeOfOptions, std::nullopt);
for (size_t maxSz = 0; maxSz < 46; maxSz++) { for (size_t maxSz = 0; maxSz < 46; maxSz++) {
MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info); MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info, nullptr, 0);
if (not invalidSzDeser.isNull()) { if (not invalidSzDeser.isNull()) {
result = invalidSzDeser.parseData(); result = invalidSzDeser.parseData();
REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT);

View File

@ -17,8 +17,8 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") {
EntityId sourceId(WidthInBytes::TWO_BYTES, 1); EntityId sourceId(WidthInBytes::TWO_BYTES, 1);
PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum); PduConfig pduConf(sourceId, destId, TransmissionMode::ACKNOWLEDGED, seqNum);
FileSize startOfScope(50); Fss startOfScope(50);
FileSize endOfScope(1050); Fss endOfScope(1050);
NakInfo info(startOfScope, endOfScope); NakInfo info(startOfScope, endOfScope);
SECTION("Serializer") { SECTION("Serializer") {
NakPduCreator serializer(pduConf, info); NakPduCreator serializer(pduConf, info);
@ -40,8 +40,8 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") {
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
REQUIRE(scope == 1050); REQUIRE(scope == 1050);
NakInfo::SegmentRequest segReq0(cfdp::FileSize(2020), cfdp::FileSize(2520)); NakInfo::SegmentRequest segReq0(cfdp::Fss(2020), cfdp::Fss(2520));
NakInfo::SegmentRequest segReq1(cfdp::FileSize(2932), cfdp::FileSize(3021)); NakInfo::SegmentRequest segReq1(cfdp::Fss(2932), cfdp::Fss(3021));
// Now add 2 segment requests to NAK info and serialize them as well // Now add 2 segment requests to NAK info and serialize them as well
std::array<NakInfo::SegmentRequest, 2> segReqs = {segReq0, segReq1}; std::array<NakInfo::SegmentRequest, 2> segReqs = {segReq0, segReq1};
size_t segReqsLen = segReqs.size(); size_t segReqsLen = segReqs.size();
@ -100,8 +100,8 @@ TEST_CASE("NAK PDU", "[cfdp][pdu]") {
REQUIRE(info.getStartOfScope().getSize() == 50); REQUIRE(info.getStartOfScope().getSize() == 50);
REQUIRE(info.getEndOfScope().getSize() == 1050); REQUIRE(info.getEndOfScope().getSize() == 1050);
NakInfo::SegmentRequest segReq0(cfdp::FileSize(2020), cfdp::FileSize(2520)); NakInfo::SegmentRequest segReq0(cfdp::Fss(2020), cfdp::Fss(2520));
NakInfo::SegmentRequest segReq1(cfdp::FileSize(2932), cfdp::FileSize(3021)); NakInfo::SegmentRequest segReq1(cfdp::Fss(2932), cfdp::Fss(3021));
// Now add 2 segment requests to NAK info and serialize them as well // Now add 2 segment requests to NAK info and serialize them as well
std::array<NakInfo::SegmentRequest, 2> segReqs = {segReq0, segReq1}; std::array<NakInfo::SegmentRequest, 2> segReqs = {segReq0, segReq1};
size_t segReqsLen = segReqs.size(); size_t segReqsLen = segReqs.size();

View File

@ -2,7 +2,7 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <cstring> #include <cstring>
#include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/Fss.h"
#include "fsfw/cfdp/pdu/FileDirectiveCreator.h" #include "fsfw/cfdp/pdu/FileDirectiveCreator.h"
#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h"
#include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/globalfunctions/arrayprinter.h"
@ -79,7 +79,7 @@ TEST_CASE("CFDP Base", "[cfdp]") {
std::array<uint8_t, 8> fssBuf = {}; std::array<uint8_t, 8> fssBuf = {};
uint8_t* buffer = fssBuf.data(); uint8_t* buffer = fssBuf.data();
size_t size = 0; size_t size = 0;
cfdp::FileSize fss; cfdp::Fss fss;
REQUIRE(fss.getSize() == 0); REQUIRE(fss.getSize() == 0);
fss.setFileSize(0x20, false); fss.setFileSize(0x20, false);
result = fss.serialize(&buffer, &size, fssBuf.size(), SerializeIF::Endianness::MACHINE); result = fss.serialize(&buffer, &size, fssBuf.size(), SerializeIF::Endianness::MACHINE);

View File

@ -23,12 +23,6 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") {
auto lv = cfdp::Lv(lvRawBuf.data(), 2); auto lv = cfdp::Lv(lvRawBuf.data(), 2);
REQUIRE(lv.getSerializedSize() == 3); REQUIRE(lv.getSerializedSize() == 3);
SECTION("Copy") {
auto lvCopy = cfdp::Lv(lv);
REQUIRE(lvCopy.getSerializedSize() == 3);
REQUIRE(lv.getValue(nullptr) == lvCopy.getValue(nullptr));
}
serPtr = rawBuf.data(); serPtr = rawBuf.data();
deserSize = 0; deserSize = 0;
REQUIRE(lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) == REQUIRE(lv.serialize(&serPtr, &deserSize, rawBuf.size(), SerializeIF::Endianness::NETWORK) ==
@ -41,6 +35,16 @@ TEST_CASE("CFDP LV", "[cfdp][lv]") {
REQUIRE(sourceIdRaw == 0x0ff0); REQUIRE(sourceIdRaw == 0x0ff0);
} }
SECTION("Move LV") {
std::array<uint8_t, 8> lvRawBuf{};
serPtr = lvRawBuf.data();
REQUIRE(sourceId.serialize(&serPtr, &deserSize, lvRawBuf.size(),
SerializeIF::Endianness::NETWORK) == returnvalue::OK);
auto lv = cfdp::Lv(lvRawBuf.data(), 2);
auto lvMovedCopy = cfdp::Lv(std::move(lv));
REQUIRE(lvMovedCopy.getSerializedSize() == 3);
}
SECTION("Empty Serialization") { SECTION("Empty Serialization") {
auto lvEmpty = Lv(); auto lvEmpty = Lv();
REQUIRE(lvEmpty.getSerializedSize() == 1); REQUIRE(lvEmpty.getSerializedSize() == 1);

View File

@ -0,0 +1,49 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp/VarLenFields.h"
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
#include "fsfw/cfdp/tlv/StringLv.h"
TEST_CASE("Reserved Message Creator", "[cfdp][tlv]") {
using namespace cfdp;
using namespace returnvalue;
std::string srcFileName = "hello.txt";
std::string destFileName = "hello2.txt";
std::array<uint8_t, 64> buffer{};
uint8_t msgBuf[32]{};
EntityId entityId(cfdp::WidthInBytes::ONE_BYTE, 5);
uint8_t* msgBufPtr = msgBuf;
size_t serLen = 0;
cfdp::StringLv srcName(srcFileName);
cfdp::StringLv destName(destFileName);
CHECK(entityId.serializeAsLv(&msgBufPtr, &serLen, sizeof(msgBuf)) == OK);
CHECK(srcName.serialize(&msgBufPtr, &serLen, sizeof(msgBuf), SerializeIF::Endianness::NETWORK) ==
OK);
CHECK(destName.serialize(&msgBufPtr, &serLen, sizeof(msgBuf), SerializeIF::Endianness::NETWORK) ==
OK);
ReservedMessageCreator creator(static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST), msgBuf,
serLen);
serLen = 0;
ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size());
CHECK(result == returnvalue::OK);
CHECK(buffer[0] == TlvType::MSG_TO_USER);
// 4 bytes "cfdp" header, 1 byte message type, entity ID LV, source name LV and dest name LV
CHECK(buffer[1] ==
5 + 1 + entityId.getSerializedSize() + 1 + srcFileName.size() + 1 + destFileName.size());
CHECK(buffer[2] == 'c');
CHECK(buffer[3] == 'f');
CHECK(buffer[4] == 'd');
CHECK(buffer[5] == 'p');
CHECK(buffer[6] == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST));
CHECK(buffer[7] == 1);
CHECK(buffer[8] == entityId.getValue());
CHECK(buffer[9] == srcFileName.size());
size_t currentIdx = 10;
CHECK(std::string(reinterpret_cast<const char*>(buffer.data()) + currentIdx,
srcFileName.size()) == srcFileName);
currentIdx += srcFileName.size() + 1;
CHECK(std::string(reinterpret_cast<const char*>(buffer.data()) + currentIdx,
destFileName.size()) == destFileName);
}

View File

@ -40,7 +40,7 @@ TEST_CASE("CFDP TLV", "[cfdp][tlv]") {
SECTION("TLV Other Value") { SECTION("TLV Other Value") {
auto tlv = Tlv(TlvType::ENTITY_ID, rawBuf.data(), deserSize); auto tlv = Tlv(TlvType::ENTITY_ID, rawBuf.data(), deserSize);
// Set new value // Set new value
sourceId.setValue(cfdp::WidthInBytes::FOUR_BYTES, 12); sourceId.setValueAndWidth(cfdp::WidthInBytes::FOUR_BYTES, 12);
REQUIRE(sourceId.serialize(&serPtr, &deserSize, rawBuf.size(), REQUIRE(sourceId.serialize(&serPtr, &deserSize, rawBuf.size(),
SerializeIF::Endianness::NETWORK) == returnvalue::OK); SerializeIF::Endianness::NETWORK) == returnvalue::OK);
tlv.setValue(rawBuf.data(), cfdp::WidthInBytes::FOUR_BYTES); tlv.setValue(rawBuf.data(), cfdp::WidthInBytes::FOUR_BYTES);

View File

@ -82,7 +82,7 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK); REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() == CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == returnvalue::OK); REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT)); CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
/* Clear message to avoid memory leak, our mock won't do it for us (yet) */ /* Clear message to avoid memory leak, our mock won't do it for us (yet) */
CommandMessageCleaner::clearCommandMessage(&messageSent); CommandMessageCleaner::clearCommandMessage(&messageSent);
@ -259,11 +259,11 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
CHECK(messageSent.getCommand() == CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET)); static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK); REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == returnvalue::OK); REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT)); CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
REQUIRE(poolOwnerMock.clearLastSentMessage() == returnvalue::OK); REQUIRE(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY); REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY);
REQUIRE(poolOwnerMock.getNextSentMessage(messageSent) == MessageQueueIF::EMPTY); REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == MessageQueueIF::EMPTY);
} }
SECTION("PeriodicHKAndMessaging") { SECTION("PeriodicHKAndMessaging") {

View File

@ -9,8 +9,8 @@ class AcceptsTmMock : public SystemObject, public AcceptsTelemetryIF {
AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn); AcceptsTmMock(object_id_t registeredId, MessageQueueId_t queueToReturn);
explicit AcceptsTmMock(MessageQueueId_t queueToReturn); explicit AcceptsTmMock(MessageQueueId_t queueToReturn);
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const override; [[nodiscard]] MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) const override;
const char* getName() const override; [[nodiscard]] const char* getName() const override;
MessageQueueId_t returnedQueue; MessageQueueId_t returnedQueue;
}; };

View File

@ -39,7 +39,8 @@ ReturnValue_t FilesystemMock::readFromFile(FileOpParams params, uint8_t **buffer
if (readSize + readLen > maxSize) { if (readSize + readLen > maxSize) {
return SerializeIF::STREAM_TOO_SHORT; return SerializeIF::STREAM_TOO_SHORT;
} }
std::copy(info.fileRaw.data() + params.offset, info.fileRaw.data() + readLen, *buffer); std::copy(info.fileRaw.data() + params.offset, info.fileRaw.data() + params.offset + readLen,
*buffer);
*buffer += readLen; *buffer += readLen;
readSize += readLen; readSize += readLen;
} }
@ -80,7 +81,7 @@ ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool dele
ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath, ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath,
FileSystemArgsIF *args) { FileSystemArgsIF *args) {
renameQueue.push(RenameInfo(oldPath, newPath)); renameQueue.emplace(oldPath, newPath);
return returnvalue::OK; return returnvalue::OK;
} }
@ -90,7 +91,7 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data)
if (iter == fileMap.end()) { if (iter == fileMap.end()) {
FileSegmentQueue queue; FileSegmentQueue queue;
if (params.size > 0) { if (params.size > 0) {
queue.push(FileWriteInfo(filename, params.offset, data, params.size)); queue.emplace(filename, params.offset, data, params.size);
} }
FileInfo info; FileInfo info;
info.fileSegQueue = queue; info.fileSegQueue = queue;
@ -100,7 +101,7 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data)
fileMap.emplace(filename, info); fileMap.emplace(filename, info);
} else { } else {
FileInfo &info = iter->second; FileInfo &info = iter->second;
info.fileSegQueue.push(FileWriteInfo(filename, params.offset, data, params.size)); info.fileSegQueue.emplace(filename, params.offset, data, params.size);
if (data == nullptr) { if (data == nullptr) {
return; return;
} }
@ -145,3 +146,13 @@ ReturnValue_t FilesystemMock::getBaseFilename(FilesystemParams params, char *nam
} }
bool FilesystemMock::isDirectory(const char *path) { return false; } bool FilesystemMock::isDirectory(const char *path) { return false; }
bool FilesystemMock::getFileSize(FilesystemParams params, size_t &fileSize) {
std::string filename(params.path);
auto iter = fileMap.find(filename);
if (iter != fileMap.end()) {
fileSize = iter->second.fileRaw.size();
return true;
}
return false;
}

View File

@ -62,6 +62,7 @@ class FilesystemMock : public HasFileSystemIF {
bool isDirectory(const char *path) override; bool isDirectory(const char *path) override;
bool fileExists(FilesystemParams params) override; bool fileExists(FilesystemParams params) override;
ReturnValue_t truncateFile(FilesystemParams params) override; ReturnValue_t truncateFile(FilesystemParams params) override;
bool getFileSize(FilesystemParams params, size_t &fileSize) override;
ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override; ReturnValue_t writeToFile(FileOpParams params, const uint8_t *data) override;
ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize, ReturnValue_t readFromFile(FileOpParams params, uint8_t **buffer, size_t &readSize,

View File

@ -124,7 +124,7 @@ ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueId_t id,
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t MessageQueueMock::getNextSentMessage(MessageQueueMessageIF& message) { ReturnValue_t MessageQueueMock::getNextSentMessageToDefaultDest(MessageQueueMessageIF& message) {
return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message); return getNextSentMessage(MessageQueueBase::getDefaultDestination(), message);
} }

View File

@ -26,7 +26,7 @@ class MessageQueueMock : public MessageQueueBase {
explicit MessageQueueMock(MessageQueueId_t queueId); explicit MessageQueueMock(MessageQueueId_t queueId);
//! Get next message which was sent to the default destination //! Get next message which was sent to the default destination
ReturnValue_t getNextSentMessage(MessageQueueMessageIF& message); ReturnValue_t getNextSentMessageToDefaultDest(MessageQueueMessageIF& message);
//! Get message which was sent to a specific ID //! Get message which was sent to a specific ID
ReturnValue_t getNextSentMessage(MessageQueueId_t id, MessageQueueMessageIF& message); ReturnValue_t getNextSentMessage(MessageQueueId_t id, MessageQueueMessageIF& message);
[[nodiscard]] bool wasMessageSent() const; [[nodiscard]] bool wasMessageSent() const;

View File

@ -32,6 +32,7 @@ class StorageManagerMock : public LocalPool {
std::pair<bool, ReturnValue_t> nextFreeElementCallFails; std::pair<bool, ReturnValue_t> nextFreeElementCallFails;
using LocalPool::getFreeElement; using LocalPool::getFreeElement;
using StorageManagerIF::getData;
void reset(); void reset();
}; };

View File

@ -4,19 +4,20 @@ namespace cfdp {
cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {} cfdp::UserMock::UserMock(HasFileSystemIF& vfs) : UserBase(vfs) {}
void UserMock::transactionIndication(const TransactionId& id) {} void UserMock::transactionIndication(const TransactionId& id) { transactionIndicRecvd.emplace(id); }
void UserMock::eofSentIndication(const TransactionId& id) {}
void UserMock::eofSentIndication(const TransactionId& id) { eofSentRecvd.emplace(id); }
void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code, void UserMock::abandonedIndication(const TransactionId& id, cfdp::ConditionCode code,
uint64_t progress) {} uint64_t progress) {}
void UserMock::eofRecvIndication(const TransactionId& id) { eofsRevd.push(id); } void UserMock::eofRecvIndication(const TransactionId& id) { eofRecvdRecvd.push(id); }
void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) { void UserMock::transactionFinishedIndication(const TransactionFinishedParams& finishedParams) {
finishedRecvd.push({finishedParams.id, finishedParams}); finishedRecvd.emplace(finishedParams.id, finishedParams);
} }
void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) { void UserMock::metadataRecvdIndication(const MetadataRecvdParams& params) {
metadataRecvd.push({params.id, params}); metadataRecvd.emplace(params.id, params);
} }
void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {} void UserMock::fileSegmentRecvdIndication(const FileSegmentRecvdParams& params) {}
@ -27,7 +28,7 @@ void UserMock::faultIndication(const TransactionId& id, cfdp::ConditionCode code
} }
void UserMock::reset() { void UserMock::reset() {
std::queue<TransactionId>().swap(eofsRevd); std::queue<TransactionId>().swap(eofRecvdRecvd);
std::queue<std::pair<TransactionId, cfdp::MetadataRecvdParams>>().swap(metadataRecvd); std::queue<std::pair<TransactionId, cfdp::MetadataRecvdParams>>().swap(metadataRecvd);
std::queue<std::pair<TransactionId, cfdp::TransactionFinishedParams>>().swap(finishedRecvd); std::queue<std::pair<TransactionId, cfdp::TransactionFinishedParams>>().swap(finishedRecvd);
} }

Some files were not shown because too many files have changed in this diff Show More