F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
11namespace Svc {
12
13// ----------------------------------------------------------------------
14// Construction, initialization, and destruction
15// ----------------------------------------------------------------------
16
17ComStub::ComStub(const char* const compName) : ComStubComponentBase(compName), m_reinitialize(true) {}
18
19void ComStub::init(const NATIVE_INT_TYPE instance) {
20 ComStubComponentBase::init(instance);
21}
22
24
25// ----------------------------------------------------------------------
26// Handler implementations for user-defined typed input ports
27// ----------------------------------------------------------------------
28
29Drv::SendStatus ComStub::comDataIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& sendBuffer) {
30 FW_ASSERT(!this->m_reinitialize || !this->isConnected_comStatus_OutputPort(0)); // A message should never get here if we need to reinitialize is needed
31 Drv::SendStatus driverStatus = Drv::SendStatus::SEND_RETRY;
32 for (NATIVE_UINT_TYPE i = 0; driverStatus == Drv::SendStatus::SEND_RETRY && i < RETRY_LIMIT; i++) {
33 driverStatus = this->drvDataOut_out(0, sendBuffer);
34 }
35 FW_ASSERT(driverStatus != Drv::SendStatus::SEND_RETRY); // If it is still in retry state, there is no good answer
36 Fw::Success comSuccess = (driverStatus.e == Drv::SendStatus::SEND_OK) ? Fw::Success::SUCCESS : Fw::Success::FAILURE;
37 this->m_reinitialize = driverStatus.e != Drv::SendStatus::SEND_OK;
38 if (this->isConnected_comStatus_OutputPort(0)) {
39 this->comStatus_out(0, comSuccess);
40 }
41 return Drv::SendStatus::SEND_OK; // Always send ok to deframer as it does not handle this anyway
42}
43
44void ComStub::drvConnected_handler(const NATIVE_INT_TYPE portNum) {
45 Fw::Success radioSuccess = Fw::Success::SUCCESS;
46 if (this->isConnected_comStatus_OutputPort(0) && m_reinitialize) {
47 this->m_reinitialize = false;
48 this->comStatus_out(0, radioSuccess);
49 }
50}
51
52void ComStub::drvDataIn_handler(const NATIVE_INT_TYPE portNum,
53 Fw::Buffer& recvBuffer,
54 const Drv::RecvStatus& recvStatus) {
55 this->comDataOut_out(0, recvBuffer, recvStatus);
56}
57
58} // end namespace Svc
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
C++ header for working with basic fprime types.
const NATIVE_UINT_TYPE RETRY_LIMIT
Definition ComStub.hpp:16
~ComStub() override
Definition ComStub.cpp:23
void init(const NATIVE_INT_TYPE instance=0)
Definition ComStub.cpp:19
ComStub(const char *const compName)
Definition ComStub.cpp:17
Definition Buffer.cpp:21