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; return result;
} }
if (!metadataOnly) { if (!metadataOnly) {
result = SerializeAdapter::serialize(&sourceNameSize, buffer, size, maxSize, streamEndianness); result = sourceName.serialize(buffer, size, maxSize, streamEndianness);
if (result != OK) { if (result != OK) {
return result; return result;
} }
std::memcpy(*buffer, sourceName, sourceNameSize); result = destName.serialize(buffer, size, maxSize, streamEndianness);
*buffer += sourceNameSize;
*size += sourceNameSize;
result = SerializeAdapter::serialize(&destNameSize, buffer, size, maxSize, streamEndianness);
if (result != OK) { if (result != OK) {
return result; return result;
} }
std::memcpy(*buffer, destName, destNameSize);
*buffer += destNameSize;
*size += destNameSize;
result = result =
SerializeAdapter::serialize(&hasTransmissionMode, buffer, size, maxSize, streamEndianness); SerializeAdapter::serialize(&hasTransmissionMode, buffer, size, maxSize, streamEndianness);
if (result != OK) { if (result != OK) {
@ -100,21 +94,11 @@ ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size
return result; return result;
} }
if (!metadataOnly) { if (!metadataOnly) {
result = SerializeAdapter::deSerialize(&sourceNameSize, buffer, size, streamEndianness); result = sourceName.deSerialize(buffer, size, streamEndianness);
if (result != OK) { if (result != OK) {
return result; return result;
} }
sourceName = reinterpret_cast<const char *>(*buffer); result = destName.deSerialize(buffer, size, streamEndianness);
*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);
if (result != OK) { if (result != OK) {
return result; return result;
} }
@ -153,7 +137,7 @@ size_t cfdp::PutRequest::getSerializedSize() const {
// Entity ID LV (1 leading size byte) and the metadata only flag. // Entity ID LV (1 leading size byte) and the metadata only flag.
size_t baseSize = 1 + destId.getSerializedSize() + 1; size_t baseSize = 1 + destId.getSerializedSize() + 1;
if (!metadataOnly) { if (!metadataOnly) {
baseSize += sizeof(sourceNameSize) + sourceNameSize + sizeof(destNameSize) + destNameSize + 2; baseSize += sourceName.getSerializedSize() + destName.getSerializedSize() + 2;
} }
baseSize += sizeof(msgsToUsersTotalSize) + msgsToUsersTotalSize + sizeof(fsRequestsTotalSize) + baseSize += sizeof(msgsToUsersTotalSize) + msgsToUsersTotalSize + sizeof(fsRequestsTotalSize) +
fsRequestsTotalSize; fsRequestsTotalSize;
@ -162,6 +146,14 @@ size_t cfdp::PutRequest::getSerializedSize() const {
void cfdp::PutRequest::setSourceAndDestName(cfdp::StringLv &sourceName_, void cfdp::PutRequest::setSourceAndDestName(cfdp::StringLv &sourceName_,
cfdp::StringLv &destName_) { cfdp::StringLv &destName_) {
this->sourceName = sourceName_.getString(sourceNameSize); this->sourceName = sourceName_;
this->destName = destName_.getString(destNameSize); 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 { class PutRequest : public SerializeIF {
public: public:
EntityId destId;
/** /**
* Metadata only constructor. * Metadata only constructor.
* @param destId * @param destId
@ -34,15 +32,26 @@ class PutRequest : public SerializeIF {
Endianness streamEndianness) override; Endianness streamEndianness) override;
[[nodiscard]] size_t getSerializedSize() const override; [[nodiscard]] size_t getSerializedSize() const override;
void setSourceAndDestName(cfdp::StringLv& sourceName, cfdp::StringLv& destName); 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]] bool isMetadataOnly() const;
[[nodiscard]] const EntityId& getDestId() const;
void setDestId(EntityId id);
private: private:
EntityId destId;
uint8_t metadataOnly = true; uint8_t metadataOnly = true;
// Transaction parameters. Omitted if the put request is metadata only. // Transaction parameters. Omitted if the put request is metadata only.
const char* destName = nullptr; cfdp::StringLv sourceName;
uint64_t destNameSize = 0;
const char* sourceName = nullptr; cfdp::StringLv destName;
uint64_t sourceNameSize = 0; // const char* destName = nullptr;
// uint64_t destNameSize = 0;
// const char* sourceName = nullptr;
// uint64_t sourceNameSize = 0;
bool hasTransmissionMode = false; bool hasTransmissionMode = false;
uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED; uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
bool hasClosureRequested = false; bool hasClosureRequested = false;

View File

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

View File

@ -1,4 +1,4 @@
target_sources( target_sources(
${FSFW_TEST_TGT} ${FSFW_TEST_TGT}
PRIVATE testDistributor.cpp testDestHandler.cpp testReservedMsgParser.cpp 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); CHECK(packetLen > 0);
PutRequest putRequest; PutRequest putRequest;
size_t dummy = packetLen; 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));
} }