F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
ComPortAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ComPortAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for Com port
5 // ======================================================================
6 
8 #include "Fw/Types/Assert.hpp"
10 
11 namespace Fw {
12 
13  namespace {
14 
15  // ----------------------------------------------------------------------
16  // Port buffer class
17  // ----------------------------------------------------------------------
18 
19  class ComPortBuffer : public Fw::SerializeBufferBase {
20 
21  public:
22 
23  Fw::Serializable::SizeType getBuffCapacity() const {
25  }
26 
27  U8* getBuffAddr() {
28  return m_buff;
29  }
30 
31  const U8* getBuffAddr() const {
32  return m_buff;
33  }
34 
35  private:
36 
38 
39  };
40 
41  }
42 
43  // ----------------------------------------------------------------------
44  // Input Port Member functions
45  // ----------------------------------------------------------------------
46 
48  InputComPort() :
49  Fw::InputPortBase(),
50  m_func(nullptr)
51  {
52 
53  }
54 
56  init()
57  {
59  }
60 
63  Fw::PassiveComponentBase* callComp,
64  CompFuncPtr funcPtr
65  )
66  {
67  FW_ASSERT(callComp != nullptr);
68  FW_ASSERT(funcPtr != nullptr);
69 
70  this->m_comp = callComp;
71  this->m_func = funcPtr;
72  this->m_connObj = callComp;
73  }
74 
76  invoke(
77  Fw::ComBuffer& data,
78  U32 context
79  )
80  {
81 #if FW_PORT_TRACING == 1
82  this->trace();
83 #endif
84 
85  FW_ASSERT(this->m_comp != nullptr);
86  FW_ASSERT(this->m_func != nullptr);
87 
88  return this->m_func(this->m_comp, this->m_portNum, data, context);
89  }
90 
91 #if FW_PORT_SERIALIZATION == 1
92 
93  Fw::SerializeStatus InputComPort ::
94  invokeSerial(Fw::SerializeBufferBase& _buffer)
95  {
96  Fw::SerializeStatus _status;
97 
98 #if FW_PORT_TRACING == 1
99  this->trace();
100 #endif
101 
102  FW_ASSERT(this->m_comp != nullptr);
103  FW_ASSERT(this->m_func != nullptr);
104 
105  Fw::ComBuffer data;
106  _status = _buffer.deserialize(data);
107  if (_status != Fw::FW_SERIALIZE_OK) {
108  return _status;
109  }
110 
111  U32 context;
112  _status = _buffer.deserialize(context);
113  if (_status != Fw::FW_SERIALIZE_OK) {
114  return _status;
115  }
116 
117  this->m_func(this->m_comp, this->m_portNum, data, context);
118 
119  return Fw::FW_SERIALIZE_OK;
120  }
121 
122 #endif
123 
124  // ----------------------------------------------------------------------
125  // Output Port Member functions
126  // ----------------------------------------------------------------------
127 
129  OutputComPort() :
130  Fw::OutputPortBase(),
131  m_port(nullptr)
132  {
133 
134  }
135 
137  init()
138  {
140  }
141 
143  addCallPort(InputComPort* callPort)
144  {
145  FW_ASSERT(callPort != nullptr);
146 
147  this->m_port = callPort;
148  this->m_connObj = callPort;
149 
150 #if FW_PORT_SERIALIZATION == 1
151  this->m_serPort = nullptr;
152 #endif
153  }
154 
156  invoke(
157  Fw::ComBuffer& data,
158  U32 context
159  )
160  {
161 #if FW_PORT_TRACING == 1
162  this->trace();
163 #endif
164 
165 #if FW_PORT_SERIALIZATION
166  FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));
167 
168  if (this->m_port != nullptr) {
169  this->m_port->invoke(data, context);
170  }
171  else {
172  Fw::SerializeStatus _status;
173  ComPortBuffer _buffer;
174 
175  _status = _buffer.serialize(data);
176  FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
177 
178  _status = _buffer.serialize(context);
179  FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
180 
181  _status = this->m_serPort->invokeSerial(_buffer);
182  FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
183  }
184 #else
185  FW_ASSERT(this->m_port != nullptr);
186  this->m_port->invoke(data, context);
187 #endif
188  }
189 
190 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:39
void invoke(Fw::ComBuffer &data, U32 context)
Invoke a port interface.
Definition: ComPortAc.cpp:76
@ SERIALIZED_SIZE
The size of the serial representations of the port arguments.
Definition: ComPortAc.hpp:37
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Definition: ComPortAc.cpp:62
InputComPort()
Constructor.
Definition: ComPortAc.cpp:48
void init()
Initialization function.
Definition: ComPortAc.cpp:56
NATIVE_INT_TYPE m_portNum
virtual void init()
PassiveComponentBase * m_comp
void addCallPort(InputComPort *callPort)
Register an input port.
Definition: ComPortAc.cpp:143
OutputComPort()
Constructor.
Definition: ComPortAc.cpp:129
void init()
Initialization function.
Definition: ComPortAc.cpp:137
void invoke(Fw::ComBuffer &data, U32 context)
Invoke a port interface.
Definition: ComPortAc.cpp:156
virtual void init()
Fw::ObjBase * m_connObj
Definition: PortBase.hpp:33
NATIVE_UINT_TYPE SizeType
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.