58 m_currentTxn(nullptr),
59 m_cfdpManager(cfdpManager),
61 m_channelId(channelId),
62 m_flowState(Cfdp::
Flow::NOT_FROZEN),
64 m_transactions(nullptr),
83 m_polldir[i].
pb.
busy =
false;
92 m_playback[i].
busy =
false;
105 U32 chunk_mem_offset = 0;
106 U32 total_chunks_needed;
115 total_chunks_needed = 0;
131 m_histories =
static_cast<History*
>(allocator.
allocate(memId, historiesSize));
135 m_chunkMem =
static_cast<Chunk*
>(allocator.
allocate(memId, chunkMemSize));
142 txn =
new (&m_transactions[j])
Transaction(
this, m_channelId, m_engine, m_cfdpManager);
152 new (cw)
CfdpChunkWrapper(static_cast<ChunkIdx>(m_dirMaxChunks[k]), &m_chunkMem[chunk_mem_offset]);
153 chunk_mem_offset += m_dirMaxChunks[k];
161 history =
new (&m_histories[j])
History();
174 if (m_transactions !=
nullptr) {
180 m_transactions =
nullptr;
183 if (m_chunks !=
nullptr) {
186 m_chunks[j].~CfdpChunkWrapper();
192 if (m_histories !=
nullptr) {
195 m_histories[j].~History();
198 m_histories =
nullptr;
201 if (m_chunkMem !=
nullptr) {
203 m_chunkMem =
nullptr;
223 if (!this->m_currentTxn) {
229 struct CycleTxContext {
232 } cycleTxCtx = {
this, &args};
247 if (txn->m_chunks ==
nullptr) {
250 if (txn->m_chunks ==
nullptr) {
263 this->m_currentTxn =
nullptr;
277 TickArgs args = {
this, fns[m_tickType], 0, 0};
285 for (U32 retry = 0; retry < maxRetries; ++retry) {
292 } tickCtx = {
this, &args};
336 U8 playback_count = 0;
339 this->processPlaybackDirectory(&m_playback[i]);
341 if (m_playback[i].busy) {
382 this->processPlaybackDirectory(&pd->
pb);
445 txn->m_history->
dir = direction;
481 struct TraverseAllContext {
485 } ctx = {fn, context, &counter};
627 if (
true == txn->m_fd.
isOpen()) {
635 if (txn->m_history !=
nullptr) {
636 if (txn->m_chunks !=
nullptr) {
638 if (chunklist_head !=
nullptr) {
642 txn->m_chunks =
nullptr;
653 txn->m_history =
nullptr;
663 bool insert_back =
false;
700 if (this->m_currentTxn == txn) {
701 this->m_currentTxn =
nullptr;
706 this->m_currentTxn = txn;
717 result = &m_cs[direction];
735 if (*chunklist_head !=
nullptr) {
737 if (node !=
nullptr) {
749 void Channel::processPlaybackDirectory(
Playback* pb) {
768 static_cast<I32>(status));
777 if (txn ==
nullptr) {
809 void Channel::updatePollPbCounted(Playback* pb, I32 up,
U8* counter) {
810 if (pb->counted != up) {
851 if (!this->m_currentTxn || (this->m_currentTxn == txn)) {
853 this->m_currentTxn =
nullptr;
855 (txn->*args->
fn)(&args->
cont);
861 if (this->m_currentTxn) {
872 return &m_transactions[index];
877 return &m_histories[index];
885 struct CycleTxContext {
889 CycleTxContext* ctx =
static_cast<CycleTxContext*
>(context);
890 return ctx->channel->cycleTxFirstActive(node, ctx->args);
898 TickContext* ctx =
static_cast<TickContext*
>(context);
899 return ctx->channel->doTick(node, ctx->args);
903 struct TraverseAllContext {
908 TraverseAllContext* ctx =
static_cast<TraverseAllContext*
>(context);
910 ctx->fn(txn, ctx->userContext);
CListNode cl_node
for connection to a CList
U8 getPriority() const
Get transaction priority.
CfdpTxnFilenames fnames
file names associated with this history entry
void moveTransaction(Transaction *txn, QueueId::T queue)
Move a transaction from one queue to another.
Fw::String dstDir
path to destination dir
virtual void * allocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t))=0
Structure for use with the Channel::doTick() function.
~Channel()
Destruct a Channel.
Argument structure for use with CfdpCListTraverseR()
Transaction * txn
output transaction pointer
History * getHistory(U32 index)
Get a history by index (for testing)
bool early_exit
early exit result
CFDP Transaction state machine class.
PlatformSizeType FwSizeType
void removeFromQueue(QueueId::T queueidx, CListNode *node)
Remove a node from a channel queue.
CListTraverseStatus
Traverse status for circular list operations.
void(Transaction::* fn)(I32 *)
member function pointer
U16 num_ts
number of transactions
void(*)(Transaction *txn, void *context) CfdpTraverseAllTransactionsFunc
Callback function type for use with Channel::traverseAllTransactions()
void setCurrentTxn(const Transaction *txn)
Set current transaction.
State assigned to a newly allocated transaction object.
U32 EntityId
Entity id size.
first one on this list is active
void set_queueTxActive(U16 queueTxActive)
Set member queueTxActive.
void sTickNak(I32 *cont)
Perform NAK response for TX transactions.
I32 cont
if 1, then re-traverse the list
I32 traverseAllTransactions(CfdpTraverseAllTransactionsFunc fn, void *context)
Traverses all transactions on all active queues and performs an operation on them.
U8 priority
priority to use when placing transactions on the pending queue
Wrapper around a CfdpChunkList object.
void reset()
Reset the chunk list to empty state.
Fw::StringTemplate< MaxFilePathSize > pending_file
CfdpChunkList chunks
Chunk list for gap tracking.
File will be deleted after the CFDP transaction.
CFDP class 2 - Reliable transfer (Acknowledged)
Channel * chan
channel object
static CListTraverseStatus prioritySearchCallback(CListNode *node, void *context)
Static callback for priority search.
Continue traversing the list.
void rTick(I32 *cont)
Perform tick (time-based) processing for R transactions.
void set_pollCounter(U8 pollCounter)
Set member pollCounter.
void processPollingDirectories()
Process all polling directories for this channel.
U32 intervalSec
number of seconds to wait before trying a new directory
I32 ran_one
should be set to 1 if a transaction was cycled
CListTraverseStatus cycleTxFirstActive(CListNode *node, void *context)
Traverse callback for cycling the first active transaction.
void set_queueTxWaiting(U16 queueTxWaiting)
Set member queueTxWaiting.
U16 get_queueTxActive() const
Get member queueTxActive.
U32 TransactionSeq
transaction sequence number size
U8 getChannelId() const
Get channel ID.
Fw::Enabled getDequeueEnabledParam(U8 channelIndex)
bool keep_history
whether history should be preserved during recycle
Status getStatus(void)
Get the status of a CFDP timer.
void set_queueRx(U16 queueRx)
Set member queueRx.
static constexpr U32 CFDP_NUM_TRANSACTIONS_PER_CHANNEL
Maximum possible number of transactions that may exist on a single CFDP channel.
void cycleTx()
Cycle the TX side of this channel.
#define CFDP_CHANNEL_NUM_TX_CHUNKS_PER_TRANSACTION
TX chunks per transaction (per channel)
U16 get_queueTxWaiting() const
Get member queueTxWaiting.
static CListTraverseStatus cycleTxFirstActiveWrapper(CListNode *node, void *context)
Static wrapper for cycleTxFirstActive callback.
void close() override
Close directory.
Argument structure for use with CList_Traverse()
void insertAfterInQueue(QueueId::T queueidx, CListNode *start, CListNode *after)
Insert a node after another in a channel queue.
Structure for use with the Channel::cycleTx() function.
Status read(char *fileNameBuffer, FwSizeType buffSize) override
Get next filename from directory stream.
void armInactTimer(Transaction *txn)
Arm the inactivity timer for a transaction.
void reset()
Reset transaction to default state.
Channel(Engine *engine, U8 channelId, CfdpManager *cfdpManager, Fw::MemAllocator &allocator, FwEnumStoreType memId)
Construct a Channel.
void clearCurrentIfMatch(Transaction *txn)
Check if current transaction matches and clear if so.
void tickTransactions()
Tick all transactions on this channel.
U16 get_queueFree() const
Get member queueFree.
Direction dir
direction of this history entry
void freeTransaction(Transaction *txn)
Frees and resets a transaction and returns it for later use.
void dequeueTransaction(Transaction *txn)
Free a transaction from the queue it's on.
Playback pb
State of the current playback requests.
void dispatchTx(Transaction *txn)
Dispatch TX state machine for a transaction.
void setTimer(U32 timerDuration)
Initialize a CFDP timer and start its execution.
void txFileInitiate(Transaction *txn, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Initiate a file transfer transaction.
Stop traversing the list.
void close() override
close the file, if not opened then do nothing
Directory stream has no more files.
static CListTraverseStatus findBySequenceNumberCallback(CListNode *node, void *context)
Static callback for finding transaction by sequence number.
void CfdpCListTraverse(CListNode *start, CListFunc fn, void *context)
Traverse the entire list, calling the given function on all nodes.
Status::T playbackDirInitiate(Playback *pb, const Fw::String &src_filename, const Fw::String &dst_filename, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Initiate playback of a directory.
Fw::String srcDir
path to source dir
CListNode * CfdpCListPop(CListNode **head)
Remove the first node from a list and return it.
void decrementCmdTxCounter()
Decrement the command TX counter for this channel.
void CfdpCListInsertBack(CListNode **head, CListNode *node)
Insert the given node into the back of a list.
Transaction * txn
OUT: holds value of transaction with which to call CfdpCListInsertAfter on.
static CListTraverseStatus doTickWrapper(CListNode *node, void *context)
Static wrapper for doTick callback.
uint8_t U8
8-bit unsigned integer
void processPlaybackDirectories()
Process all playback directories for this channel.
CFDP operation has been successful.
void insertSortPrio(Transaction *txn, QueueId::T queue)
Insert a transaction into a priority sorted transaction queue.
void sTick(I32 *cont)
Perform tick (time-based) processing for S transactions.
void set_playbackCounter(U8 playbackCounter)
Set member playbackCounter.
Cfdp::ChannelTelemetry & getChannelTelemetryRef(U8 channelId)
Get reference to channel telemetry for Channel class.
Transaction * findUnusedTransaction(Direction direction)
Find an unused transaction on this channel.
Class::T getClass() const
Get transaction class (CLASS_1 or CLASS_2)
TransactionSeq seq_num
transaction identifier, stays constant for entire transfer
void cleanup(Fw::MemAllocator &allocator, FwEnumStoreType memId)
Clean up dynamically allocated resources.
Memory Allocation base class.
void log_WARNING_LO_PlaybackDirReadFailed(const Fw::StringBase &directory, I32 status) const
Log event PlaybackDirReadFailed.
Transaction * getTransaction(U32 index)
Get a transaction by index (for testing)
void insertBackInQueue(QueueId::T queueidx, CListNode *node)
Insert a node at the back of a channel queue.
Class::T cfdpClass
the CFDP class to send
constexpr Container * container_of_cpp(Member *member_ptr, Member Container::*member)
Obtains a pointer to the parent structure.
void CfdpCListRemove(CListNode **head, CListNode *node)
Remove the given node from the list.
Operation was successful.
void run(void)
Runs a one second increment of the CFDP timers.
Fw::Enabled enabled
Enabled flag.
CListTraverseStatus doTick(CListNode *node, void *context)
Traverse callback for ticking a transaction.
Circular linked list node structure.
Transaction * findTransactionBySequenceNumber(TransactionSeq transaction_sequence_number, EntityId src_eid)
Finds an active transaction by sequence number.
Timer intervalTimer
Timer object used to poll the directory.
Structure for the telemetry array of CFDP channels.
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
CfdpFlagsCommon com
applies to all transactions
TxnStatus txn_stat
final status of operation
void resetHistory(History *history)
Returns a history structure back to its unused state.
EntityId src_eid
the source eid of the transaction
void log_WARNING_LO_DanglingFileHandleClosed(U8 channelId, U32 transactionSeq) const
Log event DanglingFileHandleClosed.
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
#define CFDP_CHANNEL_NUM_RX_CHUNKS_PER_TRANSACTION
RX chunks per transaction (per channel)
EntityId destEid
destination entity id
U8 q_index
Q index this is in.
void CfdpCListTraverseR(CListNode *end, CListFunc fn, void *context)
Reverse list traversal, starting from end, calling given function on all nodes.
void set_queueHistory(U16 queueHistory)
Set member queueHistory.
CListNode ** getChunkListHead(U8 direction)
Gets the head of the chunk list for this channel + direction.
U16 get_queueHistory() const
Get member queueHistory.
CfdpChunkWrapper * findUnusedChunks(Direction dir)
Find unused chunks for this channel.
void set_queueFree(U16 queueFree)
Set member queueFree.
void recycleTransaction(Transaction *txn)
Recover resources associated with a transaction.
U16 get_queueRx() const
Get member queueRx.
Direction
Direction identifier.
bool isOpen() const
determine if the file is open
CListNode cl_node
Circular list node for pooling.
static CListTraverseStatus traverseAllTransactionsWrapper(CListNode *node, void *context)
Static wrapper for traverseAllTransactions callback.
Pairs an offset with a size to identify a specific piece of a file.
EntityId peer_eid
peer_eid is always the "other guy", same src_eid for RX
void CfdpCListInitNode(CListNode *node)
Initialize a clist node.