F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Channel.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Channel.hpp
3 // \brief CFDP Channel operations
4 //
5 // This file is a port of channel-specific functions from the following files
6 // from the NASA Core Flight System (cFS) CFDP (CF) Application, version 3.0.0,
7 // adapted for use within the F-Prime (F') framework:
8 // - cf_cfdp.c (channel processing functions)
9 // - cf_utils.c (channel transaction and resource management)
10 //
11 // ======================================================================
12 //
13 // NASA Docket No. GSC-18,447-1
14 //
15 // Copyright (c) 2019 United States Government as represented by the
16 // Administrator of the National Aeronautics and Space Administration.
17 // All Rights Reserved.
18 //
19 // Licensed under the Apache License, Version 2.0 (the "License");
20 // you may not use this file except in compliance with the License.
21 // You may obtain a copy of the License at
22 //
23 // http://www.apache.org/licenses/LICENSE-2.0
24 //
25 // Unless required by applicable law or agreed to in writing, software
26 // distributed under the License is distributed on an "AS IS" BASIS,
27 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 // See the License for the specific language governing permissions and
29 // limitations under the License.
30 //
31 // ======================================================================
32 
33 #ifndef CFDP_CHANNEL_HPP
34 #define CFDP_CHANNEL_HPP
35 
36 #include <Fw/Types/Assert.hpp>
38 
40 
41 namespace Svc {
42 namespace Ccsds {
43 namespace Cfdp {
44 
45 // Forward declarations
46 class Engine;
47 class Transaction;
48 
56 class Channel {
57  public:
58  // ----------------------------------------------------------------------
59  // Construction
60  // ----------------------------------------------------------------------
61 
71  Channel(Engine* engine, U8 channelId, CfdpManager* cfdpManager, Fw::MemAllocator& allocator, FwEnumStoreType memId);
72 
76  ~Channel();
77 
86  void cleanup(Fw::MemAllocator& allocator, FwEnumStoreType memId);
87 
88  // Disable copy constructor and assignment operator
89  // Channel manages dynamic resources and should not be copied
90  Channel(const Channel&) = delete;
91  Channel& operator=(const Channel&) = delete;
92 
93  // ----------------------------------------------------------------------
94  // Channel Processing
95  // ----------------------------------------------------------------------
96 
102  void cycleTx();
103 
109  void tickTransactions();
110 
115 
120 
121  // ----------------------------------------------------------------------
122  // Transaction Management
123  // ----------------------------------------------------------------------
124 
134 
147  Transaction* findTransactionBySequenceNumber(TransactionSeq transaction_sequence_number, EntityId src_eid);
148 
158 
167  void resetHistory(History* history);
168 
169  // ----------------------------------------------------------------------
170  // Channel State Management
171  // ----------------------------------------------------------------------
172 
178  inline U8 getChannelId() const { return m_channelId; }
179 
185  inline U32 getOutgoingCounter() const { return m_outgoingCounter; }
186 
190  inline void incrementOutgoingCounter() { ++m_outgoingCounter; }
191 
195  inline void resetOutgoingCounter() { m_outgoingCounter = 0; }
196 
202  inline U32 getNumCmdTx() const { return m_numCmdTx; }
203 
207  inline void incrementCmdTxCounter() { ++m_numCmdTx; }
208 
212  void decrementCmdTxCounter();
213 
219  void clearCurrentIfMatch(Transaction* txn);
220 
229  void setCurrentTxn(const Transaction* txn);
230 
236  inline void setFlowState(Flow::T flowState) { m_flowState = flowState; }
237 
243  inline Flow::T getFlowState() const { return m_flowState; }
244 
251  inline Playback* getPlayback(U32 index) {
253  return &m_playback[index];
254  }
255 
262  inline CfdpPollDir* getPollDir(U32 index) {
264  return &m_polldir[index];
265  }
266 
273  Transaction* getTransaction(U32 index);
274 
281  History* getHistory(U32 index);
282 
283  // ----------------------------------------------------------------------
284  // Resource Management
285  // ----------------------------------------------------------------------
286 
299  CListNode** getChunkListHead(U8 direction);
300 
310 
311  // ----------------------------------------------------------------------
312  // Transaction Management
313  // ----------------------------------------------------------------------
314 
329  void dequeueTransaction(Transaction* txn);
330 
337  void moveTransaction(Transaction* txn, QueueId::T queue);
338 
344  void freeTransaction(Transaction* txn);
345 
361  void recycleTransaction(Transaction* txn);
362 
374  void insertSortPrio(Transaction* txn, QueueId::T queue);
375 
376  // ----------------------------------------------------------------------
377  // Queue Management
378  // ----------------------------------------------------------------------
379 
386  inline void removeFromQueue(QueueId::T queueidx, CListNode* node);
387 
395  inline void insertAfterInQueue(QueueId::T queueidx, CListNode* start, CListNode* after);
396 
403  inline void insertBackInQueue(QueueId::T queueidx, CListNode* node);
404 
405  // ----------------------------------------------------------------------
406  // Callback methods (public so wrappers can call them)
407  // ----------------------------------------------------------------------
408 
416  CListTraverseStatus cycleTxFirstActive(CListNode* node, void* context);
417 
425  CListTraverseStatus doTick(CListNode* node, void* context);
426 
427  // ----------------------------------------------------------------------
428  // Static callback wrappers (for function pointer callbacks)
429  // ----------------------------------------------------------------------
430 
437  static CListTraverseStatus cycleTxFirstActiveWrapper(CListNode* node, void* context);
438 
445  static CListTraverseStatus doTickWrapper(CListNode* node, void* context);
446 
453  static CListTraverseStatus traverseAllTransactionsWrapper(CListNode* node, void* context);
454 
455  private:
456  // ----------------------------------------------------------------------
457  // Private helper methods
458  // ----------------------------------------------------------------------
459 
468  void processPlaybackDirectory(Playback* pb);
469 
477  void updatePollPbCounted(Playback* pb, I32 up, U8* counter);
478 
479  private:
480  // ----------------------------------------------------------------------
481  // Member variables
482  // ----------------------------------------------------------------------
483 
484  Engine* m_engine;
485 
486  CListNode* m_qs[QueueId::NUM];
487  CListNode* m_cs[static_cast<U32>(Direction::DIRECTION_NUM)];
488 
489  U32 m_numCmdTx;
490 
492  CfdpPollDir m_polldir[MaxPollingDirPerChan];
493 
494  const Transaction* m_currentTxn;
495  CfdpManager* m_cfdpManager;
496 
497  U8 m_tickType;
498  U8 m_channelId;
499 
500  Flow::T m_flowState;
501  U32 m_outgoingCounter;
502 
503  // Per-channel resource arrays (dynamically allocated, moved from Engine)
504  Transaction* m_transactions;
505  History* m_histories;
506  CfdpChunkWrapper* m_chunks;
507  Chunk* m_chunkMem;
508 
509  U32 m_dirMaxChunks[static_cast<U32>(
511 
512  // Friend declarations for testing
513  friend class CfdpManagerTester;
514 };
515 
516 // ----------------------------------------------------------------------
517 // Inline function implementations
518 // ----------------------------------------------------------------------
519 
520 inline void Channel::removeFromQueue(QueueId::T queueidx, CListNode* node) {
521  CfdpCListRemove(&m_qs[queueidx], node);
522 }
523 
524 inline void Channel::insertAfterInQueue(QueueId::T queueidx, CListNode* start, CListNode* after) {
525  CfdpCListInsertAfter(&m_qs[queueidx], start, after);
526 }
527 
528 inline void Channel::insertBackInQueue(QueueId::T queueidx, CListNode* node) {
529  CfdpCListInsertBack(&m_qs[queueidx], node);
530 }
531 
532 } // namespace Cfdp
533 } // namespace Ccsds
534 } // namespace Svc
535 
536 #endif // CFDP_CHANNEL_HPP
CFDP Protocol Engine.
Definition: Engine.hpp:89
void moveTransaction(Transaction *txn, QueueId::T queue)
Move a transaction from one queue to another.
Definition: Channel.cpp:539
U8 getChannelId() const
Get the channel ID.
Definition: Channel.hpp:178
CFDP Channel class.
Definition: Channel.hpp:56
~Channel()
Destruct a Channel.
Definition: Channel.cpp:167
History * getHistory(U32 index)
Get a history by index (for testing)
Definition: Channel.cpp:875
CFDP Transaction state machine class.
void removeFromQueue(QueueId::T queueidx, CListNode *node)
Remove a node from a channel queue.
Definition: Channel.hpp:520
I32 FwEnumStoreType
CListTraverseStatus
Traverse status for circular list operations.
Definition: Clist.hpp:45
void(*)(Transaction *txn, void *context) CfdpTraverseAllTransactionsFunc
Callback function type for use with Channel::traverseAllTransactions()
Definition: Types.hpp:421
void setCurrentTxn(const Transaction *txn)
Set current transaction.
Definition: Channel.cpp:705
U32 getOutgoingCounter() const
Get the outgoing PDU counter for this cycle.
Definition: Channel.hpp:185
void CfdpCListInsertAfter(CListNode **head, CListNode *start, CListNode *after)
Insert the given node into the last after the given start node.
Definition: Clist.cpp:125
U32 EntityId
Entity id size.
I32 traverseAllTransactions(CfdpTraverseAllTransactionsFunc fn, void *context)
Traverses all transactions on all active queues and performs an operation on them.
Definition: Channel.cpp:477
Wrapper around a CfdpChunkList object.
Definition: Types.hpp:260
void processPollingDirectories()
Process all polling directories for this channel.
Definition: Channel.cpp:351
CFDP Playback entry.
Definition: Types.hpp:278
void incrementCmdTxCounter()
Increment the command TX counter for this channel.
Definition: Channel.hpp:207
CListTraverseStatus cycleTxFirstActive(CListNode *node, void *context)
Traverse callback for cycling the first active transaction.
Definition: Channel.cpp:823
U32 TransactionSeq
transaction sequence number size
Flow::T getFlowState() const
Get the flow state for this channel.
Definition: Channel.hpp:243
void cycleTx()
Cycle the TX side of this channel.
Definition: Channel.cpp:211
static CListTraverseStatus cycleTxFirstActiveWrapper(CListNode *node, void *context)
Static wrapper for cycleTxFirstActive callback.
Definition: Channel.cpp:884
void resetOutgoingCounter()
Reset the outgoing PDU counter to zero.
Definition: Channel.hpp:195
void insertAfterInQueue(QueueId::T queueidx, CListNode *start, CListNode *after)
Insert a node after another in a channel queue.
Definition: Channel.hpp:524
Channel(Engine *engine, U8 channelId, CfdpManager *cfdpManager, Fw::MemAllocator &allocator, FwEnumStoreType memId)
Construct a Channel.
Definition: Channel.cpp:51
void clearCurrentIfMatch(Transaction *txn)
Check if current transaction matches and clear if so.
Definition: Channel.cpp:698
void tickTransactions()
Tick all transactions on this channel.
Definition: Channel.cpp:267
void freeTransaction(Transaction *txn)
Frees and resets a transaction and returns it for later use.
Definition: Channel.cpp:602
void dequeueTransaction(Transaction *txn)
Free a transaction from the queue it&#39;s on.
Definition: Channel.cpp:503
void decrementCmdTxCounter()
Decrement the command TX counter for this channel.
Definition: Channel.cpp:693
void CfdpCListInsertBack(CListNode **head, CListNode *node)
Insert the given node into the back of a list.
Definition: Clist.cpp:69
static CListTraverseStatus doTickWrapper(CListNode *node, void *context)
Static wrapper for doTick callback.
Definition: Channel.cpp:893
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
void processPlaybackDirectories()
Process all playback directories for this channel.
Definition: Channel.cpp:334
void insertSortPrio(Transaction *txn, QueueId::T queue)
Insert a transaction into a priority sorted transaction queue.
Definition: Channel.cpp:662
Transaction * findUnusedTransaction(Direction direction)
Find an unused transaction on this channel.
Definition: Channel.cpp:396
void cleanup(Fw::MemAllocator &allocator, FwEnumStoreType memId)
Clean up dynamically allocated resources.
Definition: Channel.cpp:172
Memory Allocation base class.
Transaction * getTransaction(U32 index)
Get a transaction by index (for testing)
Definition: Channel.cpp:870
void insertBackInQueue(QueueId::T queueidx, CListNode *node)
Insert a node at the back of a channel queue.
Definition: Channel.hpp:528
void CfdpCListRemove(CListNode **head, CListNode *node)
Remove the given node from the list.
Definition: Clist.cpp:102
CListTraverseStatus doTick(CListNode *node, void *context)
Traverse callback for ticking a transaction.
Definition: Channel.cpp:846
Circular linked list node structure.
Definition: Clist.hpp:66
void incrementOutgoingCounter()
Increment the outgoing PDU counter.
Definition: Channel.hpp:190
Transaction * findTransactionBySequenceNumber(TransactionSeq transaction_sequence_number, EntityId src_eid)
Finds an active transaction by sequence number.
Definition: Channel.cpp:457
Channel & operator=(const Channel &)=delete
RateGroupDivider component implementation.
CfdpPollDir * getPollDir(U32 index)
Get a polling directory entry.
Definition: Channel.hpp:262
U32 getNumCmdTx() const
Get the number of commanded TX transactions.
Definition: Channel.hpp:202
Defines a base class for a memory allocator for classes.
void resetHistory(History *history)
Returns a history structure back to its unused state.
Definition: Channel.cpp:494
Directory poll entry.
Definition: Types.hpp:298
friend class CfdpManagerTester
Definition: Channel.hpp:513
T
The raw enum type.
Definition: FlowEnumAc.hpp:35
CListNode ** getChunkListHead(U8 direction)
Gets the head of the chunk list for this channel + direction.
Definition: Channel.cpp:713
void setFlowState(Flow::T flowState)
Set the flow state for this channel.
Definition: Channel.hpp:236
CfdpChunkWrapper * findUnusedChunks(Direction dir)
Find unused chunks for this channel.
Definition: Channel.cpp:725
T
The raw enum type.
void recycleTransaction(Transaction *txn)
Recover resources associated with a transaction.
Definition: Channel.cpp:620
Direction
Direction identifier.
Definition: Types.hpp:154
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Playback * getPlayback(U32 index)
Get a playback directory entry.
Definition: Channel.hpp:251
static CListTraverseStatus traverseAllTransactionsWrapper(CListNode *node, void *context)
Static wrapper for traverseAllTransactions callback.
Definition: Channel.cpp:902
Pairs an offset with a size to identify a specific piece of a file.
Definition: Chunk.hpp:49
CFDP History entry.
Definition: Types.hpp:244