F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ComRetry.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ComRetry.cpp
3 // \author valdaarhun
4 // \brief cpp file for ComRetry component implementation class
5 // ======================================================================
6 
8 #include "ComRetry.hpp"
9 
10 namespace Svc {
11 
12 // ----------------------------------------------------------------------
13 // Component construction and destruction
14 // ----------------------------------------------------------------------
15 
16 ComRetry ::ComRetry(const char* const compName)
17  : ComRetryComponentBase(compName),
18  m_num_retries(3),
19  m_retry_count(0),
20  m_retry_state(WAITING_FOR_SEND),
21  m_bufferState(Fw::Buffer::OwnershipState::OWNED) {}
22 
24 
25 void ComRetry::configure(U32 num_retries) {
26  this->m_num_retries = num_retries;
27 }
28 
29 // ----------------------------------------------------------------------
30 // Handler implementations for typed input ports
31 // ----------------------------------------------------------------------
32 
33 void ComRetry ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
34  FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
35 
36  // When waiting for send, just pass the status up the stack as the buffer should still be upstream
37  if (this->m_retry_state == WAITING_FOR_SEND) {
38  FW_ASSERT(!this->m_buffer.isValid());
39  this->comStatusOut_out(0, condition);
40  }
41  // Nominal case where delivery of buffer is successful, and everything is passed back up the stack
42  else if ((this->m_retry_state == WAITING_FOR_STATUS) && (condition == Fw::Success::SUCCESS)) {
43  FW_ASSERT(this->m_buffer.isValid());
44  this->m_retry_state = WAITING_FOR_SEND; // Successful transmission, reset state
45  this->dataReturnOut_out(0, this->m_buffer, this->m_context);
46  this->m_buffer = Fw::Buffer(); // Clear buffer
47  this->comStatusOut_out(0, condition);
48  }
49  // When retrying, and "success" is received, this is the retry case
50  else if ((this->m_retry_state == RETRYING) && (condition == Fw::Success::SUCCESS)) {
51  FW_ASSERT(this->m_buffer.isValid());
52  this->m_retry_count++;
53  this->m_retry_state = WAITING_FOR_STATUS;
54  this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
55  this->dataOut_out(0, this->m_buffer, this->m_context);
56  } else {
57  // When a failure has been seen, it can **only** be in WAITING_FOR_STATUS state
58  FW_ASSERT(this->m_retry_state == WAITING_FOR_STATUS);
59  FW_ASSERT(condition == Fw::Success::FAILURE);
60 
61  // If we have retries left then switch to RETRYING, and wait for success
62  if (this->m_retry_count < this->m_num_retries) {
63  this->m_retry_state = RETRYING;
64  }
65  // If no retries left, pass failure back up the stack and reset state
66  else {
67  this->m_retry_state = WAITING_FOR_SEND;
68  this->dataReturnOut_out(0, this->m_buffer, this->m_context);
69  this->m_buffer = Fw::Buffer(); // Clear buffer
70  this->comStatusOut_out(0, condition);
71  }
72  }
73 }
74 
75 void ComRetry ::dataIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
76  FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
77  FW_ASSERT(this->m_retry_state == WAITING_FOR_SEND);
78  this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
79  this->m_retry_state = WAITING_FOR_STATUS;
80  this->m_retry_count = 0;
81  this->dataOut_out(0, buffer, context);
82 }
83 
84 void ComRetry ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
85  FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::NOT_OWNED);
86  FW_ASSERT(this->m_retry_state == WAITING_FOR_STATUS);
87  this->m_bufferState = Fw::Buffer::OwnershipState::OWNED;
88  this->m_buffer = buffer;
89  this->m_context = context;
90 }
91 
92 } // namespace Svc
Auto-generated base for ComRetry component.
Representing success.
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataReturnOut.
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
~ComRetry()
Destroy ComRetry object.
Definition: ComRetry.cpp:23
The buffer is currently not owned.
bool isValid() const
Definition: Buffer.cpp:52
ComRetry(const char *const compName)
Construct ComRetry object.
Definition: ComRetry.cpp:16
Representing failure.
void configure(U32 num_retries)
Configure the number of retries.
Definition: ComRetry.cpp:25
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
The buffer is currently owned.
Implementation of malloc based allocator.
void comStatusOut_out(FwIndexType portNum, Fw::Success &condition)
Invoke output port comStatusOut.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.