F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Engine.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Engine.hpp
3 // \brief CFDP Engine header
4 //
5 // This file is a port of CFDP engine definitions 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.h (CFDP engine and packet parsing definitions)
9 //
10 // CFDP engine and packet parsing header file
11 //
12 // ======================================================================
13 //
14 // NASA Docket No. GSC-18,447-1
15 //
16 // Copyright (c) 2019 United States Government as represented by the
17 // Administrator of the National Aeronautics and Space Administration.
18 // All Rights Reserved.
19 //
20 // Licensed under the Apache License, Version 2.0 (the "License"); you may
21 // not use this file except in compliance with the License. You may obtain
22 // a copy of the License at
23 //
24 // http://www.apache.org/licenses/LICENSE-2.0
25 //
26 // Unless required by applicable law or agreed to in writing, software
27 // distributed under the License is distributed on an "AS IS" BASIS,
28 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 // See the License for the specific language governing permissions and
30 // limitations under the License.
31 //
32 // ======================================================================
33 
34 #ifndef CFDP_ENGINE_HPP
35 #define CFDP_ENGINE_HPP
36 
37 #include <Fw/FPrimeBasicTypes.hpp>
39 
44 
45 // Forward declarations - do NOT include CfdpManager.hpp to avoid circular dependency
46 namespace Svc {
47 namespace Ccsds {
48 class CfdpManager; // CfdpManager stays in Svc::Ccsds
49 namespace Cfdp {
50 class Channel; // Channel is in Svc::Ccsds::Cfdp
51 }
52 } // namespace Ccsds
53 } // namespace Svc
54 
55 namespace Svc {
56 namespace Ccsds {
57 namespace Cfdp {
58 
62 struct CycleTxArgs {
64  I32 ran_one;
65 };
66 
70 struct TickArgs {
72  void (Transaction::*fn)(I32*);
73  bool early_exit;
74  I32 cont;
75 };
76 
89 class Engine {
90  public:
91  // ----------------------------------------------------------------------
92  // Construction and destruction
93  // ----------------------------------------------------------------------
94 
100  explicit Engine(CfdpManager* manager);
101 
108  virtual ~Engine();
109 
110  // ----------------------------------------------------------------------
111  // Public interface
112  // ----------------------------------------------------------------------
113 
119  void init(Fw::MemAllocator& allocator, FwEnumStoreType memId);
120 
126  void cycle();
127 
134  void receivePdu(U8 chan_id, const Fw::Buffer& buffer);
135 
149  Status::T txFile(const Fw::String& src,
150  const Fw::String& dst,
151  Class::T cfdp_class,
152  Keep::T keep,
153  U8 chan_num,
154  U8 priority,
155  EntityId dest_id,
157 
170  Status::T playbackDir(const Fw::String& src,
171  const Fw::String& dst,
172  Class::T cfdp_class,
173  Keep::T keep,
174  U8 chan,
175  U8 priority,
176  EntityId dest_id);
177 
191  Status::T startPollDir(U8 chanId,
192  U8 pollId,
193  const Fw::String& srcDir,
194  const Fw::String& dstDir,
195  Class::T cfdp_class,
196  U8 priority,
197  EntityId destEid,
198  U32 intervalSec);
199 
207  Status::T stopPollDir(U8 chanId, U8 pollId);
208 
217  void setChannelFlowState(U8 channelId, Flow::T flowState);
218 
229  TransactionSeq transactionSeq,
230  EntityId entityId,
231  SuspendResume::T action);
232 
241  Status::T cancelTransactionBySeq(U8 channelId, TransactionSeq transactionSeq, EntityId entityId);
242 
251  Status::T abandonTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId);
252 
253  // ----------------------------------------------------------------------
254  // Public Transaction Interface
255  // Methods used by CfdpRx/CfdpTx transaction processing
256  // ----------------------------------------------------------------------
257 
274  void finishTransaction(Transaction* txn, bool keep_history);
275 
285  void setTxnStatus(Transaction* txn, TxnStatus txn_stat);
286 
295  void armAckTimer(Transaction* txn);
296 
305  void armInactTimer(Transaction* txn);
306 
325  virtual Status::T sendMd(Transaction* txn);
326 
342  Status::T sendFd(Transaction* txn, FileDataPdu& fdPdu);
343 
359 
385  AckTxnStatus ts,
386  FileDirective dir_code,
387  ConditionCode cc,
388  EntityId peer_eid,
389  TransactionSeq tsn);
390 
409 
427  Status::T sendNak(Transaction* txn, NakPdu& nakPdu);
428 
438  void recvMd(Transaction* txn, const MetadataPdu& pdu);
439 
454  Status::T recvFd(Transaction* txn, const FileDataPdu& pdu);
455 
469  Status::T recvEof(Transaction* txn, const EofPdu& pdu);
470 
484  Status::T recvFin(Transaction* txn, const FinPdu& pdu);
485 
499  Status::T recvNak(Transaction* txn, const NakPdu& pdu);
500 
511  void txFileInitiate(Transaction* txn, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id);
512 
527  const Fw::String& src_filename,
528  const Fw::String& dst_filename,
529  Class::T cfdp_class,
530  Keep::T keep,
531  U8 chan,
532  U8 priority,
533  EntityId dest_id);
534 
542  void dispatchTx(Transaction* txn);
543 
553 
554  private:
555  // ----------------------------------------------------------------------
556  // Private member variables
557  // ----------------------------------------------------------------------
558 
560  CfdpManager* m_manager;
561 
563  Channel* m_channels[Cfdp::NumChannels];
564 
566  TransactionSeq m_seqNum;
567 
569  Fw::MemAllocator* m_allocator;
570 
572  FwEnumStoreType m_allocatorId;
573 
574  // Note: Transactions, histories, and chunks are now owned by each Channel
575 
576  // ----------------------------------------------------------------------
577  // Private helper methods
578  // All the non-public CFDP functions converted to methods
579  // ----------------------------------------------------------------------
580 
581  // Transaction Management
582 
588  void cancelTransaction(Transaction* txn);
589 
603  Transaction* startRxTransaction(U8 chan_num);
604 
605  // PDU Operations - Send
606 
621  Status::T serializeAndSendPdu(Transaction* txn, PduBase& pdu);
622 
635  Status::T serializeAndSendPduOnChannel(Channel& chan, PduBase& pdu);
636 
652  Status::T sendFinAckStateless(Channel& chan,
653  TransactionSeq tsn,
654  EntityId finSrcEid,
655  EntityId finDstEid,
656  ConditionCode cc);
657 
658  // PDU Operations - Receive
659 
669  void recvDrop(Transaction* txn, const Fw::Buffer& buffer);
670 
683  void recvHold(Transaction* txn, const Fw::Buffer& buffer);
684 
698  bool recvInit(Transaction* txn, const Fw::Buffer& buffer);
699 
700  // Dispatch
701 
711  void dispatchRecv(Transaction* txn, const Fw::Buffer& buffer);
712 
713  // Channel Processing
714 
723  bool isPollingDir(const Fw::StringBase& src_file, U8 chan_num);
724 
732  void handleNotKeepFile(Transaction* txn);
733 
734  // Friend declarations for testing
735  friend class CfdpManagerTester;
736 };
737 
738 } // namespace Cfdp
739 } // namespace Ccsds
740 } // namespace Svc
741 
742 #endif /* !CFDP_ENGINE_HPP */
Status::T recvFd(Transaction *txn, const FileDataPdu &pdu)
Unpack a file data PDU from a received message.
Definition: Engine.cpp:412
CFDP Protocol Engine.
Definition: Engine.hpp:89
Status::T sendEof(Transaction *txn)
Create, encode, and send an EOF (End of File) PDU.
Definition: Engine.cpp:222
TransactionInitType
Transaction initiation method.
Definition: Types.hpp:165
Status::T txFile(const Fw::String &src, const Fw::String &dst, Class::T cfdp_class, Keep::T keep, U8 chan_num, U8 priority, EntityId dest_id, TransactionInitType initType=TransactionInitType::INIT_BY_COMMAND)
Begin transmit of a file.
Definition: Engine.cpp:746
CFDP Channel class.
Definition: Channel.hpp:56
Structure for use with the Channel::doTick() function.
Definition: Engine.hpp:70
Status::T stopPollDir(U8 chanId, U8 pollId)
Stop polling a directory.
Definition: Engine.cpp:921
bool early_exit
early exit result
Definition: Engine.hpp:73
CFDP Transaction state machine class.
Status::T cancelTransactionBySeq(U8 channelId, TransactionSeq transactionSeq, EntityId entityId)
Cancel a transaction with graceful close-out.
Definition: Engine.cpp:695
I32 FwEnumStoreType
void(Transaction::* fn)(I32 *)
member function pointer
Definition: Engine.hpp:72
void init(Fw::MemAllocator &allocator, FwEnumStoreType memId)
Initialize the CFDP engine.
Definition: Engine.cpp:88
void recvMd(Transaction *txn, const MetadataPdu &pdu)
Handle receipt of metadata PDU.
Definition: Engine.cpp:400
U32 EntityId
Entity id size.
Transaction initiated via command interface.
I32 cont
if 1, then re-traverse the list
Definition: Engine.hpp:74
T
The raw enum type.
Channel * chan
channel object
Definition: Engine.hpp:63
Status::T sendAck(Transaction *txn, AckTxnStatus ts, FileDirective dir_code, ConditionCode cc, EntityId peer_eid, TransactionSeq tsn)
Create, encode, and send an ACK (Acknowledgment) PDU.
Definition: Engine.cpp:257
TxnStatus
Values for Transaction Status code.
Definition: Types.hpp:193
Status::T startPollDir(U8 chanId, U8 pollId, const Fw::String &srcDir, const Fw::String &dstDir, Class::T cfdp_class, U8 priority, EntityId destEid, U32 intervalSec)
Start polling a directory.
Definition: Engine.cpp:884
CFDP Playback entry.
Definition: Types.hpp:278
I32 ran_one
should be set to 1 if a transaction was cycled
Definition: Engine.hpp:64
void finishTransaction(Transaction *txn, bool keep_history)
Finish a transaction.
Definition: Engine.cpp:977
U32 TransactionSeq
transaction sequence number size
friend class CfdpManagerTester
Definition: Engine.hpp:735
Channel * chan
channel object
Definition: Engine.hpp:71
T
The raw enum type.
Definition: KeepEnumAc.hpp:36
virtual ~Engine()
Destroy the Engine object.
Definition: Engine.cpp:66
The type of a File Data PDU.
Definition: FileDataPdu.hpp:19
void setChannelFlowState(U8 channelId, Flow::T flowState)
Set channel flow state.
Definition: Engine.cpp:671
Status::T sendNak(Transaction *txn, NakPdu &nakPdu)
Encode and send a NAK (Negative Acknowledgment) PDU.
Definition: Engine.cpp:327
Engine(CfdpManager *manager)
Construct a new Engine object.
Definition: Engine.cpp:60
virtual Status::T sendMd(Transaction *txn)
Create, encode, and send a Metadata PDU.
Definition: Engine.cpp:184
void receivePdu(U8 chan_id, const Fw::Buffer &buffer)
Receive and process a PDU.
Definition: Engine.cpp:597
Structure for use with the Channel::cycleTx() function.
Definition: Engine.hpp:62
Status::T recvNak(Transaction *txn, const NakPdu &pdu)
Unpack a NAK PDU from a received message.
Definition: Engine.cpp:464
void armInactTimer(Transaction *txn)
Arm the inactivity timer for a transaction.
Definition: Engine.cpp:109
The type of a Metadata PDU.
Definition: MetadataPdu.hpp:20
The type of a Finished PDU.
Definition: FinPdu.hpp:19
void dispatchTx(Transaction *txn)
Dispatch TX state machine for a transaction.
Definition: Engine.cpp:169
void txFileInitiate(Transaction *txn, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Initiate a file transfer transaction.
Definition: Engine.cpp:727
void setTxnStatus(Transaction *txn, TxnStatus txn_stat)
Helper function to store transaction status code only.
Definition: Engine.cpp:1070
Status::T sendFd(Transaction *txn, FileDataPdu &fdPdu)
Encode and send a File Data PDU.
Definition: Engine.cpp:214
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.
Definition: Engine.cpp:821
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
Cfdp::ChannelTelemetry & getChannelTelemetryRef(U8 channelId)
Get reference to channel telemetry for Channel class.
Definition: Engine.cpp:1182
void cycle()
Cycle the engine once per scheduler call.
Definition: Engine.cpp:951
Memory Allocation base class.
Status::T recvFin(Transaction *txn, const FinPdu &pdu)
Unpack an FIN PDU from a received message.
Definition: Engine.cpp:447
Structure for the telemetry array of CFDP channels.
RateGroupDivider component implementation.
Status::T setSuspendResumeTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId, SuspendResume::T action)
Set transaction suspend state.
Definition: Engine.cpp:676
Defines a base class for a memory allocator for classes.
The type of an EOF PDU.
Definition: EofPdu.hpp:19
Status::T sendFin(Transaction *txn, FinDeliveryCode dc, FinFileStatus fs, ConditionCode cc)
Create, encode, and send a FIN (Finished) PDU.
Definition: Engine.cpp:300
Status::T abandonTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId)
Abandon a transaction immediately.
Definition: Engine.cpp:711
T
The raw enum type.
Definition: ClassEnumAc.hpp:42
T
The raw enum type.
Definition: FlowEnumAc.hpp:35
The type of a NAK PDU.
Definition: NakPdu.hpp:24
void armAckTimer(Transaction *txn)
Arm the ACK timer for a transaction.
Definition: Engine.cpp:104
Status::T playbackDir(const Fw::String &src, const Fw::String &dst, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Begin transmit of a directory.
Definition: Engine.cpp:855
Status::T recvEof(Transaction *txn, const EofPdu &pdu)
Unpack an EOF PDU from a received message.
Definition: Engine.cpp:430