F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ComStub.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ComStub.cpp
3 // \author mstarch
4 // \brief cpp file for ComStub component implementation class
5 // ======================================================================
6 
8 #include <Fw/Logger/Logger.hpp>
9 #include "Fw/Types/Assert.hpp"
10 #include "Fw/Types/BasicTypes.hpp"
11 
12 namespace Svc {
13 
14 // ----------------------------------------------------------------------
15 // Construction, initialization, and destruction
16 // ----------------------------------------------------------------------
17 
18 ComStub::ComStub(const char* const compName) : ComStubComponentBase(compName), m_reinitialize(true), m_retry_count(0) {}
19 
21 
22 // ----------------------------------------------------------------------
23 // Handler implementations for user-defined typed input ports
24 // ----------------------------------------------------------------------
25 
26 void ComStub::dataIn_handler(const FwIndexType portNum, Fw::Buffer& sendBuffer, const ComCfg::FrameContext& context) {
27  FW_ASSERT(!this->m_reinitialize || !this->isConnected_comStatusOut_OutputPort(0)); // A message should never get here if we need to reinitialize is needed
28  this->m_storedContext = context; // Store the context of the current message
29  this->drvSendOut_out(0, sendBuffer);
30 }
31 
32 void ComStub::drvConnected_handler(const FwIndexType portNum) {
33  Fw::Success radioSuccess = Fw::Success::SUCCESS;
34  if (this->isConnected_comStatusOut_OutputPort(0) && m_reinitialize) {
35  this->m_reinitialize = false;
36  this->comStatusOut_out(0, radioSuccess);
37  }
38 }
39 
40 void ComStub::drvReceiveIn_handler(const FwIndexType portNum,
41  Fw::Buffer& recvBuffer,
42  const Drv::ByteStreamStatus& recvStatus) {
43  if (recvStatus.e == Drv::ByteStreamStatus::OP_OK) {
44  ComCfg::FrameContext emptyContext; // ComStub knows nothing about the received bytes, so use an empty context
45  this->dataOut_out(0, recvBuffer, emptyContext);
46  } else {
47  this->drvReceiveReturnOut_out(0, recvBuffer);
48  }
49 }
50 
51 void ComStub ::drvSendReturnIn_handler(FwIndexType portNum,
52  Fw::Buffer& fwBuffer,
53  const Drv::ByteStreamStatus& sendStatus) {
54  if (sendStatus != Drv::ByteStreamStatus::SEND_RETRY) {
55  // Not retrying - return buffer ownership and send status
56  this->dataReturnOut_out(0, fwBuffer, this->m_storedContext);
57  this->m_reinitialize = sendStatus.e != Drv::ByteStreamStatus::OP_OK;
58  this->m_retry_count = 0; // Reset the retry count
60  this->comStatusOut_out(0, comSuccess);
61  } else {
62  // Driver indicates we should retry (SEND_RETRY)
63  if (this->m_retry_count < this->RETRY_LIMIT) {
64  // If we have not yet retried more than the retry limit, attempt to retry
65  this->m_retry_count++;
66  this->drvSendOut_out(0, fwBuffer);
67  } else {
68  // If retried too many times, return buffer and log failure
69  this->dataReturnOut_out(0, fwBuffer, this->m_storedContext);
70  Fw::Logger::log("ComStub RETRY_LIMIT exceeded, skipped sending data");
71  this->m_retry_count = 0; // Reset the retry count
72  }
73  }
74 }
75 
76 void ComStub ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer, const ComCfg::FrameContext& context) {
77  this->drvReceiveReturnOut_out(0, fwBuffer);
78 }
79 
80 } // end namespace Svc
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataReturnOut.
Representing success.
ComStub(const char *const compName)
Definition: ComStub.cpp:18
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
static void log(const char *format,...)
log a formated string with supplied arguments
Definition: Logger.cpp:21
Auto-generated base for ComStub component.
void drvReceiveReturnOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port drvReceiveReturnOut.
bool isConnected_comStatusOut_OutputPort(FwIndexType portNum)
void drvSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port drvSendOut.
Status returned by the send call.
Operation worked as expected.
Representing failure.
const FwIndexType RETRY_LIMIT
Definition: ComStub.hpp:19
~ComStub() override
Definition: ComStub.cpp:20
PlatformIndexType FwIndexType
C++ header for working with basic fprime types.
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
void comStatusOut_out(FwIndexType portNum, Fw::Success &condition)
Invoke output port comStatusOut.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.