CFDP SOURCE handler #157

Merged
muellerr merged 107 commits from cfdp-source-handler into develop 2023-10-19 10:59:55 +02:00
6 changed files with 43 additions and 41 deletions
Showing only changes of commit fde277cd06 - Show all commits

View File

@ -31,20 +31,14 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
return result;
}
if (!metadataOnly) {
result = SerializeAdapter::serialize(&sourceNameSize, buffer, size, maxSize, streamEndianness);
result = sourceName.serialize(buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
std::memcpy(*buffer, sourceName, sourceNameSize);
*buffer += sourceNameSize;
*size += sourceNameSize;
result = SerializeAdapter::serialize(&destNameSize, buffer, size, maxSize, streamEndianness);
result = destName.serialize(buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
std::memcpy(*buffer, destName, destNameSize);
*buffer += destNameSize;
*size += destNameSize;
result =
SerializeAdapter::serialize(&hasTransmissionMode, buffer, size, maxSize, streamEndianness);
if (result != OK) {
@ -100,21 +94,11 @@ ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size
return result;
}
if (!metadataOnly) {
result = SerializeAdapter::deSerialize(&sourceNameSize, buffer, size, streamEndianness);
result = sourceName.deSerialize(buffer, size, streamEndianness);
if (result != OK) {
return result;
}
sourceName = reinterpret_cast<const char *>(*buffer);
*buffer += sourceNameSize;
*size += sourceNameSize;
result = SerializeAdapter::deSerialize(&destNameSize, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
destName = reinterpret_cast<const char *>(*buffer);
*buffer += destNameSize;
*size += destNameSize;
result = SerializeAdapter::deSerialize(&hasTransmissionMode, buffer, size, streamEndianness);
result = destName.deSerialize(buffer, size, streamEndianness);
if (result != OK) {
return result;
}
@ -153,7 +137,7 @@ 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 += sizeof(sourceNameSize) + sourceNameSize + sizeof(destNameSize) + destNameSize + 2;
baseSize += sourceName.getSerializedSize() + destName.getSerializedSize() + 2;
}
baseSize += sizeof(msgsToUsersTotalSize) + msgsToUsersTotalSize + sizeof(fsRequestsTotalSize) +
fsRequestsTotalSize;
@ -162,6 +146,14 @@ size_t cfdp::PutRequest::getSerializedSize() const {
void cfdp::PutRequest::setSourceAndDestName(cfdp::StringLv &sourceName_,
cfdp::StringLv &destName_) {
this->sourceName = sourceName_.getString(sourceNameSize);
this->destName = destName_.getString(destNameSize);
this->sourceName = sourceName_;
this->destName = 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); }

View File

@ -11,8 +11,6 @@ namespace cfdp {
class PutRequest : public SerializeIF {
public:
EntityId destId;
/**
* Metadata only constructor.
* @param destId
@ -34,15 +32,26 @@ class PutRequest : public SerializeIF {
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;
[[nodiscard]] bool isMetadataOnly() 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.
const char* destName = nullptr;
uint64_t destNameSize = 0;
const char* sourceName = nullptr;
uint64_t sourceNameSize = 0;
cfdp::StringLv sourceName;
cfdp::StringLv destName;
// const char* destName = nullptr;
// uint64_t destNameSize = 0;
// const char* sourceName = nullptr;
// uint64_t sourceNameSize = 0;
bool hasTransmissionMode = false;
uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
bool hasClosureRequested = false;

View File

@ -30,19 +30,12 @@ ReturnValue_t cfdp::ReservedMessageParser::parse(const uint8_t* msgsToUserPtr,
uint8_t messageType = 0;
if (tlv.isReservedCfdpMessage(messageType, &currentPtr, deserSize)) {
if (messageType == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST)) {
cfdp::Lv entityIdLv;
result = entityIdLv.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);
EntityId entityIdLv;
entityIdLv.deSerializeFromLv(&currentPtr, &deserSize);
if (result != returnvalue::OK) {
return result;
}
size_t entityIdSize = 0;
const uint8_t* deserStart = entityIdLv.getValue(&entityIdSize);
result = putRequest.destId.deSerialize(static_cast<cfdp::WidthInBytes>(entityIdSize),
&deserStart, &entityIdSize,
SerializeIF::Endianness::NETWORK);
if (result != OK) {
return result;
}
putRequest.setDestId(entityIdLv);
cfdp::StringLv sourceFileName;
result =
sourceFileName.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);

View File

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

View File

@ -0,0 +1,3 @@
#include <catch2/catch_test_macros.hpp>
TEST_CASE("Put Request", "[cfdp]") {}

View File

@ -55,5 +55,10 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
CHECK(packetLen > 0);
PutRequest putRequest;
size_t dummy = packetLen;
CHECK(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK);
REQUIRE(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK);
CHECK(putRequest.getDestId().getValue() == entityId.getValue());
CHECK(putRequest.getDestId().getWidth() == entityId.getWidth());
// size_t sourceNameSize = 0;
// const char* sourceNameStart
// CHECK(putRequest.getSourceName(sourceNameSize));
}