implemented basic PDU forwarding

This commit is contained in:
Robin Müller 2022-09-08 12:07:16 +02:00
parent ec1e07b466
commit b73754dfd6
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
6 changed files with 45 additions and 36 deletions

View File

@ -1,13 +1,11 @@
#include "AckPduSerializer.h" #include "AckPduCreator.h"
AckPduSerializer::AckPduSerializer(AckInfo &ackInfo, PduConfig &pduConf) AckPduCreator::AckPduCreator(AckInfo &ackInfo, PduConfig &pduConf)
: FileDirectiveCreator(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {} : FileDirectiveCreator(pduConf, cfdp::FileDirectives::ACK, 2), ackInfo(ackInfo) {}
size_t AckPduSerializer::getSerializedSize() const { size_t AckPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); }
return FileDirectiveCreator::getWholePduSize();
}
ReturnValue_t AckPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize, ReturnValue_t AckPduCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const { Endianness streamEndianness) const {
ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness); ReturnValue_t result = FileDirectiveCreator::serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {

View File

@ -1,11 +1,11 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ #ifndef FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ #define FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_
#include "AckInfo.h" #include "AckInfo.h"
#include "FileDirectiveCreator.h" #include "FileDirectiveCreator.h"
#include "FileDirectiveReader.h" #include "FileDirectiveReader.h"
class AckPduSerializer : public FileDirectiveCreator { class AckPduCreator : public FileDirectiveCreator {
public: public:
/** /**
* @brief Serializer to pack ACK PDUs * @brief Serializer to pack ACK PDUs
@ -16,9 +16,9 @@ class AckPduSerializer : public FileDirectiveCreator {
* @param transactionStatus * @param transactionStatus
* @param pduConf * @param pduConf
*/ */
AckPduSerializer(AckInfo& ackInfo, PduConfig& pduConf); AckPduCreator(AckInfo& ackInfo, PduConfig& pduConf);
size_t getSerializedSize() const override; [[nodiscard]] size_t getSerializedSize() const override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override; Endianness streamEndianness) const override;
@ -27,4 +27,4 @@ class AckPduSerializer : public FileDirectiveCreator {
AckInfo& ackInfo; AckInfo& ackInfo;
}; };
#endif /* FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ */ #endif /* FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_ */

View File

@ -1,9 +1,9 @@
#include "AckPduDeserializer.h" #include "AckPduReader.h"
AckPduDeserializer::AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info) AckPduReader::AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info)
: FileDirectiveReader(pduBuf, maxSize), info(info) {} : FileDirectiveReader(pduBuf, maxSize), info(info) {}
ReturnValue_t AckPduDeserializer::parseData() { ReturnValue_t AckPduReader::parseData() {
ReturnValue_t result = FileDirectiveReader::parseData(); ReturnValue_t result = FileDirectiveReader::parseData();
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
@ -18,14 +18,12 @@ ReturnValue_t AckPduDeserializer::parseData() {
return returnvalue::OK; return returnvalue::OK;
} }
bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) { bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) {
uint8_t ackedDirective = static_cast<cfdp::FileDirectives>(firstByte >> 4); cfdp::FileDirectives directive;
if (not checkAckedDirectiveField(firstByte, directive)) {
if (ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE and
ackedDirective != cfdp::FileDirectives::FINISH) {
return false; return false;
} }
this->info.setAckedDirective(static_cast<cfdp::FileDirectives>(ackedDirective)); this->info.setAckedDirective(directive);
uint8_t directiveSubtypeCode = firstByte & 0x0f; uint8_t directiveSubtypeCode = firstByte & 0x0f;
if (directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) { if (directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) {
return false; return false;
@ -35,3 +33,13 @@ bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte)
this->info.setTransactionStatus(static_cast<cfdp::AckTransactionStatus>(secondByte & 0x0f)); this->info.setTransactionStatus(static_cast<cfdp::AckTransactionStatus>(secondByte & 0x0f));
return true; return true;
} }
bool AckPduReader::checkAckedDirectiveField(uint8_t firstPduDataByte,
cfdp::FileDirectives& ackedDirective) {
uint8_t ackedDirectiveRaw = static_cast<cfdp::FileDirectives>(firstPduDataByte >> 4);
if (ackedDirectiveRaw != cfdp::FileDirectives::EOF_DIRECTIVE and
ackedDirectiveRaw != cfdp::FileDirectives::FINISH) {
return false;
}
ackedDirective = (static_cast<cfdp::FileDirectives>(ackedDirectiveRaw));
return true;
}

View File

@ -4,16 +4,19 @@
#include "AckInfo.h" #include "AckInfo.h"
#include "fsfw/cfdp/pdu/FileDirectiveReader.h" #include "fsfw/cfdp/pdu/FileDirectiveReader.h"
class AckPduDeserializer : public FileDirectiveReader { class AckPduReader : public FileDirectiveReader {
public: public:
AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info); AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info);
/** /**
* *
* @return * @return
* - cfdp::INVALID_DIRECTIVE_FIELDS: Invalid fields * - cfdp::INVALID_DIRECTIVE_FIELDS: Invalid fields
*/ */
ReturnValue_t parseData(); ReturnValue_t parseData() override;
static bool checkAckedDirectiveField(uint8_t firstPduDataByte,
cfdp::FileDirectives& ackedDirective);
private: private:
bool checkAndSetCodes(uint8_t rawAckedByte, uint8_t rawAckedConditionCode); bool checkAndSetCodes(uint8_t rawAckedByte, uint8_t rawAckedConditionCode);

View File

@ -6,8 +6,8 @@ target_sources(
FileDirectiveReader.cpp FileDirectiveReader.cpp
FileDirectiveCreator.cpp FileDirectiveCreator.cpp
AckInfo.cpp AckInfo.cpp
AckPduSerializer.cpp AckPduCreator.cpp
AckPduDeserializer.cpp AckPduReader.cpp
EofInfo.cpp EofInfo.cpp
EofPduCreator.cpp EofPduCreator.cpp
EofPduReader.cpp EofPduReader.cpp

View File

@ -1,8 +1,8 @@
#include <array> #include <array>
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp/pdu/AckPduDeserializer.h" #include "fsfw/cfdp/pdu/AckPduCreator.h"
#include "fsfw/cfdp/pdu/AckPduSerializer.h" #include "fsfw/cfdp/pdu/AckPduReader.h"
#include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/globalfunctions/arrayprinter.h"
TEST_CASE("ACK PDU", "[cfdp][pdu]") { TEST_CASE("ACK PDU", "[cfdp][pdu]") {
@ -18,7 +18,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") {
auto pduConf = PduConfig(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum); auto pduConf = PduConfig(sourceId, destId, TransmissionModes::ACKNOWLEDGED, seqNum);
AckInfo ackInfo(FileDirectives::EOF_DIRECTIVE, ConditionCode::NO_ERROR, AckInfo ackInfo(FileDirectives::EOF_DIRECTIVE, ConditionCode::NO_ERROR,
AckTransactionStatus::ACTIVE); AckTransactionStatus::ACTIVE);
auto ackSerializer = AckPduSerializer(ackInfo, pduConf); auto ackSerializer = AckPduCreator(ackInfo, pduConf);
result = ackSerializer.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); result = ackSerializer.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
@ -30,7 +30,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") {
ackInfo.setAckedDirective(FileDirectives::FINISH); ackInfo.setAckedDirective(FileDirectives::FINISH);
ackInfo.setAckedConditionCode(ConditionCode::FILESTORE_REJECTION); ackInfo.setAckedConditionCode(ConditionCode::FILESTORE_REJECTION);
ackInfo.setTransactionStatus(AckTransactionStatus::TERMINATED); ackInfo.setTransactionStatus(AckTransactionStatus::TERMINATED);
auto ackSerializer2 = AckPduSerializer(ackInfo, pduConf); auto ackSerializer2 = AckPduCreator(ackInfo, pduConf);
bufptr = buf.data(); bufptr = buf.data();
sz = 0; sz = 0;
result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK);
@ -44,7 +44,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") {
bufptr = buf.data(); bufptr = buf.data();
sz = 0; sz = 0;
ackInfo.setAckedDirective(FileDirectives::KEEP_ALIVE); ackInfo.setAckedDirective(FileDirectives::KEEP_ALIVE);
auto ackSerializer3 = AckPduSerializer(ackInfo, pduConf); auto ackSerializer3 = AckPduCreator(ackInfo, pduConf);
result = ackSerializer3.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); result = ackSerializer3.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK);
// Invalid file directive // Invalid file directive
REQUIRE(result != returnvalue::OK); REQUIRE(result != returnvalue::OK);
@ -57,7 +57,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") {
SECTION("Deserialize") { SECTION("Deserialize") {
AckInfo ackInfo2; AckInfo ackInfo2;
auto reader = AckPduDeserializer(buf.data(), sz, ackInfo2); auto reader = AckPduReader(buf.data(), sz, ackInfo2);
result = reader.parseData(); result = reader.parseData();
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::EOF_DIRECTIVE); REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::EOF_DIRECTIVE);
@ -67,13 +67,13 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") {
AckInfo newInfo = AckInfo(FileDirectives::FINISH, ConditionCode::FILESTORE_REJECTION, AckInfo newInfo = AckInfo(FileDirectives::FINISH, ConditionCode::FILESTORE_REJECTION,
AckTransactionStatus::TERMINATED); AckTransactionStatus::TERMINATED);
auto ackSerializer2 = AckPduSerializer(newInfo, pduConf); auto ackSerializer2 = AckPduCreator(newInfo, pduConf);
bufptr = buf.data(); bufptr = buf.data();
sz = 0; sz = 0;
result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK); result = ackSerializer2.serialize(&bufptr, &sz, maxsz, SerializeIF::Endianness::NETWORK);
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
auto reader2 = AckPduDeserializer(buf.data(), sz, ackInfo2); auto reader2 = AckPduReader(buf.data(), sz, ackInfo2);
result = reader2.parseData(); result = reader2.parseData();
REQUIRE(result == returnvalue::OK); REQUIRE(result == returnvalue::OK);
REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::FINISH); REQUIRE(ackInfo2.getAckedDirective() == FileDirectives::FINISH);
@ -93,7 +93,7 @@ TEST_CASE("ACK PDU", "[cfdp][pdu]") {
result = reader2.parseData(); result = reader2.parseData();
REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELD); REQUIRE(result == cfdp::INVALID_DIRECTIVE_FIELD);
buf[sz - 3] = cfdp::FileDirectives::ACK; buf[sz - 3] = cfdp::FileDirectives::ACK;
auto maxSizeTooSmall = AckPduDeserializer(buf.data(), sz - 2, ackInfo2); auto maxSizeTooSmall = AckPduReader(buf.data(), sz - 2, ackInfo2);
result = maxSizeTooSmall.parseData(); result = maxSizeTooSmall.parseData();
REQUIRE(result == SerializeIF::STREAM_TOO_SHORT); REQUIRE(result == SerializeIF::STREAM_TOO_SHORT);
} }