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 19 additions and 17 deletions
Showing only changes of commit 073cb4b3d5 - Show all commits

View File

@ -13,24 +13,21 @@ cfdp::ReservedMessageParser::ReservedMessageParser(StorageManagerIF& ipcStore,
MessageQueueId_t userDestination) MessageQueueId_t userDestination)
: msgQueue(msgQueue), ipcStore(ipcStore), userDestination(userDestination) {} : msgQueue(msgQueue), ipcStore(ipcStore), userDestination(userDestination) {}
ReturnValue_t cfdp::ReservedMessageParser::parse(const uint8_t* msgsToUserPtr, ReturnValue_t cfdp::ReservedMessageParser::parse(const MessageToUserTlv* msgsToUserArray,
size_t sizeOfMessages) { size_t numMsgToUser) {
ReturnValue_t result; ReturnValue_t result;
size_t currentIdx = 0;
const uint8_t* currentPtr = msgsToUserPtr;
MessageToUserTlv tlv;
size_t deserSize = sizeOfMessages;
cfdp::StringLv sourceFileName; cfdp::StringLv sourceFileName;
cfdp::StringLv destFileName; cfdp::StringLv destFileName;
PutRequest putRequest; PutRequest putRequest;
const uint8_t* currentPtr = nullptr;
size_t deserSize = 0;
bool needToSendPutRequest = false; bool needToSendPutRequest = false;
while (currentIdx < sizeOfMessages) { for (size_t idx = 0; idx < numMsgToUser; idx++) {
result = tlv.deSerialize(&currentPtr, &deserSize, SerializeIF::Endianness::NETWORK); if (&msgsToUserArray[idx] == nullptr) {
if (result != returnvalue::OK) { continue;
return result;
} }
uint8_t messageType = 0; uint8_t messageType = 0;
if (tlv.isReservedCfdpMessage(messageType, &currentPtr, deserSize)) { if (msgsToUserArray[idx].isReservedCfdpMessage(messageType, &currentPtr, deserSize)) {
if (messageType == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST)) { if (messageType == static_cast<uint8_t>(ProxyOpMessageType::PUT_REQUEST)) {
EntityId entityIdLv; EntityId entityIdLv;
entityIdLv.deSerializeFromLv(&currentPtr, &deserSize); entityIdLv.deSerializeFromLv(&currentPtr, &deserSize);
@ -52,7 +49,6 @@ ReturnValue_t cfdp::ReservedMessageParser::parse(const uint8_t* msgsToUserPtr,
needToSendPutRequest = true; needToSendPutRequest = true;
} }
} }
currentIdx += tlv.getSerializedSize();
} }
if (needToSendPutRequest) { if (needToSendPutRequest) {
store_address_t storeId; store_address_t storeId;

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
#include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/storagemanager/StorageManagerIF.h"
@ -15,7 +16,7 @@ class ReservedMessageParser {
ReservedMessageParser(StorageManagerIF& ipcStore, MessageQueueIF& msgQueue, ReservedMessageParser(StorageManagerIF& ipcStore, MessageQueueIF& msgQueue,
MessageQueueId_t userDestination); MessageQueueId_t userDestination);
ReturnValue_t parse(const uint8_t* msgsToUserPtr, size_t sizeOfMessages); ReturnValue_t parse(const MessageToUserTlv* msgsToUserArray, size_t numMsgsToUser);
private: private:
MessageQueueIF& msgQueue; MessageQueueIF& msgQueue;

View File

@ -16,7 +16,7 @@ bool MessageToUserTlv::isReservedCfdpMessage(uint8_t& messageType, const uint8_t
if (cfdp::Tlv::getLengthField() < 5) { if (cfdp::Tlv::getLengthField() < 5) {
return false; return false;
} }
if (std::strcmp(reinterpret_cast<const char*>(getValue()), "cfdp") == 0) { if (std::strncmp(reinterpret_cast<const char*>(getValue()), "cfdp", 4) == 0) {
messageType = getValue()[4]; messageType = getValue()[4];
if (msgDataStart != nullptr) { if (msgDataStart != nullptr) {
*msgDataStart = getValue() + 5; *msgDataStart = getValue() + 5;

View File

@ -54,6 +54,7 @@ ReturnValue_t cfdp::Tlv::deSerialize(const uint8_t **buffer, size_t *size,
return STREAM_TOO_SHORT; return STREAM_TOO_SHORT;
} }
rawData = *buffer;
uint8_t rawType = **buffer; uint8_t rawType = **buffer;
if (not checkType(rawType)) { if (not checkType(rawType)) {
return INVALID_TLV_TYPE; return INVALID_TLV_TYPE;
@ -102,3 +103,5 @@ void cfdp::Tlv::setValue(uint8_t *value, size_t len) {
uint8_t cfdp::Tlv::getLengthField() const { return this->value.getSerializedSize() - 1; } uint8_t cfdp::Tlv::getLengthField() const { return this->value.getSerializedSize() - 1; }
void cfdp::Tlv::setType(TlvType type) { this->type = type; } void cfdp::Tlv::setType(TlvType type) { this->type = type; }
const uint8_t *cfdp::Tlv::getRawData() const { return rawData; }

View File

@ -47,6 +47,7 @@ class Tlv : public TlvIF {
void setValue(uint8_t *value, size_t len); void setValue(uint8_t *value, size_t len);
[[nodiscard]] const uint8_t *getValue() const; [[nodiscard]] const uint8_t *getValue() const;
[[nodiscard]] const uint8_t *getRawData() const;
void setType(TlvType type); void setType(TlvType type);
[[nodiscard]] TlvType getType() const override; [[nodiscard]] TlvType getType() const override;
[[nodiscard]] uint8_t getLengthField() const override; [[nodiscard]] uint8_t getLengthField() const override;
@ -55,6 +56,7 @@ class Tlv : public TlvIF {
bool checkType(uint8_t rawType); bool checkType(uint8_t rawType);
bool zeroLen = true; bool zeroLen = true;
const uint8_t *rawData = nullptr;
TlvType type = TlvType::INVALID_TLV; TlvType type = TlvType::INVALID_TLV;
SerialBufferAdapter<uint8_t> value; SerialBufferAdapter<uint8_t> value;
}; };

View File

@ -40,10 +40,10 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
serLen = 0; serLen = 0;
ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size()); ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size());
CHECK(result == returnvalue::OK); CHECK(result == returnvalue::OK);
arrayprinter::print(buffer.data(), serLen); MessageToUserTlv msgToUser;
CHECK(msgToUser.deSerializeBe(buffer.data(), serLen, buffer.size()) == OK);
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId); ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
REQUIRE(parser.parse(buffer.data(), serLen) == OK); REQUIRE(parser.parse(&msgToUser, 1) == OK);
CommandMessage msg; CommandMessage msg;
CHECK(msgQueue.wasMessageSent()); CHECK(msgQueue.wasMessageSent());
CHECK(msgQueue.numberOfSentMessages() == 1); CHECK(msgQueue.numberOfSentMessages() == 1);