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 
45 
46 // Forward declarations - do NOT include CfdpManager.hpp to avoid circular dependency
47 namespace Svc {
48 namespace Ccsds {
49 class CfdpManager; // CfdpManager stays in Svc::Ccsds
50 namespace Cfdp {
51 class Channel; // Channel is in Svc::Ccsds::Cfdp
52 }
53 } // namespace Ccsds
54 } // namespace Svc
55 
56 namespace Svc {
57 namespace Ccsds {
58 namespace Cfdp {
59 
63 struct CycleTxArgs {
65  I32 ran_one;
66 };
67 
71 struct TickArgs {
73  void (Transaction::*fn)(I32*);
74  bool early_exit;
75  I32 cont;
76 };
77 
90 class Engine {
91  public:
92  // ----------------------------------------------------------------------
93  // Construction and destruction
94  // ----------------------------------------------------------------------
95 
101  explicit Engine(CfdpManager* manager);
102 
109  virtual ~Engine();
110 
111  // ----------------------------------------------------------------------
112  // Public interface
113  // ----------------------------------------------------------------------
114 
120  void init(Fw::MemAllocator& allocator, FwEnumStoreType memId);
121 
127  void cycle();
128 
135  void receivePdu(U8 chan_id, const Fw::Buffer& buffer);
136 
150  Status::T txFile(const Fw::String& src,
151  const Fw::String& dst,
152  Class::T cfdp_class,
153  Keep::T keep,
154  U8 chan_num,
155  U8 priority,
156  EntityId dest_id,
158 
171  Status::T playbackDir(const Fw::String& src,
172  const Fw::String& dst,
173  Class::T cfdp_class,
174  Keep::T keep,
175  U8 chan,
176  U8 priority,
177  EntityId dest_id);
178 
192  Status::T startPollDir(U8 chanId,
193  U8 pollId,
194  const Fw::String& srcDir,
195  const Fw::String& dstDir,
196  Class::T cfdp_class,
197  U8 priority,
198  EntityId destEid,
199  U32 intervalSec);
200 
208  Status::T stopPollDir(U8 chanId, U8 pollId);
209 
218  void setChannelFlowState(U8 channelId, Flow::T flowState);
219 
230  TransactionSeq transactionSeq,
231  EntityId entityId,
232  SuspendResume::T action);
233 
242  Status::T cancelTransactionBySeq(U8 channelId, TransactionSeq transactionSeq, EntityId entityId);
243 
252  Status::T abandonTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId);
253 
254  // ----------------------------------------------------------------------
255  // Public Transaction Interface
256  // Methods used by CfdpRx/CfdpTx transaction processing
257  // ----------------------------------------------------------------------
258 
275  void finishTransaction(Transaction* txn, bool keep_history);
276 
281 
291  void setTxnStatus(Transaction* txn, TxnStatus txn_stat);
292 
301  void armAckTimer(Transaction* txn);
302 
311  void armInactTimer(Transaction* txn);
312 
331  virtual Status::T sendMd(Transaction* txn);
332 
348  Status::T sendFd(Transaction* txn, FileDataPdu& fdPdu);
349 
365 
391  AckTxnStatus ts,
392  FileDirective dir_code,
393  ConditionCode cc,
394  EntityId peer_eid,
395  TransactionSeq tsn);
396 
415 
433  Status::T sendNak(Transaction* txn, NakPdu& nakPdu);
434 
467  Status::T recvMd(Transaction* txn, const MetadataPdu& pdu);
468 
483  bool validateRxDestPath(U8 chan_num, Fw::String& path, RxDestPathRejectReason& reason);
484 
499  Status::T recvFd(Transaction* txn, const FileDataPdu& pdu);
500 
514  Status::T recvEof(Transaction* txn, const EofPdu& pdu);
515 
529  Status::T recvFin(Transaction* txn, const FinPdu& pdu);
530 
544  Status::T recvNak(Transaction* txn, const NakPdu& pdu);
545 
556  void txFileInitiate(Transaction* txn, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id);
557 
572  const Fw::String& src_filename,
573  const Fw::String& dst_filename,
574  Class::T cfdp_class,
575  Keep::T keep,
576  U8 chan,
577  U8 priority,
578  EntityId dest_id);
579 
587  void dispatchTx(Transaction* txn);
588 
598 
599  private:
600  // ----------------------------------------------------------------------
601  // Private member variables
602  // ----------------------------------------------------------------------
603 
605  CfdpManager* m_manager;
606 
608  Channel* m_channels[Cfdp::NumChannels];
609 
611  TransactionSeq m_seqNum;
612 
614  Fw::MemAllocator* m_allocator;
615 
617  FwEnumStoreType m_allocatorId;
618 
619  // Note: Transactions, histories, and chunks are now owned by each Channel
620 
621  // ----------------------------------------------------------------------
622  // Private helper methods
623  // All the non-public CFDP functions converted to methods
624  // ----------------------------------------------------------------------
625 
626  // Transaction Management
627 
633  void cancelTransaction(Transaction* txn);
634 
648  Transaction* startRxTransaction(U8 chan_num);
649 
650  // PDU Operations - Send
651 
666  Status::T serializeAndSendPdu(Transaction* txn, PduBase& pdu);
667 
680  Status::T serializeAndSendPduOnChannel(Channel& chan, PduBase& pdu);
681 
697  Status::T sendFinAckStateless(Channel& chan,
698  TransactionSeq tsn,
699  EntityId finSrcEid,
700  EntityId finDstEid,
701  ConditionCode cc);
702 
703  // PDU Operations - Receive
704 
714  void recvDrop(Transaction* txn, const Fw::Buffer& buffer);
715 
728  void recvHold(Transaction* txn, const Fw::Buffer& buffer);
729 
743  bool recvInit(Transaction* txn, const Fw::Buffer& buffer);
744 
745  // Dispatch
746 
756  void dispatchRecv(Transaction* txn, const Fw::Buffer& buffer);
757 
758  // Channel Processing
759 
768  bool isPollingDir(const Fw::StringBase& src_file, U8 chan_num);
769 
777  void handleNotKeepFile(Transaction* txn);
778 
779  // Friend declarations for testing
780  friend class CfdpManagerTester;
781 };
782 
783 } // namespace Cfdp
784 } // namespace Ccsds
785 } // namespace Svc
786 
787 #endif /* !CFDP_ENGINE_HPP */
Status::T recvFd(Transaction *txn, const FileDataPdu &pdu)
Unpack a file data PDU from a received message.
Definition: Engine.cpp:472
CFDP Protocol Engine.
Definition: Engine.hpp:90
Status::T sendEof(Transaction *txn)
Create, encode, and send an EOF (End of File) PDU.
Definition: Engine.cpp:227
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:836
CFDP Channel class.
Definition: Channel.hpp:56
Structure for use with the Channel::doTick() function.
Definition: Engine.hpp:71
Status::T stopPollDir(U8 chanId, U8 pollId)
Stop polling a directory.
Definition: Engine.cpp:1010
Status::T recvMd(Transaction *txn, const MetadataPdu &pdu)
Handle receipt of metadata PDU.
Definition: Engine.cpp:442
bool early_exit
early exit result
Definition: Engine.hpp:74
CFDP Transaction state machine class.
Status::T cancelTransactionBySeq(U8 channelId, TransactionSeq transactionSeq, EntityId entityId)
Cancel a transaction with graceful close-out.
Definition: Engine.cpp:783
I32 FwEnumStoreType
void(Transaction::* fn)(I32 *)
member function pointer
Definition: Engine.hpp:73
void init(Fw::MemAllocator &allocator, FwEnumStoreType memId)
Initialize the CFDP engine.
Definition: Engine.cpp:89
U32 EntityId
Entity id size.
Transaction initiated via command interface.
I32 cont
if 1, then re-traverse the list
Definition: Engine.hpp:75
void abandonInitTransaction(Transaction *txn)
Definition: Engine.cpp:675
T
The raw enum type.
Channel * chan
channel object
Definition: Engine.hpp:64
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:262
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:973
CFDP Playback entry.
Definition: Types.hpp:278
I32 ran_one
should be set to 1 if a transaction was cycled
Definition: Engine.hpp:65
void finishTransaction(Transaction *txn, bool keep_history)
Finish a transaction.
Definition: Engine.cpp:1066
U32 TransactionSeq
transaction sequence number size
friend class CfdpManagerTester
Definition: Engine.hpp:780
Channel * chan
channel object
Definition: Engine.hpp:72
T
The raw enum type.
Definition: KeepEnumAc.hpp:36
virtual ~Engine()
Destroy the Engine object.
Definition: Engine.cpp:67
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:759
Status::T sendNak(Transaction *txn, NakPdu &nakPdu)
Encode and send a NAK (Negative Acknowledgment) PDU.
Definition: Engine.cpp:332
Engine(CfdpManager *manager)
Construct a new Engine object.
Definition: Engine.cpp:61
bool validateRxDestPath(U8 chan_num, Fw::String &path, RxDestPathRejectReason &reason)
Validate and canonicalize a received destination path against the channel rx_dir. ...
Definition: Engine.cpp:405
virtual Status::T sendMd(Transaction *txn)
Create, encode, and send a Metadata PDU.
Definition: Engine.cpp:189
void receivePdu(U8 chan_id, const Fw::Buffer &buffer)
Receive and process a PDU.
Definition: Engine.cpp:685
Structure for use with the Channel::cycleTx() function.
Definition: Engine.hpp:63
Status::T recvNak(Transaction *txn, const NakPdu &pdu)
Unpack a NAK PDU from a received message.
Definition: Engine.cpp:524
void armInactTimer(Transaction *txn)
Arm the inactivity timer for a transaction.
Definition: Engine.cpp:110
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:174
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:817
void setTxnStatus(Transaction *txn, TxnStatus txn_stat)
Helper function to store transaction status code only.
Definition: Engine.cpp:1172
Status::T sendFd(Transaction *txn, FileDataPdu &fdPdu)
Encode and send a File Data PDU.
Definition: Engine.cpp:219
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:910
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:1284
void cycle()
Cycle the engine once per scheduler call.
Definition: Engine.cpp:1040
Memory Allocation base class.
Status::T recvFin(Transaction *txn, const FinPdu &pdu)
Unpack an FIN PDU from a received message.
Definition: Engine.cpp:507
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:764
Why a received Metadata PDU destination path was rejected by the channel rx_dir check.
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:305
Status::T abandonTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId)
Abandon a transaction immediately.
Definition: Engine.cpp:799
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:105
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:944
Status::T recvEof(Transaction *txn, const EofPdu &pdu)
Unpack an EOF PDU from a received message.
Definition: Engine.cpp:490