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  inline U32 getNumRx() const { return m_numRx; }
220 
224  inline void incrementRxCounter() { ++m_numRx; }
225 
229  void decrementRxCounter();
230 
236  void clearCurrentIfMatch(Transaction* txn);
237 
246  void setCurrentTxn(const Transaction* txn);
247 
253  inline void setFlowState(Flow::T flowState) { m_flowState = flowState; }
254 
260  inline Flow::T getFlowState() const { return m_flowState; }
261 
268  inline Playback* getPlayback(U32 index) {
270  return &m_playback[index];
271  }
272 
279  inline CfdpPollDir* getPollDir(U32 index) {
281  return &m_polldir[index];
282  }
283 
290  Transaction* getTransaction(U32 index);
291 
298  History* getHistory(U32 index);
299 
300  // ----------------------------------------------------------------------
301  // Resource Management
302  // ----------------------------------------------------------------------
303 
316  CListNode** getChunkListHead(U8 direction);
317 
327 
328  // ----------------------------------------------------------------------
329  // Transaction Management
330  // ----------------------------------------------------------------------
331 
346  void dequeueTransaction(Transaction* txn);
347 
354  void moveTransaction(Transaction* txn, QueueId::T queue);
355 
361  void freeTransaction(Transaction* txn);
362 
378  void recycleTransaction(Transaction* txn);
379 
391  void insertSortPrio(Transaction* txn, QueueId::T queue);
392 
393  // ----------------------------------------------------------------------
394  // Queue Management
395  // ----------------------------------------------------------------------
396 
403  inline void removeFromQueue(QueueId::T queueidx, CListNode* node);
404 
412  inline void insertAfterInQueue(QueueId::T queueidx, CListNode* start, CListNode* after);
413 
420  inline void insertBackInQueue(QueueId::T queueidx, CListNode* node);
421 
422  // ----------------------------------------------------------------------
423  // Callback methods (public so wrappers can call them)
424  // ----------------------------------------------------------------------
425 
433  CListTraverseStatus cycleTxFirstActive(CListNode* node, void* context);
434 
442  CListTraverseStatus doTick(CListNode* node, void* context);
443 
444  // ----------------------------------------------------------------------
445  // Static callback wrappers (for function pointer callbacks)
446  // ----------------------------------------------------------------------
447 
454  static CListTraverseStatus cycleTxFirstActiveWrapper(CListNode* node, void* context);
455 
462  static CListTraverseStatus doTickWrapper(CListNode* node, void* context);
463 
470  static CListTraverseStatus traverseAllTransactionsWrapper(CListNode* node, void* context);
471 
472  private:
473  // ----------------------------------------------------------------------
474  // Private helper methods
475  // ----------------------------------------------------------------------
476 
485  void processPlaybackDirectory(Playback* pb);
486 
494  void updatePollPbCounted(Playback* pb, I32 up, U8* counter);
495 
496  private:
497  // ----------------------------------------------------------------------
498  // Member variables
499  // ----------------------------------------------------------------------
500 
501  Engine* m_engine;
502 
503  CListNode* m_qs[QueueId::NUM];
504  CListNode* m_cs[static_cast<U32>(Direction::DIRECTION_NUM)];
505 
506  U32 m_numCmdTx;
507  U32 m_numRx;
508 
510  CfdpPollDir m_polldir[MaxPollingDirPerChan];
511 
512  const Transaction* m_currentTxn;
513  CfdpManager* m_cfdpManager;
514 
515  U8 m_tickType;
516  U8 m_channelId;
517 
518  Flow::T m_flowState;
519  U32 m_outgoingCounter;
520 
521  // Per-channel resource arrays (dynamically allocated, moved from Engine)
522  Transaction* m_transactions;
523  History* m_histories;
524  CfdpChunkWrapper* m_chunks;
525  Chunk* m_chunkMem;
526 
527  U32 m_dirMaxChunks[static_cast<U32>(
529 
530  // Friend declarations for testing
531  friend class CfdpManagerTester;
532 };
533 
534 // ----------------------------------------------------------------------
535 // Inline function implementations
536 // ----------------------------------------------------------------------
537 
538 inline void Channel::removeFromQueue(QueueId::T queueidx, CListNode* node) {
539  CfdpCListRemove(&m_qs[queueidx], node);
540 }
541 
542 inline void Channel::insertAfterInQueue(QueueId::T queueidx, CListNode* start, CListNode* after) {
543  CfdpCListInsertAfter(&m_qs[queueidx], start, after);
544 }
545 
546 inline void Channel::insertBackInQueue(QueueId::T queueidx, CListNode* node) {
547  CfdpCListInsertBack(&m_qs[queueidx], node);
548 }
549 
550 } // namespace Cfdp
551 } // namespace Ccsds
552 } // namespace Svc
553 
554 #endif // CFDP_CHANNEL_HPP
CFDP Protocol Engine.
Definition: Engine.hpp:90
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:169
History * getHistory(U32 index)
Get a history by index (for testing)
Definition: Channel.cpp:934
CFDP Transaction state machine class.
void removeFromQueue(QueueId::T queueidx, CListNode *node)
Remove a node from a channel queue.
Definition: Channel.hpp:538
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:716
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:353
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:855
U32 TransactionSeq
transaction sequence number size
Flow::T getFlowState() const
Get the flow state for this channel.
Definition: Channel.hpp:260
U32 getNumRx() const
Get the number of receive transactions currently holding a slot.
Definition: Channel.hpp:219
void cycleTx()
Cycle the TX side of this channel.
Definition: Channel.cpp:213
void decrementRxCounter()
Decrement the receive transaction counter for this channel.
Definition: Channel.cpp:704
static CListTraverseStatus cycleTxFirstActiveWrapper(CListNode *node, void *context)
Static wrapper for cycleTxFirstActive callback.
Definition: Channel.cpp:943
void resetOutgoingCounter()
Reset the outgoing PDU counter to zero.
Definition: Channel.hpp:195
void incrementRxCounter()
Increment the receive transaction counter for this channel.
Definition: Channel.hpp:224
void insertAfterInQueue(QueueId::T queueidx, CListNode *start, CListNode *after)
Insert a node after another in a channel queue.
Definition: Channel.hpp:542
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:709
void tickTransactions()
Tick all transactions on this channel.
Definition: Channel.cpp:269
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:699
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:952
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
void processPlaybackDirectories()
Process all playback directories for this channel.
Definition: Channel.cpp:336
void insertSortPrio(Transaction *txn, QueueId::T queue)
Insert a transaction into a priority sorted transaction queue.
Definition: Channel.cpp:668
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:174
Memory Allocation base class.
Transaction * getTransaction(U32 index)
Get a transaction by index (for testing)
Definition: Channel.cpp:929
void insertBackInQueue(QueueId::T queueidx, CListNode *node)
Insert a node at the back of a channel queue.
Definition: Channel.hpp:546
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:905
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:279
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:531
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:724
void setFlowState(Flow::T flowState)
Set the flow state for this channel.
Definition: Channel.hpp:253
CfdpChunkWrapper * findUnusedChunks(Direction dir)
Find unused chunks for this channel.
Definition: Channel.cpp:736
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:268
static CListTraverseStatus traverseAllTransactionsWrapper(CListNode *node, void *context)
Static wrapper for traverseAllTransactions callback.
Definition: Channel.cpp:961
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