CFDP SOURCE handler #157

Merged
muellerr merged 107 commits from cfdp-source-handler into develop 2023-10-19 10:59:55 +02:00
2 changed files with 79 additions and 15 deletions
Showing only changes of commit 2585028e75 - Show all commits

View File

@ -6,6 +6,7 @@ cfdp::PutRequest::PutRequest(cfdp::EntityId destId, const uint8_t *msgsToUser,
size_t msgsToUserTotalSize, const uint8_t *fsRequests,
size_t fsRequestsSize)
: destId(std::move(destId)),
destIdWidth(destId.getWidth()),
metadataOnly(true),
msgsToUsersTotalSize(msgsToUserTotalSize),
msgsToUserStartPtr(msgsToUser),
@ -23,8 +24,10 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
if (*size + getSerializedSize() > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT;
}
**buffer = metadataOnly;
*size += 1;
result = SerializeAdapter::serialize(&metadataOnly, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
if (!metadataOnly) {
result = SerializeAdapter::serialize(&sourceNameSize, buffer, size, maxSize, streamEndianness);
if (result != OK) {
@ -40,15 +43,15 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
std::memcpy(*buffer, destName, destNameSize);
*buffer += destNameSize;
*size += destNameSize;
if (*size + 1 > maxSize) {
**buffer = transmissionMode;
*size += 1;
*buffer += 1;
result =
SerializeAdapter::serialize(&transmissionMode, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
if (*size + 1 > maxSize) {
**buffer = closureRequested;
*size += 1;
*buffer += 1;
result =
SerializeAdapter::serialize(&closureRequested, buffer, size, maxSize, streamEndianness);
if (result != OK) {
return result;
}
}
result =
@ -73,8 +76,63 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) {
ReturnValue_t result =
SerializeAdapter::deSerialize(&destIdWidth, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
result = destId.deSerialize(static_cast<cfdp::WidthInBytes>(destIdWidth), buffer, size,
streamEndianness);
if (result != OK) {
return result;
}
result = SerializeAdapter::deSerialize(&metadataOnly, buffer, size, streamEndianness);
if (result != OK) {
return result;
}
if (!metadataOnly) {
result = SerializeAdapter::deSerialize(&sourceNameSize, 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(&transmissionMode, 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 {
size_t baseSize = destId.getSerializedSize() + 1;
if (!metadataOnly) {

View File

@ -23,6 +23,11 @@ class PutRequest : public SerializeIF {
*/
PutRequest(EntityId destId, const uint8_t* msgsToUser, size_t msgsToUserTotalSize,
const uint8_t* fsRequests, size_t fsRequestsSize);
/**
* 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,
@ -31,14 +36,15 @@ class PutRequest : public SerializeIF {
[[nodiscard]] bool isMetadataOnly() const;
private:
bool metadataOnly = true;
uint8_t destIdWidth;
uint8_t metadataOnly = true;
// Transaction parameters. Omitted if the put request is metadata only.
char* destName = nullptr;
const char* destName = nullptr;
uint64_t destNameSize = 0;
char* sourceName = nullptr;
const char* sourceName = nullptr;
uint64_t sourceNameSize = 0;
TransmissionMode transmissionMode = TransmissionMode::UNACKNOWLEDGED;
bool closureRequested = false;
uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
uint8_t closureRequested = false;
// Metadata
size_t msgsToUsersTotalSize = 0;
const uint8_t* msgsToUserStartPtr = nullptr;