F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
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 
7 #include "Fw/Types/Assert.hpp"
9 #if FW_ENABLE_TEXT_LOGGING
10 #include "Fw/Types/String.hpp"
11 #endif
13 
14 namespace 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 getCapacity() 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 
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_FwIndexType "]",
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(
110  Os::Queue::Status::OP_OK == qStat,
111  static_cast<FwAssertArgType>(qStat)
112  );
113  }
114 
115  // ----------------------------------------------------------------------
116  // Getters for typed input ports
117  // ----------------------------------------------------------------------
118 
121  {
122  FW_ASSERT(
123  (0 <= portNum) && (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 
135  ActiveTextLoggerComponentBase(const char* compName) :
136  Fw::ActiveComponentBase(compName)
137  {
138 
139  }
140 
143  {
144 
145  }
146 
147  // ----------------------------------------------------------------------
148  // Port handler base-class functions for typed input ports
149  //
150  // Call these functions directly to bypass the corresponding ports
151  // ----------------------------------------------------------------------
152 
155  FwIndexType portNum,
156  FwEventIdType id,
157  Fw::Time& timeTag,
158  const Fw::LogSeverity& severity,
159  Fw::TextLogString& text
160  )
161  {
162  // Make sure port number is valid
163  FW_ASSERT(
164  (0 <= portNum) && (portNum < this->getNum_TextLogger_InputPorts()),
165  static_cast<FwAssertArgType>(portNum)
166  );
167 
168  // Call handler function
169  this->TextLogger_handler(
170  portNum,
171  id,
172  timeTag,
173  severity,
174  text
175  );
176  }
177 
178  // ----------------------------------------------------------------------
179  // Internal interface base-class functions
180  // ----------------------------------------------------------------------
181 
184  {
185  ComponentIpcSerializableBuffer msg;
187 
188  // Serialize the message ID
189  _status = msg.serializeFrom(static_cast<FwEnumStoreType>(INT_IF_TEXTQUEUE));
190  FW_ASSERT (
191  _status == Fw::FW_SERIALIZE_OK,
192  static_cast<FwAssertArgType>(_status)
193  );
194 
195  // Fake port number to make message dequeue work
196  _status = msg.serializeFrom(static_cast<FwIndexType>(0));
197  FW_ASSERT (
198  _status == Fw::FW_SERIALIZE_OK,
199  static_cast<FwAssertArgType>(_status)
200  );
201 
202  _status = msg.serializeFrom(text);
203  FW_ASSERT(
204  _status == Fw::FW_SERIALIZE_OK,
205  static_cast<FwAssertArgType>(_status)
206  );
207 
208  // Send message
210  Os::Queue::Status qStatus = this->m_queue.send(msg, 1, _block);
211 
212  if (qStatus == Os::Queue::Status::FULL) {
213  this->incNumMsgDropped();
214  return;
215  }
216 
217  FW_ASSERT(
218  qStatus == Os::Queue::OP_OK,
219  static_cast<FwAssertArgType>(qStatus)
220  );
221  }
222 
223  // ----------------------------------------------------------------------
224  // Message dispatch functions
225  // ----------------------------------------------------------------------
226 
227  Fw::QueuedComponentBase::MsgDispatchStatus ActiveTextLoggerComponentBase ::
228  doDispatch()
229  {
230  ComponentIpcSerializableBuffer _msg;
231  FwQueuePriorityType _priority = 0;
232 
233  Os::Queue::Status _msgStatus = this->m_queue.receive(
234  _msg,
236  _priority
237  );
238  FW_ASSERT(
239  _msgStatus == Os::Queue::OP_OK,
240  static_cast<FwAssertArgType>(_msgStatus)
241  );
242 
243  // Reset to beginning of buffer
244  _msg.resetDeser();
245 
246  FwEnumStoreType _desMsg = 0;
247  Fw::SerializeStatus _deserStatus = _msg.deserializeTo(_desMsg);
248  FW_ASSERT(
249  _deserStatus == Fw::FW_SERIALIZE_OK,
250  static_cast<FwAssertArgType>(_deserStatus)
251  );
252 
253  MsgTypeEnum _msgType = static_cast<MsgTypeEnum>(_desMsg);
254 
255  if (_msgType == ACTIVETEXTLOGGER_COMPONENT_EXIT) {
256  return MSG_DISPATCH_EXIT;
257  }
258 
259  FwIndexType portNum = 0;
260  _deserStatus = _msg.deserializeTo(portNum);
261  FW_ASSERT(
262  _deserStatus == Fw::FW_SERIALIZE_OK,
263  static_cast<FwAssertArgType>(_deserStatus)
264  );
265 
266  switch (_msgType) {
267  // Handle internal interface TextQueue
268  case INT_IF_TEXTQUEUE: {
270  _deserStatus = _msg.deserializeTo(text);
271 
272  // Internal interface should always deserialize
273  FW_ASSERT(
274  Fw::FW_SERIALIZE_OK == _deserStatus,
275  static_cast<FwAssertArgType>(_deserStatus)
276  );
277 
278  // Make sure there was no data left over.
279  // That means the buffer size was incorrect.
280  FW_ASSERT(
281  _msg.getDeserializeSizeLeft() == 0,
282  static_cast<FwAssertArgType>(_msg.getDeserializeSizeLeft())
283  );
284 
285  // Call handler function
287  text
288  );
289 
290  break;
291  }
292 
293  default:
294  return MSG_DISPATCH_ERROR;
295  }
296 
297  return MSG_DISPATCH_OK;
298  }
299 
300  // ----------------------------------------------------------------------
301  // Calls for messages received on typed input ports
302  // ----------------------------------------------------------------------
303 
304  void ActiveTextLoggerComponentBase ::
305  m_p_TextLogger_in(
306  Fw::PassiveComponentBase* callComp,
307  FwIndexType portNum,
308  FwEventIdType id,
309  Fw::Time& timeTag,
310  const Fw::LogSeverity& severity,
311  Fw::TextLogString& text
312  )
313  {
314  FW_ASSERT(callComp);
315  ActiveTextLoggerComponentBase* compPtr = static_cast<ActiveTextLoggerComponentBase*>(callComp);
316  compPtr->TextLogger_handlerBase(
317  portNum,
318  id,
319  timeTag,
320  severity,
321  text
322  );
323  }
324 
325 }
Serialization/Deserialization operation was successful.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
virtual void TextQueue_internalInterfaceHandler(const Fw::InternalInterfaceString &text)=0
Internal interface handler for TextQueue.
Operation succeeded.
Definition: Os.hpp:26
void init()
Initialization function.
PlatformSizeType FwSizeType
Status receive(U8 *destination, FwSizeType capacity, BlockingType blockType, FwSizeType &actualSize, FwQueuePriorityType &priority) override
receive a message from the queue through delegate
Definition: Queue.cpp:63
I32 FwEnumStoreType
Status
status returned from the queue send function
Definition: Queue.hpp:30
virtual void TextLogger_handler(FwIndexType portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text)=0
Handler for input port TextLogger.
ActiveTextLoggerComponentBase(const char *compName="")
Construct ActiveTextLoggerComponentBase object.
Os::Queue m_queue
queue object for active component
void init()
Object initializer.
Definition: ObjBase.cpp:24
SerializeStatus
forward declaration for string
Message will block until space is available.
Definition: Queue.hpp:47
FwIdType FwEventIdType
The type of an event identifier.
Os::Queue::Status createQueue(FwSizeType depth, FwSizeType msgSize)
virtual ~ActiveTextLoggerComponentBase()
Destroy ActiveTextLoggerComponentBase object.
Fw::InputLogTextPort * get_TextLogger_InputPort(FwIndexType portNum)
const char * toChar() const
Convert to a C-style char*.
Definition: ObjectName.hpp:50
FwSizeType SizeType
Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override
send a message into the queue through delegate
Definition: Queue.cpp:46
Enum representing event severity.
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
void setPortNum(FwIndexType portNum)
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
BlockingType
message type
Definition: Queue.hpp:46
PlatformQueuePriorityType FwQueuePriorityType
The type of queue priorities used.
A message was sent requesting an exit of the loop.
PlatformIndexType FwIndexType
void incNumMsgDropped()
increment the number of messages dropped
RateGroupDivider component implementation.
message sent/received okay
Definition: Queue.hpp:31
U8 BYTE
byte type
Definition: BasicTypes.h:56
message to exit active component task
Message will return with status when space is unavailable.
Definition: Queue.hpp:48
Implementation of malloc based allocator.
void TextLogger_handlerBase(FwIndexType portNum, FwEventIdType id, Fw::Time &timeTag, const Fw::LogSeverity &severity, Fw::TextLogString &text)
Handler base-class function for input port TextLogger.
static constexpr FwIndexType getNum_TextLogger_InputPorts()
void TextQueue_internalInterfaceInvoke(const Fw::InternalInterfaceString &text)
Internal interface base-class function for TextQueue.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.