F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
TlmPortAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title TlmPortAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for Tlm port
5 // ======================================================================
6 
7 #include "Fw/Tlm/TlmPortAc.hpp"
8 #include "Fw/Types/Assert.hpp"
9 
10 namespace Fw {
11 
12  // ----------------------------------------------------------------------
13  // Public constructors for TlmPortSerializer
14  // ----------------------------------------------------------------------
15 
18  m_id(),
19  m_timeTag(),
20  m_val()
21  {
22 
23  }
24 
25  // ----------------------------------------------------------------------
26  // Public member functions for TlmPortSerializer
27  // ----------------------------------------------------------------------
28 
31  {
33  if (_status == Fw::FW_SERIALIZE_OK) {
34  _status = _buffer.deserializeTo(m_id);
35  }
36  if (_status == Fw::FW_SERIALIZE_OK) {
37  _status = _buffer.deserializeTo(m_timeTag);
38  }
39  if (_status == Fw::FW_SERIALIZE_OK) {
40  _status = _buffer.deserializeTo(m_val);
41  }
42  return _status;
43  }
44 
45  // ----------------------------------------------------------------------
46  // Public static functions for TlmPortSerializer
47  // ----------------------------------------------------------------------
48 
51  FwChanIdType id,
52  Fw::Time& timeTag,
53  Fw::TlmBuffer& val,
54  Fw::SerialBufferBase& _buffer
55  )
56  {
58  if (_status == Fw::FW_SERIALIZE_OK) {
59  _status = _buffer.serializeFrom(id);
60  }
61  if (_status == Fw::FW_SERIALIZE_OK) {
62  _status = _buffer.serializeFrom(timeTag);
63  }
64  if (_status == Fw::FW_SERIALIZE_OK) {
65  _status = _buffer.serializeFrom(val);
66  }
67  return _status;
68  }
69 
70 #if !FW_DIRECT_PORT_CALLS
71 
72  // ----------------------------------------------------------------------
73  // Public constructors for InputTlmPort
74  // ----------------------------------------------------------------------
75 
78  Fw::InputPortBase(),
79  m_func(nullptr)
80  {
81 
82  }
83 
84  // ----------------------------------------------------------------------
85  // Public member functions for InputTlmPort
86  // ----------------------------------------------------------------------
87 
88  void InputTlmPort ::
90  {
92  }
93 
94  void InputTlmPort ::
96  Fw::PassiveComponentBase* callComp,
97  CompFuncPtr funcPtr
98  )
99  {
100  FW_ASSERT(callComp != nullptr);
101  FW_ASSERT(funcPtr != nullptr);
102 
103  this->m_comp = callComp;
104  this->m_func = funcPtr;
105  this->m_connObj = callComp;
106  }
107 
108  void InputTlmPort ::
110  FwChanIdType id,
111  Fw::Time& timeTag,
112  Fw::TlmBuffer& val
113  )
114  {
115 #if FW_PORT_TRACING == 1
116  this->trace();
117 #endif
118 
119  FW_ASSERT(this->m_comp != nullptr);
120  FW_ASSERT(this->m_func != nullptr);
121 
122  return this->m_func(this->m_comp, this->m_portNum, id, timeTag, val);
123  }
124 
125  // ----------------------------------------------------------------------
126  // Private member functions for InputTlmPort
127  // ----------------------------------------------------------------------
128 
129 #if FW_PORT_SERIALIZATION == 1
130 
131  Fw::SerializeStatus InputTlmPort ::
132  invokeSerial(Fw::LinearBufferBase& _buffer)
133  {
134 #if FW_PORT_TRACING == 1
135  this->trace();
136 #endif
137 
138  FW_ASSERT(this->m_comp != nullptr);
139  FW_ASSERT(this->m_func != nullptr);
140 
141  TlmPortSerializer _serializer;
142  Fw::SerializeStatus _status = _serializer.deserializePortArgs(_buffer);
143  if (_status != Fw::FW_SERIALIZE_OK) {
144  return _status;
145  }
146 
147  this->m_func(this->m_comp, this->m_portNum, _serializer.m_id, _serializer.m_timeTag, _serializer.m_val);
148 
149  return Fw::FW_SERIALIZE_OK;
150  }
151 
152 #endif
153 
154  // ----------------------------------------------------------------------
155  // Public constructors for OutputTlmPort
156  // ----------------------------------------------------------------------
157 
160  Fw::OutputPortBase(),
161  m_port(nullptr)
162  {
163 
164  }
165 
166  // ----------------------------------------------------------------------
167  // Public member functions for OutputTlmPort
168  // ----------------------------------------------------------------------
169 
170  void OutputTlmPort ::
172  {
174  }
175 
176  void OutputTlmPort ::
178  {
179  FW_ASSERT(callPort != nullptr);
180 
181  this->m_port = callPort;
182  this->m_connObj = callPort;
183 
184 #if FW_PORT_SERIALIZATION == 1
185  this->m_serPort = nullptr;
186 #endif
187  }
188 
189  void OutputTlmPort ::
191  FwChanIdType id,
192  Fw::Time& timeTag,
193  Fw::TlmBuffer& val
194  ) const
195  {
196 #if FW_PORT_TRACING == 1
197  this->trace();
198 #endif
199 
200 #if FW_PORT_SERIALIZATION
201  FW_ASSERT((this->m_port != nullptr) || (this->m_serPort != nullptr));
202 
203  if (this->m_port != nullptr) {
204  this->m_port->invoke(id, timeTag, val);
205  }
206  else {
207  Fw::SerializeStatus _status;
208  TlmPortBuffer _buffer;
209 
210  _status = TlmPortSerializer::serializePortArgs(id, timeTag, val, _buffer);
211  FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
212 
213  _status = this->m_serPort->invokeSerial(_buffer);
214  FW_ASSERT(_status == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(_status));
215  }
216 #else
217  FW_ASSERT(this->m_port != nullptr);
218  this->m_port->invoke(id, timeTag, val);
219 #endif
220  }
221 
222 #endif
223 
224 }
Serialization/Deserialization operation was successful.
FwIndexType m_portNum
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Definition: TlmPortAc.cpp:95
static Fw::SerializeStatus serializePortArgs(FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val, Fw::SerialBufferBase &_buffer)
Serialize port arguments into a buffer.
Definition: TlmPortAc.cpp:50
void init()
Initialization function.
Definition: TlmPortAc.cpp:171
void init()
Initialization function.
Definition: TlmPortAc.cpp:89
Fw::SerializeStatus deserializePortArgs(Fw::SerialBufferBase &_buffer)
Deserialze port arguments into members.
Definition: TlmPortAc.cpp:30
virtual SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG)=0
Serialize an 8-bit unsigned integer value.
void addCallPort(InputTlmPort *callPort)
Register an input port.
Definition: TlmPortAc.cpp:177
InputTlmPort()
Constructor.
Definition: TlmPortAc.cpp:77
SerializeStatus
forward declaration for string
virtual SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG)=0
Deserialize an 8-bit unsigned integer value.
void init() override
TlmPortSerializer()
Constructor.
Definition: TlmPortAc.cpp:17
FwIdType FwChanIdType
The type of a telemetry channel identifier.
OutputTlmPort()
Constructor.
Definition: TlmPortAc.cpp:159
void invoke(FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val) const
Invoke a port connection.
Definition: TlmPortAc.cpp:190
Fw::TlmBuffer m_val
Definition: TlmPortAc.hpp:122
PassiveComponentBase * m_comp
void init() override
void invoke(FwChanIdType id, Fw::Time &timeTag, Fw::TlmBuffer &val)
Invoke a port interface.
Definition: TlmPortAc.cpp:109
Implementation of malloc based allocator.
Fw::ObjBase * m_connObj
Definition: PortBase.hpp:34
#define FW_ASSERT(...)
Definition: Assert.hpp:14