impl finish PDU sending

This commit is contained in:
Robin Müller 2022-09-05 11:03:25 +02:00
parent b984128de5
commit 3dfc882226
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
9 changed files with 83 additions and 54 deletions

View File

@ -7,8 +7,10 @@
#include "fsfw/FSFW.h"
#include "fsfw/cfdp/pdu/EofPduReader.h"
#include "fsfw/cfdp/pdu/FileDataReader.h"
#include "fsfw/cfdp/pdu/FinishedPduCreator.h"
#include "fsfw/cfdp/pdu/HeaderReader.h"
#include "fsfw/objectmanager.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
using namespace returnvalue;
@ -379,6 +381,7 @@ ReturnValue_t cfdp::DestHandler::checksumVerification() {
}
return OK;
}
ReturnValue_t cfdp::DestHandler::noticeOfCompletion() {
if (dp.cfg.indicCfg.transactionFinishedIndicRequired) {
TransactionFinishedParams params(tp.transactionId, tp.conditionCode, tp.deliveryCode,
@ -388,4 +391,28 @@ ReturnValue_t cfdp::DestHandler::noticeOfCompletion() {
return OK;
}
ReturnValue_t cfdp::DestHandler::sendFinishedPdu() { return 0; }
ReturnValue_t cfdp::DestHandler::sendFinishedPdu() {
FinishedInfo info(tp.conditionCode, tp.deliveryCode, tp.deliveryStatus);
FinishPduCreator finishedPdu(tp.pduConf, info);
store_address_t storeId;
uint8_t* dataPtr = nullptr;
ReturnValue_t result =
fp.tcStore->getFreeElement(&storeId, finishedPdu.getSerializedSize(), &dataPtr);
if (result != OK) {
// TODO: Error handling and event, this is a non CFDP specific error (most likely store is full)
return result;
}
size_t serLen = 0;
result = finishedPdu.serialize(dataPtr, serLen, finishedPdu.getSerializedSize());
if (result != OK) {
// TODO: Error printout, this really should not happen
return result;
}
TmTcMessage msg(storeId);
result = fp.msgQueue.sendMessage(fp.packetDest.getReportReceptionQueue(), &msg);
if (result != OK) {
// TODO: Error handling and event, this is a non CFDP specific error (most likely store is full)
return result;
}
return OK;
}

View File

@ -15,8 +15,8 @@ target_sources(
NakPduSerializer.cpp
NakPduDeserializer.cpp
FinishedInfo.cpp
FinishedPduSerializer.cpp
FinishedPduDeserializer.cpp
FinishedPduCreator.cpp
FinishedPduReader.cpp
MetadataInfo.cpp
MetadataPduCreator.cpp
MetadataPduReader.cpp

View File

@ -16,6 +16,10 @@ class FileDirectiveCreator : public HeaderCreator {
*/
[[nodiscard]] size_t getSerializedSize() const override;
[[nodiscard]] ReturnValue_t serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const {
return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK);
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;

View File

@ -1,20 +1,18 @@
#include "FinishedPduSerializer.h"
#include "FinishedPduCreator.h"
FinishPduSerializer::FinishPduSerializer(PduConfig &conf, FinishedInfo &finishInfo)
FinishPduCreator::FinishPduCreator(PduConfig &conf, FinishedInfo &finishInfo)
: FileDirectiveCreator(conf, cfdp::FileDirectives::FINISH, 0), finishInfo(finishInfo) {
updateDirectiveFieldLen();
}
size_t FinishPduSerializer::getSerializedSize() const {
return FinishPduSerializer::getWholePduSize();
}
size_t FinishPduCreator::getSerializedSize() const { return FinishPduCreator::getWholePduSize(); }
void FinishPduSerializer::updateDirectiveFieldLen() {
void FinishPduCreator::updateDirectiveFieldLen() {
setDirectiveDataFieldLen(finishInfo.getSerializedSize());
}
ReturnValue_t FinishPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
ReturnValue_t FinishPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;

View File

@ -0,0 +1,24 @@
#ifndef FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_
#define FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_
#include "FinishedInfo.h"
#include "fsfw/cfdp/pdu/FileDataCreator.h"
#include "fsfw/cfdp/pdu/FileDirectiveCreator.h"
class FinishPduCreator : public FileDirectiveCreator {
public:
FinishPduCreator(PduConfig& pduConf, FinishedInfo& finishInfo);
void updateDirectiveFieldLen();
[[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
using FileDirectiveCreator::serialize;
private:
FinishedInfo& finishInfo;
};
#endif /* FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ */

View File

@ -1,10 +1,9 @@
#include "FinishedPduDeserializer.h"
#include "FinishedPduReader.h"
FinishPduDeserializer::FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize,
FinishedInfo& info)
FinishPduReader::FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info)
: FileDirectiveReader(pduBuf, maxSize), finishedInfo(info) {}
ReturnValue_t FinishPduDeserializer::parseData() {
ReturnValue_t FinishPduReader::parseData() {
ReturnValue_t result = FileDirectiveReader::parseData();
if (result != returnvalue::OK) {
return result;
@ -29,10 +28,10 @@ ReturnValue_t FinishPduDeserializer::parseData() {
return result;
}
FinishedInfo& FinishPduDeserializer::getInfo() { return finishedInfo; }
FinishedInfo& FinishPduReader::getInfo() { return finishedInfo; }
ReturnValue_t FinishPduDeserializer::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf,
cfdp::ConditionCode conditionCode) {
ReturnValue_t FinishPduReader::parseTlvs(size_t remLen, size_t currentIdx, const uint8_t* buf,
cfdp::ConditionCode conditionCode) {
ReturnValue_t result = returnvalue::OK;
size_t fsResponsesIdx = 0;
auto endianness = getEndianness();

View File

@ -1,12 +1,12 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_
#ifndef FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_
#define FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_
#include "fsfw/cfdp/pdu/FileDirectiveReader.h"
#include "fsfw/cfdp/pdu/FinishedInfo.h"
class FinishPduDeserializer : public FileDirectiveReader {
class FinishPduReader : public FileDirectiveReader {
public:
FinishPduDeserializer(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info);
FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info);
ReturnValue_t parseData() override;
@ -19,4 +19,4 @@ class FinishPduDeserializer : public FileDirectiveReader {
cfdp::ConditionCode conditionCode);
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */
#endif /* FSFW_CFDP_PDU_FINISHEDPDUDESERIALIZER_H_ */

View File

@ -1,23 +0,0 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_
#include "FinishedInfo.h"
#include "fsfw/cfdp/pdu/FileDataCreator.h"
#include "fsfw/cfdp/pdu/FileDirectiveCreator.h"
class FinishPduSerializer : public FileDirectiveCreator {
public:
FinishPduSerializer(PduConfig& pduConf, FinishedInfo& finishInfo);
void updateDirectiveFieldLen();
size_t getSerializedSize() const override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
private:
FinishedInfo& finishInfo;
};
#endif /* FSFW_SRC_FSFW_CFDP_PDU_FINISHEDPDUSERIALIZER_H_ */

View File

@ -1,8 +1,8 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp/pdu/FinishedPduDeserializer.h"
#include "fsfw/cfdp/pdu/FinishedPduSerializer.h"
#include "fsfw/cfdp/pdu/FinishedPduCreator.h"
#include "fsfw/cfdp/pdu/FinishedPduReader.h"
#include "fsfw/globalfunctions/arrayprinter.h"
TEST_CASE("Finished PDU", "[cfdp][pdu]") {
@ -22,7 +22,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") {
cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY);
SECTION("Serialize") {
FinishPduSerializer serializer(pduConf, info);
FinishPduCreator serializer(pduConf, info);
result = serializer.serialize(&buffer, &sz, fnBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
REQUIRE(serializer.getSerializedSize() == 12);
@ -87,10 +87,10 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") {
SECTION("Deserialize") {
FinishedInfo emptyInfo;
FinishPduSerializer serializer(pduConf, info);
FinishPduCreator serializer(pduConf, info);
result = serializer.serialize(&buffer, &sz, fnBuffer.size(), SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK);
FinishPduDeserializer deserializer(fnBuffer.data(), fnBuffer.size(), emptyInfo);
FinishPduReader deserializer(fnBuffer.data(), fnBuffer.size(), emptyInfo);
result = deserializer.parseData();
REQUIRE(result == returnvalue::OK);
REQUIRE(emptyInfo.getFileStatus() == cfdp::FileDeliveryStatus::DISCARDED_DELIBERATELY);
@ -114,7 +114,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") {
FilestoreResponseTlv emptyResponse(firstNameLv, nullptr);
responsePtr = &emptyResponse;
emptyInfo.setFilestoreResponsesArray(&responsePtr, nullptr, &len);
FinishPduDeserializer deserializer2(fnBuffer.data(), fnBuffer.size(), emptyInfo);
FinishPduReader deserializer2(fnBuffer.data(), fnBuffer.size(), emptyInfo);
result = deserializer2.parseData();
REQUIRE(result == returnvalue::OK);
REQUIRE(emptyInfo.getFsResponsesLen() == 1);
@ -152,7 +152,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") {
response.setFilestoreMessage(&emptyFsMsg);
emptyInfo.setFilestoreResponsesArray(responses.data(), &len, &len);
response2.setFilestoreMessage(&emptyFsMsg);
FinishPduDeserializer deserializer3(fnBuffer.data(), fnBuffer.size(), emptyInfo);
FinishPduReader deserializer3(fnBuffer.data(), fnBuffer.size(), emptyInfo);
result = deserializer3.parseData();
REQUIRE(result == returnvalue::OK);
auto& infoRef = deserializer3.getInfo();
@ -181,7 +181,7 @@ TEST_CASE("Finished PDU", "[cfdp][pdu]") {
REQUIRE(result == cfdp::INVALID_TLV_TYPE);
for (size_t maxSz = 0; maxSz < 45; maxSz++) {
FinishPduDeserializer faultyDeser(fnBuffer.data(), maxSz, emptyInfo);
FinishPduReader faultyDeser(fnBuffer.data(), maxSz, emptyInfo);
result = faultyDeser.parseData();
REQUIRE(result != returnvalue::OK);
}