adaptions for reserved message handling

This commit is contained in:
Robin Müller 2023-08-16 13:10:21 +02:00
parent 8c11685240
commit 073cb4b3d5
Signed by: muellerr
GPG Key ID: FCE0B2BD2195142F
6 changed files with 19 additions and 17 deletions

View File

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

View File

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

View File

@ -16,7 +16,7 @@ bool MessageToUserTlv::isReservedCfdpMessage(uint8_t& messageType, const uint8_t
if (cfdp::Tlv::getLengthField() < 5) {
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];
if (msgDataStart != nullptr) {
*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;
}
rawData = *buffer;
uint8_t rawType = **buffer;
if (not checkType(rawType)) {
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; }
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);
[[nodiscard]] const uint8_t *getValue() const;
[[nodiscard]] const uint8_t *getRawData() const;
void setType(TlvType type);
[[nodiscard]] TlvType getType() const override;
[[nodiscard]] uint8_t getLengthField() const override;
@ -55,6 +56,7 @@ class Tlv : public TlvIF {
bool checkType(uint8_t rawType);
bool zeroLen = true;
const uint8_t *rawData = nullptr;
TlvType type = TlvType::INVALID_TLV;
SerialBufferAdapter<uint8_t> value;
};

View File

@ -40,10 +40,10 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
serLen = 0;
ReturnValue_t result = creator.serializeBe(buffer.data(), serLen, buffer.size());
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);
REQUIRE(parser.parse(buffer.data(), serLen) == OK);
REQUIRE(parser.parse(&msgToUser, 1) == OK);
CommandMessage msg;
CHECK(msgQueue.wasMessageSent());
CHECK(msgQueue.numberOfSentMessages() == 1);