59 m_currentTxn(nullptr),
62 m_channelId(channelId),
63 m_flowState(Cfdp::
Flow::NOT_FROZEN),
65 m_transactions(nullptr),
85 m_polldir[i].
pb.
busy =
false;
94 m_playback[i].
busy =
false;
107 U32 chunk_mem_offset = 0;
108 U32 total_chunks_needed;
117 total_chunks_needed = 0;
133 m_histories =
static_cast<History*
>(allocator.
allocate(memId, historiesSize));
137 m_chunkMem =
static_cast<Chunk*
>(allocator.
allocate(memId, chunkMemSize));
144 txn =
new (&m_transactions[j])
Transaction(
this, m_channelId, m_engine, m_cfdpManager);
154 new (cw)
CfdpChunkWrapper(static_cast<ChunkIdx>(m_dirMaxChunks[k]), &m_chunkMem[chunk_mem_offset]);
155 chunk_mem_offset += m_dirMaxChunks[k];
163 history =
new (&m_histories[j])
History();
176 if (m_transactions !=
nullptr) {
182 m_transactions =
nullptr;
185 if (m_chunks !=
nullptr) {
188 m_chunks[j].~CfdpChunkWrapper();
194 if (m_histories !=
nullptr) {
197 m_histories[j].~History();
200 m_histories =
nullptr;
203 if (m_chunkMem !=
nullptr) {
205 m_chunkMem =
nullptr;
225 if (!this->m_currentTxn) {
231 struct CycleTxContext {
234 } cycleTxCtx = {
this, &args};
249 if (txn->m_chunks ==
nullptr) {
252 if (txn->m_chunks ==
nullptr) {
265 this->m_currentTxn =
nullptr;
279 TickArgs args = {
this, fns[m_tickType], 0, 0};
287 for (U32 retry = 0; retry < maxRetries; ++retry) {
294 } tickCtx = {
this, &args};
338 U8 playback_count = 0;
341 this->processPlaybackDirectory(&m_playback[i]);
343 if (m_playback[i].busy) {
350 tlm.set_playbackCounter(playback_count);
382 this->processPlaybackDirectory(&pd->
pb);
389 tlm.set_pollCounter(poll_count);
445 txn->m_history->
dir = direction;
481 struct TraverseAllContext {
485 } ctx = {fn, context, &counter};
512 tlm.set_queueFree(static_cast<U16>(
tlm.get_queueFree() - 1));
516 tlm.set_queueTxActive(static_cast<U16>(
tlm.get_queueTxActive() - 1));
520 tlm.set_queueTxWaiting(static_cast<U16>(
tlm.get_queueTxWaiting() - 1));
524 tlm.set_queueRx(static_cast<U16>(
tlm.get_queueRx() - 1));
528 tlm.set_queueHistory(static_cast<U16>(
tlm.get_queueHistory() - 1));
548 tlm.set_queueFree(static_cast<U16>(
tlm.get_queueFree() - 1));
552 tlm.set_queueTxActive(static_cast<U16>(
tlm.get_queueTxActive() - 1));
556 tlm.set_queueTxWaiting(static_cast<U16>(
tlm.get_queueTxWaiting() - 1));
560 tlm.set_queueRx(static_cast<U16>(
tlm.get_queueRx() - 1));
564 tlm.set_queueHistory(static_cast<U16>(
tlm.get_queueHistory() - 1));
579 tlm.set_queueFree(static_cast<U16>(
tlm.get_queueFree() + 1));
582 tlm.set_queueTxActive(static_cast<U16>(
tlm.get_queueTxActive() + 1));
585 tlm.set_queueTxWaiting(static_cast<U16>(
tlm.get_queueTxWaiting() + 1));
588 tlm.set_queueRx(static_cast<U16>(
tlm.get_queueRx() + 1));
591 tlm.set_queueHistory(static_cast<U16>(
tlm.get_queueHistory() + 1));
627 if (
true == txn->m_fd.
isOpen()) {
635 if (txn->m_history !=
nullptr) {
642 if (txn->m_chunks !=
nullptr) {
644 if (chunklist_head !=
nullptr) {
648 txn->m_chunks =
nullptr;
659 txn->m_history =
nullptr;
669 bool insert_back =
false;
711 if (this->m_currentTxn == txn) {
712 this->m_currentTxn =
nullptr;
717 this->m_currentTxn = txn;
728 result = &m_cs[direction];
746 if (*chunklist_head !=
nullptr) {
748 if (node !=
nullptr) {
760 void Channel::processPlaybackDirectory(
Playback* pb) {
779 static_cast<I32>(status));
793 const bool srcTooLong = (srcPathLen > maxPathLen);
794 const bool dstTooLong = (dstPathLen > maxPathLen);
803 if (srcTooLong || dstTooLong) {
809 if (txn ==
nullptr) {
841 void Channel::updatePollPbCounted(Playback* pb, I32 up,
U8* counter) {
842 if (pb->counted != up) {
880 const U32 prevOutgoing = this->m_outgoingCounter;
881 const TxnState prevState = txn->m_state;
892 this->m_outgoingCounter == prevOutgoing && txn->m_state == prevState &&
910 if (!this->m_currentTxn || (this->m_currentTxn == txn)) {
912 this->m_currentTxn =
nullptr;
914 (txn->*args->
fn)(&args->
cont);
920 if (this->m_currentTxn) {
931 return &m_transactions[index];
936 return &m_histories[index];
944 struct CycleTxContext {
948 CycleTxContext* ctx =
static_cast<CycleTxContext*
>(context);
949 return ctx->channel->cycleTxFirstActive(node, ctx->args);
957 TickContext* ctx =
static_cast<TickContext*
>(context);
958 return ctx->channel->doTick(node, ctx->args);
962 struct TraverseAllContext {
967 TraverseAllContext* ctx =
static_cast<TraverseAllContext*
>(context);
969 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.
TxnState
High-level state of a transaction.
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.
void log_WARNING_LO_PlaybackDestinationPathTooLong(FwSizeType length, FwSizeType maxLength, const Fw::StringBase &directory, const Fw::StringBase &entry) const
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 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 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 finishTransaction(Transaction *txn, bool keep_history)
Finish a transaction.
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.
TxSubState
Sub-state of a send file transaction.
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)
void decrementRxCounter()
Decrement the receive transaction counter for this channel.
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.
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)
void txFileInitiate(Transaction *txn, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Initiate a file transfer transaction.
void setTxnStatus(Transaction *txn, TxnStatus txn_stat)
Helper function to store transaction status code only.
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.
CfdpTxStateData send
applies to only send file transactions
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.
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.
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.
CListNode ** getChunkListHead(U8 direction)
Gets the head of the chunk list for this channel + direction.
CfdpChunkWrapper * findUnusedChunks(Direction dir)
Find unused chunks for this channel.
void log_WARNING_LO_PlaybackSourcePathTooLong(FwSizeType length, FwSizeType maxLength, const Fw::StringBase &directory, const Fw::StringBase &entry) const
void recycleTransaction(Transaction *txn)
Recover resources associated with a transaction.
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.