F´ Flight Software - C/C++ Documentation  devel
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/Types/Assert.hpp"
10 
11 namespace Svc {
12 
13 // ----------------------------------------------------------------------
14 // Construction, initialization, and destruction
15 // ----------------------------------------------------------------------
16 
17 ComStub::ComStub(const char* const compName) : ComStubComponentBase(compName), m_reinitialize(true) {}
18 
20 
21 // ----------------------------------------------------------------------
22 // Handler implementations for user-defined typed input ports
23 // ----------------------------------------------------------------------
24 
25 Drv::SendStatus ComStub::comDataIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& sendBuffer) {
26  FW_ASSERT(!this->m_reinitialize || !this->isConnected_comStatus_OutputPort(0)); // A message should never get here if we need to reinitialize is needed
28  for (NATIVE_UINT_TYPE i = 0; driverStatus == Drv::SendStatus::SEND_RETRY && i < RETRY_LIMIT; i++) {
29  driverStatus = this->drvDataOut_out(0, sendBuffer);
30  }
31  FW_ASSERT(driverStatus != Drv::SendStatus::SEND_RETRY); // If it is still in retry state, there is no good answer
33  this->m_reinitialize = driverStatus.e != Drv::SendStatus::SEND_OK;
34  if (this->isConnected_comStatus_OutputPort(0)) {
35  this->comStatus_out(0, comSuccess);
36  }
37  return Drv::SendStatus::SEND_OK; // Always send ok to deframer as it does not handle this anyway
38 }
39 
40 void ComStub::drvConnected_handler(const NATIVE_INT_TYPE portNum) {
41  Fw::Success radioSuccess = Fw::Success::SUCCESS;
42  if (this->isConnected_comStatus_OutputPort(0) && m_reinitialize) {
43  this->m_reinitialize = false;
44  this->comStatus_out(0, radioSuccess);
45  }
46 }
47 
48 void ComStub::drvDataIn_handler(const NATIVE_INT_TYPE portNum,
49  Fw::Buffer& recvBuffer,
50  const Drv::RecvStatus& recvStatus) {
51  this->comDataOut_out(0, recvBuffer, recvStatus);
52 }
53 
54 } // end namespace Svc
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
C++ header for working with basic fprime types.
Status associated with the received data.
Status returned by the send call.
T e
The raw enum value.
@ SEND_RETRY
Data send should be retried.
@ SEND_OK
Send worked as expected.
Success/Failure.
@ FAILURE
Representing failure.
@ SUCCESS
Representing success.
Auto-generated base for ComStub component.
bool isConnected_comStatus_OutputPort(FwIndexType portNum)
void comStatus_out(FwIndexType portNum, Fw::Success &condition)
Invoke output port comStatus.
void comDataOut_out(FwIndexType portNum, Fw::Buffer &recvBuffer, const Drv::RecvStatus &recvStatus)
Invoke output port comDataOut.
Drv::SendStatus drvDataOut_out(FwIndexType portNum, Fw::Buffer &sendBuffer)
Invoke output port drvDataOut.
const NATIVE_UINT_TYPE RETRY_LIMIT
Definition: ComStub.hpp:16
~ComStub() override
Definition: ComStub.cpp:19
ComStub(const char *const compName)
Definition: ComStub.cpp:17