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,14 +1,12 @@
#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) {}
size_t AckPduSerializer::getSerializedSize() const {
return FileDirectiveCreator::getWholePduSize();
}
size_t AckPduCreator::getSerializedSize() const { return FileDirectiveCreator::getWholePduSize(); }
ReturnValue_t AckPduSerializer::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
ReturnValue_t AckPduCreator::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

@ -1,11 +1,11 @@
#ifndef FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_
#define FSFW_SRC_FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_
#ifndef FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_
#define FSFW_CFDP_PDU_ACKPDUSERIALIZER_H_
#include "AckInfo.h"
#include "FileDirectiveCreator.h"
#include "FileDirectiveReader.h"
class AckPduSerializer : public FileDirectiveCreator {
class AckPduCreator : public FileDirectiveCreator {
public:
/**
* @brief Serializer to pack ACK PDUs
@ -16,9 +16,9 @@ class AckPduSerializer : public FileDirectiveCreator {
* @param transactionStatus
* @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,
Endianness streamEndianness) const override;
@ -27,4 +27,4 @@ class AckPduSerializer : public FileDirectiveCreator {
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) {}
ReturnValue_t AckPduDeserializer::parseData() {
ReturnValue_t AckPduReader::parseData() {
ReturnValue_t result = FileDirectiveReader::parseData();
if (result != returnvalue::OK) {
return result;
@ -18,14 +18,12 @@ ReturnValue_t AckPduDeserializer::parseData() {
return returnvalue::OK;
}
bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) {
uint8_t ackedDirective = static_cast<cfdp::FileDirectives>(firstByte >> 4);
if (ackedDirective != cfdp::FileDirectives::EOF_DIRECTIVE and
ackedDirective != cfdp::FileDirectives::FINISH) {
bool AckPduReader::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte) {
cfdp::FileDirectives directive;
if (not checkAckedDirectiveField(firstByte, directive)) {
return false;
}
this->info.setAckedDirective(static_cast<cfdp::FileDirectives>(ackedDirective));
this->info.setAckedDirective(directive);
uint8_t directiveSubtypeCode = firstByte & 0x0f;
if (directiveSubtypeCode != 0b0000 and directiveSubtypeCode != 0b0001) {
return false;
@ -35,3 +33,13 @@ bool AckPduDeserializer::checkAndSetCodes(uint8_t firstByte, uint8_t secondByte)
this->info.setTransactionStatus(static_cast<cfdp::AckTransactionStatus>(secondByte & 0x0f));
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 "fsfw/cfdp/pdu/FileDirectiveReader.h"
class AckPduDeserializer : public FileDirectiveReader {
class AckPduReader : public FileDirectiveReader {
public:
AckPduDeserializer(const uint8_t* pduBuf, size_t maxSize, AckInfo& info);
AckPduReader(const uint8_t* pduBuf, size_t maxSize, AckInfo& info);
/**
*
* @return
* - cfdp::INVALID_DIRECTIVE_FIELDS: Invalid fields
*/
ReturnValue_t parseData();
ReturnValue_t parseData() override;
static bool checkAckedDirectiveField(uint8_t firstPduDataByte,
cfdp::FileDirectives& ackedDirective);
private:
bool checkAndSetCodes(uint8_t rawAckedByte, uint8_t rawAckedConditionCode);

View File

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

View File

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