F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
ActiveTextLoggerComponentAc.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title ActiveTextLoggerComponentAc.cpp
3// \author Generated by fpp-to-cpp
4// \brief cpp file for ActiveTextLogger component base class
5// ======================================================================
6
8#include "Fw/Types/Assert.hpp"
10#if FW_ENABLE_TEXT_LOGGING
11#include "Fw/Types/String.hpp"
12#endif
13
14namespace Svc {
15
16 namespace {
17 enum MsgTypeEnum {
18 ACTIVETEXTLOGGER_COMPONENT_EXIT = Fw::ActiveComponentBase::ACTIVE_COMPONENT_EXIT,
19 INT_IF_TEXTQUEUE,
20 };
21
22 // Get the max size by constructing a union of the async input, command, and
23 // internal port serialization sizes
24 union BuffUnion {
25 // Size of TextQueue argument list
26 BYTE TextQueueIntIfSize[
28 ];
29 };
30
31 // Define a message buffer class large enough to handle all the
32 // asynchronous inputs to the component
33 class ComponentIpcSerializableBuffer :
35 {
36
37 public:
38
39 enum {
40 // Offset into data in buffer: Size of message ID and port number
41 DATA_OFFSET = sizeof(FwEnumStoreType) + sizeof(FwIndexType),
42 // Max data size
43 MAX_DATA_SIZE = sizeof(BuffUnion),
44 // Max message size: Size of message id + size of port + max data size
45 SERIALIZATION_SIZE = DATA_OFFSET + MAX_DATA_SIZE
46 };
47
48 Fw::Serializable::SizeType getBuffCapacity() const {
49 return sizeof(m_buff);
50 }
51
52 U8* getBuffAddr() {
53 return m_buff;
54 }
55
56 const U8* getBuffAddr() const {
57 return m_buff;
58 }
59
60 private:
61 // Should be the max of all the input ports serialized sizes...
62 U8 m_buff[SERIALIZATION_SIZE];
63
64 };
65 }
66
67 // ----------------------------------------------------------------------
68 // Component initialization
69 // ----------------------------------------------------------------------
70
71 void ActiveTextLoggerComponentBase ::
72 init(
73 FwSizeType queueDepth,
74 FwEnumStoreType instance
75 )
76 {
77 // Initialize base class
79
80 // Connect input port TextLogger
81 for (
82 FwIndexType port = 0;
83 port < static_cast<FwIndexType>(this->getNum_TextLogger_InputPorts());
84 port++
85 ) {
86 this->m_TextLogger_InputPort[port].init();
87 this->m_TextLogger_InputPort[port].addCallComp(
88 this,
89 m_p_TextLogger_in
90 );
91 this->m_TextLogger_InputPort[port].setPortNum(port);
92
93#if FW_OBJECT_NAMES == 1
94 Fw::ObjectName portName;
95 portName.format(
96 "%s_TextLogger_InputPort[%" PRI_PlatformIntType "]",
97 this->m_objName.toChar(),
98 port
99 );
100 this->m_TextLogger_InputPort[port].setObjName(portName.toChar());
101#endif
102 }
103
104 // Create the queue
105 Os::Queue::Status qStat = this->createQueue(
106 queueDepth,
107 static_cast<FwSizeType>(ComponentIpcSerializableBuffer::SERIALIZATION_SIZE)
108 );
109 FW_ASSERT(
111 static_cast<FwAssertArgType>(qStat)
112 );
113 }
114
115 // ----------------------------------------------------------------------
116 // Getters for typed input ports
117 // ----------------------------------------------------------------------
118
119 Fw::InputLogTextPort* ActiveTextLoggerComponentBase ::
120 get_TextLogger_InputPort(FwIndexType portNum)
121 {
122 FW_ASSERT(
123 portNum < this->getNum_TextLogger_InputPorts(),
124 static_cast<FwAssertArgType>(portNum)
125 );
126
127 return &this->m_TextLogger_InputPort[portNum];
128 }
129
130 // ----------------------------------------------------------------------
131 // Component construction and destruction
132 // ----------------------------------------------------------------------
133
134 ActiveTextLoggerComponentBase ::
135 ActiveTextLoggerComponentBase(const char* compName) :
136 Fw::ActiveComponentBase(compName)
137 {
138
139 }
140
141 ActiveTextLoggerComponentBase ::
142 ~ActiveTextLoggerComponentBase()
143 {
144
145 }
146
147 // ----------------------------------------------------------------------
148 // Getters for numbers of typed input ports
149 // ----------------------------------------------------------------------
150
151 FwIndexType ActiveTextLoggerComponentBase ::
152 getNum_TextLogger_InputPorts() const
153 {
154 return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_TextLogger_InputPort));
155 }
156
157 // ----------------------------------------------------------------------
158 // Port handler base-class functions for typed input ports
159 //
160 // Call these functions directly to bypass the corresponding ports
161 // ----------------------------------------------------------------------
162
163 void ActiveTextLoggerComponentBase ::
164 TextLogger_handlerBase(
165 FwIndexType portNum,
166 FwEventIdType id,
167 Fw::Time& timeTag,
168 const Fw::LogSeverity& severity,
170 )
171 {
172 // Make sure port number is valid
173 FW_ASSERT(
174 portNum < this->getNum_TextLogger_InputPorts(),
175 static_cast<FwAssertArgType>(portNum)
176 );
177
178 // Call handler function
179 this->TextLogger_handler(
180 portNum,
181 id,
182 timeTag,
183 severity,
184 text
185 );
186 }
187
188 // ----------------------------------------------------------------------
189 // Internal interface base-class functions
190 // ----------------------------------------------------------------------
191
192 void ActiveTextLoggerComponentBase ::
193 TextQueue_internalInterfaceInvoke(const Fw::InternalInterfaceString& text)
194 {
195 ComponentIpcSerializableBuffer msg;
197
198 // Serialize the message ID
199 _status = msg.serialize(static_cast<FwEnumStoreType>(INT_IF_TEXTQUEUE));
200 FW_ASSERT (
201 _status == Fw::FW_SERIALIZE_OK,
202 static_cast<FwAssertArgType>(_status)
203 );
204
205 // Fake port number to make message dequeue work
206 _status = msg.serialize(static_cast<FwIndexType>(0));
207 FW_ASSERT (
208 _status == Fw::FW_SERIALIZE_OK,
209 static_cast<FwAssertArgType>(_status)
210 );
211
212 _status = msg.serialize(text);
213 FW_ASSERT(
214 _status == Fw::FW_SERIALIZE_OK,
215 static_cast<FwAssertArgType>(_status)
216 );
217
218 // Send message
220 Os::Queue::Status qStatus = this->m_queue.send(msg, 1, _block);
221
222 if (qStatus == Os::Queue::Status::FULL) {
223 this->incNumMsgDropped();
224 return;
225 }
226
227 FW_ASSERT(
228 qStatus == Os::Queue::OP_OK,
229 static_cast<FwAssertArgType>(qStatus)
230 );
231 }
232
233 // ----------------------------------------------------------------------
234 // Message dispatch functions
235 // ----------------------------------------------------------------------
236
237 Fw::QueuedComponentBase::MsgDispatchStatus ActiveTextLoggerComponentBase ::
238 doDispatch()
239 {
240 ComponentIpcSerializableBuffer msg;
241 FwQueuePriorityType priority = 0;
242
243 Os::Queue::Status msgStatus = this->m_queue.receive(
244 msg,
246 priority
247 );
248 FW_ASSERT(
249 msgStatus == Os::Queue::OP_OK,
250 static_cast<FwAssertArgType>(msgStatus)
251 );
252
253 // Reset to beginning of buffer
254 msg.resetDeser();
255
256 FwEnumStoreType desMsg = 0;
257 Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
258 FW_ASSERT(
259 deserStatus == Fw::FW_SERIALIZE_OK,
260 static_cast<FwAssertArgType>(deserStatus)
261 );
262
263 MsgTypeEnum msgType = static_cast<MsgTypeEnum>(desMsg);
264
265 if (msgType == ACTIVETEXTLOGGER_COMPONENT_EXIT) {
266 return MSG_DISPATCH_EXIT;
267 }
268
269 FwIndexType portNum = 0;
270 deserStatus = msg.deserialize(portNum);
271 FW_ASSERT(
272 deserStatus == Fw::FW_SERIALIZE_OK,
273 static_cast<FwAssertArgType>(deserStatus)
274 );
275
276 switch (msgType) {
277 // Handle internal interface TextQueue
278 case INT_IF_TEXTQUEUE: {
280 deserStatus = msg.deserialize(text);
281
282 // Internal interface should always deserialize
283 FW_ASSERT(
284 Fw::FW_SERIALIZE_OK == deserStatus,
285 static_cast<FwAssertArgType>(deserStatus)
286 );
287
288 // Make sure there was no data left over.
289 // That means the buffer size was incorrect.
290 FW_ASSERT(
291 msg.getBuffLeft() == 0,
292 static_cast<FwAssertArgType>(msg.getBuffLeft())
293 );
294
295 // Call handler function
296 this->TextQueue_internalInterfaceHandler(
297 text
298 );
299
300 break;
301 }
302
303 default:
304 return MSG_DISPATCH_ERROR;
305 }
306
307 return MSG_DISPATCH_OK;
308 }
309
310 // ----------------------------------------------------------------------
311 // Calls for messages received on typed input ports
312 // ----------------------------------------------------------------------
313
314 void ActiveTextLoggerComponentBase ::
315 m_p_TextLogger_in(
316 Fw::PassiveComponentBase* callComp,
317 FwIndexType portNum,
318 FwEventIdType id,
319 Fw::Time& timeTag,
320 const Fw::LogSeverity& severity,
322 )
323 {
324 FW_ASSERT(callComp);
325 ActiveTextLoggerComponentBase* compPtr = static_cast<ActiveTextLoggerComponentBase*>(callComp);
326 compPtr->TextLogger_handlerBase(
327 portNum,
328 id,
329 timeTag,
330 severity,
331 text
332 );
333 }
334
335}
#define FW_ASSERT(...)
Definition Assert.hpp:14
U8 BYTE
byte type
Definition BasicTypes.h:31
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:30
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition BasicTypes.h:70
#define PRI_PlatformIntType
I32 FwEnumStoreType
Definition FpConfig.h:64
PlatformAssertArgType FwAssertArgType
Definition FpConfig.h:39
U32 FwEventIdType
Definition FpConfig.h:103
PlatformSizeType FwSizeType
Definition FpConfig.h:35
PlatformQueuePriorityType FwQueuePriorityType
Definition FpConfig.h:55
PlatformIndexType FwIndexType
Definition FpConfig.h:25
@ ACTIVE_COMPONENT_EXIT
message to exit active component task
Enum representing event severity.
void init()
Object initializer.
Definition ObjBase.cpp:27
const char * toChar() const
NATIVE_UINT_TYPE SizeType
void format(const CHAR *formatString,...)
write formatted string to buffer
BlockingType
message type
Definition Queue.hpp:44
@ BLOCKING
Message will block until space is available.
Definition Queue.hpp:45
@ NONBLOCKING
Message will return with status when space is unavailable.
Definition Queue.hpp:46
Status
status returned from the queue send function
Definition Queue.hpp:30
@ FULL
queue was full when attempting to send a message
Definition Queue.hpp:39
@ OP_OK
message sent/received okay
Definition Queue.hpp:31
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.