#ifndef FSFW_CFDP_CFDPSOURCEHANDLER_H #define FSFW_CFDP_CFDPSOURCEHANDLER_H #include #include #include "UserBase.h" #include "defs.h" #include "fsfw/cfdp/FileSize.h" #include "fsfw/cfdp/handler/mib.h" #include "fsfw/events/EventReportingProxyIF.h" #include "fsfw/storagemanager/StorageManagerIF.h" #include "fsfw/tmtcservices/AcceptsTelemetryIF.h" namespace cfdp { struct SourceHandlerParams { SourceHandlerParams(LocalEntityCfg cfg, UserBase& user) : cfg(std::move(cfg)), user(user) {} LocalEntityCfg cfg; UserBase& user; size_t maxFilePathSize = 256; }; // TODO: This class in identical to the ones used by the destination handler. Consider unifying // them. struct FsfwSourceParams { FsfwSourceParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, EventReportingProxyIF* eventReporter, StorageManagerIF& tcStore, StorageManagerIF& tmStore) : FsfwSourceParams(packetDest, msgQueue, eventReporter) { this->tcStore = &tcStore; this->tmStore = &tmStore; } FsfwSourceParams(AcceptsTelemetryIF& packetDest, MessageQueueIF* msgQueue, EventReportingProxyIF* eventReporter) : packetDest(packetDest), msgQueue(msgQueue), eventReporter(eventReporter) {} AcceptsTelemetryIF& packetDest; MessageQueueIF* msgQueue; EventReportingProxyIF* eventReporter = nullptr; StorageManagerIF* tcStore = nullptr; StorageManagerIF* tmStore = nullptr; }; class SourceHandler { public: SourceHandler(SourceHandlerParams params, FsfwSourceParams fsfwParams); /** * Pass a put request to the source handler, which might initiate a CFDP transaction and start * the state machine * @return */ ReturnValue_t putRequest(); void stateMachine(); private: enum class TransactionStep : uint8_t { IDLE = 0, TRANSACTION_START = 1, CRC_PROCEDURE = 2, SENDING_METADATA = 3, SENDING_FILE_DATA = 4, SENDING_EOF = 5, WAIT_FOR_ACK = 6, WAIT_FOR_FINISH = 7, NOTICE_OF_COMPLETION = 8 }; struct TransactionParams { // Initialize char vectors with length + 1 for 0 termination explicit TransactionParams(size_t maxFileNameLen) : sourceName(maxFileNameLen + 1), destName(maxFileNameLen + 1) {} uint32_t crc{}; std::vector sourceName; std::vector destName; cfdp::FileSize fileSize; } transactionParams; cfdp::CfdpState state = cfdp::CfdpState::IDLE; TransactionStep step = TransactionStep::IDLE; SourceHandlerParams sourceParams; FsfwSourceParams fsfwParams; void fsmNacked(); ReturnValue_t checksumGeneration(); }; } // namespace cfdp #endif // FSFW_CFDP_CFDPSOURCEHANDLER_H