implemented metadata handler
This commit is contained in:
parent
9441b4a70e
commit
b1bd631322
@ -74,6 +74,7 @@ struct TransactionSeqNum : public VarLenField {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct TransactionId {
|
struct TransactionId {
|
||||||
|
TransactionId() = default;
|
||||||
TransactionId(EntityId entityId, TransactionSeqNum seqNum)
|
TransactionId(EntityId entityId, TransactionSeqNum seqNum)
|
||||||
: entityId(std::move(entityId)), seqNum(std::move(seqNum)) {}
|
: entityId(std::move(entityId)), seqNum(std::move(seqNum)) {}
|
||||||
|
|
||||||
|
@ -3,14 +3,19 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "fsfw/cfdp/pdu/HeaderReader.h"
|
#include "fsfw/cfdp/pdu/HeaderReader.h"
|
||||||
#include "fsfw/cfdp/pdu/MetadataPduReader.h"
|
|
||||||
#include "fsfw/objectmanager.h"
|
#include "fsfw/objectmanager.h"
|
||||||
#include "fsfw/serviceinterface.h"
|
#include "fsfw/serviceinterface.h"
|
||||||
|
|
||||||
using namespace returnvalue;
|
using namespace returnvalue;
|
||||||
|
|
||||||
cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams)
|
cfdp::DestHandler::DestHandler(DestHandlerParams params, FsfwParams fsfwParams)
|
||||||
: dp(std::move(params)), fp(fsfwParams), tlvVec(params.maxTlvsInOnePdu) {}
|
: tlvVec(params.maxTlvsInOnePdu),
|
||||||
|
userTlvVec(params.maxTlvsInOnePdu),
|
||||||
|
dp(std::move(params)),
|
||||||
|
fp(fsfwParams),
|
||||||
|
tp(params.maxFilenameLen) {
|
||||||
|
tp.pduConf.direction = cfdp::Direction::TOWARDS_SENDER;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t cfdp::DestHandler::performStateMachine() {
|
ReturnValue_t cfdp::DestHandler::performStateMachine() {
|
||||||
switch (step) {
|
switch (step) {
|
||||||
@ -73,10 +78,9 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
|
|||||||
// TODO: This is not a CFDP error. Event and/or warning?
|
// TODO: This is not a CFDP error. Event and/or warning?
|
||||||
return constAccessorPair.first;
|
return constAccessorPair.first;
|
||||||
}
|
}
|
||||||
cfdp::FileSize fileSize;
|
|
||||||
cfdp::StringLv sourceFileName;
|
cfdp::StringLv sourceFileName;
|
||||||
cfdp::StringLv destFileName;
|
cfdp::StringLv destFileName;
|
||||||
MetadataInfo metadataInfo(fileSize, sourceFileName, destFileName);
|
MetadataInfo metadataInfo(tp.fileSize, sourceFileName, destFileName);
|
||||||
cfdp::Tlv* tlvArrayAsPtr = tlvVec.data();
|
cfdp::Tlv* tlvArrayAsPtr = tlvVec.data();
|
||||||
metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size());
|
metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size());
|
||||||
MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(),
|
MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(),
|
||||||
@ -89,7 +93,7 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
|
|||||||
return handleMetadataParseError(constAccessorPair.second.data(),
|
return handleMetadataParseError(constAccessorPair.second.data(),
|
||||||
constAccessorPair.second.size());
|
constAccessorPair.second.size());
|
||||||
}
|
}
|
||||||
return result;
|
return startTransaction(reader, metadataInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) {
|
ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData, size_t maxSize) {
|
||||||
@ -126,3 +130,44 @@ ReturnValue_t cfdp::DestHandler::handleMetadataParseError(const uint8_t* rawData
|
|||||||
// TODO: Appropriate returnvalue?
|
// TODO: Appropriate returnvalue?
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, MetadataInfo& info) {
|
||||||
|
if (cfdpState != CfdpStates::IDLE) {
|
||||||
|
// According to standard, discard metadata PDU if we are busy
|
||||||
|
return returnvalue::OK;
|
||||||
|
}
|
||||||
|
step = TransactionStep::TRANSACTION_START;
|
||||||
|
if (reader.getTransmissionMode() == TransmissionModes::UNACKNOWLEDGED) {
|
||||||
|
cfdpState = CfdpStates::BUSY_CLASS_1_NACKED;
|
||||||
|
} else if (reader.getTransmissionMode() == TransmissionModes::ACKNOWLEDGED) {
|
||||||
|
cfdpState = CfdpStates::BUSY_CLASS_2_ACKED;
|
||||||
|
}
|
||||||
|
tp.checksumType = info.getChecksumType();
|
||||||
|
tp.closureRequested = info.isClosureRequested();
|
||||||
|
size_t sourceNameSize = 0;
|
||||||
|
const uint8_t* sourceNamePtr = info.getSourceFileName().getValue(&sourceNameSize);
|
||||||
|
if (sourceNameSize > tp.sourceName.size()) {
|
||||||
|
// TODO: Warning, event etc.
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
std::memcpy(tp.sourceName.data(), sourceNamePtr, sourceNameSize);
|
||||||
|
tp.sourceName[sourceNameSize] = '\0';
|
||||||
|
size_t destNameSize = 0;
|
||||||
|
const uint8_t* destNamePtr = info.getDestFileName().getValue(&destNameSize);
|
||||||
|
if (destNameSize > tp.destName.size()) {
|
||||||
|
// TODO: Warning, event etc.
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
std::memcpy(tp.destName.data(), destNamePtr, destNameSize);
|
||||||
|
tp.destName[destNameSize] = '\0';
|
||||||
|
reader.fillConfig(tp.pduConf);
|
||||||
|
tp.pduConf.direction = Direction::TOWARDS_SENDER;
|
||||||
|
tp.transactionId.entityId = tp.pduConf.sourceId;
|
||||||
|
tp.transactionId.seqNum = tp.pduConf.seqNum;
|
||||||
|
if (not dp.remoteCfgTable.getRemoteCfg(tp.pduConf.destId, &tp.remoteCfg)) {
|
||||||
|
// TODO: Warning, event etc.
|
||||||
|
return FAILED;
|
||||||
|
}
|
||||||
|
step = TransactionStep::RECEIVING_FILE_DATA_PDUS;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
#include "RemoteConfigTableIF.h"
|
#include "RemoteConfigTableIF.h"
|
||||||
#include "UserBase.h"
|
#include "UserBase.h"
|
||||||
|
#include "defs.h"
|
||||||
#include "fsfw/cfdp/handler/mib.h"
|
#include "fsfw/cfdp/handler/mib.h"
|
||||||
|
#include "fsfw/cfdp/pdu/MetadataPduReader.h"
|
||||||
#include "fsfw/cfdp/pdu/PduConfig.h"
|
#include "fsfw/cfdp/pdu/PduConfig.h"
|
||||||
#include "fsfw/container/DynamicFIFO.h"
|
#include "fsfw/container/DynamicFIFO.h"
|
||||||
#include "fsfw/storagemanager/StorageManagerIF.h"
|
#include "fsfw/storagemanager/StorageManagerIF.h"
|
||||||
@ -28,7 +30,7 @@ struct PacketInfo {
|
|||||||
|
|
||||||
struct DestHandlerParams {
|
struct DestHandlerParams {
|
||||||
DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable,
|
DestHandlerParams(LocalEntityCfg cfg, UserBase& user, RemoteConfigTableIF& remoteCfgTable,
|
||||||
etl::ilist<PacketInfo>& packetList, uint8_t maxTlvsInOnePdu)
|
etl::ilist<PacketInfo>& packetList)
|
||||||
: cfg(std::move(cfg)),
|
: cfg(std::move(cfg)),
|
||||||
user(user),
|
user(user),
|
||||||
remoteCfgTable(remoteCfgTable),
|
remoteCfgTable(remoteCfgTable),
|
||||||
@ -39,7 +41,8 @@ struct DestHandlerParams {
|
|||||||
RemoteConfigTableIF& remoteCfgTable;
|
RemoteConfigTableIF& remoteCfgTable;
|
||||||
|
|
||||||
etl::ilist<PacketInfo>& packetListRef;
|
etl::ilist<PacketInfo>& packetListRef;
|
||||||
uint8_t maxTlvsInOnePdu;
|
uint8_t maxTlvsInOnePdu = 10;
|
||||||
|
size_t maxFilenameLen = 255;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FsfwParams {
|
struct FsfwParams {
|
||||||
@ -67,8 +70,6 @@ class DestHandler {
|
|||||||
ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize);
|
ReturnValue_t handleMetadataParseError(const uint8_t* rawData, size_t maxSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DestHandlerParams dp;
|
|
||||||
FsfwParams fp;
|
|
||||||
enum class TransactionStep {
|
enum class TransactionStep {
|
||||||
IDLE = 0,
|
IDLE = 0,
|
||||||
TRANSACTION_START = 1,
|
TRANSACTION_START = 1,
|
||||||
@ -77,8 +78,29 @@ class DestHandler {
|
|||||||
TRANSFER_COMPLETION = 4,
|
TRANSFER_COMPLETION = 4,
|
||||||
SENDING_FINISHED_PDU = 5
|
SENDING_FINISHED_PDU = 5
|
||||||
};
|
};
|
||||||
|
struct TransactionParams {
|
||||||
|
explicit TransactionParams(size_t maxFileNameLen)
|
||||||
|
: sourceName(maxFileNameLen), destName(maxFileNameLen) {}
|
||||||
|
|
||||||
|
ChecksumType checksumType = ChecksumType::NULL_CHECKSUM;
|
||||||
|
bool closureRequested{};
|
||||||
|
std::vector<char> sourceName;
|
||||||
|
std::vector<char> destName;
|
||||||
|
cfdp::FileSize fileSize;
|
||||||
|
TransactionId transactionId;
|
||||||
|
PduConfig pduConf;
|
||||||
|
RemoteEntityCfg* remoteCfg;
|
||||||
|
};
|
||||||
|
|
||||||
TransactionStep step = TransactionStep::IDLE;
|
TransactionStep step = TransactionStep::IDLE;
|
||||||
|
CfdpStates cfdpState = CfdpStates::IDLE;
|
||||||
std::vector<cfdp::Tlv> tlvVec;
|
std::vector<cfdp::Tlv> tlvVec;
|
||||||
|
std::vector<cfdp::Tlv> userTlvVec;
|
||||||
|
DestHandlerParams dp;
|
||||||
|
FsfwParams fp;
|
||||||
|
TransactionParams tp;
|
||||||
|
|
||||||
|
ReturnValue_t startTransaction(MetadataPduReader& reader, MetadataInfo& info);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cfdp
|
} // namespace cfdp
|
||||||
|
9
src/fsfw/cfdp/handler/defs.h
Normal file
9
src/fsfw/cfdp/handler/defs.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#ifndef FSFW_CFDP_HANDLER_DEFS_H
|
||||||
|
#define FSFW_CFDP_HANDLER_DEFS_H
|
||||||
|
|
||||||
|
namespace cfdp {
|
||||||
|
|
||||||
|
enum class CfdpStates { IDLE, BUSY_CLASS_1_NACKED, BUSY_CLASS_2_ACKED, SUSPENDED };
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // FSFW_CFDP_HANDLER_DEFS_H
|
@ -139,3 +139,13 @@ bool HeaderReader::isNull() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HeaderReader::operator bool() const { return not isNull(); }
|
HeaderReader::operator bool() const { return not isNull(); }
|
||||||
|
|
||||||
|
void HeaderReader::fillConfig(PduConfig &cfg) const {
|
||||||
|
cfg.largeFile = getLargeFileFlag();
|
||||||
|
cfg.crcFlag = getCrcFlag();
|
||||||
|
cfg.mode = getTransmissionMode();
|
||||||
|
cfg.direction = getDirection();
|
||||||
|
getTransactionSeqNum(cfg.seqNum);
|
||||||
|
getSourceId(cfg.sourceId);
|
||||||
|
getDestId(cfg.destId);
|
||||||
|
}
|
||||||
|
@ -45,6 +45,12 @@ class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF {
|
|||||||
explicit operator bool() const;
|
explicit operator bool() const;
|
||||||
[[nodiscard]] bool isNull() const;
|
[[nodiscard]] bool isNull() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fill the provided PDU configuration from the fields detected by this reader.
|
||||||
|
* @param cfg
|
||||||
|
*/
|
||||||
|
void fillConfig(PduConfig& cfg) const;
|
||||||
|
|
||||||
[[nodiscard]] virtual size_t getHeaderSize() const;
|
[[nodiscard]] virtual size_t getHeaderSize() const;
|
||||||
|
|
||||||
[[nodiscard]] size_t getPduDataFieldLen() const override;
|
[[nodiscard]] size_t getPduDataFieldLen() const override;
|
||||||
|
@ -6,16 +6,18 @@
|
|||||||
|
|
||||||
class PduConfig {
|
class PduConfig {
|
||||||
public:
|
public:
|
||||||
|
PduConfig() = default;
|
||||||
PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode,
|
PduConfig(cfdp::EntityId sourceId, cfdp::EntityId destId, cfdp::TransmissionModes mode,
|
||||||
cfdp::TransactionSeqNum seqNum, bool crcFlag = false, bool largeFile = false,
|
cfdp::TransactionSeqNum seqNum, bool crcFlag = false, bool largeFile = false,
|
||||||
cfdp::Direction direction = cfdp::Direction::TOWARDS_RECEIVER);
|
cfdp::Direction direction = cfdp::Direction::TOWARDS_RECEIVER);
|
||||||
cfdp::TransmissionModes mode;
|
|
||||||
|
cfdp::TransmissionModes mode = cfdp::TransmissionModes::ACKNOWLEDGED;
|
||||||
cfdp::TransactionSeqNum seqNum;
|
cfdp::TransactionSeqNum seqNum;
|
||||||
cfdp::EntityId sourceId;
|
cfdp::EntityId sourceId;
|
||||||
cfdp::EntityId destId;
|
cfdp::EntityId destId;
|
||||||
bool crcFlag;
|
bool crcFlag = false;
|
||||||
bool largeFile;
|
bool largeFile = false;
|
||||||
cfdp::Direction direction;
|
cfdp::Direction direction = cfdp::Direction::TOWARDS_RECEIVER;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ */
|
#endif /* FSFW_SRC_FSFW_CFDP_PDU_PDUCONFIG_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user