this parser should do the job

This commit is contained in:
Robin Müller 2023-07-24 16:38:11 +02:00
parent 52fc0958f7
commit 33df8e8cc5
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
6 changed files with 112 additions and 10 deletions

View File

@ -1,16 +1,84 @@
#include "MsgToUserParser.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"
cfdp::MsgsToUserParser::MsgsToUserParser(StorageManagerIF& ipcStore, uint32_t messageQueueDepth)
: ipcStore(ipcStore) {
messageQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth);
}
ReturnValue_t cfdp::MsgsToUserParser::parseMsgs(const uint8_t* msgsToUserPtr,
using namespace returnvalue;
cfdp::MsgsToUserParser::MsgsToUserParser(StorageManagerIF& ipcStore, MessageQueueIF& msgQueue,
MessageQueueId_t userDestination)
: msgQueue(msgQueue), ipcStore(ipcStore) {}
ReturnValue_t cfdp::MsgsToUserParser::parseMessages(const uint8_t* msgsToUserPtr,
size_t sizeOfMessages) {
ReturnValue_t result;
size_t currentIdx = 0;
const uint8_t* currentPtr = msgsToUserPtr;
MessageToUserTlv tlv;
size_t deserSize = sizeOfMessages;
PutRequest putRequest;
bool needToSendPutRequest = false;
while (currentIdx < sizeOfMessages) {
result = tlv.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
return 0;
uint8_t messageType = 0;
if (tlv.isReservedCfdpMessage(messageType)) {
if (messageType == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST)) {
cfdp::Lv entityIdLv;
result = entityIdLv.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);
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;
}
cfdp::StringLv sourceFileName;
result =
sourceFileName.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);
if (result != OK) {
return result;
}
cfdp::StringLv destFileName;
result =
destFileName.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK);
if (result != OK) {
return result;
}
putRequest.setSourceAndDestName(sourceFileName, destFileName);
needToSendPutRequest = true;
}
}
currentIdx += tlv.getSerializedSize();
}
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

@ -12,13 +12,15 @@ namespace cfdp {
*/
class MsgsToUserParser {
public:
MsgsToUserParser(StorageManagerIF& ipcStore, uint32_t queueDepth);
MsgsToUserParser(StorageManagerIF& ipcStore, MessageQueueIF& msgQueue,
MessageQueueId_t userDestination);
ReturnValue_t parseMsgs(const uint8_t* msgsToUserPtr, size_t sizeOfMessages);
ReturnValue_t parseMessages(const uint8_t* msgsToUserPtr, size_t sizeOfMessages);
private:
MessageQueueIF* messageQueue;
MessageQueueIF& msgQueue;
StorageManagerIF& ipcStore;
MessageQueueId_t userDestination;
};
} // namespace cfdp

View File

@ -43,11 +43,21 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
std::memcpy(*buffer, destName, destNameSize);
*buffer += destNameSize;
*size += destNameSize;
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) {
@ -106,10 +116,18 @@ ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size
destName = reinterpret_cast<const char *>(*buffer);
*buffer += destNameSize;
*size += destNameSize;
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;
@ -142,3 +160,9 @@ size_t cfdp::PutRequest::getSerializedSize() const {
fsRequestsTotalSize;
return baseSize;
}
void cfdp::PutRequest::setSourceAndDestName(cfdp::StringLv &sourceName_,
cfdp::StringLv &destName_) {
this->sourceName = sourceName_.getString(sourceNameSize);
this->destName = destName_.getString(sourceNameSize);
}

View File

@ -33,6 +33,7 @@ class PutRequest : public SerializeIF {
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]] bool isMetadataOnly() const;
private:
@ -43,7 +44,9 @@ class PutRequest : public SerializeIF {
uint64_t destNameSize = 0;
const char* sourceName = nullptr;
uint64_t sourceNameSize = 0;
bool hasTransmissionMode = false;
uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
bool hasClosureRequested = false;
uint8_t closureRequested = false;
// Metadata
size_t msgsToUsersTotalSize = 0;

View File

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

View File

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