more bugfixes
This commit is contained in:
parent
e8bf8b9575
commit
bb186fc965
@ -75,7 +75,7 @@ struct EntityId : public VarLenField {
|
||||
explicit EntityId(UnsignedByteField<T> byteField) : VarLenField(byteField) {}
|
||||
EntityId(cfdp::WidthInBytes width, size_t entityId) : VarLenField(width, entityId) {}
|
||||
|
||||
ReturnValue_t serializeAsLv(uint8_t **buffer, size_t *size, size_t maxSize) {
|
||||
ReturnValue_t serializeAsLv(uint8_t **buffer, size_t *size, size_t maxSize) const {
|
||||
if (buffer == nullptr or size == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
@ -87,6 +87,19 @@ struct EntityId : public VarLenField {
|
||||
*size += 1;
|
||||
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
|
||||
}
|
||||
|
||||
ReturnValue_t deSerializeFromLv(const uint8_t **buffer, size_t *deserLen) {
|
||||
if (buffer == nullptr or deserLen == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
if (*deserLen < 2) {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
auto width = static_cast<WidthInBytes>(**buffer);
|
||||
*buffer += 1;
|
||||
*deserLen -= 1;
|
||||
return VarLenField::deSerialize(width, buffer, deserLen, SerializeIF::Endianness::NETWORK);
|
||||
}
|
||||
};
|
||||
|
||||
struct TransactionSeqNum : public VarLenField {
|
||||
|
@ -6,7 +6,6 @@ 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),
|
||||
@ -17,13 +16,13 @@ cfdp::PutRequest::PutRequest(cfdp::EntityId destId, const uint8_t *msgsToUser,
|
||||
|
||||
ReturnValue_t cfdp::PutRequest::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
|
||||
SerializeIF::Endianness streamEndianness) const {
|
||||
if(buffer == nullptr or size == nullptr) {
|
||||
if (buffer == nullptr or size == nullptr) {
|
||||
return FAILED;
|
||||
}
|
||||
if (*size + getSerializedSize() > maxSize) {
|
||||
return SerializeIF::BUFFER_TOO_SHORT;
|
||||
}
|
||||
ReturnValue_t result = destId.serialize(buffer, size, maxSize, streamEndianness);
|
||||
ReturnValue_t result = destId.serializeAsLv(buffer, size, maxSize);
|
||||
if (result != OK) {
|
||||
return result;
|
||||
}
|
||||
@ -89,14 +88,10 @@ 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;
|
||||
if (buffer == nullptr or size == nullptr) {
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
result = destId.deSerialize(static_cast<cfdp::WidthInBytes>(destIdWidth), buffer, size,
|
||||
streamEndianness);
|
||||
ReturnValue_t result = destId.deSerializeFromLv(buffer, size);
|
||||
if (result != OK) {
|
||||
return result;
|
||||
}
|
||||
@ -155,7 +150,8 @@ ReturnValue_t cfdp::PutRequest::deSerialize(const uint8_t **buffer, size_t *size
|
||||
}
|
||||
|
||||
size_t cfdp::PutRequest::getSerializedSize() const {
|
||||
size_t baseSize = 1 + destId.getSerializedSize();
|
||||
// Entity ID LV (1 leading size byte) and the metadata only flag.
|
||||
size_t baseSize = 1 + destId.getSerializedSize() + 1;
|
||||
if (!metadataOnly) {
|
||||
baseSize += sizeof(sourceNameSize) + sourceNameSize + sizeof(destNameSize) + destNameSize + 2;
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ class PutRequest : public SerializeIF {
|
||||
[[nodiscard]] bool isMetadataOnly() const;
|
||||
|
||||
private:
|
||||
uint8_t destIdWidth = 0;
|
||||
uint8_t metadataOnly = true;
|
||||
// Transaction parameters. Omitted if the put request is metadata only.
|
||||
const char* destName = nullptr;
|
||||
|
@ -1,12 +1,14 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/cfdp/CfdpMessage.h"
|
||||
#include "fsfw/cfdp/VarLenFields.h"
|
||||
#include "fsfw/cfdp/handler/PutRequest.h"
|
||||
#include "fsfw/cfdp/handler/ReservedMessageParser.h"
|
||||
#include "fsfw/cfdp/tlv/Lv.h"
|
||||
#include "fsfw/cfdp/tlv/ReservedMessageCreator.h"
|
||||
#include "fsfw/cfdp/CfdpMessage.h"
|
||||
#include "fsfw/cfdp/tlv/StringLv.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
#include "fsfw/serialize.h"
|
||||
#include "mocks/MessageQueueMock.h"
|
||||
#include "mocks/StorageManagerMock.h"
|
||||
|
||||
@ -41,7 +43,7 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
|
||||
arrayprinter::print(buffer.data(), serLen);
|
||||
|
||||
ReservedMessageParser parser(ipcStore, msgQueue, destQueueId);
|
||||
CHECK(parser.parse(buffer.data(), serLen) == OK);
|
||||
REQUIRE(parser.parse(buffer.data(), serLen) == OK);
|
||||
CommandMessage msg;
|
||||
CHECK(msgQueue.wasMessageSent());
|
||||
CHECK(msgQueue.numberOfSentMessages() == 1);
|
||||
@ -49,6 +51,9 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
|
||||
store_address_t storeId = CfdpMessage::getStoreId(&msg);
|
||||
const uint8_t* data;
|
||||
size_t packetLen;
|
||||
ipcStore.getData(storeId, &data, &packetLen);
|
||||
CHECK(ipcStore.getData(storeId, &data, &packetLen) == OK);
|
||||
CHECK(packetLen > 0);
|
||||
PutRequest putRequest;
|
||||
size_t dummy = packetLen;
|
||||
CHECK(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user