fsfw/src/fsfw/cfdp/handler/SourceHandler.h

111 lines
3.0 KiB
C
Raw Normal View History

2022-09-14 19:29:43 +02:00
#ifndef FSFW_CFDP_CFDPSOURCEHANDLER_H
#define FSFW_CFDP_CFDPSOURCEHANDLER_H
2023-06-30 11:59:22 +02:00
#include <cstdint>
2023-07-17 09:53:23 +02:00
#include <vector>
2023-06-30 11:59:22 +02:00
2023-07-17 09:53:23 +02:00
#include "UserBase.h"
2023-07-14 15:56:38 +02:00
#include "defs.h"
2023-07-19 13:44:52 +02:00
#include "fsfw/cfdp/Fss.h"
2023-07-27 17:15:01 +02:00
#include "fsfw/cfdp/handler/PutRequest.h"
2023-07-17 09:53:23 +02:00
#include "fsfw/cfdp/handler/mib.h"
2023-06-30 11:59:22 +02:00
#include "fsfw/events/EventReportingProxyIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
2023-07-17 10:15:06 +02:00
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
#include "fsfw/util/ProvidesSeqCountIF.h"
2023-06-30 11:59:22 +02:00
2023-07-17 09:53:23 +02:00
namespace cfdp {
struct SourceHandlerParams {
SourceHandlerParams(LocalEntityCfg cfg, UserBase& user, ProvidesSeqCountIF& seqCountProvider)
: cfg(std::move(cfg)), user(user), seqCountProvider(seqCountProvider) {}
2023-07-17 09:53:23 +02:00
LocalEntityCfg cfg;
UserBase& user;
ProvidesSeqCountIF& seqCountProvider;
2023-07-17 09:53:23 +02:00
};
2023-06-30 11:36:19 +02:00
class SourceHandler {
2023-06-30 11:48:25 +02:00
public:
2023-07-27 17:15:01 +02:00
enum class TransactionStep : uint8_t {
IDLE = 0,
TRANSACTION_START = 1,
SENDING_METADATA = 3,
SENDING_FILE_DATA = 4,
SENDING_EOF = 5,
WAIT_FOR_ACK = 6,
WAIT_FOR_FINISH = 7,
NOTICE_OF_COMPLETION = 8
};
2023-07-17 15:21:22 +02:00
struct FsmResult {
public:
ReturnValue_t result = returnvalue::OK;
CallStatus callStatus = CallStatus::CALL_AFTER_DELAY;
CfdpState state = CfdpState::IDLE;
uint32_t packetsSent = 0;
uint8_t errors = 0;
std::array<ReturnValue_t, 3> errorCodes = {};
};
2023-07-17 10:25:09 +02:00
SourceHandler(SourceHandlerParams params, FsfwParams fsfwParams);
2023-06-30 11:48:25 +02:00
2023-07-27 17:15:01 +02:00
[[nodiscard]] CfdpState getState() const;
[[nodiscard]] TransactionStep getStep() const;
2023-07-17 10:15:06 +02:00
/**
* Pass a put request to the source handler, which might initiate a CFDP transaction and start
* the state machine
* @return
*/
2023-07-27 17:15:01 +02:00
ReturnValue_t transactionStart(PutRequest& putRequest, RemoteEntityCfg& cfg);
2023-08-14 20:47:27 +02:00
const FsmResult& stateMachine();
2023-07-14 15:56:38 +02:00
2023-07-18 09:38:46 +02:00
ReturnValue_t initialize();
2023-06-30 11:48:25 +02:00
private:
2023-07-17 09:53:23 +02:00
struct TransactionParams {
uint32_t crc{};
2023-07-27 17:15:01 +02:00
std::array<char, UINT8_MAX + 1> sourceName{};
2023-07-18 09:38:46 +02:00
size_t sourceNameSize = 0;
2023-07-27 17:15:01 +02:00
std::array<char, UINT8_MAX + 1> destName{};
2023-07-18 09:38:46 +02:00
size_t destNameSize = 0;
2023-07-19 13:44:52 +02:00
cfdp::Fss fileSize;
size_t progress = 0;
2023-07-18 09:38:46 +02:00
bool closureRequested = false;
2023-08-03 17:43:03 +02:00
ChecksumType checksumType = ChecksumType::NULL_CHECKSUM;
2023-07-19 13:44:52 +02:00
RemoteEntityCfg remoteCfg;
PduConfig pduConf;
cfdp::TransactionId id{};
2023-07-19 23:43:40 +02:00
void reset() {
sourceNameSize = 0;
destNameSize = 0;
fileSize.setFileSize(0, false);
progress = 0;
closureRequested = false;
}
2023-07-17 09:53:23 +02:00
} transactionParams;
2023-07-19 23:43:40 +02:00
2023-07-17 09:53:23 +02:00
cfdp::CfdpState state = cfdp::CfdpState::IDLE;
TransactionStep step = TransactionStep::IDLE;
2023-07-19 13:44:52 +02:00
std::array<uint8_t, 4096> fileBuf{};
2023-07-17 09:53:23 +02:00
SourceHandlerParams sourceParams;
2023-07-17 10:25:09 +02:00
cfdp::FsfwParams fsfwParams;
2023-07-17 15:21:22 +02:00
FsmResult fsmResult;
2023-07-14 15:56:38 +02:00
2023-07-17 15:21:22 +02:00
FsmResult& fsmNacked();
2023-07-17 09:53:23 +02:00
ReturnValue_t checksumGeneration();
2023-07-17 15:11:51 +02:00
ReturnValue_t prepareAndSendMetadataPdu();
2023-08-03 15:49:23 +02:00
ReturnValue_t prepareAndSendNextFileDataPdu(bool& noFileDataPdu);
2023-07-17 15:21:22 +02:00
ReturnValue_t prepareAndSendEofPdu();
2023-07-19 23:43:40 +02:00
ReturnValue_t noticeOfCompletion();
ReturnValue_t reset();
2023-07-19 13:44:52 +02:00
2023-08-03 15:49:23 +02:00
[[nodiscard]] ReturnValue_t sendGenericPdu(const SerializeIF& pdu);
void addError(ReturnValue_t error);
2023-06-30 11:36:19 +02:00
};
2022-09-14 19:29:43 +02:00
2023-07-17 09:53:23 +02:00
} // namespace cfdp
2022-09-14 19:29:43 +02:00
#endif // FSFW_CFDP_CFDPSOURCEHANDLER_H