Bump FSFW #31
@ -1,16 +1,84 @@
|
|||||||
#include "MsgToUserParser.h"
|
#include "MsgToUserParser.h"
|
||||||
|
|
||||||
|
#include "fsfw/cfdp/CfdpMessage.h"
|
||||||
|
#include "fsfw/cfdp/handler/PutRequest.h"
|
||||||
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
|
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
|
||||||
|
#include "fsfw/ipc/CommandMessage.h"
|
||||||
#include "fsfw/ipc/QueueFactory.h"
|
#include "fsfw/ipc/QueueFactory.h"
|
||||||
|
|
||||||
cfdp::MsgsToUserParser::MsgsToUserParser(StorageManagerIF& ipcStore, uint32_t messageQueueDepth)
|
using namespace returnvalue;
|
||||||
: ipcStore(ipcStore) {
|
|
||||||
messageQueue = QueueFactory::instance()->createMessageQueue(messageQueueDepth);
|
cfdp::MsgsToUserParser::MsgsToUserParser(StorageManagerIF& ipcStore, MessageQueueIF& msgQueue,
|
||||||
}
|
MessageQueueId_t userDestination)
|
||||||
ReturnValue_t cfdp::MsgsToUserParser::parseMsgs(const uint8_t* msgsToUserPtr,
|
: msgQueue(msgQueue), ipcStore(ipcStore) {}
|
||||||
|
|
||||||
|
ReturnValue_t cfdp::MsgsToUserParser::parseMessages(const uint8_t* msgsToUserPtr,
|
||||||
size_t sizeOfMessages) {
|
size_t sizeOfMessages) {
|
||||||
|
ReturnValue_t result;
|
||||||
size_t currentIdx = 0;
|
size_t currentIdx = 0;
|
||||||
|
const uint8_t* currentPtr = msgsToUserPtr;
|
||||||
|
MessageToUserTlv tlv;
|
||||||
|
size_t deserSize = sizeOfMessages;
|
||||||
|
PutRequest putRequest;
|
||||||
|
bool needToSendPutRequest = false;
|
||||||
while (currentIdx < sizeOfMessages) {
|
while (currentIdx < sizeOfMessages) {
|
||||||
|
result = tlv.deSerialize(¤tPtr, &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(¤tPtr, &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(¤tPtr, &deserSize, SerializeIF::Endianness::NETWORK);
|
||||||
|
if (result != OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
cfdp::StringLv destFileName;
|
||||||
|
result =
|
||||||
|
destFileName.deSerialize(¤tPtr, &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;
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,15 @@ namespace cfdp {
|
|||||||
*/
|
*/
|
||||||
class MsgsToUserParser {
|
class MsgsToUserParser {
|
||||||
public:
|
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:
|
private:
|
||||||
MessageQueueIF* messageQueue;
|
MessageQueueIF& msgQueue;
|
||||||
StorageManagerIF& ipcStore;
|
StorageManagerIF& ipcStore;
|
||||||
|
MessageQueueId_t userDestination;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cfdp
|
} // namespace cfdp
|
||||||
|
@ -43,11 +43,21 @@ ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t
|
|||||||
std::memcpy(*buffer, destName, destNameSize);
|
std::memcpy(*buffer, destName, destNameSize);
|
||||||
*buffer += destNameSize;
|
*buffer += destNameSize;
|
||||||
*size += destNameSize;
|
*size += destNameSize;
|
||||||
|
result =
|
||||||
|
SerializeAdapter::serialize(&hasTransmissionMode, buffer, size, maxSize, streamEndianness);
|
||||||
|
if (result != OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
result =
|
result =
|
||||||
SerializeAdapter::serialize(&transmissionMode, buffer, size, maxSize, streamEndianness);
|
SerializeAdapter::serialize(&transmissionMode, buffer, size, maxSize, streamEndianness);
|
||||||
if (result != OK) {
|
if (result != OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
result =
|
||||||
|
SerializeAdapter::serialize(&hasClosureRequested, buffer, size, maxSize, streamEndianness);
|
||||||
|
if (result != OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
result =
|
result =
|
||||||
SerializeAdapter::serialize(&closureRequested, buffer, size, maxSize, streamEndianness);
|
SerializeAdapter::serialize(&closureRequested, buffer, size, maxSize, streamEndianness);
|
||||||
if (result != OK) {
|
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);
|
destName = reinterpret_cast<const char *>(*buffer);
|
||||||
*buffer += destNameSize;
|
*buffer += destNameSize;
|
||||||
*size += destNameSize;
|
*size += destNameSize;
|
||||||
|
result = SerializeAdapter::deSerialize(&hasTransmissionMode, buffer, size, streamEndianness);
|
||||||
|
if (result != OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
result = SerializeAdapter::deSerialize(&transmissionMode, buffer, size, streamEndianness);
|
result = SerializeAdapter::deSerialize(&transmissionMode, buffer, size, streamEndianness);
|
||||||
if (result != OK) {
|
if (result != OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
result = SerializeAdapter::deSerialize(&hasClosureRequested, buffer, size, streamEndianness);
|
||||||
|
if (result != OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
result = SerializeAdapter::deSerialize(&closureRequested, buffer, size, streamEndianness);
|
result = SerializeAdapter::deSerialize(&closureRequested, buffer, size, streamEndianness);
|
||||||
if (result != OK) {
|
if (result != OK) {
|
||||||
return result;
|
return result;
|
||||||
@ -142,3 +160,9 @@ size_t cfdp::PutRequest::getSerializedSize() const {
|
|||||||
fsRequestsTotalSize;
|
fsRequestsTotalSize;
|
||||||
return baseSize;
|
return baseSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cfdp::PutRequest::setSourceAndDestName(cfdp::StringLv &sourceName_,
|
||||||
|
cfdp::StringLv &destName_) {
|
||||||
|
this->sourceName = sourceName_.getString(sourceNameSize);
|
||||||
|
this->destName = destName_.getString(sourceNameSize);
|
||||||
|
}
|
||||||
|
@ -33,6 +33,7 @@ class PutRequest : 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;
|
||||||
[[nodiscard]] size_t getSerializedSize() const override;
|
[[nodiscard]] size_t getSerializedSize() const override;
|
||||||
|
void setSourceAndDestName(cfdp::StringLv& sourceName, cfdp::StringLv& destName);
|
||||||
[[nodiscard]] bool isMetadataOnly() const;
|
[[nodiscard]] bool isMetadataOnly() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -43,7 +44,9 @@ class PutRequest : public SerializeIF {
|
|||||||
uint64_t destNameSize = 0;
|
uint64_t destNameSize = 0;
|
||||||
const char* sourceName = nullptr;
|
const char* sourceName = nullptr;
|
||||||
uint64_t sourceNameSize = 0;
|
uint64_t sourceNameSize = 0;
|
||||||
|
bool hasTransmissionMode = false;
|
||||||
uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
|
uint8_t transmissionMode = TransmissionMode::UNACKNOWLEDGED;
|
||||||
|
bool hasClosureRequested = false;
|
||||||
uint8_t closureRequested = false;
|
uint8_t closureRequested = false;
|
||||||
// Metadata
|
// Metadata
|
||||||
size_t msgsToUsersTotalSize = 0;
|
size_t msgsToUsersTotalSize = 0;
|
||||||
|
@ -7,3 +7,7 @@ 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::getString(size_t& fileSize) const {
|
||||||
|
return reinterpret_cast<const char*>(getValue(&fileSize));
|
||||||
|
}
|
||||||
|
@ -13,6 +13,7 @@ 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* getString(size_t& fileSize) 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;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user